Add a tv bottom sheet to the SystemUI.

Bug: 186720017
Test: manual
Change-Id: I1661f4ad1c07ba80223556f8e864a7e1b7f3678c
This commit is contained in:
Jacqueline Bronger
2021-05-17 08:52:11 +00:00
parent 5c518a0878
commit 2463594fdd
13 changed files with 453 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<set>
<objectAnimator
android:duration="200"
android:propertyName="scaleX"
android:valueFrom="1.0"
android:valueTo="@dimen/bottom_sheet_button_selection_scaled"
android:valueType="floatType"/>
<objectAnimator
android:duration="200"
android:propertyName="scaleY"
android:valueFrom="1.0"
android:valueTo="@dimen/bottom_sheet_button_selection_scaled"
android:valueType="floatType"/>
</set>
</item>
<item android:state_focused="false">
<set>
<objectAnimator
android:duration="200"
android:propertyName="scaleX"
android:valueFrom="@dimen/bottom_sheet_button_selection_scaled"
android:valueTo="1.0"
android:valueType="floatType"/>
<objectAnimator
android:duration="200"
android:propertyName="scaleY"
android:valueFrom="@dimen/bottom_sheet_button_selection_scaled"
android:valueTo="1.0"
android:valueType="floatType"/>
</set>
</item>
</selector>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_quint">
<translate android:fromYDelta="100%"
android:toYDelta="0"
android:duration="900"/>
</set>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_quint">
<translate android:fromYDelta="0"
android:toYDelta="100%"
android:duration="500"/>
</set>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/bottom_sheet_button_background_color_focused"/>
<item android:color="@color/bottom_sheet_button_background_color_unfocused"/>
</selector>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/bottom_sheet_button_text_color_focused"/>
<item android:color="@color/bottom_sheet_button_text_color_unfocused"/>
</selector>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/bottom_sheet_background_color"/>
<corners android:radius="@dimen/bottom_sheet_corner_radius"/>
</shape>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/bottom_sheet_background_color_with_blur"/>
<corners android:radius="@dimen/bottom_sheet_corner_radius"/>
</shape>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/bottom_sheet_button_background_color"/>
<corners android:radius="@dimen/bottom_sheet_button_corner_radius"/>
</shape>

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="@dimen/bottom_sheet_min_height"
android:paddingHorizontal="@dimen/bottom_sheet_padding_horizontal"
android:paddingVertical="@dimen/bottom_sheet_padding_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/bottom_sheet_icon"
android:layout_width="@dimen/bottom_sheet_icon_size"
android:layout_height="@dimen/bottom_sheet_icon_size"
android:layout_gravity="center_vertical"
android:tint="@color/bottom_sheet_icon_color"/>
<ImageView
android:id="@+id/bottom_sheet_second_icon"
android:layout_width="@dimen/bottom_sheet_icon_size"
android:layout_height="@dimen/bottom_sheet_icon_size"
android:layout_marginStart="@dimen/bottom_sheet_icon_margin"
android:layout_gravity="center_vertical"
android:tint="@color/bottom_sheet_icon_color"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/bottom_sheet_padding_horizontal"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/bottom_sheet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_sheet_title_margin_bottom"
android:textAppearance="@style/BottomSheet.TitleText"/>
<TextView
android:id="@+id/bottom_sheet_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_sheet_details_margin_bottom"
android:textAppearance="@style/BottomSheet.BodyText" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="@dimen/bottom_sheet_actions_width"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="@+id/bottom_sheet_positive_button"
style="@style/BottomSheet.ActionItem" />
<Space
android:layout_width="0dp"
android:layout_height="@dimen/bottom_sheet_actions_spacing" />
<Button
android:id="@+id/bottom_sheet_negative_button"
style="@style/BottomSheet.ActionItem" />
</LinearLayout>
</LinearLayout>

View File

@@ -19,4 +19,19 @@
<resources>
<color name="volume_dialog_background_color">#E61F232B</color>
<color name="volume_dialog_background_color_above_blur">#C71F232B</color>
<color name="bottom_sheet_icon_color">#D2E3FC</color>
<color name="bottom_sheet_title_color">#E8F0FE</color>
<color name="bottom_sheet_body_color">#D2E3FC</color>
<color name="bottom_sheet_background_color">#1F232C</color>
<color name="bottom_sheet_background_color_with_blur">#AA1A2734</color>
<color name="bottom_sheet_button_background_color_focused">#E8F0FE</color>
<color name="bottom_sheet_button_background_color_unfocused">#0FE8EAED</color>
<color name="bottom_sheet_button_text_color_focused">#DB202124</color>
<color name="bottom_sheet_button_text_color_unfocused">#B5E8EAED</color>
</resources>

View File

