Migrating Android Development Environment from Eclipse to IntelliJ(1)


IntelliJ is Light

The standard IDE for development of Android is Eclipse. However, when you use IntelliJ that is another IDE for Android development, it is comfortable with moving lightly and easy-to-understanding menu structure. You can use the Community Edition (Open Source) for free to develop Android Application.
intelliJ_compressed
In this article, I describe the tasks required who have been using the Eclipse for Android development ever to migrate to IntelliJ.

Installation of IntelliJ

Summary of the installation is as follows.

  1. Installation of JDK
  2. Installation of Android SDK
  3. Installation and Configuration of IntelliJ

You need a plugin called ADT to Eclipse. But It is not necessary for IntelliJ. I think if people who have already been developing in Eclipse, installing JDK and Android SDK is already done. (Or if on Ubuntu, see JDK and Android SDK Installation on Ubuntu | DeVlog.) Therefor, you can start developing as soon as install and configure IntelliJ. I will show the insallation instructions for IntelliJ below.

  1. Download a file for your platform from IntelliJ IDEA :: Download Latest Version of IntelliJ IDEA. You can use the Community Editon (free) for Android development without limitation. The case of Windows, so just follow the instructions of the installer, it is not particularly difficult to install the software. The case of Ubuntu, you can install from the software center. I think you can easily install on other platforms. Please follow the instructions on the site.
  2. After installation, the following dialog box will open with the first start, if you install the first time, press OK to select the “I do not…”.
    complete_installation
    Welcome screen opens.
    welcome_compressed

    Configuration of IntelliJ

    After opening Welcome screen, keep the basic settings.

    Project Defaults

    Before dealing with the actual project, you need to let IntelliJ to recognize JDK and Android SDK. To do so, you may set the project defaults.
    Configure > Project Defaultes > Project Structure, in “Project SDK” select New > JDK.
    set_jdk_compressed
    After opening folder selection, select the folder JDK installed.
    jdk_select_compressed
    Click “New” again and select “Android SDK” to set directory.
    set_sdk_compressed
    sdk_select_compressed
    JDK and SDK is set.
    jdk_sdk_compressed

    Change Theme

    Try to set the theme easy to see. I recommend “Darcula”.
    Select from Configure > Settings > Appearance > UI Options. After apply, you are prompted to restart.
    theme_compressed

    At this point, you are ready for developing Android. Next time, I will expain how to use IntelliJ.

    [Relative Sites]


To reset the settings for SharedPreferences in Android


I had a hard time to achieve to reset preferences back to their default values on Android development. So I would like to describe some caveats.

“setDefaultValues” ​​will set uninitialized parameters only

Description of the last parameter of “PreferenceManager#setDefaultValues” (readAgain) is as follows.

Whether to re-read the default values. If false, this method will set the default values only if this method has never been called in the past (or if the KEY_HAS_SET_DEFAULT_VALUES in the default value shared preferences file is false). To attempt to set the default values again bypassing this check, set readAgain to true.

From this description, you may feel like that the preferences will be reseted back to their default values if you call the “setDefaultValues” by readAgain being true.
However, you can not do so by the following code only.

If you look again the description of “readAgain”, you will find following notes.

Note: this will NOT reset preferences back to their default values. For that functionality, use getDefaultSharedPreferences(Context) and clear it followed by a call to this method with this parameter set to true.

This means that “setDefaultValues” loads default values but not override parameters that has been set already. Only uninitialized parameters are read. So, you should clear parameters in advance.

Clear first, then call “setDefaultVallues”

Concretely, describe as follows.

Then, settings are reset to the default values.

However, if you run the above code while displaying the “PreferenceActivity”, they will not be redraw. You can not verify that the values has been changed before back from the activity and show it again.

To redraw the Activity

If you place the reset button in “PreferenceActivity”, thus UI is incomplete. So you need a way to redraw the “Activity”. As a result of my invesigation, I found that the method in java – refreshing views of Preferences when using PreferenceActivity – Stack Overflow works well.

Then, I found out more about “Activity#overridePendingTransition” in my own way and found that you should put it after “finish()” or “startActivity()”. In addition, testing the code, I made sure that it is unnecessary to specify “FLAG_ACTIVITY_NO_ANIMATION”.

After all, I confirmed that creating the following code as a method of “Activity” (in this article, “PreferenceActivity”) and calling it after “setDefaultValues” above will go well.

[Reference Sites]


Split view of one file in Sublime Text2


How to split one file into two views in Sublime Text2

You will often be coding while comparing the two places of the same file. Of course, Sublime Text2 can display vertical or horizontal split view of one file.
sublime_split_en_compressed
However, it is a little hard to understand how to do it. So, I will explain it. (In the following description, the key assignment is assumed to Windows.)

  1. Split window by View > Layout (alt + shift + num)
    Each view divided here is recognized as each “group”.
  2. Make file clone by File > “New View into File”
    Another tab of the file is made in the same group.
  3. Move to another tab by dragging & dropping the tab made in 2, or View > “Move File To Group” (Ctrl + num).

At least, you can display the same file into two groups.

To Make Shortcut for “New View into File”

By default, any shortcut is not assigned in the menu “New View into File”. If you want to assign it to “alt + shift + c”, open the definition file by Preferences > “Key Bindings – User” and add the following definition between [ ].

If you already have other definitions, add “,” after the last definition and the definition above. I think it will be as follows.

Use “SimpleClone”

Even if you define the shortcut in this way, it is cumbersome to take 3 steps: Split View > Clone File > Move Clone to Another Group. At such times, you may use a plug-in called “SimpleClone”.

If you already installed “Package Control”, you can install by Tools > “Command Palette…” > “Package Control: Install Package” > SimpleClone.

There are menu in View > SimpleClone and shortcut is as follows.
Ctrl + Shift + right: Split to right
Ctrl + Shift + down: Split down
Ctrl + Alt + Shift + n: Make clone in new window

[Reference Sites]