heihei blog

Blog icon by Unsplash https://unsplash.com/@virussinside

2018年12月を振り返る

2018年も残りあと数時間です。

それでは、12月を振り返ります!

12月やったこと

社内では、内定者アルバイトのAndroidエンジニアがチームにジョインしたり、職種ごとに定めた技術戦略を推進する日を設けてエンジニア全員で取り組んだり。

プロダクトとしては、アプリがGoogle Playフィーチャー枠に掲載されたりと、いろいろな嬉しいことがありました。

プロダクト開発では、大きめの機能開発に携わせてもらうこととなり、モックを作り始めたところです。来年頭は、こちらにさらに注力します。

そのほか、休日などは、代々木公園にある青の洞窟に行ったり、

GooglePixelコラボのカフェに行ってみたりしました。

「Search」という映画も見ました。噂通り、映画の内容すべてがPC画面上に映されるような描写となっていて斬新だなと思いました。斬新さだけではなくて、内容も申し分なく面白くてよかったです。また観たい。

www.youtube.com

そして今は、引っ越して初めてテレビをつけて、ふるさと納税のお礼品を堪能しながら、ガキ使を見てのんびりしています。

12月内容あんまり濃くないけど、こんな感じでした!(雑)

皆様、師走もお疲れ様でした!!🐗

