Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 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 | |
| 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 | |
Ben Gilad | 03a533a | 2013-08-21 09:46:00 -0700 | [diff] [blame] | 31 | public static final int RESULT_LIMIT_DEFAULT = -1; |
| 32 | |
Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 33 | private long mDirectoryId; |
Alon Albert | dd1dcc6 | 2013-08-28 14:02:47 -0700 | [diff] [blame] | 34 | private String mContentUri; |
Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 35 | private String mDirectoryType; |
| 36 | private String mDisplayName; |
| 37 | private int mStatus; |
| 38 | private boolean mPriorityDirectory; |
| 39 | private boolean mPhotoSupported; |
Ben Gilad | 03a533a | 2013-08-21 09:46:00 -0700 | [diff] [blame] | 40 | private int mResultLimit = RESULT_LIMIT_DEFAULT; |
Alon Albert | 368cae8 | 2013-09-03 12:31:31 -0700 | [diff] [blame] | 41 | private boolean mDisplayNumber = true; |
Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 42 | |
Alon Albert | dd1dcc6 | 2013-08-28 14:02:47 -0700 | [diff] [blame] | 43 | private String mLabel; |
| 44 | |
Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 45 | public DirectoryPartition(boolean showIfEmpty, boolean hasHeader) { |
| 46 | super(showIfEmpty, hasHeader); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Directory ID, see {@link Directory}. |
| 51 | */ |
| 52 | public long getDirectoryId() { |
| 53 | return mDirectoryId; |
| 54 | } |
| 55 | |
| 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 | */ |
| 64 | public String getDirectoryType() { |
| 65 | return mDirectoryType; |
| 66 | } |
| 67 | |
| 68 | public void setDirectoryType(String directoryType) { |
| 69 | this.mDirectoryType = directoryType; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * See {@link Directory#DISPLAY_NAME}. |
| 74 | */ |
| 75 | public String getDisplayName() { |
| 76 | return mDisplayName; |
| 77 | } |
| 78 | |
| 79 | public void setDisplayName(String displayName) { |
| 80 | this.mDisplayName = displayName; |
| 81 | } |
| 82 | |
| 83 | public int getStatus() { |
| 84 | return mStatus; |
| 85 | } |
| 86 | |
| 87 | public void setStatus(int status) { |
| 88 | mStatus = status; |
| 89 | } |
| 90 | |
| 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 | */ |
| 98 | public boolean isPriorityDirectory() { |
| 99 | return mPriorityDirectory; |
| 100 | } |
| 101 | |
| 102 | public void setPriorityDirectory(boolean priorityDirectory) { |
| 103 | mPriorityDirectory = priorityDirectory; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns true if this directory supports photos. |
| 108 | */ |
| 109 | public boolean isPhotoSupported() { |
| 110 | return mPhotoSupported; |
| 111 | } |
| 112 | |
| 113 | public void setPhotoSupported(boolean flag) { |
| 114 | this.mPhotoSupported = flag; |
| 115 | } |
Ben Gilad | 03a533a | 2013-08-21 09:46:00 -0700 | [diff] [blame] | 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.common.list.ContactListAdapter#getDirectoryResultLimit()} |
| 121 | */ |
| 122 | public int getResultLimit() { |
| 123 | return mResultLimit; |
| 124 | } |
| 125 | |
| 126 | public void setResultLimit(int resultLimit) { |
| 127 | mResultLimit = resultLimit; |
| 128 | } |
Alon Albert | dd1dcc6 | 2013-08-28 14:02:47 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Used by extended directories to specify a custom content URI. Extended directories MUST have |
| 132 | * a content URI |
| 133 | */ |
| 134 | public String getContentUri() { |
| 135 | return mContentUri; |
| 136 | } |
| 137 | |
| 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 | */ |
| 145 | public String getLabel() { |
| 146 | return mLabel; |
| 147 | } |
| 148 | |
| 149 | public void setLabel(String label) { |
| 150 | mLabel = label; |
| 151 | } |
| 152 | |
| 153 | @Override |
| 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 | } |
Alon Albert | 368cae8 | 2013-09-03 12:31:31 -0700 | [diff] [blame] | 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 | } |
Chiao Cheng | 89437e8 | 2012-11-01 13:41:51 -0700 | [diff] [blame] | 179 | } |