API-19 と 20+ 間を Material Design でどう跨いでいけばいいのか

Introduction_-_Material_design_-_Google_design_guidelines

とりあえず公式をみてみる.

* テーマの設定

1. Holoのようなこれまでのテーマを継承して定義する
res/values/style.xml

2. 同じ名前でテーマをMaterialテーマを継承して定義する.
res/values-v21/style.xml

3. これらのテーマを AndroidManifest.xmlでアプリに設定する.

* レイアウトの設定

21+向けのディレクトリをそれぞれ準備する
res/layout-v21/
res/values-v21/

API-21+ に対しては, 各リソースファイルを「*-v21」として新規に作成するという考え方.

これまでのUIデザインを変化させずに, 新しく OS 5.0+ の端末に対してのみマテリアルなデザインを表示させる.

その後にこう書いてる.

* サポートライブラリをセット

Theme.AppCompat を使えば いくつかのウィジェットは MaterialDesign のものを使える.

dependencies {
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
}

EditText
Spinner
CheckBox
RadioButton
SwitchCompat
CheckedTextView
RecyclerView
CardView
Palette

完全ではないもののいくつかのウィジェットは appcompat-v7 で対応できる.

Lollipopを載せた端末の拡散具合や人気を考えると, OS4.x系端末でのマテリアルデザイン表示をしないと「マテリアルデザインに対応します(しました)」とうたいづらい.

よほどUIが凝ったアプリで無い限り, この appcompat-v7 ウィジェットを使って, これまで(API-19まで)のテーマに適用する, まずは.

/res/values/styles.xml

...
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...

とこれまでのテーマの親にもつ.

このあと, 微調整を行い, API-19までのUIをマテリアルなかんじに仕上げていき, そのあと *-v21 のリソースを触りながら, 気にせず Lollipop端末に向けてのマテリアル化を進めていく.

と, そんな順序が王道ではないかな...

Maintaining Compatibility | Android Developers


Android 5.0 (Lollipop) MaterialDesign を構成するGoogle発UI系サンプル動画 40個くらい

すべては, 以下にあるやつ今現在最新のサンプルUI系をLollipopで動かす.

Google_Samples

Google Samples

AndroidStudio の ImportSample のプレビューが表示されないので並べて置くと何かと便利かななどと思い.

AndroidStudio

パーツやふるまいの名前が分かればそれで良かったのでYouTubeのGIF書き出しでやろうかと思いましたが, 一般公開間近の非公開ステータス.

GIF_Beta_sign_up

Nexus6でやってます.

こんな感じで40個くらい.

以下から順不同で.

続きを読む >>


でかすぎる Google Play Services が 6.5.87 で分割された件

Androidアプリでメソッド数が65536を超える場合は少し手間が掛かっていました.

Androidでメソッド数が65536を超えた時の対処方法 - Qiita

GoogleAnalyticsやGoogleMapなどを利用できるライブラリ com.google.android.gms:play-services ですが、実は使っている機能は1つか2つということが多いのではないでしょうか。
com.googleは18513個もメソッドがあるので、これを節約するだけでかなりメソッドの数が減ります。

このよく言われている「com.google.android.gms:play-services」がでかすぎという話.

必要なものだけピックアップして使えるようになったようです.

Setting_Up_Google_Play_Services___Android_Developers

Setting Up Google Play Services | Android Developers

自動で, com.google.android.gms:play-services-base:6.5.87 が読み込まれたりするし, どれを使うべきなのかわかりづらいようなものもあるように思えたり.

あと, 公式ドキュメントや AndroidStudio の自動チェックで, 「推奨」から「非推奨」と言われ始めたバージョン記述「+」で書かれていたり.

compile 'com.google.android.gms:play-services:6.5.+'

compile 'com.google.android.gms:play-services-fitness:6.5.+'
compile 'com.google.android.gms:play-services-wearable:6.5.+'

これらの「+」記述は, 最新 Android Studio 1.0 でも警告される.

version

こう書いてるけど.

At the time of writing, the correct version to use is 6.5.87. As this is a very granular number, it will get updated quite quickly, so be sure the check the latest version when you are coding. Often people will use a ‘+’ to denote versions, such as 6.5.+ to use the latest 6.5 build. However, it’s typically discouraged to use a ‘+’ as it can lead to inconsistencies.

でも, やっぱり「+」は怖くないですか.

Google Play services and DEX method limits | Android Developers Blog


みんながちがうから, 世界は楽しいの「Androidify」を壁紙にする

最近, テレビでもCMやってます.

Androidify

Androidify

Androidify

自分の好みのパーツを組み合わせて, かわいいのか, ゆるキャラっぽいような, そうでもないような, 微妙なキャラを作ったりできます.

Androidify - Google Play の Android アプリ

そんな「Androidify」な無料壁紙アプリを入れてみました.

触ると反応して動きます.

20141104-162547

20141104-163544

20141104-162456

以下からダウンロードなどどぞ.

https://svg-android.googlecode.com/files/svgwallpaper.apk

微妙ですが, 色目がきれいですし.

ちと, よりすぎなんだよな...


マテリアル・デザインのアイコンセットを使いやすい配置に変える

たくさんの画像リソースが公開されています.

Material_Icons_Index

【使える! 即保存】 github で公開されている Material design icons 一覧

