Add progress bar into minimized playback control bar
Bug: 130164128
Test: manual
Change-Id: I67c09fb8af0f105d0c5d6efee5302d78c925bf15
diff --git a/car-apps-common/src/com/android/car/apps/common/MinimizedControlBar.java b/car-apps-common/src/com/android/car/apps/common/MinimizedControlBar.java
index 461d908..5c9b3e3 100644
--- a/car-apps-common/src/com/android/car/apps/common/MinimizedControlBar.java
+++ b/car-apps-common/src/com/android/car/apps/common/MinimizedControlBar.java
@@ -61,12 +61,17 @@
public MinimizedControlBar(Context context, AttributeSet attrs, int defStyleAttrs) {
- super(context, attrs, defStyleAttrs);
- init(context, attrs, defStyleAttrs);
+ this(context, attrs, defStyleAttrs, R.layout.minimized_control_bar);
}
- private void init(Context context, AttributeSet attrs, int defStyleAttrs) {
- inflate(context, R.layout.minimized_control_bar, this);
+ protected MinimizedControlBar(Context context, AttributeSet attrs, int defStyleAttrs,
+ int layoutId) {
+ super(context, attrs, defStyleAttrs);
+ init(context, layoutId);
+ }
+
+ private void init(Context context, int layoutId) {
+ inflate(context, layoutId, this);
mViews = new View[NUM_COLUMNS];
mTitle = findViewById(R.id.minimized_control_bar_title);
mSubtitle = findViewById(R.id.minimized_control_bar_subtitle);
diff --git a/car-media-common/res/drawable/minimized_progress_bar_background.xml b/car-media-common/res/drawable/minimized_progress_bar_background.xml
new file mode 100644
index 0000000..c1f45d3
--- /dev/null
+++ b/car-media-common/res/drawable/minimized_progress_bar_background.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2019, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:id="@android:id/background">
+ <shape android:shape="line">
+ <stroke android:width="@dimen/minimized_progress_bar_track_height"/>
+ </shape>
+ </item>
+
+ <item android:id="@android:id/progress">
+ <clip>
+ <shape android:shape="line">
+ <stroke android:width="@dimen/minimized_progress_bar_track_height"/>
+ </shape>
+ </clip>
+ </item>
+
+</layer-list>
diff --git a/car-media-common/res/layout/minimized_playback_control_bar.xml b/car-media-common/res/layout/minimized_playback_control_bar.xml
new file mode 100644
index 0000000..95230a3
--- /dev/null
+++ b/car-media-common/res/layout/minimized_playback_control_bar.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<merge
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <com.android.car.apps.common.MinimizedControlBar
+ android:id="@+id/minimized_control_bar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <ProgressBar
+ android:id="@+id/progress_bar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"
+ android:clickable="false"
+ android:focusable="false"
+ android:progressDrawable="@drawable/minimized_progress_bar_background"
+ android:splitTrack="false"
+ android:progressTint="@color/minimized_progress_bar_highlight"
+ android:progressBackgroundTint="@color/minimized_progress_bar_background"
+ android:background="@null"/>
+
+</merge>
diff --git a/car-media-common/res/values/colors.xml b/car-media-common/res/values/colors.xml
index 2c6f5c4..b5ada0f 100644
--- a/car-media-common/res/values/colors.xml
+++ b/car-media-common/res/values/colors.xml
@@ -36,4 +36,9 @@
<!-- Media source's color if not provided -->
<color name="media_source_default_color">@android:color/background_dark</color>
+
+ <!-- Color used on the minimized progress bar background -->
+ <color name="minimized_progress_bar_background">#00000000</color>
+ <!-- Color used on the minimized progress bar -->
+ <color name="minimized_progress_bar_highlight">@color/media_source_default_color</color>
</resources>
diff --git a/car-media-common/res/values/dimens.xml b/car-media-common/res/values/dimens.xml
index 7f69b03..396e02a 100644
--- a/car-media-common/res/values/dimens.xml
+++ b/car-media-common/res/values/dimens.xml
@@ -61,4 +61,7 @@
<!-- fragment_app_selection.xml -->
<dimen name="fragment_app_selection_list_top_offset">@*android:dimen/car_padding_5</dimen>
+
+ <!-- Minimized Progress Bar -->
+ <dimen name="minimized_progress_bar_track_height">4dp</dimen>
</resources>
diff --git a/car-media-common/src/com/android/car/media/common/MinimizedPlaybackControlBar.java b/car-media-common/src/com/android/car/media/common/MinimizedPlaybackControlBar.java
index 4b59890..1555f7a 100644
--- a/car-media-common/src/com/android/car/media/common/MinimizedPlaybackControlBar.java
+++ b/car-media-common/src/com/android/car/media/common/MinimizedPlaybackControlBar.java
@@ -16,13 +16,18 @@
package com.android.car.media.common;
+import static androidx.lifecycle.Transformations.map;
+
import static com.android.car.arch.common.LiveDataFunctions.falseLiveData;
import android.content.Context;
+import android.content.res.ColorStateList;
import android.util.AttributeSet;
+import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
+import androidx.lifecycle.LiveData;
import com.android.car.apps.common.MinimizedControlBar;
import com.android.car.media.common.playback.PlaybackViewModel;
@@ -37,6 +42,9 @@
private MediaButtonController mMediaButtonController;
private MetadataController mMetadataController;
+ private ProgressBar mProgressBar;
+ private PlaybackViewModel mPlaybackViewModel;
+ private LiveData<Long> mMaxProgress;
public MinimizedPlaybackControlBar(Context context) {
this(context, null);
@@ -47,12 +55,13 @@
}
public MinimizedPlaybackControlBar(Context context, AttributeSet attrs, int defStyleAttrs) {
- super(context, attrs, defStyleAttrs);
+ super(context, attrs, defStyleAttrs, R.layout.minimized_playback_control_bar);
init(context);
}
private void init(Context context) {
mMediaButtonController = new MediaButtonController(context, this);
+ mProgressBar = findViewById(R.id.progress_bar);
}
@Override
@@ -62,5 +71,26 @@
falseLiveData(), mTitle, mSubtitle, null, null, null, null, null, null,
mContentTile, getContext().getResources().getDimensionPixelSize(
R.dimen.minimized_control_bar_content_tile_size));
+
+ mPlaybackViewModel = model;
+ if (mProgressBar != null) {
+ mPlaybackViewModel.getMediaSourceColors().observe(owner,
+ sourceColors -> {
+ int defaultColor = getContext().getResources().getColor(
+ R.color.minimized_progress_bar_highlight, null);
+ int color = sourceColors != null ? sourceColors.getAccentColor(defaultColor)
+ : defaultColor;
+ mProgressBar.setProgressTintList(ColorStateList.valueOf(color));
+ });
+
+ // TODO(b/130566861): Get the progress and max progress through Model once Model is
+ // moved out to be a top-level class.
+ mPlaybackViewModel.getProgress().observe(owner,
+ progress -> mProgressBar.setProgress(progress.intValue()));
+ mMaxProgress = map(mPlaybackViewModel.getPlaybackStateWrapper(),
+ state -> state != null ? state.getMaxProgress() : 0L);
+ mMaxProgress.observe(owner,
+ maxProgress -> mProgressBar.setMax(maxProgress.intValue()));
+ }
}
}