blob: e8ccb43b03c6197e99b28848273a7f8f9adfca2b [file] [log] [blame]
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -07001/*
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;
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -070020import android.net.Uri;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070021import android.os.Parcel;
22import android.os.Parcelable;
23
24/**
25 * Parsed form of the intent sent to the Contacts application.
26 */
27public class ContactsRequest implements Parcelable {
28
29 /** Default mode: browse contacts */
30 public static final int ACTION_DEFAULT = 10;
31
32 /** Show contents of a specific group */
33 public static final int ACTION_GROUP = 20;
34
35 /** Show all starred contacts */
36 public static final int ACTION_STARRED = 30;
37
38 /** Show frequently contacted contacts */
39 public static final int ACTION_FREQUENT = 40;
40
41 /** Show starred and the frequent */
42 public static final int ACTION_STREQUENT = 50;
43
44 /** Show all contacts and pick them when clicking */
45 public static final int ACTION_PICK_CONTACT = 60;
46
47 /** Show all contacts as well as the option to create a new one */
48 public static final int ACTION_PICK_OR_CREATE_CONTACT = 70;
49
50 /** Show all contacts and pick them for edit when clicking, and allow creating a new contact */
51 public static final int ACTION_INSERT_OR_EDIT_CONTACT = 80;
52
53 /** Show all phone numbers and pick them when clicking */
54 public static final int ACTION_PICK_PHONE = 90;
55
56 /** Show all postal addresses and pick them when clicking */
57 public static final int ACTION_PICK_POSTAL = 100;
58
59 /** Show all contacts and create a shortcut for the picked contact */
60 public static final int ACTION_CREATE_SHORTCUT_CONTACT = 110;
61
62 /** Show all phone numbers and create a call shortcut for the picked number */
63 public static final int ACTION_CREATE_SHORTCUT_CALL = 120;
64
65 /** Show all phone numbers and create an SMS shortcut for the picked number */
66 public static final int ACTION_CREATE_SHORTCUT_SMS = 130;
67
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -070068 /** Show all contacts and activate the specified one */
69 public static final int ACTION_VIEW_CONTACT = 140;
70
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070071 private boolean mValid = true;
72 private int mActionCode = ACTION_DEFAULT;
73 private Intent mRedirectIntent;
74 private CharSequence mTitle;
75 private boolean mSearchMode;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070076 private String mQueryString;
77
78 public static final int DISPLAY_ONLY_WITH_PHONES_PREFERENCE = 0;
79 public static final int DISPLAY_ONLY_WITH_PHONES_ENABLED = 1;
80 public static final int DISPLAY_ONLY_WITH_PHONES_DISABLED = 2;
81
82 private int mDisplayOnlyWithPhones;
83 private boolean mDisplayOnlyVisible;
84 private String mGroupName;
85 private boolean mLegacyCompatibilityMode;
Dmitri Plotnikov1c5c8e22010-06-24 15:14:45 -070086 private boolean mDirectorySearchEnabled = true;
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -070087 private Uri mContactUri;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070088
89 /**
90 * Copies all fields.
91 */
92 public void copyFrom(ContactsRequest request) {
93 mValid = request.mValid;
94 mActionCode = request.mActionCode;
95 mRedirectIntent = request.mRedirectIntent;
96 mTitle = request.mTitle;
97 mSearchMode = request.mSearchMode;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070098 mQueryString = request.mQueryString;
99 mDisplayOnlyWithPhones = request.mDisplayOnlyWithPhones;
100 mDisplayOnlyVisible = request.mDisplayOnlyVisible;
101 mGroupName = request.mGroupName;
102 mLegacyCompatibilityMode = request.mLegacyCompatibilityMode;
Dmitri Plotnikov1c5c8e22010-06-24 15:14:45 -0700103 mDirectorySearchEnabled = request.mDirectorySearchEnabled;
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700104 mContactUri = request.mContactUri;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700105 }
106
107 public static Parcelable.Creator<ContactsRequest> CREATOR = new Creator<ContactsRequest>() {
108
109 public ContactsRequest[] newArray(int size) {
110 return new ContactsRequest[size];
111 }
112
113 public ContactsRequest createFromParcel(Parcel source) {
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700114 ClassLoader classLoader = this.getClass().getClassLoader();
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700115 ContactsRequest request = new ContactsRequest();
116 request.mValid = source.readInt() != 0;
117 request.mActionCode = source.readInt();
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700118 request.mRedirectIntent = source.readParcelable(classLoader);
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700119 request.mTitle = source.readCharSequence();
120 request.mSearchMode = source.readInt() != 0;
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700121 request.mQueryString = source.readString();
122 request.mDisplayOnlyWithPhones = source.readInt();
123 request.mDisplayOnlyVisible = source.readInt() != 0;
124 request.mGroupName = source.readString();
125 request.mLegacyCompatibilityMode = source.readInt() != 0;
Dmitri Plotnikov1c5c8e22010-06-24 15:14:45 -0700126 request.mDirectorySearchEnabled = source.readInt() != 0;
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700127 request.mContactUri = source.readParcelable(classLoader);
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700128 return request;
129 }
130 };
131
132 public void writeToParcel(Parcel dest, int flags) {
133 dest.writeInt(mValid ? 1 : 0);
134 dest.writeInt(mActionCode);
135 dest.writeParcelable(mRedirectIntent, 0);
136 dest.writeCharSequence(mTitle);
137 dest.writeInt(mSearchMode ? 1 : 0);
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700138 dest.writeString(mQueryString);
139 dest.writeInt(mDisplayOnlyWithPhones);
140 dest.writeInt(mDisplayOnlyVisible ? 1 : 0);
141 dest.writeString(mGroupName);
142 dest.writeInt(mLegacyCompatibilityMode ? 1 : 0);
Dmitri Plotnikov1c5c8e22010-06-24 15:14:45 -0700143 dest.writeInt(mDirectorySearchEnabled ? 1 : 0);
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700144 dest.writeParcelable(mContactUri, 0);
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700145 }
146
147 public int describeContents() {
148 return 0;
149 }
150
151 public boolean isValid() {
152 return mValid;
153 }
154
155 public void setValid(boolean flag) {
156 mValid = flag;
157 }
158
159 public Intent getRedirectIntent() {
160 return mRedirectIntent;
161 }
162
163 public void setRedirectIntent(Intent intent) {
164 mRedirectIntent = intent;
165 }
166
167 public void setActivityTitle(CharSequence title) {
168 mTitle = title;
169 }
170
171 public CharSequence getActivityTitle() {
172 return mTitle;
173 }
174
175 public int getActionCode() {
176 return mActionCode;
177 }
178
179 public void setActionCode(int actionCode) {
180 mActionCode = actionCode;
181 }
182
183 public boolean getDisplayOnlyVisible() {
184 return mDisplayOnlyVisible;
185 }
186
187 public void setDisplayOnlyVisible(boolean flag) {
188 mDisplayOnlyVisible = flag;
189 }
190
191 public int getDisplayWithPhonesOnlyOption() {
192 return mDisplayOnlyWithPhones;
193 }
194
195 public void setDisplayWithPhonesOnlyOption(int option) {
196 mDisplayOnlyWithPhones = option;
197 }
198
199 public boolean isSearchMode() {
200 return mSearchMode;
201 }
202
203 public void setSearchMode(boolean flag) {
204 mSearchMode = flag;
205 }
206
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700207 public String getQueryString() {
208 return mQueryString;
209 }
210
211 public void setQueryString(String string) {
212 mQueryString = string;
213 }
214
215 public String getGroupName() {
216 return mGroupName;
217 }
218
219 public void setGroupName(String groupName) {
220 mGroupName = groupName;
221 }
222
223 public boolean isLegacyCompatibilityMode() {
224 return mLegacyCompatibilityMode;
225 }
226
227 public void setLegacyCompatibilityMode(boolean flag) {
228 mLegacyCompatibilityMode = flag;
229 }
Dmitri Plotnikov1c5c8e22010-06-24 15:14:45 -0700230
231 /**
232 * Determines whether this search request should include directories or
233 * is limited to local contacts only.
234 */
235 public boolean isDirectorySearchEnabled() {
236 return mDirectorySearchEnabled;
237 }
238
239 public void setDirectorySearchEnabled(boolean flag) {
240 mDirectorySearchEnabled = flag;
241 }
Dmitri Plotnikov27b97bc2010-10-07 18:06:09 -0700242
243 public Uri getContactUri() {
244 return mContactUri;
245 }
246
247 public void setContactUri(Uri contactUri) {
248 this.mContactUri = contactUri;
249 }
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -0700250}