Skip to content

Instantly share code, notes, and snippets.

Avatar

Piyush Malaviya piyush-malaviya

  • Ahmedabad, Gujarat, India
View GitHub Profile
@piyush-malaviya
piyush-malaviya / JsonUtils.java
Created Apr 13, 2017
JsonUtils, JSON parsing made easy. Simply pass the json object and the path to the key you want, and it will return value if available, otherwise it will return null. Works well with simple JSONObject and Gson's JsonObject.
View JsonUtils.java
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import java.util.Map;
public class JsonUtils {
@piyush-malaviya
piyush-malaviya / PrintFormattedJson.java
Last active May 11, 2017
Print formated json in log screen. it is useful we want to show json data in formatted style in log screen.
View PrintFormattedJson.java
import android.util.Log;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import java.util.Map;
public class PrintFormattedJson {
@piyush-malaviya
piyush-malaviya / FusedLocationHelper.java
Last active Jan 19, 2018
FusedLocationHelper class is used for requesting location for continuous location update or get only single time location update.
View FusedLocationHelper.java
public class FusedLocationHelper implements GoogleApiClient.OnConnectionFailedListener, ResultCallback<Status> {
private static final String TAG = FusedLocationHelper.class.getSimpleName();
private Context context;
private GoogleApiClient googleApiClient;
private Location lastKnownLocation;
private LocationUpdateListener locationUpdateListener;
// location request parameter
private long interval = 0; // time in millisecond
private long fastestInterval = 0; // time in millisecond
View DateTimeUtils.java
import java.util.Calendar;
public class DateTimeUtils {
private static final long SEC = 1000;
private static final long MIN = SEC * 60;
private static final long HOUR = MIN * 60;
private static final long DAY = HOUR * 24;
private static final long WEEK = DAY * 7;
private static final long YESTERDAY = DAY * 2;
View EncryptDecryptConverterFactory.Java
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import android.util.Log;
import java.nio.charset.Charset;
@piyush-malaviya
piyush-malaviya / PermissionHelper.java
Last active Jan 19, 2018
Permission Helper class for handling permission flow
View PermissionHelper.java
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
View SpannableUtils.java
public class SpannableUtils {
public static void makeStringClickable(final TextView textView, String clickableText, final OnClickSpannableListener onClickSpannableListener) {
makeStringClickable(textView, clickableText, ContextCompat.getColor(textView.getContext(), R.color.colorPrimary), onClickSpannableListener);
}
public static void makeStringClickable(final TextView textView, String clickableText, final int color, final OnClickSpannableListener onClickSpannableListener) {
String text = textView.getText().toString();
if (!text.contains(clickableText)) {
@piyush-malaviya
piyush-malaviya / BaseFilterAdapter.java
Last active Jul 27, 2019
Filterable RecyclerView adapter
View BaseFilterAdapter.java
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.Filter;
import android.widget.Filterable;
import java.util.ArrayList;
public abstract class BaseFilterAdapter<T, S extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<S> implements Filterable {
View FileUtils.java
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
View LocalStorageProvider.java
public class LocalStorageProvider extends DocumentsProvider {
public static final String AUTHORITY = "com.app.android.localstorage.documents";
/**
* Default root projection: everything but Root.COLUMN_MIME_TYPES
*/
private final static String[] DEFAULT_ROOT_PROJECTION = new String[]{
DocumentsContract.Root.COLUMN_ROOT_ID,
DocumentsContract.Root.COLUMN_FLAGS,