Sunday 23 April 2017

Easy Code Tricks Android Development - Part - II


Click to review the Part I 

Here we go through the ten easy tricks to reduce our code time.  Android Studio IDE's facilitates our work to get done in a quick time.


Ctrl+N, type the class name to reach out the files directly from any where in the IDE and Ctrl+Shift+N, this pulls down all the classes, interfaces and .xml files as well



Choose from the last copy/pastes (manage your clipboard):  Mac: cmd + shift + v (Windows / Linux: ctrl + shift + v). By default there are 5 last copy/paste items.


Live Code Template: Mac: cmd + j (Windows / Linux: ctrl + j)


Enable multicursor feature: Mac: cmd + g (alt + j for Windows/Linux). press the shortcut to choose the similar text and get the cursor to the texts, while editing will update those values simultaneously.


Goto super class: Mac: cmd + u (Windows / Linux: ctrl + u). For instance, you override some method. When your caret in on the method’s name and press the shortcut, you will be redirected to the parent method.

Goto Declaration: Mac: cmd + b (Windows / Linux: ctrl + b). Place cursor on the word and use the shortcut, It allows you to quickly check and go to a declaration of a class, method or a variable.

Goto type declaration: Mac: cmd + shift + b (Windows / Linux: ctrl + shift + b).  Place cursor on the word and use the shortcut,  It allows you to quickly navigate to its type declaration.

Move and navigate between opened tabs:
Mac: cmd + shift + [ (move left) or cmd + shift + ] (move right)
Windows/Linux: alt + ← or →

Close a current tab:  Mac: cmd + w | Windows/Linux: ctrl + F4

Move hardcoded strings to resources: option + return (Windows / Linux: alt + enter). The shortcut must be used when a caret is on a text.


Sunday 2 April 2017

7 Easy Code Tricks Android Development - Part - I


Here we go through the six easy tricks to reduce our code time.  This IDE's facilitates our work to get done in a quick time.

  1. Auto-Generate the parameterized constructor
  2. Auto-Generate the Getter and Setter Method
  3. Quick Walk-through on the documentation of android classes and methods
  4. Play around the bookmarks
  5. Generate documentation comments to the user defined methods. 
  6. Rename the text and reflect them to all places.
  7. Shortcut to set comments.
1. Auto-Generate the parameterized constructor:  We can simply presses the shift key twice in the code area it will brings you the popover search, there we need to key a search term as "constru....".  Select the constructor and then it will put you to the choose fields section, here select your necessary fields which you want to make as a parameters to the constructor.  After selecting click "ok" to generate the constructor, if you want an empty constructor just select an option "Select none". 














2. Auto-Generate the Getter and Setter Method:  Same as above, press the shift key twice on the code area and key the search term as "Getter and Set...", there you can find an option "Getter and Setter" also we can select either Getter or Setter  to generate those methods.  once selecting that option we need to choose the fields to which we required the set and get methods.

  

3. Quick Walk-through on the documentation of android classes and methods:  Select or keep cursor on the classes or methods and press the shortcut key "Ctrl+Q".


4. Play around the bookmarks: This is good feature on the coding part help us to switch immediately to the line of code, no need to worry about where we are in the project or files.  Once we presses the bookmark id. it will immediately takes you to the line of code.   In order to set the Bookmark, place the cursor to the line of code and press Ctrl+Shift+<ID which sounds the number between 1 to 9>.  Same the way we need to use the same shortcut id to remove the bookmark. Importantly if you use the same bookmark Id on the other places, the previous one will be get deleted.
  • Set - Ctrl+Shift+<ID 1 to 9>
  • Goto Bookmark - Ctrl+<ID>
  • Remove - Ctrl+Shift+<ID 1 to 9>

5. Generate documentation comments to the user defined methods: The documentation for the user defined is more important, it helps the other to review our code and finds the usage details of the params and returning values and it is a adds value to the business logic as well.   Simply place the cursor above the method and put /** <Press Enter>  This will gives you the documentation template where we can fill-up with the description details. 


6. Rename the text and reflect them to all places: Normally most of the developer faces this problem they have created a variable or method or class names, they intended to change i.e. rename that and this needs to be impact on all part of the project without any glitches. 



7. Shortcut to set comments: It is a general things we can use the below key shortcuts to comment the line of codes. 
  • Single - Ctrl+/
  • Select Multiple line - Ctrl+Shift+/