com.dwg.weibo.entity.Status.java Source code

Java tutorial

Introduction

Here is the source code for com.dwg.weibo.entity.Status.java

Source

/*
 * Copyright (C) 2010-2013 The SINA WEIBO Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dwg.weibo.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.util.ArrayMap;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

/**
 * ?
 *
 * @author SINA
 * @since 2013-11-22
 */
public class Status implements Parcelable {

    /**
     * ?
     */
    public String created_at;
    /**
     * ?ID
     */
    public String id;
    /**
     * ?MID
     */
    public String mid;
    /**
     * ?ID
     */
    public String idstr;
    /**
     * ?
     */
    public int textLength;
    /**
     * ??
     */
    public String text;
    /**
     * ?140?
     */
    public boolean isLongText;
    /**
     * ???
     */
    public int source_type;
    /**
     * ???
     */
    public String source;
    /**
     * ??truefalse?
     */
    public boolean favorited;
    /**
     * ?truefalse?
     */
    public boolean truncated;
    /**
     * ??ID
     */
    public String in_reply_to_status_id;
    /**
     * ??UID
     */
    public String in_reply_to_user_id;
    /**
     * ??
     */
    public String in_reply_to_screen_name;
    /**
     * ???
     */
    public String thumbnail_pic;
    /**
     * ??
     */
    public String bmiddle_pic;
    /**
     * ??
     */
    public String original_pic;
    /**
     * ??
     */
    public Geo geo;
    /**
     * ??
     */
    public User user;
    /**
     * ??????
     */
    public Status retweeted_status;
    /**
     * ?
     */
    public int reposts_count;
    /**
     * 
     */
    public int comments_count;
    /**
     * ?
     */
    public int attitudes_count;
    /**
     * ?
     */
    public int mlevel;
    /**
     * ??????? object  type ?
     * 0?1??3?4??
     * list_id?
     */
    public Visible visible;
    /**
     * ??????
     */
    public int source_allowclick;

    /**
     * ?
     */
    public ArrayList<PicUrlsBean> pic_urls;

    /**
     * url???gson???
     */

    public ArrayList<String> thumbnail_pic_urls = new ArrayList<>();

    /**
     * ?url???gson???
     */
    public ArrayList<String> bmiddle_pic_urls = new ArrayList<>();

    /**
     * url???gson???
     */
    public ArrayList<String> origin_pic_urls = new ArrayList<>();

    /**
     * ?????gson???
     */
    public String singleImgSizeType;

