Skip to content

Instantly share code, notes, and snippets.

View Gkemon's full-sized avatar
😎
Being humanized

Gk Mohammad Emon Gkemon

😎
Being humanized
View GitHub Profile
public static void debugLog(String msg){
final StackTraceElement stackTrace = new Exception().getStackTrace()[1];
String fileName = stackTrace.getFileName();
if (fileName == null) fileName=""; // It is necessary if you want to use proguard obfuscation.
final String info = stackTrace.getMethodName() + " (" + fileName + ":"
+ stackTrace.getLineNumber() + ")";
@Gkemon
Gkemon / PermissionActivity.java
Last active August 21, 2019 09:13
Common Permission Activity which reduce boilerplate code for taking permission in android activity.
import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
@Gkemon
Gkemon / ComparableDate.java
Last active December 18, 2019 06:46
This gist is for anyone who wants sorted date strings from unsorted dates strings.
import java.text.ParseException;
import java.util.Date;
public class ComparableDate implements Comparable<ComparableDate> {
private Date dateTime;
public Date getDateTime() {
return dateTime;
}
@Gkemon
Gkemon / Application Time Spent Tracker
Last active December 18, 2019 08:42
This is a very efficient way to get total spent time of an app by a user in android.
/*This instance of the class show will be registered in the android "Aplpication" instance
like activity.getApplication().registerActivityLifecycleCallbacks(new ApplicationTimeSpentTracker());
*/
public class ApplicationTimeSpentTracker implements Application.ActivityLifecycleCallbacks {
private int activityReferences = 0;
private boolean isActivityChangingConfigurations = false;
private long startingTime;
private long stopTime;
@Override
@Gkemon
Gkemon / Unix To Human Readable Time
Last active December 19, 2019 08:33
This gist is for conversion of unix to human readable time like "Just now", " 2 days ago" , " 6 hours later" etc.
public class unixToHuman {
private static final int SECOND_MILLIS = 1000;
private static final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
private static final int HOUR_MILLIS = 60 * MINUTE_MILLIS;
private static final int DAY_MILLIS = 24 * HOUR_MILLIS;
private static final int WEEK_MILLIS = 7 * DAY_MILLIS ;
public static String getTimeAgo(long time) {
if (time < 1000000000000L) {
// if timestamp given in seconds, convert to millis
File file = new File(sdcard,"Android/file.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
String msg="My name is emon";
String directory_path = Environment.getExternalStorageDirectory().getPath();
File file = new File(directory_path,"/Android"); //"/Android" is the folder name
if(!file.exists()){
file.mkdir();
}
if (!file.exists()) {
file.createNewFile();
package com.ishtiaq.techlogicians.offergenie.list;
import android.content.Context;
import android.content.Intent;
import android.os.StrictMode;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@Gkemon
Gkemon / RotateViewByToggle.java
Created April 1, 2021 06:46
Rotate view by toggle
boolean isRotated= false;
View rotateLayout;
if(isRotated)
{
rotateLayout.setRotation(360);
rotateLayout.setTranslationX(0);
rotateLayout.setTranslationY(0);
ViewGroup.LayoutParams lp = rotateLayout.getLayoutParams();
import android.animation.AnimatorInflater;
import android.animation.StateListAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;