Android Open Source - geocamMemoForAndroid Django Memo Implementation






From Project

Back to project page geocamMemoForAndroid.

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 geocamMemoForAndroid 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

package gov.nasa.arc.geocam.memo.service;
//w  ww  . ja  va2  s  .  c  om

import gov.nasa.arc.geocam.memo.R;
import gov.nasa.arc.geocam.memo.bean.GeoCamMemoMessage;
import gov.nasa.arc.geocam.memo.exception.AuthenticationFailedException;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.apache.http.client.ClientProtocolException;

import roboguice.inject.InjectResource;
import android.content.Context;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
 * Implementation of the {@link DjangoMemoInterface} meant to interface with the Django server.
 */
public class DjangoMemoImplementation implements DjangoMemoInterface{

  /** The json converter. */
  @Inject DjangoMemoJsonConverterInterface jsonConverter;
  
  /** The server root url. */
  @InjectResource(R.string.url_server_root) String serverRootUrl;
  
  /** The path for the application server. */
  @InjectResource(R.string.url_relative_app) String appPath;
  
  /** The path for the Memo homepage. */
  @InjectResource(R.string.url_message_list) String memoMessagesJson;
  
  /** The path for the create memo page. */
  @InjectResource(R.string.url_create_message) String createMemoMessageJson;
  
  /** The context provider. */
  @Inject protected static Provider<Context> contextProvider;
  
  /** The site auth implementation. */
  @Inject SiteAuthInterface siteAuthImplementation;
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.memo.service.DjangoMemoInterface#getMemos()
   */
  @Override
  public List<GeoCamMemoMessage> getMemos() throws ClientProtocolException, AuthenticationFailedException, IOException {
    //String jsonString = 
    //  "[{\"authorUsername\": \"rhornsby\", \"longitude\": -122.057954, \"content\": \"Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.\", \"contentTimestamp\": \"03/13/11 10:48:44\", \"latitude\": 37.411629, \"messageId\": 15, \"accuracy\":60.0}]";
    String jsonString = null;
    
    jsonString = siteAuthImplementation.get(memoMessagesJson, null);
        
    return jsonConverter.deserializeList(jsonString);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.memo.service.DjangoMemoInterface#setAuth(java.lang.String, java.lang.String)
   */
  @Override
  public void setAuth(String username, String password) {
    siteAuthImplementation.setAuth(username, password);    
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.memo.service.DjangoMemoInterface#createMemo(gov.nasa.arc.geocam.memo.bean.GeoCamMemoMessage)
   */
  @Override
  public void createMemo(GeoCamMemoMessage message) throws ClientProtocolException, AuthenticationFailedException, IOException {
    HashMap<String,String>map = new HashMap<String,String>();
    map.put("message", jsonConverter.serialize(message));
    int responseCode = siteAuthImplementation.post(createMemoMessageJson, map);
    if(responseCode != 200)
    {
      throw new ClientProtocolException("Message could not be created (HTTP error "+responseCode+")");
    }
  }
}




Java Source Code List

gov.nasa.arc.geocam.memo.GeoCamMemoModule.java
gov.nasa.arc.geocam.memo.GeoCamMemoRoboApplication.java
gov.nasa.arc.geocam.memo.UIUtils.java
gov.nasa.arc.geocam.memo.activity.GeoCamMemoCreateActivity.java
gov.nasa.arc.geocam.memo.activity.GeoCamMemoHomeActivity.java
gov.nasa.arc.geocam.memo.activity.GeoCamMemoMapActivity.java
gov.nasa.arc.geocam.memo.activity.GeoCamMemoMessageArrayAdapter.java
gov.nasa.arc.geocam.memo.activity.GeoCamMemoSettings.java
gov.nasa.arc.geocam.memo.bean.GeoCamMemoMessage.java
gov.nasa.arc.geocam.memo.exception.AuthenticationFailedException.java
gov.nasa.arc.geocam.memo.service.DjangoMemoImplementation.java
gov.nasa.arc.geocam.memo.service.DjangoMemoInterface.java
gov.nasa.arc.geocam.memo.service.DjangoMemoJsonConverterImplementation.java
gov.nasa.arc.geocam.memo.service.DjangoMemoJsonConverterInterface.java
gov.nasa.arc.geocam.memo.service.GeoLocationListener.java
gov.nasa.arc.geocam.memo.service.MemoMapOverlay.java
gov.nasa.arc.geocam.memo.service.SiteAuthCookieImplementation.java
gov.nasa.arc.geocam.memo.service.SiteAuthInterface.java