Android Open Source - ExampleApp Message Obj






From Project

Back to project page ExampleApp.

License

The source code is released under:

Copyright (c) 2014, Altinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redis...

If you think the Android project ExampleApp 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 com.altinn.apps.fisher.net.jsobj;
/**/* www .  jav a 2  s.com*/
 * A JSONObject  for "messages" 
 * Created into Java Object 'MessageObj' to use their fields directly
 */

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MessageObj implements JsonObj {
  
  
  public String mMessageLink;
  public String mSubject;
  public String mStatus;
  public String mLastChangedDateTime;
  public String mLastChangedBy;
  public String mServiceOwner;
  public String mServiceCode;
  public int mServiceEdition;
  public String mSummary;
  public String mBody;
  public String mType;
  public String mMessageSender;
  private LinkObj mLink;
  public ArrayList<AttachmentObj> mAttachmentList;
  public ArrayList<FormObj> mFormList;  
  
  public MessageObj(){
    mFormList = new ArrayList<FormObj>();
    mAttachmentList = new ArrayList<AttachmentObj>();
  }
  
  /*
   * (non-Javadoc)
   * @see com.altinn.apps.fisher.net.jsobj.JsonObj#parse(org.json.JSONObject)
   */
  public MessageObj parse(JSONObject jsObj){
    MessageObj obj = new MessageObj();
    try{
      if(jsObj.has("MessageLink"))
        obj.mMessageLink = jsObj.getString("MessageLink");
      if(jsObj.has("Subject"))
        obj.mSubject = jsObj.getString("Subject");
      if(jsObj.has("Status"))
        obj.mStatus = jsObj.getString("Status");
      if(jsObj.has("LastChangedDateTime"))
        obj.mLastChangedDateTime = jsObj.getString("LastChangedDateTime");
      if(jsObj.has("LastChangedBy"))
        obj.mLastChangedBy = jsObj.getString("LastChangedBy");
      if(jsObj.has("ServiceOwner"))
        obj.mServiceOwner = jsObj.getString("ServiceOwner");
      if(jsObj.has("ServiceCode"))
        obj.mServiceCode = jsObj.getString("ServiceCode");
      if(jsObj.has("ServiceEdition"))
        obj.mServiceEdition = jsObj.getInt("ServiceEdition");
      if(jsObj.has("Summary"))
        obj.mSummary = jsObj.getString("Summary");
      if(jsObj.has("Body"))
        obj.mBody = jsObj.getString("Body");
      if(jsObj.has("Type"))
        obj.mType = jsObj.getString("Type");
      if(jsObj.has("MessageSender"))
        obj.mMessageSender = jsObj.getString("MessageSender");
      if(jsObj.has("_links")){
        JSONObject jsLinkObj = jsObj.getJSONObject("_links");
        LinkObj linkObj = new LinkObj();
        linkObj = linkObj.parse(jsLinkObj);
        if(linkObj != null)
          obj.mLink = linkObj;
      }
      if(jsObj.has("Attachments")){        
        JSONArray jsAttachmentArray = jsObj.getJSONArray("Attachments");
        for(int i = 0 ; i <jsAttachmentArray.length();i++){
          JSONObject jsAttachment = jsAttachmentArray.getJSONObject(i);
          if(jsAttachment != null){
            AttachmentObj attachmentObj = new AttachmentObj();
            attachmentObj = attachmentObj.parse(jsAttachment);
            if(attachmentObj != null){
              obj.mAttachmentList.add(attachmentObj);
            }
          }          
        }        
      }
      if(jsObj.has("_embedded")){//Added on 5/5/2014
        JSONObject jsEmbObj =  (JSONObject)jsObj.get("_embedded");//Added on 5/5/2014
        if(jsEmbObj.has("Forms")){//edited  on 5/5/2014    jsObj.has("Forms")  
          JSONArray jsFormArray = jsEmbObj.getJSONArray("Forms");//edited  on 5/5/2014    jsObj.getJSONArray("Forms")  
          for(int i = 0 ; i <jsFormArray.length();i++){
            JSONObject jsForm = jsFormArray.getJSONObject(i);
            if(jsForm != null){
              FormObj formObj = new FormObj();
              formObj = formObj.parse(jsForm);
              if(formObj != null){
                obj.mFormList.add(formObj);
              }
            }          
          }        
        }
      }
      
    }catch(JSONException jse){
      obj = null;
    }catch(Exception e){
      obj = null;
    }
    return obj;
  }
  
  /**
   * its a warper function for, which will support String type input.
   */
  public MessageObj parse(String jsStrings) throws JSONException {
    JSONObject jsObj = new JSONObject(jsStrings);
    return parse(jsObj);
  }
  
  /*
   * (non-Javadoc)
   * @see com.altinn.apps.fisher.net.jsobj.JsonObj#createJson()
   */
  public JSONObject createJson(){    
    JSONObject  jsObj = null;
    try {
      jsObj = new JSONObject();
      if(mMessageLink != null)
        jsObj.put("MessageLink", mMessageLink);
      if(mSubject != null)
        jsObj.put("Subject", mSubject);
      if(mStatus != null)
        jsObj.put("Status", mStatus);
      if(mLastChangedDateTime != null)
        jsObj.put("LastChangedDateTime", mLastChangedDateTime);
      if(mServiceOwner != null)
        jsObj.put("ServiceOwner", mServiceOwner);
      if(mServiceCode != null)
        jsObj.put("ServiceCode", mServiceCode);
      if(mServiceEdition != 0)
        jsObj.put("ServiceEdition", mServiceEdition);
      if(mSummary != null)
        jsObj.put("Summary", mSummary);
      if(mBody != null)
        jsObj.put("Body", mBody);
      if(mType != null)
        jsObj.put("Type", mType);
      if(mMessageSender != null)
        jsObj.put("MessageSender", mMessageSender);
      if(mLastChangedBy != null)
        jsObj.put("LastChangedBy", mLastChangedBy);
      if(mLink != null && mLink.mLinkList != null && mLink.mLinkList.size()>0){
        JSONObject jsLinkObj = new JSONObject();
        for(int i = 0 ; i <mLink.mLinkList.size();i++ ){
          LinkItemObj lItemObj = mLink.mLinkList.get(i);
          String itemType = null;
          if(lItemObj.mLinkType == LinkItemObj.LINK_TYPE_SELF){
            itemType = "self";
          }else if(lItemObj.mLinkType == LinkItemObj.LINK_TYPE_PRINT){
            itemType = "print";
          }else if(lItemObj.mLinkType == LinkItemObj.LINK_TYPE_ATTACHMENT){
            itemType = "attachment";
          }else if(lItemObj.mLinkType == LinkItemObj.LINK_TYPE_MESSAGE){
            itemType = "message";
          }          
          if(itemType != null){
            JSONObject jsLinkItemObj = lItemObj.createJson();
            if(jsLinkItemObj != null){
              jsLinkObj.put(itemType, jsLinkItemObj);
            }
          }
        }        
        jsObj.put("_links", jsLinkObj);
      }
      if(mAttachmentList != null && mAttachmentList.size()>0){//Edited on 5/5/2014 : AND condition added
        JSONArray jsAttachmentArray = new JSONArray();
        for(int i = 0 ; i <mAttachmentList.size();i++ ){
          AttachmentObj attachmentObj = mAttachmentList.get(i);        
          JSONObject jsAttachmentObj = attachmentObj.createJson();
          if(jsAttachmentObj != null){
            jsAttachmentArray.put(jsAttachmentObj);
          }
        }
        jsObj.put("Attachments", jsAttachmentArray);
      }
      
      JSONArray jsFormArray = null;
      if(mFormList != null && mFormList.size()>0){
        jsFormArray = new JSONArray();
        for(int i = 0 ; i <mFormList.size();i++ ){
          FormObj formObj = mFormList.get(i);        
          JSONObject jsFormObj = formObj.createJson();
          if(jsFormObj != null){
            jsFormArray.put(jsFormObj);
          }
        }
        JSONObject jsEmbedded = new JSONObject();//Added on 5/5/2014
        jsObj.put("_embedded", jsEmbedded);//Added on 5/5/2014
        jsEmbedded.put("Forms", jsFormArray);//Added on 5/5/2014        
        //jsObj.put("Forms", jsFormArray);//commented on 5/5/2014
      }
      
    } catch (JSONException e) {
      jsObj = null;
      e.printStackTrace();
    }
    
    return jsObj;
  }

}




