PaperSourceSettingScr.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
  61. public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
  62. }
  63. public void onGetInkState() throws RemoteException {
  64. }
  65. public void onGetStatusState() throws RemoteException {
  66. }
  67. public void onNotifyContinueable(int i) throws RemoteException {
  68. }
  69. public void onNotifyEndJob(int i) throws RemoteException {
  70. }
  71. public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
  72. }
  73. public void onNotifyProgress(int i, int i2) throws RemoteException {
  74. }
  75. };
  76. private ServiceConnection mEpsonConnection = new ServiceConnection() {
  77. public void onServiceDisconnected(ComponentName componentName) {
  78. EPLog.v("SettingScr", "onServiceDisconnected");
  79. try {
  80. PaperSourceSettingScr.this.mEpsonService.unregisterCallback(PaperSourceSettingScr.this.mCallback);
  81. } catch (RemoteException e) {
  82. e.printStackTrace();
  83. }
  84. IEpsonService unused = PaperSourceSettingScr.this.mEpsonService = null;
  85. }
  86. public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  87. IEpsonService unused = PaperSourceSettingScr.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
  88. EPLog.v("SettingScr", "onServiceConnected");
  89. if (PaperSourceSettingScr.this.mEpsonService != null) {
  90. try {
  91. PaperSourceSettingScr.this.mEpsonService.registerCallback(PaperSourceSettingScr.this.mCallback);
  92. } catch (RemoteException e) {
  93. e.printStackTrace();
  94. }
  95. PaperSourceSettingScr.this.mHandler.sendEmptyMessage(1);
  96. }
  97. }
  98. };
  99. private IEpsonService mEpsonService = null;
  100. Handler mHandler = new Handler(new Handler.Callback() {
  101. public boolean handleMessage(Message message) {
  102. int i = message.what;
  103. if (i == 1) {
  104. PaperSourceSettingScr paperSourceSettingScr = PaperSourceSettingScr.this;
  105. paperSourceSettingScr.aPaperSourceSetting = paperSourceSettingScr.getIntent().getParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO);
  106. PaperSourceSettingScr.this.addPaparSettings();
  107. PaperSourceSettingScr.this.progress.dismiss();
  108. return false;
  109. } else if (i != 100) {
  110. return false;
  111. } else {
  112. PaperSourceSettingScr.this.aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO);
  113. PaperSourceSettingScr.this.addPaparSettings();
  114. return false;
  115. }
  116. }
  117. });
  118. PaperSourceInfoBuilder mListBuilder = null;
  119. private String mPrintSettingTypeName = PrintSetting.Kind.photo.name();
  120. PaperSourceInfo paperSourceInfo = null;
  121. WorkingDialog progress = null;
  122. protected void onCreate(Bundle bundle) {
  123. super.onCreate(bundle);
  124. ViewGroup viewGroup = (ViewGroup) getLayoutInflater().inflate(R.layout.paper_source_setting, (ViewGroup) null);
  125. this.mListBuilder = new PaperSourceInfoBuilder(getBaseContext(), viewGroup);
  126. this.mListBuilder.build();
  127. ((TextView) viewGroup.findViewById(R.id.empty)).setText(R.string.ph_Detail);
  128. ((ListView) viewGroup.findViewById(16908298)).setOnItemClickListener(this.listItemClickLister);
  129. setContentView((View) viewGroup);
  130. setActionBar((int) R.string.ph_Title, true);
  131. this.mPrintSettingTypeName = getIntent().getStringExtra(PRINT_SETTING_TYPE);
  132. PrintSetting instance = PrintSetting.getInstance(this, this.mPrintSettingTypeName);
  133. instance.loadSettings();
  134. PaperSourceSetting paperSourceSetting = new PaperSourceSetting();
  135. paperSourceSetting.paperSizeId = instance.paperSizeValue;
  136. paperSourceSetting.paperTypeId = instance.paperTypeValue;
  137. paperSourceSetting.paperSource = instance.paperSourceValue;
  138. this.mListBuilder.setResource(paperSourceSetting);
  139. this.paperSourceInfo = PaperSourceInfo.getInstance(this);
  140. if (this.mEpsonService == null) {
  141. Intent intent = new Intent();
  142. intent.setClass(this, EpsonService.class);
  143. bindService(intent, this.mEpsonConnection, 1);
  144. }
  145. this.progress = new WorkingDialog(this);
  146. this.progress.show();
  147. }
  148. protected void onDestroy() {
  149. super.onDestroy();
  150. IEpsonService iEpsonService = this.mEpsonService;
  151. if (iEpsonService != null) {
  152. try {
  153. iEpsonService.unregisterCallback(this.mCallback);
  154. unbindService(this.mEpsonConnection);
  155. this.mEpsonService = null;
  156. } catch (RemoteException e) {
  157. e.printStackTrace();
  158. }
  159. }
  160. }
  161. protected void onResume() {
  162. super.onResume();
  163. this.paperSourceInfo.start(this, this.mHandler);
  164. }
  165. protected void onPause() {
  166. super.onPause();
  167. this.paperSourceInfo.stop();
  168. }
  169. private void addPaparSettings() {
  170. int i;
  171. int i2;
  172. if (this.mEpsonService != null && this.aPaperSourceSetting != null) {
  173. this.mListBuilder.refresh();
  174. for (int i3 = 0; i3 < this.aPaperSourceSetting.size(); i3++) {
  175. PaperSourceSetting paperSourceSetting = this.aPaperSourceSetting.get(i3);
  176. try {
  177. paperSourceSetting.bSupportESCPR = false;
  178. int[] paperSize = this.mEpsonService.getPaperSize();
  179. if (paperSize != null) {
  180. i = 0;
  181. while (true) {
  182. if (i >= paperSize.length) {
  183. break;
  184. } else if (paperSize[i] == paperSourceSetting.paperSizeId) {
  185. break;
  186. } else {
  187. i++;
  188. }
  189. }
  190. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  191. } else {
  192. i = 0;
  193. }
  194. int[] paperType = this.mEpsonService.getPaperType(i);
  195. if (paperType != null) {
  196. i2 = 0;
  197. while (true) {
  198. if (i2 >= paperType.length) {
  199. break;
  200. } else if (paperType[i2] == paperSourceSetting.paperTypeId) {
  201. break;
  202. } else {
  203. i2++;
  204. }
  205. }
  206. } else {
  207. i2 = 0;
  208. }
  209. int[] paperSource = this.mEpsonService.getPaperSource(i, i2, 1);
  210. if (paperSource != null) {
  211. int i4 = 0;
  212. while (true) {
  213. if (i4 >= paperSource.length) {
  214. break;
  215. } else if (paperSource[i4] == paperSourceSetting.paperSource) {
  216. break;
  217. } else {
  218. i4++;
  219. }
  220. }
  221. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  222. }
  223. paperSourceSetting.bSupportESCPR = true;
  224. } catch (RemoteException e) {
  225. e.printStackTrace();
  226. }
  227. this.mListBuilder.addPaperInfoSetting(paperSourceSetting);
  228. }
  229. }
  230. }
  231. protected Dialog onCreateDialog(int i) {
  232. Dialog onCreateDialog = super.onCreateDialog(i);
  233. if (i != 10) {
  234. return onCreateDialog;
  235. }
  236. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  237. 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() {
  238. public void onClick(DialogInterface dialogInterface, int i) {
  239. dialogInterface.dismiss();
  240. }
  241. });
  242. return builder.create();
  243. }
  244. public class PaperSourceInfoBuilder extends AbstractListBuilder {
  245. private static final int ACTIVE = 2;
  246. private static final int SIZE = 0;
  247. private static final int TYPE = 1;
  248. PaperSourceSetting curSetting = null;
  249. MediaInfo.PaperSize mPaperSizeLookupTable = new MediaInfo.PaperSize();
  250. MediaInfo.PaperType mPaperTypeLookupTable = new MediaInfo.PaperType();
  251. public void addPrinter(String[] strArr) {
  252. }
  253. public AlphabetIndexer getIndexer() {
  254. return null;
  255. }
  256. protected void notifyDataChange() {
  257. }
  258. public PaperSourceInfoBuilder(Context context, ViewGroup viewGroup) {
  259. super(context, viewGroup);
  260. }
  261. protected void buildData() {
  262. this.mData.clear();
  263. }
  264. public View buildViewHolder() {
  265. return this.mLayoutInflater.inflate(R.layout.printer_item, (ViewGroup) null);
  266. }
  267. public Vector<View> buildViewHolderContent(View view) {
  268. Vector<View> vector = new Vector<>();
  269. vector.add(view.findViewById(R.id.name));
  270. vector.add(view.findViewById(R.id.f336ip));
  271. vector.add(view.findViewById(R.id.active_icon));
  272. return vector;
  273. }
  274. public void buildViewHolderContentData(int i, Vector<View> vector, Vector<Object> vector2) {
  275. PaperSourceSetting paperSourceSetting = (PaperSourceSetting) vector2.elementAt(i);
  276. ((TextView) vector.elementAt(0)).setText(PaperSourceSettingScr.this.getResources().getString(this.mPaperSizeLookupTable.getStringId(paperSourceSetting.paperSizeId)));
  277. ((TextView) vector.elementAt(1)).setText(PaperSourceSettingScr.this.getResources().getString(this.mPaperTypeLookupTable.getStringId(paperSourceSetting.paperTypeId)));
  278. vector.elementAt(2).setVisibility(this.curSetting.equals(paperSourceSetting) ? 0 : 8);
  279. if (!paperSourceSetting.bSupportESCPR) {
  280. ((TextView) vector.elementAt(0)).setTextColor(this.mContext.getResources().getColor(R.color.light_gray));
  281. } else {
  282. ((TextView) vector.elementAt(0)).setTextColor(this.mContext.getResources().getColor(R.color.all_black));
  283. }
  284. }
  285. public void setResource(Object obj) {
  286. this.curSetting = (PaperSourceSetting) obj;
  287. }
  288. public void addPaperInfoSetting(PaperSourceSetting paperSourceSetting) {
  289. this.mData.add(paperSourceSetting);
  290. this.mAdapter.notifyDataSetChanged();
  291. }
  292. }
  293. }