Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
gabrielemariotti / README.MD
Last active Feb 18, 2021
How to use the ShapeableImageView.
View README.MD

The Material Components Library introduced with the 1.2.0-alpha03 the new ShapeableImageView.

In your layout you can use:

 <com.google.android.material.imageview.ShapeableImageView
      android:id="@+id/image_view"
      app:srcCompat="@drawable/..." />

Then in your code apply the ShapeAppearanceModel to define your custom corners:

@gabrielemariotti
gabrielemariotti / README.md
Last active Jan 24, 2019
How to manage the firebase libraries in a multi-module projects
View README.md

Centralize the firebase libraries dependencies in gradle

ext {
      firebaseVersion = '9.0.0';

      firebaseDependencies = [
              core :         "com.google.firebase:firebase-core:${firebaseVersion}",
              database :     "com.google.firebase:firebase-database:${firebaseVersion}",
              storage :      "com.google.firebase:firebase-storage:${firebaseVersion}",
@gabrielemariotti
gabrielemariotti / README.md
Last active Feb 24, 2021
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)
View README.md

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
View ColoredSnackBar.java
public class ColoredSnackBar {
private static final int red = 0xfff44336;
private static final int green = 0xff4caf50;
private static final int blue = 0xff2195f3;
private static final int orange = 0xffffc107;
private static View getSnackBarLayout(Snackbar snackbar) {
if (snackbar != null) {
@gabrielemariotti
gabrielemariotti / README.md
Last active Feb 2, 2021
A SectionedGridRecyclerViewAdapter: use this class to realize a simple sectioned grid `RecyclerView.Adapter`.
View README.md

You can use this class to realize a simple sectioned grid RecyclerView.Adapter without changing your code.

Screen

The RecyclerView has to use a GridLayoutManager.

This is a porting of the class SimpleSectionedListAdapter provided by Google

If you are looking for a sectioned list RecyclerView.Adapter you can take a look here

@gabrielemariotti
gabrielemariotti / gist:10716d3a7c0089f3c034
Created Jan 14, 2015
How to customize the MaterialLargeImageCard with a own class (requires cardslib 2.1.+)
View gist:10716d3a7c0089f3c034
//Create a Card, set the title over the image and set the thumbnail
CustomMaterialLargeImageCard card = (CustomMaterialLargeImageCard)
CustomMaterialLargeImageCard.with(getActivity())
.setTextOverImage("Italian Beaches "+i)
.setTitle("This is my favorite local beach "+i)
.setSubTitle("A wonderful place")
.useDrawableId(R.drawable.sea)
.setupSupplementalActions(R.layout.carddemo_native_material_supplemental_actions_large, actions)
//It is important to use this build method
.build(new CustomMaterialLargeImageCard(getActivity()));
@gabrielemariotti
gabrielemariotti / MainActivity.java
Last active Feb 15, 2021
How to obtain a CardView (support library) with a Image and rounded corners for API<21
View MainActivity.java
ImageView imageView = (ImageView) findViewById(R.id.card_thumbnail_image);
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.rose);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
//Default
imageView.setBackgroundResource(R.drawable.rose);
} else {
//RoundCorners
RoundCornersDrawable round = new RoundCornersDrawable(mBitmap,
getResources().getDimension(R.dimen.cardview_default_radius), 0); //or your custom radius
@gabrielemariotti
gabrielemariotti / build.gradle
Created Oct 25, 2014
Gist for cardslib 2.0.0.RC1
View build.gradle
repositories {
mavenCentral()
//snapshot for rc1
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
//Core card library
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.0-RC1-SNAPSHOT'
@gabrielemariotti
gabrielemariotti / Readme.md
Last active Dec 22, 2016
UndoBar with Material Design
View Readme.md

These layouts provide a simple undo bar with Material Design.

This gist does not contain any Android L API.

undobar with action undobar mobile
Screen Screen
View HelperUtil.java
public class HelperUtil {
private final HelperUtilImpl mImpl;
public HelperUtil (Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
mImpl = new HelperUtilImplL(context);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
mImpl = new HelperUtilImplKK(context);