Home | History | Annotate | Download | only in list
      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 
     17 package com.android.contacts.list;
     18 
     19 import android.content.Intent;
     20 import android.net.Uri;
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 
     24 /**
     25  * Parsed form of the intent sent to the Contacts application.
     26  */
     27 public 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     /** Show contacts recommended for joining with a specified target contact */
     81     public static final int ACTION_PICK_JOIN = 150;
     82 
     83     private boolean mValid = true;
     84     private int mActionCode = ACTION_DEFAULT;
     85     private Intent mRedirectIntent;
     86     private CharSequence mTitle;
     87     private boolean mSearchMode;
     88     private String mQueryString;
     89     private boolean mIncludeProfile;
     90     private boolean mLegacyCompatibilityMode;
     91     private boolean mDirectorySearchEnabled = true;
     92     private Uri mContactUri;
     93 
     94     @Override
     95     public String toString() {
     96         return "{ContactsRequest:mValid=" + mValid
     97                 + " mActionCode=" + mActionCode
     98                 + " mRedirectIntent=" + mRedirectIntent
     99                 + " mTitle=" + mTitle
    100                 + " mSearchMode=" + mSearchMode
    101                 + " mQueryString=" + mQueryString
    102                 + " mIncludeProfile=" + mIncludeProfile
    103                 + " mLegacyCompatibilityMode=" + mLegacyCompatibilityMode
    104                 + " mDirectorySearchEnabled=" + mDirectorySearchEnabled
    105                 + " mContactUri=" + mContactUri
    106                 + "}";
    107     }
    108 
    109     /**
    110      * Copies all fields.
    111      */
    112     public void copyFrom(ContactsRequest request) {
    113         mValid = request.mValid;
    114         mActionCode = request.mActionCode;
    115         mRedirectIntent = request.mRedirectIntent;
    116         mTitle = request.mTitle;
    117         mSearchMode = request.mSearchMode;
    118         mQueryString = request.mQueryString;
    119         mIncludeProfile = request.mIncludeProfile;
    120         mLegacyCompatibilityMode = request.mLegacyCompatibilityMode;
    121         mDirectorySearchEnabled = request.mDirectorySearchEnabled;
    122         mContactUri = request.mContactUri;
    123     }
    124 
    125     public static Parcelable.Creator<ContactsRequest> CREATOR = new Creator<ContactsRequest>() {
    126 
    127         public ContactsRequest[] newArray(int size) {
    128             return new ContactsRequest[size];
    129         }
    130 
    131         public ContactsRequest createFromParcel(Parcel source) {
    132             ClassLoader classLoader = this.getClass().getClassLoader();
    133             ContactsRequest request = new ContactsRequest();
    134             request.mValid = source.readInt() != 0;
    135             request.mActionCode = source.readInt();
    136             request.mRedirectIntent = source.readParcelable(classLoader);
    137             request.mTitle = source.readCharSequence();
    138             request.mSearchMode = source.readInt() != 0;
    139             request.mQueryString = source.readString();
    140             request.mIncludeProfile = source.readInt() != 0;
    141             request.mLegacyCompatibilityMode  = source.readInt() != 0;
    142             request.mDirectorySearchEnabled = source.readInt() != 0;
    143             request.mContactUri = source.readParcelable(classLoader);
    144             return request;
    145         }
    146     };
    147 
    148     public void writeToParcel(Parcel dest, int flags) {
    149         dest.writeInt(mValid ? 1 : 0);
    150         dest.writeInt(mActionCode);
    151         dest.writeParcelable(mRedirectIntent, 0);
    152         dest.writeCharSequence(mTitle);
    153         dest.writeInt(mSearchMode ? 1 : 0);
    154         dest.writeString(mQueryString);
    155         dest.writeInt(mIncludeProfile ? 1 : 0);
    156         dest.writeInt(mLegacyCompatibilityMode ? 1 : 0);
    157         dest.writeInt(mDirectorySearchEnabled ? 1 : 0);
    158         dest.writeParcelable(mContactUri, 0);
    159     }
    160 
    161     public int describeContents() {
    162         return 0;
    163     }
    164 
    165     public boolean isValid() {
    166         return mValid;
    167     }
    168 
    169     public void setValid(boolean flag) {
    170         mValid = flag;
    171     }
    172 
    173     public Intent getRedirectIntent() {
    174         return mRedirectIntent;
    175     }
    176 
    177     public void setRedirectIntent(Intent intent) {
    178         mRedirectIntent = intent;
    179     }
    180 
    181     public void setActivityTitle(CharSequence title) {
    182         mTitle = title;
    183     }
    184 
    185     public CharSequence getActivityTitle() {
    186         return mTitle;
    187     }
    188 
    189     public int getActionCode() {
    190         return mActionCode;
    191     }
    192 
    193     public void setActionCode(int actionCode) {
    194         mActionCode = actionCode;
    195     }
    196 
    197     public boolean isSearchMode() {
    198         return mSearchMode;
    199     }
    200 
    201     public void setSearchMode(boolean flag) {
    202         mSearchMode = flag;
    203     }
    204 
    205     public String getQueryString() {
    206         return mQueryString;
    207     }
    208 
    209     public void setQueryString(String string) {
    210         mQueryString = string;
    211     }
    212 
    213     public boolean shouldIncludeProfile() {
    214         return mIncludeProfile;
    215     }
    216 
    217     public void setIncludeProfile(boolean includeProfile) {
    218         mIncludeProfile = includeProfile;
    219     }
    220 
    221     public boolean isLegacyCompatibilityMode() {
    222         return mLegacyCompatibilityMode;
    223     }
    224 
    225     public void setLegacyCompatibilityMode(boolean flag) {
    226         mLegacyCompatibilityMode = flag;
    227     }
    228 
    229     /**
    230      * Determines whether this search request should include directories or
    231      * is limited to local contacts only.
    232      */
    233     public boolean isDirectorySearchEnabled() {
    234         return mDirectorySearchEnabled;
    235     }
    236 
    237     public void setDirectorySearchEnabled(boolean flag) {
    238         mDirectorySearchEnabled = flag;
    239     }
    240 
    241     public Uri getContactUri() {
    242         return mContactUri;
    243     }
    244 
    245     public void setContactUri(Uri contactUri) {
    246         this.mContactUri = contactUri;
    247     }
    248 }
    249