ContactsRequest.java revision 0a4d2258411478c7c78790cd55ba25c99f588c26
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.net.Uri;
21import 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 all contacts */
33    public static final int ACTION_ALL_CONTACTS = 15;
34
35    /** Show all contacts with phone numbers */
36    public static final int ACTION_CONTACTS_WITH_PHONES = 17;
37
38    /** Show contents of a specific group */
39    public static final int ACTION_GROUP = 20;
40
41    /** Show all starred contacts */
42    public static final int ACTION_STARRED = 30;
43
44    /** Show frequently contacted contacts */
45    public static final int ACTION_FREQUENT = 40;
46
47    /** Show starred and the frequent */
48    public static final int ACTION_STREQUENT = 50;
49
50    /** Show all contacts and pick them when clicking */
51    public static final int ACTION_PICK_CONTACT = 60;
52
53    /** Show all contacts as well as the option to create a new one */
54    public static final int ACTION_PICK_OR_CREATE_CONTACT = 70;
55
56    /** Show all contacts and pick them for edit when clicking, and allow creating a new contact */
57    public static final int ACTION_INSERT_OR_EDIT_CONTACT = 80;
58
59    /** Show all phone numbers and pick them when clicking */
60    public static final int ACTION_PICK_PHONE = 90;
61
62    /** Show all postal addresses and pick them when clicking */
63    public static final int ACTION_PICK_POSTAL = 100;
64
65    /** Show all postal addresses and pick them when clicking */
66    public static final int ACTION_PICK_EMAIL = 105;
67
68    /** Show all contacts and create a shortcut for the picked contact */
69    public static final int ACTION_CREATE_SHORTCUT_CONTACT = 110;
70
71    /** Show all phone numbers and create a call shortcut for the picked number */
72    public static final int ACTION_CREATE_SHORTCUT_CALL = 120;
73
74    /** Show all phone numbers and create an SMS shortcut for the picked number */
75    public static final int ACTION_CREATE_SHORTCUT_SMS = 130;
76
77    /** Show all contacts and activate the specified one */
78    public static final int ACTION_VIEW_CONTACT = 140;
79
80    private boolean mValid = true;
81    private int mActionCode = ACTION_DEFAULT;
82    private Intent mRedirectIntent;
83    private CharSequence mTitle;
84    private boolean mSearchMode;
85    private String mQueryString;
86    private boolean mIncludeProfile;
87    private String mGroupName;
88    private boolean mLegacyCompatibilityMode;
89    private boolean mDirectorySearchEnabled = true;
90    private Uri mContactUri;
91
92    /**
93     * Copies all fields.
94     */
95    public void copyFrom(ContactsRequest request) {
96        mValid = request.mValid;
97        mActionCode = request.mActionCode;
98        mRedirectIntent = request.mRedirectIntent;
99        mTitle = request.mTitle;
100        mSearchMode = request.mSearchMode;
101        mQueryString = request.mQueryString;
102        mIncludeProfile = request.mIncludeProfile;
103        mGroupName = request.mGroupName;
104        mLegacyCompatibilityMode = request.mLegacyCompatibilityMode;
105        mDirectorySearchEnabled = request.mDirectorySearchEnabled;
106        mContactUri = request.mContactUri;
107    }
108
109    public static Parcelable.Creator<ContactsRequest> CREATOR = new Creator<ContactsRequest>() {
110
111        public ContactsRequest[] newArray(int size) {
112            return new ContactsRequest[size];
113        }
114
115        public ContactsRequest createFromParcel(Parcel source) {
116            ClassLoader classLoader = this.getClass().getClassLoader();
117            ContactsRequest request = new ContactsRequest();
118            request.mValid = source.readInt() != 0;
119            request.mActionCode = source.readInt();
120            request.mRedirectIntent = source.readParcelable(classLoader);
121            request.mTitle = source.readCharSequence();
122            request.mSearchMode = source.readInt() != 0;
123            request.mQueryString = source.readString();
124            request.mIncludeProfile = source.readInt() != 0;
125            request.mGroupName = source.readString();
126            request.mLegacyCompatibilityMode  = source.readInt() != 0;
127            request.mDirectorySearchEnabled = source.readInt() != 0;
128            request.mContactUri = source.readParcelable(classLoader);
129            return request;
130        }
131    };
132
133    public void writeToParcel(Parcel dest, int flags) {
134        dest.writeInt(mValid ? 1 : 0);
135        dest.writeInt(mActionCode);
136        dest.writeParcelable(mRedirectIntent, 0);
137        dest.writeCharSequence(mTitle);
138        dest.writeInt(mSearchMode ? 1 : 0);
139        dest.writeString(mQueryString);
140        dest.writeInt(mIncludeProfile ? 1 : 0);
141        dest.writeString(mGroupName);
142        dest.writeInt(mLegacyCompatibilityMode ? 1 : 0);
143        dest.writeInt(mDirectorySearchEnabled ? 1 : 0);
144        dest.writeParcelable(mContactUri, 0);
145    }
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 isSearchMode() {
184        return mSearchMode;
185    }
186
187    public void setSearchMode(boolean flag) {
188        mSearchMode = flag;
189    }
190
191    public String getQueryString() {
192        return mQueryString;
193    }
194
195    public void setQueryString(String string) {
196        mQueryString = string;
197    }
198
199    public boolean shouldIncludeProfile() {
200        return mIncludeProfile;
201    }
202
203    public void setIncludeProfile(boolean includeProfile) {
204        mIncludeProfile = includeProfile;
205    }
206
207    public String getGroupName() {
208        return mGroupName;
209    }
210
211    public void setGroupName(String groupName) {
212        mGroupName = groupName;
213    }
214
215    public boolean isLegacyCompatibilityMode() {
216        return mLegacyCompatibilityMode;
217    }
218
219    public void setLegacyCompatibilityMode(boolean flag) {
220        mLegacyCompatibilityMode = flag;
221    }
222
223    /**
224     * Determines whether this search request should include directories or
225     * is limited to local contacts only.
226     */
227    public boolean isDirectorySearchEnabled() {
228        return mDirectorySearchEnabled;
229    }
230
231    public void setDirectorySearchEnabled(boolean flag) {
232        mDirectorySearchEnabled = flag;
233    }
234
235    public Uri getContactUri() {
236        return mContactUri;
237    }
238
239    public void setContactUri(Uri contactUri) {
240        this.mContactUri = contactUri;
241    }
242}
243