private void refreshCampaigns() { mSharedPreferencesHelper.setLastCampaignRefreshTime(System.currentTimeMillis()); new CampaignReadTask(this) { @Override protected void onPreExecute() { super.onPreExecute(); getActionBar().setProgressVisible(true); } @Override protected void onPostExecute(CampaignReadResponse response) { if (response == null) return; super.onPostExecute(response); getActionBar().setProgressVisible(false); } }.execute(mSharedPreferencesHelper.getUsername(), mSharedPreferencesHelper.getHashedPassword()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); setContentView(R.layout.login); // first see if they are already logged in final SharedPreferencesHelper preferencesHelper = new SharedPreferencesHelper(this); // Funf Ohmage /* if (preferencesHelper.isUserDisabled()) { ((OhmageApplication) getApplication()).resetAll(); }*/ mUpdateCredentials = getIntent().getBooleanExtra(EXTRA_UPDATE_CREDENTIALS, false); // if they are, redirect them to the dashboard if (preferencesHelper.isAuthenticated() && !mUpdateCredentials) { startActivityForResult(new Intent(this, MainActivity.class), LOGIN_FINISHED); return; } mLoginButton = (Button) findViewById(R.id.login); mUsernameEdit = (EditText) findViewById(R.id.login_username); mPasswordEdit = (EditText) findViewById(R.id.login_password); mVersionText = (TextView) findViewById(R.id.version); try { mVersionText.setText("v" + getPackageManager().getPackageInfo("org.ohmage", 0).versionName); } catch (Exception e) { Log.e(TAG, "unable to retrieve version", e); mVersionText.setText(" "); } mLoginButton.setOnClickListener(mClickListener); mPreferencesHelper = new SharedPreferencesHelper(this); if (savedInstanceState == null) { Log.i(TAG, "creating from scratch"); // clear login fail notification (if such notification existed) // NotificationHelper.cancel(this, NotificationHelper.NOTIFY_LOGIN_FAIL, null); // move this down so notification is only cleared if login is successful??? // the following block is commented out to support single user lock-in, implemented in the // code below /*String username = mPreferencesHelper.getUsername(); if (username.length() > 0) { Log.i(TAG, "saved credentials exist"); mUsernameEdit.setText(username); mPasswordEdit.setText(DUMMY_PASSWORD); //launch main activity and finish //WE CAN'T DO THIS BECAUSE IF THE ACTIVITY IS LAUNCHED AFTER AN HTTP ERROR NOTIFICATION, CREDS WILL STILL BE STORED //startActivity(new Intent(LoginActivity.this, MainActivity.class)); //finish(); //OR do Login? doLogin(); //what if this works the other way around? make main activity the starting point, and launch login if needed? } else { Log.i(TAG, "saved credentials do not exist"); }*/ // Funf Ohmage /* if (mPreferencesHelper.isUserDisabled()) { ((OhmageApplication) getApplication()).resetAll(); } */ // code for single user lock-in String username = mPreferencesHelper.getUsername(); if (username.length() > 0) { Log.i(TAG, "saved username exists"); mUsernameEdit.setText(username); mUsernameEdit.setEnabled(false); mUsernameEdit.setFocusable(false); // String hashedPassword = mPreferencesHelper.getHashedPassword(); // if (hashedPassword.length() > 0) { // Log.i(TAG, "saved password exists"); // mPasswordEdit.setText(DUMMY_PASSWORD); // //doLogin(); // } else { // Log.i(TAG, "no saved password, must have had a login problem"); // } } else { Log.i(TAG, "no saved username"); } } // Funf-Ohmage // Since Campaighns not needed /* mCampaignDownloadTask = (CampaignReadTask) getSupportLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<CampaignReadResponse>() { @Override public Loader<CampaignReadResponse> onCreateLoader(int id, Bundle args) { return new CampaignReadTask(OhmageLoginActivity.this, null, null); } @Override public void onLoadFinished(Loader<CampaignReadResponse> loader, CampaignReadResponse data) { String urn = Campaign.getSingleCampaign(OhmageLoginActivity.this); if(urn == null) { // Downloading the campaign failed so we should reset the username and password mPreferencesHelper.clearCredentials(); Toast.makeText(OhmageLoginActivity.this, R.string.login_error_downloading_campaign, Toast.LENGTH_LONG).show(); } else { loginFinished(((CampaignReadTask) loader).getUsername(), ((CampaignReadTask) loader).getHashedPassword()); } dismissDialog(DIALOG_DOWNLOADING_CAMPAIGNS); } @Override public void onLoaderReset(Loader<CampaignReadResponse> loader) { } });*/ }