Theerasan Tonthongkam - Ta
Android Jetpack
AndroidX
What is AndroidX
What normal
people think?
What am I think
about?
What is AndroidX
Refactor
Support
Library
AndroidX
What is Android Jetpack?
Accelerate development Eliminate boilerplate code Build high quality, robust apps
Android Jetpack
● Guidance
● Recommendation & Tools
● How to make a good App
AndroidX
● Library
● Technical guarantees
versioning/ naming
build.gradle
dependencies {
// Slice
implementation 'androidx.slice:slice-core:1.0.0-alpha3'
implementation 'androidx.slice:slice-builders:1.0.0-alpha3'
// KTX
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
}
Behind the scene
of AndroidX
Mismatched artifact/ package
name is weird, could be confusing.
“ “
Developer have to understand the
legacy of Support Library .../ not
great.
“ “
Have to update version of Support
Library, but nothing new.
“ “
2011
Support-v4 (sdk 4)
Watch components
Car components
TV components
Testing components
More...
- com.android.support
+ support-v4
+ support-v13
+ appcompat-v7
+ cardview-v7
+ coordinatorlayout
+ …
+ …
+ …
+ …
+ more
- com.android.support
+ support-v4
+ support-v13
+ appcompat-v7
+ preference-v14
+ recyclerview-v7
+ gridlayout-v7
+ palette-v7
+ …
Min SDK version
14
- com.android.support
+ support-v4
+ support-v13
+ appcompat-v7
+ preference-v14
+ recyclerview-v7
+ gridlayout-v7
+ palette-v7
+ …
What is in Support V-13?
“ไมมี...
ไมมีเลยเจาคะ”
support-v13 support-v4
component 1
component 2
component …
component n
- com.android.support
+ recommendation
23.0.1
23.1.0
23.1.1
23.2.0
23.2.1
23.3.0
23.4.0
24.0.0-alpha1
24.0.0-alpha2
24.0.0-beta1
24.0.0
24.0.1
24.1.1
24.2.0
24.2.1
25.0.0
25.0.1
25.1.0
25.1.1
25.2.0
25.3.0
25.3.1
25.4.0
26.0.0-alpha1
26.0.0-beta1
26.0.0-beta2
26.0.0
Why it has weird naming?
● Create for long time ago
● Hard to fix--legacy code
● All support version have to be the same
dependencies {
implementation ‘com.android.support:animated-vector-drawable:27.0.2’
implementation ‘com.android.support:customtabs:26.1.0’
}
Hint error message
All com.android.support libraries must use the exact same version specification (mixing
versions can lead to runtime crashes). Found versions 27.0.2, 26.1.0. Examples include
com.android.support:animated-vector-drawable:27.0.2 and
com.android.support:customtabs:26.1.0
there are some combinations of libraries, or tools and libraries, that are incompatible, or can
lead to bugs. One such incompatibility is compiling with a version of the Android support
libraries that is not the latest version (or in particular, a version lower than your
targetSdkVersion.)
Big refactoring
Support Library to AndroidX
Android Extension Library
AndroidX
Artifacts
● More logical
● Finer-grain-artifact
● Clearer scope
support library
import android.support.v7.widget.RecyclerView
androidx
import androidx.recyclerview.widget.RecyclerView
Umbrella effect
28.0.0 1.0.0
Refined versioning
Semantic-version
major.minor.bug
Finer scope
Clearer and pattern
adroidx.<feature>:classname
adroidx.<feature>:<feature>-<subfeature>
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0-alpha3'
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0-alpha3'
}
V-4 V-7 V-13 V-14
Migration tools
Android Studio 3.2 canary 15+
build.gradle
android {
compileSdkVersion 28
…
…
…
…
}
Migrate tools bug
Some method signature are changed
Migrate tools bug
Use full path instead of class name + import
3rd party
Jetifier
Jetifier is released which will perform refactoring task inside jar/aar file
https://developer.android.com/topic/libraries/support-library/refactor
AndroidX & Support 28.0.0
● AndroidX is included in Support Library 28.0.0
● No new feature in Support Library 28.0.0
“เตือนแลวนะ”
What’s new in AndroidX
3 cool features
RecyclerView
selection
Slice
Android KTX
more...
https://goo.gl/gZYbHJ
RecyclerView
Selection
● Touch and mouse-driven
● Preserves state between
Activity lifecycle events
● Fine-grained-control
build.gradle
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0-alpha3'
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0-alpha3'
}
NewsListView.kt
with(binding.list) {
adapter = NewsListAdapter(binding.viewModel!!)
val stableIdKeyProvider = StableIdKeyProvider(this)
val selectionTracker = SelectionTracker.Builder<Long>(
"news-selection",
this,
stableIdKeyProvider,
MyItemsLookUp(this, binding.viewModel!!),
StorageStrategy.createLongStorage())
.build()
(adapter as NewsListAdapter).selectionTracker = selectionTracker
}
class MyItemsLookUp(private val recyclerView: RecyclerView) :
ItemDetailsLookup<Long>() {
override fun getItemDetails(event: MotionEvent):
ItemDetails<Long?>? {
val view = recyclerView.findChildViewUnder(event.x,
event.y)
if (view != null) {
val viewHolder = recyclerView.getChildViewHolder(view)
if (viewHolder is NewsListAdapter.NewsViewHolder) {
return object : ItemDetails<Long?>() {
override fun getSelectionKey(): Long? =
viewHolder.itemId
override fun getPosition(): Int =
viewHolder.adapterPosition
}
}
return null
}
}
NewsListAdaptor.kt
init {
setHasStableIds(true)
}
override fun getItemId(position: Int): Long =
items[position].id.toLong()
override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
holder.bind(items[position])
holder.setSelected(selectionTracker?.isSelected(item.id.toLong()))
}
bg_selection.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/selectedBackground" />
</selector>
item_news.xml
<LinearLayout
android:id="@+id/wrapper"
android:background="@drawable/bg_selection"
Slice
● Slice provider
● Slice template
● Let you app show on Google
App & Google Assistant
https://github.com/googlesamples/android-SliceViewer/releases
build.gradle
dependencies {
implementation 'androidx.slice:slice-core:1.0.0-alpha3'
implementation 'androidx.slice:slice-builders:1.0.0-alpha3'
}
AndroidManifest.xml
<provider
android:name=".slice.NewsSlice"
android:authorities="news.ta.com.news"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.app.slice.category.SLICE" />
<data
android:host="news.ta.com.news"
android:pathPrefix="/newsslice"
android:scheme="http" />
</intent-filter>
</provider>
NewsSlice.kt
override fun onBindSlice(sliceUri: Uri): Slice? {
return if (sliceUri.path == "/newsslice" && NewsApplication.news
!= null) {
ListBuilder(context, sliceUri)
.addRow {
it.setTitle(NewsApplication.news!!.headline)
it.setSubtitle(NewsApplication.news!!.description)
it.setPrimaryAction(openTempActivity)
}
.build()
} else {
//do something
}
}
otlin Extension
Android KTX
Write more concise, idiomatic Kotlin code
dependencies {
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
}
KOTLIN KOTLIN + ANDROID KTX
sharedPreferences.edit()
.putBoolean("key", value)
.apply()
sharedPreferences.edit {
putBoolean("key", value)
}
KOTLIN KOTLIN + ANDROID KTX
db.beginTransaction()
try {
// insert data
db.setTransactionSuccessful()
} finally {
db.endTransaction()
}
db.transaction {
// insert data
}
KOTLIN KOTLIN + ANDROID KTX
val uri = Uri.parse(myUriString) val uri = myUriString.toUri()
KOTLIN KOTLIN + ANDROID KTX
for (i in 0..view.childCount) {
doSomething(i, view[i])
}
view.children.forEachIndexed {
i, v -> doSomething(i, v)
}
More
● HEIF Writer provides support for writing HEIF-format still images. (High
Efficiency Image File Format)
● Design Library Theme.MaterialComponents
● Browser actions provides a protocol for app developers to launch a
consistent
● ListAdapter for RecyclerView (along with AsyncListDiffer)
● SortedList.ReplaceAll
● https://goo.gl/vrDRXy
Sugoiiiiiiiiiiii
https://youtu.be/jdKUm8tGogw
More information
Conclusion
AndroidX
AndroidX
● Big refactor from Support Library
● Artficats, Naming, Package
● Technical gaurantee
● Some features in Jetpack
● More cool features will make you life easier
Question?
Current job openings
● Frontend Developer - Singapore
● Backend Developer - Singapore
● Android developer - Bangkok
● iOS developer - Bangkok
Forward your CV:
sarah@eatigo.com
jutamat@eatigo.com
Thank you
Theerasan Tonthongkam - Ta
https://goo.gl/gZYbHJ
https://medium.com/ta-tonthongkam
Helpful resources
@IhazardTa
AndroidX Google Extended I/O BKK 2018

AndroidX Google Extended I/O BKK 2018