Skip to content

Instantly share code, notes, and snippets.

View erfanegtfi's full-sized avatar

Erfan Eghterafi erfanegtfi

  • Iran
View GitHub Profile
public static final String md5(String s) {
String MD5 = CommonUtils.MD5_INSTANCE;
try {
MessageDigest digest = MessageDigest.getInstance(io.fabric.sdk.android.services.common.CommonUtils.MD5_INSTANCE);
digest.update(s.getBytes());
byte[] messageDigest = digest.digest();
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest) {
String h = Integer.toHexString(aMessageDigest & 255);
while (h.length() < 2) {
@erfanegtfi
erfanegtfi / timeConvert.java
Created April 13, 2018 12:35
convert Minute To Hour
public static void convertMinuteToHour(int totalMinute, TextView textView) {
if (totalMinute >= 60) {
int hours = (int) Math.floor((double) (totalMinute / 60));
totalMinute %= 60;
if (totalMinute == 0) {
textView.setText("طول بازدید: " + persianNumbers(String.valueOf(hours)) + " ساعت ");
return;
} else {
textView.setText("طول بازدید: " + persianNumbers(String.valueOf(hours)) + " ساعت و " + persianNumbers(String.valueOf(totalMinute)) + " دقیقه ");
return;
@erfanegtfi
erfanegtfi / timeConvert.java
Created April 13, 2018 12:35
get Time Difference DAY, HOUR, MINUTE, SECOND
public class TimeUtils {
public static final long DAY = 86400000;
public static final long HOUR = 3600000;
public static final long MINUTE = 60000;
public static final long SECOND = 1000;
public static long getMinuteDifference(long startTime, long endTime) {
return (endTime - startTime) / MINUTE;
}
@erfanegtfi
erfanegtfi / encode_decode.java
Created April 13, 2018 12:37
Hash String md5, sha1
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Hash {
public static String getHash(String txt, String hashType) {
try {
byte[] array = MessageDigest.getInstance(hashType).digest(txt.getBytes());
StringBuffer sb = new StringBuffer();
@erfanegtfi
erfanegtfi / Validator.java
Created April 13, 2018 12:40
valid email, mobile, price, ssn ...
public class Validator {
public static boolean isValidEmailAddress(String email) {
String emailRegex;
String stricterFilterString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
String laxString = ".+@.+\\.[A-Za-z]{2}[A-Za-z]*";
if (true) {
emailRegex = stricterFilterString;
} else {
emailRegex = laxString;
}
@erfanegtfi
erfanegtfi / AndroidUtils.java
Created April 13, 2018 12:46
is App In Background
public static boolean isAppIsInBackground(Context context) {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
isInBackground = false;
@erfanegtfi
erfanegtfi / AndroidUtils.java
Created April 13, 2018 11:18
getAppVersionCode
public static Integer getAppVersionCode() {
try {
return Integer.valueOf(MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionCode);
} catch (Exception ex) {
ex.printStackTrace();
return Integer.valueOf(1);
}
}
@erfanegtfi
erfanegtfi / AndroidUtils.java
Created April 13, 2018 11:30
getAppVersionName
public static String getAppVersionName() {
try {
return MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionName;
} catch (Exception ex) {
ex.printStackTrace();
return "1";
}
}
public class MyApp extends Application {
public static boolean isAppInBackground = false;
private Activity mCurrentActivity;
public void onCreate() {
super.onCreate();
setScreenOrientation();
this.mMyApp = (MyApp) getApplicationContext();
public static final String md5(String s) {
String MD5 = CommonUtils.MD5_INSTANCE;
try {
MessageDigest digest = MessageDigest.getInstance(CommonUtils.MD5_INSTANCE);
digest.update(s.getBytes());
byte[] messageDigest = digest.digest();
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest) {
String h = Integer.toHexString(aMessageDigest & 255);
while (h.length() < 2) {