歌尔基办 v2.7.0版本的 MD5 值为:921fd7c85ec097e8cab7f049269b36e4
以下内容为反编译后的 AndroidUtilities.java 源代码,内容仅作参考
package im.ovithmjoec.messenger;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.camera2.CameraManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.provider.CallLog;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.util.StateSet;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.webkit.MimeTypeMap;
import android.widget.EdgeEffect;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import androidx.core.internal.view.SupportMenu;
import androidx.exifinterface.media.ExifInterface;
import androidx.viewpager.widget.ViewPager;
import com.android.internal.telephony.ITelephony;
import com.bjz.comm.net.premission.PermissionUtils;
import com.bumptech.glide.load.resource.bitmap.HardwareConfigState;
import com.google.android.exoplayer2.source.hls.DefaultHlsExtractorFactory;
import com.google.android.exoplayer2.text.ttml.TtmlNode;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.gms.auth.api.phone.SmsRetriever;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.king.zxing.util.LogUtils;
import com.litesuits.orm.db.assit.SQLBuilder;
import im.ovithmjoec.messenger.LocaleController;
import im.ovithmjoec.messenger.SharedConfig;
import im.ovithmjoec.phoneformat.PhoneFormat;
import im.ovithmjoec.tgnet.ConnectionsManager;
import im.ovithmjoec.tgnet.TLObject;
import im.ovithmjoec.tgnet.TLRPC;
import im.ovithmjoec.ui.ThemePreviewActivity;
import im.ovithmjoec.ui.WallpapersListActivity;
import im.ovithmjoec.ui.actionbar.AlertDialog;
import im.ovithmjoec.ui.actionbar.BaseFragment;
import im.ovithmjoec.ui.actionbar.BottomSheet;
import im.ovithmjoec.ui.actionbar.Theme;
import im.ovithmjoec.ui.cells.TextDetailSettingsCell;
import im.ovithmjoec.ui.components.AlertsCreator;
import im.ovithmjoec.ui.components.BackgroundGradientDrawable;
import im.ovithmjoec.ui.components.ForegroundDetector;
import im.ovithmjoec.ui.components.LayoutHelper;
import im.ovithmjoec.ui.components.PickerBottomLayout;
import im.ovithmjoec.ui.components.TypefaceSpan;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import kotlin.UByte;
import org.slf4j.Marker;
public class AndroidUtilities {
public static final int FLAG_TAG_ALL = 11;
public static final int FLAG_TAG_BOLD = 2;
public static final int FLAG_TAG_BR = 1;
public static final int FLAG_TAG_COLOR = 4;
public static final int FLAG_TAG_URL = 8;
public static Pattern WEB_URL;
private static RectF bitmapRect;
private static ContentObserver callLogContentObserver;
private static int[] documentIcons;
private static int[] documentMediaIcons;
public static boolean firstConfigurationWas;
private static boolean hasCallPermissions;
public static boolean incorrectDisplaySizeFix;
public static boolean isInMultiwindow;
public static int leftBaseline;
private static Field mAttachInfoField;
private static Field mStableInsetsField;
public static int roundMessageSize;
private static Paint roundPaint;
private static Runnable unregisterRunnable;
public static boolean usingHardwareInput;
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<>();
private static int prevOrientation = -10;
private static boolean waitingForSms = false;
private static boolean waitingForCall = false;
private static final Object smsLock = new Object();
private static final Object callLock = new Object();
public static int statusBarHeight = 0;
public static float density = 1.0f;
public static Point displaySize = new Point();
public static Integer photoSize = null;
public static DisplayMetrics displayMetrics = new DisplayMetrics();
public static DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
public static AccelerateInterpolator accelerateInterpolator = new AccelerateInterpolator();
public static OvershootInterpolator overshootInterpolator = new OvershootInterpolator();
private static Boolean isTablet = null;
private static int adjustOwnerClassGuid = 0;
public static float[] RGBtoHSB(int i, int i2, int i3) {
float[] fArr = new float[3];
int i4 = i > i2 ? i : i2;
if (i3 > i4) {
i4 = i3;
}
int i5 = i < i2 ? i : i2;
if (i3 < i5) {
i5 = i3;
}
float f = i4;
float f2 = f / 255.0f;
float f3 = 0.0f;
float f4 = i4 != 0 ? (i4 - i5) / f : 0.0f;
if (f4 != 0.0f) {
float f5 = i4 - i5;
float f6 = (i4 - i) / f5;
float f7 = (i4 - i2) / f5;
float f8 = (i4 - i3) / f5;
float f9 = (i == i4 ? f8 - f7 : i2 == i4 ? (f6 + 2.0f) - f8 : (f7 + 4.0f) - f6) / 6.0f;
f3 = f9 < 0.0f ? f9 + 1.0f : f9;
}
fArr[0] = f3;
fArr[1] = f4;
fArr[2] = f2;
return fArr;
}
public static int alphaColor(float f, int i) {
return (((int) (f * 256.0f)) << 24) | (((i >> 16) & 255) << 16) | (((i >> 8) & 255) << 8) | (i & 255);
}
public static void checkForCrashes(Activity activity) {
}
public static int compare(int i, int i2) {
if (i == i2) {
return 0;
}
return i > i2 ? 1 : -1;
}
public static int getMyLayerVersion(int i) {
return i & 65535;
}
public static int getPeerLayerVersion(int i) {
return (i >> 16) & 65535;
}
public static boolean isEmojiCharacter(char c) {
return c == 0 || c == '\t' || c == '\n' || c == '\r' || (c >= ' ' && c <= 55295) || ((c >= 57344 && c <= 65533) || (c >= 0 && c <= 65535));
}
public static int setMyLayerVersion(int i, int i2) {
return (i & SupportMenu.CATEGORY_MASK) | i2;
}
public static int setPeerLayerVersion(int i, int i2) {
return (i & 65535) | (i2 << 16);
}
static {
WEB_URL = null;
try {
WEB_URL = Pattern.compile("((?:(http|https|Http|Https):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?(?:" + Pattern.compile("(([a-zA-Z0-9 -\ud7ff豈-\ufdcfﷰ-\uffef]([a-zA-Z0-9 -\ud7ff豈-\ufdcfﷰ-\uffef\\-]{0,61}[a-zA-Z0-9 -\ud7ff豈-\ufdcfﷰ-\uffef]){0,1}\\.)+[a-zA-Z -\ud7ff豈-\ufdcfﷰ-\uffef]{2,63}|" + Pattern.compile("((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9]))") + SQLBuilder.PARENTHESES_RIGHT) + ")(?:\\:\\d{1,5})?)(\\/(?:(?:[a-zA-Z0-9 -\ud7ff豈-\ufdcfﷰ-\uffef\\;\\/\\?\\:\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?(?:\\b|$)");
} catch (Exception e) {
FileLog.e(e);
}
leftBaseline = isTablet() ? 80 : 72;
checkDisplaySize(ApplicationLoader.applicationContext, null);
documentIcons = new int[]{R.drawable.media_doc_blue, R.drawable.media_doc_green, R.drawable.media_doc_red, R.drawable.media_doc_yellow};
documentMediaIcons = new int[]{R.drawable.media_doc_blue_b, R.drawable.media_doc_green_b, R.drawable.media_doc_red_b, R.drawable.media_doc_yellow_b};
hasCallPermissions = Build.VERSION.SDK_INT >= 23;
}
public static int getThumbForNameOrMime(String str, String str2, boolean z) {
int i;
if (str == null || str.length() == 0) {
return z ? documentMediaIcons[0] : documentIcons[0];
}
if (str.contains(".doc") || str.contains(".txt") || str.contains(".psd")) {
i = 0;
} else if (str.contains(".xls") || str.contains(".csv")) {
i = 1;
} else if (str.contains(".pdf") || str.contains(".ppt") || str.contains(".key")) {
i = 2;
} else {
i = (str.contains(".zip") || str.contains(".rar") || str.contains(".ai") || str.contains(DefaultHlsExtractorFactory.MP3_FILE_EXTENSION) || str.contains(".mov") || str.contains(".avi")) ? 3 : -1;
}
if (i == -1) {
int lastIndexOf = str.lastIndexOf(46);
String substring = lastIndexOf == -1 ? "" : str.substring(lastIndexOf + 1);
if (substring.length() != 0) {
i = substring.charAt(0) % documentIcons.length;
} else {
i = str.charAt(0) % documentIcons.length;
}
}
return z ? documentMediaIcons[i] : documentIcons[i];
}
public static int[] calcDrawableColor(Drawable drawable) {
int[] colorsList;
Bitmap createScaledBitmap;
int[] iArr = new int[4];
int i = -16777216;
try {
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
if (bitmap != null && (createScaledBitmap = Bitmaps.createScaledBitmap(bitmap, 1, 1, true)) != null) {
i = createScaledBitmap.getPixel(0, 0);
if (bitmap != createScaledBitmap) {
createScaledBitmap.recycle();
}
}
} else if (drawable instanceof ColorDrawable) {
i = ((ColorDrawable) drawable).getColor();
} else if ((drawable instanceof BackgroundGradientDrawable) && (colorsList = ((BackgroundGradientDrawable) drawable).getColorsList()) != null && colorsList.length > 0) {
i = colorsList[0];
}
} catch (Exception e) {
FileLog.e(e);
}
double[] rgbToHsv = rgbToHsv((i >> 16) & 255, (i >> 8) & 255, i & 255);
rgbToHsv[1] = Math.min(1.0d, rgbToHsv[1] + 0.05d + ((1.0d - rgbToHsv[1]) * 0.1d));
int[] hsvToRgb = hsvToRgb(rgbToHsv[0], rgbToHsv[1], Math.max((double) FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE, rgbToHsv[2] * 0.65d));
iArr[0] = Color.argb(102, hsvToRgb[0], hsvToRgb[1], hsvToRgb[2]);
iArr[1] = Color.argb(136, hsvToRgb[0], hsvToRgb[1], hsvToRgb[2]);
int[] hsvToRgb2 = hsvToRgb(rgbToHsv[0], rgbToHsv[1], Math.max((double) FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE, rgbToHsv[2] * 0.72d));
iArr[2] = Color.argb(102, hsvToRgb2[0], hsvToRgb2[1], hsvToRgb2[2]);
iArr[3] = Color.argb(136, hsvToRgb2[0], hsvToRgb2[1], hsvToRgb2[2]);
return iArr;
}
public static double[] rgbToHsv(int i, int i2, int i3) {
double d;
double d2;
double d3;
double d4 = i;
Double.isNaN(d4);
double d5 = d4 / 255.0d;
double d6 = i2;
Double.isNaN(d6);
double d7 = d6 / 255.0d;
double d8 = i3;
Double.isNaN(d8);
double d9 = d8 / 255.0d;
double d10 = (d5 <= d7 || d5 <= d9) ? d7 > d9 ? d7 : d9 : d5;
double d11 = (d5 >= d7 || d5 >= d9) ? d7 < d9 ? d7 : d9 : d5;
double d12 = d10 - d11;
double d13 = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
double d14 = d10 == FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE ? 0.0d : d12 / d10;
if (d10 != d11) {
if (d5 > d7 && d5 > d9) {
d = (d7 - d9) / d12;
d2 = d7 < d9 ? 6 : 0;
Double.isNaN(d2);
} else if (d7 > d9) {
d3 = 2.0d + ((d9 - d5) / d12);
d13 = d3 / 6.0d;
} else {
d = (d5 - d7) / d12;
d2 = 4.0d;
}
d3 = d + d2;
d13 = d3 / 6.0d;
}
return new double[]{d13, d14, d10};
}
private static int[] hsvToRgb(double d, double d2, double d3) {
double d4 = 6.0d * d;
double floor = (int) Math.floor(d4);
Double.isNaN(floor);
double d5 = d4 - floor;
double d6 = (1.0d - d2) * d3;
double d7 = (1.0d - (d5 * d2)) * d3;
double d8 = d3 * (1.0d - ((1.0d - d5) * d2));
int i = ((int) floor) % 6;
double d9 = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
if (i != 0) {
if (i == 1) {
d9 = d3;
d8 = d6;
d6 = d7;
} else if (i == 2) {
d9 = d3;
} else if (i == 3) {
d8 = d3;
d9 = d7;
} else if (i == 4) {
d9 = d6;
d6 = d8;
d8 = d3;
} else if (i != 5) {
d8 = 0.0d;
d6 = 0.0d;
} else {
d9 = d6;
d8 = d7;
}
return new int[]{(int) (d6 * 255.0d), (int) (d9 * 255.0d), (int) (d8 * 255.0d)};
}
d9 = d8;
d8 = d6;
d6 = d3;
return new int[]{(int) (d6 * 255.0d), (int) (d9 * 255.0d), (int) (d8 * 255.0d)};
}
public static void requestAdjustResize(Activity activity, int i) {
if (activity == null || isTablet()) {
return;
}
activity.getWindow().setSoftInputMode(16);
adjustOwnerClassGuid = i;
}
public static void setAdjustResizeToNothing(Activity activity, int i) {
if (activity == null || isTablet() || adjustOwnerClassGuid != i) {
return;
}
activity.getWindow().setSoftInputMode(48);
}
public static void removeAdjustResize(Activity activity, int i) {
if (activity == null || isTablet() || adjustOwnerClassGuid != i) {
return;
}
activity.getWindow().setSoftInputMode(32);
}
public static boolean isGoogleMapsInstalled(final BaseFragment baseFragment) {
try {
ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
return true;
} catch (PackageManager.NameNotFoundException unused) {
if (baseFragment.getParentActivity() == null) {
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(baseFragment.getParentActivity());
builder.setMessage(LocaleController.getString("InstallGoogleMaps", R.string.InstallGoogleMaps));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public final void onClick(DialogInterface dialogInterface, int i) {
AndroidUtilities.lambda$isGoogleMapsInstalled$0(BaseFragment.this, dialogInterface, i);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
baseFragment.showDialog(builder.create());
return false;
}
}
public static void lambda$isGoogleMapsInstalled$0(BaseFragment baseFragment, DialogInterface dialogInterface, int i) {
try {
baseFragment.getParentActivity().startActivityForResult(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=com.google.android.apps.maps")), 500);
} catch (Exception e) {
FileLog.e(e);
}
}
public static int[] toIntArray(List<Integer> list) {
int size = list.size();
int[] iArr = new int[size];
for (int i = 0; i < size; i++) {
iArr[i] = list.get(i).intValue();
}
return iArr;
}
public static boolean isInternalUri(Uri uri) {
String path = uri.getPath();
if (path == null) {
return false;
}
if (path.matches(Pattern.quote(new File(ApplicationLoader.applicationContext.getCacheDir(), "voip_logs").getAbsolutePath()) + "/\\d+\\.log")) {
return false;
}
int i = 0;
while (true) {
if (path != null && path.length() > 4096) {
return true;
}
try {
String readlink = Utilities.readlink(path);
if (readlink == null || readlink.equals(path)) {
break;
}
i++;
if (i >= 10) {
return true;
}
path = readlink;
} catch (Throwable unused) {
return true;
}
}
if (path != null) {
try {
String canonicalPath = new File(path).getCanonicalPath();
if (canonicalPath != null) {
path = canonicalPath;
}
} catch (Exception unused2) {
path.replace("/./", "/");
}
}
if (path.endsWith(".attheme") || path == null) {
return false;
}
String lowerCase = path.toLowerCase();
StringBuilder sb = new StringBuilder();
sb.append("/data/data/");
sb.append(ApplicationLoader.applicationContext.getPackageName());
return lowerCase.contains(sb.toString());
}
public static void lockOrientation(Activity activity) {
if (activity == null || prevOrientation != -10) {
return;
}
try {
prevOrientation = activity.getRequestedOrientation();
WindowManager windowManager = (WindowManager) activity.getSystemService("window");
if (windowManager != null && windowManager.getDefaultDisplay() != null) {
int rotation = windowManager.getDefaultDisplay().getRotation();
int i = activity.getResources().getConfiguration().orientation;
if (rotation == 3) {
if (i == 1) {
activity.setRequestedOrientation(1);
} else {
activity.setRequestedOrientation(8);
}
} else if (rotation == 1) {
if (i == 1) {
activity.setRequestedOrientation(9);
} else {
activity.setRequestedOrientation(0);
}
} else if (rotation == 0) {
if (i == 2) {
activity.setRequestedOrientation(0);
} else {
activity.setRequestedOrientation(1);
}
} else if (i == 2) {
activity.setRequestedOrientation(8);
} else {
activity.setRequestedOrientation(9);
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
public static void unlockOrientation(Activity activity) {
if (activity == null) {
return;
}
try {
if (prevOrientation != -10) {
activity.setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e(e);
}
}
private static class VcardData {
String name;
ArrayList<String> phones;
StringBuilder vcard;
private VcardData() {
this.phones = new ArrayList<>();
this.vcard = new StringBuilder();
}
}
public static class VcardItem {
public int type;
public ArrayList<String> vcardData = new ArrayList<>();
public String fullData = "";
public boolean checked = true;
public String[] getRawValue() {
byte[] decodeQuotedPrintable;
int indexOf = this.fullData.indexOf(58);
if (indexOf < 0) {
return new String[0];
}
String substring = this.fullData.substring(0, indexOf);
String substring2 = this.fullData.substring(indexOf + 1);
String str = null;
String str2 = "UTF-8";
for (String str3 : substring.split(";")) {
String[] split = str3.split("=");
if (split.length == 2) {
if (split[0].equals("CHARSET")) {
str2 = split[1];
} else if (split[0].equals("ENCODING")) {
str = split[1];
}
}
}
String[] split2 = substring2.split(";");
for (int i = 0; i < split2.length; i++) {
if (!TextUtils.isEmpty(split2[i]) && str != null && str.equalsIgnoreCase("QUOTED-PRINTABLE") && (decodeQuotedPrintable = AndroidUtilities.decodeQuotedPrintable(AndroidUtilities.getStringBytes(split2[i]))) != null && decodeQuotedPrintable.length != 0) {
try {
split2[i] = new String(decodeQuotedPrintable, str2);
} catch (Exception unused) {
}
}
}
return split2;
}
public String getValue(boolean z) {
byte[] decodeQuotedPrintable;
StringBuilder sb = new StringBuilder();
int indexOf = this.fullData.indexOf(58);
if (indexOf < 0) {
return "";
}
if (sb.length() > 0) {
sb.append(", ");
}
String substring = this.fullData.substring(0, indexOf);
String substring2 = this.fullData.substring(indexOf + 1);
String str = null;
String str2 = "UTF-8";
for (String str3 : substring.split(";")) {
String[] split = str3.split("=");
if (split.length == 2) {
if (split[0].equals("CHARSET")) {
str2 = split[1];
} else if (split[0].equals("ENCODING")) {
str = split[1];
}
}
}
String[] split2 = substring2.split(";");
boolean z2 = false;
for (int i = 0; i < split2.length; i++) {
if (!TextUtils.isEmpty(split2[i])) {
if (str != null && str.equalsIgnoreCase("QUOTED-PRINTABLE") && (decodeQuotedPrintable = AndroidUtilities.decodeQuotedPrintable(AndroidUtilities.getStringBytes(split2[i]))) != null && decodeQuotedPrintable.length != 0) {
try {
split2[i] = new String(decodeQuotedPrintable, str2);
} catch (Exception unused) {
}
}
if (z2 && sb.length() > 0) {
sb.append(" ");
}
sb.append(split2[i]);
if (!z2) {
z2 = split2[i].length() > 0;
}
}
}
if (z) {
int i2 = this.type;
if (i2 == 0) {
return PhoneFormat.getInstance().format(sb.toString());
}
if (i2 == 5) {
String[] split3 = sb.toString().split(ExifInterface.GPS_DIRECTION_TRUE);
if (split3.length > 0) {
String[] split4 = split3[0].split("-");
if (split4.length == 3) {
Calendar calendar = Calendar.getInstance();
calendar.set(1, Utilities.parseInt(split4[0]).intValue());
calendar.set(2, Utilities.parseInt(split4[1]).intValue() - 1);
calendar.set(5, Utilities.parseInt(split4[2]).intValue());
return LocaleController.getInstance().formatterYearMax.format(calendar.getTime());
}
}
}
}
return sb.toString();
}
public String getRawType(boolean z) {
int indexOf = this.fullData.indexOf(58);
if (indexOf < 0) {
return "";
}
String substring = this.fullData.substring(0, indexOf);
if (this.type == 20) {
String[] split = substring.substring(2).split(";");
if (z) {
return split[0];
}
return split.length > 1 ? split[split.length - 1] : "";
}
String[] split2 = substring.split(";");
for (int i = 0; i < split2.length; i++) {
if (split2[i].indexOf(61) < 0) {
substring = split2[i];
}
}
return substring;
}
public String getType() {
int i = this.type;
if (i == 5) {
return LocaleController.getString("ContactBirthday", R.string.ContactBirthday);
}
if (i == 6) {
if ("ORG".equalsIgnoreCase(getRawType(true))) {
return LocaleController.getString("ContactJob", R.string.ContactJob);
}
return LocaleController.getString("ContactJobTitle", R.string.ContactJobTitle);
}
int indexOf = this.fullData.indexOf(58);
if (indexOf < 0) {
return "";
}
String substring = this.fullData.substring(0, indexOf);
if (this.type == 20) {
substring = substring.substring(2).split(";")[0];
} else {
String[] split = substring.split(";");
for (int i2 = 0; i2 < split.length; i2++) {
if (split[i2].indexOf(61) < 0) {
substring = split[i2];
}
}
if (substring.startsWith("X-")) {
substring = substring.substring(2);
}
char c = 65535;
switch (substring.hashCode()) {
case -2015525726:
if (substring.equals("MOBILE")) {
c = 2;
break;
}
break;
case 2064738:
if (substring.equals("CELL")) {
c = 3;
break;
}
break;
case 2223327:
if (substring.equals("HOME")) {
c = 1;
break;
}
break;
case 2464291:
if (substring.equals("PREF")) {
c = 0;
break;
}
break;
case 2670353:
if (substring.equals("WORK")) {
c = 5;
break;
}
break;
case 75532016:
if (substring.equals("OTHER")) {
c = 4;
break;
}
break;
}
if (c == 0) {
substring = LocaleController.getString("PhoneMain", R.string.PhoneMain);
} else if (c == 1) {
substring = LocaleController.getString("PhoneHome", R.string.PhoneHome);
} else if (c == 2 || c == 3) {
substring = LocaleController.getString("PhoneMobile", R.string.PhoneMobile);
} else if (c == 4) {
substring = LocaleController.getString("PhoneOther", R.string.PhoneOther);
} else if (c == 5) {
substring = LocaleController.getString("PhoneWork", R.string.PhoneWork);
}
}
return substring.substring(0, 1).toUpperCase() + substring.substring(1).toLowerCase();
}
}
public static byte[] getStringBytes(String str) {
try {
return str.getBytes("UTF-8");
} catch (Exception unused) {
return new byte[0];
}
}
public static ArrayList<TLRPC.User> loadVCardFromStream(Uri uri, int i, boolean z, ArrayList<VcardItem> arrayList, String str) {
InputStream createInputStream;
char c;
String[] strArr;
byte[] decodeQuotedPrintable;
VcardItem vcardItem;
ArrayList<VcardItem> arrayList2 = arrayList;
ArrayList<TLRPC.User> arrayList3 = null;
AnonymousClass1 anonymousClass1 = 0;
if (z) {
try {
createInputStream = ApplicationLoader.applicationContext.getContentResolver().openAssetFileDescriptor(uri, "r").createInputStream();
} catch (Throwable th) {
th = th;
FileLog.e(th);
return arrayList3;
}
} else {
try {
createInputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
} catch (Throwable th2) {
th = th2;
arrayList3 = null;
FileLog.e(th);
return arrayList3;
}
}
ArrayList arrayList4 = new ArrayList();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(createInputStream, "UTF-8"));
int i2 = 0;
VcardData vcardData = null;
String str2 = null;
VcardItem vcardItem2 = null;
boolean z2 = false;
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
if (readLine.startsWith("PHOTO")) {
z2 = true;
} else {
if (readLine.indexOf(58) >= 0) {
if (readLine.startsWith("BEGIN:VCARD")) {
vcardData = new VcardData();
arrayList4.add(vcardData);
vcardData.name = str;
} else if (!readLine.startsWith("END:VCARD") && arrayList2 != null) {
if (readLine.startsWith("TEL")) {
vcardItem = new VcardItem();
vcardItem.type = i2;
} else if (readLine.startsWith("EMAIL")) {
vcardItem = new VcardItem();
vcardItem.type = 1;
} else {
if (!readLine.startsWith("ADR") && !readLine.startsWith("LABEL") && !readLine.startsWith("GEO")) {
if (readLine.startsWith("URL")) {
vcardItem = new VcardItem();
vcardItem.type = 3;
} else if (readLine.startsWith("NOTE")) {
vcardItem = new VcardItem();
vcardItem.type = 4;
} else if (readLine.startsWith("BDAY")) {
vcardItem = new VcardItem();
vcardItem.type = 5;
} else {
if (!readLine.startsWith("ORG") && !readLine.startsWith("TITLE") && !readLine.startsWith("ROLE")) {
if (readLine.startsWith("X-ANDROID")) {
vcardItem = new VcardItem();
vcardItem.type = -1;
} else {
if (!readLine.startsWith("X-PHONETIC") && readLine.startsWith("X-")) {
vcardItem = new VcardItem();
vcardItem.type = 20;
}
vcardItem2 = anonymousClass1;
if (vcardItem2 != null && vcardItem2.type >= 0) {
arrayList2.add(vcardItem2);
}
z2 = false;
}
}
vcardItem = new VcardItem();
vcardItem.type = 6;
}
}
vcardItem = new VcardItem();
vcardItem.type = 2;
}
vcardItem2 = vcardItem;
if (vcardItem2 != null) {
arrayList2.add(vcardItem2);
}
z2 = false;
}
vcardItem2 = anonymousClass1;
z2 = false;
}
if (!z2 && vcardData != null) {
if (vcardItem2 == null) {
if (vcardData.vcard.length() > 0) {
vcardData.vcard.append('\n');
}
vcardData.vcard.append(readLine);
} else {
vcardItem2.vcardData.add(readLine);
}
}
if (str2 != null) {
readLine = str2 + readLine;
str2 = null;
}
String str3 = "=";
if (readLine.contains("=QUOTED-PRINTABLE") && readLine.endsWith("=")) {
str2 = readLine.substring(i2, readLine.length() - 1);
anonymousClass1 = 0;
} else {
if (!z2 && vcardData != null && vcardItem2 != null) {
vcardItem2.fullData = readLine;
}
int indexOf = readLine.indexOf(LogUtils.COLON);
if (indexOf >= 0) {
strArr = new String[]{readLine.substring(0, indexOf), readLine.substring(indexOf + 1).trim()};
c = 0;
} else {
c = 0;
strArr = new String[]{readLine.trim()};
}
if (strArr.length >= 2 && vcardData != null) {
if (!strArr[c].startsWith("FN") && (!strArr[c].startsWith("ORG") || !TextUtils.isEmpty(vcardData.name))) {
if (strArr[0].startsWith("TEL")) {
vcardData.phones.add(strArr[1]);
}
}
String[] split = strArr[0].split(";");
int length = split.length;
int i3 = 0;
String str4 = null;
String str5 = null;
while (i3 < length) {
int i4 = length;
String[] split2 = split[i3].split(str3);
String[] strArr2 = split;
String str6 = str3;
if (split2.length == 2) {
if (split2[0].equals("CHARSET")) {
str5 = split2[1];
} else if (split2[0].equals("ENCODING")) {
str4 = split2[1];
}
}
i3++;
length = i4;
split = strArr2;
str3 = str6;
}
vcardData.name = strArr[1];
if (str4 != null && str4.equalsIgnoreCase("QUOTED-PRINTABLE") && (decodeQuotedPrintable = decodeQuotedPrintable(getStringBytes(vcardData.name))) != null && decodeQuotedPrintable.length != 0) {
vcardData.name = new String(decodeQuotedPrintable, str5);
}
arrayList2 = arrayList;
anonymousClass1 = 0;
i2 = 0;
}
arrayList2 = arrayList;
anonymousClass1 = 0;
i2 = 0;
}
}
} else {
try {
break;
} catch (Exception e) {
FileLog.e(e);
}
}
}
bufferedReader.close();
createInputStream.close();
arrayList3 = null;
for (int i5 = 0; i5 < arrayList4.size(); i5++) {
VcardData vcardData2 = (VcardData) arrayList4.get(i5);
if (vcardData2.name != null && !vcardData2.phones.isEmpty()) {
if (arrayList3 == null) {
arrayList3 = new ArrayList<>();
}
String str7 = vcardData2.phones.get(0);
int i6 = 0;
while (true) {
if (i6 >= vcardData2.phones.size()) {
break;
}
String str8 = vcardData2.phones.get(i6);
if (ContactsController.getInstance(i).contactsByShortPhone.get(str8.substring(Math.max(0, str8.length() - 7))) != null) {
str7 = str8;
break;
}
i6++;
}
TLRPC.TL_userContact_old2 tL_userContact_old2 = new TLRPC.TL_userContact_old2();
tL_userContact_old2.phone = str7;
tL_userContact_old2.first_name = vcardData2.name;
tL_userContact_old2.last_name = "";
tL_userContact_old2.id = 0;
TLRPC.TL_restrictionReason tL_restrictionReason = new TLRPC.TL_restrictionReason();
tL_restrictionReason.text = vcardData2.vcard.toString();
tL_restrictionReason.platform = "";
tL_restrictionReason.reason = "";
tL_userContact_old2.restriction_reason.add(tL_restrictionReason);
arrayList3.add(tL_userContact_old2);
}
}
return arrayList3;
}
public static Typeface getTypeface(String str) {
Typeface createFromAsset;
Typeface typeface;
synchronized (typefaceCache) {
if (!typefaceCache.containsKey(str)) {
try {
if (Build.VERSION.SDK_INT >= 26) {
Typeface.Builder builder = new Typeface.Builder(ApplicationLoader.applicationContext.getAssets(), str);
if (str.contains("medium")) {
builder.setWeight(HardwareConfigState.DEFAULT_MAXIMUM_FDS_FOR_HARDWARE_CONFIGS);
}
if (str.contains(TtmlNode.ITALIC)) {
builder.setItalic(true);
}
createFromAsset = builder.build();
} else {
createFromAsset = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), str);
}
typefaceCache.put(str, createFromAsset);
} catch (Exception e) {
if (BuildVars.LOGS_ENABLED) {
FileLog.e("Could not get typeface '" + str + "' because " + e.getMessage());
}
return null;
}
}
typeface = typefaceCache.get(str);
}
return typeface;
}
public static boolean isWaitingForSms() {
boolean z;
synchronized (smsLock) {
z = waitingForSms;
}
return z;
}
public static void setWaitingForSms(boolean z) {
synchronized (smsLock) {
waitingForSms = z;
if (z) {
SmsRetriever.getClient(ApplicationLoader.applicationContext).startSmsRetriever().addOnSuccessListener(new OnSuccessListener() {
@Override
public final void onSuccess(Object obj) {
AndroidUtilities.lambda$setWaitingForSms$1((Void) obj);
}
});
}
}
}
public static void lambda$setWaitingForSms$1(Void r0) {
if (BuildVars.DEBUG_VERSION) {
FileLog.d("sms listener registered");
}
}
public static int getShadowHeight() {
float f = density;
if (f >= 4.0f) {
return 3;
}
return f >= 2.0f ? 2 : 1;
}
public static boolean isWaitingForCall() {
boolean z;
synchronized (callLock) {
z = waitingForCall;
}
return z;
}
public static void setWaitingForCall(boolean z) {
synchronized (callLock) {
waitingForCall = z;
}
}
public static boolean showKeyboard(View view) {
if (view == null) {
return false;
}
try {
return ((InputMethodManager) view.getContext().getSystemService("input_method")).showSoftInput(view, 1);
} catch (Exception e) {
FileLog.e(e);
return false;
}
}
public static boolean isKeyboardShowed(View view) {
if (view == null) {
return false;
}
try {
return ((InputMethodManager) view.getContext().getSystemService("input_method")).isActive(view);
} catch (Exception e) {
FileLog.e(e);
return false;
}
}
public static String[] getCurrentKeyboardLanguage() {
String str;
try {
InputMethodManager inputMethodManager = (InputMethodManager) ApplicationLoader.applicationContext.getSystemService("input_method");
InputMethodSubtype currentInputMethodSubtype = inputMethodManager.getCurrentInputMethodSubtype();
String str2 = null;
if (currentInputMethodSubtype != null) {
str = Build.VERSION.SDK_INT >= 24 ? currentInputMethodSubtype.getLanguageTag() : null;
if (TextUtils.isEmpty(str)) {
str = currentInputMethodSubtype.getLocale();
}
} else {
InputMethodSubtype lastInputMethodSubtype = inputMethodManager.getLastInputMethodSubtype();
if (lastInputMethodSubtype != null) {
String languageTag = Build.VERSION.SDK_INT >= 24 ? lastInputMethodSubtype.getLanguageTag() : null;
str = TextUtils.isEmpty(languageTag) ? lastInputMethodSubtype.getLocale() : languageTag;
} else {
str = null;
}
}
if (!TextUtils.isEmpty(str)) {
return new String[]{str.replace('_', '-')};
}
String systemLocaleStringIso639 = LocaleController.getSystemLocaleStringIso639();
LocaleController.LocaleInfo currentLocaleInfo = LocaleController.getInstance().getCurrentLocaleInfo();
String baseLangCode = currentLocaleInfo.getBaseLangCode();
if (TextUtils.isEmpty(baseLangCode)) {
baseLangCode = currentLocaleInfo.getLangCode();
}
if (!systemLocaleStringIso639.contains(baseLangCode) && !baseLangCode.contains(systemLocaleStringIso639)) {
str2 = baseLangCode;
return TextUtils.isEmpty(str2) ? new String[]{systemLocaleStringIso639.replace('_', '-'), str2} : new String[]{systemLocaleStringIso639.replace('_', '-')};
}
if (!systemLocaleStringIso639.contains("en")) {
str2 = "en";
}
if (TextUtils.isEmpty(str2)) {
}
} catch (Exception unused) {
return new String[]{"en"};
}
}
public static void hideKeyboard(View view) {
if (view == null) {
return;
}
try {
InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService("input_method");
if (inputMethodManager.isActive()) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} catch (Exception e) {
FileLog.e(e);
}
}
public static File getCacheDir() {
String str;
try {
str = Environment.getExternalStorageState();
} catch (Exception e) {
FileLog.e(e);
str = null;
}
if (str == null || str.startsWith("mounted")) {
try {
File externalCacheDir = ApplicationLoader.applicationContext.getExternalCacheDir();
if (externalCacheDir != null) {
return externalCacheDir;
}
} catch (Exception e2) {
FileLog.e(e2);
}
}
try {
File cacheDir = ApplicationLoader.applicationContext.getCacheDir();
if (cacheDir != null) {
return cacheDir;
}
} catch (Exception e3) {
FileLog.e(e3);
}
return new File("");
}
public static int dp(float f) {
if (f == 0.0f) {
return 0;
}
return (int) Math.ceil(density * f);
}
public static int dpr(float f) {
if (f == 0.0f) {
return 0;
}
return Math.round(density * f);
}
public static int dp2(float f) {
if (f == 0.0f) {
return 0;
}
return (int) Math.floor(density * f);
}
public static float dpf2(float f) {
if (f == 0.0f) {
return 0.0f;
}
return density * f;
}
public static float sp2px(float f) {
if (f == 0.0f || ApplicationLoader.applicationContext == null) {
return 0.0f;
}
return (f * ApplicationLoader.applicationContext.getResources().getDisplayMetrics().scaledDensity) + 0.5f;
}
public static void checkDisplaySize(Context context, Configuration configuration) {
Display defaultDisplay;
try {
int i = (int) density;
float f = context.getResources().getDisplayMetrics().density;
density = f;
int i2 = (int) f;
if (firstConfigurationWas && i != i2) {
Theme.reloadAllResources(context);
}
boolean z = true;
firstConfigurationWas = true;
if (configuration == null) {
configuration = context.getResources().getConfiguration();
}
if (configuration.keyboard == 1 || configuration.hardKeyboardHidden != 1) {
z = false;
}
usingHardwareInput = z;
WindowManager windowManager = (WindowManager) context.getSystemService("window");
if (windowManager != null && (defaultDisplay = windowManager.getDefaultDisplay()) != null) {
defaultDisplay.getMetrics(displayMetrics);
defaultDisplay.getSize(displaySize);
}
if (configuration.screenWidthDp != 0) {
int ceil = (int) Math.ceil(configuration.screenWidthDp * density);
if (Math.abs(displaySize.x - ceil) > 3) {
displaySize.x = ceil;
}
}
if (configuration.screenHeightDp != 0) {
int ceil2 = (int) Math.ceil(configuration.screenHeightDp * density);
if (Math.abs(displaySize.y - ceil2) > 3) {
displaySize.y = ceil2;
}
}
if (roundMessageSize == 0) {
if (isTablet()) {
roundMessageSize = (int) (getMinTabletSide() * 0.6f);
} else {
roundMessageSize = (int) (Math.min(displaySize.x, displaySize.y) * 0.6f);
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.e("display size = " + displaySize.x + " " + displaySize.y + " " + displayMetrics.xdpi + "x" + displayMetrics.ydpi);
}
} catch (Exception e) {
FileLog.e(e);
}
}
public static double fixLocationCoord(double d) {
double d2 = (long) (d * 1000000.0d);
Double.isNaN(d2);
return d2 / 1000000.0d;
}
public static String formapMapUrl(int i, double d, double d2, int i2, int i3, boolean z, int i4) {
int min = Math.min(2, (int) Math.ceil(density));
int i5 = MessagesController.getInstance(i).mapProvider;
if (i5 == 1 || i5 == 3) {
String str = null;
String[] strArr = {"ru_RU", "tr_TR"};
LocaleController.LocaleInfo currentLocaleInfo = LocaleController.getInstance().getCurrentLocaleInfo();
for (int i6 = 0; i6 < 2; i6++) {
if (strArr[i6].toLowerCase().contains(currentLocaleInfo.shortName)) {
str = strArr[i6];
}
}
if (str == null) {
str = "en_US";
}
return z ? String.format(Locale.US, "https://static-maps.yandex.ru/1.x/?ll=%.6f,%.6f&z=%d&size=%d,%d&l=map&scale=%d&pt=%.6f,%.6f,vkbkm&lang=%s", Double.valueOf(d2), Double.valueOf(d), Integer.valueOf(i4), Integer.valueOf(i2 * min), Integer.valueOf(i3 * min), Integer.valueOf(min), Double.valueOf(d2), Double.valueOf(d), str) : String.format(Locale.US, "https://static-maps.yandex.ru/1.x/?ll=%.6f,%.6f&z=%d&size=%d,%d&l=map&scale=%d&lang=%s", Double.valueOf(d2), Double.valueOf(d), Integer.valueOf(i4), Integer.valueOf(i2 * min), Integer.valueOf(i3 * min), Integer.valueOf(min), str);
}
String string = ApplicationLoader.applicationContext.getResources().getString(R.string.baidu_map_key);
String string2 = ApplicationLoader.applicationContext.getResources().getString(R.string.baidu_map_code);
return z ? String.format(Locale.US, "http://api.map.baidu.com/staticimage/v2?ak=%s&mcode=%s¢er=%.6f,%.6f&width=%d&height=%d&zoom=%d&scale=%d&coordtype=gcj02ll©right=1&dpiType=ph&markers=%.6f,%.6f&markerStyles=l,,red", string, string2, Double.valueOf(d2), Double.valueOf(d), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(min), Double.valueOf(d2), Double.valueOf(d)) : String.format(Locale.US, "http://api.map.baidu.com/staticimage/v2?ak=%s&mcode=%s¢er=%.6f,%.6f&width=%d&height=%d&zoom=%d&scale=%d&coordtype=gcj02ll©right=1&dpiType=ph", string, string2, Double.valueOf(d2), Double.valueOf(d), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(min));
}
public static float getPixelsInCM(float f, boolean z) {
return (f / 2.54f) * (z ? displayMetrics.xdpi : displayMetrics.ydpi);
}
public static void runOnUIThread(Runnable runnable) {
runOnUIThread(runnable, 0L);
}
public static void runOnUIThread(Runnable runnable, long j) {
if (j == 0) {
ApplicationLoader.applicationHandler.post(runnable);
} else {
ApplicationLoader.applicationHandler.postDelayed(runnable, j);
}
}
public static void cancelRunOnUIThread(Runnable runnable) {
ApplicationLoader.applicationHandler.removeCallbacks(runnable);
}
public static boolean isTablet() {
if (isTablet == null) {
isTablet = Boolean.valueOf(ApplicationLoader.applicationContext.getResources().getBoolean(R.bool.isTablet));
}
return isTablet.booleanValue();
}
public static boolean isSmallTablet() {
return ((float) Math.min(displaySize.x, displaySize.y)) / density <= 700.0f;
}
public static int getMinTabletSide() {
if (!isSmallTablet()) {
int min = Math.min(displaySize.x, displaySize.y);
int i = (min * 35) / 100;
if (i < dp(320.0f)) {
i = dp(320.0f);
}
return min - i;
}
int min2 = Math.min(displaySize.x, displaySize.y);
int max = Math.max(displaySize.x, displaySize.y);
int i2 = (max * 35) / 100;
if (i2 < dp(320.0f)) {
i2 = dp(320.0f);
}
return Math.min(min2, max - i2);
}
public static int getPhotoSize() {
if (photoSize == null) {
photoSize = 1280;
}
return photoSize.intValue();
}
public static void endIncomingCall() {
if (hasCallPermissions) {
try {
TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService("phone");
Method declaredMethod = Class.forName(telephonyManager.getClass().getName()).getDeclaredMethod("getITelephony", new Class[0]);
declaredMethod.setAccessible(true);
ITelephony iTelephony = (ITelephony) declaredMethod.invoke(telephonyManager, new Object[0]);
ITelephony iTelephony2 = (ITelephony) declaredMethod.invoke(telephonyManager, new Object[0]);
iTelephony2.silenceRinger();
iTelephony2.endCall();
} catch (Throwable th) {
FileLog.e(th);
}
}
}
public static String obtainLoginPhoneCall(String str) {
if (hasCallPermissions) {
try {
Cursor query = ApplicationLoader.applicationContext.getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[]{"number", "date"}, "type IN (3,1,5)", null, "date DESC LIMIT 5");
while (query.moveToNext()) {
String string = query.getString(0);
long j = query.getLong(1);
if (BuildVars.LOGS_ENABLED) {
FileLog.e("number = " + string);
}
if (Math.abs(System.currentTimeMillis() - j) < 3600000 && checkPhonePattern(str, string)) {
if (query != null) {
query.close();
}
return string;
}
}
if (query != null) {
query.close();
}
} catch (Exception e) {
FileLog.e(e);
}
return null;
}
return null;
}
public static boolean checkPhonePattern(String str, String str2) {
if (!TextUtils.isEmpty(str) && !str.equals("*")) {
String[] split = str.split("\\*");
String stripExceptNumbers = PhoneFormat.stripExceptNumbers(str2);
int i = 0;
for (String str3 : split) {
if (!TextUtils.isEmpty(str3)) {
int indexOf = stripExceptNumbers.indexOf(str3, i);
if (indexOf == -1) {
return false;
}
i = indexOf + str3.length();
}
}
}
return true;
}
public static int getViewInset(View view) {
if (view != null && Build.VERSION.SDK_INT >= 21 && view.getHeight() != displaySize.y && view.getHeight() != displaySize.y - statusBarHeight) {
try {
if (mAttachInfoField == null) {
Field declaredField = View.class.getDeclaredField("mAttachInfo");
mAttachInfoField = declaredField;
declaredField.setAccessible(true);
}
Object obj = mAttachInfoField.get(view);
if (obj != null) {
if (mStableInsetsField == null) {
Field declaredField2 = obj.getClass().getDeclaredField("mStableInsets");
mStableInsetsField = declaredField2;
declaredField2.setAccessible(true);
}
return ((Rect) mStableInsetsField.get(obj)).bottom;
}
} catch (Exception e) {
FileLog.e(e);
}
}
return 0;
}
public static Point getRealScreenSize() {
Point point = new Point();
try {
WindowManager windowManager = (WindowManager) ApplicationLoader.applicationContext.getSystemService("window");
if (Build.VERSION.SDK_INT >= 17) {
windowManager.getDefaultDisplay().getRealSize(point);
} else {
try {
point.set(((Integer) Display.class.getMethod("getRawWidth", new Class[0]).invoke(windowManager.getDefaultDisplay(), new Object[0])).intValue(), ((Integer) Display.class.getMethod("getRawHeight", new Class[0]).invoke(windowManager.getDefaultDisplay(), new Object[0])).intValue());
} catch (Exception e) {
point.set(windowManager.getDefaultDisplay().getWidth(), windowManager.getDefaultDisplay().getHeight());
FileLog.e(e);
}
}
} catch (Exception e2) {
FileLog.e(e2);
}
return point;
}
public static void setEnabled(View view, boolean z) {
if (view == null) {
return;
}
view.setEnabled(z);
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
setEnabled(viewGroup.getChildAt(i), z);
}
}
}
public static CharSequence getTrimmedString(CharSequence charSequence) {
if (charSequence != null && charSequence.length() != 0) {
while (charSequence.length() > 0 && (charSequence.charAt(0) == '\n' || charSequence.charAt(0) == ' ')) {
charSequence = charSequence.subSequence(1, charSequence.length());
}
while (charSequence.length() > 0 && (charSequence.charAt(charSequence.length() - 1) == '\n' || charSequence.charAt(charSequence.length() - 1) == ' ')) {
charSequence = charSequence.subSequence(0, charSequence.length() - 1);
}
}
return charSequence;
}
public static void setViewPagerEdgeEffectColor(ViewPager viewPager, int i) {
if (Build.VERSION.SDK_INT >= 21) {
try {
Field declaredField = ViewPager.class.getDeclaredField("mLeftEdge");
declaredField.setAccessible(true);
EdgeEffect edgeEffect = (EdgeEffect) declaredField.get(viewPager);
if (edgeEffect != null) {
edgeEffect.setColor(i);
}
Field declaredField2 = ViewPager.class.getDeclaredField("mRightEdge");
declaredField2.setAccessible(true);
EdgeEffect edgeEffect2 = (EdgeEffect) declaredField2.get(viewPager);
if (edgeEffect2 != null) {
edgeEffect2.setColor(i);
}
} catch (Exception unused) {
}
}
}
public static void setScrollViewEdgeEffectColor(HorizontalScrollView horizontalScrollView, int i) {
if (Build.VERSION.SDK_INT >= 21) {
try {
Field declaredField = HorizontalScrollView.class.getDeclaredField("mEdgeGlowLeft");
declaredField.setAccessible(true);
EdgeEffect edgeEffect = (EdgeEffect) declaredField.get(horizontalScrollView);
if (edgeEffect != null) {
edgeEffect.setColor(i);
}
Field declaredField2 = HorizontalScrollView.class.getDeclaredField("mEdgeGlowRight");
declaredField2.setAccessible(true);
EdgeEffect edgeEffect2 = (EdgeEffect) declaredField2.get(horizontalScrollView);
if (edgeEffect2 != null) {
edgeEffect2.setColor(i);
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
public static void setScrollViewEdgeEffectColor(ScrollView scrollView, int i) {
if (Build.VERSION.SDK_INT >= 21) {
try {
Field declaredField = ScrollView.class.getDeclaredField("mEdgeGlowTop");
declaredField.setAccessible(true);
EdgeEffect edgeEffect = (EdgeEffect) declaredField.get(scrollView);
if (edgeEffect != null) {
edgeEffect.setColor(i);
}
Field declaredField2 = ScrollView.class.getDeclaredField("mEdgeGlowBottom");
declaredField2.setAccessible(true);
EdgeEffect edgeEffect2 = (EdgeEffect) declaredField2.get(scrollView);
if (edgeEffect2 != null) {
edgeEffect2.setColor(i);
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
public static void clearDrawableAnimation(View view) {
if (Build.VERSION.SDK_INT < 21 || view == null) {
return;
}
if (view instanceof ListView) {
Drawable selector = ((ListView) view).getSelector();
if (selector != null) {
selector.setState(StateSet.NOTHING);
return;
}
return;
}
Drawable background = view.getBackground();
if (background != null) {
background.setState(StateSet.NOTHING);
background.jumpToCurrentState();
}
}
public static SpannableStringBuilder replaceTags(String str) {
return replaceTags(str, 11, new Object[0]);
}
public static SpannableStringBuilder replaceTags(String str, int i, Object... objArr) {
try {
StringBuilder sb = new StringBuilder(str);
if ((i & 1) != 0) {
while (true) {
int indexOf = sb.indexOf("<br>");
if (indexOf == -1) {
break;
}
sb.replace(indexOf, indexOf + 4, "\n");
}
while (true) {
int indexOf2 = sb.indexOf("<br/>");
if (indexOf2 == -1) {
break;
}
sb.replace(indexOf2, indexOf2 + 5, "\n");
}
}
ArrayList arrayList = new ArrayList();
if ((i & 2) != 0) {
while (true) {
int indexOf3 = sb.indexOf("<b>");
if (indexOf3 == -1) {
break;
}
sb.replace(indexOf3, indexOf3 + 3, "");
int indexOf4 = sb.indexOf("</b>");
if (indexOf4 == -1) {
indexOf4 = sb.indexOf("<b>");
}
sb.replace(indexOf4, indexOf4 + 4, "");
arrayList.add(Integer.valueOf(indexOf3));
arrayList.add(Integer.valueOf(indexOf4));
}
while (true) {
int indexOf5 = sb.indexOf("**");
if (indexOf5 == -1) {
break;
}
sb.replace(indexOf5, indexOf5 + 2, "");
int indexOf6 = sb.indexOf("**");
if (indexOf6 >= 0) {
sb.replace(indexOf6, indexOf6 + 2, "");
arrayList.add(Integer.valueOf(indexOf5));
arrayList.add(Integer.valueOf(indexOf6));
}
}
}
if ((i & 8) != 0) {
while (true) {
int indexOf7 = sb.indexOf("**");
if (indexOf7 == -1) {
break;
}
sb.replace(indexOf7, indexOf7 + 2, "");
int indexOf8 = sb.indexOf("**");
if (indexOf8 >= 0) {
sb.replace(indexOf8, indexOf8 + 2, "");
arrayList.add(Integer.valueOf(indexOf7));
arrayList.add(Integer.valueOf(indexOf8));
}
}
}
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sb);
for (int i2 = 0; i2 < arrayList.size() / 2; i2++) {
int i3 = i2 * 2;
spannableStringBuilder.setSpan(new TypefaceSpan(getTypeface("fonts/rmedium.ttf")), ((Integer) arrayList.get(i3)).intValue(), ((Integer) arrayList.get(i3 + 1)).intValue(), 33);
}
return spannableStringBuilder;
} catch (Exception e) {
FileLog.e(e);
return new SpannableStringBuilder(str);
}
}
public static class LinkMovementMethodMy extends LinkMovementMethod {
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent motionEvent) {
try {
boolean onTouchEvent = super.onTouchEvent(textView, spannable, motionEvent);
if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
Selection.removeSelection(spannable);
}
return onTouchEvent;
} catch (Exception e) {
FileLog.e(e);
return false;
}
}
}
public static boolean needShowPasscode() {
return needShowPasscode(false);
}
public static boolean needShowPasscode(boolean z) {
boolean isWasInBackground = ForegroundDetector.getInstance().isWasInBackground(z);
if (z) {
ForegroundDetector.getInstance().resetBackgroundVar();
}
return SharedConfig.passcodeHash.length() > 0 && isWasInBackground && (SharedConfig.appLocked || (!(SharedConfig.autoLockIn == 0 || SharedConfig.lastPauseTime == 0 || SharedConfig.appLocked || SharedConfig.lastPauseTime + SharedConfig.autoLockIn > ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime()) || ConnectionsManager.getInstance(UserConfig.selectedAccount).getCurrentTime() + 5 < SharedConfig.lastPauseTime));
}
public static void shakeView(final View view, final float f, final int i) {
if (view == null) {
return;
}
if (i == 6) {
view.setTranslationX(0.0f);
return;
}
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(view, "translationX", dp(f)));
animatorSet.setDuration(50L);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
AndroidUtilities.shakeView(view, i == 5 ? 0.0f : -f, i + 1);
}
});
animatorSet.start();
}
public static void checkForUpdates(Activity activity) {
boolean z = BuildVars.DEBUG_VERSION;
}
public static void unregisterUpdates() {
boolean z = BuildVars.DEBUG_VERSION;
}
public static void addToClipboard(CharSequence charSequence) {
try {
((ClipboardManager) ApplicationLoader.applicationContext.getSystemService("clipboard")).setPrimaryClip(ClipData.newPlainText("label", charSequence));
} catch (Exception e) {
FileLog.e(e);
}
}
public static void addMediaToGallery(String str) {
if (str == null) {
return;
}
addMediaToGallery(Uri.fromFile(new File(str)));
}
public static void addMediaToGallery(Uri uri) {
if (uri == null) {
return;
}
try {
Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
intent.setData(uri);
ApplicationLoader.applicationContext.sendBroadcast(intent);
} catch (Exception e) {
FileLog.e(e);
}
}
public static File getAlbumDir(boolean z) {
if (z || (Build.VERSION.SDK_INT >= 23 && ApplicationLoader.applicationContext.checkSelfPermission(PermissionUtils.EXTERNAL_STORAGE) != 0)) {
return FileLoader.getDirectory(4);
}
if ("mounted".equals(Environment.getExternalStorageState())) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Sheng");
if (file.mkdirs() || file.exists()) {
return file;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("failed to create directory");
}
File externalFilesDir = ApplicationLoader.applicationContext.getExternalFilesDir("Sheng");
if (!externalFilesDir.mkdirs()) {
externalFilesDir.exists();
}
return null;
} else if (BuildVars.LOGS_ENABLED) {
FileLog.d("External storage is not mounted READ/WRITE.");
return null;
} else {
return null;
}
}
public static String getPath(Uri uri) {
String[] split;
try {
if ((Build.VERSION.SDK_INT >= 19) && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) {
if (isExternalStorageDocument(uri)) {
if ("primary".equalsIgnoreCase(DocumentsContract.getDocumentId(uri).split(LogUtils.COLON)[0])) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else if (isDownloadsDocument(uri)) {
return getDataColumn(ApplicationLoader.applicationContext, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
} else {
if (isMediaDocument(uri)) {
String[] split2 = DocumentsContract.getDocumentId(uri).split(LogUtils.COLON);
String str = split2[0];
char c = 65535;
int hashCode = str.hashCode();
if (hashCode != 93166550) {
if (hashCode != 100313435) {
if (hashCode == 112202875 && str.equals(MimeTypes.BASE_TYPE_VIDEO)) {
c = 1;
}
} else if (str.equals(TtmlNode.TAG_IMAGE)) {
c = 0;
}
} else if (str.equals(MimeTypes.BASE_TYPE_AUDIO)) {
c = 2;
}
Uri uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
return getDataColumn(ApplicationLoader.applicationContext, uri2, "_id=?", new String[]{split2[1]});
}
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
return getDataColumn(ApplicationLoader.applicationContext, uri, null, null);
} else {
if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
}
} catch (Exception e) {
FileLog.e(e);
}
return null;
}
public static String getDataColumn(Context context, Uri uri, String str, String[] strArr) {
Cursor query;
try {
query = context.getContentResolver().query(uri, new String[]{"_data"}, str, strArr, null);
} catch (Exception unused) {
}
if (query == null || !query.moveToFirst()) {
if (query != null) {
query.close();
}
return null;
}
String string = query.getString(query.getColumnIndexOrThrow("_data"));
if (string.startsWith("content://") || !(string.startsWith("/") || string.startsWith("file://"))) {
if (query != null) {
query.close();
}
return null;
}
if (query != null) {
query.close();
}
return string;
}
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
public static File generatePicturePath() {
return generatePicturePath(false);
}
public static File generatePicturePath(boolean z) {
try {
File albumDir = getAlbumDir(z);
Date date = new Date();
date.setTime(System.currentTimeMillis() + Utilities.random.nextInt(1000) + 1);
String format = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(date);
return new File(albumDir, "IMG_" + format + ".jpg");
} catch (Exception e) {
FileLog.e(e);
return null;
}
}
public static CharSequence generateSearchName(String str, String str2, String str3) {
if (str == null && str2 == null) {
return "";
}
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
if (str == null || str.length() == 0) {
str = str2;
} else if (str2 != null && str2.length() != 0) {
str = str + " " + str2;
}
String trim = str.trim();
String str4 = " " + trim.toLowerCase();
int i = 0;
while (true) {
int indexOf = str4.indexOf(" " + str3, i);
if (indexOf == -1) {
break;
}
int i2 = indexOf - (indexOf == 0 ? 0 : 1);
int length = str3.length() + (indexOf == 0 ? 0 : 1) + i2;
if (i != 0 && i != i2 + 1) {
spannableStringBuilder.append((CharSequence) trim.substring(i, i2));
} else if (i == 0 && i2 != 0) {
spannableStringBuilder.append((CharSequence) trim.substring(0, i2));
}
String substring = trim.substring(i2, Math.min(trim.length(), length));
if (substring.startsWith(" ")) {
spannableStringBuilder.append((CharSequence) " ");
}
String trim2 = substring.trim();
int length2 = spannableStringBuilder.length();
spannableStringBuilder.append((CharSequence) trim2);
spannableStringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4)), length2, trim2.length() + length2, 33);
i = length;
}
if (i != -1 && i < trim.length()) {
spannableStringBuilder.append((CharSequence) trim.substring(i));
}
return spannableStringBuilder;
}
public static boolean isAirplaneModeOn() {
return Build.VERSION.SDK_INT < 17 ? Settings.System.getInt(ApplicationLoader.applicationContext.getContentResolver(), "airplane_mode_on", 0) != 0 : Settings.Global.getInt(ApplicationLoader.applicationContext.getContentResolver(), "airplane_mode_on", 0) != 0;
}
public static File generateVideoPath() {
return generateVideoPath(false);
}
public static File generateVideoPath(boolean z) {
try {
File albumDir = getAlbumDir(z);
Date date = new Date();
date.setTime(System.currentTimeMillis() + Utilities.random.nextInt(1000) + 1);
String format = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(date);
return new File(albumDir, "VID_" + format + ".mp4");
} catch (Exception e) {
FileLog.e(e);
return null;
}
}
public static String formatFileSize(long j) {
return formatFileSize(j, false);
}
public static String formatFileSize(long j, boolean z) {
if (j < 1024) {
return String.format("%d B", Long.valueOf(j));
}
if (j < 1048576) {
float f = ((float) j) / 1024.0f;
if (z) {
int i = (int) f;
if ((f - i) * 10.0f == 0.0f) {
return String.format("%d KB", Integer.valueOf(i));
}
}
return String.format("%.1f KB", Float.valueOf(f));
} else if (j < 1073741824) {
float f2 = (((float) j) / 1024.0f) / 1024.0f;
if (z) {
int i2 = (int) f2;
if ((f2 - i2) * 10.0f == 0.0f) {
return String.format("%d MB", Integer.valueOf(i2));
}
}
return String.format("%.1f MB", Float.valueOf(f2));
} else {
float f3 = ((((float) j) / 1024.0f) / 1024.0f) / 1024.0f;
if (z) {
int i3 = (int) f3;
if ((f3 - i3) * 10.0f == 0.0f) {
return String.format("%d GB", Integer.valueOf(i3));
}
}
return String.format("%.1f GB", Float.valueOf(f3));
}
}
public static byte[] decodeQuotedPrintable(byte[] bArr) {
if (bArr == null) {
return null;
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i = 0;
while (i < bArr.length) {
byte b = bArr[i];
if (b == 61) {
int i2 = i + 1;
try {
int digit = Character.digit((char) bArr[i2], 16);
i = i2 + 1;
byteArrayOutputStream.write((char) ((digit << 4) + Character.digit((char) bArr[i], 16)));
} catch (Exception e) {
FileLog.e(e);
return null;
}
} else {
byteArrayOutputStream.write(b);
}
i++;
}
byte[] byteArray = byteArrayOutputStream.toByteArray();
try {
byteArrayOutputStream.close();
} catch (Exception e2) {
FileLog.e(e2);
}
return byteArray;
}
public static boolean copyFile(InputStream inputStream, File file) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte[] bArr = new byte[4096];
while (true) {
int read = inputStream.read(bArr);
if (read > 0) {
Thread.yield();
fileOutputStream.write(bArr, 0, read);
} else {
fileOutputStream.close();
return true;
}
}
}
public static boolean copyFile(File file, File file2) throws IOException {
if (file.equals(file2)) {
return true;
}
if (!file2.exists()) {
file2.createNewFile();
}
try {
FileInputStream fileInputStream = new FileInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(file2);
try {
fileOutputStream.getChannel().transferFrom(fileInputStream.getChannel(), 0L, fileInputStream.getChannel().size());
fileOutputStream.close();
fileInputStream.close();
return true;
} finally {
}
} catch (Exception e) {
FileLog.e(e);
return false;
}
}
public static byte[] calcAuthKeyHash(byte[] bArr) {
byte[] bArr2 = new byte[16];
System.arraycopy(Utilities.computeSHA1(bArr), 0, bArr2, 0, 16);
return bArr2;
}
public static void openDocument(MessageObject messageObject, Activity activity, BaseFragment baseFragment) {
TLRPC.Document document;
String str;
if (messageObject == null || (document = messageObject.getDocument()) == null) {
return;
}
String attachFileName = messageObject.messageOwner.media != null ? FileLoader.getAttachFileName(document) : "";
File file = (messageObject.messageOwner.attachPath == null || messageObject.messageOwner.attachPath.length() == 0) ? null : new File(messageObject.messageOwner.attachPath);
if (file == null || (file != null && !file.exists())) {
file = FileLoader.getPathToMessage(messageObject.messageOwner);
}
if (file == null || !file.exists()) {
return;
}
if (baseFragment != null && file.getName().toLowerCase().endsWith("attheme")) {
Theme.ThemeInfo applyThemeFile = Theme.applyThemeFile(file, messageObject.getDocumentName(), null, true);
if (applyThemeFile != null) {
baseFragment.presentFragment(new ThemePreviewActivity(applyThemeFile));
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("IncorrectTheme", R.string.IncorrectTheme));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
baseFragment.showDialog(builder.create());
return;
}
try {
Intent intent = new Intent("android.intent.action.VIEW");
intent.setFlags(1);
MimeTypeMap singleton = MimeTypeMap.getSingleton();
int lastIndexOf = attachFileName.lastIndexOf(46);
if (lastIndexOf == -1 || ((str = singleton.getMimeTypeFromExtension(attachFileName.substring(lastIndexOf + 1).toLowerCase())) == null && ((str = document.mime_type) == null || str.length() == 0))) {
str = null;
}
if (Build.VERSION.SDK_INT >= 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", file), str != null ? str : "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(file), str != null ? str : "text/plain");
}
if (str != null) {
try {
activity.startActivityForResult(intent, 500);
return;
} catch (Exception unused) {
if (Build.VERSION.SDK_INT >= 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", file), "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(file), "text/plain");
}
activity.startActivityForResult(intent, 500);
return;
}
}
activity.startActivityForResult(intent, 500);
} catch (Exception unused2) {
if (activity == null) {
return;
}
AlertDialog.Builder builder2 = new AlertDialog.Builder(activity);
builder2.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder2.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder2.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, messageObject.getDocument().mime_type));
if (baseFragment != null) {
baseFragment.showDialog(builder2.create());
} else {
builder2.show();
}
}
}
public static void openForView(MessageObject messageObject, final Activity activity) {
String str;
String fileName = messageObject.getFileName();
File file = (messageObject.messageOwner.attachPath == null || messageObject.messageOwner.attachPath.length() == 0) ? null : new File(messageObject.messageOwner.attachPath);
if (file == null || !file.exists()) {
file = FileLoader.getPathToMessage(messageObject.messageOwner);
}
if (file == null || !file.exists()) {
return;
}
Intent intent = new Intent("android.intent.action.VIEW");
intent.setFlags(1);
MimeTypeMap singleton = MimeTypeMap.getSingleton();
int lastIndexOf = fileName.lastIndexOf(46);
if (lastIndexOf != -1) {
str = singleton.getMimeTypeFromExtension(fileName.substring(lastIndexOf + 1).toLowerCase());
if (str == null) {
if (messageObject.type == 9 || messageObject.type == 0) {
str = messageObject.getDocument().mime_type;
}
if (str != null) {
}
}
if (Build.VERSION.SDK_INT < 26 && str != null && str.equals("application/vnd.android.package-archive") && !ApplicationLoader.applicationContext.getPackageManager().canRequestPackageInstalls()) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ApkRestricted", R.string.ApkRestricted));
builder.setPositiveButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), new DialogInterface.OnClickListener() {
@Override
public final void onClick(DialogInterface dialogInterface, int i) {
AndroidUtilities.lambda$openForView$2(activity, dialogInterface, i);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show();
return;
}
if (Build.VERSION.SDK_INT < 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", file), str != null ? str : "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(file), str != null ? str : "text/plain");
}
if (str == null) {
try {
activity.startActivityForResult(intent, 500);
return;
} catch (Exception unused) {
if (Build.VERSION.SDK_INT >= 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", file), "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(file), "text/plain");
}
activity.startActivityForResult(intent, 500);
return;
}
}
activity.startActivityForResult(intent, 500);
return;
}
str = null;
if (Build.VERSION.SDK_INT < 26) {
}
if (Build.VERSION.SDK_INT < 24) {
}
if (str == null) {
}
}
public static void lambda$openForView$2(Activity activity, DialogInterface dialogInterface, int i) {
try {
activity.startActivity(new Intent("android.settings.MANAGE_UNKNOWN_APP_SOURCES", Uri.parse("package:" + activity.getPackageName())));
} catch (Exception e) {
FileLog.e(e);
}
}
public static void openForView(TLObject tLObject, Activity activity) {
if (tLObject == null || activity == null) {
return;
}
String attachFileName = FileLoader.getAttachFileName(tLObject);
File pathToAttach = FileLoader.getPathToAttach(tLObject, true);
if (pathToAttach == null || !pathToAttach.exists()) {
return;
}
Intent intent = new Intent("android.intent.action.VIEW");
intent.setFlags(1);
MimeTypeMap singleton = MimeTypeMap.getSingleton();
int lastIndexOf = attachFileName.lastIndexOf(46);
String str = null;
if (lastIndexOf != -1) {
String mimeTypeFromExtension = singleton.getMimeTypeFromExtension(attachFileName.substring(lastIndexOf + 1).toLowerCase());
if (mimeTypeFromExtension == null) {
if (tLObject instanceof TLRPC.TL_document) {
mimeTypeFromExtension = ((TLRPC.TL_document) tLObject).mime_type;
}
if (mimeTypeFromExtension != null) {
}
}
str = mimeTypeFromExtension;
}
if (Build.VERSION.SDK_INT >= 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", pathToAttach), str != null ? str : "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(pathToAttach), str != null ? str : "text/plain");
}
if (str != null) {
try {
activity.startActivityForResult(intent, 500);
return;
} catch (Exception unused) {
if (Build.VERSION.SDK_INT >= 24) {
intent.setDataAndType(FileProvider.getUriForFile(activity, "im.ovithmjoec.messenger.provider", pathToAttach), "text/plain");
} else {
intent.setDataAndType(Uri.fromFile(pathToAttach), "text/plain");
}
activity.startActivityForResult(intent, 500);
return;
}
}
activity.startActivityForResult(intent, 500);
}
public static boolean isBannedForever(TLRPC.TL_chatBannedRights tL_chatBannedRights) {
return tL_chatBannedRights == null || Math.abs(((long) tL_chatBannedRights.until_date) - (System.currentTimeMillis() / 1000)) > 157680000;
}
public static void setRectToRect(Matrix matrix, RectF rectF, RectF rectF2, int i, boolean z) {
float height;
float width;
float height2;
boolean z2;
float f;
float f2;
float height3;
float height4;
if (i == 90 || i == 270) {
height = rectF2.height() / rectF.width();
width = rectF2.width();
height2 = rectF.height();
} else {
height = rectF2.width() / rectF.width();
width = rectF2.height();
height2 = rectF.height();
}
float f3 = width / height2;
if (height < f3) {
height = f3;
z2 = true;
} else {
z2 = false;
}
if (z) {
matrix.setTranslate(rectF2.left, rectF2.top);
}
if (i == 90) {
matrix.preRotate(90.0f);
matrix.preTranslate(0.0f, -rectF2.width());
} else if (i == 180) {
matrix.preRotate(180.0f);
matrix.preTranslate(-rectF2.width(), -rectF2.height());
} else if (i == 270) {
matrix.preRotate(270.0f);
matrix.preTranslate(-rectF2.height(), 0.0f);
}
if (z) {
f = (-rectF.left) * height;
f2 = (-rectF.top) * height;
} else {
f = rectF2.left - (rectF.left * height);
f2 = rectF2.top - (rectF.top * height);
}
if (z2) {
height3 = rectF2.width();
height4 = rectF.width();
} else {
height3 = rectF2.height();
height4 = rectF.height();
}
float f4 = (height3 - (height4 * height)) / 2.0f;
if (z2) {
f += f4;
} else {
f2 += f4;
}
matrix.preScale(height, height);
if (z) {
matrix.preTranslate(f, f2);
}
}
public static boolean handleProxyIntent(Activity activity, Intent intent) {
Uri data;
String str;
String str2;
String str3;
String str4;
String str5;
String str6;
String str7;
String path;
if (intent == null) {
return false;
}
try {
if ((intent.getFlags() & 1048576) == 0 && (data = intent.getData()) != null) {
String scheme = data.getScheme();
String str8 = null;
if (scheme != null) {
if (!scheme.equals("http") && !scheme.equals("https")) {
if (scheme.equals("hchat")) {
String uri = data.toString();
if (uri.startsWith("hchat:proxy") || uri.startsWith("hchat://proxy") || uri.startsWith("hchat:socks") || uri.startsWith("hchat://socks")) {
Uri parse = Uri.parse(uri.replace("hchat:proxy", "hchat://m12345.cc").replace("hchat://proxy", "hchat://m12345.cc").replace("hchat://socks", "hchat://m12345.cc").replace("hchat:socks", "hchat://m12345.cc"));
String queryParameter = parse.getQueryParameter("server");
String queryParameter2 = parse.getQueryParameter("port");
String queryParameter3 = parse.getQueryParameter("user");
str2 = parse.getQueryParameter("pass");
str = parse.getQueryParameter("secret");
str4 = queryParameter2;
str3 = queryParameter;
str8 = queryParameter3;
if (!TextUtils.isEmpty(str3) && !TextUtils.isEmpty(str4)) {
showProxyAlert(activity, str3, str4, str8 != null ? "" : str8, str2 != null ? "" : str2, str != null ? "" : str);
return true;
}
}
}
}
String host = data.getHost();
if (host == null || !"m12345.cc".equals(host.toLowerCase()) || (path = data.getPath()) == null || !(path.startsWith("/socks") || path.startsWith("/proxy"))) {
str5 = null;
str6 = null;
str7 = null;
str2 = null;
} else {
String queryParameter4 = data.getQueryParameter("server");
str6 = data.getQueryParameter("port");
String queryParameter5 = data.getQueryParameter("user");
str2 = data.getQueryParameter("pass");
str7 = data.getQueryParameter("secret");
str5 = queryParameter4;
str8 = queryParameter5;
}
str3 = str5;
str4 = str6;
str = str7;
if (!TextUtils.isEmpty(str3)) {
showProxyAlert(activity, str3, str4, str8 != null ? "" : str8, str2 != null ? "" : str2, str != null ? "" : str);
return true;
}
}
str = null;
str2 = null;
str3 = null;
str4 = null;
if (!TextUtils.isEmpty(str3)) {
}
}
} catch (Exception unused) {
}
return false;
}
public static boolean shouldEnableAnimation() {
return Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT >= 28 || (!((PowerManager) ApplicationLoader.applicationContext.getSystemService("power")).isPowerSaveMode() && Settings.Global.getFloat(ApplicationLoader.applicationContext.getContentResolver(), "animator_duration_scale", 1.0f) > 0.0f);
}
public static void showProxyAlert(Activity activity, final String str, final String str2, final String str3, final String str4, final String str5) {
String str6;
BottomSheet.Builder builder = new BottomSheet.Builder(activity);
final Runnable dismissRunnable = builder.getDismissRunnable();
builder.setApplyTopPadding(false);
builder.setApplyBottomPadding(false);
LinearLayout linearLayout = new LinearLayout(activity);
builder.setCustomView(linearLayout);
linearLayout.setOrientation(1);
if (!TextUtils.isEmpty(str5)) {
TextView textView = new TextView(activity);
textView.setText(LocaleController.getString("UseProxySettingsTips", R.string.UseProxySettingsTips));
textView.setTextColor(Theme.getColor(Theme.key_dialogTextGray4));
textView.setTextSize(1, 14.0f);
textView.setGravity(49);
linearLayout.addView(textView, LayoutHelper.createLinear(-2, -2, (LocaleController.isRTL ? 5 : 3) | 48, 17, 8, 17, 8));
View view = new View(activity);
view.setBackgroundColor(Theme.getColor(Theme.key_divider));
linearLayout.addView(view, new LinearLayout.LayoutParams(-1, 1));
}
for (int i = 0; i < 5; i++) {
String str7 = null;
if (i == 0) {
str6 = LocaleController.getString("UseProxyAddress", R.string.UseProxyAddress);
str7 = str;
} else if (i == 1) {
str7 = "" + str2;
str6 = LocaleController.getString("UseProxyPort", R.string.UseProxyPort);
} else if (i == 2) {
str6 = LocaleController.getString("UseProxySecret", R.string.UseProxySecret);
str7 = str5;
} else if (i == 3) {
str6 = LocaleController.getString("UseProxyUsername", R.string.UseProxyUsername);
str7 = str3;
} else if (i == 4) {
str6 = LocaleController.getString("UseProxyPassword", R.string.UseProxyPassword);
str7 = str4;
} else {
str6 = null;
}
if (!TextUtils.isEmpty(str7)) {
TextDetailSettingsCell textDetailSettingsCell = new TextDetailSettingsCell(activity);
textDetailSettingsCell.setTextAndValue(str7, str6, true);
textDetailSettingsCell.getTextView().setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
textDetailSettingsCell.getValueTextView().setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
linearLayout.addView(textDetailSettingsCell, LayoutHelper.createLinear(-1, -2));
if (i == 2) {
break;
}
}
}
PickerBottomLayout pickerBottomLayout = new PickerBottomLayout(activity, false);
pickerBottomLayout.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
linearLayout.addView(pickerBottomLayout, LayoutHelper.createFrame(-1, 48, 83));
pickerBottomLayout.cancelButton.setPadding(dp(18.0f), 0, dp(18.0f), 0);
pickerBottomLayout.cancelButton.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
pickerBottomLayout.cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
pickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view2) {
dismissRunnable.run();
}
});
pickerBottomLayout.doneButtonTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
pickerBottomLayout.doneButton.setPadding(dp(18.0f), 0, dp(18.0f), 0);
pickerBottomLayout.doneButtonBadgeTextView.setVisibility(8);
pickerBottomLayout.doneButtonTextView.setText(LocaleController.getString("ConnectingConnectProxy", R.string.ConnectingConnectProxy).toUpperCase());
pickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view2) {
AndroidUtilities.lambda$showProxyAlert$4(str, str2, str5, str4, str3, dismissRunnable, view2);
}
});
builder.show();
}
public static void lambda$showProxyAlert$4(String str, String str2, String str3, String str4, String str5, Runnable runnable, View view) {
SharedConfig.ProxyInfo proxyInfo;
SharedPreferences.Editor edit = MessagesController.getGlobalMainSettings().edit();
edit.putBoolean("proxy_enabled", true);
edit.putString("proxy_ip", str);
int intValue = Utilities.parseInt(str2).intValue();
edit.putInt("proxy_port", intValue);
if (TextUtils.isEmpty(str3)) {
edit.remove("proxy_secret");
if (TextUtils.isEmpty(str4)) {
edit.remove("proxy_pass");
} else {
edit.putString("proxy_pass", str4);
}
if (TextUtils.isEmpty(str5)) {
edit.remove("proxy_user");
} else {
edit.putString("proxy_user", str5);
}
proxyInfo = new SharedConfig.ProxyInfo(str, intValue, str5, str4, "");
} else {
edit.remove("proxy_pass");
edit.remove("proxy_user");
edit.putString("proxy_secret", str3);
proxyInfo = new SharedConfig.ProxyInfo(str, intValue, "", "", str3);
}
edit.commit();
SharedConfig.currentProxy = SharedConfig.addProxy(proxyInfo);
ConnectionsManager.setProxySettings(true, str, intValue, str5, str4, str3);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged, new Object[0]);
runnable.run();
}
public static String getSystemProperty(String str) {
try {
return (String) Class.forName("android.os.SystemProperties").getMethod("get", String.class).invoke(null, str);
} catch (Exception unused) {
return null;
}
}
public static CharSequence concat(CharSequence... charSequenceArr) {
if (charSequenceArr.length == 0) {
return "";
}
int i = 0;
boolean z = true;
if (charSequenceArr.length == 1) {
return charSequenceArr[0];
}
int length = charSequenceArr.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
z = false;
break;
} else if (charSequenceArr[i2] instanceof Spanned) {
break;
} else {
i2++;
}
}
if (z) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
int length2 = charSequenceArr.length;
while (i < length2) {
CharSequence charSequence = charSequenceArr[i];
if (charSequence == null) {
charSequence = "null";
}
spannableStringBuilder.append(charSequence);
i++;
}
return new SpannedString(spannableStringBuilder);
}
StringBuilder sb = new StringBuilder();
int length3 = charSequenceArr.length;
while (i < length3) {
sb.append(charSequenceArr[i]);
i++;
}
return sb.toString();
}
public static int HSBtoRGB(float f, float f2, float f3) {
int i;
int i2;
int i3 = 0;
if (f2 == 0.0f) {
i3 = (int) ((f3 * 255.0f) + 0.5f);
i = i3;
i2 = i;
} else {
float floor = (f - ((float) Math.floor(f))) * 6.0f;
float floor2 = floor - ((float) Math.floor(floor));
float f4 = (1.0f - f2) * f3;
float f5 = (1.0f - (f2 * floor2)) * f3;
float f6 = (1.0f - (f2 * (1.0f - floor2))) * f3;
int i4 = (int) floor;
if (i4 == 0) {
i3 = (int) ((f3 * 255.0f) + 0.5f);
i = (int) ((f6 * 255.0f) + 0.5f);
} else if (i4 == 1) {
i3 = (int) ((f5 * 255.0f) + 0.5f);
i = (int) ((f3 * 255.0f) + 0.5f);
} else if (i4 != 2) {
if (i4 == 3) {
i3 = (int) ((f4 * 255.0f) + 0.5f);
i = (int) ((f5 * 255.0f) + 0.5f);
} else if (i4 == 4) {
i3 = (int) ((f6 * 255.0f) + 0.5f);
i = (int) ((f4 * 255.0f) + 0.5f);
} else if (i4 != 5) {
i = 0;
i2 = 0;
} else {
i3 = (int) ((f3 * 255.0f) + 0.5f);
i = (int) ((f4 * 255.0f) + 0.5f);
i2 = (int) ((f5 * 255.0f) + 0.5f);
}
i2 = (int) ((f3 * 255.0f) + 0.5f);
} else {
i3 = (int) ((f4 * 255.0f) + 0.5f);
i = (int) ((f3 * 255.0f) + 0.5f);
i2 = (int) ((f6 * 255.0f) + 0.5f);
}
i2 = (int) ((f4 * 255.0f) + 0.5f);
}
return ((i & 255) << 8) | (-16777216) | ((i3 & 255) << 16) | (i2 & 255);
}
public static int getPatternColor(int i) {
float[] RGBtoHSB = RGBtoHSB(Color.red(i), Color.green(i), Color.blue(i));
if (RGBtoHSB[1] > 0.0f || (RGBtoHSB[2] < 1.0f && RGBtoHSB[2] > 0.0f)) {
RGBtoHSB[1] = Math.min(1.0f, RGBtoHSB[1] + 0.05f + ((1.0f - RGBtoHSB[1]) * 0.1f));
}
if (RGBtoHSB[2] > 0.5f) {
RGBtoHSB[2] = Math.max(0.0f, RGBtoHSB[2] * 0.65f);
} else {
RGBtoHSB[2] = Math.max(0.0f, Math.min(1.0f, 1.0f - (RGBtoHSB[2] * 0.65f)));
}
return HSBtoRGB(RGBtoHSB[0], RGBtoHSB[1], RGBtoHSB[2]) & 1728053247;
}
public static int getPatternSideColor(int i) {
float[] RGBtoHSB = RGBtoHSB(Color.red(i), Color.green(i), Color.blue(i));
RGBtoHSB[1] = Math.min(1.0f, RGBtoHSB[1] + 0.05f);
if (RGBtoHSB[2] > 0.5f) {
RGBtoHSB[2] = Math.max(0.0f, RGBtoHSB[2] * 0.9f);
} else {
RGBtoHSB[2] = Math.max(0.0f, RGBtoHSB[2] * 0.9f);
}
return HSBtoRGB(RGBtoHSB[0], RGBtoHSB[1], RGBtoHSB[2]) | (-16777216);
}
public static String getWallPaperUrl(Object obj, int i) {
String str;
if (obj instanceof TLRPC.TL_wallPaper) {
TLRPC.TL_wallPaper tL_wallPaper = (TLRPC.TL_wallPaper) obj;
String str2 = "https://" + MessagesController.getInstance(i).linkPrefix + "/bg/" + tL_wallPaper.slug;
StringBuilder sb = new StringBuilder();
if (tL_wallPaper.settings != null) {
if (tL_wallPaper.settings.blur) {
sb.append("blur");
}
if (tL_wallPaper.settings.motion) {
if (sb.length() > 0) {
sb.append(Marker.ANY_NON_NULL_MARKER);
}
sb.append("motion");
}
}
if (sb.length() > 0) {
return str2 + "?mode=" + sb.toString();
}
return str2;
} else if (obj instanceof WallpapersListActivity.ColorWallpaper) {
WallpapersListActivity.ColorWallpaper colorWallpaper = (WallpapersListActivity.ColorWallpaper) obj;
String lowerCase = String.format("%02x%02x%02x", Integer.valueOf(((byte) (colorWallpaper.color >> 16)) & UByte.MAX_VALUE), Integer.valueOf(((byte) (colorWallpaper.color >> 8)) & UByte.MAX_VALUE), Byte.valueOf((byte) (colorWallpaper.color & 255))).toLowerCase();
if (colorWallpaper.pattern != null) {
str = "https://" + MessagesController.getInstance(i).linkPrefix + "/bg/" + colorWallpaper.pattern.slug + "?intensity=" + ((int) (colorWallpaper.intensity * 100.0f)) + "&bg_color=" + lowerCase;
} else {
str = "https://" + MessagesController.getInstance(i).linkPrefix + "/bg/" + lowerCase;
}
return str;
} else {
return null;
}
}
public static float distanceInfluenceForSnapDuration(float f) {
return (float) Math.sin((f - 0.5f) * 0.47123894f);
}
public static void makeAccessibilityAnnouncement(CharSequence charSequence) {
AccessibilityManager accessibilityManager = (AccessibilityManager) ApplicationLoader.applicationContext.getSystemService("accessibility");
if (accessibilityManager.isEnabled()) {
AccessibilityEvent obtain = AccessibilityEvent.obtain();
obtain.setEventType(16384);
obtain.getText().add(charSequence);
accessibilityManager.sendAccessibilityEvent(obtain);
}
}
public static int getOffsetColor(int i, int i2, float f, float f2) {
int red = Color.red(i2);
int green = Color.green(i2);
int blue = Color.blue(i2);
int alpha = Color.alpha(i2);
int red2 = Color.red(i);
int green2 = Color.green(i);
int blue2 = Color.blue(i);
int alpha2 = Color.alpha(i);
return Color.argb((int) ((alpha2 + ((alpha - alpha2) * f)) * f2), (int) (red2 + ((red - red2) * f)), (int) (green2 + ((green - green2) * f)), (int) (blue2 + ((blue - blue2) * f)));
}
public static int indexOfIgnoreCase(String str, String str2) {
if (str2.isEmpty() || str.isEmpty()) {
return str.indexOf(str2);
}
for (int i = 0; i < str.length() && str2.length() + i <= str.length(); i++) {
int i2 = 0;
for (int i3 = i; i3 < str.length() && i2 < str2.length() && Character.toLowerCase(str.charAt(i3)) == Character.toLowerCase(str2.charAt(i2)); i3++) {
i2++;
}
if (i2 == str2.length()) {
return i;
}
}
return -1;
}
public static float computePerceivedBrightness(int i) {
return (((Color.red(i) * 0.2126f) + (Color.green(i) * 0.7152f)) + (Color.blue(i) * 0.0722f)) / 255.0f;
}
public static void setLightNavigationBar(Window window, boolean z) {
if (Build.VERSION.SDK_INT >= 26) {
View decorView = window.getDecorView();
int systemUiVisibility = decorView.getSystemUiVisibility();
decorView.setSystemUiVisibility(z ? systemUiVisibility | 16 : systemUiVisibility & (-17));
}
}
public static int getVersionCode(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static String getVersionName(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
}
}
public static byte[] getBlock(long j, File file, int i) {
RandomAccessFile randomAccessFile;
byte[] bArr = new byte[i];
RandomAccessFile randomAccessFile2 = null;
try {
randomAccessFile = new RandomAccessFile(file, "r");
try {
try {
randomAccessFile.seek(j);
int read = randomAccessFile.read(bArr);
if (read == -1) {
try {
randomAccessFile.close();
} catch (IOException unused) {
}
return null;
} else if (read == i) {
try {
randomAccessFile.close();
} catch (IOException unused2) {
}
return bArr;
} else {
byte[] bArr2 = new byte[read];
System.arraycopy(bArr, 0, bArr2, 0, read);
try {
randomAccessFile.close();
} catch (IOException unused3) {
}
return bArr2;
}
} catch (IOException e) {
e = e;
e.printStackTrace();
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (IOException unused4) {
}
}
return null;
}
} catch (Throwable th) {
th = th;
randomAccessFile2 = randomAccessFile;
if (randomAccessFile2 != null) {
try {
randomAccessFile2.close();
} catch (IOException unused5) {
}
}
throw th;
}
} catch (IOException e2) {
e = e2;
randomAccessFile = null;
} catch (Throwable th2) {
th = th2;
if (randomAccessFile2 != null) {
}
throw th;
}
}
public static String getFileMD5(File file) {
if (!file.isFile()) {
return null;
}
byte[] bArr = new byte[1024];
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
FileInputStream fileInputStream = new FileInputStream(file);
while (true) {
int read = fileInputStream.read(bArr, 0, 1024);
if (read != -1) {
messageDigest.update(bArr, 0, read);
} else {
fileInputStream.close();
return byteArrayToHex(messageDigest.digest());
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String byteArrayToHex(byte[] bArr) {
char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char[] cArr2 = new char[bArr.length * 2];
int i = 0;
for (byte b : bArr) {
int i2 = i + 1;
cArr2[i] = cArr[(b >>> 4) & 15];
i = i2 + 1;
cArr2[i2] = cArr[b & 15];
}
return new String(cArr2);
}
public static boolean checkHasExitsUserOrDeletedEverAndShowDialog(BaseFragment baseFragment, String str) {
if (str == null) {
return false;
}
for (int i = 0; i < 3; i++) {
UserConfig userConfig = UserConfig.getInstance(i);
if (UserObject.isDeleted(userConfig.getCurrentUser())) {
AlertsCreator.showSimpleAlert(baseFragment, LocaleController.getString("ReminderDeletedEverPleaseUseOtherAccount", R.string.ReminderDeletedEverPleaseUseOtherAccount));
return true;
} else if (PhoneNumberUtils.compare(str, userConfig.getCurrentUser().phone)) {
if (i == UserConfig.selectedAccount) {
AlertsCreator.showSimpleAlert(baseFragment, LocaleController.getString("AccountAlreadyLoggedIn", R.string.AccountAlreadyLoggedIn));
} else {
AlertsCreator.showSimpleAlert(baseFragment, LocaleController.getString("ReminderAccountHadExitsAndSwitchAccount", R.string.ReminderAccountHadExitsAndSwitchAccount));
}
return true;
}
}
return false;
}
public static boolean checkCamera(Context context) {
String[] strArr = new String[0];
try {
strArr = ((CameraManager) context.getSystemService("camera")).getCameraIdList();
} catch (Exception e) {
e.printStackTrace();
}
if (strArr != null && strArr.length > 0) {
String str = strArr[0];
if (strArr[1] != null) {
return true;
}
}
return false;
}
public static boolean isAppOnForeground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService("activity");
String packageName = context.getApplicationContext().getPackageName();
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager != null ? activityManager.getRunningAppProcesses() : null;
if (runningAppProcesses == null) {
return false;
}
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
if (runningAppProcessInfo.processName.equals(packageName) && runningAppProcessInfo.importance == 100) {
return true;
}
}
return false;
}
public static int getSystemVersion() {
return Integer.parseInt(Build.VERSION.RELEASE);
}
public static void handleKeyboardShelterProblem(EditText editText) {
handleKeyboardShelterProblem(editText, false);
}
public static void handleKeyboardShelterProblem(EditText editText, boolean z) {
if (editText != null && isEMUI() && Build.VERSION.SDK_INT >= 27) {
int inputType = editText.getInputType() & 4095;
boolean z2 = inputType == 129;
boolean z3 = inputType == 225;
boolean z4 = inputType == 18;
if (z2) {
editText.setInputType(1);
} else if (z3) {
editText.setInputType(1);
} else if (z4) {
editText.setInputType(2);
}
if (z2 || z3 || z4) {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
}
public static boolean isMIUI() {
return "xiaomi".equalsIgnoreCase(Build.MANUFACTURER);
}
public static boolean isEMUI() {
return "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER);
}
public static boolean isOPPO() {
return "OPPO".equalsIgnoreCase(Build.MANUFACTURER);
}
public static boolean isVIVO() {
return "vivo".equalsIgnoreCase(Build.MANUFACTURER);
}
public static boolean containsEmoji(CharSequence charSequence) {
int length = charSequence.length();
for (int i = 0; i < length; i++) {
if (!isEmojiCharacter(charSequence.charAt(i))) {
return true;
}
}
return false;
}
public static boolean isScreenOriatationPortrait(Context context) {
return context.getResources().getConfiguration().orientation == 1;
}
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
RenderScript create = RenderScript.create(context);
ScriptIntrinsicBlur create2 = ScriptIntrinsicBlur.create(create, Element.U8_4(create));
Allocation createFromBitmap = Allocation.createFromBitmap(create, bitmap);
Allocation createFromBitmap2 = Allocation.createFromBitmap(create, createBitmap);
create2.setRadius(15.0f);
create2.setInput(createFromBitmap);
create2.forEach(createFromBitmap2);
createFromBitmap2.copyTo(createBitmap);
create.destroy();
return createBitmap;
}
}