Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 androidx.app.slice.widget; |
| 18 | |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 19 | import static android.app.slice.Slice.HINT_ACTIONS; |
| 20 | import static android.app.slice.Slice.HINT_SHORTCUT; |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 21 | import static android.app.slice.Slice.HINT_SUMMARY; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 22 | import static android.app.slice.Slice.HINT_TITLE; |
| 23 | import static android.app.slice.SliceItem.FORMAT_ACTION; |
| 24 | import static android.app.slice.SliceItem.FORMAT_IMAGE; |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 25 | import static android.app.slice.SliceItem.FORMAT_INT; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 26 | import static android.app.slice.SliceItem.FORMAT_REMOTE_INPUT; |
| 27 | import static android.app.slice.SliceItem.FORMAT_SLICE; |
| 28 | import static android.app.slice.SliceItem.FORMAT_TEXT; |
| 29 | import static android.app.slice.SliceItem.FORMAT_TIMESTAMP; |
Mady Mellor | 37bd071 | 2018-02-02 14:07:52 -0800 | [diff] [blame] | 30 | |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 31 | import static androidx.app.slice.core.SliceHints.SUBTYPE_RANGE; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 32 | |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 33 | import android.content.Context; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 34 | import android.support.annotation.Nullable; |
| 35 | import android.support.annotation.RestrictTo; |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 36 | import android.text.TextUtils; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 37 | import android.util.Log; |
| 38 | |
| 39 | import java.util.ArrayList; |
| 40 | import java.util.List; |
| 41 | |
| 42 | import androidx.app.slice.SliceItem; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 43 | import androidx.app.slice.core.SliceQuery; |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 44 | import androidx.app.slice.view.R; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Extracts information required to present content in a row format from a slice. |
| 48 | * @hide |
| 49 | */ |
| 50 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) |
| 51 | public class RowContent { |
| 52 | private static final String TAG = "RowContent"; |
| 53 | |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 54 | private SliceItem mPrimaryAction; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 55 | private SliceItem mStartItem; |
| 56 | private SliceItem mTitleItem; |
| 57 | private SliceItem mSubtitleItem; |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 58 | private SliceItem mSummaryItem; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 59 | private ArrayList<SliceItem> mEndItems = new ArrayList<>(); |
Amin Shaikh | bfeddba | 2018-01-10 14:51:13 -0500 | [diff] [blame] | 60 | private boolean mEndItemsContainAction; |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 61 | private SliceItem mRange; |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 62 | private boolean mIsHeader; |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 63 | private int mLineCount = 0; |
| 64 | private int mMaxHeight; |
| 65 | private int mMinHeight; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 66 | |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 67 | public RowContent(Context context, SliceItem rowSlice, boolean isHeader) { |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 68 | populate(rowSlice, isHeader); |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 69 | mMaxHeight = context.getResources().getDimensionPixelSize(R.dimen.abc_slice_row_max_height); |
| 70 | mMinHeight = context.getResources().getDimensionPixelSize(R.dimen.abc_slice_row_min_height); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
Mady Mellor | 3220613 | 2017-12-21 22:22:26 -0800 | [diff] [blame] | 74 | * Resets the content. |
| 75 | */ |
| 76 | public void reset() { |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 77 | mPrimaryAction = null; |
Mady Mellor | 3220613 | 2017-12-21 22:22:26 -0800 | [diff] [blame] | 78 | mStartItem = null; |
| 79 | mTitleItem = null; |
| 80 | mSubtitleItem = null; |
Mady Mellor | 3220613 | 2017-12-21 22:22:26 -0800 | [diff] [blame] | 81 | mEndItems.clear(); |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 82 | mIsHeader = false; |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 83 | mLineCount = 0; |
Mady Mellor | 3220613 | 2017-12-21 22:22:26 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 87 | * @return whether this row has content that is valid to display. |
| 88 | */ |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 89 | private boolean populate(SliceItem rowSlice, boolean isHeader) { |
Mady Mellor | 3220613 | 2017-12-21 22:22:26 -0800 | [diff] [blame] | 90 | reset(); |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 91 | mIsHeader = isHeader; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 92 | if (!isValidRow(rowSlice)) { |
| 93 | Log.w(TAG, "Provided SliceItem is invalid for RowContent"); |
| 94 | return false; |
| 95 | } |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 96 | // Find primary action first (otherwise filtered out of valid row items) |
| 97 | String[] hints = new String[] {HINT_SHORTCUT, HINT_TITLE}; |
| 98 | mPrimaryAction = SliceQuery.find(rowSlice, FORMAT_SLICE, hints, |
| 99 | new String[] { HINT_ACTIONS } /* nonHints */); |
| 100 | |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 101 | // Filter anything not viable for displaying in a row |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 102 | ArrayList<SliceItem> rowItems = filterInvalidItems(rowSlice); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 103 | // If we've only got one item that's a slice / action use those items instead |
| 104 | if (rowItems.size() == 1 && (FORMAT_ACTION.equals(rowItems.get(0).getFormat()) |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 105 | || FORMAT_SLICE.equals(rowItems.get(0).getFormat())) |
| 106 | && !rowItems.get(0).hasHint(HINT_SHORTCUT)) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 107 | if (isValidRow(rowItems.get(0))) { |
| 108 | rowSlice = rowItems.get(0); |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 109 | rowItems = filterInvalidItems(rowSlice); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 110 | } |
| 111 | } |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 112 | if (SUBTYPE_RANGE.equals(rowSlice.getSubType())) { |
| 113 | mRange = rowSlice; |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 114 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 115 | if (rowItems.size() > 0) { |
| 116 | // Start item |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 117 | SliceItem firstItem = rowItems.get(0); |
| 118 | if (FORMAT_SLICE.equals(firstItem.getFormat())) { |
| 119 | SliceItem unwrappedItem = firstItem.getSlice().getItems().get(0); |
| 120 | if (isStartType(unwrappedItem)) { |
| 121 | mStartItem = unwrappedItem; |
| 122 | rowItems.remove(0); |
| 123 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 124 | } |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 125 | |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 126 | // Text + end items |
Mady Mellor | 238b9b6 | 2018-01-09 16:15:40 -0800 | [diff] [blame] | 127 | ArrayList<SliceItem> endItems = new ArrayList<>(); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 128 | for (int i = 0; i < rowItems.size(); i++) { |
| 129 | final SliceItem item = rowItems.get(i); |
| 130 | if (FORMAT_TEXT.equals(item.getFormat())) { |
| 131 | if ((mTitleItem == null || !mTitleItem.hasHint(HINT_TITLE)) |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 132 | && item.hasHint(HINT_TITLE) && !item.hasHint(HINT_SUMMARY)) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 133 | mTitleItem = item; |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 134 | } else if (mSubtitleItem == null && !item.hasHint(HINT_SUMMARY)) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 135 | mSubtitleItem = item; |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 136 | } else if (mSummaryItem == null && item.hasHint(HINT_SUMMARY)) { |
| 137 | mSummaryItem = item; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 138 | } |
| 139 | } else { |
Mady Mellor | 238b9b6 | 2018-01-09 16:15:40 -0800 | [diff] [blame] | 140 | endItems.add(item); |
| 141 | } |
| 142 | } |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 143 | if (hasText(mTitleItem)) { |
| 144 | mLineCount++; |
| 145 | } |
| 146 | if (hasText(mSubtitleItem)) { |
| 147 | mLineCount++; |
| 148 | } |
Mady Mellor | 238b9b6 | 2018-01-09 16:15:40 -0800 | [diff] [blame] | 149 | // Special rules for end items: only one timestamp, can't be mixture of icons / actions |
| 150 | boolean hasTimestamp = mStartItem != null |
| 151 | && FORMAT_TIMESTAMP.equals(mStartItem.getFormat()); |
| 152 | String desiredFormat = null; |
| 153 | for (int i = 0; i < endItems.size(); i++) { |
| 154 | final SliceItem item = endItems.get(i); |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 155 | boolean isAction = FORMAT_SLICE.equals(item.getFormat()) |
| 156 | && item.hasHint(HINT_SHORTCUT); |
Mady Mellor | 238b9b6 | 2018-01-09 16:15:40 -0800 | [diff] [blame] | 157 | if (FORMAT_TIMESTAMP.equals(item.getFormat())) { |
| 158 | if (!hasTimestamp) { |
| 159 | hasTimestamp = true; |
| 160 | mEndItems.add(item); |
| 161 | } |
| 162 | } else if (desiredFormat == null) { |
| 163 | desiredFormat = item.getFormat(); |
| 164 | mEndItems.add(item); |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 165 | mEndItemsContainAction |= isAction; |
Mady Mellor | 238b9b6 | 2018-01-09 16:15:40 -0800 | [diff] [blame] | 166 | } else if (desiredFormat.equals(item.getFormat())) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 167 | mEndItems.add(item); |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 168 | mEndItemsContainAction |= isAction; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 172 | return isValid(); |
| 173 | } |
| 174 | |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 175 | /** |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 176 | * @return the {@link SliceItem} representing the range in the row; can be null. |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 177 | */ |
| 178 | @Nullable |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 179 | public SliceItem getRange() { |
| 180 | return mRange; |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 184 | * @return whether this row has content that is valid to display. |
| 185 | */ |
| 186 | public boolean isValid() { |
| 187 | return mStartItem != null |
| 188 | || mTitleItem != null |
| 189 | || mSubtitleItem != null |
| 190 | || mEndItems.size() > 0; |
| 191 | } |
| 192 | |
| 193 | @Nullable |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 194 | public SliceItem getPrimaryAction() { |
| 195 | return mPrimaryAction; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Nullable |
| 199 | public SliceItem getStartItem() { |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 200 | return mIsHeader ? null : mStartItem; |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Nullable |
| 204 | public SliceItem getTitleItem() { |
| 205 | return mTitleItem; |
| 206 | } |
| 207 | |
| 208 | @Nullable |
| 209 | public SliceItem getSubtitleItem() { |
| 210 | return mSubtitleItem; |
| 211 | } |
| 212 | |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 213 | @Nullable |
| 214 | public SliceItem getSummaryItem() { |
| 215 | return mSummaryItem == null ? mSubtitleItem : mSummaryItem; |
| 216 | } |
| 217 | |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 218 | public ArrayList<SliceItem> getEndItems() { |
| 219 | return mEndItems; |
| 220 | } |
| 221 | |
| 222 | /** |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 223 | * @return whether {@link #getEndItems()} contains a SliceItem with FORMAT_SLICE, HINT_SHORTCUT |
Amin Shaikh | bfeddba | 2018-01-10 14:51:13 -0500 | [diff] [blame] | 224 | */ |
| 225 | public boolean endItemsContainAction() { |
| 226 | return mEndItemsContainAction; |
| 227 | } |
| 228 | |
| 229 | /** |
Mady Mellor | 8a2763f | 2018-02-16 13:39:25 -0800 | [diff] [blame^] | 230 | * @return the number of lines of text contained in this row. |
| 231 | */ |
| 232 | public int getLineCount() { |
| 233 | return mLineCount; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @return the height to display a row at when it is used as a small template. |
| 238 | */ |
| 239 | public int getSmallHeight() { |
| 240 | return mMaxHeight; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * @return the height the content in this template requires to be displayed. |
| 245 | */ |
| 246 | public int getActualHeight() { |
| 247 | return isValid() |
| 248 | ? (getLineCount() > 1 || mIsHeader) ? mMaxHeight : mMinHeight |
| 249 | : 0; |
| 250 | } |
| 251 | |
| 252 | private static boolean hasText(SliceItem textSlice) { |
| 253 | return textSlice != null && !TextUtils.isEmpty(textSlice.getText()); |
| 254 | } |
| 255 | |
| 256 | /** |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 257 | * @return whether this is a valid item to use to populate a row of content. |
| 258 | */ |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 259 | private static boolean isValidRow(SliceItem rowSlice) { |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 260 | if (rowSlice == null) { |
| 261 | return false; |
| 262 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 263 | // Must be slice or action |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 264 | if (FORMAT_SLICE.equals(rowSlice.getFormat()) |
| 265 | || FORMAT_ACTION.equals(rowSlice.getFormat())) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 266 | // Must have at least one legitimate child |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 267 | List<SliceItem> rowItems = rowSlice.getSlice().getItems(); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 268 | for (int i = 0; i < rowItems.size(); i++) { |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 269 | if (isValidRowContent(rowSlice, rowItems.get(i))) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 270 | return true; |
| 271 | } |
| 272 | } |
| 273 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 277 | private static ArrayList<SliceItem> filterInvalidItems(SliceItem rowSlice) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 278 | ArrayList<SliceItem> filteredList = new ArrayList<>(); |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 279 | for (SliceItem i : rowSlice.getSlice().getItems()) { |
| 280 | if (isValidRowContent(rowSlice, i)) { |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 281 | filteredList.add(i); |
| 282 | } |
| 283 | } |
| 284 | return filteredList; |
| 285 | } |
| 286 | |
| 287 | /** |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 288 | * @return whether this item is valid content to display in a row. |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 289 | */ |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 290 | private static boolean isValidRowContent(SliceItem slice, SliceItem item) { |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 291 | if (FORMAT_SLICE.equals(item.getFormat()) && !item.hasHint(HINT_SHORTCUT)) { |
| 292 | // Unpack contents of slice |
| 293 | item = item.getSlice().getItems().get(0); |
| 294 | } |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 295 | final String itemFormat = item.getFormat(); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 296 | return FORMAT_TEXT.equals(itemFormat) |
| 297 | || FORMAT_IMAGE.equals(itemFormat) |
| 298 | || FORMAT_TIMESTAMP.equals(itemFormat) |
| 299 | || FORMAT_REMOTE_INPUT.equals(itemFormat) |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 300 | || (FORMAT_SLICE.equals(itemFormat) && item.hasHint(HINT_TITLE) |
| 301 | && !item.hasHint(HINT_SHORTCUT)) |
| 302 | || (FORMAT_SLICE.equals(itemFormat) && item.hasHint(HINT_SHORTCUT) |
| 303 | && !item.hasHint(HINT_TITLE)) |
Amin Shaikh | f2cdc3a | 2018-01-17 09:35:23 -0500 | [diff] [blame] | 304 | || FORMAT_ACTION.equals(itemFormat) |
Amin Shaikh | 853c11f | 2018-01-17 09:38:58 -0500 | [diff] [blame] | 305 | || (FORMAT_INT.equals(itemFormat) && SUBTYPE_RANGE.equals(slice.getSubType())); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
| 309 | * @return Whether this item is appropriate to be considered a "start" item, i.e. go in the |
| 310 | * front slot of a row. |
| 311 | */ |
| 312 | private static boolean isStartType(SliceItem item) { |
| 313 | final String type = item.getFormat(); |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 314 | return (FORMAT_ACTION.equals(type) && (SliceQuery.find(item, FORMAT_IMAGE) != null)) |
Mady Mellor | 9683469 | 2018-01-29 13:55:17 -0800 | [diff] [blame] | 315 | || FORMAT_IMAGE.equals(type) |
Mady Mellor | af76b3b | 2018-02-07 10:31:15 -0800 | [diff] [blame] | 316 | || FORMAT_TIMESTAMP.equals(type); |
Mady Mellor | 6b5cd61 | 2017-12-14 11:36:59 -0800 | [diff] [blame] | 317 | } |
| 318 | } |