2015年5月11日月曜日

全画面の Toast を表示する

Gravity の FILL_HORIZONTALFILL_GRAVITY を指定します。
private void showFullscreenToast(Context context, String message) { TextView tv = new TextView(context); tv.setText(message); tv.setTextColor(Color.WHITE); tv.setBackgroundColor(Color.parseColor("#99000000")); tv.setGravity(Gravity.CENTER); Toast toast = new Toast(context); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL, 0, 0); toast.setView(tv); toast.show(); }

対応するToastクラスのコードは以下になります。

http://tools.oesf.biz/android-5.0.1_r1.0/xref/frameworks/base/core/java/android/widget/Toast.java#400 400 if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) { 401 mParams.horizontalWeight = 1.0f; 402 } 403 if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) { 404 mParams.verticalWeight = 1.0f; 405 }


2015年4月11日土曜日

DroidCon Montreal に行ってきました。



DriodCon Japan 開催をもくろむ mhidaka と共に視察(半分観光)として DroidCon Montreal に行ってきました。

DroidCon Montreal

カナダで最初のDroidConということで、Welcome talk では Toronto じゃなくて Montreal だぜ、いぇい、というのりでした。
朝食と昼食が出たのですが、ホテルの朝食よりおいしかったです。
9時スタートに来てもらうには朝食は必須ですね。



セッションメモ

Keynote - An Open Source Advantage
Jake Wharton & Jesse Wilson (Square Inc.)

セッションスライド
https://speakerdeck.com/swankjesse/an-open-source-advantage-droidcon-mtl-2015

二人が交互に話すスタイルだった
オープンソースの利点と運営(メンテナンス)についての話
say no (nicely) が大事



Building First Class SDKs
Ty Smith (Twitter)

セッションスライド
https://speakerdeck.com/tysmith/droidcon-montreal-building-first-class-sdks-a-fabric-case-study



A Few "OK" Libraries
Jake Wharton (Square Inc.)

セッションスライド
https://speakerdeck.com/jakewharton/a-few-ok-libraries-droidcon-mtl-2015

OkHttp, Retrofit, Moshi で利用すべく、dataのinput/ouputのライブラリである
Okio https://github.com/square/okio を作ったという話

java.io.*の使いにくさについて滔々と語る
複数のコンセプトが含まれていて振る舞いに一貫性がないAPIは使いにくいし、わかりにくい

Okio は java.io.*, java.nio.*を補完するもので、主な interface は Source と Sink
Source の read() メソッドは1種類だけでシンプル
Source と Sink を継承した BufferedSource と BufferedSink が用意されており、これらを実装したクラスとして Buffer が用意されている

例えば File file = // ... Sink fileSink = Okio.sink(file); Sink gzipSink = new GzipSink(fileSink); BfferedSink bufferedSink = Okio.buffer(gzipSink); bufferedSink.writeUtf8("Hello, hello, hello!"); bufferedSink.close(); とすると、"Hello, hello, hello!" を gzip ものがファイルに書き込まれる File file = // ... Sink fileSink = Okio.sink(file); Sink gzipSink = new GzipSink(fileSink); Sha1Sink hashingSink = new Sha1Sink(gzipSink); BfferedSink bufferedSink = Okio.buffer(gzipSink); bufferedSink.writeUtf8("Hello, hello, hello!"); bufferedSink.close(); のように Sha1Sink を GzipSink の前に挟むと、"Hello, hello, hello!" の Sha1 を gzip したものがファイルに書き込まれる

OkHttp の RequestBody には void writeTo(Buffered sink) というメソッドがあり ResponseBody には BufferedSource source() というメソッドがある

Moshi は Okio を利用した JSON のライブラリ
streaming 用には JsonReder / JsonWriter を使う
JsonWriter writer = new JsonWriter(sink); JsonReader reader = new JsonReader(source); オブジェクトへのマッピングは JsonAdapter を使う
ちなみに reflection ベース

Retrofit の Converter として MoshiConverter を指定できる



HTTP in a Hostile World
Jesse Wilson

セッションスライド
https://speakerdeck.com/swankjesse/http-in-a-hostile-world-droidcon-mtl-2015

https://bugsnag.com/



Debug Builds: A New Hope
Matt Precious (Square Inc.)

セッションスライド
https://speakerdeck.com/mattprecious/debug-builds-a-new-hope-droidcon-mtl-2015

