Slide 1

Slide 1 text

Support Library total review Takahiro Shimokawa ( @androhi ) 1 DroidKaigi 2016

Slide 2

Slide 2 text

I am ... • engineer at Zaim Inc. • DroidKaigi 2015 & 2016 staff • DroidKaigi 2015 & 2016 speaker 2 DroidKaigi 2016

Slide 3

Slide 3 text

Previous DroidKaigi on April 25, 2015 3 DroidKaigi 2016

Slide 4

Slide 4 text

Previous DroidKaigi on April 25, 2015 4 DroidKaigi 2016

Slide 5

Slide 5 text

Support Library? The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs. — Android Developers 5 DroidKaigi 2016

Slide 6

Slide 6 text

Chronicle-1 The release date of android OS and the number of Support Library1 1 Reference: Android developers - API Levels and Android version history. 6 DroidKaigi 2016

Slide 7

Slide 7 text

7 DroidKaigi 2016

Slide 8

Slide 8 text

Chronicle-2 Interval of updates2 2 Reference: Android Developers - Support Library Revisions. 8 DroidKaigi 2016

Slide 9

Slide 9 text

9 DroidKaigi 2016

Slide 10

Slide 10 text

Why does it need? In order to implement the function across different API level. 10 DroidKaigi 2016

Slide 11

Slide 11 text

11 DroidKaigi 2016

Slide 12

Slide 12 text

What can we do? 1. We can better implementation. (Not the best) • e.g. Use of RxJava 2. We can easily implement a user interface that Google is recommended. • e.g. Implementation of Material design 12 DroidKaigi 2016

Slide 13

Slide 13 text

Sorry, exclude these today. • Android Testing Support Library • Data Binding Library 13 DroidKaigi 2016

Slide 14

Slide 14 text

V series • v4 Support Library • v7 Support Library • v8 Support Library • v13 Support Library • v14 Preference Support Library • v17 Preference Support Library • v17 Leanback Library 14 DroidKaigi 2016

Slide 15

Slide 15 text

v4 Support Library • Android 1.6 (API level 4) and higher • With the biggest API set in Support Library • Without resouces dependencies { compile 'com.android.support:support-v4:23.1.1' } 15 DroidKaigi 2016

Slide 16

Slide 16 text

Frequently used class • Fragment • ViewPager • NotificationCompat • DrawerLayout • SwipeRefreshLayout • Loader (AsyncTaskLoader / CursorLoader) 16 DroidKaigi 2016

Slide 17

Slide 17 text

Demo: DrawerLayout • Including v7-appcompat and design support library • ActionBarDrawerToggle • NavigationView 17 DroidKaigi 2016

Slide 18

Slide 18 text

AndroidStudio Templete: Navigation Drawer Activity public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.xx, R.string.xx); drawer.setDrawerListener(toggle); toggle.syncState(); ... 18 DroidKaigi 2016

Slide 19

Slide 19 text

Demo: SwipeRefreshLayout • UI customize • setColorScheme(int... colors) 19 DroidKaigi 2016

Slide 20

Slide 20 text

The Class that I want you to remember NestedScrollView >> There is a case to be required in Design Support Library. 20 DroidKaigi 2016

Slide 21

Slide 21 text

Helpful class Many class named ʙCompat Helper for accessing features in [name of class] introduced after API level 4 in a backwards compatible fashion. 21 DroidKaigi 2016

Slide 22

Slide 22 text

Example: NotificationCompat Helper for accessing features in Notification introduced after API level 4 in a backwards compatible fashion. — NotificationCompat - Class overview 22 DroidKaigi 2016

Slide 23

Slide 23 text

// v4 Support Library Notification notification = new NotificationCompat.Builder(); .setContentTitle("Title") .setContentText("message") .setSmallIcon(R.drawable.new_mail) .build(); // android.app Notivication notification = new Notification.Builder(context); .setContentTitle("Title") .setContentText("message") .setSmallIcon(R.drawable.new_mail) .build(); 23 DroidKaigi 2016

Slide 24

Slide 24 text

v7 Support Library • Android 2.1 (API level 7) and higher • You can be included independently. • With resouces 24 DroidKaigi 2016

Slide 25

Slide 25 text

