Android Open Source - geocamTalkAndroid Intent Helper






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__
//from w  ww  . ja  v a2  s .  c om
package gov.nasa.arc.geocam.talk.service;

import gov.nasa.arc.geocam.talk.R;
import gov.nasa.arc.geocam.talk.bean.TalkServerIntent;
import roboguice.inject.InjectResource;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.google.inject.Inject;

/**
 * The Class IntentHelper.
 */
public class IntentHelper implements IIntentHelper {
  
  /** The context. */
  private Context context;

  /** The c2dm sender address. */
  @InjectResource(R.string.c2dm_sender_address) 
  String c2dmSenderAddress;
  
  /**
   * Instantiates a new intent helper.
   *
   * @param context the context
   */
  @Inject
  public IntentHelper(Context context) {
    this.context = context;
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#Synchronize()
   */
  @Override
  public void Synchronize() {
    Intent synchronizeIntent = new Intent(this.context, TalkServer.class);
    synchronizeIntent.setAction(TalkServerIntent.INTENT_SYNCHRONIZE.toString());
    context.startService(synchronizeIntent);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#BroadcastNewMessages()
   */
  @Override
  public void BroadcastNewMessages() {
    Intent newMsgIntent = new Intent(TalkServerIntent.INTENT_NEW_MESSAGES.toString());
    this.context.sendBroadcast(newMsgIntent);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#RegisterC2dm()
   */
  @Override
  public void RegisterC2dm() {
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
        registrationIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0)); 
        registrationIntent.putExtra("sender", c2dmSenderAddress);
        context.startService(registrationIntent);
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#UnregisterC2dm()
   */
  @Override
  public void UnregisterC2dm() {
    Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
    unregIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    context.startService(unregIntent);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#StoreC2dmRegistrationId(java.lang.String)
   */
  @Override
  public void StoreC2dmRegistrationId(String registrationId) {
    Intent storeRegistrationIdIntent = new Intent(this.context, TalkServer.class);
    storeRegistrationIdIntent.setAction(TalkServerIntent.INTENT_STORE_C2DM_ID.toString());
    storeRegistrationIdIntent.putExtra(
        TalkServerIntent.EXTRA_REGISTRATION_ID.toString(),
        registrationId);
    context.startService(storeRegistrationIdIntent);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#PushedMessage(java.lang.String)
   */
  @Override
  public void PushedMessage(String messageId) {
    Intent pushedMessageIntent = new Intent(this.context, TalkServer.class);
    pushedMessageIntent.setAction(TalkServerIntent.INTENT_PUSHED_MESSAGE.toString());
    pushedMessageIntent.putExtra(
        TalkServerIntent.EXTRA_MESSAGE_ID.toString(),
        messageId);
    context.startService(pushedMessageIntent);
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#Login()
   */
  @Override public void Login()
  {
    Intent loginInent = new Intent(this.context, TalkServer.class);
    loginInent.setAction(TalkServerIntent.INTENT_LOGIN.toString());
    Log.i("Talk", "Login intent broadcast");
    context.startService(loginInent);  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#LoginFailed()
   */
  @Override
  public void LoginFailed()
  {
    Intent loginFailedIntent = new Intent(TalkServerIntent.INTENT_LOGIN_FAILED.toString());
    context.sendBroadcast(loginFailedIntent);  
    Log.i("Talk", "Login failed broadcast");
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IIntentHelper#StopServices()
   */
  @Override
  public void StopServices() {
    Intent i = new Intent(this.context, TalkServer.class);
    context.stopService(i);
  }
}




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