How to add Eclipse Code Formatter file in Android Studio - android

What I have:
I have a customised code format (.xml) file that my team wants to use in our project. This file includes predefined coding styles and conventions for java file.
What I want to do:
Now I have to add this formatter as a default code format, so that when click the shortcut of auto code format, the entire file will be formatted according to the the conventions defined in the formatter.

After a long 2days effort I managed the steps to integrate Eclipse Code Formatter in Android Studio
Here I am sharing step by step procedures to integrate Eclipse Code Formatter in Android Studio:
Step 1: Go to the Plugins Section of Android Studio.
The easiest way is Click Shift twice and type Plugins. Now go to the plugins menu.
Step 2: Click on Browse Repositories
Step 3: Type Eclipse Code Formatter in the search box. Select it and Click Install button in the right section
Step 4: After successful installation you can see a blue Eclipse Icon in the top pen
Step 5: Now go to Settings >> Other Settings >> Eclipse Code formatter
Click the Browse button.
Step 6: Then select the Code Format XML file
Thats it
Any time you click the code formatting command your full code will be formatted according to the code formatter.
Code formatting shortcut:
Windows:
Ctrl + Alt + L
Linux:
Ctrl + Start + Alt + L
Mac:
Option + Command + L
In case anyone want to see how the code formatter xml looks, you can check this one.
One of the mostly used code style used by google is here.

Related

Android studio .editorconfig file not overriding the styles

I am currently trying to use ktlint and I want the same style to be followed by all developers so I want to override the AS styles with my own using the **.editorconfig **file but when I run ktlintFormat and then run alt + cmd + L there are new formatting changes. Ideally the .editorconfig should over ride the studio styles but it doesn't seem to be happening.
PS : I have checked the enabled editorconfig support in preference.
Tried adding my .editorconfig file and formatted styles but it is not being honoured and still picking up AS styles on manual formatting while there should be no change when manually formatting.

How to search all files for a string in Android Studio?

In Android Studio (IntelliJ) how do you execute a 'File Search' for a string within a Scope of files? Can Search Everywhere do this, I only see how to use it to search 'code', not 'files'
Example: Search for the string "Dummy Button" in the 'Workspace Scope'.
Expected Response: res/values/string.xml:line4
You can do it in two ways,
Goto Menu -> Edit -> Find -> Find in Path
Or use the shortcut,
ctrl+shift+f
In Android Studio,
On a Windows or Linux based machine use shortcut Ctrl + Shift + F to search any string in whole project. It's easy to remember considering Ctrl + F is used to search in the current file. So just press the Shift as well.
On OSX use the Command key instead of Ctrl.
Use Ctrl + F combination for Windows and Linux to search in current file.
Use Shift + Shift (Double Tap Shift) combination for Windows and Linux to search Project File of Project.
Command+Shift+F on Mac to find in path
In Android Studio 4.1 update, the combination for Mac users changed, now you should use Control + Shift + f.
Try this. Enter your string name in dialogue box after pressing ctrl+shift+f
Menu Bar->Edit->Find->Find in Path...
Press Two times Shift button and write in search box it will search in whole Android studio.
In my case, I accidentally checked the box of "File mask". So all xml files are not searchable in Find in Path. Maybe this can help you.

Ctrl + Space Not Working Properly Android Studio

i am facing problem in android studio. In eclipse when i want to use class like Intent, then i write intent starting with lower case it give me suggestion box indicating class name Intent, but in android studio if i type intent starting with lower case it does not Provide Suggestion class name Intent.Thanks in advance.
In my case Ctrl + Space was overloaded by mac shortcuts. And even in the case, I disabled them, they conflict with Android Studio.
So, I gave them another keys and it solved the problem.
Go to the System Preferences -> Keyboard -> Shortcuts -> Input Sources and use new keys for them.
The problem is that Android Studio has different key binding than Eclipse, but you can set the key binding to be the same as in eclipse in android studio settings. Also by default ctrl + space is case sensitive in Android studio, you need to turn that off too.
Move to File -> Settings -> Keymap and change keymaps settings to eclipse so that you can use the short cut keys like in eclipse.
You can set 'Case sensitive completion' to 'None' in IDE Settings > Editor > Code Completion.
That should do it :)
File --> Settings --> Editor --> General --> Code Completion --> Case sensitive completion --> None

How to add code snippets in Android Studio IDE?

does anyone know how to add code snippets in Android Studio IDE?
I didn't found a menu entry or something like this.
I also want to know is it possible to change the existing snippets?
To add/edit templates:
On the menu choose File -> Settings, then under IDE Settings (or Editor) go to Live Templates.
To insert a template:
On the menu choose Code -> Insert Live Template (or use it's assigned shortcut key).
Screenshot Android Studio 3.4
Code snippets are known as Live Templates in Android Studio
Browse the current Live Templates
Go to File > Settings > Editor > Live Templates. Then click on the different options to see what they do.
Here are some interesting ones:
foreach
for ($i$ : $data$) {
$cursor$
}
Toast
android.widget.Toast.makeText($className$.this, "$text$", Toast.LENGTH_SHORT).show();
todo
// TODO: $date$ $todo$
logi
android.util.Log.i(TAG, "$METHOD_NAME$: $content$");
The words surrounded by $ signs are places where things will be filled in automatically from the context or where the user can tab through to fill them in.
Use a Live Template
Just type in the abbreviation and tab through anything that you need to fill in.
Example:
logi
and I'm given this
Log.i(TAG, "myMethodName: |");
with the cursor located at the position I marked with the vertical line |.
Make you own Live Template
Just write the code, highlight it, and go to Tools > Save as Live Template.
Further Study
Creating and Editing Live Templates (IntelliJ docs)
Level-up with Android Studio Shortcuts and Live Templates
Android Studio Live Templates
Go to Settings (File > Settings, or CTRLALT + S) then search for "Live Templates".
A template screen will be opened. You can see here all live templates and you can also create your own custom live templates.
It is important that you choose the correct template group to define your new template (e.g. "Android").
As an example, I will define a Toast method as a live template.
You can also click "use static import as possible" not to be handle importing stuff.
Cntr + j : to insert an existant live template.
File -> Settings -> Editor -> Code style -> live Templates >> add a template with button +
edit your template and OK :)
go to Settings
(Files > Settings (ctrl + alt + s) > then click Editor > Live Templates )
like this:
then type your abbreviation name and use your template any where

In eclipse, shortcut for "ctrl+shift+g" for multiproject?

I have multi android project in eclipse, when I read source code, I want to know all the reference for one class, but the Ctrl + Shift + G just the search result in the same project. even I click the right menu -- Reference--worksapce.

Categories

Resources