Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
gabrielemariotti / README.md
Last active February 24, 2021 10:52
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)

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
@gabrielemariotti
gabrielemariotti / MainActivity.java
Last active February 15, 2021 17:32
How to obtain a CardView (support library) with a Image and rounded corners for API<21
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 / mobile-AndroidManifest.xml
Last active September 15, 2020 11:33
Android Wear: small gist to start an Activity on the mobile handheld from the Android Wear device.
<service android:name=".ListenerServiceFromWear">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
@gabrielemariotti
gabrielemariotti / GridActivity.java
Created July 27, 2014 21:38
Android Wear: How to use a simple a GridViewPager with a FragmentGridPagerAdapter.
public class GridActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
final GridViewPager mGridPager = (GridViewPager) findViewById(R.id.pager);
mGridPager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager()));
}
@gabrielemariotti
gabrielemariotti / HelperUtil.java
Created September 3, 2014 10:19
HelperUtil using a IMPL
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);
public class HelperUtil {
public static HelperUtilBase getInstance(Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return new HelperUtilL(context);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
return new HelperUtilKK(context);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return new HelperUtilJB(context);
@gabrielemariotti
gabrielemariotti / Readme.md
Last active June 14, 2018 08:40
SlideInOutLeftDefaultItemAnimator : a simple animator which applies a slide in/out from/to the left animation to item views in the `RecyclerView`

This class provides a simple animator which applies a slide in/out from/to the left animation to item views in the RecyclerView

This code is cloned from DefaultItemAnimator provided by Google, customizing the part highlighted as "Custom implementation".

Example:

   mRecyclerView.setItemAnimator(new SlideInOutLeftDefaultItemAnimator(mRecyclerView));
@gabrielemariotti
gabrielemariotti / MyRecyclerViewAdapter.java
Created August 16, 2014 14:38
RecyclerView and ViewHolder based on viewType
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerView.MyViewHolder>{
public static class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(View view) {
super(view);
}
}
@gabrielemariotti
gabrielemariotti / BatteryActivity.java
Created July 15, 2014 22:56
Android Wear: small gist to get data from Battery
public class BatteryActivity extends Activity {
//UI Elements
private TextView mTextViewLevel;
private TextView mTextViewTemperature;
private TextView mTextViewVoltage;
private TextView mTextViewHealth;
//Battery details
private int level;
@gabrielemariotti
gabrielemariotti / Readme.md
Last active December 22, 2016 14:54
UndoBar with Material Design

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