Daggerとか使って、Endpoints とかパラメータをいろいろ変えられるデバッグ用画面を作る話
つまり U+2020 の説明
https://github.com/JakeWharton/u2020

アプリケーションプロセスを再スタートさせるtips
デバッグビルドで根本的な状態(staging から production に変えるとか)を変えるためにだけ利用すべし
ProcessPhoenix.triggerRebirth(getContext()); ProcessPhoenix.java
https://gist.github.com/JakeWharton/9404647aa6a2b2818d22

Charles
http://www.charlesproxy.com/

スクリーンショット付きのバグレポートを簡単に作れるライブラリ Telescope https://github.com/mattprecious/telescope

つまり、U+2020 を Fork すべし!



Transition Your Development
Kevin Grant(Tumblr)

セッションスライド
(まだ見つからなかった)

前半はわりとトランジション・アニメーションの概念的な話

後半はコードも出てきた
ViewTreeObserver.addOnPreDrawListener() 使って animation のトリガーにするのは ugly だからダメ絶対

Tumblr で、Likeボタンのアニメーションあり、なし、でどっちがより LikeしてくれるかABテストしたけど、50%、50%で違いがなかったそうだ

Lollipop の Dialer のアニメーションのサンプル作ったので参考にしてねとのこと
https://github.com/kevinthecity/DialerAnimation



getBounds(), the Drawable Story
Jamie Huson, Lisa Neigut (Etsy)

内容は
https://speakerdeck.com/niftynei/getbounds-the-story-of-drawables-and-their-view-masters
とだいたい同じ

CustomDrawable の作り方の話

Devoxx 2013 での Cyril Mottier のセッションが参考になる
https://speakerdeck.com/cyrilmottier/mastering-android-drawables



Mastering Recyclerview Layouts
Dave Smith (NewCircle, Inc.)

セッションスライド
http://www.slideshare.net/devunwired/mastering-recyclerview-layouts

RecyclerView の基本的な使い方
GirdLayoutManagerで各位置の span size を変えるとか

RecylerView Playground
https://github.com/devunwired/recyclerview-playground

Building a RecyclerView LayoutManager
http://wiresareobsolete.com/2015/02/recyclerview-layoutmanager-redux/

Android SDK Reference
http://developer.android.com/training/material/lists-cards.html



Recipes for a Solid Foundation
Eric Cochran (IFTTT)

セッションスライド
(まだ見つからなかった)

1ActivityでFragmentの管理よろしくしてくれるライブラリ作ったそうだ
https://github.com/nightlynexus/dire



Introduction To Functional Reactive Programming On Android
Juan Gomez (Netflix)

セッションスライド
https://speakerdeck.com/juandg/intro-to-functional-reactive-programming-droidcon-mtl-2015

Introductionな話
RxJava は Started at Netflix
図がわかりやすかった

https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables



Gotta Persist 'Em All: Realm As Replacement fo Sqlite
Siena Aguayo (Indiegogo)

セッションスライド
http://www.slideshare.net/SienaAguayo/gotta-persist-em-all-realm-as-replacement-for-sq-lite-46956020

Realm を使ってポケモンデータをあれこれする話
このお姉さんは Pokemon Master
スライドにも随所にポケモンがでてきた
(キレイハナ、ダストダス、ラティアス、ラティオス、フーディン、フシギダネ、ミロカロス)
フシギダネは bulbasaur と言うそうだ



DroidCon Japan?

日本でDroidConを開催したらJakewhartonが来てくれるかもしれない。がんばれ mhidaka





おまけ

モントリオールはフランス語圏(フランス語圏としてはパリについで2番目の経済圏らしい by roishi情報)なので 町中の表示がみんなフランス語でした。SORTIE は exit のことだということを覚えました。

ノートルダム大聖堂にも行きました(入場料5$)。昼の12時には鐘がなっていました。



マリー・レーヌ・デュ・モンド大聖堂にも行きました(入場料無料)。


2015年3月10日火曜日

Material Design Color メモ

Componentsalphacolorcolor resource
text87%#000000#de000000
subheader54%#000000 or primary color#8a000000
hint50%#000000#80000000
divider12%#000000#1f000000


EditText
statealphacolorcolor resource
error100%#f44336#fff44336
hint text26%#000000#43000000



ちなみに colors_material.xml では次のように定義されている <color name="primary_text_default_material_light">#de000000</color> <color name="secondary_text_default_material_light">#8a000000</color>