Android Open Source - Team7-301Project Author Controller






From Project

Back to project page Team7-301Project.

License

The source code is released under:

Apache License

If you think the Android project Team7-301Project 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 ca.ualberta.cs.controllers;
/*  w  w  w  .  ja  va  2 s .  c om*/
import android.content.Context;
import ca.ualberta.cs.models.AuthorModel;
import ca.ualberta.cs.views.MainScreenActivity;
import ca.ualberta.cs.views.Observer;

/**
 * The users name and geographical location are controlled through this class. It parses data
 * before using the AuthorModel class to save it. It also gives access to AuthorModels 
 * notifyObservers() method.
 * @author bbruner
 * @author dlacours
 */
public class AuthorController 
{
  private AuthorModel authorModel;
  
  /**
   * Constructor.
   * @param viewsContext This is the instance of the view creating the controller. 
   * Generally, the argument will be "this". This parameter is required so that 
   * AuthorModel has access to the views update() method.
   */
  public AuthorController(Observer viewsContext)
  {
    this.authorModel = new AuthorModel();
    this.authorModel.addObserver(viewsContext);
  }
  /** this is for getting only
   * not to be used for setting 
   */
  public AuthorController(){
    this.authorModel = new AuthorModel();
  }
  /**this is for getting only 
   * not to be used for setting 
   * @return authorModel
   */
  public AuthorModel getModel(){
    return authorModel;
  }
  
  /**
   * Sets who the author is after parsing the text. The parsing checks that the 
   * provided author name is not a null pointer and that the name is not too long
   * (greater than 30 characters). The models notifiyObservers() function is called
   * if the parsing is passed, otherwise, nothing is done.
   * @param author Name of the author to be set.
   */
  public void setSessionAuthor(String author)
  {
    if( author != null && author.length() < 30)
    {
      this.authorModel.setSessionAuthor(author);
      this.authorModel.notifyObservers();
    }
  }
  
  /**
   * Directly calls the models notifyObservers() method.
   */
  public void refresh()
  {
    this.authorModel.notifyObservers();
  }
  
  /**
   * Sets the location of the author after parsing their location. The location is parsed
   * to check whether they are setting or unsetting their location and to make sure their
   * location is not greater than 30 characters.
   * @param userLoc Author location to be set. pass a null pointer to unset the authors
   * location.
   */
  public void setSessionLocation(String userLoc) {
    // TODO Auto-generated method stub
    
    if((userLoc != null) && userLoc.length() < 30)
    {
      //if it is null, then they are unsetting their location
      this.authorModel.setSessionLocation(userLoc);
    } else {

      this.authorModel.setSet(false);
      
    }
  }
  
  /**
   * Sets where the author is. This input should be from a gps. There is no restriction
   * on where the input comes from, but other applications will expect that this method
   * was called with real gps latitude.
   * @param lat Author latitude to be set.
   */
  public void setSessionLatitude(double lat) {
    this.authorModel.setSessionLatitude(lat);
  }  
  
  /**
   * Sets where the author is. This input should be from a gps. There is no restriction
   * on where the input comes from, but other applications will expect that this method
   * was called with real gps longitude.
   * @param lon Author longitude to be set.
   */
  public void setSessionLongitude(double lon) {
    this.authorModel.setSessionLongitude(lon);
  }
  
  /**
   * Set if the authors location is set :/. So basically, pass an argument of true
   * if the authors location is set. Pass an argument of false if the authors location
   * is not set.
   * @param set True if the authors location is set, false if the authors location is not set.
   */
  public void setLocationType(String word) {
    this.authorModel.setLocationType(word);
  }
  

}




Java Source Code List

ca.ualberta.cs.controllers.AuthorController.java
ca.ualberta.cs.controllers.BrowseController.java
ca.ualberta.cs.controllers.ForumEntryController.java
ca.ualberta.cs.controllers.SearchController.java
ca.ualberta.cs.f14t07_application.Hits.java
ca.ualberta.cs.f14t07_application.LogoActivity.java
ca.ualberta.cs.f14t07_application.Post.java
ca.ualberta.cs.intent_singletons.BrowseRequestSingleton.java
ca.ualberta.cs.intent_singletons.ContextSingleton.java
ca.ualberta.cs.intent_singletons.EntrySingleton.java
ca.ualberta.cs.intent_singletons.ForumEntrySingleton.java
ca.ualberta.cs.models.Answer.java
ca.ualberta.cs.models.AuthorModel.java
ca.ualberta.cs.models.DataManager.java
ca.ualberta.cs.models.Entry.java
ca.ualberta.cs.models.ForumEntryList.java
ca.ualberta.cs.models.ForumEntry.java
ca.ualberta.cs.models.JsonDriver.java
ca.ualberta.cs.models.Observable.java
ca.ualberta.cs.models.Question.java
ca.ualberta.cs.models.Reply.java
ca.ualberta.cs.remote_server.NetworkChecker.java
ca.ualberta.cs.remote_server.SearchHit.java
ca.ualberta.cs.remote_server.SearchResponse.java
ca.ualberta.cs.remote_server.SimpleSearchCommand.java
ca.ualberta.cs.views.AnswerActivity.java
ca.ualberta.cs.views.AnswerListAdapter.java
ca.ualberta.cs.views.AskActivity.java
ca.ualberta.cs.views.BrowseActivity.java
ca.ualberta.cs.views.HelpActivity.java
ca.ualberta.cs.views.MainScreenActivity.java
ca.ualberta.cs.views.Observer.java
ca.ualberta.cs.views.QuestionActivity.java
ca.ualberta.cs.views.ReplyListAdapter.java