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
@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 / 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;
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() + ")";