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

Java tutorial

Introduction

Here is the source code for com.dwg.weibo.entity.Geo.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.text.TextUtils;

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

/**
 * ??
 * 
 * @author SINA
 * @since 2013-11-24
 */
public class Geo implements Parcelable {

    /** ??? */
    public String longitude;
    /** ?? */
    public String latitude;
    /** ? */
    public String city;
    /** ??? */
    public String province;
    /** ?? */
    public String city_name;
    /** ???? */
    public String province_name;
    /** ?? */
    public String address;
    /** ?? */
    public String pinyin;
    /** ?? */
    public String more;

    public static Geo parse(String jsonString) {
        if (TextUtils.isEmpty(jsonString)) {
            return null;
        }

        Geo geo = null;
        try {
            JSONObject jsonObject = new JSONObject(jsonString);
            geo = parse(jsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return geo;
    }

    public static Geo parse(JSONObject jsonObject) {
        if (null == jsonObject) {
            return null;
        }

        Geo geo = new Geo();
        geo.longitude = jsonObject.optString("longitude");
        geo.latitude = jsonObject.optString("latitude");
        geo.city = jsonObject.optString("city");
        geo.province = jsonObject.optString("province");
        geo.city_name = jsonObject.optString("city_name");
        geo.province_name = jsonObject.optString("province_name");
        geo.address = jsonObject.optString("address");
        geo.pinyin = jsonObject.optString("pinyin");
        geo.more = jsonObject.optString("more");

        return geo;
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.longitude);
        dest.writeString(this.latitude);
        dest.writeString(this.city);
        dest.writeString(this.province);
        dest.writeString(this.city_name);
        dest.writeString(this.province_name);
        dest.writeString(this.address);
        dest.writeString(this.pinyin);
        dest.writeString(this.more);
    }

    public Geo() {
    }

    protected Geo(Parcel in) {
        this.longitude = in.readString();
        this.latitude = in.readString();
        this.city = in.readString();
        this.province = in.readString();
        this.city_name = in.readString();
        this.province_name = in.readString();
        this.address = in.readString();
        this.pinyin = in.readString();
        this.more = in.readString();
    }

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

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