Java Source Code List

com.altinn.apps.fisher.AppContext.java
com.altinn.apps.fisher.CacheManager.java
com.altinn.apps.fisher.common.AppConstants.java
com.altinn.apps.fisher.common.IStatusMessage.java
com.altinn.apps.fisher.common.MenuItem.java
com.altinn.apps.fisher.common.StatusMessage.java
com.altinn.apps.fisher.db.DataBaseHelper.java
com.altinn.apps.fisher.db.FactoryDBHelper.java
com.altinn.apps.fisher.db.FishCategoryDBHelper.java
com.altinn.apps.fisher.db.FormDBHelper.java
com.altinn.apps.fisher.db.IDBHelper.java
com.altinn.apps.fisher.db.RegsDBHelper.java
com.altinn.apps.fisher.db.VesselDBHelper.java
com.altinn.apps.fisher.gps.CLocationProvider.java
com.altinn.apps.fisher.gps.ILocationUpdateListner.java
com.altinn.apps.fisher.models.CaughtInfoData.java
com.altinn.apps.fisher.models.InfoData.java
com.altinn.apps.fisher.models.ReportInfoData.java
com.altinn.apps.fisher.models.UserProfile.java
com.altinn.apps.fisher.net.AbstractWorkerTask.java
com.altinn.apps.fisher.net.CookieHelper.java
com.altinn.apps.fisher.net.IParser.java
com.altinn.apps.fisher.net.JSParser.java
com.altinn.apps.fisher.net.ParseManager.java
com.altinn.apps.fisher.net.TaskNotifier.java
com.altinn.apps.fisher.net.jsobj.AttachmentObj.java
com.altinn.apps.fisher.net.jsobj.FormObj.java
com.altinn.apps.fisher.net.jsobj.JSConstants.java
com.altinn.apps.fisher.net.jsobj.JsonObj.java
com.altinn.apps.fisher.net.jsobj.LinkItemObj.java
com.altinn.apps.fisher.net.jsobj.LinkObj.java
com.altinn.apps.fisher.net.jsobj.MessageObj.java
com.altinn.apps.fisher.net.jsobj.MessagesEmbedded.java
com.altinn.apps.fisher.net.jsobj.OrganisationObj.java
com.altinn.apps.fisher.net.tasks.LoginTask.java
com.altinn.apps.fisher.net.tasks.RefreshTokenTask.java
com.altinn.apps.fisher.net.tasks.SendReportTask.java
com.altinn.apps.fisher.net.tasks.UserProfileTask.java
com.altinn.apps.fisher.settings.FactoryDetails.java
com.altinn.apps.fisher.settings.FishDetails.java
com.altinn.apps.fisher.settings.SettingItem.java
com.altinn.apps.fisher.settings.VesselsDetails.java
com.altinn.apps.fisher.ui.component.DurationTimePickDialog.java
com.altinn.apps.fisher.ui.component.RAutoCompleteTextView.java
com.altinn.apps.fisher.ui.component.RButton.java
com.altinn.apps.fisher.ui.component.REditText.java
com.altinn.apps.fisher.ui.component.RTextView.java
com.altinn.apps.fisher.ui.screen.BaseActivity.java
com.altinn.apps.fisher.ui.screen.BrowserActivity.java
com.altinn.apps.fisher.ui.screen.FactoryDetailsActivity.java
com.altinn.apps.fisher.ui.screen.HomeActivity.java
com.altinn.apps.fisher.ui.screen.InformationActivity.java
com.altinn.apps.fisher.ui.screen.MenuNavigationActivity.java
com.altinn.apps.fisher.ui.screen.ReportActivity.java
com.altinn.apps.fisher.ui.screen.ReportReceivedFishActivity.java
com.altinn.apps.fisher.ui.screen.ReportSendDetailActivity.java
com.altinn.apps.fisher.ui.screen.SplashActivity.java
com.altinn.apps.fisher.ui.screen.UserProfileActivity.java
com.altinn.apps.fisher.utils.PreferenceUtils.java
com.altinn.apps.fisher.utils.Utils.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java