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