MemcardWriteProgress.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package com.epson.memcardacc;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.ProgressBar;
  8. import android.widget.TextView;
  9. import com.epson.iprint.prtlogger.Analytics;
  10. import com.epson.iprint.prtlogger.CommonLog;
  11. import com.epson.iprint.prtlogger.PrintLog;
  12. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  13. import epson.common.Utils;
  14. import epson.print.Util.EPLog;
  15. import java.util.ArrayList;
  16. import java.util.concurrent.CountDownLatch;
  17. import java.util.concurrent.TimeUnit;
  18. public class MemcardWriteProgress extends Activity {
  19. public static final int ERROR_CODE_COMMUNICATION_ERROR = 1;
  20. public static final int ERROR_CODE_DISK_FULL = 5;
  21. public static final int ERROR_CODE_INTERNAL_ERROR = 6;
  22. public static final int ERROR_CODE_NO_ERROR = 0;
  23. public static final int ERROR_CODE_PRINTER_BUSY = 2;
  24. public static final int ERROR_CODE_STORAGE_CONNECCT_ERROR = 3;
  25. public static final int ERROR_CODE_WRITE_ERROR = 4;
  26. public static final String KEY_CHECK_WIFI_DIRECT = "check_wifi_direct";
  27. public static final String KEY_CIFS_STORAGE_TYPE = "cifs_storage_set_type";
  28. public static final String KEY_IMAGE_LIST = "imageList";
  29. public static final String KEY_WRITE_FILE_LIST = "write_file_list";
  30. public static final String KEY_WRITE_FOLDER_NAME = "target_folder_name";
  31. private static final String LOG_TAG = "MemcardWriteProgress";
  32. public static final String MEMCARD_STORAGE_TYPE = "memcard_storage_type";
  33. public static final int RESULT_COMPLETE = -2;
  34. public static final int RESULT_ERROR = 3;
  35. public static final String RESULT_KEY_CIFS_ERROR_CODE = "cifs_errorcode";
  36. boolean disconnectOnThreadFinish = false;
  37. private Button mCancelButton;
  38. protected int mCifsAccessStorageType;
  39. CopyTask mCopyTask;
  40. private CountDownLatch mCountDownLatch;
  41. protected ArrayList<String> mImageList;
  42. protected int mMemcardStorageType;
  43. private TextView mSheetPerTotalText;
  44. protected String mTargetFolderName;
  45. private ProgressBar mTotalProgress;
  46. private WifiDirectConnector mWifiDirectConnector;
  47. protected ArrayList<String> mWriteFileList;
  48. protected void onCreate(Bundle bundle) {
  49. super.onCreate(bundle);
  50. Utils.setFInishOnTOuchOutside(this, false);
  51. setContentView(R.layout.memcard_write_progress);
  52. mCountDownLatch = new CountDownLatch(1);
  53. mSheetPerTotalText = (TextView) findViewById(R.id.percent);
  54. mTotalProgress = (ProgressBar) findViewById(R.id.progress_percent);
  55. Intent intent = getIntent();
  56. mImageList = intent.getStringArrayListExtra("imageList");
  57. mTargetFolderName = intent.getStringExtra("target_folder_name");
  58. mMemcardStorageType = intent.getIntExtra("memcard_storage_type", 1);
  59. if (mTargetFolderName == null) {
  60. setResult(3);
  61. finish();
  62. }
  63. mWriteFileList = intent.getStringArrayListExtra(KEY_WRITE_FILE_LIST);
  64. ArrayList<String> arrayList = mWriteFileList;
  65. if (arrayList != null) {
  66. if (!checkWriteFile(mImageList, arrayList)) {
  67. setResult(3);
  68. finish();
  69. }
  70. ((TextView) findViewById(R.id.copyingMessageText)).setText(R.string.mcphotocopy_sending_message);
  71. }
  72. mCifsAccessStorageType = intent.getIntExtra(KEY_CIFS_STORAGE_TYPE, 1);
  73. mWifiDirectConnector = new WifiDirectConnector(this, intent.getBooleanExtra(KEY_CHECK_WIFI_DIRECT, false));
  74. mCancelButton = (Button) findViewById(R.id.cancel_button);
  75. mCancelButton.setOnClickListener(new View.OnClickListener() {
  76. public void onClick(View view) {
  77. MemcardWriteProgress.this.actionCancelTask();
  78. }
  79. });
  80. execCopyTask();
  81. }
  82. protected void execCopyTask() {
  83. EPLog.i(LOG_TAG, "mCopyTask.execute()");
  84. mCopyTask = new CopyTask(this, mCifsAccessStorageType, mMemcardStorageType, mImageList, mWriteFileList, mTargetFolderName, getLogData());
  85. mCopyTask.executeOnExecutor(new Void[0]);
  86. }
  87. private CommonLog getLogData() {
  88. CommonLog commonLog = new CommonLog();
  89. commonLog.numberOfSheet = 0;
  90. commonLog.action = PrintLog.ACTION_ID_MEMORY_CARD_COPY_TO_PRINTER;
  91. commonLog.printerName = Analytics.getDefaultPrinterName(this);
  92. return commonLog;
  93. }
  94. /* JADX WARNING: Removed duplicated region for block: B:9:0x001a */
  95. /* Code decompiled incorrectly, please refer to instructions dump. */
  96. protected static boolean checkWriteFile(java.util.ArrayList<java.lang.String> r3, java.util.ArrayList<java.lang.String> r4) {
  97. /*
  98. r0 = 1
  99. if (r4 != 0) goto L_0x0004
  100. return r0
  101. L_0x0004:
  102. int r1 = r4.size()
  103. int r3 = r3.size()
  104. r2 = 0
  105. if (r1 == r3) goto L_0x0010
  106. return r2
  107. L_0x0010:
  108. java.util.Iterator r3 = r4.iterator()
  109. L_0x0014:
  110. boolean r4 = r3.hasNext()
  111. if (r4 == 0) goto L_0x0031
  112. java.lang.Object r4 = r3.next()
  113. java.lang.String r4 = (java.lang.String) r4
  114. java.lang.String r1 = ".*[\"*/:<>?\\\\|].*"
  115. boolean r1 = r4.matches(r1)
  116. if (r1 != 0) goto L_0x0030
  117. int r4 = r4.length()
  118. r1 = 128 (0x80,float:1.794E-43)
  119. if (r4 < r1) goto L_0x0014
  120. L_0x0030:
  121. return r2
  122. L_0x0031:
  123. return r0
  124. */
  125. throw new UnsupportedOperationException("Method not decompiled: com.epson.memcardacc.MemcardWriteProgress.checkWriteFile(java.util.ArrayList, java.util.ArrayList):boolean");
  126. }
  127. protected void onStart() {
  128. super.onStart();
  129. MemcardUtil.keepScreenOn(getWindow());
  130. }
  131. protected void onResume() {
  132. super.onResume();
  133. mWifiDirectConnector.tryConnectWifiDirect();
  134. }
  135. protected void onStop() {
  136. EPLog.d(LOG_TAG, "onStop()");
  137. MemcardUtil.clearKeepScreenOn(getWindow());
  138. actionCancelTask();
  139. super.onStop();
  140. }
  141. protected void actionCancelTask() {
  142. mCancelButton.setEnabled(false);
  143. taskCancel();
  144. }
  145. protected void taskCancel() {
  146. mCopyTask.taskCancel();
  147. }
  148. public void setProgressText(int i, int i2) {
  149. mSheetPerTotalText.setText(String.format("%d/%d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)}));
  150. }
  151. public void setProgress(int i, int i2) {
  152. setProgressText(i, i2);
  153. mTotalProgress.setMax(i2);
  154. mTotalProgress.setProgress(i);
  155. }
  156. public void finishWithState(int i, int i2, @Nullable CommonLog commonLog) {
  157. EPLog.d(LOG_TAG, "finishWithState state = " + i);
  158. mWifiDirectConnector.tryDisconnectWifiDirect();
  159. if (commonLog != null && commonLog.numberOfSheet > 0) {
  160. Analytics.sendCommonLog(this, commonLog);
  161. }
  162. Intent intent = null;
  163. if (i2 != 0) {
  164. intent = new Intent();
  165. intent.putExtra(RESULT_KEY_CIFS_ERROR_CODE, i2);
  166. }
  167. setResult(i, intent);
  168. finish();
  169. }
  170. private void connectOk() {
  171. mCountDownLatch.countDown();
  172. }
  173. protected boolean waitWifiConnect() {
  174. try {
  175. return mCountDownLatch.await(4, TimeUnit.MINUTES);
  176. } catch (InterruptedException e) {
  177. e.printStackTrace();
  178. return false;
  179. }
  180. }
  181. class WifiDirectConnector {
  182. private boolean isTryConnectSimpleAp;
  183. private Activity mActivity;
  184. private boolean mCheckWifiDirect;
  185. public WifiDirectConnector(Activity activity, boolean z) {
  186. mCheckWifiDirect = z;
  187. mActivity = activity;
  188. }
  189. public void tryConnectWifiDirect() {
  190. if (!mCheckWifiDirect) {
  191. MemcardWriteProgress.this.connectOk();
  192. return;
  193. }
  194. if (!WiFiDirectManager.isNeedConnect(mActivity, WiFiDirectManager.DEVICE_TYPE_PRINTER)) {
  195. isTryConnectSimpleAp = false;
  196. } else if (!this.isTryConnectSimpleAp) {
  197. isTryConnectSimpleAp = true;
  198. if (WiFiDirectManager.reconnect(mActivity, WiFiDirectManager.DEVICE_TYPE_PRINTER, -1)) {
  199. return;
  200. }
  201. }
  202. MemcardWriteProgress.this.connectOk();
  203. }
  204. public void tryDisconnectWifiDirect() {
  205. if (mCheckWifiDirect) {
  206. Activity activity = mActivity;
  207. WiFiDirectManager.disconnect(activity, WiFiDirectManager.DEVICE_TYPE_PRINTER, MemcardUtil.getPrinterIpAddress(activity));
  208. }
  209. }
  210. }
  211. }