ScanSettingsActivity.java 31 KB

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