PaperSourceSettingScr.java 13 KB

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