Mady Mellor | dc05204 | 2018-01-04 17:11:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 19 | import android.content.Context; |
| 20 | import android.support.annotation.ColorInt; |
| 21 | import android.support.annotation.NonNull; |
| 22 | import android.support.annotation.RestrictTo; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
| 25 | import android.widget.FrameLayout; |
| 26 | |
| 27 | import androidx.app.slice.Slice; |
| 28 | import androidx.app.slice.SliceItem; |
| 29 | |
| 30 | /** |
| 31 | * Base class for children views of {@link SliceView}. |
| 32 | * @hide |
| 33 | */ |
| 34 | @RestrictTo(RestrictTo.Scope.LIBRARY) |
| 35 | public abstract class SliceChildView extends FrameLayout { |
| 36 | |
| 37 | protected SliceView.SliceObserver mObserver; |
| 38 | protected int mTintColor; |
| 39 | |
| 40 | public SliceChildView(@NonNull Context context) { |
| 41 | super(context); |
| 42 | } |
| 43 | |
| 44 | public SliceChildView(Context context, AttributeSet attributeSet) { |
| 45 | this(context); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return the mode of the slice being presented. |
| 50 | */ |
| 51 | public abstract int getMode(); |
| 52 | |
| 53 | /** |
| 54 | * @param slice the slice to show in this view. |
| 55 | */ |
| 56 | public abstract void setSlice(Slice slice); |
| 57 | |
| 58 | /** |
| 59 | * Called when the view should be reset. |
| 60 | */ |
| 61 | public abstract void resetView(); |
| 62 | |
| 63 | /** |
| 64 | * @return the view. |
| 65 | */ |
| 66 | public View getView() { |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Sets a custom color to use for tinting elements like icons for this view. |
| 72 | */ |
| 73 | public void setTint(@ColorInt int tintColor) { |
| 74 | mTintColor = tintColor; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Sets the observer to notify when an interaction events occur on the view. |
| 79 | */ |
| 80 | public void setSliceObserver(SliceView.SliceObserver observer) { |
| 81 | mObserver = observer; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Populates style information for this view. |
| 86 | */ |
| 87 | public void setStyle(AttributeSet attrs) { |
| 88 | // TODO |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Called when the slice being displayed in this view is an element of a larger list. |
| 93 | */ |
| 94 | public void setSliceItem(SliceItem slice, boolean isHeader, int rowIndex, |
| 95 | SliceView.SliceObserver observer) { |
| 96 | // Do nothing |
| 97 | } |
| 98 | } |