Merge "Add more education tips for widgets. (2/3)" into sc-dev am: 8a8c36cca9 am: f14a4682b6 am: 34419d22e8
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14678271 Change-Id: Ifb87d56cb334e2085de2f8234e4ff079ddc9d1b8
This commit is contained in:
@@ -63,7 +63,8 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
|
||||
TYPE_TASK_MENU,
|
||||
TYPE_OPTIONS_POPUP,
|
||||
TYPE_ICON_SURFACE,
|
||||
TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP
|
||||
TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP,
|
||||
TYPE_WIDGETS_EDUCATION_DIALOG
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface FloatingViewType {}
|
||||
@@ -85,17 +86,19 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
|
||||
public static final int TYPE_ICON_SURFACE = 1 << 13;
|
||||
|
||||
public static final int TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP = 1 << 14;
|
||||
public static final int TYPE_WIDGETS_EDUCATION_DIALOG = 1 << 15;
|
||||
|
||||
public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP
|
||||
| TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET
|
||||
| TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU
|
||||
| TYPE_OPTIONS_POPUP | TYPE_SNACKBAR | TYPE_LISTENER | TYPE_ALL_APPS_EDU
|
||||
| TYPE_ICON_SURFACE | TYPE_DRAG_DROP_POPUP | TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP;
|
||||
| TYPE_ICON_SURFACE | TYPE_DRAG_DROP_POPUP | TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP
|
||||
| TYPE_WIDGETS_EDUCATION_DIALOG;
|
||||
|
||||
// Type of popups which should be kept open during launcher rebind
|
||||
public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET
|
||||
| TYPE_WIDGETS_BOTTOM_SHEET | TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE
|
||||
| TYPE_ALL_APPS_EDU | TYPE_ICON_SURFACE;
|
||||
| TYPE_ALL_APPS_EDU | TYPE_ICON_SURFACE | TYPE_WIDGETS_EDUCATION_DIALOG;
|
||||
|
||||
// Usually we show the back button when a floating view is open. Instead, hide for these types.
|
||||
public static final int TYPE_HIDE_BACK_BUTTON = TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE
|
||||
|
||||
@@ -105,10 +105,6 @@ public class ArrowTipView extends AbstractFloatingView {
|
||||
private void init(Context context) {
|
||||
inflate(context, R.layout.arrow_toast, this);
|
||||
setOrientation(LinearLayout.VERTICAL);
|
||||
View dismissButton = findViewById(R.id.dismiss);
|
||||
dismissButton.setOnClickListener(view -> {
|
||||
handleClose(true);
|
||||
});
|
||||
|
||||
View arrowView = findViewById(R.id.arrow);
|
||||
ViewGroup.LayoutParams arrowLp = arrowView.getLayoutParams();
|
||||
@@ -194,18 +190,18 @@ public class ArrowTipView extends AbstractFloatingView {
|
||||
public ArrowTipView showAtLocation(String text, int arrowXCoord, int yCoord) {
|
||||
ViewGroup parent = mActivity.getDragLayer();
|
||||
@Px int parentViewWidth = parent.getWidth();
|
||||
@Px int textViewWidth = getContext().getResources()
|
||||
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_width);
|
||||
@Px int maxTextViewWidth = getContext().getResources()
|
||||
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_max_width);
|
||||
@Px int minViewMargin = getContext().getResources()
|
||||
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_min_margin);
|
||||
if (parentViewWidth < textViewWidth + 2 * minViewMargin) {
|
||||
if (parentViewWidth < maxTextViewWidth + 2 * minViewMargin) {
|
||||
Log.w(TAG, "Cannot display tip on a small screen of size: " + parentViewWidth);
|
||||
return null;
|
||||
}
|
||||
|
||||
TextView textView = findViewById(R.id.text);
|
||||
textView.setText(text);
|
||||
textView.setWidth(textViewWidth);
|
||||
textView.setMaxWidth(maxTextViewWidth);
|
||||
parent.addView(this);
|
||||
requestLayout();
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.launcher3.views;
|
||||
|
||||
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
|
||||
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
|
||||
/**
|
||||
* Education view about widgets.
|
||||
*/
|
||||
public class WidgetsEduView extends AbstractSlideInView<Launcher> implements Insettable {
|
||||
|
||||
private static final int DEFAULT_CLOSE_DURATION = 200;
|
||||
|
||||
protected static final int FINAL_SCRIM_BG_COLOR = 0x88000000;
|
||||
|
||||
private Rect mInsets = new Rect();
|
||||
private View mEduView;
|
||||
|
||||
|
||||
public WidgetsEduView(Context context, AttributeSet attr) {
|
||||
this(context, attr, 0);
|
||||
}
|
||||
|
||||
public WidgetsEduView(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mContent = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleClose(boolean animate) {
|
||||
handleClose(true, DEFAULT_CLOSE_DURATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isOfType(int type) {
|
||||
return (type & TYPE_WIDGETS_EDUCATION_DIALOG) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mEduView = findViewById(R.id.edu_view);
|
||||
findViewById(R.id.edu_close_button)
|
||||
.setOnClickListener(v -> close(/* animate= */ true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInsets(Rect insets) {
|
||||
int leftInset = insets.left - mInsets.left;
|
||||
int rightInset = insets.right - mInsets.right;
|
||||
int bottomInset = insets.bottom - mInsets.bottom;
|
||||
mInsets.set(insets);
|
||||
setPadding(leftInset, getPaddingTop(), rightInset, 0);
|
||||
mEduView.setPaddingRelative(mEduView.getPaddingStart(),
|
||||
mEduView.getPaddingTop(), mEduView.getPaddingEnd(), bottomInset);
|
||||
}
|
||||
|
||||
private void show() {
|
||||
attachToContainer();
|
||||
animateOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrimColor(Context context) {
|
||||
return FINAL_SCRIM_BG_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
setTranslationShift(mTranslationShift);
|
||||
}
|
||||
|
||||
private void animateOpen() {
|
||||
if (mIsOpen || mOpenCloseAnimator.isRunning()) {
|
||||
return;
|
||||
}
|
||||
mIsOpen = true;
|
||||
mOpenCloseAnimator.setValues(
|
||||
PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
|
||||
mOpenCloseAnimator.setInterpolator(FAST_OUT_SLOW_IN);
|
||||
mOpenCloseAnimator.start();
|
||||
}
|
||||
|
||||
/** Shows widget education dialog. */
|
||||
public static WidgetsEduView showEducationDialog(Launcher launcher) {
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(launcher);
|
||||
WidgetsEduView v = (WidgetsEduView) layoutInflater.inflate(
|
||||
R.layout.widgets_edu, launcher.getDragLayer(), false);
|
||||
v.show();
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,14 @@ import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.PendingAnimation;
|
||||
import com.android.launcher3.compat.AccessibilityManagerCompat;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.views.ArrowTipView;
|
||||
import com.android.launcher3.views.RecyclerViewFastScroller;
|
||||
import com.android.launcher3.views.TopRoundedCornerView;
|
||||
import com.android.launcher3.views.WidgetsEduView;
|
||||
import com.android.launcher3.widget.BaseWidgetSheet;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener;
|
||||
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
|
||||
@@ -79,12 +82,16 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
private static final long DEFAULT_OPEN_DURATION = 267;
|
||||
private static final long FADE_IN_DURATION = 150;
|
||||
private static final long EDUCATION_TIP_DELAY_MS = 200;
|
||||
private static final long EDUCATION_DIALOG_DELAY_MS = 500;
|
||||
private static final float VERTICAL_START_POSITION = 0.3f;
|
||||
// The widget recommendation table can easily take over the entire screen on devices with small
|
||||
// resolution or landscape on phone. This ratio defines the max percentage of content area that
|
||||
// the table can display.
|
||||
private static final float RECOMMENDATION_TABLE_HEIGHT_RATIO = 0.75f;
|
||||
|
||||
private static final String KEY_WIDGETS_EDUCATION_DIALOG_SEEN =
|
||||
"launcher.widgets_education_dialog_seen";
|
||||
|
||||
private final Rect mInsets = new Rect();
|
||||
private final boolean mHasWorkProfile;
|
||||
private final SparseArray<AdapterHolder> mAdapters = new SparseArray();
|
||||
@@ -93,6 +100,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
entry -> mCurrentUser.equals(entry.mPkgItem.user);
|
||||
private final Predicate<WidgetsListBaseEntry> mWorkWidgetsFilter =
|
||||
mPrimaryWidgetsFilter.negate();
|
||||
@Nullable private ArrowTipView mLatestEducationalTip;
|
||||
private final OnLayoutChangeListener mLayoutChangeListenerToShowTips =
|
||||
new OnLayoutChangeListener() {
|
||||
@Override
|
||||
@@ -116,11 +124,12 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
removeOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||
return;
|
||||
}
|
||||
View viewForTip = getViewToShowEducationTip();
|
||||
if (showEducationTipOnViewIfPossible(viewForTip) != null) {
|
||||
mLatestEducationalTip = showEducationTipOnViewIfPossible(getViewToShowEducationTip());
|
||||
if (mLatestEducationalTip != null) {
|
||||
removeOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||
}
|
||||
};
|
||||
|
||||
private final int mTabsHeight;
|
||||
private final int mViewPagerTopPadding;
|
||||
private final int mSearchAndRecommendationContainerBottomMargin;
|
||||
@@ -221,9 +230,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
mSearchAndRecommendationViewHolder.mSearchBar.initialize(
|
||||
mActivityContext.getPopupDataProvider(), /* searchModeListener= */ this);
|
||||
|
||||
if (!hasSeenEducationTip()) {
|
||||
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||
}
|
||||
setUpEducationViewsIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -608,6 +615,10 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
@Override
|
||||
protected void onCloseComplete() {
|
||||
super.onCloseComplete();
|
||||
removeCallbacks(mShowEducationTipTask);
|
||||
if (mLatestEducationalTip != null) {
|
||||
mLatestEducationalTip.close(false);
|
||||
}
|
||||
AccessibilityManagerCompat.sendStateEventToTest(getContext(), NORMAL_STATE_ORDINAL);
|
||||
}
|
||||
|
||||
@@ -680,6 +691,38 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Shows education dialog for widgets. */
|
||||
private WidgetsEduView showEducationDialog() {
|
||||
mActivityContext.getSharedPrefs().edit()
|
||||
.putBoolean(KEY_WIDGETS_EDUCATION_DIALOG_SEEN, true).apply();
|
||||
return WidgetsEduView.showEducationDialog(mActivityContext);
|
||||
}
|
||||
|
||||
/** Returns {@code true} if education dialog has previously been shown. */
|
||||
protected boolean hasSeenEducationDialog() {
|
||||
return mActivityContext.getSharedPrefs()
|
||||
.getBoolean(KEY_WIDGETS_EDUCATION_DIALOG_SEEN, false)
|
||||
|| Utilities.IS_RUNNING_IN_TEST_HARNESS;
|
||||
}
|
||||
|
||||
private void setUpEducationViewsIfNeeded() {
|
||||
if (!hasSeenEducationDialog()) {
|
||||
postDelayed(() -> {
|
||||
WidgetsEduView eduDialog = showEducationDialog();
|
||||
eduDialog.addOnCloseListener(() -> {
|
||||
if (!hasSeenEducationTip()) {
|
||||
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||
// Call #requestLayout() to trigger layout change listener in order to show
|
||||
// arrow tip immediately if there is a widget to show it on.
|
||||
requestLayout();
|
||||
}
|
||||
});
|
||||
}, EDUCATION_DIALOG_DELAY_MS);
|
||||
} else if (!hasSeenEducationTip()) {
|
||||
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||
}
|
||||
}
|
||||
|
||||
/** A holder class for holding adapters & their corresponding recycler view. */
|
||||
private final class AdapterHolder {
|
||||
static final int PRIMARY = 0;
|
||||
|
||||
Reference in New Issue
Block a user