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
@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;

/**
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Build;
import android.os.IBinder;
android {
...
buildTypes {
release {
minifyEnabled true
...
}
debug {
@piyush-malaviya
piyush-malaviya / sms_retriever_hash_v9.sh
Created September 4, 2019 10:33
Retrive SMS Hash Code
Save the raw script file locally then run chmod u+x sms_retriever_hash_v9.sh
Stackoverflow: https://stackoverflow.com/questions/53849023/android-sms-retriever-api-computing-apps-hash-string-problem
@piyush-malaviya
piyush-malaviya / Status bar transparent
Created April 19, 2019 13:06
Make Status bar transparent
protected fun setStatusBarTranslucent(makeTranslucent: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (makeTranslucent) {
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
@piyush-malaviya
piyush-malaviya / EditTextDateValidation.java
Created April 19, 2019 05:04 — forked from devrath/EditTextDateValidation.java
Validation date in EditText for android while user is clicking
//SOURCE: http://stackoverflow.com/questions/16889502/how-to-mask-an-edittext-to-show-the-dd-mm-yyyy-date-format
EditText date;
date = (EditText)findViewById(R.id.whichdate);
date.addTextChangedListener(tw);
TextWatcher tw = new TextWatcher() {
private String current = "";
@piyush-malaviya
piyush-malaviya / PDFUtil.java
Created March 19, 2019 10:09 — forked from tejpratap46/PDFUtil.java
Android Generate PDF from view
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.pdf.PdfDocument;
import android.graphics.pdf.PdfRenderer;
import android.os.AsyncTask;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.util.Log;
/**
* Util class for converting between dp, px and other magical pixel units
*/
public class PixelUtil {
private PixelUtil() {
}
public static int dpToPx(Context context, int dp) {
int px = Math.round(dp * getPixelScaleFactor(context));
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.animation.LinearInterpolator;
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;