Each v7 library 1. v7-appcompat 2. v7-cardview 3. v7-gridlayout 4. v7-mediarouter 5. v7-palette 6. v7-recyclerview 7. v7-preference 25 DroidKaigi 2016

Slide 26

Slide 26 text

Frequently used library • v7-appcompat • v7-recyclerview 26 DroidKaigi 2016

Slide 27

Slide 27 text

v7-appcompat • Depend on v4-support. • Support for material design user interface implementations. dependencies { compile 'com.android.support:appcompat-v7:23.1.1' } 27 DroidKaigi 2016

Slide 28

Slide 28 text

i.e. depend on v4-support $ gradle -q dependencies app:dependencies ------------------------------------------------------------ Root project ------------------------------------------------------------ No configurations ------------------------------------------------------------ Project :app - Injects the build id used by the Fabric SDK. ------------------------------------------------------------ _debugCompile - ## Internal use, do not manually configure ## +--- com.android.support:appcompat-v7:23.0.1 (*) | +--- com.android.support:support-v4:23.0.1 (*) ... 28 DroidKaigi 2016

Slide 29

Slide 29 text

i.e support for material design implementations e.g. AlertDialog // v7-appcompat new android.support.v7.app.AlertDialog.Builder(context) .setTitle("Hi!") .setMessage("Welcome to DroidKaigi 2016.") .setNegativeButton("close", null) .show(); // android.app new AlertDialog.Builder(context) .setTitle("Hi!") .setMessage("Welcome to DroidKaigi 2016.") .setNegativeButton("close", null) .show(); 29 DroidKaigi 2016

Slide 30

Slide 30 text

30 DroidKaigi 2016

Slide 31

Slide 31 text

v7-recyclerview • There is also a case to replace the ListView of ViewHolder pattern. • It increases the degree of freedom in the display of the List format. dependencies { compile 'com.android.support:recyclerview-v7:23.1.1' } 31 DroidKaigi 2016

Slide 32

Slide 32 text

e.g. Calendar view with v7- recyclerview • Customized LayoutManager • Customized ItemDecoration 32 DroidKaigi 2016

Slide 33

Slide 33 text

Create calendar view RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.calendar_recyclerview); // appearance of the cell CalendarLayoutManager layoutManager = new CalendarLayoutManager(getActivity(), 7); recyclerView.setLayoutManager(layoutManager); // draw the separator recyclerView.addItemDecoration(new CalendarDividerItemDecoration(getActivity())); mAdapter = new CalendarAdapter(getActivity(), mCurrentYear, mCurrentMonth); mAdapter.setOnActionListener(this); recyclerView.setAdapter(mAdapter); 33 DroidKaigi 2016

Slide 34

Slide 34 text

Other v7: cardview • Support for the CardView widget. dependencies { compile 'com.android.support:cardview-v7:23.1.1' } 34 DroidKaigi 2016

Slide 35

Slide 35 text

Other v7: gridlayout • Support for the GridLayout class. dependencies { compile 'com.android.support:gridlayout-v7:23.1.1' } 35 DroidKaigi 2016

Slide 36

Slide 36 text

Other v7: palette • Add the Palette class which lets you extract prominent colors from an image. dependencies { compile 'com.android.support:palette-v7:23.1.1' } 36 DroidKaigi 2016

Slide 37

Slide 37 text

Other v7: preference • Add preference object, such as ChexboxPreference and ListPreference. • Add v4-support based PreferenceFragmentCompat class. dependencies { compile 'com.android.support:preference-v7:23.1.1' } 37 DroidKaigi 2016

Slide 38

Slide 38 text

Other v7: mediarouter • Provide MediaRouter and MediaRouteProvider class. • Google recommend using the library only in connection with Google Cast. dependencies { compile 'com.android.support:mediarouter-v7:23.1.1' } 38 DroidKaigi 2016

Slide 39

Slide 39 text

v8 Support Library • Android 2.2 (API level 8) and higher • Support for the RenderScript computation framework. defaultConfig { renderscriptTargetApi 18 renderscriptSupportModeEnabled true } 39 DroidKaigi 2016

Slide 40

Slide 40 text

What is the RenderScript?3 • High-speed drawing processing using GPU. • Not tied to a machine-architectures like AndroidNDK. 3 Reference: Android Developers - RenderScript. 40 DroidKaigi 2016

