private void hideProgressDialog() { wifiListFragment.startAggroLoading(); if (connectToApSpinnerDialog != null) { if (!isFinishing()) { connectToApSpinnerDialog.dismiss(); } connectToApSpinnerDialog = null; } }
private void showProgressDialog() { wifiListFragment.stopAggroLoading(); String msg = Phrase.from(this, R.string.connecting_to_soft_ap) .put("device_name", getString(R.string.device_name)) .format() .toString(); connectToApSpinnerDialog = new ProgressDialog(this); connectToApSpinnerDialog.setMessage(msg); connectToApSpinnerDialog.setCancelable(false); connectToApSpinnerDialog.setIndeterminate(true); connectToApSpinnerDialog.show(); }
private void startConnectWorker() { // first, make sure we haven't actually been called twice... if (connectToApTask != null) { log.d("Already running connect worker " + connectToApTask + ", refusing to start another"); return; } wifiListFragment.stopAggroLoading(); // FIXME: verify first that we're still connected to the intended network if (!canStartProcessAgain()) { hideProgressDialog(); onMaxAttemptsReached(); return; } discoverProcessAttempts++; // Kind of lame; this just has doInBackground() return null on success, or if an // exception was thrown, it passes that along instead to indicate failure. connectToApTask = new AsyncTask<Void, Void, SetupStepException>() { @Override protected SetupStepException doInBackground(Void... voids) { try { // including this sleep because without it, // we seem to attempt a socket connection too early, // and it makes the process time out log.d("Waiting a couple seconds before trying the socket connection..."); EZ.threadSleep(2000); discoverProcessWorker.doTheThing( new InterfaceBindingSocketFactory(DiscoverDeviceActivity.this, currentSSID)); return null; } catch (SetupStepException e) { log.d("Setup exception thrown: ", e); return e; } } @Override protected void onPostExecute(SetupStepException error) { connectToApTask = null; if (error == null) { // no exceptions thrown, huzzah hideProgressDialog(); startActivity(new Intent(DiscoverDeviceActivity.this, SelectNetworkActivity.class)); finish(); } else if (error instanceof DeviceAlreadyClaimed) { hideProgressDialog(); onDeviceClaimedByOtherUser(); } else { // nope, do it all over again. // FIXME: this might be a good time to display some feedback... startConnectWorker(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }