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
package ir.gushtomorghebaradaran.Utils; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
import android.preference.PreferenceManager; | |
import com.google.gson.Gson; | |
public class Prefs<T> { |
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
package com.besat.Utils; | |
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
import java.util.Locale; |
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 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; | |
} |
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.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 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 convertToHexString(byte[] data) { | |
StringBuilder buf = new StringBuilder(); | |
for (byte b : data) { | |
int halfbyte = (b >>> 4) & 15; | |
int two_halfs = 0; | |
while (true) { | |
char c = (halfbyte < 0 || halfbyte > 9) ? (char) ((halfbyte - 10) + 97) : (char) (halfbyte + 48); | |
buf.append(c); | |
halfbyte = b & 15; | |
int two_halfs2 = two_halfs + 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 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) { |
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 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 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 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; |
OlderNewer