    public static class PicUrlsBean implements Parcelable {
        public String thumbnail_pic;

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.thumbnail_pic);
        }

        public PicUrlsBean() {
        }

        protected PicUrlsBean(Parcel in) {
            this.thumbnail_pic = in.readString();
        }

        public static final Creator<PicUrlsBean> CREATOR = new Creator<PicUrlsBean>() {
            @Override
            public PicUrlsBean createFromParcel(Parcel source) {
                return new PicUrlsBean(source);
            }

            @Override
            public PicUrlsBean[] newArray(int size) {
                return new PicUrlsBean[size];
            }
        };
    }

    //    public static Status parse(String jsonString) {
    //        try {
    //            JSONObject jsonObject = new JSONObject(jsonString);
    //            return Status.parse(jsonObject);
    //        } catch (JSONException e) {
    //            e.printStackTrace();
    //        }
    //
    //        return null;
    //    }

    //    public static Status parse(JSONObject jsonObject) {
    //        if (null == jsonObject) {
    //            return null;
    //        }
    //
    //        Status status = new Status();
    //        status.created_at = jsonObject.optString("created_at");
    //        status.id = jsonObject.optString("id");
    //        status.mid = jsonObject.optString("mid");
    //        status.idstr = jsonObject.optString("idstr");
    //        status.text = jsonObject.optString("text");
    //
    //        status.source = getSource(jsonObject.optString("source"));
    //
    //        status.favorited = jsonObject.optBoolean("favorited", false);
    //        status.truncated = jsonObject.optBoolean("truncated", false);
    //
    //        // Have NOT supported
    //        status.in_reply_to_status_id = jsonObject.optString("in_reply_to_status_id");
    //        status.in_reply_to_user_id = jsonObject.optString("in_reply_to_user_id");
    //        status.in_reply_to_screen_name = jsonObject.optString("in_reply_to_screen_name");
    //
    //        status.thumbnail_pic = jsonObject.optString("thumbnail_pic");
    //        status.bmiddle_pic = jsonObject.optString("bmiddle_pic");
    //        status.original_pic = jsonObject.optString("original_pic");
    //        status.geo = Geo.parse(jsonObject.optJSONObject("geo"));
    //        status.user = User.parse(jsonObject.optJSONObject("user"));
    //        status.retweeted_status = Status.parse(jsonObject.optJSONObject("retweeted_status"));
    //        status.reposts_count = jsonObject.optInt("reposts_count");
    //        status.comments_count = jsonObject.optInt("comments_count");
    //        status.attitudes_count = jsonObject.optInt("attitudes_count");
    //        status.mlevel = jsonObject.optInt("mlevel", -1);    // Have NOT supported
    //        status.visible = Visible.parse(jsonObject.optJSONObject("visible"));
    //
    //
    //        JSONArray picUrlsArray = jsonObject.optJSONArray("pic_urls");
    //        if (picUrlsArray != null && picUrlsArray.length() > 0) {
    //            int length = picUrlsArray.length();
    //            status.thumbnail_pic_urls = new ArrayList<String>(length);
    //            status.bmiddle_pic_urls = new ArrayList<String>(length);
    //            status.origin_pic_urls = new ArrayList<String>(length);
    //            JSONObject tmpObject = null;
    //            String thumbnailUrl;
    //            for (int ix = 0; ix < length; ix++) {
    //                tmpObject = picUrlsArray.optJSONObject(ix);
    //                if (tmpObject != null) {
    //                    thumbnailUrl = tmpObject.optString("thumbnail_pic");
    //                    status.thumbnail_pic_urls.add(thumbnailUrl);
    //                    status.bmiddle_pic_urls.add(thumbnailUrl.replace("thumbnail", "bmiddle"));
    //                    LogUtil.d("wenming", thumbnailUrl.replace("thumbnail", "bmiddle"));
    //                    status.origin_pic_urls.add(thumbnailUrl.replace("thumbnail", "large"));
    //                }
    //            }
    //        }
    //
    //        if (status.thumbnail_pic_urls != null && status.thumbnail_pic_urls.size() == 1) {
    //            Random random = new Random();
    //            status.singleImgSizeType = random.nextInt(3);
    //        }
    //
    //        return status;
    //    }

    //    private static String getOriginUrl(String thumbnail_url) {
    //        StringBuffer buffer = new StringBuffer(thumbnail_url);
    //        buffer.replace(22, 31, "bmiddle");
    //        // Log.d("wenming", buffer.toString());
    //        return buffer.toString();
    //    }
    public Status() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.created_at);
        dest.writeString(this.id);
        dest.writeString(this.mid);
        dest.writeString(this.idstr);
        dest.writeInt(this.textLength);
        dest.writeString(this.text);
        dest.writeByte(this.isLongText ? (byte) 1 : (byte) 0);
        dest.writeInt(this.source_type);
        dest.writeString(this.source);
        dest.writeByte(this.favorited ? (byte) 1 : (byte) 0);
        dest.writeByte(this.truncated ? (byte) 1 : (byte) 0);
        dest.writeString(this.in_reply_to_status_id);
        dest.writeString(this.in_reply_to_user_id);
        dest.writeString(this.in_reply_to_screen_name);
        dest.writeString(this.thumbnail_pic);
        dest.writeString(this.bmiddle_pic);
        dest.writeString(this.original_pic);
        dest.writeParcelable(this.geo, flags);
        dest.writeParcelable(this.user, flags);
        dest.writeParcelable(this.retweeted_status, flags);
        dest.writeInt(this.reposts_count);
        dest.writeInt(this.comments_count);
        dest.writeInt(this.attitudes_count);
        dest.writeInt(this.mlevel);
        dest.writeParcelable(this.visible, flags);
        dest.writeInt(this.source_allowclick);
        dest.writeList(this.pic_urls);
        dest.writeStringList(this.thumbnail_pic_urls);
        dest.writeStringList(this.bmiddle_pic_urls);
        dest.writeStringList(this.origin_pic_urls);
        dest.writeString(this.singleImgSizeType);
    }

    protected Status(Parcel in) {
        this.created_at = in.readString();
        this.id = in.readString();
        this.mid = in.readString();
        this.idstr = in.readString();
        this.textLength = in.readInt();
        this.text = in.readString();
        this.isLongText = in.readByte() != 0;
        this.source_type = in.readInt();
        this.source = in.readString();
        this.favorited = in.readByte() != 0;
        this.truncated = in.readByte() != 0;
        this.in_reply_to_status_id = in.readString();
        this.in_reply_to_user_id = in.readString();
        this.in_reply_to_screen_name = in.readString();
        this.thumbnail_pic = in.readString();
        this.bmiddle_pic = in.readString();
        this.original_pic = in.readString();
        this.geo = in.readParcelable(Geo.class.getClassLoader());
        this.user = in.readParcelable(User.class.getClassLoader());
        this.retweeted_status = in.readParcelable(Status.class.getClassLoader());
        this.reposts_count = in.readInt();
        this.comments_count = in.readInt();
        this.attitudes_count = in.readInt();
        this.mlevel = in.readInt();
        this.visible = in.readParcelable(Visible.class.getClassLoader());
        this.source_allowclick = in.readInt();
        this.pic_urls = new ArrayList<PicUrlsBean>();
        in.readList(this.pic_urls, PicUrlsBean.class.getClassLoader());
        this.thumbnail_pic_urls = in.createStringArrayList();
        this.bmiddle_pic_urls = in.createStringArrayList();
        this.origin_pic_urls = in.createStringArrayList();
        this.singleImgSizeType = in.readString();
    }

    public static final Creator<Status> CREATOR = new Creator<Status>() {
        @Override
        public Status createFromParcel(Parcel source) {
            return new Status(source);
        }

        @Override
        public Status[] newArray(int size) {
            return new Status[size];
        }
    };
}