Slide 41

Slide 41 text

v13 Support Library • Android 3.2 (API level 13) and higher • Support for using the ViewPager with "android.app.Fragment". dependencies { compile 'com.android.support:support-v13:23.1.1' } 41 DroidKaigi 2016

Slide 42

Slide 42 text

v14 Preference Support Library • Support for PreferenceFragment using "android.app.Fragment". dependencies { compile 'com.android.support:preference-v14:23.1.1' } 42 DroidKaigi 2016

Slide 43

Slide 43 text

v17 Preference Support Library • Provide preference interfaces on TV devices dependencies { compile 'com.android.support:preference-leanback-v17:23.1.1' } 43 DroidKaigi 2016

Slide 44

Slide 44 text

Reference image 44 DroidKaigi 2016

Slide 45

Slide 45 text

v17 Leanback Library • Support for use the UI widgets for TV apps. • Provide the theme of Theme.Leanback. • Depend on v4-support and v7-recyclerview. dependencies { compile 'com.android.support:leanback-v17:23.1.1' } 45 DroidKaigi 2016

Slide 46

Slide 46 text

Frequently used class • BrawseFragment • DetailFragmentFragment 46 DroidKaigi 2016

Slide 47

Slide 47 text

Demo: androidtv-leanbackGitHub For me all access to local network and internet do not work with android tv emulator sdk 22 and 23. — Playback/Streaming does not work. #50 GitHub https:/ /github.com/googlesamples/androidtv-Leanback 47 DroidKaigi 2016

Slide 48

Slide 48 text

e.g. androidtv project 48 DroidKaigi 2016

Slide 49

Slide 49 text

BrawseFragment Have a dedicated listener setOnSearchClickedListener(View.OnClickListener); setOnItemViewClickedListener(OnItemViewClickedListener); setOnItemViewSelectedListener(OnItemViewSelectedListener); 49 DroidKaigi 2016

Slide 50

Slide 50 text

Speciality series • Multidex Support Library • Annotations Support Library • Design Support Library • Custom Tabs Support Library • Percent Support Library • Recommendation Support Library for TV 50 DroidKaigi 2016

Slide 51

Slide 51 text

Multidex Support Library • Building apps with multiple Dalvik Executable(DEX) files. • Without resouces 51 DroidKaigi 2016

Slide 52

Slide 52 text

What case does multidex need? If you get in such a build error... Conversion to Dalvik format failed: Unable to excute dex: method ID not in [0, 0xffff]: 65536 52 DroidKaigi 2016

Slide 53

Slide 53 text

What case does multidex need? Or that's recently... trouble writing output: Too many field references: 131000; max is 65536. You may try using --multi-dex option. 53 DroidKaigi 2016

Slide 54

Slide 54 text

How to create the multidex app? android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.0' } 54 DroidKaigi 2016

Slide 55

Slide 55 text

Optimizing multidex development builds For the development flavor, set a minimum SDK version of 21. This setting generates multidex output much faster using the ART-supported format. For the release flavor, set a minimum SDK version which matches your actual minimum support level. — from Android Developers 55 DroidKaigi 2016

Slide 56

Slide 56 text