どれもいいかんじです.

で, これ一覧で好きなアイコンを選んだあと,

zipをダウンロード/展開したあとどれを使ったらいいのか.

たとえば, 一覧で「error」アイコンを使おうとすると

こんなにある.

./alert/drawable-hdpi/ic_error_black_18dp.png
./alert/drawable-hdpi/ic_error_black_24dp.png
./alert/drawable-hdpi/ic_error_black_36dp.png
./alert/drawable-hdpi/ic_error_black_48dp.png
./alert/drawable-hdpi/ic_error_grey600_18dp.png
...(略)...
./alert/drawable-xxxhdpi/ic_error_red_48dp.png
./alert/drawable-xxxhdpi/ic_error_white_18dp.png
./alert/drawable-xxxhdpi/ic_error_white_24dp.png
./alert/drawable-xxxhdpi/ic_error_white_36dp.png
./alert/drawable-xxxhdpi/ic_error_white_48dp.png

ディレクトリの構造はこんなかんじになってる.

material-design-icons-master
├── action
│   ├── drawable-hdpi
│   │   ├── ic_error_red_18dp.png
│   │   ├── ic_error_red_24dp.png
│   │   ├── ic_error_red_36dp.png
│   │   ├── ic_error_red_48dp.png
│   ├── drawable-mdpi
│   ├── drawable-xhdpi
│   ├── drawable-xxhdpi
│   ├── drawable-xxxhdpi

アイコンファイルを選択する他に

いくつか決めなければならないことがあったりします.

・dpi
・color
・dip

「色」は見て決めれるけども...

以下を見ながら, dip(サイズ/スケール) と

対象ファイル, 新しいファイル名を決める.

Launcher ic_launcher_***.png 48dp
Action Bar ic_menu_***.png 32dp
Small/Contextual ic_***.png 16dp
Notification ic_stat_notify_***.png 24dp

Iconography | Android Developers

細かくいろいろ区別できるのだろうけど,

Android Studioのプロジェクトデフォルトdpiの構成に

drawableディレクトリはとりあえず合わせよう.

res
├── drawable-hdpi
│   └── ic_error.png
├── drawable-mdpi
│   └── ic_error.png
├── drawable-xhdpi
│   └── ic_error.png
├── drawable-xxhdpi
│   └── ic_error.png

などとシコシコ手動でやってみたがめんどうなので

zip の展開後のディレクトリ構成とファイル名を

あらかじめ変更しておけば, フォルダごと上書きできそうなので

一括でスクリプトで以下に変更しておく.

{category}/drawable-{dpi}/ic_{name}_{color}_{dip}.png
↓
{category}/{name}/{color}/{dip}/drawable-{dpi}/ic_{name}.png

<?php
/**
 Restructure dirs/files tree.
 
https://github.com/google/material-design-icons
 
Usage:
 
$ curl -LO https://github.com/google/material-design-icons/archive/master.zip
$ unzip material-design-icons-master.zip
$ ls
... material-design-icons-master ... 
$ php restructure.php
 
{category}/drawable-{dpi}/ic_{name}_{color}_{dip}.png
-> {category}/{name}/{color}/{dip}/drawable-{dpi}/ic_{name}.png
 
 
~/material-design-icons-master_new $ tree . 
.
├── action
│   ├── 3d_rotation
│   │   ├── black
│   │   │   ├── 18dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xxhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   └── drawable-xxxhdpi
│   │   │   │       └── ic_3d_rotation.png
│   │   │   ├── 24dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
...
*/
 
foreach (glob('material-design-icons-master/*/*/*.png') as $file) {
  if (is_file($file) && preg_match('@/drawable@', $file)) {
    $path_parts = pathinfo($file);
    $filename = $path_parts['filename'];
    $dirs = explode('/', $path_parts['dirname']);
    $category   = $dirs[1];
    $dip        = substr($filename, strrpos($filename, '_') + 1);
    $dpi        = substr($dirs[2], strpos($dirs[2], '-') + 1);
    $filename   = substr($filename, 0, strpos($filename, '_' . $dip));
    $name_color = substr($filename, strpos($filename, '_') + 1);
    $color      = substr($name_color, strrpos($name_color, '_') + 1);
    $name       = substr($name_color, 0, strpos($name_color, '_' . $color));
    $path = sprintf('%s_new/%s/%s/%s/%s/drawable-%s/ic_%s.png',
                    $dirs[0], $category, $name, $color, $dip, $dpi, $name);
    mkdir(dirname($path), 0777, true);
    copy($file, $path);
    echo $file . "\n";
    echo '-> ' . $path . "\n";
  }
}

ディレクトリ構成を変更 - gist

構成変更後はこんなかんじに.

~/material-design-icons-master_new $ tree . 
.
├── action
│   ├── 3d_rotation
│   │   ├── black
│   │   │   ├── 18dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xxhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   └── drawable-xxxhdpi
│   │   │   │       └── ic_3d_rotation.png
│   │   │   ├── 24dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
...

こうしておけば,

使いたいアイコンの色, 利用場所(dip) を考えながら,

GUI上でディレクトリごと上書きで,

IDE上の res ディレクトリ以下にコピーすればよい.

icon_copy

よくみると, IDE側の drawable-*** のディレクトリ名は微妙に違ってたりするが(笑)