Merge "[5/n] Letterbox Education: update the dialog layout."

This commit is contained in:
Tom Natan
2022-02-08 20:32:39 +00:00
committed by Android (Google) Code Review
11 changed files with 102 additions and 115 deletions

View File

@@ -14,11 +14,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:background="@android:color/system_neutral1_900"
android:clickable="true">
</FrameLayout>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/compat_controls_background"/>
<corners android:radius="@dimen/letterbox_education_dialog_corner_radius"/>
</shape>

View File

@@ -16,6 +16,6 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/system_accent1_100"/>
<solid android:color="@color/letterbox_education_accent_primary"/>
<corners android:radius="12dp"/>
</shape>

View File

@@ -14,8 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- DO NOT SUBMIT - find right color!! -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/system_accent1_10">
<item android:drawable="@drawable/letterbox_education_dismiss_background"/>
<item android:drawable="@drawable/letterbox_education_dismiss_button_background"/>
</ripple>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/letterbox_education_dialog_icon_size"
android:height="@dimen/letterbox_education_dialog_icon_size"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="@color/letterbox_education_accent_primary"
android:fillType="evenOdd"
android:pathData="M2 8C0.895431 8 0 8.89543 0 10V38C0 39.1046 0.895431 40 2 40H46C47.1046 40 48 39.1046 48 38V10C48 8.89543 47.1046 8 46 8H2ZM44 12H4V36H44V12Z" />
<path
android:fillColor="@color/letterbox_education_accent_primary"
android:pathData="M 17 14 L 31 14 Q 32 14 32 15 L 32 33 Q 32 34 31 34 L 17 34 Q 16 34 16 33 L 16 15 Q 16 14 17 14 Z" />
</vector>

View File

@@ -13,30 +13,31 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<com.android.wm.shell.compatui.LetterboxEduDialogLayout
<com.android.wm.shell.compatui.letterboxedu.LetterboxEduDialogLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/compat_controls_background"
android:gravity="center"
android:paddingTop="24dp"
android:paddingBottom="32dp"
android:paddingHorizontal="32dp">
android:background="@android:color/system_neutral1_900">
<!-- The background of the top-level layout acts as the background dim. -->
<!-- Adding an extra layer to animate the alpha of the background and content separately. -->
<LinearLayout
android:id="@+id/letterbox_education_content"
android:id="@+id/letterbox_education_dialog_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical">
android:orientation="vertical"
android:background="@drawable/letterbox_education_dialog_background"
android:padding="24dp">
<ImageView
android:id="@+id/letterbox_education_icon"
android:layout_width="@dimen/letterbox_education_dialog_icon_size"
android:layout_height="@dimen/letterbox_education_dialog_icon_size"
android:layout_marginBottom="20dp" />
android:layout_marginBottom="12dp"
android:src="@drawable/letterbox_education_ic_letterboxed_app"/>
<TextView
android:id="@+id/letterbox_education_dialog_title"
@@ -44,50 +45,50 @@
android:layout_height="wrap_content"
android:maxWidth="@dimen/letterbox_education_dialog_title_max_width"
android:lineSpacingExtra="4sp"
android:text="@string/letterbox_education_dialog_title"
android:textAlignment="center"
android:textColor="@color/compat_controls_text"
android:textSize="24sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxWidth="@dimen/letterbox_education_dialog_title_max_width"
android:lineSpacingExtra="4sp"
android:text="@string/letterbox_education_dialog_subtext"
android:textAlignment="center"
android:textColor="@color/letterbox_education_text_secondary"
android:textSize="14sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="horizontal"
android:paddingTop="43dp">
android:paddingTop="48dp">
<com.android.wm.shell.compatui.letterboxedu.LetterboxEduDialogActionLayout
android:id="@+id/letterbox_education_dialog_screen_rotation_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/letterbox_education_ic_screen_rotation"/>
app:icon="@drawable/letterbox_education_ic_screen_rotation"
app:text="@string/letterbox_education_screen_rotation_text"/>
<com.android.wm.shell.compatui.letterboxedu.LetterboxEduDialogActionLayout
android:id="@+id/letterbox_education_dialog_split_screen_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/letterbox_education_dialog_space_between_actions"
app:icon="@drawable/letterbox_education_ic_split_screen"
app:text="@string/letterbox_education_split_screen_text"/>
<com.android.wm.shell.compatui.letterboxedu.LetterboxEduDialogActionLayout
android:id="@+id/letterbox_education_dialog_reposition_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginStart="@dimen/letterbox_education_dialog_space_between_actions"
app:icon="@drawable/letterbox_education_ic_reposition"
app:text="@string/letterbox_education_reposition_text"/>
</LinearLayout>
<Button
android:id="@+id/letterbox_education_dialog_dismiss"
android:id="@+id/letterbox_education_dialog_dismiss_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginTop="43dp"
android:layout_marginHorizontal="24dp"
android:background="@drawable/letterbox_education_dismiss_background_ripple"
android:gravity="center"
android:layout_marginTop="48dp"
android:background="@drawable/letterbox_education_dismiss_button_background_ripple"
android:text="@string/letterbox_education_got_it"
android:textColor="@android:color/system_neutral1_900"
android:textAlignment="center"
@@ -95,4 +96,4 @@
</LinearLayout>
</com.android.wm.shell.compatui.LetterboxEduDialogLayout>
</com.android.wm.shell.compatui.letterboxedu.LetterboxEduDialogLayout>

