ActivityViewImageSelect.java 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  1. package epson.print;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.ComponentName;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.content.IntentFilter;
  9. import android.content.ServiceConnection;
  10. import android.content.SharedPreferences;
  11. import android.content.res.Configuration;
  12. import android.database.Cursor;
  13. import android.net.Uri;
  14. import android.os.AsyncTask;
  15. import android.os.Bundle;
  16. import android.os.Handler;
  17. import android.os.IBinder;
  18. import android.os.Message;
  19. import android.os.RemoteException;
  20. import android.support.annotation.MainThread;
  21. import android.view.KeyEvent;
  22. import android.view.Menu;
  23. import android.view.MenuItem;
  24. import android.view.View;
  25. import android.widget.AdapterView;
  26. import android.widget.Button;
  27. import android.widget.Gallery;
  28. import android.widget.ImageButton;
  29. import android.widget.ImageView;
  30. import android.widget.LinearLayout;
  31. import android.widget.TextView;
  32. import android.widget.Toast;
  33. import android.widget.ZoomControls;
  34. import androidx.annotation.NonNull;
  35. import androidx.annotation.Nullable;
  36. import androidx.fragment.app.DialogFragment;
  37. import androidx.fragment.app.FragmentActivity;
  38. import androidx.lifecycle.Observer;
  39. import androidx.lifecycle.ViewModelProviders;
  40. import com.epson.iprint.apf.ApfAdapter;
  41. import com.epson.iprint.apf.ApfPreviewView;
  42. import com.epson.iprint.prtlogger.NewLoggerController;
  43. import com.epson.iprint.prtlogger.PrintLog;
  44. import com.epson.iprint.shared.EpsoniPrintSharedActivity;
  45. import com.epson.iprint.shared.SharedParamPhoto;
  46. import com.epson.mobilephone.common.ReviewInvitationDialog;
  47. import com.epson.mobilephone.common.ReviewInvitationViewModel;
  48. import com.epson.mobilephone.common.escpr.MediaInfo;
  49. import com.epson.mobilephone.common.license.LicenseTopActivity;
  50. import com.epson.mobilephone.common.wifidirect.NfcTagUtils;
  51. import java.io.File;
  52. import java.io.FileNotFoundException;
  53. import java.io.FileOutputStream;
  54. import java.io.IOException;
  55. import java.io.InputStream;
  56. import java.util.ArrayList;
  57. import java.util.Deque;
  58. import java.util.Iterator;
  59. import epson.common.Constants;
  60. import epson.common.DialogProgressViewModel;
  61. import epson.common.ExternalFileUtils;
  62. import epson.common.IprintLicenseInfo;
  63. import epson.common.IprintUserSurveyInfo;
  64. import epson.common.OsAssistant;
  65. import epson.common.Utils;
  66. import epson.print.Util.AsyncTaskExecutor;
  67. import epson.print.Util.EPLog;
  68. import epson.print.imgsel.PhotoImageSelectActivity;
  69. import epson.print.phlayout.PhotoPreview;
  70. import epson.print.phlayout.PhotoPreviewImageList;
  71. import epson.print.screen.PaperSourceInfo;
  72. import epson.print.screen.PaperSourceSetting;
  73. import epson.print.screen.PaperSourceSettingScr;
  74. import epson.print.screen.PrintProgress;
  75. import epson.print.screen.PrintSetting;
  76. import epson.print.screen.SettingScr;
  77. import epson.print.service.EpsonService;
  78. import epson.print.service.IEpsonService;
  79. import epson.print.service.IEpsonServiceCallback;
  80. public class ActivityViewImageSelect extends ActivityIACommon implements View.OnClickListener, PhotoPreview.ViewSizeChangeListener, ReviewInvitationDialog.OnClickListener {
  81. private static final int ALL_REFRESH_DRAW_END = 4;
  82. private static final String DIALOG_ALL_UPDATE = "dialog_all_update";
  83. private static final String DIALOG_KEY_STORE_DIALOG = "store-dialog";
  84. private static final String DIALOG_LOAD = "dialog_load";
  85. private static final String DIALOG_PROGRESS = "dialog_progress";
  86. private static final int FROM_EPSON_PHOTO = 0;
  87. private static final int FROM_NOT_PHOTO = 1;
  88. public static final String LIST_ALBUM = "listAlbum";
  89. private static final int LOAD_ALL_IMAGE = 3;
  90. static final int MAX_IMAGE_NUMBER = 30;
  91. private static final int MESSAGE_OUT_OF_MEMORY_ERROR_NOTIFY = 8;
  92. private static final int OUT_OF_MEMORY_ERROR = 7;
  93. public static final String PARAMS_KEY_EPSON_COLOR_MODE = "epson_color_mode";
  94. public static final String PARAMS_KEY_FROM_EPSON = "FROM_EPSON";
  95. public static final String PARAMS_KEY_IMAGE_LIST = "imageList";
  96. public static final String PARAMS_KEY_PRINT_LOG = "print_log";
  97. private static final int PREVIEW_LOAD_DIALOG_DISMISS = 1;
  98. private static final int PREVIEW_LOAD_DIALOG_SHOW = 0;
  99. private static final int REQUEST_CODE_LICENSE_CHECK = 10;
  100. private static final int RESULT_RUNTIMEPERMMISSION = 9;
  101. private static final int START_PRINT = 5;
  102. private static final String TAG = "ActivityViewImageSelect";
  103. private static final int UPDATE_PAPERSIZE_TEXT = 6;
  104. private static final int ZOOM_CONTROL = 2;
  105. private ArrayList<PaperSourceSetting> aPaperSourceSetting;
  106. private ImageButton addButton = null;
  107. boolean bAutoStartPrint = false;
  108. boolean bRequestPermission = false;
  109. private Context context = null;
  110. private int currentColor = 0;
  111. private int currentLayout = 2;
  112. private int currentLayoutMulti = 0;
  113. private int currentPaperSize = 0;
  114. private String currentPrinterName = "";
  115. private Button deleteButton = null;
  116. private boolean enableShowWarning = true;
  117. private Gallery gallery = null;
  118. private GalleryAdapter galleryAdapter = null;
  119. private final PhotoPreviewImageList imageList = new PhotoPreviewImageList();
  120. private int imageNo = 0;
  121. private boolean isCustomAction = false;
  122. private boolean isPaperLandscape = false;
  123. private boolean isPrintedOK = false;
  124. private boolean isRemotePrinter = false;
  125. private boolean mAllReloadTaskDone;
  126. protected final Object mAllReloadTaskLock = new Object();
  127. private volatile boolean mAllReloadTaskRetryRequested;
  128. private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
  129. public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
  130. }
  131. public void onGetInkState() throws RemoteException {
  132. }
  133. public void onGetStatusState() throws RemoteException {
  134. }
  135. public void onNotifyContinueable(int i) throws RemoteException {
  136. }
  137. public void onNotifyEndJob(int i) throws RemoteException {
  138. }
  139. public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
  140. }
  141. public void onNotifyProgress(int i, int i2) throws RemoteException {
  142. }
  143. };
  144. private boolean mEnableEpsonColorDisplay;
  145. private ImageView mEpsonColorImageView;
  146. private ServiceConnection mEpsonConnection = new ServiceConnection() {
  147. public void onServiceDisconnected(ComponentName componentName) {
  148. try {
  149. mEpsonService.unregisterCallback(mCallback);
  150. } catch (RemoteException e) {
  151. e.printStackTrace();
  152. }
  153. IEpsonService unused = mEpsonService = null;
  154. }
  155. public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  156. IEpsonService unused = mEpsonService = IEpsonService.Stub.asInterface(iBinder);
  157. if (mEpsonService != null) {
  158. try {
  159. mEpsonService.registerCallback(mCallback);
  160. } catch (RemoteException e) {
  161. e.printStackTrace();
  162. }
  163. }
  164. }
  165. };
  166. private IEpsonService mEpsonService = null;
  167. private boolean mFileCheckEnd;
  168. Handler mHandler = new Handler(new Handler.Callback() {
  169. public boolean handleMessage(Message message) {
  170. if (isFinishing()) {
  171. return true;
  172. }
  173. int i = message.what;
  174. if (i != 100) {
  175. switch (i) {
  176. case 0:
  177. mModelDialog.doShow(DIALOG_LOAD);
  178. break;
  179. case 1:
  180. mModelDialog.doDismiss(DIALOG_LOAD);
  181. break;
  182. case 2:
  183. break;
  184. case 3:
  185. ActivityViewImageSelect activityViewImageSelect = ActivityViewImageSelect.this;
  186. AllReloadTask unused = reloadTask = new AllReloadTask(context);
  187. if (reloadTask != null) {
  188. reloadTask.executeOnExecutor(new Void[0]);
  189. }
  190. mHandler.sendEmptyMessageDelayed(1, 300);
  191. break;
  192. default:
  193. switch (i) {
  194. case 5:
  195. startPrint();
  196. break;
  197. case 6:
  198. papersizeTextView.setText(getString(new MediaInfo.PaperSize().getStringId(currentPaperSize)));
  199. break;
  200. case 7:
  201. if (imageList.size() <= 0) {
  202. deleteButton.setEnabled(false);
  203. printButton.setEnabled(false);
  204. int unused2 = imageNo = 0;
  205. }
  206. TextView access$1900 = pageTextView;
  207. access$1900.setText(imageNo + CommonDefine.SLASH + imageList.size());
  208. updateGallery();
  209. previewImageView.invalidate();
  210. Toast.makeText(context, context.getString(R.string.file_size_notsupport), 1).show();
  211. break;
  212. case 8:
  213. showSimpleDialog(R.string.str_err_msg_out_of_memory_title);
  214. return true;
  215. }
  216. }
  217. } else {
  218. ArrayList unused3 = aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO);
  219. if (aPaperSourceSetting != null) {
  220. papersizeTextView.setBackgroundColor(getResources().getColor(R.color.epson_blue));
  221. papersizeTextView.setTextColor(getResources().getColor(R.color.all_white));
  222. PrintSetting printSetting = new PrintSetting(ActivityViewImageSelect.this, PrintSetting.Kind.photo);
  223. printSetting.loadSettings();
  224. if (paperSourceInfo.checkPaperMissmatch(printSetting, aPaperSourceSetting)) {
  225. paperMissmath.setVisibility(View.VISIBLE);
  226. } else {
  227. paperMissmath.setVisibility(View.GONE);
  228. }
  229. } else {
  230. papersizeTextView.setBackgroundColor(getResources().getColor(R.color.all_white));
  231. papersizeTextView.setTextColor(getResources().getColor(R.color.epson_blue));
  232. paperMissmath.setVisibility(View.GONE);
  233. }
  234. }
  235. return true;
  236. }
  237. });
  238. private final ArrayList<String> mImageFilenameListFromIntent = new ArrayList<>();
  239. private int mIntentFileType = 0;
  240. protected volatile boolean mIsAllReloadTaskRetryAcceptable;
  241. private boolean mLicenseCheckDone;
  242. private DialogProgressViewModel mModelDialog;
  243. private boolean mOnSizeChangeReceived;
  244. private PrintLog mPrintLog;
  245. private ReviewInvitationViewModel mReviewInvitationViewModel;
  246. private int mStartActivityFromPhoto = 0;
  247. private TextView pageTextView = null;
  248. private ImageView paperMissmath = null;
  249. PaperSourceInfo paperSourceInfo = null;
  250. private TextView papersizeTextView = null;
  251. protected ApfPreviewView previewImageView;
  252. private Button printButton = null;
  253. private String printerId = "";
  254. private AllReloadTask reloadTask = null;
  255. private Button rotateButton = null;
  256. private ZoomControls zoomControls = null;
  257. public void onCreate(Bundle bundle) {
  258. super.onCreate(bundle);
  259. setContentView(R.layout.photo_preview);
  260. context = this;
  261. mReviewInvitationViewModel = (ReviewInvitationViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(ReviewInvitationViewModel.class);
  262. mReviewInvitationViewModel.getShowInvitationLiveData().observe(this, new Observer<Boolean>() {
  263. public void onChanged(@Nullable Boolean bool) {
  264. if (bool.booleanValue()) {
  265. showStoreDialog();
  266. }
  267. }
  268. });
  269. mOnSizeChangeReceived = false;
  270. mLicenseCheckDone = false;
  271. mFileCheckEnd = false;
  272. mModelDialog = (DialogProgressViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(DialogProgressViewModel.class);
  273. mModelDialog.getDialogJob().observe(this, new Observer() {
  274. public final void onChanged(Object obj) {
  275. lambda$onCreate$0(ActivityViewImageSelect.this, (Deque) obj);
  276. }
  277. });
  278. NewLoggerController.stopLoggerIfNotAgreed(this);
  279. setActionBar(R.string.photo_btn_label, true);
  280. ExternalFileUtils.getInstance(this).initTempViewDir();
  281. ExternalFileUtils.getInstance(this).initTempCRDir();
  282. ExternalFileUtils.getInstance(this).initPrintDir();
  283. Intent intent = getIntent();
  284. if (intent == null) {
  285. Toast.makeText(this, getString(R.string.no_image), 0).show();
  286. finish();
  287. }
  288. setFieldFromStartIntent(intent);
  289. if (mImageFilenameListFromIntent.size() == 0) {
  290. clearListToastAndFinish();
  291. return;
  292. }
  293. mEnableEpsonColorDisplay = getEpsonColorModeFromIntent(intent);
  294. PhotoPreview photoPreview = (PhotoPreview) findViewById(R.id.previewImageView);
  295. photoPreview.setViewSizeChangeListener(this);
  296. previewImageView = new ApfPreviewView();
  297. previewImageView.init(this, photoPreview);
  298. SharedPreferences sharedPreferences = getSharedPreferences("PrintSetting", 0);
  299. if (sharedPreferences != null) {
  300. currentPrinterName = sharedPreferences.getString(Constants.PRINTER_NAME, getString(R.string.str_lbl_title_scan));
  301. printerId = sharedPreferences.getString(Constants.PRINTER_ID, (String) null);
  302. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  303. printSetting.loadSettings();
  304. currentPaperSize = printSetting.paperSizeValue;
  305. currentLayout = printSetting.layoutValue;
  306. currentLayoutMulti = printSetting.layoutMultiPageValue;
  307. currentColor = printSetting.colorValue;
  308. previewImageView.setLayout(currentLayout, currentLayoutMulti);
  309. previewImageView.setPaper(currentPaperSize);
  310. previewImageView.setColor(currentColor);
  311. }
  312. previewImageView.setApfLibParams(0, 0, 0);
  313. papersizeTextView = (TextView) findViewById(R.id.btn_paper_size);
  314. papersizeTextView.setText(getPaperSizeName());
  315. papersizeTextView.setOnClickListener(this);
  316. pageTextView = (TextView) findViewById(R.id.btn_photo_count);
  317. Handler handler = mHandler;
  318. if (handler != null) {
  319. handler.sendEmptyMessage(2);
  320. }
  321. rotateButton = (Button) findViewById(R.id.bt_rotate);
  322. rotateButton.setOnClickListener(this);
  323. gallery = (Gallery) findViewById(R.id.gallery);
  324. if (mImageFilenameListFromIntent.size() != 0) {
  325. gallery.setCallbackDuringFling(false);
  326. gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  327. public void onNothingSelected(AdapterView<?> adapterView) {
  328. }
  329. public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
  330. if (imageNo != i) {
  331. int unused = imageNo = i;
  332. gallery.setSelection(imageNo);
  333. new PreviewImageSelectTask().executeOnExecutor(new Void[0]);
  334. }
  335. }
  336. });
  337. }
  338. addButton = (ImageButton) findViewById(R.id.btn_add_photo);
  339. addButton.setOnClickListener(this);
  340. deleteButton = (Button) findViewById(R.id.btn_deselect);
  341. deleteButton.setOnClickListener(this);
  342. if (mImageFilenameListFromIntent.size() == 0) {
  343. deleteButton.setEnabled(false);
  344. }
  345. if (mStartActivityFromPhoto != 0) {
  346. addButton.setVisibility(View.GONE);
  347. deleteButton.setVisibility(View.GONE);
  348. }
  349. printButton = (Button) findViewById(R.id.btn_print);
  350. printButton.setOnClickListener(this);
  351. previewImageView.setZoomControlHandler(mHandler);
  352. paperMissmath = (ImageView) findViewById(R.id.icon_papermissmatch);
  353. mModelDialog.doShow(DIALOG_LOAD);
  354. enableShowWarning = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).getBoolean(Constants.ENABLE_SHOW_WARNING, true);
  355. isRemotePrinter = MyPrinter.isRemotePrinter(this);
  356. switch (intent.getIntExtra("from", 0)) {
  357. case 3:
  358. setTitle(getString(R.string.document_btn_label));
  359. ((LinearLayout) findViewById(R.id.linearLayout3)).setVisibility(View.GONE);
  360. break;
  361. case 4:
  362. setTitle(getString(R.string.network_storage_title));
  363. ((LinearLayout) findViewById(R.id.linearLayout3)).setVisibility(View.GONE);
  364. break;
  365. default:
  366. setTitle(getString(R.string.photo_btn_label));
  367. break;
  368. }
  369. mEpsonColorImageView = (ImageView) findViewById(R.id.epsonColorImageView);
  370. updateEpsonColorStatus();
  371. paperSourceInfo = PaperSourceInfo.getInstance(this);
  372. if (mEpsonService == null) {
  373. bindService(new Intent(this, EpsonService.class), mEpsonConnection, 1);
  374. }
  375. if (bundle == null) {
  376. startLicenseCheckActivity();
  377. } else if (!permissionCheck()) {
  378. finish();
  379. }
  380. }
  381. public static /* synthetic */ void lambda$onCreate$0(ActivityViewImageSelect activityViewImageSelect, Deque deque) {
  382. String[] checkQueue = mModelDialog.checkQueue();
  383. if (checkQueue != null) {
  384. String str = checkQueue[0];
  385. String str2 = checkQueue[1];
  386. if (str2.equals("do_show")) {
  387. showDialog(str);
  388. }
  389. if (str2.equals("do_dismiss")) {
  390. dismissDialog(str);
  391. }
  392. }
  393. }
  394. private void showStoreDialog() {
  395. ReviewInvitationDialog.newInstance().show(getSupportFragmentManager(), DIALOG_KEY_STORE_DIALOG);
  396. }
  397. private void observeImageList(PhotoPreviewImageList photoPreviewImageList) {
  398. PhotoImageConvertViewModel photoImageConvertViewModel = (PhotoImageConvertViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(PhotoImageConvertViewModel.class);
  399. photoImageConvertViewModel.getData().observe(this, new Observer<PhotoImageConvertViewModel.Result>() {
  400. public void onChanged(@Nullable PhotoImageConvertViewModel.Result result) {
  401. if (result.epImageWrappers == null) {
  402. clearListToastAndFinish();
  403. } else if (!setPhotoImageList(result.epImageWrappers)) {
  404. clearListToastAndFinish();
  405. } else {
  406. updateImageListDisplay();
  407. boolean unused = mFileCheckEnd = true;
  408. loadImage();
  409. }
  410. }
  411. });
  412. photoImageConvertViewModel.setOriginalImageList(mImageFilenameListFromIntent);
  413. }
  414. private void updateGallery() {
  415. galleryAdapter.setImageList(imageList.getGalleryFileList());
  416. }
  417. private boolean checkExternalStorageReadPermission() {
  418. return ActivityRequestPermissions.checkPermission(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"});
  419. }
  420. private void requestReadExternalStoragePermission() {
  421. ActivityRequestPermissions.requestPermission((Activity) this, new ActivityRequestPermissions.Permission(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}[0], new String[]{getString(R.string.permission_dialog_title), getString(R.string.permission_dialog_title)}, new String[]{ActivityRequestPermissions.DialogParameter.setMessage2((Context) this, getString(R.string.permission_dialog_message_storage)), ActivityRequestPermissions.DialogParameter.setMessage3A((Context) this, getString(R.string.permission_dialog_message_storage), getString(R.string.permission_function_storage))}), 9);
  422. bRequestPermission = true;
  423. }
  424. private boolean setPhotoImageList(@Nullable ArrayList<PhotoPreviewImageList.EpImageWrapper> arrayList) {
  425. imageList.clear();
  426. if (arrayList == null) {
  427. return false;
  428. }
  429. Iterator<PhotoPreviewImageList.EpImageWrapper> it = arrayList.iterator();
  430. while (it.hasNext()) {
  431. imageList.add(it.next());
  432. }
  433. if (imageList.size() <= 0) {
  434. return false;
  435. }
  436. return true;
  437. }
  438. private void updateImageListDisplay() {
  439. previewImageView.setImageList(imageList);
  440. TextView textView = pageTextView;
  441. textView.setText("1/" + imageList.size());
  442. if (imageList.size() == 0) {
  443. deleteButton.setEnabled(false);
  444. }
  445. }
  446. private void startLicenseCheckActivity() {
  447. IprintLicenseInfo.beforeLicenseCheck(getApplicationContext());
  448. startActivityForResult(LicenseTopActivity.getStartIntent(getApplicationContext(), new IprintLicenseInfo(), new IprintUserSurveyInfo()), 10);
  449. }
  450. private void setFieldFromStartIntent(@NonNull Intent intent) {
  451. ArrayList<String> arrayFileFullPath;
  452. int i = 0;
  453. isCustomAction = false;
  454. mImageFilenameListFromIntent.clear();
  455. mIntentFileType = 0;
  456. mStartActivityFromPhoto = 1;
  457. try {
  458. mPrintLog = (PrintLog) intent.getSerializableExtra("print_log");
  459. } catch (ClassCastException unused) {
  460. }
  461. if (EpsoniPrintSharedActivity.ACTION_PHOTO_PRINT.equals(intent.getAction())) {
  462. isCustomAction = true;
  463. SharedParamPhoto sharedParamPhoto = (SharedParamPhoto) intent.getSerializableExtra("extParam");
  464. if (sharedParamPhoto != null && (arrayFileFullPath = sharedParamPhoto.getArrayFileFullPath()) != null) {
  465. int i2 = 0;
  466. while (i < arrayFileFullPath.size()) {
  467. if (i2 < 30) {
  468. mImageFilenameListFromIntent.add(arrayFileFullPath.get(i));
  469. i2++;
  470. }
  471. i++;
  472. }
  473. if (sharedParamPhoto.isFileTypeValid()) {
  474. mIntentFileType = sharedParamPhoto.getFile_type();
  475. }
  476. mStartActivityFromPhoto = 1;
  477. } else {
  478. return;
  479. }
  480. } else {
  481. if (intent.getStringArrayListExtra(LIST_ALBUM) == null && intent.getStringArrayListExtra("imageList") == null && -1 == intent.getIntExtra("from", -1)) {
  482. new PrintSetting(this, (PrintSetting.Kind) null).resetPrintSettings();
  483. }
  484. if (intent.getStringArrayListExtra(LIST_ALBUM) != null) {
  485. if (intent.getBooleanExtra(CommonDefine.STYPE, false)) {
  486. mStartActivityFromPhoto = 1;
  487. intent.removeExtra(CommonDefine.STYPE);
  488. }
  489. ArrayList<String> stringArrayListExtra = intent.getStringArrayListExtra(LIST_ALBUM);
  490. if (stringArrayListExtra != null) {
  491. while (i < stringArrayListExtra.size()) {
  492. mImageFilenameListFromIntent.add(stringArrayListExtra.get(i));
  493. i++;
  494. }
  495. intent.removeExtra(LIST_ALBUM);
  496. } else {
  497. return;
  498. }
  499. } else if (intent.getBooleanExtra(PARAMS_KEY_FROM_EPSON, false)) {
  500. mStartActivityFromPhoto = 1;
  501. Uri uri = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM");
  502. if (uri != null) {
  503. String decode = Uri.decode(uri.getPath());
  504. if (decode != null) {
  505. mImageFilenameListFromIntent.add(decode);
  506. } else {
  507. return;
  508. }
  509. } else {
  510. ArrayList<String> stringArrayListExtra2 = intent.getStringArrayListExtra("android.intent.extra.STREAM");
  511. if (stringArrayListExtra2 != null) {
  512. while (i < stringArrayListExtra2.size()) {
  513. mImageFilenameListFromIntent.add(stringArrayListExtra2.get(i));
  514. i++;
  515. }
  516. } else {
  517. return;
  518. }
  519. }
  520. } else if ("android.intent.action.SEND".equals(intent.getAction())) {
  521. mStartActivityFromPhoto = 1;
  522. setPrintLogForExternalApp();
  523. try {
  524. Uri uri2 = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM");
  525. if (uri2 != null) {
  526. addImageByIntent(intent, uri2);
  527. } else {
  528. return;
  529. }
  530. } catch (Exception unused2) {
  531. return;
  532. }
  533. } else if ("android.intent.action.VIEW".equals(intent.getAction())) {
  534. mStartActivityFromPhoto = 1;
  535. setPrintLogForExternalApp();
  536. try {
  537. addImageByIntent(intent, intent.getData());
  538. } catch (Exception unused3) {
  539. }
  540. } else if ("android.intent.action.SEND_MULTIPLE".equals(intent.getAction())) {
  541. mStartActivityFromPhoto = 1;
  542. setPrintLogForExternalApp();
  543. Bundle extras = intent.getExtras();
  544. if (extras != null) {
  545. if (extras.get("android.intent.extra.STREAM") instanceof ArrayList) {
  546. try {
  547. ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra("android.intent.extra.STREAM");
  548. if (parcelableArrayListExtra != null) {
  549. while (i < parcelableArrayListExtra.size() && i < 30) {
  550. try {
  551. addImageByIntent(intent, (Uri) parcelableArrayListExtra.get(i));
  552. i++;
  553. } catch (Exception unused4) {
  554. return;
  555. }
  556. }
  557. }
  558. } catch (Exception unused5) {
  559. return;
  560. }
  561. } else {
  562. try {
  563. addImageByIntent(intent, (Uri) intent.getExtras().getParcelable("android.intent.extra.STREAM"));
  564. } catch (Exception unused6) {
  565. return;
  566. }
  567. }
  568. } else {
  569. return;
  570. }
  571. } else {
  572. mStartActivityFromPhoto = 0;
  573. ArrayList<String> stringArrayListExtra3 = intent.getStringArrayListExtra("imageList");
  574. if (stringArrayListExtra3 != null) {
  575. while (i < stringArrayListExtra3.size()) {
  576. mImageFilenameListFromIntent.add(stringArrayListExtra3.get(i));
  577. i++;
  578. }
  579. } else {
  580. return;
  581. }
  582. }
  583. }
  584. if (mPrintLog == null) {
  585. mPrintLog = new PrintLog();
  586. }
  587. }
  588. private void setPrintLogForExternalApp() {
  589. if (mPrintLog == null) {
  590. mPrintLog = new PrintLog();
  591. }
  592. if (mPrintLog.callerPackage == null) {
  593. mPrintLog.callerPackage = getCallingPackage();
  594. }
  595. if (mPrintLog.uiRoute <= 0) {
  596. mPrintLog.uiRoute = 4097;
  597. }
  598. }
  599. private void requestPermissionOrObserveImageList() {
  600. if (!requestExternalStoragePermissionIfNeeded()) {
  601. observeImageList(imageList);
  602. }
  603. }
  604. private boolean requestExternalStoragePermissionIfNeeded() {
  605. if (!isPermissionRequestRequired(mImageFilenameListFromIntent)) {
  606. return false;
  607. }
  608. requestReadExternalStoragePermission();
  609. return true;
  610. }
  611. private boolean isPermissionRequestRequired(@NonNull ArrayList<String> arrayList) {
  612. if (!ActivityRequestPermissions.isRuntimePermissionSupported() || checkExternalStorageReadPermission()) {
  613. return false;
  614. }
  615. String lowerCase = ExternalFileUtils.getInstance(this).getWorkingDir().toLowerCase();
  616. Iterator<String> it = arrayList.iterator();
  617. while (it.hasNext()) {
  618. if (!it.next().toLowerCase().startsWith(lowerCase)) {
  619. return true;
  620. }
  621. }
  622. return false;
  623. }
  624. private void loadImage() {
  625. if (mFileCheckEnd && mOnSizeChangeReceived && mLicenseCheckDone) {
  626. galleryAdapter = new GalleryAdapter(getApplicationContext(), imageList.getGalleryFileList());
  627. gallery.setAdapter(galleryAdapter);
  628. gallery.setSelection(imageNo);
  629. galleryAdapter.setAlignLeft(gallery);
  630. mHandler.sendEmptyMessage(3);
  631. }
  632. }
  633. private void clearListToastAndFinish() {
  634. Toast.makeText(this, getString(R.string.file_size_notsupport), 1).show();
  635. imageList.clear();
  636. onBackPressed();
  637. }
  638. public static boolean checkBmpNot24Bit(@NonNull EPImage ePImage) {
  639. return Utils.checkMimeType(ePImage.loadImageFileName, CommonDefine.IMAGE_TYPE_BMP) && new EPImageUtil().getBitCount(ePImage.loadImageFileName) != 24;
  640. }
  641. private void addImageByIntent(Intent intent, Uri uri) {
  642. String contentFromCR;
  643. String type = intent.getType();
  644. String uri2 = uri.toString();
  645. if (uri2.startsWith("content://")) {
  646. Cursor cursor = null;
  647. try {
  648. cursor = getContentResolver().query(uri, new String[]{"_data"}, (String) null, (String[]) null, (String) null);
  649. } catch (IllegalArgumentException unused) {
  650. }
  651. if (cursor != null) {
  652. cursor.close();
  653. } else if (uri.toString().startsWith("content://com.android.gallery3d.provider")) {
  654. EPLog.d(TAG, "Actual URI: " + uri.toString());
  655. uri = Uri.parse(uri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d"));
  656. EPLog.d(TAG, "Effective URI: " + uri.toString());
  657. }
  658. String contentFromCR2 = getContentFromCR(uri, type);
  659. if (contentFromCR2 != null) {
  660. mImageFilenameListFromIntent.add(contentFromCR2);
  661. return;
  662. }
  663. String realPathFromURI = getRealPathFromURI(uri);
  664. if (realPathFromURI != null) {
  665. mImageFilenameListFromIntent.add(realPathFromURI);
  666. EPLog.d(TAG, "addImageByIntent by getRealPathFromURI");
  667. return;
  668. }
  669. } else if (uri2.startsWith("file://")) {
  670. if (type == null || type.length() <= 0 || (contentFromCR = getContentFromCR(uri, type)) == null) {
  671. String path = uri.getPath();
  672. if (path.startsWith("/file:")) {
  673. path = path.substring(6);
  674. }
  675. if (Utils.isPhotoFile(path)) {
  676. mImageFilenameListFromIntent.add(path);
  677. EPLog.d(TAG, "addImageByIntent by isPhotoFile()");
  678. return;
  679. }
  680. } else {
  681. mImageFilenameListFromIntent.add(contentFromCR);
  682. return;
  683. }
  684. }
  685. clearListToastAndFinish();
  686. }
  687. private String getContentFromCR(Uri uri, String str) {
  688. String str2;
  689. File file;
  690. EPLog.d(TAG, "getContentFromCR uri = " + uri + " fType = " + str);
  691. try {
  692. str2 = Utils.makeTempFileName(str);
  693. } catch (FileNotFoundException unused) {
  694. EPLog.w(TAG, "getContentFromCR Unknown fType = " + str);
  695. str2 = String.valueOf(System.currentTimeMillis());
  696. }
  697. try {
  698. InputStream openInputStream = getContentResolver().openInputStream(uri);
  699. File file2 = new File(ExternalFileUtils.getInstance(this).getTempCRDir(), str2);
  700. FileOutputStream fileOutputStream = new FileOutputStream(file2);
  701. byte[] bArr = new byte[1024];
  702. while (true) {
  703. int read = openInputStream.read(bArr);
  704. if (read <= 0) {
  705. break;
  706. }
  707. fileOutputStream.write(bArr, 0, read);
  708. }
  709. fileOutputStream.close();
  710. if (Utils.getExtention(file2.getName()) == null) {
  711. String realMimeType = Utils.getRealMimeType(file2.getAbsolutePath());
  712. String mimeExt = realMimeType != null ? Utils.getMimeExt(realMimeType) : null;
  713. if (mimeExt != null) {
  714. file = new File(file2.getAbsolutePath() + mimeExt);
  715. file2.renameTo(file);
  716. EPLog.d(TAG, "getContentFromCR success");
  717. return file.getAbsolutePath();
  718. }
  719. }
  720. file = file2;
  721. EPLog.d(TAG, "getContentFromCR success");
  722. return file.getAbsolutePath();
  723. } catch (IOException e) {
  724. e.printStackTrace();
  725. return null;
  726. }
  727. }
  728. public String getRealPathFromURI(Uri uri) {
  729. Cursor query = getContentResolver().query(uri, new String[]{"_data"}, (String) null, (String[]) null, (String) null);
  730. String str = null;
  731. if (query == null) {
  732. return null;
  733. }
  734. try {
  735. int columnIndexOrThrow = query.getColumnIndexOrThrow("_data");
  736. query.moveToFirst();
  737. str = query.getString(columnIndexOrThrow);
  738. } catch (Exception e) {
  739. e.printStackTrace();
  740. } catch (Throwable th) {
  741. query.close();
  742. throw th;
  743. }
  744. query.close();
  745. return str;
  746. }
  747. public static boolean checkEPImage(EPImage ePImage) {
  748. return ePImage != null && ePImage.srcWidth > 0 && ePImage.srcHeight > 0;
  749. }
  750. protected boolean getEpsonColorModeFromIntent(Intent intent) {
  751. return intent.getBooleanExtra(PARAMS_KEY_EPSON_COLOR_MODE, false);
  752. }
  753. private String getPaperSizeName() {
  754. MediaInfo.PaperSize paperSize = new MediaInfo.PaperSize();
  755. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  756. printSetting.loadSettings();
  757. return getString(paperSize.getStringId(printSetting.paperSizeValue));
  758. }
  759. private boolean permissionCheck() {
  760. if (!IprintLicenseInfo.isAgreedCurrentVersion(getApplicationContext())) {
  761. return false;
  762. }
  763. mLicenseCheckDone = true;
  764. requestPermissionOrObserveImageList();
  765. return true;
  766. }
  767. protected void onActivityResult(int i, int i2, Intent intent) {
  768. super.onActivityResult(i, i2, intent);
  769. switch (i) {
  770. case 5:
  771. if (i2 == -1) {
  772. SharedPreferences sharedPreferences = getSharedPreferences("PrintSetting", 0);
  773. String string = sharedPreferences.getString(Constants.PRINTER_NAME, getString(R.string.str_lbl_title_scan));
  774. if (!string.equals(currentPrinterName)) {
  775. currentPrinterName = string;
  776. printerId = sharedPreferences.getString(Constants.PRINTER_ID, (String) null);
  777. updateEpsonColorStatus();
  778. bAutoStartPrint = true;
  779. mHandler.sendEmptyMessage(3);
  780. return;
  781. }
  782. onClick(printButton);
  783. EPLog.d(TAG, "onClick(printButton)");
  784. return;
  785. }
  786. return;
  787. case 9:
  788. if (i2 != -1) {
  789. clearListToastAndFinish();
  790. return;
  791. } else {
  792. requestPermissionOrObserveImageList();
  793. return;
  794. }
  795. case 10:
  796. if (!permissionCheck()) {
  797. mModelDialog.doDismiss(DIALOG_LOAD);
  798. finish();
  799. return;
  800. }
  801. return;
  802. case CommonDefine.REQUEST_SETTING /*254*/:
  803. onPrintSettingEnd(i2);
  804. return;
  805. case 255:
  806. unlockScreenRotation();
  807. if (i2 == 0) {
  808. setResult(i2);
  809. if (isCustomAction) {
  810. setResult(0);
  811. finish();
  812. return;
  813. }
  814. } else if (i2 != 4) {
  815. if (i2 == 1000) {
  816. printButton.setEnabled(true);
  817. ExternalFileUtils.getInstance(this).initPrintDir();
  818. return;
  819. }
  820. return;
  821. }
  822. mReviewInvitationViewModel.onPrintEnd(PrintProgress.isPrintSuccess(i2));
  823. if (isCustomAction) {
  824. setResult(-1);
  825. finish();
  826. return;
  827. }
  828. printButton.setEnabled(true);
  829. ExternalFileUtils.getInstance(this).initPrintDir();
  830. return;
  831. default:
  832. return;
  833. }
  834. }
  835. private void onPrintSettingEnd(int i) {
  836. int i2;
  837. boolean z;
  838. int i3;
  839. int i4;
  840. int i5;
  841. int i6;
  842. int i7;
  843. boolean z2;
  844. if (i == 3) {
  845. printButton.setEnabled(true);
  846. SharedPreferences sharedPreferences = getSharedPreferences("PrintSetting", 0);
  847. String string = getString(R.string.str_lbl_title_scan);
  848. printerId = sharedPreferences.getString(Constants.PRINTER_ID, (String) null);
  849. int i8 = 2;
  850. if (sharedPreferences != null) {
  851. string = sharedPreferences.getString(Constants.PRINTER_NAME, getString(R.string.str_lbl_title_scan));
  852. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  853. printSetting.loadSettings();
  854. i7 = printSetting.paperSizeValue;
  855. i8 = printSetting.layoutValue;
  856. i6 = printSetting.layoutMultiPageValue;
  857. i5 = printSetting.colorValue;
  858. i4 = printSetting.photoApfValueForLocalPrinter;
  859. i3 = printSetting.sharpnessForPhoto;
  860. int i9 = printSetting.paperTypeValue;
  861. int code = Constants.MediaName.EPS_MTID_PLAIN.getCode();
  862. EpLog.m77i("KIND = " + printSetting.getKind() + " NEW setteing = " + i9 + " plain = " + code);
  863. i2 = (i9 == code && printSetting.getKind() == PrintSetting.Kind.photo) ? 1 : 0;
  864. z = MyPrinter.isRemotePrinter(this);
  865. } else {
  866. i2 = 0;
  867. i7 = 0;
  868. i6 = 0;
  869. i5 = 0;
  870. i4 = 0;
  871. i3 = 0;
  872. z = false;
  873. }
  874. if (!currentPrinterName.equalsIgnoreCase(string)) {
  875. currentPrinterName = string;
  876. z2 = true;
  877. } else {
  878. z2 = false;
  879. }
  880. if (currentLayout != i8) {
  881. currentLayout = i8;
  882. previewImageView.setLayout(currentLayout, currentLayoutMulti);
  883. z2 = true;
  884. }
  885. if (currentLayoutMulti != i6) {
  886. currentLayoutMulti = i6;
  887. previewImageView.setLayout(currentLayout, currentLayoutMulti);
  888. z2 = true;
  889. }
  890. if (currentPaperSize != i7) {
  891. currentPaperSize = i7;
  892. previewImageView.setPaper(i7);
  893. papersizeTextView.setText(getString(new MediaInfo.PaperSize().getStringId(i7)));
  894. z2 = true;
  895. }
  896. if (currentColor != i5) {
  897. currentColor = i5;
  898. previewImageView.setColor(currentColor);
  899. z2 = true;
  900. }
  901. if (imageList.size() == 0) {
  902. printButton.setEnabled(false);
  903. }
  904. if (isRemotePrinter != z) {
  905. isRemotePrinter = z;
  906. z2 = true;
  907. }
  908. if (!z) {
  909. if (previewImageView.getApfMode() != i4) {
  910. z2 = true;
  911. }
  912. if (previewImageView.getSharpnessValue() != i3) {
  913. z2 = true;
  914. }
  915. if (previewImageView.getClearlyVividMode() != i2) {
  916. z2 = true;
  917. }
  918. }
  919. updateEpsonColorStatus();
  920. if (z2) {
  921. mHandler.sendEmptyMessage(3);
  922. }
  923. }
  924. }
  925. private boolean isEpsonColorMode() {
  926. boolean z = false;
  927. if (!mEnableEpsonColorDisplay) {
  928. return false;
  929. }
  930. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  931. printSetting.loadSettings();
  932. int apfValue = getApfValue(printSetting);
  933. int i = printSetting.paperTypeValue;
  934. int i2 = printSetting.colorValue;
  935. if (apfValue == 1) {
  936. z = true;
  937. }
  938. return ApfAdapter.isEpsonColor(this, i, i2, z);
  939. }
  940. private void updateEpsonColorStatus() {
  941. mEpsonColorImageView.setVisibility(isEpsonColorMode() ? 0 : 8);
  942. }
  943. protected void onResume() {
  944. EPLog.d("ActivityImageViewSelect", "onResume");
  945. super.onResume();
  946. NfcTagUtils.enableForegroundDispatch(this, (IntentFilter[]) null, (String[][]) null);
  947. paperMissmath.setVisibility(View.GONE);
  948. paperSourceInfo.start(this, mHandler);
  949. }
  950. protected void onNewIntent(Intent intent) {
  951. NfcTagUtils.EpsonNfcConnectInfo parseNECTag;
  952. super.onNewIntent(intent);
  953. String action = intent.getAction();
  954. if (reloadTask != null) {
  955. switch (C211111.$SwitchMap$android$os$AsyncTask$Status[reloadTask.getStatus().ordinal()]) {
  956. case 1:
  957. case 2:
  958. if ("android.nfc.action.NDEF_DISCOVERED".equals(action) && (parseNECTag = NfcTagUtils.parseNECTag(this, intent)) != null) {
  959. Intent intent2 = new Intent();
  960. intent2.setClass(this, ActivityNfcPrinter.class);
  961. intent2.putExtra(ActivityNfcPrinter.CONNECTINFO, parseNECTag);
  962. intent2.putExtra(ActivityNfcPrinter.CHANGEMODE, 1);
  963. startActivityForResult(intent2, 5);
  964. return;
  965. }
  966. return;
  967. default:
  968. return;
  969. }
  970. }
  971. }
  972. /* renamed from: epson.print.ActivityViewImageSelect$11 */
  973. static /* synthetic */ class C211111 {
  974. static final /* synthetic */ int[] $SwitchMap$android$os$AsyncTask$Status = new int[AsyncTask.Status.values().length];
  975. /* JADX WARNING: Can't wrap try/catch for region: R(6:0|1|2|3|4|6) */
  976. /* JADX WARNING: Code restructure failed: missing block: B:7:?, code lost:
  977. return;
  978. */
  979. /* JADX WARNING: Failed to process nested try/catch */
  980. /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0014 */
  981. static {
  982. /*
  983. android.os.AsyncTask$Status[] r0 = android.os.AsyncTask.Status.values()
  984. int r0 = r0.length
  985. int[] r0 = new int[r0]
  986. $SwitchMap$android$os$AsyncTask$Status = r0
  987. int[] r0 = $SwitchMap$android$os$AsyncTask$Status // Catch:{ NoSuchFieldError -> 0x0014 }
  988. android.os.AsyncTask$Status r1 = android.os.AsyncTask.Status.PENDING // Catch:{ NoSuchFieldError -> 0x0014 }
  989. int r1 = r1.ordinal() // Catch:{ NoSuchFieldError -> 0x0014 }
  990. r2 = 1
  991. r0[r1] = r2 // Catch:{ NoSuchFieldError -> 0x0014 }
  992. L_0x0014:
  993. int[] r0 = $SwitchMap$android$os$AsyncTask$Status // Catch:{ NoSuchFieldError -> 0x001f }
  994. android.os.AsyncTask$Status r1 = android.os.AsyncTask.Status.FINISHED // Catch:{ NoSuchFieldError -> 0x001f }
  995. int r1 = r1.ordinal() // Catch:{ NoSuchFieldError -> 0x001f }
  996. r2 = 2
  997. r0[r1] = r2 // Catch:{ NoSuchFieldError -> 0x001f }
  998. L_0x001f:
  999. return
  1000. */
  1001. throw new UnsupportedOperationException("Method not decompiled: epson.print.C211111.<clinit>():void");
  1002. }
  1003. }
  1004. protected void onDestroy() {
  1005. EPLog.d("ActivityImageViewSelect", "onDestroy");
  1006. super.onDestroy();
  1007. }
  1008. @MainThread
  1009. private void localUnbindService() {
  1010. IEpsonService iEpsonService = mEpsonService;
  1011. if (iEpsonService != null) {
  1012. try {
  1013. iEpsonService.cancelSearchPrinter();
  1014. mEpsonService.unregisterCallback(mCallback);
  1015. unbindService(mEpsonConnection);
  1016. } catch (RemoteException unused) {
  1017. }
  1018. }
  1019. }
  1020. protected void onPause() {
  1021. EPLog.d("ActivityImageViewSelect", "onPause");
  1022. super.onPause();
  1023. NfcTagUtils.disableForegroundDispatch(this);
  1024. paperSourceInfo.stop();
  1025. if (isFinishing()) {
  1026. localUnbindService();
  1027. ApfPreviewView.deleteWorkingDirectory(this);
  1028. PhotoImageConvertViewModel.clearTempDirectory(this);
  1029. }
  1030. }
  1031. protected void onRestart() {
  1032. EPLog.d("ActivityImageViewSelect", "onRestart");
  1033. super.onRestart();
  1034. }
  1035. public void onBackPressed() {
  1036. if (mStartActivityFromPhoto == 0) {
  1037. Intent intent = new Intent();
  1038. intent.putStringArrayListExtra("imageList", imageList.getArgumentFileList());
  1039. setResult(18, intent);
  1040. } else if (isPrintedOK) {
  1041. setResult(-1);
  1042. } else {
  1043. setResult(0);
  1044. }
  1045. finish();
  1046. }
  1047. private void check3GAndStartPrint() {
  1048. mHandler.sendEmptyMessage(5);
  1049. }
  1050. private void showSimpleDialog(int i) {
  1051. SimpleMessageDialogFragment.newInstance(i).show(getSupportFragmentManager(), "simple-dialog");
  1052. }
  1053. private void unlockScreenRotation() {
  1054. setRequestedOrientation(-1);
  1055. }
  1056. private void startPrint() {
  1057. printButton.setEnabled(false);
  1058. OsAssistant.lockScreenRotation(this);
  1059. ExternalFileUtils.getInstance(this).initPrintDir();
  1060. if (isRemotePrinter) {
  1061. SharedPreferences.Editor edit = getSharedPreferences("PrintSetting", 0).edit();
  1062. edit.putInt(epson.common.Constants.SOURCE_TYPE, 2);
  1063. edit.commit();
  1064. }
  1065. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  1066. printSetting.loadSettings();
  1067. EPImageList imageList2 = previewImageView.getImageList();
  1068. imageList2.apfModeInPrinting = getApfValue(printSetting);
  1069. imageList2.setSharpness(getSharpnessValue(printSetting));
  1070. imageList2.setClearlyVivid(getClearlyVividValue(printSetting));
  1071. imageList2.setMultifileMode(true);
  1072. if (mPrintLog == null) {
  1073. mPrintLog = new PrintLog();
  1074. }
  1075. mPrintLog.previewType = 1;
  1076. startActivityForResult(PrintProgress.getPrintIntent(this, imageList2, false, isEpsonColorMode(), mPrintLog), 255);
  1077. }
  1078. private void addPhotos() {
  1079. PhotoImageSelectActivity.startAddImageSelect(this, imageList.getArgumentFileList());
  1080. }
  1081. public void onClick(View view) {
  1082. switch (view.getId()) {
  1083. case R.id.bt_rotate /*2131230858*/:
  1084. if (isPaperLandscape) {
  1085. isPaperLandscape = false;
  1086. } else {
  1087. isPaperLandscape = true;
  1088. }
  1089. if (currentLayout != 4) {
  1090. new PaperDirectionRotateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
  1091. return;
  1092. }
  1093. return;
  1094. case R.id.btn_add_photo /*2131230867*/:
  1095. if (imageList.size() == 30) {
  1096. new AlertDialog.Builder(this).setMessage(getString(R.string.max_image)).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  1097. public void onClick(DialogInterface dialogInterface, int i) {
  1098. }
  1099. }).create().show();
  1100. return;
  1101. }
  1102. addPhotos();
  1103. finish();
  1104. return;
  1105. case R.id.btn_deselect /*2131230869*/:
  1106. removeCurrentImage();
  1107. return;
  1108. case R.id.btn_paper_size /*2131230874*/:
  1109. if (aPaperSourceSetting != null) {
  1110. Intent intent = new Intent();
  1111. intent.setClass(this, PaperSourceSettingScr.class);
  1112. intent.putParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO, aPaperSourceSetting);
  1113. intent.putExtra(PaperSourceSettingScr.PRINT_SETTING_TYPE, PrintSetting.Kind.photo.name());
  1114. startActivityForResult(intent, CommonDefine.REQUEST_SETTING);
  1115. return;
  1116. }
  1117. callPrintSetting();
  1118. return;
  1119. case R.id.btn_print /*2131230877*/:
  1120. isRemotePrinter = MyPrinter.isRemotePrinter(this);
  1121. if (isRemotePrinter && enableShowWarning) {
  1122. AlertDialog.Builder cancelable = new AlertDialog.Builder(context).setCancelable(false);
  1123. cancelable.setMessage(getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
  1124. public void onClick(DialogInterface dialogInterface, int i) {
  1125. check3GAndStartPrint();
  1126. }
  1127. }).setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
  1128. public void onClick(DialogInterface dialogInterface, int i) {
  1129. }
  1130. }).show();
  1131. return;
  1132. } else if (currentPrinterName.equalsIgnoreCase(getString(R.string.str_lbl_title_scan))) {
  1133. new AlertDialog.Builder(context).setCancelable(false).setTitle(R.string.printer_not_select).setMessage(getString(R.string.printer_notselect_warning)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  1134. public void onClick(DialogInterface dialogInterface, int i) {
  1135. }
  1136. }).show();
  1137. return;
  1138. } else {
  1139. check3GAndStartPrint();
  1140. return;
  1141. }
  1142. default:
  1143. return;
  1144. }
  1145. }
  1146. protected void adjustImageNo() {
  1147. if (imageNo >= imageList.size()) {
  1148. imageNo = imageList.size() - 1;
  1149. }
  1150. if (imageNo < 0) {
  1151. imageNo = 0;
  1152. }
  1153. }
  1154. protected void removeCurrentImage() {
  1155. previewImageView.invalidateImageNo();
  1156. int i = imageNo;
  1157. if (i >= 0 && i < imageList.size()) {
  1158. imageList.remove(imageNo);
  1159. imageNo--;
  1160. }
  1161. updateGallery();
  1162. adjustImageNo();
  1163. new PreviewImageSelectTask().executeOnExecutor(new Void[0]);
  1164. }
  1165. protected void updateScreen() {
  1166. if (imageList.size() < 30) {
  1167. addButton.setEnabled(true);
  1168. addButton.setImageResource(R.drawable.plus);
  1169. }
  1170. if (imageList.size() > 0) {
  1171. TextView textView = pageTextView;
  1172. textView.setText((imageNo + 1) + CommonDefine.SLASH + imageList.size());
  1173. gallery.setSelection(imageNo);
  1174. } else {
  1175. deleteButton.setEnabled(false);
  1176. printButton.setEnabled(false);
  1177. pageTextView.setText("0/0");
  1178. }
  1179. if (previewImageView.getIsPaperLandscape()) {
  1180. isPaperLandscape = true;
  1181. } else {
  1182. isPaperLandscape = false;
  1183. }
  1184. Handler handler = mHandler;
  1185. if (handler != null) {
  1186. handler.sendEmptyMessage(2);
  1187. }
  1188. }
  1189. public boolean onOptionsItemSelected(MenuItem menuItem) {
  1190. if (menuItem.getItemId() == R.id.Menu_Show_PrintSettings) {
  1191. callPrintSetting();
  1192. }
  1193. return super.onOptionsItemSelected(menuItem);
  1194. }
  1195. public boolean onCreateOptionsMenu(Menu menu) {
  1196. super.onCreateOptionsMenu(menu);
  1197. getMenuInflater().inflate(R.menu.print_menu, menu);
  1198. return true;
  1199. }
  1200. public void callPrintSetting() {
  1201. System.gc();
  1202. SharedPreferences.Editor edit = getSharedPreferences("PrintSetting", 0).edit();
  1203. edit.putInt(epson.common.Constants.SOURCE_TYPE, 2);
  1204. edit.commit();
  1205. startActivityForResult(new Intent(this, SettingScr.class), CommonDefine.REQUEST_SETTING);
  1206. }
  1207. public boolean onKeyDown(int i, KeyEvent keyEvent) {
  1208. if (keyEvent.getAction() == 0 && i == 84) {
  1209. EPLog.e("key search", "diable");
  1210. return true;
  1211. } else if (keyEvent.getAction() != 0 || i != 4) {
  1212. return false;
  1213. } else {
  1214. onBackPressed();
  1215. return true;
  1216. }
  1217. }
  1218. public void onConfigurationChanged(Configuration configuration) {
  1219. super.onConfigurationChanged(configuration);
  1220. }
  1221. protected int getApfValue(PrintSetting printSetting) {
  1222. if (!isRemotePrinter) {
  1223. return printSetting.photoApfValueForLocalPrinter;
  1224. }
  1225. return 0;
  1226. }
  1227. protected int getSharpnessValue(PrintSetting printSetting) {
  1228. if (!isRemotePrinter) {
  1229. return printSetting.sharpnessForPhoto;
  1230. }
  1231. return 0;
  1232. }
  1233. protected int getClearlyVividValue(PrintSetting printSetting) {
  1234. if (!isRemotePrinter) {
  1235. int i = printSetting.paperTypeValue;
  1236. int code = Constants.MediaName.EPS_MTID_PLAIN.getCode();
  1237. EpLog.m77i("setteing = " + i + "plain = " + code);
  1238. return (i == code && printSetting.getKind() == PrintSetting.Kind.photo) ? 1 : 0;
  1239. }
  1240. }
  1241. public void onViewSizeChanged() {
  1242. EPLog.d(TAG, "onViewSizeChanged()");
  1243. if (isFinishing()) {
  1244. EPLog.d(TAG, "onViewSizeChanged() isFinishing == true");
  1245. return;
  1246. }
  1247. mOnSizeChangeReceived = true;
  1248. loadImage();
  1249. }
  1250. public void invitationDialogClicked(boolean z) {
  1251. mReviewInvitationViewModel.setStartStoreEnd();
  1252. }
  1253. protected boolean executeAllReloadTaskAgain() {
  1254. synchronized (mAllReloadTaskLock) {
  1255. if (!mIsAllReloadTaskRetryAcceptable) {
  1256. return false;
  1257. }
  1258. mAllReloadTaskRetryRequested = true;
  1259. return true;
  1260. }
  1261. }
  1262. protected boolean lastCheckAllReloadTaskRetryRequest() {
  1263. synchronized (mAllReloadTaskLock) {
  1264. if (mAllReloadTaskRetryRequested) {
  1265. return true;
  1266. }
  1267. mIsAllReloadTaskRetryAcceptable = false;
  1268. return false;
  1269. }
  1270. }
  1271. private void showDialog(String r4) {
  1272. throw new UnsupportedOperationException("Method not decompiled: epson.print.showDialog(java.lang.String):void");
  1273. }
  1274. private void dismissDialog(String str) {
  1275. DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(str);
  1276. if (dialogFragment != null) {
  1277. dialogFragment.dismiss();
  1278. }
  1279. }
  1280. private class AllReloadTask extends AsyncTaskExecutor<Void, Integer, Boolean> {
  1281. private Context context = null;
  1282. private volatile boolean endRedraw = false;
  1283. private boolean firstDraw = true;
  1284. Handler handler = new Handler(new Handler.Callback() {
  1285. public boolean handleMessage(Message message) {
  1286. if (message.what == 4) {
  1287. EPLog.i(TAG, "handleMessage(): msg.arg1 = " + message.arg1 + ", index = " + AllReloadTask.index);
  1288. if (AllReloadTask.firstDraw) {
  1289. boolean unused = AllReloadTask.firstDraw = false;
  1290. }
  1291. boolean unused2 = AllReloadTask.endRedraw = true;
  1292. }
  1293. return true;
  1294. }
  1295. });
  1296. private int index = 0;
  1297. private boolean mDeletePreview;
  1298. public AllReloadTask(Context context2) {
  1299. context = context2;
  1300. }
  1301. public AsyncTask<Void, Integer, Boolean> executeOnExecutor(Void... voidArr) {
  1302. if (executeAllReloadTaskAgain()) {
  1303. return null;
  1304. }
  1305. mIsAllReloadTaskRetryAcceptable = true;
  1306. return super.executeOnExecutor(voidArr);
  1307. }
  1308. protected void onPreExecute() {
  1309. mModelDialog.doShow(DIALOG_ALL_UPDATE);
  1310. imageList.clearExceptSrcFileName();
  1311. previewImageView.setDrawEndHandler(handler);
  1312. }
  1313. protected Boolean doInBackground(Void... voidArr) {
  1314. System.gc();
  1315. int i = 0;
  1316. do {
  1317. try {
  1318. if (mEpsonService != null) {
  1319. break;
  1320. }
  1321. Thread.sleep(100);
  1322. i++;
  1323. } catch (RemoteException e) {
  1324. e.printStackTrace();
  1325. } catch (InterruptedException e2) {
  1326. e2.printStackTrace();
  1327. }
  1328. } while (i < 100);
  1329. if (mEpsonService != null) {
  1330. if (isRemotePrinter) {
  1331. mEpsonService.EpsonConnectUpdatePrinterSettings(PrintSetting.Kind.photo.name());
  1332. } else {
  1333. mEpsonService.updatePrinterSettings(PrintSetting.Kind.photo.name());
  1334. }
  1335. }
  1336. PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.photo);
  1337. printSetting.loadSettings();
  1338. int unused = currentPaperSize = printSetting.paperSizeValue;
  1339. int unused2 = currentLayout = printSetting.layoutValue;
  1340. int unused3 = currentLayoutMulti = printSetting.layoutMultiPageValue;
  1341. int unused4 = currentColor = printSetting.colorValue;
  1342. previewImageView.setLayout(currentLayout, currentLayoutMulti);
  1343. previewImageView.setPaper(currentPaperSize);
  1344. previewImageView.setColor(currentColor);
  1345. previewImageView.setApfLibParams(getApfValue(printSetting), getSharpnessValue(printSetting), getClearlyVividValue(printSetting));
  1346. mHandler.sendEmptyMessage(6);
  1347. do {
  1348. boolean unused5 = mAllReloadTaskRetryRequested = false;
  1349. previewImageView.setPaper(currentPaperSize);
  1350. updatePreviewImage();
  1351. } while (lastCheckAllReloadTaskRetryRequest());
  1352. boolean unused6 = mAllReloadTaskDone = true;
  1353. return true;
  1354. }
  1355. private void updatePreviewImage() {
  1356. previewImageView.invalidateImageNo();
  1357. previewImageView.invalidatePreview();
  1358. index = 0;
  1359. while (index < imageList.size()) {
  1360. EPLog.i(TAG, "doInBack Start -> " + index);
  1361. while (!mAllReloadTaskRetryRequested) {
  1362. try {
  1363. if (previewImageView.setImage(index, 2, this)) {
  1364. endRedraw = false;
  1365. publishProgress(new Integer[]{Integer.valueOf(index + 1)});
  1366. int i = 0;
  1367. while (true) {
  1368. if (endRedraw) {
  1369. break;
  1370. }
  1371. Thread.sleep(100, 0);
  1372. i++;
  1373. if (i >= 50) {
  1374. break;
  1375. }
  1376. }
  1377. EPLog.i(TAG, "doInBack End -> " + index);
  1378. index++;
  1379. } else {
  1380. Thread.sleep(300);
  1381. }
  1382. } catch (InterruptedException e) {
  1383. e.printStackTrace();
  1384. } catch (OutOfMemoryError unused) {
  1385. imageList.remove(index);
  1386. index--;
  1387. mDeletePreview = true;
  1388. if (mAllReloadTaskDone) {
  1389. mHandler.sendEmptyMessage(8);
  1390. int unused2 = imageNo = 0;
  1391. } else {
  1392. mHandler.sendEmptyMessage(7);
  1393. }
  1394. }
  1395. }
  1396. return;
  1397. }
  1398. if (imageList.size() > 0) {
  1399. showCurrentImage();
  1400. return;
  1401. }
  1402. try {
  1403. previewImageView.setImage(0, 2, this);
  1404. } catch (OutOfMemoryError unused3) {
  1405. }
  1406. }
  1407. private void showCurrentImage() {
  1408. boolean z = false;
  1409. while (true) {
  1410. try {
  1411. previewImageView.setImage(imageNo, 0, this);
  1412. return;
  1413. } catch (OutOfMemoryError unused) {
  1414. if (!z) {
  1415. mHandler.sendEmptyMessage(8);
  1416. }
  1417. z = true;
  1418. if (imageList.size() > 0) {
  1419. if (imageNo >= 0 && imageNo < imageList.size()) {
  1420. imageList.remove(imageNo);
  1421. }
  1422. int unused2 = imageNo = 0;
  1423. } else {
  1424. return;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. private boolean testCheckStatus() {
  1430. try {
  1431. Thread.sleep(1000);
  1432. } catch (InterruptedException e) {
  1433. e.printStackTrace();
  1434. }
  1435. return mAllReloadTaskRetryRequested;
  1436. }
  1437. protected void onProgressUpdate(Integer... numArr) {
  1438. previewImageView.invalidate();
  1439. TextView access$1900 = pageTextView;
  1440. access$1900.setText(numArr[0] + CommonDefine.SLASH + imageList.size());
  1441. if (previewImageView.getIsPaperLandscape()) {
  1442. boolean unused = isPaperLandscape = true;
  1443. } else {
  1444. boolean unused2 = isPaperLandscape = false;
  1445. }
  1446. }
  1447. protected void onPostExecute(Boolean bool) {
  1448. if (!isFinishing()) {
  1449. if (mDeletePreview) {
  1450. updateGallery();
  1451. }
  1452. previewImageView.invalidate();
  1453. updateScreen();
  1454. previewImageView.setDrawEndHandler((Handler) null);
  1455. mModelDialog.doDismiss(DIALOG_ALL_UPDATE);
  1456. if (bAutoStartPrint) {
  1457. ActivityViewImageSelect activityViewImageSelect = ActivityViewImageSelect.this;
  1458. onClick(printButton);
  1459. EPLog.d(TAG, "onClick(printButton)");
  1460. bAutoStartPrint = false;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. private class PreviewImageSelectTask extends AsyncTaskExecutor<Void, Void, Void> {
  1466. private boolean mError;
  1467. private PreviewImageSelectTask() {
  1468. }
  1469. protected Void doInBackground(Void... voidArr) {
  1470. boolean z = false;
  1471. while (true) {
  1472. try {
  1473. previewImageView.setImage(imageNo, 0, ActivityViewImageSelect.this);
  1474. return null;
  1475. } catch (OutOfMemoryError unused) {
  1476. mError = true;
  1477. if (!z) {
  1478. mHandler.sendEmptyMessage(8);
  1479. }
  1480. if (imageList.size() <= 0) {
  1481. return null;
  1482. }
  1483. if (imageNo >= 0 && imageNo < imageList.size()) {
  1484. imageList.remove(imageNo);
  1485. }
  1486. int unused2 = imageNo = 0;
  1487. z = true;
  1488. }
  1489. }
  1490. }
  1491. protected void onPreExecute() {
  1492. mModelDialog.doShow(DIALOG_PROGRESS);
  1493. }
  1494. protected void onPostExecute(Void voidR) {
  1495. if (!isFinishing()) {
  1496. if (mError) {
  1497. updateGallery();
  1498. }
  1499. previewImageView.invalidate();
  1500. updateScreen();
  1501. mModelDialog.doDismiss(DIALOG_PROGRESS);
  1502. }
  1503. }
  1504. }
  1505. private class PaperDirectionRotateTask extends AsyncTask<Void, Void, Void> {
  1506. private PaperDirectionRotateTask() {
  1507. }
  1508. protected void onPreExecute() {
  1509. mModelDialog.doShow(DIALOG_PROGRESS);
  1510. }
  1511. protected void onPostExecute(Void voidR) {
  1512. if (!isFinishing()) {
  1513. mModelDialog.doDismiss(DIALOG_PROGRESS);
  1514. }
  1515. }
  1516. protected Void doInBackground(Void... voidArr) {
  1517. previewImageView.setIsPaperLandscape(isPaperLandscape, ActivityViewImageSelect.this);
  1518. return null;
  1519. }
  1520. }
  1521. }