Posts

Showing posts from 2015

How to centralize the support libraries dependencies in gradle

Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries. A very good way is to separate gradle build files, defining something like: root --gradleScript ----dependencies.gradle --module1 ----build.gradle --build.gradle In gradleScript/dependecies.gradle : ext { //Version supportLibrary = '22.2.1' //Support Libraries dependencies supportDependencies = [ design : "com.android.support:design:${supportLibrary}", recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}", cardView : "com.android.support:cardview-v7:${supportLibrary}", appCompat : "com.android.support:appcompat-v7:${supportLibrary}", supportAnnotation: "com.android.support:support-annotations:${supportLibrary}", ] } In the top level file build.gradle ...

A First Glance at Stetho tool

Image
I decided to spend a few hours on Stetho . Stetho is a sophisticated debug bridge for Android applications. How to enable it It is very simple to enable Stetho. Just add these lines to your build.gradle : dependencies { // Stetho core compile 'com.facebook.stetho:stetho:1.1.1' //If you want to add a network helper compile 'com.facebook.stetho:stetho-okhttp:1.1.1' } Then in your Application you can enable the tool just adding: Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp( Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector( Stetho.defaultInspectorModulesProvider(this)) .build()); In my simple application, I have a network call with okhttp-client , a simple value in the shared preferences, and a small db with one table. Now the last...

Gradle tip: how to use the archivesBaseName to change the apk name

I am seeing a lot of build.gradle where there are tasks to rename the apks. I prefer using something different, without use another tasks, setting the archivesBaseName . For example: defaultConfig { .... project.ext.set("archivesBaseName", "MyName-" + defaultConfig.versionName); } Output: MyName-1.0.12-release.apk

#SnackBar gist: A ColoredSnackBar

Image
The default backgroud color for the snackbar in material design can be quite neutral. Of course it provides a lightweight feedback for the users. In same cases this kind of feedback, can to be too anonymous , and the user doesn't give it the right importance and attention . We are trying to use (not everywhere and not always) a colored snackbar, to highlight the type of message that we are showing. In this way the user can recognize a warning message for example. Ok... it is not material (or not?)... but the feedback from users is very good. And yes.. it remembers the styles used by Crouton. Here a simple gist .

A Material styled AlertDialog

Image
Are you looking for a Material styled AlertDialog? Here a short gist to migrate the "old" AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Dialog"); builder.setMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo,"); builder.setPositiveButton("OK", null); builder.setNegativeButton("Cancel", null); builder.show(); Now you can use the new android.support.v7.app.AlertDialog and the the code becomes: import android.support.v7.app.AlertDialog; AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle); builder.setTitle("Dialog")...

Android #gist: A SectionedGridRecyclerViewAdapter

Image
It is a SectionedGridRecyclerViewAdapter . It is the porting of the SimpleSectionedListAdapter[1] provided by Google with the #io code. It can be used to realize a simple sectioned grid without changing your adapter. It works with a RecyclerView with a GridLayoutManager. Here the code : [1]: Google Io14