Android Open Source - Android-VKontakte-SDK Attachment






From Project

Back to project page Android-VKontakte-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-VKontakte-SDK 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.perm.kate.api;
/*from  ww w. j ava2 s. co m*/
import java.io.Serializable;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Attachment implements Serializable {
    private static final long serialVersionUID = 1L;
    public long id;//used only for wall post attached to message
    public String type; //photo,posted_photo,video,audio,link,note,app,poll,doc,geo,message,page,album
    public Photo photo; 
    //public Photo posted_photo; 
    public Video video; 
    public Audio audio; 
    public Link link; 
    public Note note; 
    public Graffiti graffiti;
    public VkApp app; 
    public VkPoll poll;
    public Geo geo;
    public Document document;
    public Message message;
    public WallMessage wallMessage;
    public Page page;
    public Gift gift;
    public Album album;

    public static ArrayList<Attachment> parseAttachments(JSONArray attachments, long from_id, long copy_owner_id, JSONObject geo_json) throws JSONException {
        ArrayList<Attachment> attachments_arr=new ArrayList<Attachment>();
        if(attachments!=null){
            int size=attachments.length();
            for(int j=0;j<size;++j){
                Object att=attachments.get(j);
                if(att instanceof JSONObject==false)
                    continue;
                JSONObject json_attachment=(JSONObject)att;
                Attachment attachment=new Attachment();
                attachment.type=json_attachment.getString("type");
                if(attachment.type.equals("photo") || attachment.type.equals("posted_photo")){
                    JSONObject x=json_attachment.optJSONObject("photo");
                    if(x!=null)
                        attachment.photo=Photo.parse(x);
                }
                else if(attachment.type.equals("graffiti"))
                    attachment.graffiti=Graffiti.parse(json_attachment.getJSONObject("graffiti"));
                else if(attachment.type.equals("link"))
                    attachment.link=Link.parse(json_attachment.getJSONObject("link"));
                else if(attachment.type.equals("audio"))
                    attachment.audio=Audio.parse(json_attachment.getJSONObject("audio"));
                else if(attachment.type.equals("note"))
                    attachment.note=Note.parse(json_attachment.getJSONObject("note"));
                else if(attachment.type.equals("video"))
                    attachment.video=Video.parseForAttachments(json_attachment.getJSONObject("video"));
                else if(attachment.type.equals("poll")){
                    attachment.poll=VkPoll.parse(json_attachment.getJSONObject("poll"));
                    if(attachment.poll.owner_id==0){
                        //???? ????????? ?????? ??? ????? copy_owner_id ?????? ??? ??? ????????? 
                        //if(copy_owner_id!=0)
                        //    attachment.poll.owner_id=copy_owner_id;
                        //else
                        attachment.poll.owner_id=from_id;
                    }
                }
                else if(attachment.type.equals("doc"))
                    attachment.document=Document.parse(json_attachment.getJSONObject("doc"));
                else if(attachment.type.equals("wall"))
                    attachment.wallMessage=WallMessage.parse(json_attachment.getJSONObject("wall"));
                else if(attachment.type.equals("page"))
                    attachment.page=Page.parseFromAttachment(json_attachment.getJSONObject("page"));
                else if(attachment.type.equals("gift"))
                    attachment.gift=Gift.parse(json_attachment.getJSONObject("gift"));
                else if(attachment.type.equals("album"))
                    attachment.album=Album.parseFromAttachment(json_attachment.getJSONObject("album"));
                attachments_arr.add(attachment);
            }
        }
        
        //Geo ???? ?????????? ? attacmnets ????? ?? ?????
        if(geo_json!=null){
            Attachment a=new Attachment();
            a.type="geo";
            a.geo=Geo.parse(geo_json);
            attachments_arr.add(a);
        }
        return attachments_arr;
    }
}




Java Source Code List

com.perm.kate.api.Album.java
com.perm.kate.api.Api.java
com.perm.kate.api.Attachment.java
com.perm.kate.api.AudioAlbum.java
com.perm.kate.api.Audio.java
com.perm.kate.api.Auth.java
com.perm.kate.api.BanInfo.java
com.perm.kate.api.BannArg.java
com.perm.kate.api.City.java
com.perm.kate.api.CommentList.java
com.perm.kate.api.Comment.java
com.perm.kate.api.Constants.java
com.perm.kate.api.Contact.java
com.perm.kate.api.Counters.java
com.perm.kate.api.Country.java
com.perm.kate.api.Document.java
com.perm.kate.api.FriendsList.java
com.perm.kate.api.Geo.java
com.perm.kate.api.Gift.java
com.perm.kate.api.Graffiti.java
com.perm.kate.api.GroupBanItem.java
com.perm.kate.api.GroupTopic.java
com.perm.kate.api.Group.java
com.perm.kate.api.IdsPair.java
com.perm.kate.api.KException.java
com.perm.kate.api.LastActivity.java
com.perm.kate.api.Link.java
com.perm.kate.api.Media.java
com.perm.kate.api.Message.java
com.perm.kate.api.NameCases.java
com.perm.kate.api.NewsItem.java
com.perm.kate.api.NewsJTags.java
com.perm.kate.api.NewsTypes.java
com.perm.kate.api.Newsfeed.java
com.perm.kate.api.Note.java
com.perm.kate.api.Notification.java
com.perm.kate.api.Notifications.java
com.perm.kate.api.Page.java
com.perm.kate.api.Params.java
com.perm.kate.api.PhotoComment.java
com.perm.kate.api.PhotoTag.java
com.perm.kate.api.Photo.java
com.perm.kate.api.Place.java
com.perm.kate.api.Reply.java
com.perm.kate.api.SearchDialogItem.java
com.perm.kate.api.User.java
com.perm.kate.api.Video.java
com.perm.kate.api.VkApp.java
com.perm.kate.api.VkPollAnswer.java
com.perm.kate.api.VkPoll.java
com.perm.kate.api.VkStatus.java
com.perm.kate.api.WallMessage.java
com.perm.kate.api.sample.Account.java
com.perm.kate.api.sample.Constants.java
com.perm.kate.api.sample.LoginActivity.java
com.perm.kate.api.sample.MainActivity.java
com.perm.utils.Utils.java
com.perm.utils.WrongResponseCodeException.java