123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- package epson.print.screen;
- 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.net.Uri;
- import android.os.AsyncTask;
- 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.Button;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import com.epson.iprint.prtlogger.Analytics;
- import com.epson.mobilephone.common.escpr.MediaInfo;
- import com.epson.mobilephone.common.wifidirect.escprLib;
- import epson.common.Constants;
- import epson.common.IPAddressUtils;
- import epson.common.Utils;
- import epson.common.httpclient.IAHttpClient;
- import epson.print.ActivityIACommon;
- import epson.print.R;
- import epson.print.CommonDefine;
- import epson.print.MyPrinter;
- 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;
- import epson.print.widgets.CustomTitleAlertDialogBuilder;
- import epson.print.widgets.PrinterInfoBuilder;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Locale;
- public class PrinterFinder extends ActivityIACommon {
- private static final int DELAY = 100;
- private static final int DIALOG_INFORM = 0;
- /* access modifiers changed from: private */
- public static boolean foundPrinter = false;
- /* access modifiers changed from: private */
- public static final Object mLock = new Object();
- private final int CANCEL_FIND_PRINTER = 2;
- private final int DISPLAY_FIND_RESULT = 6;
- private final int INFORM_DIALOG = 5;
- private final String PRINTER_COMMON_DEVICENAME = "common_devicename";
- private final String PRINTER_ID = "id";
- private final String PRINTER_INDEX = "index";
- private final String PRINTER_IP = escprLib.PRINTER_IP;
- private final String PRINTER_NAME = "name";
- private final int SEARCH_PRINTER = 1;
- private final int SELECT_PRINTER = 4;
- private final int UPDATE_PRINTER = 3;
- int curError;
- /* access modifiers changed from: private */
- public boolean isDialogOpen = false;
- /* access modifiers changed from: private */
- public boolean isFinishSearchPrinter = false;
- /* access modifiers changed from: private */
- public Boolean isFocused = true;
- AbstractListBuilder mBuilder;
- /* access modifiers changed from: private */
- public IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
- 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 onNotifyProgress(int i, int i2) throws RemoteException {
- }
- public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
- Message obtain = Message.obtain();
- obtain.what = 3;
- Bundle bundle = new Bundle();
- bundle.putString("name", str);
- bundle.putString(escprLib.PRINTER_IP, str2);
- bundle.putString("id", str3);
- bundle.putString("common_devicename", str5);
- obtain.setData(bundle);
- PrinterFinder.this.mHandler.sendMessage(obtain);
- }
- public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
- synchronized (PrinterFinder.mLock) {
- boolean unused = PrinterFinder.foundPrinter = Utils.getPrefBoolean(PrinterFinder.this.getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH);
- if ((i2 == -1300 || i2 == -1351) && !PrinterFinder.foundPrinter) {
- i2 = -1100;
- } else if ((i2 == -1300 || i2 == -1351 || i2 == -1100) && PrinterFinder.foundPrinter) {
- i2 = -11001;
- }
- }
- PrinterFinder printerFinder = PrinterFinder.this;
- printerFinder.curError = i2;
- printerFinder.mHandler.sendEmptyMessage(5);
- }
- };
- Context mContext;
- private ServiceConnection mEpsonConnection = new ServiceConnection() {
- public void onServiceDisconnected(ComponentName componentName) {
- try {
- PrinterFinder.this.mEpsonService.unregisterCallback(PrinterFinder.this.mCallback);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- IEpsonService unused = PrinterFinder.this.mEpsonService = null;
- }
- public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
- IEpsonService unused = PrinterFinder.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
- if (PrinterFinder.this.mEpsonService != null) {
- try {
- PrinterFinder.this.mEpsonService.registerCallback(PrinterFinder.this.mCallback);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- }
- };
- /* access modifiers changed from: private */
- public IEpsonService mEpsonService = null;
- Handler mHandler = new Handler(new Handler.Callback() {
- public boolean handleMessage(Message message) {
- switch (message.what) {
- case 1:
- if (PrinterFinder.this.mEpsonService == null) {
- PrinterFinder.this.mHandler.sendEmptyMessageDelayed(1, 100);
- break;
- } else {
- try {
- boolean unused = PrinterFinder.this.isFinishSearchPrinter = false;
- PrinterFinder.this.searchButtonSetEnabled(false);
- PrinterFinder.this.mProgressBar.setVisibility(0);
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.searching_text));
- PrinterFinder.this.mEpsonService.searchPrinters((String) null, (String) null, 1);
- break;
- } catch (RemoteException e) {
- e.printStackTrace();
- break;
- }
- }
- case 2:
- if (PrinterFinder.this.mEpsonService != null) {
- try {
- PrinterFinder.this.mEpsonService.cancelSearchPrinter();
- break;
- } catch (RemoteException e2) {
- e2.printStackTrace();
- break;
- }
- }
- break;
- case 3:
- final Bundle data = message.getData();
- String string = data.getString("name");
- if (string == null || string.contentEquals("FINISH")) {
- if (!PrinterFinder.this.mIsClickSelect) {
- if (PrinterFinder.this.mBuilder.getData().size() <= 0) {
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.EPS_PRNERR_COMM_TITLE1));
- } else if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable));
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable));
- } else {
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(String.format(PrinterFinder.this.getString(R.string.numberOfPrintersAvailable), new Object[]{Integer.valueOf(PrinterFinder.this.mBuilder.getData().size())}));
- }
- PrinterFinder.this.mBuilder.getAdapter().notifyDataSetChanged();
- PrinterFinder.this.mProgressBar.setVisibility(8);
- PrinterFinder.this.searchButtonSetEnabled(true);
- boolean unused2 = PrinterFinder.this.isFinishSearchPrinter = true;
- break;
- }
- } else {
- synchronized (PrinterFinder.mLock) {
- if (!PrinterFinder.this.printerList.contains(data.getString("id"))) {
- new AsyncTask<Void, Void, MyPrinter[]>() {
- /* access modifiers changed from: protected */
- public MyPrinter[] doInBackground(Void... voidArr) {
- IAHttpClient.HttpResponse httpResponse;
- String buildURL = IPAddressUtils.buildURL(Analytics.EXTENSION_STRING_WEB, data.getString(escprLib.PRINTER_IP), "/PRESENTATION/EPSONCONNECT");
- IAHttpClient.HttpGet httpGet = new IAHttpClient.HttpGet(buildURL);
- IAHttpClient iAHttpClient = new IAHttpClient();
- iAHttpClient.setFollowRedirects(false);
- try {
- httpResponse = iAHttpClient.execute(httpGet);
- } catch (IOException unused) {
- EPLog.m305d("httpResponse", "IOException");
- httpResponse = null;
- }
- if (httpResponse != null) {
- int responseCode = httpResponse.getResponseCode();
- EPLog.m305d("Response", "res : " + responseCode);
- if (200 == responseCode || (300 <= responseCode && responseCode < 400)) {
- MyPrinter myPrinter = new MyPrinter(data.getString("name"), data.getString(escprLib.PRINTER_IP), data.getString("id"), (String) null);
- myPrinter.setCommonDeviceName(data.getString("common_devicename"));
- return new MyPrinter[]{myPrinter};
- } else if (404 == responseCode) {
- EPLog.m305d("Response", "NotFound:" + buildURL);
- } else {
- EPLog.m305d("Response", "Error:" + buildURL);
- }
- }
- return null;
- }
- /* access modifiers changed from: protected */
- public void onPostExecute(MyPrinter[] myPrinterArr) {
- super.onPostExecute(myPrinterArr);
- if (myPrinterArr != null) {
- ((PrinterInfoBuilder) PrinterFinder.this.mBuilder).addPrinter(myPrinterArr[0]);
- PrinterFinder.this.printerList.add(data.getString("id"));
- }
- }
- }.execute(new Void[0]);
- boolean unused3 = PrinterFinder.foundPrinter = true;
- break;
- } else {
- break;
- }
- }
- }
- break;
- case 4:
- if (PrinterFinder.this.mEpsonService != null) {
- try {
- PrinterFinder.this.mEpsonService.setCurPrinter(message.getData().getInt("index"));
- } catch (RemoteException e3) {
- e3.printStackTrace();
- }
- }
- Intent intent = new Intent();
- Bundle bundle = new Bundle();
- bundle.putString(Constants.PRINTER_NAME, message.getData().getString("name"));
- bundle.putString(Constants.PRINTER_IP, message.getData().getString(escprLib.PRINTER_IP));
- bundle.putString(Constants.PRINTER_ID, message.getData().getString("id"));
- intent.putExtras(bundle);
- PrinterFinder.this.setResult(-1, intent);
- PrinterFinder.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(IPAddressUtils.buildURL(Analytics.EXTENSION_STRING_WEB, message.getData().getString(escprLib.PRINTER_IP), "/PRESENTATION/EPSONCONNECT"))));
- PrinterFinder.this.finish();
- break;
- case 5:
- if (!PrinterFinder.this.isDialogOpen) {
- boolean unused4 = PrinterFinder.this.isDialogOpen = true;
- EPLog.m313i("mHandler", "curError = " + PrinterFinder.this.curError);
- PrinterFinder.this.showDialog(0);
- break;
- }
- break;
- }
- return false;
- }
- });
- boolean mIsClickSelect = false;
- ViewGroup mLayout;
- ProgressBar mProgressBar;
- Button mSearchButton;
- /* access modifiers changed from: private */
- public ArrayList<String> printerList = new ArrayList<>();
- /* access modifiers changed from: protected */
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
- if (this.mEpsonService == null) {
- bindService(new Intent(this, EpsonService.class), this.mEpsonConnection, 1);
- }
- this.printerList.clear();
- this.mLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.search_printer_layout, (ViewGroup) null);
- buildElements();
- this.mIsClickSelect = false;
- setContentView((View) this.mLayout);
- this.mContext = this;
- setActionBar((int) R.string.remoteprinter_get_emailadress, true);
- }
- private void buildElements() {
- this.mLayout.findViewById(R.id.rl_localremoteselect).setVisibility(8);
- this.mSearchButton = (Button) this.mLayout.findViewById(R.id.function_button);
- this.mProgressBar = (ProgressBar) this.mLayout.findViewById(R.id.progress_bar);
- searchButtonSetEnabled(false);
- this.mProgressBar.setVisibility(0);
- this.mLayout.findViewById(R.id.ble_wifi_setting).setVisibility(8);
- this.mLayout.findViewById(R.id.not_found_printer_epsonsn).setVisibility(8);
- this.mBuilder = new PrinterInfoBuilder(getBaseContext(), this.mLayout, 0);
- this.mBuilder.setResource(getIntent().getExtras().getString(Constants.PRINTER_NAME));
- this.mBuilder.build();
- this.mBuilder.refresh();
- ((ListView) this.mLayout.findViewById(16908298)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
- if (PrinterFinder.this.isFocused.booleanValue()) {
- Boolean unused = PrinterFinder.this.isFocused = false;
- PrinterFinder printerFinder = PrinterFinder.this;
- printerFinder.mIsClickSelect = true;
- Message obtainMessage = printerFinder.mHandler.obtainMessage();
- obtainMessage.what = 4;
- Bundle bundle = new Bundle();
- bundle.putInt("index", i);
- bundle.putString("name", ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getName());
- bundle.putString("id", ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getPrinterId());
- bundle.putString(escprLib.PRINTER_IP, ((MyPrinter) PrinterFinder.this.mBuilder.getData().elementAt(i)).getIp());
- obtainMessage.setData(bundle);
- PrinterFinder.this.mHandler.sendMessageDelayed(obtainMessage, 100);
- }
- }
- });
- this.mSearchButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- synchronized (PrinterFinder.mLock) {
- PrinterFinder.this.printerList.clear();
- PrinterFinder.this.mBuilder.refresh();
- }
- boolean unused = PrinterFinder.this.isFinishSearchPrinter = false;
- PrinterFinder.this.searchButtonSetEnabled(false);
- PrinterFinder.this.mProgressBar.setVisibility(0);
- ((TextView) PrinterFinder.this.mLayout.findViewById(R.id.empty)).setText(PrinterFinder.this.getString(R.string.searching_text));
- PrinterFinder.this.mHandler.sendEmptyMessageDelayed(1, 100);
- }
- });
- }
- /* access modifiers changed from: protected */
- public void onDestroy() {
- super.onDestroy();
- if (this.mEpsonService != null) {
- if (!this.isFinishSearchPrinter) {
- this.mHandler.sendEmptyMessageDelayed(2, 200);
- }
- try {
- this.mEpsonService.unregisterCallback(this.mCallback);
- unbindService(this.mEpsonConnection);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- this.mBuilder.destructor();
- }
- public void onBackPressed() {
- super.onBackPressed();
- try {
- this.mEpsonService.cancelSearchPrinter();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- /* access modifiers changed from: protected */
- public void onResume() {
- super.onResume();
- EPLog.m307e("Epson", "PrinterFinder.java call onResume()");
- this.mHandler.sendEmptyMessageDelayed(1, 100);
- EPLog.m305d("PrinterFinder", "Send CHECK_PRINTER Message.");
- }
- /* access modifiers changed from: protected */
- public void onPause() {
- EPLog.m305d("SearchPrinterScr", "onPause");
- super.onPause();
- }
- /* access modifiers changed from: protected */
- public Dialog onCreateDialog(int i) {
- if (i != 0) {
- return null;
- }
- EPLog.m313i("DIALOG_INFORM", "curError = " + this.curError);
- int i2 = this.curError;
- if (!(i2 == -1100 && i2 == -11001)) {
- if (Utils.getPrefBoolean(getApplicationContext(), "PrintSetting", CommonDefine.RE_SEARCH)) {
- this.curError = -11001;
- } else {
- this.curError = -1100;
- }
- }
- Integer[] stringId = MediaInfo.ErrorTable.getStringId(this.curError);
- if (stringId == null) {
- stringId = new Integer[]{Integer.valueOf(R.string.NOT_IMPLEMENT), Integer.valueOf(R.string.NOT_IMPLEMENT_TITLE)};
- }
- String string = getString(stringId[0].intValue());
- String ssid = Utils.getSSID(this);
- if (Utils.isConnectedWifi(this) && this.curError == -11001 && ssid != null) {
- string = String.format(getString(R.string.EPS_ERR_PRINTER_NOT_FOUND_RESEARCH), new Object[]{ssid});
- }
- return new CustomTitleAlertDialogBuilder(this).setCancelable(false).setTitle(getString(stringId[1].intValue())).setMessage(string).setNegativeButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- PrinterFinder.this.removeDialog(0);
- boolean unused = PrinterFinder.this.isDialogOpen = false;
- }
- }).create();
- }
- public void searchButtonSetEnabled(boolean z) {
- this.mSearchButton.setVisibility(0);
- if (z) {
- this.mSearchButton.setEnabled(true);
- } else {
- this.mSearchButton.setEnabled(false);
- }
- }
- }
|