package epson.print.screen; import android.app.AlertDialog; import android.app.Dialog; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.RemoteException; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AlphabetIndexer; import android.widget.ListView; import android.widget.TextView; import com.epson.mobilephone.common.escpr.MediaInfo; import java.util.ArrayList; import java.util.Vector; import epson.print.ActivityIACommon; import epson.print.R; import epson.print.Util.EPLog; import epson.print.service.EpsonService; import epson.print.service.IEpsonService; import epson.print.service.IEpsonServiceCallback; import epson.print.widgets.AbstractListBuilder; public class PaperSourceSettingScr extends ActivityIACommon { private static final int ID_BINDSERVICE = 1; private static final int ID_NOT_ESCPRSUPPORT = 10; public static final String PRINT_SETTING_TYPE = "print-setting-type"; private static final int SETTING_DONE = 3; ArrayList aPaperSourceSetting; AdapterView.OnItemClickListener listItemClickLister = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView adapterView, View view, int i, long j) { PaperSourceSetting paperSourceSetting = (PaperSourceSetting) mListBuilder.getData().elementAt(i); if (!paperSourceSetting.bSupportESCPR) { showDialog(10); return; } PaperSourceSettingScr paperSourceSettingScr = PaperSourceSettingScr.this; PrintSetting instance = PrintSetting.getInstance(paperSourceSettingScr, paperSourceSettingScr.mPrintSettingTypeName); instance.loadSettings(); instance.paperSizeValue = paperSourceSetting.paperSizeId; instance.paperTypeValue = paperSourceSetting.paperTypeId; instance.paperSourceValue = paperSourceSetting.paperSource; instance.saveSettings(); try { mEpsonService.updatePrinterSettings(mPrintSettingTypeName); } catch (RemoteException e) { e.printStackTrace(); } setResult(3); finish(); } }; private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() { public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException { } public void onGetInkState() throws RemoteException { } public void onGetStatusState() throws RemoteException { } public void onNotifyContinueable(int i) throws RemoteException { } public void onNotifyEndJob(int i) throws RemoteException { } public void onNotifyError(int i, int i2, boolean z) throws RemoteException { } public void onNotifyProgress(int i, int i2) throws RemoteException { } }; private ServiceConnection mEpsonConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName componentName) { EPLog.v("SettingScr", "onServiceDisconnected"); try { mEpsonService.unregisterCallback(mCallback); } catch (RemoteException e) { e.printStackTrace(); } IEpsonService unused = mEpsonService = null; } public void onServiceConnected(ComponentName componentName, IBinder iBinder) { IEpsonService unused = mEpsonService = IEpsonService.Stub.asInterface(iBinder); EPLog.v("SettingScr", "onServiceConnected"); if (mEpsonService != null) { try { mEpsonService.registerCallback(mCallback); } catch (RemoteException e) { e.printStackTrace(); } mHandler.sendEmptyMessage(1); } } }; private IEpsonService mEpsonService = null; Handler mHandler = new Handler(new Handler.Callback() { public boolean handleMessage(Message message) { int i = message.what; if (i == 1) { PaperSourceSettingScr paperSourceSettingScr = PaperSourceSettingScr.this; paperSourceSettingScr.aPaperSourceSetting = paperSourceSettingScr.getIntent().getParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO); addPaparSettings(); progress.dismiss(); return false; } else if (i != 100) { return false; } else { aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO); addPaparSettings(); return false; } } }); PaperSourceInfoBuilder mListBuilder = null; private String mPrintSettingTypeName = PrintSetting.Kind.photo.name(); PaperSourceInfo paperSourceInfo = null; WorkingDialog progress = null; protected void onCreate(Bundle bundle) { super.onCreate(bundle); ViewGroup viewGroup = (ViewGroup) getLayoutInflater().inflate(R.layout.paper_source_setting, (ViewGroup) null); mListBuilder = new PaperSourceInfoBuilder(getBaseContext(), viewGroup); mListBuilder.build(); ((TextView) viewGroup.findViewById(R.id.empty)).setText(R.string.ph_Detail); ((ListView) viewGroup.findViewById(16908298)).setOnItemClickListener(listItemClickLister); setContentView((View) viewGroup); setActionBar((int) R.string.ph_Title, true); mPrintSettingTypeName = getIntent().getStringExtra(PRINT_SETTING_TYPE); PrintSetting instance = PrintSetting.getInstance(this, mPrintSettingTypeName); instance.loadSettings(); PaperSourceSetting paperSourceSetting = new PaperSourceSetting(); paperSourceSetting.paperSizeId = instance.paperSizeValue; paperSourceSetting.paperTypeId = instance.paperTypeValue; paperSourceSetting.paperSource = instance.paperSourceValue; mListBuilder.setResource(paperSourceSetting); paperSourceInfo = PaperSourceInfo.getInstance(this); if (mEpsonService == null) { Intent intent = new Intent(); intent.setClass(this, EpsonService.class); bindService(intent, mEpsonConnection, 1); } progress = new WorkingDialog(this); progress.show(); } protected void onDestroy() { super.onDestroy(); IEpsonService iEpsonService = mEpsonService; if (iEpsonService != null) { try { iEpsonService.unregisterCallback(mCallback); unbindService(mEpsonConnection); mEpsonService = null; } catch (RemoteException e) { e.printStackTrace(); } } } protected void onResume() { super.onResume(); paperSourceInfo.start(this, mHandler); } protected void onPause() { super.onPause(); paperSourceInfo.stop(); } private void addPaparSettings() { int i; int i2; if (mEpsonService != null && aPaperSourceSetting != null) { mListBuilder.refresh(); for (int i3 = 0; i3 < aPaperSourceSetting.size(); i3++) { PaperSourceSetting paperSourceSetting = aPaperSourceSetting.get(i3); try { paperSourceSetting.bSupportESCPR = false; int[] paperSize = mEpsonService.getPaperSize(); if (paperSize != null) { i = 0; while (true) { if (i >= paperSize.length) { break; } else if (paperSize[i] == paperSourceSetting.paperSizeId) { break; } else { i++; } } mListBuilder.addPaperInfoSetting(paperSourceSetting); } else { i = 0; } int[] paperType = mEpsonService.getPaperType(i); if (paperType != null) { i2 = 0; while (true) { if (i2 >= paperType.length) { break; } else if (paperType[i2] == paperSourceSetting.paperTypeId) { break; } else { i2++; } } } else { i2 = 0; } int[] paperSource = mEpsonService.getPaperSource(i, i2, 1); if (paperSource != null) { int i4 = 0; while (true) { if (i4 >= paperSource.length) { break; } else if (paperSource[i4] == paperSourceSetting.paperSource) { break; } else { i4++; } } mListBuilder.addPaperInfoSetting(paperSourceSetting); } paperSourceSetting.bSupportESCPR = true; } catch (RemoteException e) { e.printStackTrace(); } mListBuilder.addPaperInfoSetting(paperSourceSetting); } } } protected Dialog onCreateDialog(int i) { Dialog onCreateDialog = super.onCreateDialog(i); if (i != 10) { return onCreateDialog; } AlertDialog.Builder builder = new AlertDialog.Builder(this); 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() { public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); return builder.create(); } public class PaperSourceInfoBuilder extends AbstractListBuilder { private static final int ACTIVE = 2; private static final int SIZE = 0; private static final int TYPE = 1; PaperSourceSetting curSetting = null; MediaInfo.PaperSize mPaperSizeLookupTable = new MediaInfo.PaperSize(); MediaInfo.PaperType mPaperTypeLookupTable = new MediaInfo.PaperType(); public void addPrinter(String[] strArr) { } public AlphabetIndexer getIndexer() { return null; } protected void notifyDataChange() { } public PaperSourceInfoBuilder(Context context, ViewGroup viewGroup) { super(context, viewGroup); } protected void buildData() { mData.clear(); } public View buildViewHolder() { return mLayoutInflater.inflate(R.layout.printer_item, (ViewGroup) null); } public Vector buildViewHolderContent(View view) { Vector vector = new Vector<>(); vector.add(view.findViewById(R.id.name)); vector.add(view.findViewById(R.id.f336ip)); vector.add(view.findViewById(R.id.active_icon)); return vector; } public void buildViewHolderContentData(int i, Vector vector, Vector vector2) { PaperSourceSetting paperSourceSetting = (PaperSourceSetting) vector2.elementAt(i); ((TextView) vector.elementAt(0)).setText(getResources().getString(mPaperSizeLookupTable.getStringId(paperSourceSetting.paperSizeId))); ((TextView) vector.elementAt(1)).setText(getResources().getString(mPaperTypeLookupTable.getStringId(paperSourceSetting.paperTypeId))); vector.elementAt(2).setVisibility(curSetting.equals(paperSourceSetting) ? 0 : 8); if (!paperSourceSetting.bSupportESCPR) { ((TextView) vector.elementAt(0)).setTextColor(mContext.getResources().getColor(R.color.light_gray)); } else { ((TextView) vector.elementAt(0)).setTextColor(mContext.getResources().getColor(R.color.all_black)); } } public void setResource(Object obj) { curSetting = (PaperSourceSetting) obj; } public void addPaperInfoSetting(PaperSourceSetting paperSourceSetting) { mData.add(paperSourceSetting); mAdapter.notifyDataSetChanged(); } } }