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 package com.android.contacts.common.list;
     17 
     18 import android.provider.ContactsContract.Directory;
     19 import com.android.common.widget.CompositeCursorAdapter;
     20 
     21 /** Model object for a {@link Directory} row. */
     22 public final class DirectoryPartition extends CompositeCursorAdapter.Partition {
     23 
     24   public static final int STATUS_NOT_LOADED = 0;
     25   public static final int STATUS_LOADING = 1;
     26   public static final int STATUS_LOADED = 2;
     27 
     28   public static final int RESULT_LIMIT_DEFAULT = -1;
     29 
     30   private long mDirectoryId;
     31   private String mContentUri;
     32   private String mDirectoryType;
     33   private String mDisplayName;
     34   private int mStatus;
     35   private boolean mPriorityDirectory;
     36   private boolean mPhotoSupported;
     37   private int mResultLimit = RESULT_LIMIT_DEFAULT;
     38   private boolean mDisplayNumber = true;
     39 
     40   private String mLabel;
     41 
     42   public DirectoryPartition(boolean showIfEmpty, boolean hasHeader) {
     43     super(showIfEmpty, hasHeader);
     44   }
     45 
     46   /** Directory ID, see {@link Directory}. */
     47   public long getDirectoryId() {
     48     return mDirectoryId;
     49   }
     50 
     51   public void setDirectoryId(long directoryId) {
     52     this.mDirectoryId = directoryId;
     53   }
     54 
     55   /**
     56    * Directory type resolved from {@link Directory#PACKAGE_NAME} and {@link
     57    * Directory#TYPE_RESOURCE_ID};
     58    */
     59   public String getDirectoryType() {
     60     return mDirectoryType;
     61   }
     62 
     63   public void setDirectoryType(String directoryType) {
     64     this.mDirectoryType = directoryType;
     65   }
     66 
     67   /** See {@link Directory#DISPLAY_NAME}. */
     68   public String getDisplayName() {
     69     return mDisplayName;
     70   }
     71 
     72   public void setDisplayName(String displayName) {
     73     this.mDisplayName = displayName;
     74   }
     75 
     76   public int getStatus() {
     77     return mStatus;
     78   }
     79 
     80   public void setStatus(int status) {
     81     mStatus = status;
     82   }
     83 
     84   public boolean isLoading() {
     85     return mStatus == STATUS_NOT_LOADED || mStatus == STATUS_LOADING;
     86   }
     87 
     88   /** Returns true if this directory should be loaded before non-priority directories. */
     89   public boolean isPriorityDirectory() {
     90     return mPriorityDirectory;
     91   }
     92 
     93   public void setPriorityDirectory(boolean priorityDirectory) {
     94     mPriorityDirectory = priorityDirectory;
     95   }
     96 
     97   /** Returns true if this directory supports photos. */
     98   public boolean isPhotoSupported() {
     99     return mPhotoSupported;
    100   }
    101 
    102   public void setPhotoSupported(boolean flag) {
    103     this.mPhotoSupported = flag;
    104   }
    105 
    106   /**
    107    * Max number of results for this directory. Defaults to {@link #RESULT_LIMIT_DEFAULT} which
    108    * implies using the adapter's {@link
    109    * com.android.contacts.common.list.ContactListAdapter#getDirectoryResultLimit()}
    110    */
    111   public int getResultLimit() {
    112     return mResultLimit;
    113   }
    114 
    115   public void setResultLimit(int resultLimit) {
    116     mResultLimit = resultLimit;
    117   }
    118 
    119   /**
    120    * Used by extended directories to specify a custom content URI. Extended directories MUST have a
    121    * content URI
    122    */
    123   public String getContentUri() {
    124     return mContentUri;
    125   }
    126 
    127   public void setContentUri(String contentUri) {
    128     mContentUri = contentUri;
    129   }
    130 
    131   /** A label to display in the header next to the display name. */
    132   public String getLabel() {
    133     return mLabel;
    134   }
    135 
    136   public void setLabel(String label) {
    137     mLabel = label;
    138   }
    139 
    140   @Override
    141   public String toString() {
    142     return "DirectoryPartition{"
    143         + "mDirectoryId="
    144         + mDirectoryId
    145         + ", mContentUri='"
    146         + mContentUri
    147         + '\''
    148         + ", mDirectoryType='"
    149         + mDirectoryType
    150         + '\''
    151         + ", mDisplayName='"
    152         + mDisplayName
    153         + '\''
    154         + ", mStatus="
    155         + mStatus
    156         + ", mPriorityDirectory="
    157         + mPriorityDirectory
    158         + ", mPhotoSupported="
    159         + mPhotoSupported
    160         + ", mResultLimit="
    161         + mResultLimit
    162         + ", mLabel='"
    163         + mLabel
    164         + '\''
    165         + '}';
    166   }
    167 
    168   /**
    169    * Whether or not to display the phone number in app that have that option - Dialer. If false,
    170    * Phone Label should be used instead of Phone Number.
    171    */
    172   public boolean isDisplayNumber() {
    173     return mDisplayNumber;
    174   }
    175 
    176   public void setDisplayNumber(boolean displayNumber) {
    177     mDisplayNumber = displayNumber;
    178   }
    179 }
    180