This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 String encode(String s, String key) { | |
| if (s != null) | |
| return base64Encode(xorWithKey(s.getBytes(), key.getBytes())); | |
| else | |
| return null; | |
| } | |
| public String decode(String s, String key) { | |
| if (s != null) | |
| return new String(xorWithKey(base64Decode(s), key.getBytes())); |
This file contains hidden or 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.util.Base64; | |
| import android.util.Log; | |
| import java.security.InvalidKeyException; | |
| import java.security.NoSuchAlgorithmException; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.NoSuchPaddingException; | |
| import javax.crypto.SecretKey; | |
| import javax.crypto.spec.SecretKeySpec; | |
| import pl.droidsonroids.gif.BuildConfig; |
This file contains hidden or 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 byte[] convertToByteArray(String hexString) { | |
| int len = hexString.length(); | |
| byte[] data = new byte[(len / 2)]; | |
| for (int i = 0; i < len; i += 2) { | |
| data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); | |
| } | |
| return data; | |
| } |