GeocoderParams.java revision 34901409a404c8c66914c5a8ad0f29b1bcde0e78
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.location;
18
19import android.content.Context;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Locale;
24
25/**
26 * This class contains extra parameters to pass to an IGeocodeProvider
27 * implementation from the Geocoder class.  Currently this contains the
28 * language, country and variant information from the Geocoder's locale
29 * as well as the Geocoder client's package name for geocoder server
30 * logging.  This information is kept in a separate class to allow for
31 * future expansion of the IGeocodeProvider interface.
32 */
33public class GeocoderParams implements Parcelable {
34    private Locale mLocale;
35    private String mPackageName;
36
37    // used only for parcelling
38    private GeocoderParams() {
39    }
40
41    /**
42     * This object is only constructed by the Geocoder class
43     *
44     * @hide
45     */
46    public GeocoderParams(Context context, Locale locale) {
47        mLocale = locale;
48        mPackageName = context.getPackageName();
49    }
50
51    /**
52     * returns the Geocoder's locale
53     */
54    public Locale getLocale() {
55        return mLocale;
56    }
57
58    /**
59     * returns the package name of the Geocoder's client
60     */
61    public String getClientPackage() {
62        return mPackageName;
63    }
64
65    public static final Parcelable.Creator<GeocoderParams> CREATOR =
66        new Parcelable.Creator<GeocoderParams>() {
67        public GeocoderParams createFromParcel(Parcel in) {
68            GeocoderParams gp = new GeocoderParams();
69            String language = in.readString();
70            String country = in.readString();
71            String variant = in.readString();
72            gp.mLocale = new Locale(language, country, variant);
73            gp.mPackageName = in.readString();
74            return gp;
75        }
76
77        public GeocoderParams[] newArray(int size) {
78            return new GeocoderParams[size];
79        }
80    };
81
82    public int describeContents() {
83        return 0;
84    }
85
86    public void writeToParcel(Parcel parcel, int flags) {
87        parcel.writeString(mLocale.getLanguage());
88        parcel.writeString(mLocale.getCountry());
89        parcel.writeString(mLocale.getVariant());
90        parcel.writeString(mPackageName);
91    }
92}
93