Merge changes I5d1c9e4b,I08154c94 into sc-dev am: 1fbf9200f1 am: e908dbba29

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14899453

Change-Id: Icc45b99bc5daac07ab781ec794748218b3ab9087
This commit is contained in:
Alina Zaidi
2021-06-10 21:16:35 +00:00
committed by Automerger Merge Worker
7 changed files with 176 additions and 46 deletions
+3 -2
View File
@@ -28,13 +28,14 @@
android:padding="16dp" android:padding="16dp"
android:background="@drawable/arrow_toast_rounded_background" android:background="@drawable/arrow_toast_rounded_background"
android:elevation="2dp" android:elevation="2dp"
android:outlineProvider="none"
android:textColor="@color/arrow_tip_view_content" android:textColor="@color/arrow_tip_view_content"
android:textSize="14sp"/> android:textSize="14sp"/>
<View <View
android:id="@+id/arrow" android:id="@+id/arrow"
android:elevation="2dp" android:elevation="2dp"
android:outlineProvider="none"
android:layout_width="@dimen/arrow_toast_arrow_width" android:layout_width="@dimen/arrow_toast_arrow_width"
android:layout_height="8dp" android:layout_height="10dp"/>
android:layout_marginTop="-2dp"/>
</merge> </merge>
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project <!-- Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
+1
View File
@@ -61,6 +61,7 @@
<dimen name="widget_reconfigure_button_padding">6dp</dimen> <dimen name="widget_reconfigure_button_padding">6dp</dimen>
<dimen name="widget_reconfigure_button_margin">32dp</dimen> <dimen name="widget_reconfigure_button_margin">32dp</dimen>
<dimen name="widget_reconfigure_button_size">36dp</dimen> <dimen name="widget_reconfigure_button_size">36dp</dimen>
<dimen name="widget_reconfigure_tip_top_margin">16dp</dimen>
<!-- Fast scroll --> <!-- Fast scroll -->
<dimen name="fastscroll_track_min_width">6dp</dimen> <dimen name="fastscroll_track_min_width">6dp</dimen>
+5
View File
@@ -105,6 +105,11 @@
<!-- Dialog text. This dialog lets a user know how they can use widgets on their phone. <!-- Dialog text. This dialog lets a user know how they can use widgets on their phone.
[CHAR_LIMIT=NONE] --> [CHAR_LIMIT=NONE] -->
<string name="widget_education_content">To get info without opening apps, you can add widgets to your Home screen</string> <string name="widget_education_content">To get info without opening apps, you can add widgets to your Home screen</string>
<!-- Text on an educational tip on widget informing users that they can change widget settings.
[CHAR_LIMIT=NONE] -->
<string name="reconfigurable_widget_education_tip">Tap to change widget settings</string>
<!-- Text on the button that closes the education dialog about widgets. [CHAR_LIMIT=50] --> <!-- Text on the button that closes the education dialog about widgets. [CHAR_LIMIT=50] -->
<string name="widget_education_close_button">Got it</string> <string name="widget_education_close_button">Got it</string>
@@ -24,12 +24,16 @@ import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import com.android.launcher3.accessibility.DragViewStateAnnouncer; import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.logging.InstanceId; import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence; import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.PendingRequestArgs; import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.views.ArrowTipView;
import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.util.WidgetSizes; import com.android.launcher3.widget.util.WidgetSizes;
@@ -42,6 +46,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private static final float DIMMED_HANDLE_ALPHA = 0f; private static final float DIMMED_HANDLE_ALPHA = 0f;
private static final float RESIZE_THRESHOLD = 0.66f; private static final float RESIZE_THRESHOLD = 0.66f;
private static final String KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =
"launcher.reconfigurable_widget_education_tip_seen";
private static final Rect sTmpRect = new Rect(); private static final Rect sTmpRect = new Rect();
private static final int HANDLE_COUNT = 4; private static final int HANDLE_COUNT = 4;
@@ -238,6 +244,15 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
mWidgetView.getAppWidgetId(), mWidgetView.getAppWidgetId(),
Launcher.REQUEST_RECONFIGURE_APPWIDGET); Launcher.REQUEST_RECONFIGURE_APPWIDGET);
}); });
if (!hasSeenReconfigurableWidgetEducationTip()) {
post(() -> {
if (showReconfigurableWidgetEducationTip() != null) {
mLauncher.getSharedPrefs().edit()
.putBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN,
true).apply();
}
});
}
} }
// When we create the resize frame, we first mark all cells as unoccupied. The appropriate // When we create the resize frame, we first mark all cells as unoccupied. The appropriate
@@ -679,4 +694,25 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|| keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END || keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END
|| keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN); || keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN);
} }
@Nullable private ArrowTipView showReconfigurableWidgetEducationTip() {
Rect rect = new Rect();
if (!mReconfigureButton.getGlobalVisibleRect(rect)) {
return null;
}
@Px int tipMargin = mLauncher.getResources()
.getDimensionPixelSize(R.dimen.widget_reconfigure_tip_top_margin);
return new ArrowTipView(mLauncher, /* isPointingUp= */ true)
.showAroundRect(
getContext().getString(R.string.reconfigurable_widget_education_tip),
/* arrowXCoord= */ rect.left + mReconfigureButton.getWidth() / 2,
/* rect= */ rect,
/* margin= */ tipMargin);
}
private boolean hasSeenReconfigurableWidgetEducationTip() {
return mLauncher.getSharedPrefs()
.getBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN, false)
|| Utilities.IS_RUNNING_IN_TEST_HARNESS;
}
} }
+120 -35
View File
@@ -17,8 +17,10 @@
package com.android.launcher3.views; package com.android.launcher3.views;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.graphics.CornerPathEffect; import android.graphics.CornerPathEffect;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.ShapeDrawable;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
@@ -53,9 +55,10 @@ public class ArrowTipView extends AbstractFloatingView {
protected final BaseDraggingActivity mActivity; protected final BaseDraggingActivity mActivity;
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private final boolean mIsPointingUp;
private final int mArrowWidth; private final int mArrowWidth;
private boolean mIsPointingUp;
private Runnable mOnClosed; private Runnable mOnClosed;
private View mArrowView;
public ArrowTipView(Context context) { public ArrowTipView(Context context) {
this(context, false); this(context, false);
@@ -73,6 +76,9 @@ public class ArrowTipView extends AbstractFloatingView {
public boolean onControllerInterceptTouchEvent(MotionEvent ev) { public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (ev.getAction() == MotionEvent.ACTION_DOWN) {
close(true); close(true);
if (mActivity.getDragLayer().isEventOverView(this, ev)) {
return true;
}
} }
return false; return false;
} }
@@ -106,24 +112,8 @@ public class ArrowTipView extends AbstractFloatingView {
inflate(context, R.layout.arrow_toast, this); inflate(context, R.layout.arrow_toast, this);
setOrientation(LinearLayout.VERTICAL); setOrientation(LinearLayout.VERTICAL);
View arrowView = findViewById(R.id.arrow); mArrowView = findViewById(R.id.arrow);
ViewGroup.LayoutParams arrowLp = arrowView.getLayoutParams(); updateArrowTipInView();
ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
arrowLp.width, arrowLp.height, mIsPointingUp));
Paint arrowPaint = arrowDrawable.getPaint();
arrowPaint.setColor(ContextCompat.getColor(getContext(), R.color.arrow_tip_view_bg));
// The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
arrowPaint.setPathEffect(new CornerPathEffect(
context.getResources().getDimension(R.dimen.arrow_toast_corner_radius)));
arrowView.setBackground(arrowDrawable);
if (mIsPointingUp) {
removeView(arrowView);
addView(arrowView, 0);
}
mIsOpen = true;
mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
} }
/** /**
@@ -136,10 +126,10 @@ public class ArrowTipView extends AbstractFloatingView {
/** /**
* Show the ArrowTipView (tooltip) center, start, or end aligned. * Show the ArrowTipView (tooltip) center, start, or end aligned.
* *
* @param text The text to be shown in the tooltip. * @param text The text to be shown in the tooltip.
* @param gravity The gravity aligns the tooltip center, start, or end. * @param gravity The gravity aligns the tooltip center, start, or end.
* @param arrowMarginStart The margin from start to place arrow (ignored if center) * @param arrowMarginStart The margin from start to place arrow (ignored if center)
* @param top The Y coordinate of the bottom of tooltip. * @param top The Y coordinate of the bottom of tooltip.
* @return The tooltip. * @return The tooltip.
*/ */
public ArrowTipView show(String text, int gravity, int arrowMarginStart, int top) { public ArrowTipView show(String text, int gravity, int arrowMarginStart, int top) {
@@ -149,8 +139,7 @@ public class ArrowTipView extends AbstractFloatingView {
DragLayer.LayoutParams params = (DragLayer.LayoutParams) getLayoutParams(); DragLayer.LayoutParams params = (DragLayer.LayoutParams) getLayoutParams();
params.gravity = gravity; params.gravity = gravity;
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) findViewById( LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mArrowView.getLayoutParams();
R.id.arrow).getLayoutParams();
lp.gravity = gravity; lp.gravity = gravity;
if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) { if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
@@ -166,6 +155,9 @@ public class ArrowTipView extends AbstractFloatingView {
params.leftMargin = mActivity.getDeviceProfile().workspacePadding.left; params.leftMargin = mActivity.getDeviceProfile().workspacePadding.left;
params.rightMargin = mActivity.getDeviceProfile().workspacePadding.right; params.rightMargin = mActivity.getDeviceProfile().workspacePadding.right;
post(() -> setY(top - (mIsPointingUp ? 0 : getHeight()))); post(() -> setY(top - (mIsPointingUp ? 0 : getHeight())));
mIsOpen = true;
mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
setAlpha(0); setAlpha(0);
animate() animate()
.alpha(1f) .alpha(1f)
@@ -178,18 +170,61 @@ public class ArrowTipView extends AbstractFloatingView {
} }
/** /**
* Show the ArrowTipView (tooltip) custom aligned. * Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
* cannot fit on screen in the requested orientation.
* *
* @param text The text to be shown in the tooltip. * @param text The text to be shown in the tooltip.
* @param arrowXCoord The X coordinate for the arrow on the tip. The arrow is usually in the * @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
* center of ArrowTipView unless the ArrowTipView goes beyond screen margin. * center of tooltip unless the tooltip goes beyond screen margin.
* @param yCoord The Y coordinate of the bottom of the tooltip. * @param yCoord The Y coordinate of the pointed tip end of the tooltip.
* @return The tool tip view. * @return The tool tip view. {@code null} if the tip can not be shown.
*/ */
@Nullable @Nullable public ArrowTipView showAtLocation(String text, @Px int arrowXCoord, @Px int yCoord) {
public ArrowTipView showAtLocation(String text, int arrowXCoord, int yCoord) { return showAtLocation(
text,
arrowXCoord,
/* yCoordDownPointingTip= */ yCoord,
/* yCoordUpPointingTip= */ yCoord);
}
/**
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
* cannot fit on screen in the requested orientation.
*
* @param text The text to be shown in the tooltip.
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
* center of tooltip unless the tooltip goes beyond screen margin.
* @param rect The coordinates of the view which requests the tooltip to be shown.
* @param margin The margin between {@param rect} and the tooltip.
* @return The tool tip view. {@code null} if the tip can not be shown.
*/
@Nullable public ArrowTipView showAroundRect(
String text, @Px int arrowXCoord, Rect rect, @Px int margin) {
return showAtLocation(
text,
arrowXCoord,
/* yCoordDownPointingTip= */ rect.top - margin,
/* yCoordUpPointingTip= */ rect.bottom + margin);
}
/**
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
* cannot fit on screen in the requested orientation.
*
* @param text The text to be shown in the tooltip.
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
* center of tooltip unless the tooltip goes beyond screen margin.
* @param yCoordDownPointingTip The Y coordinate of the pointed tip end of the tooltip when the
* tooltip is placed pointing downwards.
* @param yCoordUpPointingTip The Y coordinate of the pointed tip end of the tooltip when the
* tooltip is placed pointing upwards.
* @return The tool tip view. {@code null} if the tip can not be shown.
*/
@Nullable private ArrowTipView showAtLocation(String text, @Px int arrowXCoord,
@Px int yCoordDownPointingTip, @Px int yCoordUpPointingTip) {
ViewGroup parent = mActivity.getDragLayer(); ViewGroup parent = mActivity.getDragLayer();
@Px int parentViewWidth = parent.getWidth(); @Px int parentViewWidth = parent.getWidth();
@Px int parentViewHeight = parent.getHeight();
@Px int maxTextViewWidth = getContext().getResources() @Px int maxTextViewWidth = getContext().getResources()
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_max_width); .getDimensionPixelSize(R.dimen.widget_picker_education_tip_max_width);
@Px int minViewMargin = getContext().getResources() @Px int minViewMargin = getContext().getResources()
@@ -206,22 +241,45 @@ public class ArrowTipView extends AbstractFloatingView {
requestLayout(); requestLayout();
post(() -> { post(() -> {
// Adjust the tooltip horizontally.
float halfWidth = getWidth() / 2f; float halfWidth = getWidth() / 2f;
float xCoord; float xCoord;
if (arrowXCoord - halfWidth < minViewMargin) { if (arrowXCoord - halfWidth < minViewMargin) {
// If the tooltip is estimated to go beyond the left margin, place its start just at
// the left margin.
xCoord = minViewMargin; xCoord = minViewMargin;
} else if (arrowXCoord + halfWidth > parentViewWidth - minViewMargin) { } else if (arrowXCoord + halfWidth > parentViewWidth - minViewMargin) {
// If the tooltip is estimated to go beyond the right margin, place it such that its
// end is just at the right margin.
xCoord = parentViewWidth - minViewMargin - getWidth(); xCoord = parentViewWidth - minViewMargin - getWidth();
} else { } else {
// Place the tooltip such that its center is at arrowXCoord.
xCoord = arrowXCoord - halfWidth; xCoord = arrowXCoord - halfWidth;
} }
setX(xCoord); setX(xCoord);
setY(yCoord - getHeight());
View arrowView = findViewById(R.id.arrow); // Adjust the tooltip vertically.
arrowView.setX(arrowXCoord - xCoord - arrowView.getWidth() / 2f); @Px int viewHeight = getHeight();
if (mIsPointingUp
? (yCoordUpPointingTip + viewHeight > parentViewHeight)
: (yCoordDownPointingTip - viewHeight < 0)) {
// Flip the view if it exceeds the vertical bounds of screen.
mIsPointingUp = !mIsPointingUp;
updateArrowTipInView();
}
// Place the tooltip such that its top is at yCoordUpPointingTip if arrow is displayed
// pointing upwards, otherwise place it such that its bottom is at
// yCoordDownPointingTip.
setY(mIsPointingUp ? yCoordUpPointingTip : yCoordDownPointingTip - viewHeight);
// Adjust the arrow's relative position on tooltip to make sure the actual position of
// arrow's pointed tip is always at arrowXCoord.
mArrowView.setX(arrowXCoord - xCoord - mArrowView.getWidth() / 2f);
requestLayout(); requestLayout();
}); });
mIsOpen = true;
mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
setAlpha(0); setAlpha(0);
animate() animate()
.alpha(1f) .alpha(1f)
@@ -233,6 +291,27 @@ public class ArrowTipView extends AbstractFloatingView {
return this; return this;
} }
private void updateArrowTipInView() {
ViewGroup.LayoutParams arrowLp = mArrowView.getLayoutParams();
ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
arrowLp.width, arrowLp.height, mIsPointingUp));
Paint arrowPaint = arrowDrawable.getPaint();
@Px int arrowTipRadius = getContext().getResources()
.getDimensionPixelSize(R.dimen.arrow_toast_corner_radius);
arrowPaint.setColor(ContextCompat.getColor(getContext(), R.color.arrow_tip_view_bg));
arrowPaint.setPathEffect(new CornerPathEffect(arrowTipRadius));
mArrowView.setBackground(arrowDrawable);
// Add negative margin so that the rounded corners on base of arrow are not visible.
removeView(mArrowView);
if (mIsPointingUp) {
addView(mArrowView, 0);
((ViewGroup.MarginLayoutParams) arrowLp).setMargins(0, 0, 0, -1 * arrowTipRadius);
} else {
addView(mArrowView, 1);
((ViewGroup.MarginLayoutParams) arrowLp).setMargins(0, -1 * arrowTipRadius, 0, 0);
}
}
/** /**
* Register a callback fired when toast is hidden * Register a callback fired when toast is hidden
*/ */
@@ -240,4 +319,10 @@ public class ArrowTipView extends AbstractFloatingView {
mOnClosed = runnable; mOnClosed = runnable;
return this; return this;
} }
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
close(/* animate= */ false);
}
} }
@@ -207,16 +207,18 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
if (view == null || !ViewCompat.isLaidOut(view)) { if (view == null || !ViewCompat.isLaidOut(view)) {
return null; return null;
} }
mActivityContext.getSharedPrefs().edit()
.putBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, true).apply();
int[] coords = new int[2]; int[] coords = new int[2];
view.getLocationOnScreen(coords); view.getLocationOnScreen(coords);
ArrowTipView arrowTipView = new ArrowTipView(mActivityContext); ArrowTipView arrowTipView =
return arrowTipView.showAtLocation( new ArrowTipView(mActivityContext, /* isPointingUp= */ false).showAtLocation(
getContext().getString(R.string.long_press_widget_to_add), getContext().getString(R.string.long_press_widget_to_add),
/* arrowXCoord= */coords[0] + view.getWidth() / 2, /* arrowXCoord= */coords[0] + view.getWidth() / 2,
/* yCoord= */coords[1]); /* yCoord= */coords[1]);
if (arrowTipView != null) {
mActivityContext.getSharedPrefs().edit()
.putBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, true).apply();
}
return arrowTipView;
} }
/** Returns {@code true} if tip has previously been shown on any of {@link BaseWidgetSheet}. */ /** Returns {@code true} if tip has previously been shown on any of {@link BaseWidgetSheet}. */