View File

@@ -35,6 +35,7 @@
<color name="compat_controls_text">@android:color/system_neutral1_50</color>
<!-- Letterbox Education -->
<color name="letterbox_education_accent_primary">@android:color/system_accent1_100</color>
<color name="letterbox_education_text_secondary">@android:color/system_neutral2_200</color>
<!-- GM2 colors -->

View File

@@ -226,18 +226,14 @@
<dimen name="letterbox_education_dialog_icon_size">48dp</dimen>
<!-- The width of each action container in the letterbox education dialog -->
<dimen name="letterbox_education_dialog_action_width">136dp</dimen>
<dimen name="letterbox_education_dialog_action_width">140dp</dimen>
<!-- The space between two actions in the letterbox education dialog -->
<dimen name="letterbox_education_dialog_space_between_actions">18dp</dimen>
<dimen name="letterbox_education_dialog_space_between_actions">24dp</dimen>
<!-- The maximum width of the title and subtitle in the letterbox education dialog. -->
<dimen name="letterbox_education_dialog_title_max_width">444dp</dimen>
<!-- The distance that the letterbox education dialog will move up during appear/dismiss
animation. -->
<dimen name="letterbox_education_dialog_animation_elevation">20dp</dimen>
<!-- The width of the brand image on staring surface. -->
<dimen name="starting_surface_brand_image_width">200dp</dimen>

View File

@@ -172,19 +172,16 @@
<string name="camera_compat_dismiss_button_description">No camera issues? Tap to dismiss.</string>
<!-- The title of the letterbox education dialog. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_dialog_title">Get the most out of <xliff:g id="app_name" example="YouTube">%s</xliff:g></string>
<string name="letterbox_education_dialog_title">Some apps work best in portrait</string>
<!-- Description of the rotate screen into portrait action. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_screen_rotation_portrait_text">Rotate your screen to portrait</string>
<!-- The subtext of the letterbox education dialog. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_dialog_subtext">Try one of these options to make the most of your space</string>
<!-- Description of the rotate screen into landscape action. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_screen_rotation_landscape_text">Rotate your screen to landscape</string>
<!-- Description of the put app in split-screen action. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_split_screen_text">Drag in another app to use split screen</string>
<!-- Description of the rotate screen action. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_screen_rotation_text">Rotate your device to go full screen</string>
<!-- Description of the reposition app action. [CHAR LIMIT=NONE] -->
<string name="letterbox_education_reposition_text">Double tap to reposition</string>
<string name="letterbox_education_reposition_text">Double-tap next to an app to reposition it</string>
<!-- Button text for dismissing the letterbox education dialog. [CHAR LIMIT=20] -->
<string name="letterbox_education_got_it">Got it</string>

View File

