PaperSourceSettingScr.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. package epson.print.screen;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.ComponentName;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.content.ServiceConnection;
  9. import android.os.Bundle;
  10. import android.os.Handler;
  11. import android.os.IBinder;
  12. import android.os.Message;
  13. import android.os.RemoteException;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.AdapterView;
  17. import android.widget.AlphabetIndexer;
  18. import android.widget.ListView;
  19. import android.widget.TextView;
  20. import com.epson.mobilephone.common.escpr.MediaInfo;
  21. import epson.print.ActivityIACommon;
  22. import epson.print.R;
  23. import epson.print.Util.EPLog;
  24. import epson.print.screen.PrintSetting;
  25. import epson.print.service.EpsonService;
  26. import epson.print.service.IEpsonService;
  27. import epson.print.service.IEpsonServiceCallback;
  28. import epson.print.widgets.AbstractListBuilder;
  29. import java.util.ArrayList;
  30. import java.util.Vector;
  31. public class PaperSourceSettingScr extends ActivityIACommon {
  32. private static final int ID_BINDSERVICE = 1;
  33. private static final int ID_NOT_ESCPRSUPPORT = 10;
  34. public static final String PRINT_SETTING_TYPE = "print-setting-type";
  35. private static final int SETTING_DONE = 3;
  36. ArrayList<PaperSourceSetting> aPaperSourceSetting;
  37. AdapterView.OnItemClickListener listItemClickLister = new AdapterView.OnItemClickListener() {
  38. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  39. PaperSourceSetting paperSourceSetting = (PaperSourceSetting) PaperSourceSettingScr.this.mListBuilder.getData().elementAt(i);
  40. if (!paperSourceSetting.bSupportESCPR) {
  41. PaperSourceSettingScr.this.showDialog(10);
  42. return;
  43. }
  44. PaperSourceSettingScr paperSourceSettingScr = PaperSourceSettingScr.this;
  45. PrintSetting instance = PrintSetting.getInstance(paperSourceSettingScr, paperSourceSettingScr.mPrintSettingTypeName);
  46. instance.loadSettings();
  47. instance.paperSizeValue = paperSourceSetting.paperSizeId;
  48. instance.paperTypeValue = paperSourceSetting.paperTypeId;
  49. instance.paperSourceValue = paperSourceSetting.paperSource;
  50. instance.saveSettings();
  51. try {
  52. PaperSourceSettingScr.this.mEpsonService.updatePrinterSettings(PaperSourceSettingScr.this.mPrintSettingTypeName);
  53. } catch (RemoteException e) {
  54. e.printStackTrace();
  55. }
  56. PaperSourceSettingScr.this.setResult(3);
  57. PaperSourceSettingScr.this.finish();
  58. }
  59. };
  60. /* access modifiers changed from: private */
  61. public IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
  62. public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
  63. }
  64. public void onGetInkState() throws RemoteException {
  65. }
  66. public void onGetStatusState() throws RemoteException {
  67. }
  68. public void onNotifyContinueable(int i) throws RemoteException {
  69. }
  70. public void onNotifyEndJob(int i) throws RemoteException {
  71. }
  72. public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
  73. }
  74. public void onNotifyProgress(int i, int i2) throws RemoteException {
  75. }
  76. };
  77. private ServiceConnection mEpsonConnection = new ServiceConnection() {
  78. public void onServiceDisconnected(ComponentName componentName) {
  79. EPLog.v("SettingScr", "onServiceDisconnected");
  80. try {
  81. PaperSourceSettingScr.this.mEpsonService.unregisterCallback(PaperSourceSettingScr.this.mCallback);
  82. } catch (RemoteException e) {
  83. e.printStackTrace();
  84. }
  85. IEpsonService unused = PaperSourceSettingScr.this.mEpsonService = null;
  86. }
  87. public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  88. IEpsonService unused = PaperSourceSettingScr.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
  89. EPLog.v("SettingScr", "onServiceConnected");
  90. if (PaperSourceSettingScr.this.mEpsonService != null) {
  91. try {
  92. PaperSourceSettingScr.this.mEpsonService.registerCallback(PaperSourceSettingScr.this.mCallback);
  93. } catch (RemoteException e) {
  94. e.printStackTrace();
  95. }
  96. PaperSourceSettingScr.this.mHandler.sendEmptyMessage(1);
  97. }
  98. }
  99. };
  100. /* access modifiers changed from: private */
  101. public IEpsonService mEpsonService = null;
  102. Handler mHandler = new Handler(new Handler.Callback() {
  103. public boolean handleMessage(Message message) {
  104. int i = message.what;
  105. if (i == 1) {
  106. PaperSourceSettingScr paperSourceSettingScr = PaperSourceSettingScr.this;
  107. paperSourceSettingScr.aPaperSourceSetting = paperSourceSettingScr.getIntent().getParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO);
  108. PaperSourceSettingScr.this.addPaparSettings();
  109. PaperSourceSettingScr.this.progress.dismiss();
  110. return false;
  111. } else if (i != 100) {
  112. return false;
  113. } else {
  114. PaperSourceSettingScr.this.aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO);
  115. PaperSourceSettingScr.this.addPaparSettings();
  116. return false;
  117. }
  118. }
  119. });
  120. PaperSourceInfoBuilder mListBuilder = null;
  121. /* access modifiers changed from: private */
  122. public String mPrintSettingTypeName = PrintSetting.Kind.photo.name();
  123. PaperSourceInfo paperSourceInfo = null;
  124. WorkingDialog progress = null;
  125. /* access modifiers changed from: protected */
  126. public void onCreate(Bundle bundle) {
  127. super.onCreate(bundle);
  128. ViewGroup viewGroup = (ViewGroup) getLayoutInflater().inflate(R.layout.paper_source_setting, (ViewGroup) null);
  129. this.mListBuilder = new PaperSourceInfoBuilder(getBaseContext(), viewGroup);
  130. this.mListBuilder.build();
  131. ((TextView) viewGroup.findViewById(R.id.empty)).setText(R.string.ph_Detail);
  132. ((ListView) viewGroup.findViewById(16908298)).setOnItemClickListener(this.listItemClickLister);
  133. setContentView((View) viewGroup);
  134. setActionBar((int) R.string.ph_Title, true);
  135. this.mPrintSettingTypeName = getIntent().getStringExtra(PRINT_SETTING_TYPE);
  136. PrintSetting instance = PrintSetting.getInstance(this, this.mPrintSettingTypeName);
  137. instance.loadSettings();
  138. PaperSourceSetting paperSourceSetting = new PaperSourceSetting();
  139. paperSourceSetting.paperSizeId = instance.paperSizeValue;
  140. paperSourceSetting.paperTypeId = instance.paperTypeValue;
  141. paperSourceSetting.paperSource = instance.paperSourceValue;
  142. this.mListBuilder.setResource(paperSourceSetting);
  143. this.paperSourceInfo = PaperSourceInfo.getInstance(this);
  144. if (this.mEpsonService == null) {
  145. Intent intent = new Intent();
  146. intent.setClass(this, EpsonService.class);
  147. bindService(intent, this.mEpsonConnection, 1);
  148. }
  149. this.progress = new WorkingDialog(this);
  150. this.progress.show();
  151. }
  152. /* access modifiers changed from: protected */
  153. public void onDestroy() {
  154. super.onDestroy();
  155. IEpsonService iEpsonService = this.mEpsonService;
  156. if (iEpsonService != null) {
  157. try {
  158. iEpsonService.unregisterCallback(this.mCallback);
  159. unbindService(this.mEpsonConnection);
  160. this.mEpsonService = null;
  161. } catch (RemoteException e) {
  162. e.printStackTrace();
  163. }
  164. }
  165. }
  166. /* access modifiers changed from: protected */
  167. public void onResume() {
  168. super.onResume();
  169. this.paperSourceInfo.start(this, this.mHandler);
  170. }
  171. /* access modifiers changed from: protected */
  172. public void onPause() {
  173. super.onPause();
  174. this.paperSourceInfo.stop();
  175. }
  176. private void addPaparSettings() {
  177. int i;
  178. int i2;
  179. if (this.mEpsonService != null && this.aPaperSourceSetting != null) {
  180. this.mListBuilder.refresh();
  181. for (int i3 = 0; i3 < this.aPaperSourceSetting.size(); i3++) {
  182. PaperSourceSetting paperSourceSetting = this.aPaperSourceSetting.get(i3);
  183. try {
  184. paperSourceSetting.bSupportESCPR = false;
  185. int[] paperSize = this.mEpsonService.getPaperSize();
  186. if (paperSize != null) {
  187. i = 0;
  188. while (true) {
  189. if (i >= paperSize.length) {
  190. break;
  191. } else if (paperSize[i] == paperSourceSetting.paperSizeId) {
  192. break;
  193. } else {
  194. i++;
  195. }
  196. }
  197. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  198. } else {
  199. i = 0;
  200. }
  201. int[] paperType = this.mEpsonService.getPaperType(i);
  202. if (paperType != null) {
  203. i2 = 0;
  204. while (true) {
  205. if (i2 >= paperType.length) {
  206. break;
  207. } else if (paperType[i2] == paperSourceSetting.paperTypeId) {
  208. break;
  209. } else {
  210. i2++;
  211. }
  212. }
  213. } else {
  214. i2 = 0;
  215. }
  216. int[] paperSource = this.mEpsonService.getPaperSource(i, i2, 1);
  217. if (paperSource != null) {
  218. int i4 = 0;
  219. while (true) {
  220. if (i4 >= paperSource.length) {
  221. break;
  222. } else if (paperSource[i4] == paperSourceSetting.paperSource) {
  223. break;
  224. } else {
  225. i4++;
  226. }
  227. }
  228. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  229. }
  230. paperSourceSetting.bSupportESCPR = true;
  231. } catch (RemoteException e) {
  232. e.printStackTrace();
  233. }
  234. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  235. }
  236. }
  237. }
  238. /* access modifiers changed from: protected */
  239. public Dialog onCreateDialog(int i) {
  240. Dialog onCreateDialog = super.onCreateDialog(i);
  241. if (i != 10) {
  242. return onCreateDialog;
  243. }
  244. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  245. builder.setTitle(getResources().getString(R.string.ph_cannotSet_Title)).setMessage(getResources().getString(R.string.ph_cannotSet_Detail)).setPositiveButton(getResources().getString(R.string.f343ok), new DialogInterface.OnClickListener() {
  246. public void onClick(DialogInterface dialogInterface, int i) {
  247. dialogInterface.dismiss();
  248. }
  249. });
  250. return builder.create();
  251. }
  252. public class PaperSourceInfoBuilder extends AbstractListBuilder {
  253. private static final int ACTIVE = 2;
  254. private static final int SIZE = 0;
  255. private static final int TYPE = 1;
  256. PaperSourceSetting curSetting = null;
  257. MediaInfo.PaperSize mPaperSizeLookupTable = new MediaInfo.PaperSize();
  258. MediaInfo.PaperType mPaperTypeLookupTable = new MediaInfo.PaperType();
  259. public void addPrinter(String[] strArr) {
  260. }
  261. public AlphabetIndexer getIndexer() {
  262. return null;
  263. }
  264. /* access modifiers changed from: protected */
  265. public void notifyDataChange() {
  266. }
  267. public PaperSourceInfoBuilder(Context context, ViewGroup viewGroup) {
  268. super(context, viewGroup);
  269. }
  270. /* access modifiers changed from: protected */
  271. public void buildData() {
  272. this.mData.clear();
  273. }
  274. public View buildViewHolder() {
  275. return this.mLayoutInflater.inflate(R.layout.printer_item, (ViewGroup) null);
  276. }
  277. public Vector<View> buildViewHolderContent(View view) {
  278. Vector<View> vector = new Vector<>();
  279. vector.add(view.findViewById(R.id.name));
  280. vector.add(view.findViewById(R.id.f336ip));
  281. vector.add(view.findViewById(R.id.active_icon));
  282. return vector;
  283. }
  284. public void buildViewHolderContentData(int i, Vector<View> vector, Vector<Object> vector2) {
  285. PaperSourceSetting paperSourceSetting = (PaperSourceSetting) vector2.elementAt(i);
  286. ((TextView) vector.elementAt(0)).setText(PaperSourceSettingScr.this.getResources().getString(this.mPaperSizeLookupTable.getStringId(paperSourceSetting.paperSizeId)));
  287. ((TextView) vector.elementAt(1)).setText(PaperSourceSettingScr.this.getResources().getString(this.mPaperTypeLookupTable.getStringId(paperSourceSetting.paperTypeId)));
  288. vector.elementAt(2).setVisibility(this.curSetting.equals(paperSourceSetting) ? 0 : 8);
  289. if (!paperSourceSetting.bSupportESCPR) {
  290. ((TextView) vector.elementAt(0)).setTextColor(this.mContext.getResources().getColor(R.color.light_gray));
  291. } else {
  292. ((TextView) vector.elementAt(0)).setTextColor(this.mContext.getResources().getColor(R.color.all_black));
  293. }
  294. }
  295. public void setResource(Object obj) {
  296. this.curSetting = (PaperSourceSetting) obj;
  297. }
  298. public void addPaperInfoSetting(PaperSourceSetting paperSourceSetting) {
  299. this.mData.add(paperSourceSetting);
  300. this.mAdapter.notifyDataSetChanged();
  301. }
  302. }
  303. }