ScanSettingsActivity.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package epson.scan.activity;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.AsyncTask;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.ImageView;
  11. import android.widget.LinearLayout;
  12. import android.widget.TextView;
  13. import com.epson.iprint.shared.SharedParamScan;
  14. import com.epson.mobilephone.common.PrintingLib.define.Constants;
  15. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  16. import epson.common.Constants;
  17. import epson.common.Utils;
  18. import epson.print.ActivityIACommon;
  19. import epson.print.R;
  20. import epson.print.EPPrinterManager;
  21. import epson.print.Util.EPLog;
  22. import epson.scan.lib.ScanCommonParams;
  23. import epson.scan.lib.ScanInfoStorage;
  24. import epson.scan.lib.ScanSettingHelper;
  25. import epson.scan.lib.ScanSizeHelper;
  26. import epson.scan.lib.ScannerInfo;
  27. public class ScanSettingsActivity extends ActivityIACommon {
  28. public static final String HIDE_COLOR_MODE = "hide-color-mode";
  29. public static final String HIDE_RESOLUTION = "hide-resolution";
  30. public static final String IS_NEW_SAVE = "IS_NEW_SAVE";
  31. public static final String NO_CLEAR_RESULT = "NO_CLEAR_RESULT";
  32. public static final String PARAM_KEY_EXTERNAL_DATA = "external-scan-params";
  33. private static final int REQUEST_CODE_BRIGHTNESS = 8;
  34. private static final int REQUEST_CODE_CHANGE_ESC_I_VERSION = 100;
  35. private static final int REQUEST_CODE_SELECT_SCANNER = 1;
  36. private static final String SCAN_SETTINGS_LAST_DENSITY = "SCAN_SETTINGS_LAST_DENSITY";
  37. private static final String SCAN_SETTINGS_LAST_DENSITY_STATUS = "SCAN_SETTINGS_LAST_DENSITY_STATUS";
  38. private static final String SCAN_SETTINGS_LAST_VALUE = "SCAN_SETTINGS_LAST_VALUE";
  39. private static final String SCAN_SUPPORTED_RESOLUTION_LIST = "SCAN_SUPPORTED_RESOLUTION_LIST";
  40. private static final String SCAN_SUPPORTED_SIZE_LIST = "SCAN_SUPPORTED_SIZE_LIST";
  41. private String autoConnectSsid = null;
  42. private Context context;
  43. private AlertDialog errorDialog;
  44. private boolean isNeedSaveSupportedOptions = false;
  45. private LinearLayout llScanName;
  46. private LinearLayout llScanSettingsAdvance2Sided;
  47. private LinearLayout llScanSettingsColor;
  48. private LinearLayout llScanSettingsDensity;
  49. private LinearLayout llScanSettingsGamma;
  50. private LinearLayout llScanSettingsResolution;
  51. private LinearLayout llScanSettingsSize;
  52. private LinearLayout llScanSettingsSource;
  53. private View mBrightnessSeparator;
  54. private SharedParamScan mExternalIntentData;
  55. private boolean mHideColorMode;
  56. private boolean mHideResolution;
  57. private View.OnClickListener mLLScanNameClick = new View.OnClickListener() {
  58. public void onClick(View view) {
  59. ScanSettingsActivity.this.llScanName.setClickable(false);
  60. new AsyncTask<Void, Void, Void>() {
  61. protected void onPreExecute() {
  62. }
  63. protected Void doInBackground(Void... voidArr) {
  64. WiFiDirectManager.disconnect(ScanSettingsActivity.this.getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_SCANNER, ScanSettingsActivity.this.scanInfo.getIp());
  65. WiFiDirectManager.disconnectSimpleAP(ScanSettingsActivity.this.getApplicationContext(), ScanSettingsActivity.this.autoConnectSsid, ScanSettingsActivity.this.scanInfo.getIp());
  66. return null;
  67. }
  68. protected void onPostExecute(Void voidR) {
  69. ScanSettingsActivity.this.startActivityForResult(ScanSearchActivity.getStartIntent(ScanSettingsActivity.this.getApplicationContext(), ScanSettingsActivity.this.scanInfo.getScannerId(), ScanSettingsActivity.this.scanInfo.getLocation(), ScanSettingsActivity.this.autoConnectSsid), 1);
  70. ScanSettingsActivity.this.llScanName.setClickable(true);
  71. }
  72. }.execute(new Void[0]);
  73. }
  74. };
  75. private View.OnClickListener mLLScanSettings2Sided = new View.OnClickListener() {
  76. public void onClick(View view) {
  77. ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
  78. scanSettingsActivity.goToSettingAdvanceDetailsScreen(Constants.SCAN_SETTINGS_DETAIL_TITLE, R.string.str_settings_2sided_title, scanSettingsActivity.scanInfo.getTwoSidedScanningValue(), 7);
  79. }
  80. };
  81. private View.OnClickListener mLLScanSettingsColor = new View.OnClickListener() {
  82. public void onClick(View view) {
  83. if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
  84. return;
  85. }
  86. if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
  87. ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
  88. scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, R.string.str_settings_color_title, scanSettingsActivity.scanInfo.getColorValue(), 5);
  89. }
  90. }
  91. };
  92. private View.OnClickListener mLLScanSettingsDensity = new View.OnClickListener() {
  93. public void onClick(View view) {
  94. ScanSettingsActivity.this.goToSettingAdvanceDensityScreen();
  95. }
  96. };
  97. private View.OnClickListener mLLScanSettingsGamma = new View.OnClickListener() {
  98. public void onClick(View view) {
  99. ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
  100. scanSettingsActivity.goToSettingAdvanceDetailsScreen(Constants.SCAN_SETTINGS_DETAIL_TITLE, R.string.str_settings_gamma_title, scanSettingsActivity.scanInfo.getGammaValue(), 9);
  101. }
  102. };
  103. private View.OnClickListener mLLScanSettingsResolution = new View.OnClickListener() {
  104. public void onClick(View view) {
  105. if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
  106. return;
  107. }
  108. if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
  109. ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
  110. scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, R.string.str_settings_resolution_title, scanSettingsActivity.scanInfo.getResolutionValue(), 6);
  111. }
  112. }
  113. };
  114. private View.OnClickListener mLLScanSettingsSize = new View.OnClickListener() {
  115. public void onClick(View view) {
  116. ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
  117. scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, R.string.str_scanning_size, scanSettingsActivity.scanInfo.getSizeValue(), 11);
  118. }
  119. };
  120. private View.OnClickListener mLLScanSettingsSource = new View.OnClickListener() {
  121. public void onClick(View view) {
  122. if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
  123. return;
  124. }
  125. if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
  126. ScanSettingsActivity.this.startInputUnitSettingActivity();
  127. }
  128. }
  129. };
  130. private ScanInfoStorage mScanInfoStorage;
  131. private View progressGetOption;
  132. private ScannerInfo scanInfo;
  133. private ScannerInfo siOrigin;
  134. private TextView tvScanner2Sided;
  135. private TextView tvScannerColor;
  136. private TextView tvScannerDensity;
  137. private TextView tvScannerGamma;
  138. private TextView tvScannerName;
  139. private TextView tvScannerResolution;
  140. private TextView tvScannerSize;
  141. private TextView tvScannerSource;
  142. private View viewScanSettingsAdvance2Sided;
  143. private View viewScanSettingsSource;
  144. protected void onCreate(Bundle bundle) {
  145. super.onCreate(bundle);
  146. mScanInfoStorage = ScanInfoStorage.getInstance();
  147. setContentView((int) R.layout.scan_settings_main);
  148. setActionBar((int) R.string.str_lbl_title_scan_settings, true);
  149. context = this;
  150. llScanName = (LinearLayout) findViewById(R.id.llScannerName);
  151. llScanName.setOnClickListener(mLLScanNameClick);
  152. llScanSettingsSource = (LinearLayout) findViewById(R.id.llScanSettingsSource);
  153. llScanSettingsSource.setOnClickListener(mLLScanSettingsSource);
  154. llScanSettingsSize = (LinearLayout) findViewById(R.id.llScanSettingsSize);
  155. llScanSettingsSize.setOnClickListener(mLLScanSettingsSize);
  156. viewScanSettingsSource = findViewById(R.id.viewScanSettingsSource);
  157. llScanSettingsColor = (LinearLayout) findViewById(R.id.llScanSettingsColor);
  158. llScanSettingsColor.setOnClickListener(mLLScanSettingsColor);
  159. llScanSettingsResolution = (LinearLayout) findViewById(R.id.llScanSettingsResolution);
  160. llScanSettingsResolution.setOnClickListener(mLLScanSettingsResolution);
  161. tvScannerName = (TextView) findViewById(R.id.tvScannerName);
  162. tvScannerSource = (TextView) findViewById(R.id.tvScannerSource);
  163. tvScannerSize = (TextView) findViewById(R.id.tvScannerSize);
  164. tvScannerColor = (TextView) findViewById(R.id.tvScannerColor);
  165. tvScannerResolution = (TextView) findViewById(R.id.tvScannerResolution);
  166. progressGetOption = findViewById(R.id.progressGetOption);
  167. llScanSettingsAdvance2Sided = (LinearLayout) findViewById(R.id.llScanSettingsAdvance2Sided);
  168. llScanSettingsAdvance2Sided.setOnClickListener(mLLScanSettings2Sided);
  169. viewScanSettingsAdvance2Sided = findViewById(R.id.viewScanSettingsAdvance2Sided);
  170. llScanSettingsDensity = (LinearLayout) findViewById(R.id.llScanSettingsDensity);
  171. llScanSettingsDensity.setOnClickListener(mLLScanSettingsDensity);
  172. mBrightnessSeparator = findViewById(R.id.brightnessSeparator);
  173. llScanSettingsGamma = (LinearLayout) findViewById(R.id.llScanSettingsGamma);
  174. llScanSettingsGamma.setOnClickListener(mLLScanSettingsGamma);
  175. tvScanner2Sided = (TextView) findViewById(R.id.tvScanner2Sided);
  176. tvScannerDensity = (TextView) findViewById(R.id.tvScannerDensity);
  177. tvScannerGamma = (TextView) findViewById(R.id.tvScannerGamma);
  178. Intent intent = getIntent();
  179. mHideResolution = intent.getBooleanExtra(HIDE_RESOLUTION, false);
  180. if (mHideResolution) {
  181. llScanSettingsResolution.setVisibility(8);
  182. }
  183. mHideColorMode = intent.getBooleanExtra(HIDE_COLOR_MODE, false);
  184. if (mHideColorMode) {
  185. llScanSettingsColor.setVisibility(8);
  186. }
  187. mExternalIntentData = (SharedParamScan) intent.getSerializableExtra(PARAM_KEY_EXTERNAL_DATA);
  188. scanInfo = new ScannerInfo();
  189. getScannerSavedSettings();
  190. if (this.scanInfo.getIp().equals("")) {
  191. setBlankSettings();
  192. showNewSelectedScannerInfo();
  193. } else {
  194. setResolutionClickable();
  195. setColorModeClickable();
  196. }
  197. siOrigin = new ScannerInfo(this.scanInfo);
  198. updateScannerInfoIfEscIVersionChanged(getIntent());
  199. }
  200. private void updateScannerInfoIfEscIVersionChanged(Intent intent) {
  201. ScannerPropertyWrapper scannerPropertyWrapper = SettingActivityParams.getScannerPropertyWrapper(intent);
  202. if (scannerPropertyWrapper != null) {
  203. if (!scannerPropertyWrapper.isPrinterSet()) {
  204. resetSettings();
  205. return;
  206. }
  207. ScannerInfo i1ScannerInfo = scannerPropertyWrapper.getI1ScannerInfo();
  208. if (i1ScannerInfo != null) {
  209. isNeedSaveSupportedOptions = true;
  210. updateSelectedScannerInfo(i1ScannerInfo, scannerPropertyWrapper.getSimpleApSsid());
  211. }
  212. }
  213. }
  214. private void updatePrinterIcon() {
  215. if (this.scanInfo.isModelNameEmpty()) {
  216. ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setVisibility(8);
  217. return;
  218. }
  219. ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setVisibility(0);
  220. switch (this.scanInfo.getLocation()) {
  221. case 1:
  222. ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.C2136drawable.print_local);
  223. return;
  224. case 2:
  225. ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.C2136drawable.print_remote);
  226. return;
  227. case 3:
  228. ((ImageView) findViewById(R.id.imageViewPrinterLocation)).setImageResource(R.C2136drawable.print_ip);
  229. return;
  230. default:
  231. return;
  232. }
  233. }
  234. private void getScannerSavedSettings() {
  235. EPLog.m313i("epson.scan.activity.ScanSettingsActivity", "Start get saved option");
  236. loadRefScannerName();
  237. loadRefScannerSourceSetting();
  238. loadRefScannerColorSetting();
  239. loadRefScannerResolutionSetting();
  240. loadRefScannerBasicOptions();
  241. scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
  242. mScanInfoStorage.loadScanSetting(this, scanInfo);
  243. int[] iArr = new int[64];
  244. for (int i = 0; i < 64; i++) {
  245. Context context2 = context;
  246. iArr[i] = Utils.getPrefInt(context2, epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_OPTIONS_RESOLUTION_ + i);
  247. }
  248. scanInfo.setSupportedResolutionList(iArr);
  249. autoConnectSsid = WiFiDirectManager.getConnectInfo(this, WiFiDirectManager.DEVICE_TYPE_SCANNER);
  250. updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), scanInfo.getSupportedAdfDuplex());
  251. tvScannerDensity.setText(String.valueOf(255 - scanInfo.getDensityValue()));
  252. tvScannerGamma.setText(this.scanInfo.getGammaName());
  253. }
  254. @Deprecated
  255. private void loadRefScannerName() {
  256. mScanInfoStorage.loadScannerConnectivityInfo(this, scanInfo);
  257. displayScannerName();
  258. updatePrinterIcon();
  259. }
  260. private void displayScannerName() {
  261. String ipPrinterUserName;
  262. if (this.scanInfo.getLocation() != 3 || (ipPrinterUserName = new EPPrinterManager(this).getIpPrinterUserName(this.scanInfo.getScannerId())) == null) {
  263. String modelName = scanInfo.getModelName();
  264. if (modelName == null || modelName.isEmpty()) {
  265. tvScannerName.setText(R.string.str_lbl_title_scan);
  266. } else {
  267. tvScannerName.setText(modelName);
  268. }
  269. } else {
  270. tvScannerName.setText(ipPrinterUserName);
  271. }
  272. }
  273. @Deprecated
  274. private void loadRefScannerSourceSetting() {
  275. mScanInfoStorage.loadSupportedAdfSize(this, scanInfo);
  276. mScanInfoStorage.loadReadUnitValue(this, scanInfo);
  277. tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
  278. if (this.scanInfo.getSupportedAdfHeight() == 0 && scanInfo.getSupportedAdfWidth() == 0) {
  279. llScanSettingsSource.setVisibility(8);
  280. viewScanSettingsSource.setVisibility(8);
  281. return;
  282. }
  283. llScanSettingsSource.setVisibility(0);
  284. viewScanSettingsSource.setVisibility(0);
  285. }
  286. @Deprecated
  287. private void loadRefScannerColorSetting() {
  288. mScanInfoStorage.loadColorValue(this, scanInfo);
  289. tvScannerColor.setText(getString(this.scanInfo.getColorName()));
  290. }
  291. @Deprecated
  292. private void loadRefScannerResolutionSetting() {
  293. mScanInfoStorage.loadResolution(this, scanInfo);
  294. tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
  295. }
  296. private void loadRefScannerBasicOptions() {
  297. mScanInfoStorage.loadSupportedValue(this, scanInfo);
  298. }
  299. private void startInputUnitSettingActivity() {
  300. if (this.scanInfo.getSupportedAdfWidth() > 0 && scanInfo.getSupportedAdfHeight() > 0) {
  301. startActivityForResult(InputUnitSettingActivity.getStartIntent(this, scanInfo.getSourceValue(), scanInfo.getAdfPaperGuide()), 4);
  302. }
  303. }
  304. private void startDetailSettingScreenForResult(String str, int i, int i2, int i3) {
  305. Intent intent = new Intent(this, ScanSettingsDetailActivity.class);
  306. intent.putExtra(str, i);
  307. intent.putExtra(SCAN_SETTINGS_LAST_VALUE, i2);
  308. intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_ADF_WIDTH, scanInfo.getSupportedAdfWidth());
  309. intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT, scanInfo.getSupportedAdfHeight());
  310. intent.putExtra(SCAN_SUPPORTED_RESOLUTION_LIST, scanInfo.getSupportedResolutionList());
  311. intent.putExtra(epson.common.Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE, scanInfo.getAdfPaperGuide());
  312. int[] iArr = new int[0];
  313. switch (this.scanInfo.getSourceValue()) {
  314. case 0:
  315. iArr = ScanSizeHelper.getSupportedScanSizeList(this.scanInfo.getSourceValue(), 0, scanInfo.getSupportedBasicWidth(), scanInfo.getSupportedBasicHeight(), scanInfo.getSupportedBasicResolution());
  316. break;
  317. case 1:
  318. iArr = ScanSizeHelper.getSupportedScanSizeList(this.scanInfo.getSourceValue(), scanInfo.getTwoSidedScanningValue(), scanInfo.getSupportedAdfWidth(), scanInfo.getSupportedAdfHeight(), scanInfo.getSupportedBasicResolution());
  319. break;
  320. }
  321. intent.putExtra(SCAN_SUPPORTED_SIZE_LIST, iArr);
  322. intent.setAction("android.intent.action.VIEW");
  323. startActivityForResult(intent, i3);
  324. }
  325. private void goToSettingAdvanceDensityScreen() {
  326. startActivityForResult(ScanSettingsAdvanceDensityActivity.getStartIntent(this, scanInfo.getDensityValue(), scanInfo.isDensityStatus()), 8);
  327. }
  328. private void goToSettingAdvanceDetailsScreen(String str, int i, int i2, int i3) {
  329. Intent intent = new Intent(this, ScanSettingsAdvanceDetailActivity.class);
  330. intent.putExtra(str, i);
  331. intent.putExtra(SCAN_SETTINGS_LAST_VALUE, i2);
  332. intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_SUPPORTED_ADF_DUPLEX, scanInfo.getSupportedAdfDuplex());
  333. int i4 = 1;
  334. if (!this.scanInfo.isAdfDuplexRotaitonYes()) {
  335. i4 = 0;
  336. }
  337. intent.putExtra(epson.common.Constants.SCAN_REFS_SETTINGS_ROTATE, i4);
  338. intent.setAction("android.intent.action.VIEW");
  339. startActivityForResult(intent, i3);
  340. }
  341. protected void onActivityResult(int i, int i2, Intent intent) {
  342. super.onActivityResult(i, i2, intent);
  343. if (i == 1) {
  344. onScannerSelectResult(i2, intent);
  345. } else if (i != 100) {
  346. if (i2 == -1) {
  347. Bundle extras = intent.getExtras();
  348. boolean z = false;
  349. switch (i) {
  350. case 4:
  351. scanInfo.setSourceValue(InputUnitSettingActivity.getInputUnit(intent));
  352. int adfAlignment = InputUnitSettingActivity.getAdfAlignment(intent);
  353. if (adfAlignment >= 0) {
  354. scanInfo.setAdfPaperGuide(adfAlignment);
  355. }
  356. tvScannerSource.setText(this.scanInfo.getSourceName());
  357. if (this.scanInfo.getSourceValue() == 0) {
  358. scanInfo.setTwoSidedScanningValue(0);
  359. }
  360. updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), scanInfo.getSupportedAdfDuplex());
  361. scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
  362. tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
  363. break;
  364. case 5:
  365. scanInfo.setColorValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_COLOR));
  366. tvScannerColor.setText(getString(this.scanInfo.getColorName()));
  367. break;
  368. case 6:
  369. scanInfo.setResolutionValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_RESOLUTION));
  370. tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
  371. break;
  372. case 7:
  373. scanInfo.setTwoSidedScanningValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_2SIDED));
  374. String string = extras.getString(epson.common.Constants.SCAN_REFS_SETTINGS_2SIDED_NAME);
  375. int i3 = R.string.str_yes;
  376. if (!string.equals(getString(R.string.str_yes))) {
  377. i3 = R.string.str_no;
  378. }
  379. tvScanner2Sided.setText(i3);
  380. ScannerInfo scannerInfo = scanInfo;
  381. if (extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_ROTATE) == 1) {
  382. z = true;
  383. }
  384. scannerInfo.setAdfDuplexRotaitonYes(z);
  385. if (this.scanInfo.getTwoSidedScanningValue() == 1) {
  386. scanInfo.setSourceValue(1);
  387. tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
  388. }
  389. scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
  390. tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
  391. break;
  392. case 8:
  393. scanInfo.setDensityValue(ScanSettingsAdvanceDensityActivity.getDensityFromReturnIntent(intent));
  394. scanInfo.setDensityStatus(ScanSettingsAdvanceDensityActivity.getChangeAble(intent));
  395. tvScannerDensity.setText(String.valueOf(255 - scanInfo.getDensityValue()));
  396. break;
  397. case 9:
  398. scanInfo.setGammaValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_GAMMA));
  399. String string2 = extras.getString(epson.common.Constants.SCAN_REFS_SETTINGS_GAMMA_NAME);
  400. int i4 = R.string.str_settings_gamma_10;
  401. if (!string2.equals(getString(R.string.str_settings_gamma_10))) {
  402. i4 = R.string.str_settings_gamma_18;
  403. }
  404. tvScannerGamma.setText(i4);
  405. break;
  406. case 11:
  407. scanInfo.setSizeValue(extras.getInt(epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE));
  408. tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
  409. break;
  410. }
  411. }
  412. EPLog.m313i(getLocalClassName(), "back to settings");
  413. } else if (i2 == 1) {
  414. onScannerSelectResult(-1, intent);
  415. } else {
  416. setResult(i2, intent);
  417. finish();
  418. }
  419. }
  420. private void onScannerSelectResult(int i, Intent intent) {
  421. if (i == -1) {
  422. ScannerPropertyWrapper scannerPropertyWrapper = SettingActivityParams.getScannerPropertyWrapper(intent);
  423. if (scannerPropertyWrapper != null) {
  424. if (scannerPropertyWrapper.getEscIVersion() != 2) {
  425. ScannerInfo i1ScannerInfo = scannerPropertyWrapper.getI1ScannerInfo();
  426. if (i1ScannerInfo != null) {
  427. updateSelectedScannerInfo(i1ScannerInfo, scannerPropertyWrapper.getSimpleApSsid());
  428. }
  429. } else if (SettingActivityParams.returnIfEscIVersionChanged(getIntent())) {
  430. setResult(1, SettingActivityParams.getSettingReturnIntent(scannerPropertyWrapper));
  431. finish();
  432. } else {
  433. startActivityForResult(SettingActivityParams.getChangeSettingActivityStartIntent(this, scannerPropertyWrapper, true, mHideColorMode, mHideResolution, mExternalIntentData), 100);
  434. }
  435. }
  436. } else {
  437. updateIpAddressPrinter();
  438. }
  439. }
  440. private void updateIpAddressPrinter() {
  441. if (this.scanInfo.getLocation() == 3 && !new EPPrinterManager(this).doseContainScannerIdInIpPrinterList(this.scanInfo.getScannerId())) {
  442. resetSettings();
  443. }
  444. }
  445. private void updateSelectedScannerInfo(ScannerInfo scannerInfo, String str) {
  446. isNeedSaveSupportedOptions = true;
  447. scanInfo.setScannerId(scannerInfo.getScannerId());
  448. scanInfo.setIp(scannerInfo.getIp());
  449. scanInfo.setLocation(scannerInfo.getLocation());
  450. scanInfo.setModelName(scannerInfo.getModelName());
  451. autoConnectSsid = str;
  452. displayScannerName();
  453. updatePrinterIcon();
  454. scanInfo.setSupportedOptions(new int[7]);
  455. scanInfo.setSupportedResolutionList(new int[64]);
  456. ScanSettingHelper.updateNewSelectedScannerSupportedOptions(this.scanInfo);
  457. setBlankSettings();
  458. scanInfo.setSupportedOptions(scannerInfo.getSupportedOptions());
  459. scanInfo.setSupportedResolutionList(scannerInfo.getSupportedResolutionList());
  460. ScanSettingHelper.updateNewSelectedScannerSupportedOptions(this.scanInfo);
  461. ScanSettingHelper.setDefaultSettings3(ScanCommonParams.load(this), scanInfo);
  462. showNewSelectedScannerInfo();
  463. if (!this.scanInfo.getIp().equals("")) {
  464. setResolutionClickable();
  465. setColorModeClickable();
  466. llScanSettingsDensity.setClickable(true);
  467. llScanSettingsGamma.setClickable(true);
  468. }
  469. }
  470. private void setBlankSettings() {
  471. scanInfo.setSourceValue(0);
  472. scanInfo.setSupportedAdfHeight(0);
  473. scanInfo.setSupportedAdfWidth(0);
  474. scanInfo.setSupportedAdfDuplex(0);
  475. scanInfo.setTwoSidedScanningValue(0);
  476. scanInfo.setResolutionValue(150);
  477. scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
  478. scanInfo.setColorValue(1);
  479. scanInfo.setDensityStatus(false);
  480. scanInfo.setDensityValue(128);
  481. scanInfo.setGammaValue(1);
  482. llScanSettingsResolution.setClickable(false);
  483. llScanSettingsColor.setClickable(false);
  484. llScanSettingsDensity.setClickable(false);
  485. llScanSettingsGamma.setClickable(false);
  486. }
  487. private void showNewSelectedScannerInfo() {
  488. displayNewDocumentSourceSetting();
  489. tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
  490. tvScannerColor.setText(getString(this.scanInfo.getColorName()));
  491. tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
  492. tvScannerDensity.setText(String.valueOf(255 - scanInfo.getDensityValue()));
  493. tvScannerGamma.setText(this.scanInfo.getGammaName());
  494. }
  495. private void displayNewDocumentSourceSetting() {
  496. if (this.scanInfo.getSupportedAdfHeight() == 0 && scanInfo.getSupportedAdfWidth() == 0) {
  497. llScanSettingsSource.setVisibility(8);
  498. viewScanSettingsSource.setVisibility(8);
  499. } else {
  500. llScanSettingsSource.setVisibility(0);
  501. viewScanSettingsSource.setVisibility(0);
  502. tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
  503. }
  504. updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), scanInfo.getSupportedAdfDuplex());
  505. }
  506. private void updateScanner2SidedSetting(int i, int i2) {
  507. tvScanner2Sided.setText(i);
  508. if (i2 != 1) {
  509. llScanSettingsAdvance2Sided.setVisibility(8);
  510. viewScanSettingsAdvance2Sided.setVisibility(8);
  511. return;
  512. }
  513. llScanSettingsAdvance2Sided.setVisibility(0);
  514. viewScanSettingsAdvance2Sided.setVisibility(0);
  515. }
  516. private void setResolutionClickable() {
  517. if (!mHideResolution) {
  518. llScanSettingsResolution.setClickable(true);
  519. }
  520. }
  521. private void setColorModeClickable() {
  522. if (!mHideColorMode) {
  523. llScanSettingsColor.setClickable(true);
  524. }
  525. }
  526. public void onBackPressed() {
  527. new EPPrinterManager(this).rollbackIPPrinterInfo();
  528. setResult(0);
  529. finish();
  530. }
  531. private void onSettingDone() {
  532. if (this.progressGetOption.getVisibility() == 8) {
  533. if (!this.scanInfo.isReSearch() && !this.scanInfo.getIp().equals("")) {
  534. scanInfo.setReSearch(true);
  535. }
  536. if (this.isNeedSaveSupportedOptions) {
  537. ScanSettingHelper.saveSupportedOptionToRef(this.context, scanInfo);
  538. String str = autoConnectSsid;
  539. if (str == null || str.length() <= 0) {
  540. WiFiDirectManager.resetConnectInfo(this, WiFiDirectManager.DEVICE_TYPE_SCANNER);
  541. } else {
  542. WiFiDirectManager.setConnectInfo(this, autoConnectSsid, WiFiDirectManager.DEVICE_TYPE_SCANNER, scanInfo.getModelName());
  543. }
  544. }
  545. boolean z = false;
  546. isNeedSaveSupportedOptions = false;
  547. if (this.scanInfo.getModelName().equals(this.siOrigin.getModelName()) && scanInfo.getSourceValue() == siOrigin.getSourceValue() && scanInfo.getColorValue() == siOrigin.getColorValue() && scanInfo.getResolutionValue() == siOrigin.getResolutionValue() && scanInfo.getTwoSidedScanningValue() == siOrigin.getTwoSidedScanningValue() && scanInfo.isAdfDuplexRotaitonYes() == siOrigin.isAdfDuplexRotaitonYes() && scanInfo.getAdfPaperGuide() == siOrigin.getAdfPaperGuide() && scanInfo.getDensityValue() == siOrigin.getDensityValue() && scanInfo.getGammaValue() == siOrigin.getGammaValue()) {
  548. z = true;
  549. }
  550. ScanInfoStorage.saveEscIVersion(this, 1);
  551. ScanSettingHelper.saveAllUserSettingsToRef(this.context, scanInfo);
  552. backToScanScreen(z);
  553. }
  554. }
  555. private void backToScanScreen(boolean z) {
  556. new EPPrinterManager(this).commitIPPrinterInfo();
  557. Intent intent = getIntent();
  558. intent.putExtra(epson.common.Constants.ACT_RESULT, epson.common.Constants.ACT_RESULT_SAVE);
  559. intent.putExtra(IS_NEW_SAVE, true);
  560. intent.putExtra(NO_CLEAR_RESULT, z);
  561. setResult(-1, intent);
  562. finish();
  563. }
  564. protected void onStop() {
  565. super.onStop();
  566. EPLog.m313i(getLocalClassName(), "scannsetting screen, onStop");
  567. progressGetOption.setVisibility(8);
  568. AlertDialog alertDialog = errorDialog;
  569. if (alertDialog != null && alertDialog.isShowing()) {
  570. errorDialog.dismiss();
  571. }
  572. }
  573. private void resetSettings() {
  574. scanInfo.setScannerId("");
  575. scanInfo.setIp("");
  576. scanInfo.setModelName("");
  577. scanInfo.setLocation(1);
  578. autoConnectSsid = "";
  579. setBlankSettings();
  580. showNewSelectedScannerInfo();
  581. displayScannerName();
  582. updatePrinterIcon();
  583. }
  584. public boolean onCreateOptionsMenu(Menu menu) {
  585. getMenuInflater().inflate(R.menu.menu_done, menu);
  586. return super.onCreateOptionsMenu(menu);
  587. }
  588. public boolean onOptionsItemSelected(MenuItem menuItem) {
  589. if (menuItem.getItemId() != R.id.menuSettingsDone) {
  590. return super.onOptionsItemSelected(menuItem);
  591. }
  592. onSettingDone();
  593. return true;
  594. }
  595. }