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
@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 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,
@piyush-malaviya
piyush-malaviya / HomeActivity.java
Last active Apr 19, 2018
Get directories and files list using native methods
View HomeActivity.java
public class HomeActivity extends BaseAppCompatActivity {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
public native Object[] getMediaFiles(String root);
@Override
View AAR File Publish gradle
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
apply plugin: 'maven-publish'
android {
publishNonDefault true
compileSdkVersion 25
buildToolsVersion "25.0.3"
View GridSpacingItemDecoration.java
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 / NotificationCenter.java
Created Dec 12, 2017
NotificationCenter class like ios
View NotificationCenter.java
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<>();