@@ -31,7 +31,7 @@ import com.android.wm.shell.R;
/**
* Container for compat UI controls.
*/
public class CompatUILayout extends LinearLayout {
class CompatUILayout extends LinearLayout {
private CompatUIWindowManager mWindowManager;

View File

@@ -16,7 +16,6 @@
package com.android.wm.shell.compatui.letterboxedu;
import android.annotation.StringRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
@@ -32,8 +31,6 @@ import com.android.wm.shell.R;
*/
// TODO(b/215316431): Add tests
class LetterboxEduDialogActionLayout extends FrameLayout {
private final ImageView mIcon;
private final TextView mText;
LetterboxEduDialogActionLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -46,26 +43,15 @@ class LetterboxEduDialogActionLayout extends FrameLayout {
/* defStyleRes= */ 0);
int iconId = styledAttributes.getResourceId(
R.styleable.LetterboxEduDialogActionLayout_icon, 0);
String optionalText = styledAttributes.getString(
String text = styledAttributes.getString(
R.styleable.LetterboxEduDialogActionLayout_text);
styledAttributes.recycle();
View rootView = inflate(getContext(), R.layout.letterbox_education_dialog_action_layout,
this);
mIcon = rootView.findViewById(R.id.letterbox_education_dialog_action_icon);
mIcon.setImageResource(iconId);
mText = rootView.findViewById(R.id.letterbox_education_dialog_action_text);
if (optionalText != null) {
mText.setText(optionalText);
}
}
void setText(@StringRes int id) {
mText.setText(getResources().getString(id));
}
void setIconRotation(float rotation) {
mIcon.setRotation(rotation);
((ImageView) rootView.findViewById(
R.id.letterbox_education_dialog_action_icon)).setImageResource(iconId);
((TextView) rootView.findViewById(R.id.letterbox_education_dialog_action_text)).setText(
text);
}
}

View File

@@ -17,22 +17,23 @@
package com.android.wm.shell.compatui.letterboxedu;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Configuration.Orientation;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.wm.shell.R;
/**
* Container for Letterbox Education Dialog.
* Container for Letterbox Education Dialog and background dim.
*
* <p>This layout should fill the entire task and the background around the dialog acts as the
* background dim which dismisses the dialog when clicked.
*/
// TODO(b/215316431): Add tests
public class LetterboxEduDialogLayout extends FrameLayout {
class LetterboxEduDialogLayout extends FrameLayout {
// The alpha of a background is a number between 0 (fully transparent) to 255 (fully opaque).
// 204 is simply 255 * 0.8.
private static final int BACKGROUND_DIM_ALPHA = 204;
public LetterboxEduDialogLayout(Context context) {
this(context, null);
@@ -52,43 +53,23 @@ public class LetterboxEduDialogLayout extends FrameLayout {
}
/**
* Register a callback for the dismiss button.
* Register a callback for the dismiss button and background dim.
*
* @param callback The callback to register
*/
void setDismissOnClickListener(Runnable callback) {
findViewById(R.id.letterbox_education_dialog_dismiss).setOnClickListener(
findViewById(R.id.letterbox_education_dialog_dismiss_button).setOnClickListener(
view -> callback.run());
// Clicks on the background dim should also dismiss the dialog.
setOnClickListener(view -> callback.run());
// We add a no-op on-click listener to the dialog container so that clicks on it won't
// propagate to the listener of the layout (which represents the background dim).
findViewById(R.id.letterbox_education_dialog_container).setOnClickListener(view -> {});
}
/**
* Updates the layout with the given app info.
* @param appIcon The name of the app
* @param appIcon The icon of the app
*/
void updateAppInfo(String appName, Drawable appIcon) {
((ImageView) findViewById(R.id.letterbox_education_icon)).setImageDrawable(appIcon);
((TextView) findViewById(R.id.letterbox_education_dialog_title)).setText(
getResources().getString(R.string.letterbox_education_dialog_title, appName));
}
/**
* Updates the layout according to the given orientation.
* @param orientation The orientation of the display
*/
void updateDisplayOrientation(@Orientation int orientation) {
boolean isOrientationPortrait = orientation == Configuration.ORIENTATION_PORTRAIT;
((LetterboxEduDialogActionLayout) findViewById(
R.id.letterbox_education_dialog_screen_rotation_action)).setText(
isOrientationPortrait
? R.string.letterbox_education_screen_rotation_landscape_text
: R.string.letterbox_education_screen_rotation_portrait_text);
if (isOrientationPortrait) {
((LetterboxEduDialogActionLayout) findViewById(
R.id.letterbox_education_dialog_split_screen_action)).setIconRotation(90f);
}
findViewById(R.id.letterbox_education_dialog_reposition_action).setVisibility(
isOrientationPortrait ? View.GONE : View.VISIBLE);
@Override
protected void onFinishInflate() {
super.onFinishInflate();
getBackground().mutate().setAlpha(BACKGROUND_DIM_ALPHA);
}
}