@@ -21,4 +21,27 @@
<dimen name="privacy_chip_icon_margin">3dp</dimen>
<dimen name="privacy_chip_icon_padding">8dp</dimen>
<dimen name="privacy_chip_icon_size">13dp</dimen>
<dimen name="bottom_sheet_padding_horizontal">32dp</dimen>
<dimen name="bottom_sheet_padding_vertical">24dp</dimen>
<dimen name="bottom_sheet_icon_size">42dp</dimen>
<dimen name="bottom_sheet_icon_margin">8dp</dimen>
<dimen name="bottom_sheet_title_margin_bottom">18dp</dimen>
<dimen name="bottom_sheet_details_margin_bottom">8dp</dimen>
<dimen name="bottom_sheet_actions_width">296dp</dimen>
<dimen name="bottom_sheet_actions_spacing">12dp</dimen>
<item name="bottom_sheet_button_selection_scaled" format="float" type="dimen">1.1</item>
<dimen name="bottom_sheet_button_width">232dp</dimen>
<dimen name="bottom_sheet_button_padding_horizontal">20dp</dimen>
<dimen name="bottom_sheet_button_padding_vertical">16dp</dimen>
<dimen name="bottom_sheet_corner_radius">24dp</dimen>
<dimen name="bottom_sheet_button_corner_radius">10dp</dimen>
<dimen name="bottom_sheet_min_height">208dp</dimen>
<dimen name="bottom_sheet_margin">24dp</dimen>
<dimen name="bottom_sheet_background_blur_radius">120dp</dimen>
</resources>

View File

@@ -28,4 +28,34 @@
<item name="android:textColorPrimaryInverse">@color/tv_volume_dialog_accent</item>
<item name="android:dialogCornerRadius">@dimen/volume_dialog_panel_width_half</item>
</style>
<style name="BottomSheet" parent="Theme.Leanback">
<item name="android:windowIsFloating">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimAmount">0.2</item>
</style>
<style name="BottomSheet.TitleText">
<item name="android:textSize">28sp</item>
<item name="android:textColor">@color/bottom_sheet_title_color</item>
</style>
<style name="BottomSheet.BodyText">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/bottom_sheet_body_color</item>
</style>
<style name="BottomSheet.ActionItem">
<item name="android:layout_width">@dimen/bottom_sheet_button_width</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">left|center_vertical</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/bottom_sheet_button_text_color</item>
<item name="android:background">@drawable/bottom_sheet_button_background</item>
<item name="android:paddingHorizontal">@dimen/bottom_sheet_button_padding_horizontal</item>
<item name="android:paddingVertical">@dimen/bottom_sheet_button_padding_vertical</item>
<item name="android:stateListAnimator">@anim/tv_bottom_sheet_button_state_list_animator</item>
</style>
</resources>

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2021 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.
*/
package com.android.systemui.tv;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import com.android.systemui.R;
import java.util.function.Consumer;
/**
* Generic bottom sheet with up to two icons in the beginning and two buttons.
*/
public abstract class TvBottomSheetActivity extends Activity {
private static final String TAG = TvBottomSheetActivity.class.getSimpleName();
private Drawable mBackgroundWithBlur;
private Drawable mBackgroundWithoutBlur;
private final Consumer<Boolean> mBlurConsumer = this::onBlurChanged;
private void onBlurChanged(boolean enabled) {
Log.v(TAG, "blur enabled: " + enabled);
getWindow().setBackgroundDrawable(enabled ? mBackgroundWithBlur : mBackgroundWithoutBlur);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tv_bottom_sheet);
overridePendingTransition(R.anim.tv_bottom_sheet_enter, 0);
mBackgroundWithBlur = getResources()
.getDrawable(R.drawable.bottom_sheet_background_with_blur);
mBackgroundWithoutBlur = getResources().getDrawable(R.drawable.bottom_sheet_background);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
int screenHeight = metrics.heightPixels;
int marginPx = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_margin);
WindowManager.LayoutParams windowParams = getWindow().getAttributes();
windowParams.width = screenWidth - marginPx * 2;
windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
windowParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
windowParams.horizontalMargin = 0f;
windowParams.verticalMargin = (float) marginPx / screenHeight;
windowParams.format = PixelFormat.TRANSPARENT;
windowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
windowParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
windowParams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
getWindow().setAttributes(windowParams);
getWindow().setElevation(getWindow().getElevation() + 5);
getWindow().setBackgroundBlurRadius(getResources().getDimensionPixelSize(
R.dimen.bottom_sheet_background_blur_radius));
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindowManager().addCrossWindowBlurEnabledListener(mBlurConsumer);
}
@Override
public void onDetachedFromWindow() {
getWindowManager().removeCrossWindowBlurEnabledListener(mBlurConsumer);
super.onDetachedFromWindow();
}
@Override
public void finish() {
super.finish();
overridePendingTransition(0, R.anim.tv_bottom_sheet_exit);
}
}