1 /* 2 * Copyright (C) 2020 Google Inc. 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 com.android.car.carlauncher.homescreen.ui; 18 19 import android.graphics.drawable.Drawable; 20 import android.view.View; 21 22 /** 23 * A layout that displays a title line of text with a subtitle line below and three buttons to 24 * control the audio. Displayed using card_content_descriptive_text_with_controls.xml 25 */ 26 public class DescriptiveTextWithControlsView extends CardContent { 27 28 private CardBackgroundImage mImage; 29 private CharSequence mTitle; 30 private CharSequence mSubtitle; 31 private Control mLeftControl; 32 private Control mCenterControl; 33 private Control mRightControl; 34 private long mStartTime; 35 private SeekBarViewModel mSeekBarViewModel; 36 37 //TODO(b/260002616): considering using builder DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, CharSequence subtitle)38 public DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, 39 CharSequence subtitle) { 40 mImage = image; 41 mTitle = title; 42 mSubtitle = subtitle; 43 } 44 DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, CharSequence subtitle, SeekBarViewModel seekBarViewModel)45 public DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, 46 CharSequence subtitle, SeekBarViewModel seekBarViewModel) { 47 mImage = image; 48 mTitle = title; 49 mSubtitle = subtitle; 50 mSeekBarViewModel = seekBarViewModel; 51 } 52 DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, CharSequence subtitle, Control leftControl, Control centerControl, Control rightControl)53 public DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, 54 CharSequence subtitle, Control leftControl, Control centerControl, 55 Control rightControl) { 56 mImage = image; 57 mTitle = title; 58 mSubtitle = subtitle; 59 mLeftControl = leftControl; 60 mCenterControl = centerControl; 61 mRightControl = rightControl; 62 } 63 DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, CharSequence subtitle, long startTime, Control leftControl, Control centerControl, Control rightControl)64 public DescriptiveTextWithControlsView(CardBackgroundImage image, CharSequence title, 65 CharSequence subtitle, long startTime, Control leftControl, 66 Control centerControl, Control rightControl) { 67 mImage = image; 68 mTitle = title; 69 mSubtitle = subtitle; 70 mStartTime = startTime; 71 mLeftControl = leftControl; 72 mCenterControl = centerControl; 73 mRightControl = rightControl; 74 } 75 76 @Override getType()77 public HomeCardContentType getType() { 78 return HomeCardContentType.DESCRIPTIVE_TEXT_WITH_CONTROLS; 79 } 80 getImage()81 public CardBackgroundImage getImage() { 82 return mImage; 83 } 84 getTitle()85 public CharSequence getTitle() { 86 return mTitle; 87 } 88 getSubtitle()89 public CharSequence getSubtitle() { 90 return mSubtitle; 91 } 92 getStartTime()93 public long getStartTime() { 94 return mStartTime; 95 } 96 getLeftControl()97 public Control getLeftControl() { 98 return mLeftControl; 99 } 100 getCenterControl()101 public Control getCenterControl() { 102 return mCenterControl; 103 } 104 getRightControl()105 public Control getRightControl() { 106 return mRightControl; 107 } 108 getSeekBarViewModel()109 public SeekBarViewModel getSeekBarViewModel() { 110 return mSeekBarViewModel; 111 } 112 113 /** 114 * A button shown with the DescriptiveTextWithControlsView that has a {@link Drawable} icon 115 * used as the button's image and an {@link android.view.View.OnClickListener} that defines the 116 * action when the button is clicked. 117 */ 118 public static class Control { 119 120 private Drawable mIcon; 121 private View.OnClickListener mOnClickListener; 122 Control(Drawable icon, View.OnClickListener listener)123 public Control(Drawable icon, View.OnClickListener listener) { 124 mIcon = icon; 125 mOnClickListener = listener; 126 } 127 getIcon()128 public Drawable getIcon() { 129 return mIcon; 130 } 131 getOnClickListener()132 public View.OnClickListener getOnClickListener() { 133 return mOnClickListener; 134 } 135 } 136 } 137