Notes - Fun with LiveData (Android Dev Summit '18)

※Notes記事では、英語のセッション動画やポッドキャストの内容を(雑に)英語でメモに書き残すことを行っています。本記事は、あくまで動画を見ながら、参考程度に読んでいただくことを想定しています。Notes記事には雑メモ程度のものだったり、書き起こしのようなものもあります。これから実際の動画を見る際には、本記事の内容が少しでもお役に立てば幸いです。(内容において不備、誤字脱字等ありましたら気軽にご連絡いただけると嬉しいです。)

本記事は、Fun with LiveData (Android Dev Summit '18)の記事です。

f:id:shaunkawano:20181216213849p:plain

LiveData

Simple

Lifecycle-aware

  • In order to observe LiveData you need to provide lifecycle
  • LiveData is going to remove subscription on appropriate lifecycle event, for free

Observable

  • Activity and other view components have different lifecycle
  • Even Activity, when rotation changed, gets recreated and if some components have a reference to this activity then it leads to memory leak or worst, crash with NPE

=> Instead of letting something have reference of Activity, letting Activity observe live data is safe.

Data Holder

  • Live data is not a stream, data holder
  • If you want some stream concept use Rx

Transformations

  • If you use LiveData and ViewModel, you totally need to have transformations

Antipatterns

  • Storing big objects across Transformations
  • Sharing instances of LiveData
class SharedLiveDataRepository(val dataSource: MyDataSource) {
  private val result = MutableLiveData<Long>()

  fun loadItem(itemId: String): LiveData<Long> {
    result.value = dataSource.getData(itemId)
    return result // here we share the `result` LiveData
  }
}
  • Edge case: Activity Transitions
    • Two activities are active at the same time
    • If your class is a repository and you are creating a field of LiveData then maybe you are doing something wrong

When NOT to use LiveData

  • If you need a lot of operators or streams, use Rx.
  • If your operations are not about UI or lifecycle, use callback interfaces
  • If you have one-shot operation chaining, use coroutines

📝

  • LiveDataはデータホルダーなのでメモリに保持したくないようなオブジェクトは渡すべきではない
  • オペレーターやストリームの概念が必要なのであればRxJavaなどのリアクティブのコンセプトに特化したライブラリを使うべき
  • LiveDataのインスタンス共有は、(2つのAcitvity内のLiveDataが同時にActiveになる可能性があるため)極力避ける。そのような場合は都度、新しいLiveDataを生成。LiveDataの生成はそこまで重たい処理ではない。

Notes - Get Animated (Android Dev Summit '18)

※Notes記事では、英語のセッション動画やポッドキャストの内容を(雑に)英語でメモに書き残すことを行っています。本記事は、あくまで動画を見ながら、参考程度に読んでいただくことを想定しています。Notes記事には雑メモ程度のものだったり、書き起こしのようなものもあります。これから実際の動画を見る際には、本記事の内容が少しでもお役に立てば幸いです。(内容において不備、誤字脱字等ありましたら気軽にご連絡いただけると嬉しいです!m(__)m)

本記事は、Get Animated (Android Dev Summit '18)に関する記事です。

f:id:shaunkawano:20181216212636p:plain

Android Animation APIs

  • View Animations
  • Value Animator
  • Object Animator
  • View Property Animator
  • Transitions
  • Animated Vector Drawable
  • Physics
  • MotionLayout

android.view.animation

is now consider deprecated

  • Measure => Layout => Draw
    • android.view.animation is only applied in Draw process
  • WindowAnimation only accepts android.view.animation so it should be used only here, but otherwise consider it as deprecated
  • You may use it in FragmentTransaction
    • API also accepts Android animator so prefer animator

When to use which Animator

  • ObjectAnimator - general purpose, property animator
  • ValueAnimator - custom animation
  • ViewPropertyAnimator
    • Multiple properties on the same View
    • Fire and forget
  • PropertyValuesHolder - multiple properties on the same object
  • AnimatorSet - choreograph a set of animations

AnimatedVectorDrawable

When to use

  • Icon animation
  • Fire & forget animations
  • Performance critical

Physics

Physics-based Animation

  • Interruptible
  • Continuity
  • Realistic Look

Transitions

  • Shared element activity transitions
  • Window content enter/exit
  • Modularize animations
  • Simple changes

Motion / Animation

Helper

In ConstraintLayout 2.0, all the helpers are exposed for achieving encapsulated behaviors

  • ConstraintLayout utility
  • Apply it to a set of widgets
  • Supported in Android Studio
  • Use Animation APIs in helpers to promote reuse

E.g. Circular Reveal:

@Override
public void updatePostLayout(ConstraintLayout container) {
  super.updatePostLayout(container);
  if (mContainer != container) {
    int rad = (int) Math.hypot(mComputedMaxY - mComputedMinY, mComputedMaxX - mComputedMinX);
    Animator anim = ViewAnimationUtils.createCircularReveal(this, (int) mComputedCenterX - getLeft(), (int) mComputedCenterY - getTop(0, 0, rad);
    anim.setDuration(2000);
    anim.start();
  }
  mContainer = container;
}
<com.example.CircularRevealHelper
    android:id="@+id/helper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/lake"
    app:constraint_referenced_ids="imageView" />

MotionLayout

  • Only two states: Start to End
  • Where it shines
    • Declarative motion
    • Bespoke motion
    • Touch-driven motion

MotionLayout: Library

  • Part of ConstraintLayout 2.0
  • Released at Google IO'18
  • Built upon ConstraintLayout 1.1
  • Alpha 2

📝

  • android.view.animationはwindow animationには現状必要だが、それ以外のアニメーションには別のAPIを利用するほうが良さそう
  • 今後MotionLayoutが出てきてものすごいアニメーションを表現できるようになると思うが、既存APIとは適材適所で使い分けする必要がありそう
  • MotionLayoutの説明の部分で住友さんのツイッターアカウントが取り上げられていてめちゃ驚いた

2018年11月を振り返る

2018年もあと8%弱らしいです |←2019年| ┗(^o^ )┓三

それでは11月を振り返ります。

11月やったこと

Matching Dev Meetupを開催した

11/14(水)にMatching Dev Meetup#1 - iOS / Androidを開催しました。当日の写真などはぜひ弊社ブログにて。ブログにも記載しましたが、このイベントはsatoshin21さんとpotatotipsにてお話した際に盛り上がって開催に至ったものです。アットホームなイベントにできたらなーと思っていたので、開始前から懇親が盛り上がっていて楽しめて何よりでした。今後も継続的にやっていけたらと思っています。

弊社ブログには記載し忘れましたが、満足率は20件の回答中95%と嬉しい結果でした!

f:id:shaunkawano:20181203004117p:plain

ご参加していただいた皆様、改めてありがとうございました!

Androidテスト全書」を読み始めた

もともと本読むのが苦手なのですが、少しずつ読んでいます。今、3章まで読み終わりました。

一章の「テスト大事」という文字から溢れんばかりのメッセージがズシンときました。引き続き読む。

「The Manager's Path: A Guide for Tech Leaders Navigating Growth and Change」を読み始めた

弊社のエンジニアリングマネージャーがtimesチャンネルで勧めていたのをポチったもの。(少なくともAmazonには日本語電書籍版がなかったです。)まだ2章目入ったくらい。いまのところ真新しいことがたくさん!というよりは、どちらかというと、「そうだよね、意識しなきゃだよな。。」ということがたくさんある。すでに買ってよかった。言われてみると当たり前ってことでも意識して行動できないことたくさん。下記とかも。

Developing a sense of ownership and authority for your own experiences at work, and not relying on your manager to set the entire tone for your relationship, is an important step in owning your career and workplace happiness.


※12/3(月)追記

O'Reilly Japanのウェブサイトにて電子版が販売されているとのことです!@takasfzさん教えていただき、ありがとうございました!

www.oreilly.co.jp

その他

DroidKaigiのプロポーザルが採択された

エモ枠でがんばります!(「技術戦略」がテーマです。こういう内容ききたい!などがあればぜひお気軽にDM等でご連絡ください!!🙏)

明治神宮の銀杏並木を散策した

1−2週間前にいってきました。人がたくさんいた。。今くらいの時期が色が一番綺麗かも!

f:id:shaunkawano:20181203010630p:plain

それでは、11月もお疲れ様でした〜ヽ('∀')ノ

Notes - Modern Android Notifications (Android Dev Summit '18)

※Notes記事では、英語のセッション動画やポッドキャストの内容を(雑に)英語でメモに書き残すことを行っています。本記事は、あくまで動画を見ながら、参考程度に読んでいただくことを想定しています。Notes記事には雑メモ程度のものだったり、書き起こしのようなものもあります。これから実際の動画を見る際には、本記事の内容が少しでもお役に立てば幸いです。(内容において不備、誤字脱字等ありましたら気軽にご連絡いただけると嬉しいです!m(__)m)

本記事は、Modern Android Notifications (Android Dev Summit '18)の記事です。

f:id:shaunkawano:20181203014407p:plain

  • Respect user's settings
  • Send well-structured notification
  • Send relevant and timely notification
  • Make use of Auto-cancelling
  • Make use of Timeouts
  • No notifications that are not actionable

Notification Channels

  • Used to empower users
  • Help user categorize the notification
  • Help user customize the setting

Tips

  • Don't use only one channel
  • Don't use wrong/blocked channel

What's new in Notifications

  • API 28: New person class
// create new Person
val sender = Person.Builder().setName(name)
  .setUri(uri)
  .setIcon(icon)
  .build()

// create message with image
val message = Notification.MessagingStyle.Message("Picture", time, sender)
  .setData("image/", imageUri)

val style = Notification.MessagingStyle(sender)
  .addMessage("Check this out!", time, sender)
  .addMessage(message)
  .build()
...

val builder = Notification.Builder(this, CHANNEL_ID)
  .setSmallIcon(R.drawable.notification_icon)
  .setStyle(style) 

Tips

  • Do not auto-cancel messaging notification after sending
    • Let user swipe the notification when they finish their conversation

Digital Wellbeing

  • Overview of app usage
  • Dashboard for notification received, time spending on apps
  • To manage notifications, reduce interruptions

How are notifications counted?

=> If notifications were sent to blocked channel they are not counted, otherwise counted.

Reduce interruptions

  • Empower user

Work with Do not Disturb

  • Set category
  • Tag people
    • Add person
    • Set the URI associated with the person

Summary

Don't annoy the user. Respect them. Empower them. Delight them.

Connect them to the people they care about.

2018年10月を振り返る

2018年も85%くらいが終わったようですキャ━━━━(#゚ロ゚#)━━━━ッ!! 11/6(火)時点

10月もさくさっくと振り返ります。

10月やったこと

Android Weekend復活した

去年ごろから、海外出身の社内の先輩Androidエンジニアと二人でほっそり開催していたミートアップイベントを10月再開しました。(自分はAndroidXとはなにかについて発表しました)

もともと月1で定期的に開催できたら良いよね、と言っていたのですがお互いチームが変わったりと変化が起こるうちにいつのまにか開催できていない月が続いていました。ですが、10月から改めて再開することに。ロゴも知人のデザイナーの方が作ってくださり、かっこよい感じに。今は、多くても10人いかないくらいの小規模なミートアップという感じで、英語での先輩エンジニアと自分のLTを行ってあとは雑談だったりネットワーキングの場となっています。

ゆるく、気軽に参加できる形になっていますので、興味のある方はお気軽にご参加いただければと思います。(イベント参加についてはこちらをどうぞ)

特に下記の方にお勧めです:

  • Androidアプリ開発の知識を広げたい方
  • Androidアプリ開発の知見を共有したい方
  • 英語のリスニング・スピーキングを練習したい方(LTじゃなくても、まずは参加するだけでも多少は練習になりますよ〜)

技術書典#5にてiOS / Android本を出した

f:id:shaunkawano:20181106003646j:plain:w400

サイバーエージェントグループ所属の有志のiOS / Androidアプリエンジニアのメンバー6人で本を執筆しました。無事に完売できて嬉しかったです!技術書典自体は二回目の参加で、毎回、いつの間にかスケジュールに追われているという状況です。(決起会の際とかには本当にスケジュール的に余裕あるのにね〜)

前回はOkioについて、今回はPicassoについて内部実装だったりもうじきリリースされそうなPicasso 3のことについて執筆しました。

次回また応募するかはわかりませんが、もしまた執筆するとしたら、次こそはスケジュールどおりに書きたい( *゚Д゚)・;'.、グハッ!!

DroidKaigi 2019プロポーザルを提出した

「アプリをさらに成長させるための技術戦略(振り返りとこれから)」というタイトルのプロポーザルを提出しました。今、(未熟ながら)Androidチームのリーダーを任せてもらっています。もし採択された場合には、自分がAndroidチーム内で「これやってみたらいいのでは」と思って実践したことや工夫したことだったり、事業部全体で取り決めをした技術戦略などについて弊社ではこういうふうにやっていますというようなシンプルに共有だったりをできればと思っております。

また、このセッションではAndroidの技術についてメインで話すつもりはないのですが、Androidチーム内でアプリの成長を特に加速させる(させた)ような技術的な取り組み・選定・実装などについても、もし共有に値しそうなものがあれば、ぜひ共有できればと思っています。

その他

  • 秩父に旅行に行ってきた

西武秩父駅から自転車で山を駆け上りました。なお、電動自転車を選択しました。(無難)こちらの写真はその時立ち寄ったメイプルベースというおしゃれなカフェにて。

f:id:shaunkawano:20181106005359j:plain:w500

メイプルシロップどばーなフレンチトーストがとてもとても美味しかったです。

  • 引っ越しをした

今までは新宿寄りだったのですが、渋谷寄りのほうに転居。歩いて会社に出社しています。運動。会社でも最近は階段を使って移動するように意識しています。筋肉ほしい。(甘い)

10月は新しい期の始まりで、新しくジョインしたメンバーが目まぐるしく改善をしてくれていたり、チーム内の施策チームががらっと変わったり、いろんな変化があった月だったかなと思います。

11月は、11日にAndroid Weekend、そして14日にはMatching Dev Meetupという株式会社エウレカや株式会社Diverseといったマッチング業界に携わるエンジニアを集めたイベントの第一回目を開催予定!今回はiOS / Androidの会となっています。興味のある方はぜひ奮ってご参加ください!

matching-dev-group.connpass.com

(イベントロゴは弊社デザイナーの@Dhon40作)

それでは、10月もお疲れ様でしたヽ('∀')ノ

BuildConfigを生成しないようにする方法

TL;DR

android {
  ...
  libraryVariants.all {
    it.generateBuildConfig.enabled = false
  }
}

自動生成されるBuildConfig.javaについて

Androidアプリ開発等において、プロジェクト構成をマルチモジュールの形にすることで得られるメリットは大きくなってきています。 通常、AndroidプロジェクトををビルドするとBuildConfig.javaというファイルが自動で生成されます。(R.javaというリソースIDの一覧を保持するファイルも生成されます。)

BuildConfig.javaには、通常下記のような記述がされています。

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.shaunkawano.blog.sample";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";

BuildConfigを生成しないようにする方法

BuildConfigファイルには設定によって独自の定数を追加することができます。が、そのような定数を保持するBuildConfigファイルはプロジェクト内で一つ存在すれば良さそうです。また、マルチモジュールを構成するようなライブラリモジュール内のBuildConfigファイルに動的な定数値が定義されていることも稀です。つまり大半の場合はライブラリモジュールのBuildConfigファイルは不要であることが多いです。

ライブラリモジュールのBuildConfigファイルを生成しないようにするには、ライブラリモジュールのbuild.gradleに下記の設定を記述します:

android {
  ...

  libraryVariants.all {
    it.generateBuildConfig.enabled = false
  }
}

参考

メモ程度ですが、以上です。