Android Open Source - geocamTalkAndroid Authenticated Base Activity






From Project

Back to project page geocamTalkAndroid.

License

The source code is released under:

NASA OPEN SOURCE AGREEMENT VERSION 1.3 THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN COMPUTER SOFTWARE ORI...

If you think the Android project geocamTalkAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// __BEGIN_LICENSE__
// Copyright (C) 2008-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__
//  w  w w.j a v a2  s.  c  om
package gov.nasa.arc.geocam.talk.activity;

import gov.nasa.arc.geocam.talk.GeoCamTalkRoboApplication;
import gov.nasa.arc.geocam.talk.R;
import gov.nasa.arc.geocam.talk.UIUtils;
import gov.nasa.arc.geocam.talk.bean.TalkServerIntent;
import gov.nasa.arc.geocam.talk.service.ISiteAuth;
import roboguice.activity.RoboActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.inject.Inject;

/**
 * A base activity for activities protected by authentication.
 */
public class AuthenticatedBaseActivity extends RoboActivity {

  /** The site auth. */
  @Inject
  ISiteAuth siteAuth;

  /** The {@link BroadcastReceiver} that will receive login failed intents. */
  protected BroadcastReceiver login_failed_receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
      if (intent.getAction().contentEquals(TalkServerIntent.INTENT_LOGIN_FAILED.toString())) {
        Toast.makeText(context, "Could not log in. Please provide login credentials.",
            Toast.LENGTH_LONG);
        Log.i("Talk", "AuthBase received LOGIN_FAILED intent");
        UIUtils.goToLogin(context);
      }
    }
  };

  /* (non-Javadoc)
   * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
   */
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.default_menu, menu);
    return true;
  }

  /* (non-Javadoc)
   * @see roboguice.activity.RoboActivity#onResume()
   */
  @Override
  protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction(TalkServerIntent.INTENT_LOGIN_FAILED.toString());
    registerReceiver(login_failed_receiver, filter);
  }
  
  /* (non-Javadoc)
   * @see roboguice.activity.RoboActivity#onPause()
   */
  @Override
  protected void onPause() {
    unregisterReceiver(login_failed_receiver);
    super.onPause();
  }
  
  /* (non-Javadoc)
   * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
   */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {

      case R.id.logout_menu_button:
        try {
          Log.i("Talk", "Logout Menu Item");
          UIUtils.logout(siteAuth);
          this.startActivity(new Intent(this, GeoCamTalkLogon.class));
        } catch (Exception e) {
          UIUtils.displayException(getApplicationContext(), e, "You're screwed");
        }
        return false;
      case R.id.create_message_button:
        Log.i("Talk", "Create Message Menu Item");
        UIUtils.createTalkMessage(this);
        return false;
      case R.id.message_list_button:
        UIUtils.goHome(this);
        return false;
      case R.id.exit_menu_button:
        ((GeoCamTalkRoboApplication) getApplication()).stopThreads();
        finish();
                moveTaskToBack(true);
        System.exit(0);
                //android.os.Process.killProcess(android.os.Process.myPid());
        return false;        
      case R.id.settings_button:
        UIUtils.goToSettings(this);
        Log.i("Talk", "Settings Menu Item");
        return false;
      default:
        Log.i("Talk", "NO BUTTON!!!");
        return super.onOptionsItemSelected(item);
    }
  }

}




Java Source Code List

gov.nasa.arc.geocam.talk.GeoCamTalkModule.java
gov.nasa.arc.geocam.talk.GeoCamTalkRoboApplication.java
gov.nasa.arc.geocam.talk.UIUtils.java
gov.nasa.arc.geocam.talk.activity.AuthenticatedBaseActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkCreateActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkLogon.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMapActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMessageAdapter.java
gov.nasa.arc.geocam.talk.activity.SettingsActivity.java
gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage.java
gov.nasa.arc.geocam.talk.bean.ServerResponse.java
gov.nasa.arc.geocam.talk.bean.TalkServerIntent.java
gov.nasa.arc.geocam.talk.exception.AuthenticationFailedException.java
gov.nasa.arc.geocam.talk.service.AudioPlayer.java
gov.nasa.arc.geocam.talk.service.AudioRecorder.java
gov.nasa.arc.geocam.talk.service.C2DMReciever.java
gov.nasa.arc.geocam.talk.service.DatabaseHelper.java
gov.nasa.arc.geocam.talk.service.GeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.GeoLocationListener.java
gov.nasa.arc.geocam.talk.service.IAudioPlayer.java
gov.nasa.arc.geocam.talk.service.IAudioRecorder.java
gov.nasa.arc.geocam.talk.service.IDatabaseHelper.java
gov.nasa.arc.geocam.talk.service.IGeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.IIntentHelper.java
gov.nasa.arc.geocam.talk.service.IMessageStore.java
gov.nasa.arc.geocam.talk.service.ISiteAuth.java
gov.nasa.arc.geocam.talk.service.ITalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.ITalkServer.java
gov.nasa.arc.geocam.talk.service.IntentHelper.java
gov.nasa.arc.geocam.talk.service.MessageStore.java
gov.nasa.arc.geocam.talk.service.SiteAuthCookie.java
gov.nasa.arc.geocam.talk.service.TalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.TalkMapOverlay.java
gov.nasa.arc.geocam.talk.service.TalkServer.java