Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Support Library v23.2 overview

Support Library v23.2 overview

shibuya.apk #6で発表した内容です

Takahiro Shimokawa

March 16, 2016
Tweet

More Decks by Takahiro Shimokawa

Other Decks in Programming

Transcript

  1. Support Library
    v23.2 overview
    @androhi 1

    View Slide

  2. About me
    4 Zaim Inc.
    4 GitHub / Twitter / Qiita
    4 @androhi
    4 DroidKaigi 2016 staff & speaker
    @androhi 2

    View Slide

  3. Agenda
    4 v23.2ͷτϐοΫ
    4 RecyclerViewͷࣗಈαΠζௐ੔ػೳ
    @androhi 3

    View Slide

  4. v23.2ͷτϐοΫ
    1. VectorDrawableͷαϙʔτ
    4 Ξχϝʔγϣϯ෇͖͸Ұ෦੍ݶ͋Γ
    2. AppCompatͷDayNightςʔϚ
    3. BottomSheetͷαϙʔτ
    4. ΧελϜλϒʹϘτϜόʔͷ௥Ճ
    5. AndroidTVͷLeanbackڧԽ
    @androhi 4

    View Slide

  5. VectorDrawable ͷαϙʔτ
    4 VectorDrawableରԠ·ͱΊ @konifar
    4 AppCompat v23.2 — Age of the vectors
    @androhi 5

    View Slide

  6. DayNight ςʔϚͷ௥Ճ
    <br/>...<br/>
    // ΞϓϦશମʹઃఆ
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    // Activity΍Dialog୯ҐͰઃఆ
    AppCompatDelegate delegate = getDelegate();
    delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    @androhi 6

    View Slide

  7. BottomSheet ͷαϙʔτ
    4 αϙʔτϥΠϒϥϦ @yuichi_araki
    4 BottomSheetBehaviorΛ࢖͏
    @napplecomputer
    @androhi 7

    View Slide

  8. ΧελϜλϒͷϘ
    τϜόʔ
    ※ chrome v49 Ҏ্
    @androhi 8

    View Slide

  9. ΧελϜλϒͷϘτϜόʔ
    // VectorDrawableͰ΋େৎ෉ʂ
    Bitmap icon1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_room_24dp);
    Bitmap icon2 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_favorite_24dp);
    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
    .setToolbarColor(getResources().getColor(R.color.colorPrimary))
    .setSecondaryToolbarColor(getResources().getColor(R.color.colorPrimary))
    // ௥ՃͰ͖Δͷ͸4ݸ·ͰɻͦΕҎ্͸IllegalStateException
    .addToolbarItem(1, icon1, "description1", pendingIntent)
    .addToolbarItem(2, icon2, "description2", pendingIntent)
    .build();
    customTabsIntent.launchUrl(this, Uri.parse("http://zaim.net"));
    @androhi 9

    View Slide

  10. Leanback ڧԽ
    4 GuidedStepFragment ͷେ෯ͳվળ
    4 ࠓճ͸ࢼͤ·ͤΜͰͨ͠...
    @androhi 10

    View Slide

  11. RecyclerViewͷ
    ࣗಈαΠζௐ੔ػೳ
    @androhi 11

    View Slide

  12. WRAP_CONTENT ͷ༗ޮԽ
    RecyclerView ΛίϯςϯπͷαΠζʹԠͯ͡α
    ΠζมߋͰ͖ΔΑ͏ʹͳΓ·͢ɻͭ·ΓɺҎલ͸
    Ͱ͖ͳ͔ͬͨ RecyclerView ͷੇ๏஋ʹ
    WRAP_CONTENT Λ࢖༻͢Δ͜ͱ͕Ͱ͖ΔΑ͏
    ʹͳ͍ͬͯ·͢ɻ
    — Google Developers Japan
    @androhi 12

    View Slide

  13. activity.xml

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff0000"/>
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/recycler_view"
    android:background="#00ff00"
    android:text="Test"/>

    @androhi 13

    View Slide

  14. list_item.xml

    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    android:id="@+id/list_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

    @androhi 14

    View Slide

  15. @androhi 15

    View Slide

  16. @androhi 16

    View Slide

  17. ΋͜͠Μͳ list_item.xml ͩͬͨ
    Β...

    android:layout_width="match_parent"
    android:layout_height="match_parent">
    android:id="@+id/list_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

    @androhi 17

    View Slide

  18. @androhi 18

    View Slide

  19. v23.1 -> v23.2 ͷΞοϓσʔτ
    RecyclerView ͷ࢖༻Օॴ͸ཁ஫ҙ
    @androhi 19

    View Slide

  20. LayoutManager ͷมߋ
    ϏϧτΠϯͷ LayoutManager ΛܧঝͤͣɺΧε
    λϜͷ LayoutManager Λ࢖༻͍ͯ͠Δ৔߹ɺ͜
    Ε͸ΦϓτΠϯ API ʹͳΓ·͢ɻ
    setAutoMeasureEnabled(true) Λݺͼग़͠ɺ
    ϝιουͷ Javadoc ʹৄ͘͠هࡌ͞Ε͍ͯΔͱ
    ͓Γɺࡉ͔ͳมߋΛՃ͑Δඞཁ͕͋Γ·͢ɻ
    — Google Developers Japan
    @androhi 20

    View Slide

  21. LayoutManager#setAutoMeasureEn
    abled(boolean)
    ϨΠΞ΢τͷଌఆ( onMeasure )Λɺ
    RecyclerView ͕ߦ͏( =true )ͷ͔
    LayoutManager ͕ߦ͏( =false )ͷ͔Λఆٛ͢
    Δϝιουɻ
    -> RecyclerView ͕ଌఆ͢Δ৔߹͸ɺࢠͷཁૉ͔
    ΒαΠζΛࣗಈܭࢉ͢Δɻ
    @androhi 21

    View Slide

  22. v23.1 ͷ LinearLayoutManager
    // Constructor
    public LinearLayoutManager(Context context, int orientation,
    boolean reverseLayout) {
    setOrientation(orientation);
    setReverseLayout(reverseLayout);
    }
    @androhi 22

    View Slide

  23. v23.2 ͷ LinearLayoutManager
    public LinearLayoutManager(Context context, int orientation,
    boolean reverseLayout) {
    setOrientation(orientation);
    setReverseLayout(reverseLayout);
    setAutoMeasureEnabled(true);
    }
    @androhi 23

    View Slide

  24. LayoutManager ΛΧελϜͯ͠Δ
    ͳΒ
    onMeasure Λ override ͍ͯ͠Δ৔߹͸ɺΧε
    λϜ LayoutMnagerͷதͰ
    setAutoMeasureEnabled(false) ΛݺͿɻ
    @androhi 24

    View Slide

  25. ·ͱΊ
    4 VectorDrawable αϙʔτ࠷ߴ
    4 RecyclerView ͸ཁ஫ҙ
    @androhi 25

    View Slide