This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getAppVersionName() { | |
try { | |
return MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionName; | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
return "1"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApp extends Application { | |
public static boolean isAppInBackground = false; | |
private Activity mCurrentActivity; | |
public void onCreate() { | |
super.onCreate(); | |
setScreenOrientation(); | |
this.mMyApp = (MyApp) getApplicationContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |