RTL UI for stack & manage menu user education

- default start position takes into account RTL
- removed alpha on manage edu UI to match the stack edu UI

Fixes: 158562723
Test: be in RTL, get first bubble => stack edu uses RTL UI & is on right,
      tap on it => manage educaiton is on right
Test: do same for LTR
Test: change layout to LTR & RTL => all expanded views, manage edus update
      direction
Change-Id: I8a482055a54fd306493bbaa96363ef172cf18bb2
This commit is contained in:
Lyn Han
2020-06-16 22:03:01 -07:00
committed by Mady Mellor
parent c5c35fc376
commit 72f6dbdf3d
6 changed files with 107 additions and 17 deletions

View File

@@ -0,0 +1,22 @@
<!--
~ Copyright (C) 2020 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="?android:attr/colorAccent"/>
<corners
android:bottomLeftRadius="360dp"
android:topLeftRadius="360dp" />
</shape>

View File

@@ -31,7 +31,6 @@
android:layout_marginEnd="24dp"
android:orientation="vertical"
android:background="@drawable/bubble_stack_user_education_bg"
android:alpha="0.9"
>
<TextView
@@ -61,6 +60,7 @@
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button_layout"
android:orientation="horizontal" >
<com.android.systemui.statusbar.AlphaOptimizedButton
@@ -73,7 +73,6 @@
android:clickable="false"
android:text="@string/manage_bubbles_text"
android:textColor="?attr/wallpaperTextColor"
android:alpha="0.89"
/>
<com.android.systemui.statusbar.AlphaOptimizedButton
@@ -88,4 +87,4 @@
/>
</LinearLayout>
</LinearLayout>
</com.android.systemui.bubbles.BubbleManageEducationView>
</com.android.systemui.bubbles.BubbleManageEducationView>

View File

@@ -207,6 +207,9 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
*/
private int mDensityDpi = Configuration.DENSITY_DPI_UNDEFINED;
/** Last known direction, used to detect layout direction changes @link #onConfigChanged}. */
private int mLayoutDirection = View.LAYOUT_DIRECTION_UNDEFINED;
private boolean mInflateSynchronously;
// TODO (b/145659174): allow for multiple callbacks to support the "shadow" new notif pipeline
@@ -832,8 +835,10 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
mBubbleIconFactory = new BubbleIconFactory(mContext);
mStackView.onDisplaySizeChanged();
}
mStackView.onLayoutDirectionChanged();
if (newConfig.getLayoutDirection() != mLayoutDirection) {
mLayoutDirection = newConfig.getLayoutDirection();
mStackView.onLayoutDirectionChanged(mLayoutDirection);
}
}
}

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -34,6 +35,8 @@ import com.android.systemui.R;
public class BubbleManageEducationView extends LinearLayout {
private View mManageView;
private TextView mTitleTextView;
private TextView mDescTextView;
public BubbleManageEducationView(Context context) {
this(context, null);
@@ -57,6 +60,8 @@ public class BubbleManageEducationView extends LinearLayout {
super.onFinishInflate();
mManageView = findViewById(R.id.manage_education_view);
mTitleTextView = findViewById(R.id.user_education_title);
mDescTextView = findViewById(R.id.user_education_description);
final TypedArray ta = mContext.obtainStyledAttributes(
new int[] {android.R.attr.colorAccent,
@@ -66,8 +71,8 @@ public class BubbleManageEducationView extends LinearLayout {
ta.recycle();
textColor = ContrastColorUtil.ensureTextContrast(textColor, bgColor, true);
((TextView) findViewById(R.id.user_education_title)).setTextColor(textColor);
((TextView) findViewById(R.id.user_education_description)).setTextColor(textColor);
mTitleTextView.setTextColor(textColor);
mDescTextView.setTextColor(textColor);
}
/**
@@ -84,4 +89,18 @@ public class BubbleManageEducationView extends LinearLayout {
public int getManageViewHeight() {
return mManageView.getHeight();
}
@Override
public void setLayoutDirection(int direction) {
super.setLayoutDirection(direction);
if (getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
mManageView.setBackgroundResource(R.drawable.bubble_stack_user_education_bg_rtl);
mTitleTextView.setGravity(Gravity.RIGHT);
mDescTextView.setGravity(Gravity.RIGHT);
} else {
mManageView.setBackgroundResource(R.drawable.bubble_stack_user_education_bg);
mTitleTextView.setGravity(Gravity.LEFT);
mDescTextView.setGravity(Gravity.LEFT);
}
}
}

View File

@@ -51,7 +51,6 @@ import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.Choreographer;
import android.view.DisplayCutout;
@@ -71,6 +70,7 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.MainThread;
@@ -1107,6 +1107,7 @@ public class BubbleStackView extends FrameLayout
title.setTextColor(textColor);
description.setTextColor(textColor);
updateUserEducationForLayoutDirection();
addView(mUserEducationView);
}
@@ -1123,7 +1124,7 @@ public class BubbleStackView extends FrameLayout
false /* attachToRoot */);
mManageEducationView.setVisibility(GONE);
mManageEducationView.setElevation(mBubbleElevation);
mManageEducationView.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);
addView(mManageEducationView);
}
}
@@ -1205,13 +1206,17 @@ public class BubbleStackView extends FrameLayout
}
/** Tells the views with locale-dependent layout direction to resolve the new direction. */
public void onLayoutDirectionChanged() {
mManageMenu.resolveLayoutDirection();
mFlyout.resolveLayoutDirection();
if (mExpandedBubble != null && mExpandedBubble.getExpandedView() != null) {
mExpandedBubble.getExpandedView().resolveLayoutDirection();
public void onLayoutDirectionChanged(int direction) {
mManageMenu.setLayoutDirection(direction);
mFlyout.setLayoutDirection(direction);
if (mUserEducationView != null) {
mUserEducationView.setLayoutDirection(direction);
updateUserEducationForLayoutDirection();
}
if (mManageEducationView != null) {
mManageEducationView.setLayoutDirection(direction);
}
updateExpandedViewDirection(direction);
}
/** Respond to the display size change by recalculating view size and location. */
@@ -1286,6 +1291,18 @@ public class BubbleStackView extends FrameLayout
});
}
void updateExpandedViewDirection(int direction) {
final List<Bubble> bubbles = mBubbleData.getBubbles();
if (bubbles.isEmpty()) {
return;
}
bubbles.forEach(bubble -> {
if (bubble.getExpandedView() != null) {
bubble.getExpandedView().setLayoutDirection(direction);
}
});
}
void setupLocalMenu(AccessibilityNodeInfo info) {
Resources res = mContext.getResources();
@@ -1633,6 +1650,8 @@ public class BubbleStackView extends FrameLayout
if (mShouldShowUserEducation && mUserEducationView.getVisibility() != VISIBLE) {
mUserEducationView.setAlpha(0);
mUserEducationView.setVisibility(VISIBLE);
updateUserEducationForLayoutDirection();
// Post so we have height of mUserEducationView
mUserEducationView.post(() -> {
final int viewHeight = mUserEducationView.getHeight();
@@ -1650,6 +1669,28 @@ public class BubbleStackView extends FrameLayout
return false;
}
private void updateUserEducationForLayoutDirection() {
if (mUserEducationView == null) {
return;
}
LinearLayout textLayout = mUserEducationView.findViewById(R.id.user_education_view);
TextView title = mUserEducationView.findViewById(R.id.user_education_title);
TextView description = mUserEducationView.findViewById(R.id.user_education_description);
boolean isLtr =
getResources().getConfiguration().getLayoutDirection() == LAYOUT_DIRECTION_LTR;
if (isLtr) {
mUserEducationView.setLayoutDirection(LAYOUT_DIRECTION_LTR);
textLayout.setBackgroundResource(R.drawable.bubble_stack_user_education_bg);
title.setGravity(Gravity.LEFT);
description.setGravity(Gravity.LEFT);
} else {
mUserEducationView.setLayoutDirection(LAYOUT_DIRECTION_RTL);
textLayout.setBackgroundResource(R.drawable.bubble_stack_user_education_bg_rtl);
title.setGravity(Gravity.RIGHT);
description.setGravity(Gravity.RIGHT);
}
}
/**
* If necessary, hides the user education view for the bubble stack.
*

View File

@@ -940,8 +940,12 @@ public class StackAnimationController extends
/** Returns the default stack position, which is on the top left. */
public PointF getDefaultStartPosition() {
return new PointF(
getAllowableStackPositionRegion().left,
boolean isRtl = mLayout != null
&& mLayout.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL;
return new PointF(isRtl
? getAllowableStackPositionRegion().right
: getAllowableStackPositionRegion().left,
getAllowableStackPositionRegion().top + mStackStartingVerticalOffset);
}