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 com.android.car.media.common; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.widget.ImageButton; 22 import android.widget.ProgressBar; 23 24 import androidx.annotation.NonNull; 25 import androidx.lifecycle.LifecycleOwner; 26 27 import com.android.car.apps.common.ControlBar; 28 import com.android.car.media.common.playback.PlaybackViewModel; 29 30 /** 31 * Basic playback control bar (doesn't display any metadata). 32 */ 33 public class PlaybackControlsActionBar extends ControlBar { 34 35 private ImageButton mOverflowButton; 36 private ProgressBar mCircularProgressBar; 37 38 private MediaButtonController mMediaButtonController; 39 40 private boolean mShowCircularProgressBar; 41 42 /** Creates a {@link PlaybackControlsActionBar} view */ PlaybackControlsActionBar(Context context)43 public PlaybackControlsActionBar(Context context) { 44 this(context, null, 0, 0); 45 } 46 47 /** Creates a {@link PlaybackControlsActionBar} view */ PlaybackControlsActionBar(Context context, AttributeSet attrs)48 public PlaybackControlsActionBar(Context context, AttributeSet attrs) { 49 this(context, attrs, 0, 0); 50 } 51 52 /** Creates a {@link PlaybackControlsActionBar} view */ PlaybackControlsActionBar(Context context, AttributeSet attrs, int defStyleAttr)53 public PlaybackControlsActionBar(Context context, AttributeSet attrs, int defStyleAttr) { 54 this(context, attrs, defStyleAttr, 0); 55 } 56 57 /** Creates a {@link PlaybackControlsActionBar} view */ PlaybackControlsActionBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)58 public PlaybackControlsActionBar(Context context, AttributeSet attrs, int defStyleAttr, 59 int defStyleRes) { 60 super(context, attrs, defStyleAttr, defStyleRes); 61 init(context); 62 } 63 init(Context context)64 private void init(Context context) { 65 mOverflowButton = createIconButton(context.getDrawable(R.drawable.ic_overflow_button), 66 R.layout.control_bar_selectable_button); 67 mOverflowButton.setId(R.id.overflow); 68 setExpandCollapseView(mOverflowButton); 69 70 mMediaButtonController = new MediaButtonController(context, this, 71 R.color.playback_control_color, R.layout.play_pause_stop_button_layout, 72 R.drawable.ic_skip_previous, R.drawable.ic_skip_next); 73 74 mShowCircularProgressBar = context.getResources().getBoolean( 75 R.bool.show_circular_progress_bar); 76 mCircularProgressBar = findViewById(R.id.circular_progress_bar); 77 } 78 setModel(@onNull PlaybackViewModel model, @NonNull LifecycleOwner owner)79 public void setModel(@NonNull PlaybackViewModel model, @NonNull LifecycleOwner owner) { 80 mMediaButtonController.setModel(model, owner); 81 ControlBarHelper.initProgressBar(getContext(), owner, model, mCircularProgressBar, 82 mShowCircularProgressBar); 83 } 84 } 85