Android Open Source - unicef_gis_mobile Report






From Project

Back to project page unicef_gis_mobile.

License

The source code is released under:

MIT License

If you think the Android project unicef_gis_mobile 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 org.unicef.gis.model;
/* w ww.  ja  v a 2s.c  o  m*/
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.ektorp.support.OpenCouchDbDocument;

import android.location.Location;
import android.net.Uri;

public class Report extends OpenCouchDbDocument {  
  public static final String TYPE = "report";
  
  public static final String TIMESTAMP_KEY = "timestamp";
  public static final String ID_KEY = "_id";
  public static final String TITLE_KEY = "title";
  public static final String LATITUDE_KEY = "latitude";
  public static final String LONGITUDE_KEY = "longitude";
  public static final String IMAGE_URI_KEY = "imageUri";
  public static final String TAGS_KEY = "tags";
  public static final String REVISION_KEY = "_rev";
  public static final String SYNCED_DATA_KEY = "syncedData";
  public static final String SYNCED_IMAGE_KEY = "syncedImage";
  public static final String TYPE_KEY = "type";
  public static final String ATTEMPTS_KEY = "attempts";
  public static final Object POST_TO_TWITTER_KEY = "postToTwitter";
  public static final Object POST_TO_FACEBOOK_KEY = "postToFacebook";
  
  private static final long serialVersionUID = 1L;
    
  private String title;
  private Double latitude;
  private Double longitude;
  private List<String> tags;
  private String imageUri;
  private String timestamp;
  private Boolean syncedData;
  private Boolean syncedImage;
  private String type;
  private Integer attempts;
  
  private Boolean postToTwitter;
  private Boolean postToFacebook;
  
  public Report(String title, Location location, Uri imageUri, List<String> tags) {    
    this(title, location.getLatitude(), location.getLongitude(), imageUri.toString(), tags);
  }
  
  public Report(String title, Double latitude, Double longitude, String imageUri, List<String> tags) {
    type = TYPE;
    
    this.title = title;
    
    this.latitude = latitude;
    this.longitude = longitude;
        
    this.tags = tags;
    this.imageUri = imageUri.toString();
    
    this.timestamp = generateTimestamp();
    
    this.setPostToTwitter(false);
    this.setPostToFacebook(false);
    
    setSyncedData(false);
    setSyncedImage(false);
    setAttempts(0);
  }

  public String getTitle() {
    return title;
  }
  
  public void setTitle(String title) {
    this.title = title;
  }
  
  public Double getLatitude() {
    return latitude;
  }
  
  public void setLatitude(Double latitude) {
    this.latitude = latitude;
  }
  
  public Double getLongitude() {
    return longitude;
  }
  
  public void setLongitude(Double longitude) {
    this.longitude = longitude;
  }
  
  public List<String> getTags() {
    return tags;
  }
  
  public void setTags(List<String> tags) {
    this.tags = tags;
  }
  
  public String getImageUri() {
    return imageUri;
  }
  
  public void setImageUri(String imageUri) {
    this.imageUri = imageUri;
  }
  
  public String getTimestamp() {
    return timestamp;
  }
  
  public void setTimestamp(String timestamp) {
    this.timestamp = timestamp;
  }
  
  private String generateTimestamp() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return dateFormat.format(new Date());    
  }
  
  @Override
    public boolean equals(Object o) {
        if(o instanceof Report) {
            Report other = (Report)o;
            if(getId() != null && other.getId() != null && getId().equals(other.getId())) {
                return true;
            }
        }
        return false;
    }

  @SuppressWarnings("unchecked")
  public static List<Report> collectionFromMap(
      List<Map<String, Object>> plainReports) {
    List<Report> reports = new ArrayList<Report>();

    for (Map<String, Object> plainReport : plainReports) {
      reports.add(fromMap((Map<String, Object>) plainReport.get("value")));
    }
    
    return reports;
  }

  @SuppressWarnings("unchecked")
  public static Report fromMap(Map<String, Object> objReport) {    
    String plainTitle = (String)objReport.get(TITLE_KEY);
    Double plainLatitude = (Double) objReport.get(LATITUDE_KEY); 
    Double plainLongitude = (Double) objReport.get(LONGITUDE_KEY);
    String imageUri = (String) objReport.get(IMAGE_URI_KEY); 
    List<String> tags = (List<String>) objReport.get(TAGS_KEY);
    String timestamp = (String) objReport.get(TIMESTAMP_KEY);
    Boolean syncedData = (Boolean) objReport.get(SYNCED_DATA_KEY);
    Boolean syncedImage = (Boolean) objReport.get(SYNCED_IMAGE_KEY);
    Integer attempts = (Integer) objReport.get(ATTEMPTS_KEY);
    Boolean postToTwitter = (Boolean) objReport.get(POST_TO_TWITTER_KEY);
    Boolean postToFacebook = (Boolean) objReport.get(POST_TO_FACEBOOK_KEY);
    
    Report report = new Report(plainTitle, plainLatitude, plainLongitude, imageUri, tags);    
    report.setId((String) objReport.get(ID_KEY));
    report.setRevision((String) objReport.get(REVISION_KEY));
    report.setTimestamp(timestamp);
    report.setSyncedData(syncedData);
    report.setSyncedImage(syncedImage);
    report.setAttempts(attempts);
    report.setPostToTwitter(postToTwitter);
    report.setPostToFacebook(postToFacebook);
    
    return report;
  }
  
  public Boolean getSyncedData() {
    return syncedData;
  }

  public void setSyncedData(Boolean syncedData) {
    this.syncedData = syncedData;
  }

  public Boolean getSyncedImage() {
    return syncedImage;
  }

  public void setSyncedImage(Boolean syncedImage) {
    this.syncedImage = syncedImage;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public Integer getAttempts() {
    return attempts;
  }

  public void setAttempts(Integer attempts) {
    this.attempts = attempts;
  }

  public String json() throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(this);
  }

  public Boolean getPostToTwitter() {
    return postToTwitter;
  }

  public void setPostToTwitter(Boolean postToTwitter) {
    this.postToTwitter = postToTwitter;
  }

  public Boolean getPostToFacebook() {
    return postToFacebook;
  }

  public void setPostToFacebook(Boolean postToFacebook) {
    this.postToFacebook = postToFacebook;
  }
}




