@Override public void handleMessage(Message msg) { if (msg.what == USER_ADDED_ACCOUNT_SUCCESS_CODE) { try { if (null != dialog) { dialog.dismiss(); } finish(); } catch (Exception e) { e.printStackTrace(); } } else if (msg.what == USER_ADDED_ACCOUNT_FAILED_CODE) { if (null != dialog) { dialog.dismiss(); } LewaConnectionAlertDialog alertDailog = new LewaConnectionAlertDialog(LewaLoginActivity.this); alertDailog.prepareBuilder( getString(R.string.alert_dialog_login_failed), getString(R.string.alert_dialog_login_failed_result), null, getString(R.string.label_back)); alertDailog.showAlertDialog(null); } }
private void doJob(final String email, final String password) { teleManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final Login login = new Login(LewaLoginActivity.this); login.setLoginParams(email, password, teleManager.getDeviceId()); dialog = new CustomProgressDailog(LewaLoginActivity.this); dialog.setProperties(null, getString(R.string.progress_dialog_logining)); dialog.show(); new Thread( new Runnable() { @Override public void run() { try { String response = login.attemptLogin(); JSONObject jsonObject = login.parseLoginData(response); if (jsonObject.has(KEY_OK) && jsonObject.getBoolean(KEY_OK)) { if (null != jsi) { String uid = jsonObject.getString("uid"); jsi.setUserID(uid); jsi.setClientID(jsonObject.getString("cid")); jsi.setClientKey(jsonObject.getString("key")); jsi.setUserSecret(jsonObject.getString("secret")); jsi.setUserEmail(jsonObject.getString("email")); jsi.setAccessToken(jsonObject.getString("access_token")); putSpValue(KEY_SPNAME, uid); } } else { // Log.e(TAG, "login failed"); Message msg = Message.obtain(); msg.what = USER_ADDED_ACCOUNT_FAILED_CODE; finishHandler.sendMessage(msg); return; } Thread.sleep(2000); } catch (JSONException e1) { e1.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Message msg = Message.obtain(); msg.what = USER_ADDED_ACCOUNT_SUCCESS_CODE; finishHandler.sendMessage(msg); } }) .start(); }
@Override public void onPause() { this.unregisterReceiver(this.bcr); this.unbindService(); if (null != dialog) { dialog.dismiss(); } super.onPause(); }