My everyday Android practice demos with Kotlin in 100(far and far more...) days.
39. Image Puzzle Game
Date: 2018-8-10
What I learned from this demo:
Make a simple image puzzle game with bitmap data operations: scale, draw, clip and so on
Use the powerful BRVAH library to make a simple RecyclerView with XML layout
Now remove the support library and migrate to androidX packages, so Anko layout is not supported right now
PS: Restart(cold reboot) simulator to make the downloaded images appear in gallery.
# while build failed with this problem:# Cause: delight/rhinosandox/RhinoSandboxes# Try run the command in terminal:
gradlew clean assemble -stacktrace
Create Observable from buttons and text changes, and merge them together
Switch work threads, use doOnNext to show progress bar, and dispose them when needed
Use arrays in XML resource, change the button appearance use the theme of Widget.AppCompat.Button.Colored
34. Basic Material Animation
Date: 2018-3-11
What I learned from this demo:
Basic material animations for Fragment: enter/exit transition, shared element trasition
Use coroutines to do time-consuming process: async, await in launch coroutines scope
Build animations in ConstraintLayout use simple and powerful ConstraintSet and Transition
Single activity as a container with multiple fragments
Resource: Android KTX libraryKeyframe Animations with ConstraintLayout and ConstraintSetPS: While use shared element between fragments, I notice that, the 1st: add will not work but replace works, and 2nd: I set transitionName in the CardView instead of directly in the ImageView, which is the sub-view of CardView, that works!
33. ObjectBox And Coroutines
Date: 2018-3-7
What I learned from this demo:
Work with ObjectBox to do the operations of databases
Try to use Kotlin Coroutines to simulate some time-consuming process, it's just a test
Create the custom Application, use open source toast: Toasty, use NestedScrollView in CoordinatorLayout
Resource: ObjectBox APIA test project, lost of functionalities are not accomplished yet.
32. Basic Android MVP
Date: 2018-3-1
What I learned from this demo:
Use the basic MVP pattern in Android project, to make code clean and testable
Understand and use the abstract class and abstract methods
The data binding in view, use this library: KotlinAndroidViewBindings (I just copied some code in my project.)
No layout XML files, but replace with the anko layout library to create views
Use WindowManager to display floating views on the window
Deal with the back button pressed to hide the activity, prevent from finishing the app
After 2 months at last! Still 2 problems or questions:1. If back pressed and app is killed, then the android.view.WindowLeaked exception throws, how to solve?2. In the emulator, if the drag and drop event happens outside, then the position of the window will be some wried.
20. Simple Search Web View
Date: 2017-10-18
What I learned from this demo:
Work with WebView, set the client as WebViewClient and WebChromeClient
Use the ToolBar instead of ActionBar, try SearchView in the tool bar
Save and retrieve list items (StringSet) in shared preferences
Add or remove item in RecyclerView, handle long click events on list item
Deal with the WebView in NestedScrollView through the library: NestedScrollWebView in Github
The asynchronized task with doAsync and uiThread in Kotlin
Basic file and stream operations in Android
18. Basic File Operation
Date: 2017-10-4
What I learned from this demo:
Use SharedPreferences to store and retrieve simple data
Basic file operations on Android system, with openFileInput and openFileOutput
Set data in the activity result and return
17. Simple Broadcast Receiver
Date: 2017-09-27
What I learned from this demo:
Use one of the most four important components in Android: Broadcast Receiver
Extension functions in Kotlin with AppCompatActivity
Try the open-source library: EventBus to post and handle events, and also the CircleImageView
Reduce the redundant of layout by using <inlucde> tags
I am still not very clear with Android BroadcastReceiver, I found that it sometimes(especially for the single app development) can be replaced with EventBus through publish/subscribe pattern, is that right?
16. Self Adaption
Date: 2017-09-12
What I learned from this demo:
Use the Fragments in the Activities
Specify different layouts for different size or screen orientation (layout-land and layout-large)
Use the empty view element as spacer or divider (be careful of the tag, it is View not view!)
Dynamically set the visibility of view
Till now I have no idea of using the savedInstanceState variable to make the data consistent while rotate the screen orientation, I should try it out later.
15. Database with Room
Date: 2017-09-04
What I learned from this demo:
Use the Room Persistence Library for the basic database operations: INSERT/DELETE/UPDATE/QUERY
Work with data class in Kotlin and the let lamda, and the annotations
Convert date types to string types, and vice versa by using SimpleDateFormat or DateFormat.getDateInstance()
Use adb shell and sqlite3 command to query the data in emulator local system files:
$ adb quit
# for more than one device found here
$ adb devices
$ adb -s <emulator name> shell
$ cd data/data/me.liuqingwen.android.projectdatabaseroom/databases
$ sqlite3
$ .open <dbname.db>
$ .tables
$ SELECT * FROM <table name>
14. Activity Animations
Date: 2017-09-01
What I learned from this demo:
Transitions between activities use overridePendingTransition
Work with animation xml resource file, the difference of "50%" and "50%p" (relative to parent view)
Override onBackPressed method to finish the activity
13. Simple Activity with Intent
Date: 2017-08-31
What I learned from this demo:
Dealing with the custom item click handler of RecyclerView
Start an intent to show another Activity by startActivityForResult
Get the result from another activity through method of onActivityResult
12. Simple Animations with Custom View
Date: 2017-08-30
What I learned from this demo:
Custom view with custom attributes (declared in the xml value file)
Use onMeasure to set the correct size of view
Use onDraw to display the paint on the canvas
Work with the basic object animator and animator-set
The importance of lazy properties in Kotlin, think about the code:
//the [sunColor] initialized here will be changed later in the constructor through xml user attributes.privatevar sunColor =Color.RED/*//the paint directly initialized will not be the expected one, as the [sunColor] will change later for xml attributes!private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { this.color = [email protected] this.isAntiAlias = true}*///by using the lazy properties, the paint will be all right with the [sunColor] property!privateval paint by lazy {
Paint(Paint.ANTI_ALIAS_FLAG).apply {
this.color =this@SunView.sunColor
this.isAntiAlias =true
}
}
11. Simple Scalable ImageView
Date: 2017-08-28
What I learned from this demo:
Multiple constructors from base class inheritance in Kotlin
The basic knowledge of custom view: onLayout (left, right, top, bottom)/setFrame/onTouchEvent (Here I should always return true for receiving other touch events)
Multi-touch handle on views: use event.actionMasked instead of event.action
This is a bad-experienced project(view), I think I have to improve that in the next days while learning.
11. Simple ASynchronized Works
Date: 2017-08-17
What I learned from this demo:
Try to figure out the differences of usage between Handler and AsyncTask in Android
Download file from server via OkHttp and read bytes from InputStream
RandomAccessFile for writing file content from specified positions
Till now I can't figure out a solution to pause/resume the downloading tasks, and I will try it later.
10. Swipe Refresh RecylcerView
Date: 2017-08-16
What I learned from this demo:
Work with SwipeRefreshLayout and RecyclerView
Basic AlertDialog and Snackbar usage
Custom header and footer item in RecyclerView (It looks a little weird!)
9. Simple Video Player
Date: 2017-08-14
What I learned from this demo:
The first time explore the MediaPlayer with SurfaceView
Got idea of LayoutParams and its simple properties (ConstraintLayout.LayoutParams)
8. Basic Material Design
Date: 2017-08-12
What I learned from this demo:
Basic material design elements: DrawerLayout, NavigationView, CoordinatorLayout, AppBarLayout with Toolbar and FloatingActionButton
Try to use the open source Android libraries of RxAndroid, OkHttp, Gson and Glide, ect.
DrawerLayout must work with a child with layout_gravity property specified.
Gson tokens with types: object : TypeToken<List<Turns>>() {}.type is the right way.
请发表评论