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 : "${supportLibrary}", recyclerView : "${supportLibrary}", cardView : "${supportLibrary}", appCompat : "${supportLibrary}", supportAnnotation: "${supportLibrary}", ] } In the top level file build.gradle

A First Glance at Stetho tool

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

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

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);; Now you can use the new and the the code becomes: import; AlertDialog.Builder builder = new AlertDialog.Builder(this,; builder.setTitle("Dialog")

Android #gist: A SectionedGridRecyclerViewAdapter

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

Android-5: Card and images with rounded corners in Android 4

Card and images with rounded corners in Android 4 As you know the CardView in support library has a different behaviour for API=21 and API &lt 21. If you would like to have an image (full or partial) inside your cardView with Rounded corners it is by default only in Android 5. This gist can be useful to achieve the same aspect also in Android V4 (and as always it can be improved) Here the link . The trick is to elaborate the image and obtain an image with rounded corners (I am using the snippet published by +Romain Guy) Pay attention: you have to use cardView.setPreventCornerOverlap(false) ; to avoid the internal padding in api&lt21.