1 /* 2 * Copyright 2019 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.util.Size; 22 import android.widget.ProgressBar; 23 24 import androidx.annotation.NonNull; 25 import androidx.lifecycle.LifecycleOwner; 26 27 import com.android.car.apps.common.MinimizedControlBar; 28 import com.android.car.media.common.playback.PlaybackViewModel; 29 30 /** 31 * This is a CarControlBar used for displaying Media content, including metadata for the currently 32 * playing song and basic controls. 33 */ 34 public class MinimizedPlaybackControlBar extends MinimizedControlBar { 35 36 private static final String TAG = "Media.ControlBar"; 37 38 private MediaButtonController mMediaButtonController; 39 private MetadataController mMetadataController; 40 private ProgressBar mLinearProgressBar; 41 private ProgressBar mCircularProgressBar; 42 private PlaybackViewModel mPlaybackViewModel; 43 44 private boolean mShowLinearProgressBar; 45 private boolean mShowCircularProgressBar; 46 MinimizedPlaybackControlBar(Context context)47 public MinimizedPlaybackControlBar(Context context) { 48 this(context, null); 49 } 50 MinimizedPlaybackControlBar(Context context, AttributeSet attrs)51 public MinimizedPlaybackControlBar(Context context, AttributeSet attrs) { 52 this(context, attrs, 0); 53 } 54 MinimizedPlaybackControlBar(Context context, AttributeSet attrs, int defStyleAttrs)55 public MinimizedPlaybackControlBar(Context context, AttributeSet attrs, int defStyleAttrs) { 56 super(context, attrs, defStyleAttrs, R.layout.minimized_playback_control_bar); 57 init(context); 58 } 59 init(Context context)60 private void init(Context context) { 61 mMediaButtonController = new MediaButtonController(context, this, 62 R.color.playback_control_color, R.layout.play_pause_stop_button_layout, 63 R.drawable.ic_skip_previous, R.drawable.ic_skip_next); 64 65 mShowLinearProgressBar = context.getResources().getBoolean(R.bool.show_linear_progress_bar); 66 mLinearProgressBar = findViewById(R.id.linear_progress_bar); 67 68 mShowCircularProgressBar = context.getResources().getBoolean( 69 R.bool.show_circular_progress_bar); 70 mCircularProgressBar = findViewById(R.id.circular_progress_bar); 71 } 72 73 /** Connects the bar to the {@link PlaybackViewModel}. */ setModel(@onNull PlaybackViewModel model, @NonNull LifecycleOwner owner, @NonNull Size maxArtSize)74 public void setModel(@NonNull PlaybackViewModel model, @NonNull LifecycleOwner owner, 75 @NonNull Size maxArtSize) { 76 mMediaButtonController.setModel(model, owner); 77 mMetadataController = new MetadataController(owner, model, 78 mTitle, mSubtitle, null, null, null, null, null, null, mContentTile, maxArtSize); 79 mPlaybackViewModel = model; 80 81 ControlBarHelper.initProgressBar(getContext(), owner, mPlaybackViewModel, 82 mLinearProgressBar, mShowLinearProgressBar); 83 ControlBarHelper.initProgressBar(getContext(), owner, mPlaybackViewModel, 84 mCircularProgressBar, mShowCircularProgressBar); 85 } 86 } 87