コマンドラインで stackoverflow を快速に検索できる「how2」

使い方はこうです.

usage: how2 [-l python/ruby/etc.] search string

コマンドである「how2」に続いて, 検索したいキーワードを入力します.

bz2

言語 (タグ?) を限定する場合はオプション「 -l 」を付けます.

例えば, キーワードを「retrolambda」「RxJava」として android 関連の情報を探します.

$ how2 -l android retrolambda rxjava

how2

さらに他に情報を見たい場合は [SPACE] を押すと一覧で表示されて選択できます.

__—_how2 2

__—_how2 3

__—_how2 4

これはもう「tldr」よりも広く分かりやすい説明をみつけることができそうです.

インストールは以下で.

$ brew install node
$ npm install -g how2

santinic/how2: stackoverflow from the terminal

man は長すぎるので「tldr」


【AndroidStudio 不要】サンプルアプリは「dryrun」で試してすぐ捨てよう

参考にしたいサンプルアプリをGiHubで見つけて試してみる場合は以下のような手順

1. サンプルアプリのリポジトリを探す.
2. zip をダウンロードする.
3. それを展開する.
4. AndroidStudio などIDEを開く.
5. インポートする.
6. Gradle が sync する.
7. プロジェクトを run.
8. 実行するデバイスを選択する.
9. 実際に動かしてみる.
10. zipファイルとプロジェクトフォルダを捨てる.

となりますが,「dryrun」をインストールすると

$ gem install dryrun
...
$ dryrun -h
Usage: dryrun GITHUB_URL [OPTIONS]

Options
    -m, --module MODULE_NAME         Custom module to run
    -p, --path PATH                  Custom path to android project
    -h, --help                       Displays help
    -v, --version                    Displays version

dryrun: Try the demo project of any Android Library

リポジトリのURLのみでターミナルからの一行で起動までが可能になります. AndroidStudioなどIDEは起動しなくてよいです.

プロジェクトディレクトリは残りません.

$ dryrun https://github.com/cesarferreira/android-helloworld

usage_v2

cesarferreira_dryrun__Try_the_demo_project_of_any_Android_Library

アプリ起動後, 動かしてみて, いらなくなったらターミナル出力の最終行に表示されているadbコマンドでアンインストール.

...
> If you want to remove the app you just installed, execute:
adb uninstall github.cesarferreira.helloworld

あなたのマシンには試したテストアプリの不要なプロジェクトディレクトリがたくさんありませんか?

man は長すぎるので「tldr」


Android Studio 使えるエディタのテーマを「Color Themes」

IDEのエディタのテーマ集があります.

Color_Themes

Color_Themes 2

Color_Themes

Color Themes

ダウンロードしてインポートするだけ.

How to install a theme?

Select «File» → «Import Setting» from the main menu and follow the instructions. After the IDE restarted go to the Preferences, expand «Editor» → «Colors and fonts» tab and choose the installed theme.

IntelliJ IDEA に使えるということで AndroidStudio でも使えます.

Which IDEs are supported?

Themes on this site support fully all family of JetBrains' IDEs: IntelliJ IDEA, PhpStorm, PyCharm, RubyMine, WebStorm and AppCode.

y-a-r-g/color-themes


Android世界有名技術系タレントたちのブログをまとめて取得する

どうしても日本語の記事では量が少なく, 更新タイミングも少し遅くなる.

こんな有名なタレント群のブログをまとめてくれています.

ziem_android-development-blogs

ziem/android-development-blogs

OPMLやCSVでダウンロードできるのでRSSリーダやその他クライアントで一括で取り込んで読みましょう.

RSSフィード情報をOPML形式でインポート/エクスポートする | feedlyの使い方 | ぼくらのハウツーノート

私の Feedly はこんなんなりましたけど.

Android_Development

しかしこの人たちはすごいなあ.

あの「Hacker News」で ベストなストーリーを見つける方法


Android Data Binding は いつ実力を発揮できるのだ?!

Data_Binding_Guide___Android_Developers

Data Binding Guide | Android Developers

たくさん記事を見かけるようになったのでかんたんに比較してみようかと思い.

20160104-195007

これまで

public class MainActivity extends AppCompatActivity {

  private TextView name;
  private TextView age;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    name = (TextView) findViewById(R.id.name);
    age = (TextView) findViewById(R.id.age);

    User user = new User("ジョーンズ", 30);

    name.setText(user.name);
    age.setText(String.valueOf(user.age));
  }

  public void onClickName(View v) {
    Toast.makeText(this, " 名前をクリックしました。", Toast.LENGTH_SHORT).show();
  }

}
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickName"
        />
    <TextView
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
 </LinearLayout>

ButterKnife

dependencies {
 	...
    compile 'com.jakewharton:butterknife:7.0.1'
}
public class MainActivity extends AppCompatActivity {

  @Bind(R.id.name) TextView name;
  @Bind(R.id.age) TextView age;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    ButterKnife.bind(this);

    User user = new User("ジョーンズ", 30);

    name.setText(user.name);
    age.setText(String.valueOf(user.age));
  }

  @OnClick(R.id.name)
  public void onClickName(View v) {
    Toast.makeText(this, " 名前をクリックしました。", Toast.LENGTH_SHORT).show();
  }

}
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
 </LinearLayout>

Data Binding

android {
	...
    dataBinding {
        enabled = true
    }
}
public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MainActivityBinding binding = 
         DataBindingUtil.setContentView(this, R.layout.main_activity);

    User user = new User("ジョーンズ", 30);

    binding.setUser(user);
    binding.setActivity(this);
  }

  public void onClickName(View v) {
    Toast.makeText(this, " 名前をクリックしました。", Toast.LENGTH_SHORT).show();
  }

}
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="user"
            type="com.example.User"/>
        <variable
            name="activity"
            type="com.example.MainActivity" />
    </data>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{user.name}"
            android:onClick="@{activity.onClickName}"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{String.valueOf(user.age)}"
            />
    </LinearLayout>
</layout>

むむむ...

レイアウトを繰り返し使うような ListView/RecyclerView で実力を発揮するのかな?

This is more than binding simple data to your views and avoiding the boilerplate code. To me, this is actually mixing business logic in your UI layouts. Your views should be as dumb as possible, adhering to the Single Responsibility Principle with the only responsibility to show data. This could lead to a complicated, cluttered and unclean codebase.

We've seen some of the examples of the Data Binding API. I'm sure that this API was created in order to ease the developers' work and avoid boilerplate, but one can overuse it and accidentally create chaos in his code. Mixing Java in your view code has never been a good idea. Does JSP ring a bell?

How you can go wrong with the new Data Binding API

強力な分だけ「用法・用量」に注意, ということなのか.

ちなみに AndroidStudio最新環境では build.gradle 内 dataBinding { enabled = true } のみで使えるようになっておる.

Data Binding Guide | Android Developers