Utils.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. package epson.common;
  2. import android.annotation.TargetApi;
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.Service;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.SharedPreferences;
  9. import android.graphics.Bitmap;
  10. import android.graphics.BitmapFactory;
  11. import android.graphics.Rect;
  12. import android.graphics.drawable.Drawable;
  13. import android.net.ConnectivityManager;
  14. import android.net.NetworkInfo;
  15. import android.net.wifi.WifiManager;
  16. import android.os.Build;
  17. import android.os.Environment;
  18. import android.view.KeyEvent;
  19. import android.widget.TextView;
  20. import androidx.annotation.NonNull;
  21. import androidx.annotation.Nullable;
  22. import epson.print.CommonDefine;
  23. import epson.print.Util.EPLog;
  24. import epson.print.widgets.CustomTitleAlertDialogBuilder;
  25. import java.io.File;
  26. import java.io.FileInputStream;
  27. import java.io.FileNotFoundException;
  28. import java.io.IOException;
  29. import java.util.Locale;
  30. import java.util.UUID;
  31. public class Utils {
  32. private static String TAG = "epson.common.Utils";
  33. private Utils() {
  34. }
  35. public static void savePref(Context context, String str, String str2, int i) {
  36. SharedPreferences.Editor edit = context.getSharedPreferences(str, 0).edit();
  37. edit.putInt(str2, i);
  38. edit.commit();
  39. }
  40. public static void savePref(Context context, String str, String str2, String str3) {
  41. SharedPreferences.Editor edit = context.getSharedPreferences(str, 0).edit();
  42. edit.putString(str2, str3);
  43. edit.commit();
  44. }
  45. public static void savePref(Context context, String str, String str2, boolean z) {
  46. SharedPreferences.Editor edit = context.getSharedPreferences(str, 0).edit();
  47. edit.putBoolean(str2, z);
  48. edit.commit();
  49. }
  50. public static String getPrefString(Context context, String str, String str2) {
  51. return context.getSharedPreferences(str, 0).getString(str2, "");
  52. }
  53. public static int getPrefInt(Context context, String str, String str2) {
  54. return context.getSharedPreferences(str, 0).getInt(str2, 0);
  55. }
  56. public static boolean getPrefBoolean(Context context, String str, String str2) {
  57. return context.getSharedPreferences(str, 0).getBoolean(str2, false);
  58. }
  59. public static Bitmap decodeFile(File file, int i, boolean z) throws FileNotFoundException, OutOfMemoryError, IOException {
  60. return decodeFile(file, i);
  61. }
  62. /* JADX WARNING: Removed duplicated region for block: B:22:0x0041 */
  63. /* JADX WARNING: Removed duplicated region for block: B:24:0x0046 */
  64. /* Code decompiled incorrectly, please refer to instructions dump. */
  65. public static void copyFile(java.io.File r9, java.io.File r10) throws java.io.IOException {
  66. /*
  67. boolean r0 = r10.exists()
  68. if (r0 != 0) goto L_0x0009
  69. r10.createNewFile()
  70. L_0x0009:
  71. r0 = 0
  72. java.io.FileInputStream r1 = new java.io.FileInputStream // Catch:{ all -> 0x003d }
  73. r1.<init>(r9) // Catch:{ all -> 0x003d }
  74. java.nio.channels.FileChannel r9 = r1.getChannel() // Catch:{ all -> 0x003d }
  75. java.io.FileOutputStream r1 = new java.io.FileOutputStream // Catch:{ all -> 0x0037 }
  76. r1.<init>(r10) // Catch:{ all -> 0x0037 }
  77. java.nio.channels.FileChannel r10 = r1.getChannel() // Catch:{ all -> 0x0037 }
  78. r4 = 0
  79. long r6 = r9.size() // Catch:{ all -> 0x0032 }
  80. r2 = r10
  81. r3 = r9
  82. r2.transferFrom(r3, r4, r6) // Catch:{ all -> 0x0032 }
  83. if (r9 == 0) goto L_0x002c
  84. r9.close()
  85. L_0x002c:
  86. if (r10 == 0) goto L_0x0031
  87. r10.close()
  88. L_0x0031:
  89. return
  90. L_0x0032:
  91. r0 = move-exception
  92. r8 = r0
  93. r0 = r9
  94. r9 = r8
  95. goto L_0x003f
  96. L_0x0037:
  97. r10 = move-exception
  98. r8 = r0
  99. r0 = r9
  100. r9 = r10
  101. r10 = r8
  102. goto L_0x003f
  103. L_0x003d:
  104. r9 = move-exception
  105. r10 = r0
  106. L_0x003f:
  107. if (r0 == 0) goto L_0x0044
  108. r0.close()
  109. L_0x0044:
  110. if (r10 == 0) goto L_0x0049
  111. r10.close()
  112. L_0x0049:
  113. throw r9
  114. */
  115. throw new UnsupportedOperationException("Method not decompiled: epson.common.Utils.copyFile(java.io.File, java.io.File):void");
  116. }
  117. public static Bitmap decodeFile(File file, int i) throws FileNotFoundException, OutOfMemoryError {
  118. BitmapFactory.Options options = new BitmapFactory.Options();
  119. options.inJustDecodeBounds = true;
  120. BitmapFactory.decodeFile(file.getAbsolutePath(), options);
  121. int max = Math.max((options.outWidth / i) + 1, (options.outHeight / i) + 1);
  122. if (max < 1) {
  123. max = 1;
  124. }
  125. options.inJustDecodeBounds = false;
  126. options.inSampleSize = max;
  127. return BitmapFactory.decodeFile(file.getAbsolutePath(), options);
  128. }
  129. public static Bitmap decodeFileByScale(File file, int i) throws FileNotFoundException, OutOfMemoryError {
  130. BitmapFactory.Options options = new BitmapFactory.Options();
  131. options.inSampleSize = i;
  132. return BitmapFactory.decodeStream(new FileInputStream(file), (Rect) null, options);
  133. }
  134. public static Bitmap decodeFileBySample(File file, BitmapFactory.Options options) throws FileNotFoundException, OutOfMemoryError {
  135. return BitmapFactory.decodeStream(new FileInputStream(file), (Rect) null, options);
  136. }
  137. public static void deleteTempFile(String str) {
  138. File file = new File(str);
  139. if (file.exists() && file.isFile()) {
  140. file.delete();
  141. }
  142. }
  143. public static boolean isOnline(Context context) {
  144. NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
  145. return activeNetworkInfo != null && activeNetworkInfo.isConnected();
  146. }
  147. public static boolean isConnecting(@NonNull Context context) {
  148. NetworkInfo activeNetworkInfo;
  149. ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
  150. if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) {
  151. return false;
  152. }
  153. return activeNetworkInfo.isConnectedOrConnecting();
  154. }
  155. public static boolean isConnectedWifi(Context context) {
  156. NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getNetworkInfo(1);
  157. if (networkInfo == null || networkInfo.getType() != 1 || !networkInfo.isConnected()) {
  158. return false;
  159. }
  160. return true;
  161. }
  162. public static boolean isEnableMobileData(Context context) {
  163. ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
  164. NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
  165. boolean isAvailable = networkInfo != null ? networkInfo.isAvailable() : false;
  166. if (isAvailable) {
  167. try {
  168. isAvailable = Boolean.TRUE.equals(connectivityManager.getClass().getMethod("getMobileDataEnabled", new Class[0]).invoke(connectivityManager, new Object[0]));
  169. String str = TAG;
  170. EPLog.i(str, "getMobileDataEnabled :" + Boolean.valueOf(isAvailable).toString());
  171. } catch (Exception unused) {
  172. EPLog.m307e(TAG, "getMobileDataEnabled : Error");
  173. }
  174. }
  175. String str2 = TAG;
  176. EPLog.i(str2, "isEnableMobileData :" + Boolean.valueOf(isAvailable).toString());
  177. return isAvailable;
  178. }
  179. public static String getSSID(Context context) {
  180. try {
  181. return ((WifiManager) context.getSystemService(Service.WIFI_SERVICE)).getConnectionInfo().getSSID();
  182. } catch (SecurityException e) {
  183. e.printStackTrace();
  184. return null;
  185. }
  186. }
  187. public static AlertDialog makeMessageBox(Context context, String str, String str2) {
  188. AlertDialog.Builder makeMassageBoxInternal = makeMassageBoxInternal(context, str2);
  189. makeMassageBoxInternal.setTitle((CharSequence) null);
  190. makeMassageBoxInternal.setMessage(str);
  191. return makeMassageBoxInternal.create();
  192. }
  193. public static AlertDialog makeMessageBox(Context context, String str, String str2, String str3) {
  194. AlertDialog.Builder makeMassageBoxInternal = makeMassageBoxInternal(context, str3);
  195. makeMassageBoxInternal.setTitle(str);
  196. makeMassageBoxInternal.setMessage(str2);
  197. return makeMassageBoxInternal.create();
  198. }
  199. private static AlertDialog.Builder makeMassageBoxInternal(Context context, String str) {
  200. CustomTitleAlertDialogBuilder customTitleAlertDialogBuilder = new CustomTitleAlertDialogBuilder(context);
  201. customTitleAlertDialogBuilder.setCancelable(false);
  202. customTitleAlertDialogBuilder.setOnKeyListener(new DialogInterface.OnKeyListener() {
  203. public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
  204. return keyEvent.getKeyCode() == 84;
  205. }
  206. });
  207. customTitleAlertDialogBuilder.setPositiveButton(str, new DialogInterface.OnClickListener() {
  208. public void onClick(DialogInterface dialogInterface, int i) {
  209. dialogInterface.dismiss();
  210. }
  211. });
  212. return customTitleAlertDialogBuilder;
  213. }
  214. public static CustomTitleAlertDialogBuilder getCustomTitleDialogBuilder(Context context) {
  215. CustomTitleAlertDialogBuilder customTitleAlertDialogBuilder = new CustomTitleAlertDialogBuilder(context);
  216. customTitleAlertDialogBuilder.setCancelable(false);
  217. customTitleAlertDialogBuilder.setOnKeyListener(new DialogInterface.OnKeyListener() {
  218. public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
  219. return keyEvent.getKeyCode() == 84;
  220. }
  221. });
  222. return customTitleAlertDialogBuilder;
  223. }
  224. public void deleteTempFoler(String str) {
  225. File file = new File(str);
  226. File[] listFiles = file.listFiles();
  227. if (listFiles != null) {
  228. for (int i = 0; i < listFiles.length; i++) {
  229. if (listFiles[i].isFile()) {
  230. listFiles[i].delete();
  231. } else if (listFiles[i].isDirectory()) {
  232. deleteTempFoler(listFiles[i].toString());
  233. }
  234. }
  235. }
  236. if (file.exists() && file.isFile()) {
  237. file.delete();
  238. }
  239. }
  240. public static String getPreffix(String str) {
  241. if (str == null) {
  242. return null;
  243. }
  244. int lastIndexOf = str.lastIndexOf(CommonDefine.DOT);
  245. return (lastIndexOf == -1 || lastIndexOf == 0) ? str : str.substring(0, lastIndexOf);
  246. }
  247. public static String getSuffix(String str) {
  248. int lastIndexOf;
  249. if (str == null || (lastIndexOf = str.lastIndexOf(CommonDefine.DOT)) == -1 || lastIndexOf == 0) {
  250. return null;
  251. }
  252. return str.substring(lastIndexOf + 1);
  253. }
  254. @Nullable
  255. public static String getMimeType(@Nullable String str) {
  256. if (str == null) {
  257. return null;
  258. }
  259. return getExtType(getExtention(new File(str).getName()));
  260. }
  261. public static String getExtention(String str) {
  262. String suffix = getSuffix(str);
  263. if (suffix == null) {
  264. return null;
  265. }
  266. return CommonDefine.DOT + suffix;
  267. }
  268. public static String getMimeExt(String str) {
  269. if (str == null) {
  270. return null;
  271. }
  272. switch (MimeType.toMimeType(str)) {
  273. case PDF_TYPE:
  274. return CommonDefine.FileType_PDF;
  275. case DOC_TYPE_1:
  276. return CommonDefine.FileType_WORD_1;
  277. case DOCX_TYPE_2:
  278. return CommonDefine.FileType_WORD_2;
  279. case EXCEL_TYPE_1:
  280. return CommonDefine.FileType_EXCEL_1;
  281. case EXCEL_TYPE_2:
  282. return CommonDefine.FileType_EXCEL_2;
  283. case POWERPOINT_TYPE_1:
  284. return CommonDefine.FileType_POWERPOINT_1;
  285. case POWERPOINT_TYPE_2:
  286. return CommonDefine.FileType_POWERPOINT_2;
  287. case TEXT_TYPE:
  288. return CommonDefine.FileType_TXT;
  289. case RTF_TYPE:
  290. return CommonDefine.FileType_RTF;
  291. case CSV_TYPE:
  292. return CommonDefine.FileType_CSV;
  293. case HTML_TYPE:
  294. return CommonDefine.FileType_HTML_1;
  295. case IMAGE_TYPE:
  296. return ".jpg";
  297. case IMAGE_TYPE_PNG:
  298. return ".png";
  299. case IMAGE_TYPE_BMP:
  300. return ".bmp";
  301. case IMAGE_TYPE_HEIF:
  302. return CommonDefine.FileType_HEIF;
  303. default:
  304. char c = 65535;
  305. if (str.hashCode() == -1004747228 && str.equals(CommonDefine.CSV_TYPE)) {
  306. c = 0;
  307. }
  308. if (c != 0) {
  309. return null;
  310. }
  311. return CommonDefine.FileType_CSV;
  312. }
  313. }
  314. public static String getExtType(String str) {
  315. if (str == null) {
  316. return null;
  317. }
  318. String lowerCase = str.toLowerCase(Locale.ENGLISH);
  319. switch (ExtType.toExtType(lowerCase)) {
  320. case FileType_PDF:
  321. return "application/pdf";
  322. case FileType_WORD_1:
  323. return CommonDefine.DOC_TYPE_1;
  324. case FileType_WORD_2:
  325. return CommonDefine.DOCX_TYPE_2;
  326. case FileType_EXCEL_1:
  327. return CommonDefine.EXCEL_TYPE_1;
  328. case FileType_EXCEL_2:
  329. return CommonDefine.EXCEL_TYPE_2;
  330. case FileType_POWERPOINT_1:
  331. return CommonDefine.POWERPOINT_TYPE_1;
  332. case FileType_POWERPOINT_2:
  333. return CommonDefine.POWERPOINT_TYPE_2;
  334. case FileType_TXT:
  335. return CommonDefine.TEXT_TYPE;
  336. case FileType_RTF:
  337. return CommonDefine.RTF_TYPE;
  338. case FileType_CSV:
  339. return CommonDefine.CSV_TYPE;
  340. case FileType_HTML_1:
  341. return CommonDefine.HTML_TYPE;
  342. case FileType_HTML_2:
  343. return CommonDefine.HTML_TYPE;
  344. case FileType_JPG:
  345. case FileType_JPEG:
  346. return "image/jpeg";
  347. case FileType_PNG:
  348. return "image/png";
  349. case FileType_BMP:
  350. return CommonDefine.IMAGE_TYPE_BMP;
  351. case FileType_HEIF:
  352. return CommonDefine.IMAGE_TYPE_HEIF;
  353. default:
  354. return null;
  355. }
  356. }
  357. public static boolean isGConvertFile(String str) {
  358. String extention;
  359. if (str == null || (extention = getExtention(str)) == null) {
  360. return false;
  361. }
  362. String lowerCase = extention.toLowerCase(Locale.ENGLISH);
  363. switch (ExtType.toExtType(lowerCase)) {
  364. case FileType_WORD_1:
  365. case FileType_WORD_2:
  366. case FileType_EXCEL_1:
  367. case FileType_EXCEL_2:
  368. case FileType_POWERPOINT_1:
  369. case FileType_POWERPOINT_2:
  370. case FileType_TXT:
  371. case FileType_RTF:
  372. case FileType_CSV:
  373. case FileType_HTML_1:
  374. case FileType_HTML_2:
  375. return true;
  376. default:
  377. return false;
  378. }
  379. }
  380. public static boolean isPhotoFile(String str) {
  381. String extention;
  382. if (str == null || (extention = getExtention(str)) == null || getExtType(extention) == null) {
  383. return false;
  384. }
  385. switch (MimeType.toMimeType(r3)) {
  386. case IMAGE_TYPE:
  387. case IMAGE_TYPE_PNG:
  388. case IMAGE_TYPE_BMP:
  389. return true;
  390. case IMAGE_TYPE_HEIF:
  391. if (Build.VERSION.SDK_INT >= 28) {
  392. return true;
  393. }
  394. return false;
  395. default:
  396. return false;
  397. }
  398. }
  399. public static String makeTempFileName(String str) throws FileNotFoundException {
  400. String valueOf = String.valueOf(System.currentTimeMillis());
  401. String mimeExt = getMimeExt(str);
  402. if (mimeExt != null) {
  403. return valueOf + mimeExt;
  404. }
  405. throw new FileNotFoundException();
  406. }
  407. public static boolean isECConvertFile(String str) {
  408. String extention;
  409. if (str == null || (extention = getExtention(str)) == null) {
  410. return false;
  411. }
  412. String lowerCase = extention.toLowerCase(Locale.ENGLISH);
  413. switch (ExtType.toExtType(lowerCase)) {
  414. case FileType_WORD_1:
  415. case FileType_WORD_2:
  416. case FileType_EXCEL_1:
  417. case FileType_EXCEL_2:
  418. case FileType_POWERPOINT_1:
  419. case FileType_POWERPOINT_2:
  420. return true;
  421. default:
  422. return false;
  423. }
  424. }
  425. public static boolean checkMimeType(String str, String str2) {
  426. return str2 != null && str2.equalsIgnoreCase(getExtType(getExtention(str)));
  427. }
  428. public static String getRealMimeType(String str) {
  429. BitmapFactory.Options options = new BitmapFactory.Options();
  430. options.inJustDecodeBounds = true;
  431. BitmapFactory.decodeFile(str, options);
  432. return options.outMimeType;
  433. }
  434. public static String getRemoteOperationUUID(Context context) {
  435. String prefString = getPrefString(context, CommonDefine.DEVICE_INFO, CommonDefine.REMOTE_OPERATION_UUID);
  436. if (!"".equals(prefString)) {
  437. return prefString;
  438. }
  439. String str = "urn:uuid:" + UUID.randomUUID().toString();
  440. savePref(context, CommonDefine.DEVICE_INFO, CommonDefine.REMOTE_OPERATION_UUID, str);
  441. return str;
  442. }
  443. public static boolean isMediaMounted() {
  444. return "mounted".equals(Environment.getExternalStorageState());
  445. }
  446. @TargetApi(11)
  447. public static void setFInishOnTOuchOutside(Activity activity, boolean z) {
  448. if (Build.VERSION.SDK_INT >= 11) {
  449. activity.setFinishOnTouchOutside(z);
  450. }
  451. }
  452. public static void setDrawble2TextView(Context context, TextView textView, int i) {
  453. Drawable drawable = context.getResources().getDrawable(i);
  454. int textSize = (textView.getTextSize() * 1.5f);
  455. drawable.setBounds(0, 0, textSize, textSize);
  456. textView.setCompoundDrawables(drawable, (Drawable) null, (Drawable) null, (Drawable) null);
  457. }
  458. public static java.lang.String getAssetsFileContents(android.content.Context r4, java.lang.String r5) {
  459. throw new UnsupportedOperationException("Method not decompiled: epson.common.Utils.getAssetsFileContents(android.content.Context, java.lang.String):java.lang.String");
  460. }
  461. public static java.lang.String[] replaceMessage(java.lang.Integer[] r5, int r6, android.content.Context r7) {
  462. throw new UnsupportedOperationException("Method not decompiled: epson.common.Utils.replaceMessage(java.lang.Integer[], int, android.content.Context):java.lang.String[]");
  463. }
  464. }