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