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