Java Source Code List

com.couchbase.cblite.ektorp.CBLiteHttpClient.java
com.couchbase.cblite.ektorp.CBLiteHttpResponse.java
edu.mit.mobile.android.utils.StreamUtils.java
org.unicef.gis.auth.AuthenticatorService.java
org.unicef.gis.auth.Authenticator.java
org.unicef.gis.infrastructure.CompileTimeSettings.java
org.unicef.gis.infrastructure.ILocationServiceConsumer.java
org.unicef.gis.infrastructure.LocationService.java
org.unicef.gis.infrastructure.Network.java
org.unicef.gis.infrastructure.Notificator.java
org.unicef.gis.infrastructure.RoutesResolver.java
org.unicef.gis.infrastructure.ServerUrlPreferenceNotSetException.java
org.unicef.gis.infrastructure.UnicefGisApi.java
org.unicef.gis.infrastructure.data.CouchDbLiteStoreAdapter.java
org.unicef.gis.infrastructure.data.UnicefGisContentProvider.java
org.unicef.gis.infrastructure.data.UnicefGisStore.java
org.unicef.gis.infrastructure.image.AsyncDrawable.java
org.unicef.gis.infrastructure.image.BitmapWorkerTask.java
org.unicef.gis.infrastructure.image.Camera.java
org.unicef.gis.model.Report.java
org.unicef.gis.model.Tag.java
org.unicef.gis.model.couchdb.NullReduce.java
org.unicef.gis.model.couchdb.ReportLoader.java
org.unicef.gis.model.couchdb.views.AllReportsByTimestampDesc.java
org.unicef.gis.model.couchdb.views.PendingSyncReports.java
org.unicef.gis.model.couchdb.views.UnicefGisView.java
org.unicef.gis.model.couchdb.views.UploadedReports.java
org.unicef.gis.sync.SyncAdapter.java
org.unicef.gis.sync.SyncService.java
org.unicef.gis.ui.AlertDialogFragment.java
org.unicef.gis.ui.AuthenticatorActivity.java
org.unicef.gis.ui.ConfigureServerUrlActivity.java
org.unicef.gis.ui.DeleteUploadedReportsTask.java
org.unicef.gis.ui.FetchTagsActivity.java
org.unicef.gis.ui.FetchTagsTask.java
org.unicef.gis.ui.MyReportsActivity.java
org.unicef.gis.ui.SettingsActivity.java
org.unicef.gis.ui.SettingsFragment.java
org.unicef.gis.ui.report.ChooseTagsFragment.java
org.unicef.gis.ui.report.CreateReportActivityConstants.java
org.unicef.gis.ui.report.CreateReportActivity.java
org.unicef.gis.ui.report.GetTagsTaskFragment.java
org.unicef.gis.ui.report.GetTagsTask.java
org.unicef.gis.ui.report.IChooseTagsCallbacks.java
org.unicef.gis.ui.report.IGetTagsCallback.java
org.unicef.gis.ui.report.IGetTagsTaskFragmentCallbacks.java
org.unicef.gis.ui.report.IReportSummaryCallbacks.java
org.unicef.gis.ui.report.ReportRowAdapter.java
org.unicef.gis.ui.report.ReportSummaryFragment.java
org.unicef.gis.ui.report.ReportViewModel.java
org.unicef.gis.ui.report.ToggleTagAdapter.java