Skip to content

Instantly share code, notes, and snippets.

View piyush-malaviya's full-sized avatar

Piyush Malaviya piyush-malaviya

  • Ahmedabad, Gujarat, India
View GitHub Profile
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
public class ToolbarUtils {
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
public class StringUtils {
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
import android.app.Activity;
import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.os.Parcel;
import android.os.Parcelable;
public class ParcelableUtil {
public static byte[] marshall(Parcelable parceable) {
Parcel parcel = Parcel.obtain();
parceable.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes;
@piyush-malaviya
piyush-malaviya / NotificationCenter.java
Created December 12, 2017 10:40
NotificationCenter class like ios
import java.util.HashMap;
import java.util.Observer;
public final class NotificationCenter {
private static NotificationCenter instance;
private final HashMap<String, NotificationObservable> observables;
private NotificationCenter() {
observables = new HashMap<>();
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
apply plugin: 'maven-publish'
android {
publishNonDefault true
compileSdkVersion 25
buildToolsVersion "25.0.3"
@piyush-malaviya
piyush-malaviya / ContactHelper.java
Last active December 22, 2021 06:06
Contact helper class for fetching all contact details from contact id.
public class ContactHelper {
private static final String TAG = ContactHelper.class.getSimpleName();
public static ModelContact getContactDetails(final Context context, String contactId) {
ModelContact contact = new ModelContact();
contact.setContactId(contactId);
Cursor cursor = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spanCount;
private int spacing;
private boolean includeEdge;
@piyush-malaviya
piyush-malaviya / GridSpacingItemDecoration.md
Last active February 17, 2020 09:55 — forked from cxyxlxdm/GridSpacingItemDecoration.md
Add column spacing in RecyclerView with GridLayoutManager

Android Recyclerview GridLayoutManager column spacing Here is the question, the first answer does not work well in my project,and it makes the spacing bigger between item and item. the second answer is quite perfect.But if RecyclerView has headers,it does not work well. Then I fixed it.

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**