Build configuration sample android { productFlavors { // Define separate dev and prod product flavors. dev { // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin // to pre-dex each module and produce an APK that can be tested on // Android Lollipop without time consuming dex merging processes. minSdkVersion 21 } prod { // The actual minSdkVersion for the application. minSdkVersion 14 } } ... buildTypes { release { runProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile 'com.android.support:multidex:1.0.0' } 56 DroidKaigi 2016

Slide 57

Slide 57 text

What happens when you create the multidex app?4 $ unzip app-debug.apk extracting: ... inflating: ... $ ls AndroidManifest.xml app-normal-debug.apk classes.dex lib res META-INF assets classes2.dex org resources.arsc $ ls *.dex classes.dex classes2.dex 4 Reference to Building Apps with Over 65K Methods 57 DroidKaigi 2016

Slide 58

Slide 58 text

Annotations Support Library • Support for annotation metadata. • With resouces dependencies { compile 'com.android.support:support-annotations:23.1.1' } 58 DroidKaigi 2016

Slide 59

Slide 59 text

e.g. @NotNull private void something() { setMessage(null); // Out warning setMessage("message"); // Not out warning } private void setMessage(@NotNull String message) { ... } 59 DroidKaigi 2016

Slide 60

Slide 60 text

Various annotation Check whether resouce id -> @StringRes / @LayoutRes / @DrawableRes Using like enum -> @IntDef / @StringDef Check the executing thread -> @MainThread / @WorkerThread and more... 60 DroidKaigi 2016

Slide 61

Slide 61 text

Design Support Library • Support for material design components and patterns. • With resouces dependencies { compile 'com.android.support:design:23.1.1' } 61 DroidKaigi 2016

Slide 62

Slide 62 text

For new components • FloatingActionButton • NavigationView • Snackbar 62 DroidKaigi 2016

Slide 63

Slide 63 text

For design pattern • AppBarLayout • CollapsingToolbarLayout • CoordinatorLayout • TabLayout • TextInputLayout 63 DroidKaigi 2016

Slide 64

Slide 64 text

Demo: CoordinatorLayout / AppBarLayout / FloatingActionButton • Each component move with together. 64 DroidKaigi 2016

Slide 65

Slide 65 text

Structure of the layout file 65 DroidKaigi 2016

Slide 66

Slide 66 text

Structure of the layout file 66 DroidKaigi 2016

Slide 67

Slide 67 text

Structure of the layout file 67 DroidKaigi 2016

Slide 68

Slide 68 text

Structure of the layout file 68 DroidKaigi 2016

Slide 69

Slide 69 text

Animation of FAB FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); // Set custom behavior class params.setBehavior(new ScrollingFabBehavior()); 69 DroidKaigi 2016

Slide 70

Slide 70 text

Custom Tabs Support Library • Support for managing CustomTabs. • With resouces dependencies { compile 'com.android.support:customtabs:23.1.1' } 70 DroidKaigi 2016

Slide 71

Slide 71 text

Custom Tabs?5 Chrome Custom Tabs allow an app to customize how Chrome looks and feels. — from official site 5 CustomTabs's oficial site: Chrome Custom Tabs 71 DroidKaigi 2016

Slide 72

Slide 72 text

Demo: Custom Tabs • UI customization • Performance optimization • Need pre-fetch 72 DroidKaigi 2016

Slide 73

Slide 73 text

73 DroidKaigi 2016

Slide 74

Slide 74 text

How to open the page with CustomTabs CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() // customize toolbar's color .setToolbarColor(getResources().getColor(R.color.colorPrimary)) .build(); // use shared project String packageName = CustomTabsHelper.getPackageNameToUse(MainActivity.this); customTabsIntent.intent.setPackage(packageName); customTabsIntent.launchUrl(MainActivity.this, Uri.parse("http://zaim.net/")); 74 DroidKaigi 2016

Slide 75

Slide 75 text

Percent Support Library • Support for managing percentage based dimmentions. • With resouces dependencies { compile 'com.android.support:percent:23.1.1' } 75 DroidKaigi 2016

Slide 76

Slide 76 text

PercentLayout • FrameLayout -> PercentFrameLayout • RelativeLayout -> PercentRelativeLayout 76 DroidKaigi 2016

Slide 77

Slide 77 text

Sample layout file 77 DroidKaigi 2016

Slide 78

Slide 78 text

Recommendation Support Library for TV • Content catalog in the TV home screen. • With resouces dependencies { compile 'com.android.support:recommendation:23.1.1' } 78 DroidKaigi 2016

Slide 79

Slide 79 text

e.g. from Android Developers 79 DroidKaigi 2016

Slide 80

Slide 80 text

Build recommendations6 public class RecommendationBuilder { ... public RecommendationBuilder setTitle(String title) { mTitle = title; return this; } public RecommendationBuilder setDescription(String description) { mDescription = description; return this; } public RecommendationBuilder setImage(String uri) { mImageUri = uri; return this; } public RecommendationBuilder setBackground(String uri) { mBackgroundUri = uri; return this; } ... 6 Reference: Android Developers - Recommending TV Content. 80 DroidKaigi 2016

Slide 81

Slide 81 text

Summary - First, let's use v4-support and v7-appcompat library. - The speciality series will use if neccessary. 81 DroidKaigi 2016

Slide 82

Slide 82 text

Thank you for listening 82 DroidKaigi 2016