ContactsRequest.java revision 1ce1e7cf261994e46e6fe85ed4d445241ad55f16
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 com.android.contacts.list;
18
19import android.content.Intent;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * Parsed form of the intent sent to the Contacts application.
25 */
26public class ContactsRequest implements Parcelable {
27
28    /** Default mode: browse contacts */
29    public static final int ACTION_DEFAULT = 10;
30
31    /** Show contents of a specific group */
32    public static final int ACTION_GROUP = 20;
33
34    /** Show all starred contacts */
35    public static final int ACTION_STARRED = 30;
36
37    /** Show frequently contacted contacts */
38    public static final int ACTION_FREQUENT = 40;
39
40    /** Show starred and the frequent */
41    public static final int ACTION_STREQUENT = 50;
42
43    /** Show all contacts and pick them when clicking */
44    public static final int ACTION_PICK_CONTACT = 60;
45
46    /** Show all contacts as well as the option to create a new one */
47    public static final int ACTION_PICK_OR_CREATE_CONTACT = 70;
48
49    /** Show all contacts and pick them for edit when clicking, and allow creating a new contact */
50    public static final int ACTION_INSERT_OR_EDIT_CONTACT = 80;
51
52    /** Show all phone numbers and pick them when clicking */
53    public static final int ACTION_PICK_PHONE = 90;
54
55    /** Show all postal addresses and pick them when clicking */
56    public static final int ACTION_PICK_POSTAL = 100;
57
58    /** Show all contacts and create a shortcut for the picked contact */
59    public static final int ACTION_CREATE_SHORTCUT_CONTACT = 110;
60
61    /** Show all phone numbers and create a call shortcut for the picked number */
62    public static final int ACTION_CREATE_SHORTCUT_CALL = 120;
63
64    /** Show all phone numbers and create an SMS shortcut for the picked number */
65    public static final int ACTION_CREATE_SHORTCUT_SMS = 130;
66
67    private boolean mValid = true;
68    private int mActionCode = ACTION_DEFAULT;
69    private Intent mRedirectIntent;
70    private CharSequence mTitle;
71    private boolean mSearchMode;
72    private boolean mSearchResultsMode;
73    private String mQueryString;
74
75    public static final int DISPLAY_ONLY_WITH_PHONES_PREFERENCE = 0;
76    public static final int DISPLAY_ONLY_WITH_PHONES_ENABLED = 1;
77    public static final int DISPLAY_ONLY_WITH_PHONES_DISABLED = 2;
78
79    private int mDisplayOnlyWithPhones;
80    private boolean mDisplayOnlyVisible;
81    private String mGroupName;
82    private boolean mLegacyCompatibilityMode;
83
84    /**
85     * Copies all fields.
86     */
87    public void copyFrom(ContactsRequest request) {
88        mValid = request.mValid;
89        mActionCode = request.mActionCode;
90        mRedirectIntent = request.mRedirectIntent;
91        mTitle = request.mTitle;
92        mSearchMode = request.mSearchMode;
93        mSearchResultsMode = request.mSearchResultsMode;
94        mQueryString = request.mQueryString;
95        mDisplayOnlyWithPhones = request.mDisplayOnlyWithPhones;
96        mDisplayOnlyVisible = request.mDisplayOnlyVisible;
97        mGroupName = request.mGroupName;
98        mLegacyCompatibilityMode = request.mLegacyCompatibilityMode;
99    }
100
101    public static Parcelable.Creator<ContactsRequest> CREATOR = new Creator<ContactsRequest>() {
102
103        public ContactsRequest[] newArray(int size) {
104            return new ContactsRequest[size];
105        }
106
107        public ContactsRequest createFromParcel(Parcel source) {
108            ContactsRequest request = new ContactsRequest();
109            request.mValid = source.readInt() != 0;
110            request.mActionCode = source.readInt();
111            request.mRedirectIntent = source.readParcelable(this.getClass().getClassLoader());
112            request.mTitle = source.readCharSequence();
113            request.mSearchMode = source.readInt() != 0;
114            request.mSearchResultsMode = source.readInt() != 0;
115            request.mQueryString = source.readString();
116            request.mDisplayOnlyWithPhones = source.readInt();
117            request.mDisplayOnlyVisible = source.readInt() != 0;
118            request.mGroupName = source.readString();
119            request.mLegacyCompatibilityMode  = source.readInt() != 0;
120            return request;
121        }
122    };
123
124    public void writeToParcel(Parcel dest, int flags) {
125        dest.writeInt(mValid ? 1 : 0);
126        dest.writeInt(mActionCode);
127        dest.writeParcelable(mRedirectIntent, 0);
128        dest.writeCharSequence(mTitle);
129        dest.writeInt(mSearchMode ? 1 : 0);
130        dest.writeInt(mSearchResultsMode ? 1 : 0);
131        dest.writeString(mQueryString);
132        dest.writeInt(mDisplayOnlyWithPhones);
133        dest.writeInt(mDisplayOnlyVisible ? 1 : 0);
134        dest.writeString(mGroupName);
135        dest.writeInt(mLegacyCompatibilityMode ? 1 : 0);
136    }
137
138    public int describeContents() {
139        return 0;
140    }
141
142    public boolean isValid() {
143        return mValid;
144    }
145
146    public void setValid(boolean flag) {
147        mValid = flag;
148    }
149
150    public Intent getRedirectIntent() {
151        return mRedirectIntent;
152    }
153
154    public void setRedirectIntent(Intent intent) {
155        mRedirectIntent = intent;
156    }
157
158    public void setActivityTitle(CharSequence title) {
159        mTitle = title;
160    }
161
162    public CharSequence getActivityTitle() {
163        return mTitle;
164    }
165
166    public int getActionCode() {
167        return mActionCode;
168    }
169
170    public void setActionCode(int actionCode) {
171        mActionCode = actionCode;
172    }
173
174    public boolean getDisplayOnlyVisible() {
175        return mDisplayOnlyVisible;
176    }
177
178    public void setDisplayOnlyVisible(boolean flag) {
179        mDisplayOnlyVisible = flag;
180    }
181
182    public int getDisplayWithPhonesOnlyOption() {
183        return mDisplayOnlyWithPhones;
184    }
185
186    public void setDisplayWithPhonesOnlyOption(int option) {
187        mDisplayOnlyWithPhones = option;
188    }
189
190    public boolean isSearchMode() {
191        return mSearchMode;
192    }
193
194    public void setSearchMode(boolean flag) {
195        mSearchMode = flag;
196    }
197
198    public boolean isSearchResultsMode() {
199        return mSearchResultsMode;
200    }
201
202    public void setSearchResultsMode(boolean flag) {
203        mSearchResultsMode = flag;
204    }
205
206    public String getQueryString() {
207        return mQueryString;
208    }
209
210    public void setQueryString(String string) {
211        mQueryString = string;
212    }
213
214    public String getGroupName() {
215        return mGroupName;
216    }
217
218    public void setGroupName(String groupName) {
219        mGroupName = groupName;
220    }
221
222    public boolean isLegacyCompatibilityMode() {
223        return mLegacyCompatibilityMode;
224    }
225
226    public void setLegacyCompatibilityMode(boolean flag) {
227        mLegacyCompatibilityMode = flag;
228    }
229}
230