Merge "Import translations. DO NOT MERGE" into ub-launcher3-qt-dev
diff --git a/quickstep/recents_ui_overrides/res/layout/proactive_hints_container.xml b/quickstep/recents_ui_overrides/res/layout/proactive_hints_container.xml
deleted file mode 100644
index be3f17a..0000000
--- a/quickstep/recents_ui_overrides/res/layout/proactive_hints_container.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<com.android.quickstep.hints.ProactiveHintsContainer
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|bottom"
- android:gravity="center_horizontal">
-</com.android.quickstep.hints.ProactiveHintsContainer>
\ No newline at end of file
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
index 097ff46..3ace25a 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
@@ -547,6 +547,10 @@
(mSystemUiStateFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0, base,
mInputMonitorCompat, mSwipeTouchRegion);
}
+ } else {
+ if ((mSystemUiStateFlags & SYSUI_STATE_SCREEN_PINNING) != 0) {
+ base = mResetGestureInputConsumer;
+ }
}
return base;
}
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java
index 5aab944..7fac813 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java
@@ -18,9 +18,11 @@
import static android.provider.Settings.ACTION_APP_USAGE_SETTINGS;
+import static com.android.launcher3.Utilities.prefixTextWithIcon;
+
+import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
-import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps.AppUsageLimit;
@@ -28,16 +30,16 @@
import android.icu.text.MeasureFormat.FormatWidth;
import android.icu.util.Measure;
import android.icu.util.MeasureUnit;
+import android.os.Build;
import android.os.UserHandle;
-import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
-import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.StringRes;
import com.android.launcher3.BaseActivity;
+import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -46,45 +48,72 @@
import java.time.Duration;
import java.util.Locale;
-public final class DigitalWellBeingToast extends LinearLayout {
+@TargetApi(Build.VERSION_CODES.Q)
+public final class DigitalWellBeingToast {
static final Intent OPEN_APP_USAGE_SETTINGS_TEMPLATE = new Intent(ACTION_APP_USAGE_SETTINGS);
static final int MINUTE_MS = 60000;
- private final LauncherApps mLauncherApps;
-
- public interface InitializeCallback {
- void call(String contentDescription);
- }
private static final String TAG = DigitalWellBeingToast.class.getSimpleName();
+ private final BaseDraggingActivity mActivity;
+ private final TaskView mTaskView;
+ private final LauncherApps mLauncherApps;
+
private Task mTask;
- private TextView mText;
+ private boolean mHasLimit;
+ private long mAppRemainingTimeMs;
- public DigitalWellBeingToast(Context context, AttributeSet attrs) {
- super(context, attrs);
- setLayoutDirection(Utilities.isRtl(getResources()) ?
- View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
- setOnClickListener((view) -> openAppUsageSettings());
- mLauncherApps = context.getSystemService(LauncherApps.class);
+ public DigitalWellBeingToast(BaseDraggingActivity activity, TaskView taskView) {
+ mActivity = activity;
+ mTaskView = taskView;
+ mLauncherApps = activity.getSystemService(LauncherApps.class);
}
- public TextView getTextView() {
- return mText;
+ private void setTaskFooter(View view) {
+ View oldFooter = mTaskView.setFooter(TaskView.INDEX_DIGITAL_WELLBEING_TOAST, view);
+ if (oldFooter != null) {
+ oldFooter.setOnClickListener(null);
+ mActivity.getViewCache().recycleView(R.layout.digital_wellbeing_toast, oldFooter);
+ }
}
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
-
- mText = findViewById(R.id.digital_well_being_remaining_time);
+ private void setNoLimit() {
+ mHasLimit = false;
+ mTaskView.setContentDescription(mTask.titleDescription);
+ setTaskFooter(null);
+ mAppRemainingTimeMs = 0;
}
- public void initialize(Task task, InitializeCallback callback) {
+ private void setLimit(long appUsageLimitTimeMs, long appRemainingTimeMs) {
+ mAppRemainingTimeMs = appRemainingTimeMs;
+ mHasLimit = true;
+ TextView toast = mActivity.getViewCache().getView(R.layout.digital_wellbeing_toast,
+ mActivity, mTaskView);
+ toast.setText(prefixTextWithIcon(mActivity, R.drawable.ic_hourglass_top, getText()));
+ toast.setOnClickListener(this::openAppUsageSettings);
+ setTaskFooter(toast);
+
+ mTaskView.setContentDescription(
+ getContentDescriptionForTask(mTask, appUsageLimitTimeMs, appRemainingTimeMs));
+ RecentsView rv = mTaskView.getRecentsView();
+ if (rv != null) {
+ rv.onDigitalWellbeingToastShown();
+ }
+ }
+
+ public String getText() {
+ return getText(mAppRemainingTimeMs);
+ }
+
+ public boolean hasLimit() {
+ return mHasLimit;
+ }
+
+ public void initialize(Task task) {
mTask = task;
if (task.key.userId != UserHandle.myUserId()) {
- setVisibility(GONE);
- callback.call(task.titleDescription);
+ setNoLimit();
return;
}
@@ -98,16 +127,12 @@
final long appRemainingTimeMs =
usageLimit != null ? usageLimit.getUsageRemaining() : -1;
- post(() -> {
+ mTaskView.post(() -> {
if (appUsageLimitTimeMs < 0 || appRemainingTimeMs < 0) {
- setVisibility(GONE);
+ setNoLimit();
} else {
- setVisibility(VISIBLE);
- mText.setText(getText(appRemainingTimeMs));
+ setLimit(appUsageLimitTimeMs, appRemainingTimeMs);
}
-
- callback.call(getContentDescriptionForTask(
- task, appUsageLimitTimeMs, appRemainingTimeMs));
});
});
}
@@ -146,7 +171,7 @@
// Use a specific string for usage less than one minute but non-zero.
if (duration.compareTo(Duration.ZERO) > 0) {
- return getResources().getString(durationLessThanOneMinuteStringId);
+ return mActivity.getString(durationLessThanOneMinuteStringId);
}
// Otherwise, return 0-minute string.
@@ -176,24 +201,24 @@
}
private String getText(long remainingTime) {
- return getResources().getString(
+ return mActivity.getString(
R.string.time_left_for_app,
getRoundedUpToMinuteReadableDuration(remainingTime));
}
- public void openAppUsageSettings() {
+ public void openAppUsageSettings(View view) {
final Intent intent = new Intent(OPEN_APP_USAGE_SETTINGS_TEMPLATE)
.putExtra(Intent.EXTRA_PACKAGE_NAME,
mTask.getTopComponent().getPackageName()).addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
try {
- final BaseActivity activity = BaseActivity.fromContext(getContext());
+ final BaseActivity activity = BaseActivity.fromContext(view.getContext());
final ActivityOptions options = ActivityOptions.makeScaleUpAnimation(
- this, 0, 0,
- getWidth(), getHeight());
+ view, 0, 0,
+ view.getWidth(), view.getHeight());
activity.startActivity(intent, options.toBundle());
activity.getUserEventDispatcher().logActionOnControl(LauncherLogProto.Action.Touch.TAP,
- LauncherLogProto.ControlType.APP_USAGE_SETTINGS, this);
+ LauncherLogProto.ControlType.APP_USAGE_SETTINGS, view);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Failed to open app usage settings for task "
+ mTask.getTopComponent().getPackageName(), e);
@@ -203,7 +228,7 @@
private String getContentDescriptionForTask(
Task task, long appUsageLimitTimeMs, long appRemainingTimeMs) {
return appUsageLimitTimeMs >= 0 && appRemainingTimeMs >= 0 ?
- getResources().getString(
+ mActivity.getString(
R.string.task_contents_description_with_remaining_time,
task.titleDescription,
getText(appRemainingTimeMs)) :
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index f66e401..9058e7e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -351,6 +351,9 @@
.getDimensionPixelSize(R.dimen.recents_empty_message_text_padding);
setWillNotDraw(false);
updateEmptyMessage();
+
+ // Initialize quickstep specific cache params here, as this is constructed only once
+ mActivity.getViewCache().setCacheSize(R.layout.digital_wellbeing_toast, 5);
}
public OverScroller getScroller() {
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
index 694d501..e7e4189 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
@@ -27,6 +27,8 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.res.Resources;
@@ -39,6 +41,7 @@
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.Log;
+import android.view.Gravity;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.view.accessibility.AccessibilityNodeInfo;
@@ -145,14 +148,12 @@
};
private final TaskOutlineProvider mOutlineProvider;
- private final FooterOutlineProvider mFooterOutlineProvider;
private Task mTask;
private TaskThumbnailView mSnapshotView;
private TaskMenuView mMenuView;
private IconView mIconView;
- private View mTaskFooterContainer;
- private DigitalWellBeingToast mDigitalWellBeingToast;
+ private final DigitalWellBeingToast mDigitalWellBeingToast;
private float mCurveScale;
private float mFullscreenProgress;
private final FullscreenDrawParams mCurrentFullscreenParams;
@@ -171,6 +172,14 @@
private TaskThumbnailCache.ThumbnailLoadRequest mThumbnailLoadRequest;
private TaskIconCache.IconLoadRequest mIconLoadRequest;
+ // Order in which the footers appear. Lower order appear below higher order.
+ public static final int INDEX_DIGITAL_WELLBEING_TOAST = 0;
+ public static final int INDEX_PROACTIVE_SUGGEST = 1;
+ private final FooterWrapper[] mFooters = new FooterWrapper[2];
+ private float mFooterVerticalOffset = 0;
+ private float mFooterAlpha = 1;
+ private int mStackHeight;
+
public TaskView(Context context) {
this(context, null);
}
@@ -208,8 +217,9 @@
mCornerRadius = TaskCornerRadius.get(context);
mWindowCornerRadius = QuickStepContract.getWindowCornerRadius(context.getResources());
mCurrentFullscreenParams = new FullscreenDrawParams(mCornerRadius);
+ mDigitalWellBeingToast = new DigitalWellBeingToast(mActivity, this);
+
mOutlineProvider = new TaskOutlineProvider(getResources(), mCurrentFullscreenParams);
- mFooterOutlineProvider = new FooterOutlineProvider(mCurrentFullscreenParams);
setOutlineProvider(mOutlineProvider);
}
@@ -218,10 +228,6 @@
super.onFinishInflate();
mSnapshotView = findViewById(R.id.snapshot);
mIconView = findViewById(R.id.icon);
- mDigitalWellBeingToast = findViewById(R.id.digital_well_being_toast);
- mTaskFooterContainer = findViewById(R.id.task_footer_container);
- mTaskFooterContainer.setOutlineProvider(mFooterOutlineProvider);
- mTaskFooterContainer.setClipToOutline(true);
}
public TaskMenuView getMenuView() {
@@ -357,15 +363,7 @@
if (ENABLE_QUICKSTEP_LIVE_TILE.get() && isRunningTask()) {
getRecentsView().updateLiveTileIcon(task.icon);
}
- mDigitalWellBeingToast.initialize(
- mTask,
- contentDescription -> {
- setContentDescription(contentDescription);
- if (mDigitalWellBeingToast.getVisibility() == VISIBLE
- && getRecentsView() != null) {
- getRecentsView().onDigitalWellbeingToastShown();
- }
- });
+ mDigitalWellBeingToast.initialize(mTask);
});
} else {
mSnapshotView.setThumbnail(null, null);
@@ -424,14 +422,12 @@
mIconView.setScaleX(scale);
mIconView.setScaleY(scale);
- int footerVerticalOffset = (int) (mTaskFooterContainer.getHeight() * (1.0f - scale));
- mTaskFooterContainer.setTranslationY(
- mCurrentFullscreenParams.mCurrentDrawnInsets.bottom +
- mCurrentFullscreenParams.mCurrentDrawnInsets.top +
- footerVerticalOffset);
- mFooterOutlineProvider.setFullscreenDrawParams(
- mCurrentFullscreenParams, footerVerticalOffset);
- mTaskFooterContainer.invalidateOutline();
+ mFooterVerticalOffset = 1.0f - scale;
+ for (FooterWrapper footer : mFooters) {
+ if (footer != null) {
+ footer.updateFooterOffset();
+ }
+ }
}
public void setIconScaleAnimStartProgress(float startProgress) {
@@ -505,8 +501,13 @@
mSnapshotView.setDimAlpha(curveInterpolation * MAX_PAGE_SCRIM_ALPHA);
setCurveScale(getCurveScaleForCurveInterpolation(curveInterpolation));
- float fade = Utilities.boundToRange(1.0f - 2 * scrollState.linearInterpolation, 0f, 1f);
- mTaskFooterContainer.setAlpha(fade);
+ mFooterAlpha = Utilities.boundToRange(1.0f - 2 * scrollState.linearInterpolation, 0f, 1f);
+ for (FooterWrapper footer : mFooters) {
+ if (footer != null) {
+ footer.mView.setAlpha(mFooterAlpha);
+ }
+ }
+
if (mMenuView != null) {
mMenuView.setPosition(getX() - getRecentsView().getScrollX(), getY());
mMenuView.setScaleX(getScaleX());
@@ -514,6 +515,56 @@
}
}
+
+ /**
+ * Sets the footer at the specific index and returns the previously set footer.
+ */
+ public View setFooter(int index, View view) {
+ View oldFooter = null;
+
+ // If the footer are is already collapsed, do not animate entry
+ boolean shouldAnimateEntry = mFooterVerticalOffset <= 0;
+
+ if (mFooters[index] != null) {
+ oldFooter = mFooters[index].mView;
+ mFooters[index].release();
+ removeView(oldFooter);
+
+ // If we are replacing an existing footer, do not animate entry
+ shouldAnimateEntry = false;
+ }
+ if (view != null) {
+ int indexToAdd = getChildCount();
+ for (int i = index - 1; i >= 0; i--) {
+ if (mFooters[i] != null) {
+ indexToAdd = indexOfChild(mFooters[i].mView);
+ break;
+ }
+ }
+
+ addView(view, indexToAdd);
+ ((LayoutParams) view.getLayoutParams()).gravity =
+ Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
+ view.setAlpha(mFooterAlpha);
+ mFooters[index] = new FooterWrapper(view);
+ if (shouldAnimateEntry) {
+ mFooters[index].animateEntry();
+ }
+ } else {
+ mFooters[index] = null;
+ }
+
+ mStackHeight = 0;
+ for (FooterWrapper footer : mFooters) {
+ if (footer != null) {
+ footer.setVerticalShift(mStackHeight);
+ mStackHeight += footer.mExpectedHeight;
+ }
+ }
+
+ return oldFooter;
+ }
+
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
@@ -523,6 +574,18 @@
SYSTEM_GESTURE_EXCLUSION_RECT.get(0).set(0, 0, getWidth(), getHeight());
setSystemGestureExclusionRects(SYSTEM_GESTURE_EXCLUSION_RECT);
}
+
+ mStackHeight = 0;
+ for (FooterWrapper footer : mFooters) {
+ if (footer != null) {
+ mStackHeight += footer.mView.getHeight();
+ }
+ }
+ for (FooterWrapper footer : mFooters) {
+ if (footer != null) {
+ footer.updateFooterOffset();
+ }
+ }
}
public static float getCurveScaleForInterpolation(float linearInterpolation) {
@@ -581,26 +644,74 @@
}
}
- private static final class FooterOutlineProvider extends ViewOutlineProvider {
+ private class FooterWrapper extends ViewOutlineProvider {
- private FullscreenDrawParams mFullscreenDrawParams;
- private int mVerticalOffset;
- private final Rect mOutlineRect = new Rect();
+ final View mView;
+ final ViewOutlineProvider mOldOutlineProvider;
+ final ViewOutlineProvider mDelegate;
- FooterOutlineProvider(FullscreenDrawParams params) {
- mFullscreenDrawParams = params;
+ final int mExpectedHeight;
+ final int mOldPaddingBottom;
+
+ int mAnimationOffset = 0;
+ int mEntryAnimationOffset = 0;
+
+ public FooterWrapper(View view) {
+ mView = view;
+ mOldOutlineProvider = view.getOutlineProvider();
+ mDelegate = mOldOutlineProvider == null
+ ? ViewOutlineProvider.BACKGROUND : mOldOutlineProvider;
+
+ int h = view.getLayoutParams().height;
+ if (h > 0) {
+ mExpectedHeight = h;
+ } else {
+ int m = MeasureSpec.makeMeasureSpec(MeasureSpec.EXACTLY - 1, MeasureSpec.AT_MOST);
+ view.measure(m, m);
+ mExpectedHeight = view.getMeasuredHeight();
+ }
+ mOldPaddingBottom = view.getPaddingBottom();
+
+ if (mOldOutlineProvider != null) {
+ view.setOutlineProvider(this);
+ view.setClipToOutline(true);
+ }
}
- void setFullscreenDrawParams(FullscreenDrawParams params, int verticalOffset) {
- mFullscreenDrawParams = params;
- mVerticalOffset = verticalOffset;
+ public void setVerticalShift(int shift) {
+ mView.setPadding(mView.getPaddingLeft(), mView.getPaddingTop(),
+ mView.getPaddingRight(), mOldPaddingBottom + shift);
}
@Override
public void getOutline(View view, Outline outline) {
- mOutlineRect.set(0, 0, view.getWidth(), view.getHeight());
- mOutlineRect.offset(0, -mVerticalOffset);
- outline.setRoundRect(mOutlineRect, mFullscreenDrawParams.mCurrentDrawnCornerRadius);
+ mDelegate.getOutline(view, outline);
+ outline.offset(0, -mAnimationOffset - mEntryAnimationOffset);
+ }
+
+ void updateFooterOffset() {
+ mAnimationOffset = Math.round(mStackHeight * mFooterVerticalOffset);
+ mView.setTranslationY(mAnimationOffset + mEntryAnimationOffset
+ + mCurrentFullscreenParams.mCurrentDrawnInsets.bottom
+ + mCurrentFullscreenParams.mCurrentDrawnInsets.top);
+ mView.invalidateOutline();
+ }
+
+ void release() {
+ mView.setOutlineProvider(mOldOutlineProvider);
+ setVerticalShift(0);
+ }
+
+ void animateEntry() {
+ ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
+ animator.addUpdateListener(anim -> {
+ float factor = 1 - anim.getAnimatedFraction();
+ int totalShift = mExpectedHeight + mView.getPaddingBottom() - mOldPaddingBottom;
+ mEntryAnimationOffset = Math.round(factor * totalShift);
+ updateFooterOffset();
+ });
+ animator.setDuration(100);
+ animator.start();
}
}
@@ -624,7 +735,7 @@
}
}
- if (mDigitalWellBeingToast.getVisibility() == VISIBLE) {
+ if (mDigitalWellBeingToast.hasLimit()) {
info.addAction(
new AccessibilityNodeInfo.AccessibilityAction(
R.string.accessibility_app_usage_settings,
@@ -648,7 +759,7 @@
}
if (action == R.string.accessibility_app_usage_settings) {
- mDigitalWellBeingToast.openAppUsageSettings();
+ mDigitalWellBeingToast.openAppUsageSettings(this);
return true;
}
diff --git a/quickstep/res/layout/digital_wellbeing_toast.xml b/quickstep/res/layout/digital_wellbeing_toast.xml
new file mode 100644
index 0000000..83594e4
--- /dev/null
+++ b/quickstep/res/layout/digital_wellbeing_toast.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+-->
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="48dp"
+ android:background="@drawable/bg_wellbeing_toast"
+ android:fontFamily="sans-serif"
+ android:forceHasOverlappingRendering="false"
+ android:gravity="center"
+ android:importantForAccessibility="noHideDescendants"
+ android:textColor="@android:color/white"
+ android:textSize="14sp"/>
\ No newline at end of file
diff --git a/quickstep/res/layout/task.xml b/quickstep/res/layout/task.xml
index 6a595a1..60cfa0c 100644
--- a/quickstep/res/layout/task.xml
+++ b/quickstep/res/layout/task.xml
@@ -25,7 +25,7 @@
android:id="@+id/snapshot"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginTop="@dimen/task_thumbnail_top_margin" />
+ android:layout_marginTop="@dimen/task_thumbnail_top_margin"/>
<com.android.quickstep.views.IconView
android:id="@+id/icon"
@@ -33,47 +33,5 @@
android:layout_height="@dimen/task_thumbnail_icon_size"
android:layout_gravity="top|center_horizontal"
android:focusable="false"
- android:importantForAccessibility="no" />
-
- <LinearLayout
- android:id="@+id/task_footer_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:animateLayoutChanges="true"
- android:forceHasOverlappingRendering="true"
- android:layout_gravity="bottom|center_horizontal">
- <FrameLayout
- android:id="@+id/proactive_suggest_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:visibility="gone"
- />
- <com.android.quickstep.views.DigitalWellBeingToast
- android:id="@+id/digital_well_being_toast"
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:importantForAccessibility="noHideDescendants"
- android:background="@drawable/bg_wellbeing_toast"
- android:gravity="center"
- android:visibility="gone">
- <ImageView
- android:id="@+id/digital_well_being_hourglass"
- android:layout_width="24dp"
- android:layout_height="24dp"
- android:layout_marginEnd="8dp"
- android:src="@drawable/ic_hourglass_top"
- />
- <TextView
- android:id="@+id/digital_well_being_remaining_time"
- android:layout_width="wrap_content"
- android:layout_height="24dp"
- android:fontFamily="sans-serif"
- android:textSize="14sp"
- android:textColor="@android:color/white"
- android:gravity="center_vertical"
- />
- </com.android.quickstep.views.DigitalWellBeingToast>
- </LinearLayout>
+ android:importantForAccessibility="no"/>
</com.android.quickstep.views.TaskView>
\ No newline at end of file
diff --git a/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
index 46161cb..8643160 100644
--- a/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
@@ -59,6 +59,7 @@
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.Interpolators;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.util.MultiValueAlpha;
@@ -182,6 +183,12 @@
mDeviceProfile = dp;
}
+ @Override
+ public boolean supportsAdaptiveIconAnimation() {
+ return hasControlRemoteAppTransitionPermission()
+ && FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM.get();
+ }
+
/**
* @return ActivityOptions with remote animations that controls how the window of the opening
* targets are displayed.
diff --git a/quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java b/quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java
index 70f9c90..0c5a6f5 100644
--- a/quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java
+++ b/quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java
@@ -51,15 +51,15 @@
mLauncher.pressHome();
final DigitalWellBeingToast toast = getToast();
- assertTrue("Toast is not visible", toast.isShown());
- assertEquals("Toast text: ", "5 minutes left today", toast.getTextView().getText());
+ assertTrue("Toast is not visible", toast.hasLimit());
+ assertEquals("Toast text: ", "5 minutes left today", toast.getText());
// Unset time limit for app.
runWithShellPermission(
() -> usageStatsManager.unregisterAppUsageLimitObserver(observerId));
mLauncher.pressHome();
- assertFalse("Toast is visible", getToast().isShown());
+ assertFalse("Toast is visible", getToast().hasLimit());
} finally {
runWithShellPermission(
() -> usageStatsManager.unregisterAppUsageLimitObserver(observerId));
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 2f801e0..7085c60 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -32,6 +32,7 @@
import android.graphics.drawable.Drawable;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.Property;
import android.util.TypedValue;
import android.view.KeyEvent;
@@ -52,6 +53,7 @@
import com.android.launcher3.icons.IconCache.IconLoadRequest;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.model.PackageItemInfo;
+import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.views.ActivityContext;
import java.text.NumberFormat;
@@ -304,6 +306,9 @@
@Override
public boolean onTouchEvent(MotionEvent event) {
+ if (TestProtocol.sDebugTracing) {
+ Log.d(TestProtocol.NO_START_TAG, "BubbleTextView.onTouchEvent " + event);
+ }
// Call the superclass onTouchEvent first, because sometimes it changes the state to
// isPressed() on an ACTION_UP
boolean result = super.onTouchEvent(event);
diff --git a/src/com/android/launcher3/LauncherAppTransitionManager.java b/src/com/android/launcher3/LauncherAppTransitionManager.java
index fb50dfb..4bddc6a 100644
--- a/src/com/android/launcher3/LauncherAppTransitionManager.java
+++ b/src/com/android/launcher3/LauncherAppTransitionManager.java
@@ -51,4 +51,8 @@
}
return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
}
+
+ public boolean supportsAdaptiveIconAnimation() {
+ return false;
+ }
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index cc9bda7..7bdbb95 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -69,6 +69,7 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
import com.android.launcher3.graphics.RotationMode;
+import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutKey;
@@ -562,6 +563,20 @@
return spanned;
}
+ /**
+ * Prefixes a text with the provided icon
+ */
+ public static CharSequence prefixTextWithIcon(Context context, int iconRes, CharSequence msg) {
+ // Update the hint to contain the icon.
+ // Prefix the original hint with two spaces. The first space gets replaced by the icon
+ // using span. The second space is used for a singe space character between the hint
+ // and the icon.
+ SpannableString spanned = new SpannableString(" " + msg);
+ spanned.setSpan(new TintedDrawableSpan(context, iconRes),
+ 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ return spanned;
+ }
+
public static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences(
LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index d68ff44..ea9b077 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -26,6 +26,7 @@
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -625,6 +626,9 @@
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (TestProtocol.sDebugTracing) {
+ Log.d(TestProtocol.NO_START_TAG, "AllAppsContainerView.dispatchTouchEvent " + ev);
+ }
final boolean result = super.dispatchTouchEvent(ev);
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
index 1ff484b..31fcc8c 100644
--- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
+++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java
@@ -20,6 +20,7 @@
import static android.view.View.MeasureSpec.makeMeasureSpec;
import static com.android.launcher3.LauncherState.ALL_APPS_HEADER;
+import static com.android.launcher3.Utilities.prefixTextWithIcon;
import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
import android.content.Context;
@@ -40,6 +41,7 @@
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.allapps.AlphabeticalAppsList;
@@ -89,14 +91,7 @@
mFixedTranslationY = getTranslationY();
mMarginTopAdjusting = mFixedTranslationY - getPaddingTop();
- // Update the hint to contain the icon.
- // Prefix the original hint with two spaces. The first space gets replaced by the icon
- // using span. The second space is used for a singe space character between the hint
- // and the icon.
- SpannableString spanned = new SpannableString(" " + getHint());
- spanned.setSpan(new TintedDrawableSpan(getContext(), R.drawable.ic_allapps_search),
- 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
- setHint(spanned);
+ setHint(prefixTextWithIcon(getContext(), R.drawable.ic_allapps_search, getHint()));
}
@Override
diff --git a/src/com/android/launcher3/graphics/TintedDrawableSpan.java b/src/com/android/launcher3/graphics/TintedDrawableSpan.java
index d719575..0bfc435 100644
--- a/src/com/android/launcher3/graphics/TintedDrawableSpan.java
+++ b/src/com/android/launcher3/graphics/TintedDrawableSpan.java
@@ -32,7 +32,7 @@
public TintedDrawableSpan(Context context, int resourceId) {
super(ALIGN_BOTTOM);
- mDrawable = context.getDrawable(resourceId);
+ mDrawable = context.getDrawable(resourceId).mutate();
mOldTint = 0;
mDrawable.setTint(0);
}
diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java
index f858dc4..85f763d 100644
--- a/src/com/android/launcher3/touch/ItemClickHandler.java
+++ b/src/com/android/launcher3/touch/ItemClickHandler.java
@@ -49,6 +49,7 @@
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.views.FloatingIconView;
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetAddFlowHandler;
@@ -259,6 +260,10 @@
intent.setPackage(null);
}
}
+ if (v != null && launcher.getAppTransitionManager().supportsAdaptiveIconAnimation()) {
+ // Preload the icon to reduce latency b/w swapping the floating view with the original.
+ FloatingIconView.fetchIcon(launcher, v, item, true /* isOpening */);
+ }
launcher.startActivitySafely(v, intent, item, sourceContainer);
}
}
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index 939b0f2..ac152db 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -29,6 +29,7 @@
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.Property;
import android.view.MotionEvent;
import android.view.View;
@@ -240,6 +241,9 @@
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (TestProtocol.sDebugTracing) {
+ Log.d(TestProtocol.NO_START_TAG, "BaseDragLayer.dispatchTouchEvent " + ev);
+ }
switch (ev.getAction()) {
case ACTION_DOWN: {
float x = ev.getX();
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index 339681c..b6c4fed 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -17,6 +17,7 @@
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
import static com.android.launcher3.Utilities.getBadge;
+import static com.android.launcher3.Utilities.getFullDrawable;
import static com.android.launcher3.Utilities.mapToRange;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM;
@@ -42,6 +43,7 @@
import android.os.CancellationSignal;
import android.os.Handler;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
@@ -65,6 +67,7 @@
import com.android.launcher3.shortcuts.DeepShortcutView;
import androidx.annotation.Nullable;
+import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
import androidx.dynamicanimation.animation.FloatPropertyCompat;
import androidx.dynamicanimation.animation.SpringAnimation;
@@ -77,6 +80,11 @@
public class FloatingIconView extends View implements
Animator.AnimatorListener, ClipPathView, OnGlobalLayoutListener {
+ private static final String TAG = FloatingIconView.class.getSimpleName();
+
+ // Manages loading the icon on a worker thread
+ private static @Nullable IconLoadResult sIconLoadResult;
+
public static final float SHAPE_PROGRESS_DURATION = 0.10f;
private static final int FADE_DURATION_MS = 200;
private static final Rect sTmpRect = new Rect();
@@ -126,6 +134,8 @@
private boolean mIsAdaptiveIcon = false;
private boolean mIsOpening;
+ private IconLoadResult mIconLoadResult;
+
private @Nullable Drawable mBadge;
private @Nullable Drawable mForeground;
private @Nullable Drawable mBackground;
@@ -299,8 +309,8 @@
* @param v The view to copy
* @param positionOut Rect that will hold the size and position of v.
*/
- private void matchPositionOf(View v, RectF positionOut) {
- float rotation = getLocationBoundsForView(v, positionOut);
+ private void matchPositionOf(Launcher launcher, View v, boolean isOpening, RectF positionOut) {
+ float rotation = getLocationBoundsForView(launcher, v, isOpening, positionOut);
final LayoutParams lp = new LayoutParams(
Math.round(positionOut.width()),
Math.round(positionOut.height()));
@@ -328,8 +338,9 @@
* - For DeepShortcutView, we return the bounds of the icon view.
* - For BubbleTextView, we return the icon bounds.
*/
- private float getLocationBoundsForView(View v, RectF outRect) {
- boolean ignoreTransform = !mIsOpening;
+ private static float getLocationBoundsForView(Launcher launcher, View v, boolean isOpening,
+ RectF outRect) {
+ boolean ignoreTransform = !isOpening;
if (v instanceof DeepShortcutView) {
v = ((DeepShortcutView) v).getBubbleText();
ignoreTransform = false;
@@ -353,7 +364,7 @@
float[] points = new float[] {iconBounds.left, iconBounds.top, iconBounds.right,
iconBounds.bottom};
float[] rotation = new float[] {0};
- Utilities.getDescendantCoordRelativeToAncestor(v, mLauncher.getDragLayer(), points,
+ Utilities.getDescendantCoordRelativeToAncestor(v, launcher.getDragLayer(), points,
false, ignoreTransform, rotation);
outRect.set(
Math.min(points[0], points[2]),
@@ -363,148 +374,217 @@
return rotation[0];
}
+ /**
+ * Loads the icon and saves the results to {@link #sIconLoadResult}.
+ * Runs onIconLoaded callback (if any), which signifies that the FloatingIconView is
+ * ready to display the icon. Otherwise, the FloatingIconView will grab the results when its
+ * initialized.
+ *
+ * @param originalView The View that the FloatingIconView will replace.
+ * @param info ItemInfo of the originalView
+ * @param pos The position of the view.
+ */
@WorkerThread
@SuppressWarnings("WrongThread")
- private void getIcon(View v, ItemInfo info, boolean isOpening,
- Runnable onIconLoadedRunnable, CancellationSignal loadIconSignal) {
- final LayoutParams lp = (LayoutParams) getLayoutParams();
+ private static void getIconResult(Launcher l, View originalView, ItemInfo info, RectF pos,
+ IconLoadResult iconLoadResult) {
Drawable drawable = null;
+ Drawable badge = null;
boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
- Drawable btvIcon = v instanceof BubbleTextView ? ((BubbleTextView) v).getIcon() : null;
+ Drawable btvIcon = originalView instanceof BubbleTextView
+ ? ((BubbleTextView) originalView).getIcon() : null;
if (info instanceof SystemShortcut) {
- if (v instanceof ImageView) {
- drawable = ((ImageView) v).getDrawable();
- } else if (v instanceof DeepShortcutView) {
- drawable = ((DeepShortcutView) v).getIconView().getBackground();
+ if (originalView instanceof ImageView) {
+ drawable = ((ImageView) originalView).getDrawable();
+ } else if (originalView instanceof DeepShortcutView) {
+ drawable = ((DeepShortcutView) originalView).getIconView().getBackground();
} else {
- drawable = v.getBackground();
+ drawable = originalView.getBackground();
}
} else {
- boolean isFolderIcon = v instanceof FolderIcon;
- int width = isFolderIcon ? v.getWidth() : lp.width;
- int height = isFolderIcon ? v.getHeight() : lp.height;
+ boolean isFolderIcon = originalView instanceof FolderIcon;
+ int width = isFolderIcon ? originalView.getWidth() : (int) pos.width();
+ int height = isFolderIcon ? originalView.getHeight() : (int) pos.height();
if (supportsAdaptiveIcons) {
- drawable = Utilities.getFullDrawable(mLauncher, info, width, height, false,
- sTmpObjArray);
+ drawable = getFullDrawable(l, info, width, height, false, sTmpObjArray);
if (drawable instanceof AdaptiveIconDrawable) {
- mBadge = getBadge(mLauncher, info, sTmpObjArray[0]);
+ badge = getBadge(l, info, sTmpObjArray[0]);
} else {
// The drawable we get back is not an adaptive icon, so we need to use the
// BubbleTextView icon that is already legacy treated.
drawable = btvIcon;
}
} else {
- if (v instanceof BubbleTextView) {
+ if (originalView instanceof BubbleTextView) {
// Similar to DragView, we simply use the BubbleTextView icon here.
drawable = btvIcon;
} else {
- drawable = Utilities.getFullDrawable(mLauncher, info, width, height, false,
- sTmpObjArray);
+ drawable = getFullDrawable(l, info, width, height, false, sTmpObjArray);
}
}
}
- Drawable finalDrawable = drawable == null ? null
- : drawable.getConstantState().newDrawable();
- boolean isAdaptiveIcon = supportsAdaptiveIcons
- && finalDrawable instanceof AdaptiveIconDrawable;
- int iconOffset = getOffsetForIconBounds(finalDrawable);
+ drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
+ int iconOffset = getOffsetForIconBounds(l, drawable, pos);
+ synchronized (iconLoadResult) {
+ iconLoadResult.drawable = drawable;
+ iconLoadResult.badge = badge;
+ iconLoadResult.iconOffset = iconOffset;
+ if (iconLoadResult.onIconLoaded != null) {
+ l.getMainExecutor().execute(iconLoadResult.onIconLoaded);
+ iconLoadResult.onIconLoaded = null;
+ }
+ iconLoadResult.isIconLoaded = true;
+ }
+ }
- mLauncher.getMainExecutor().execute(() -> {
- if (isAdaptiveIcon) {
- mIsAdaptiveIcon = true;
- boolean isFolderIcon = finalDrawable instanceof FolderAdaptiveIcon;
+ /**
+ * Sets the drawables of the {@param originalView} onto this view.
+ *
+ * @param originalView The View that the FloatingIconView will replace.
+ * @param drawable The drawable of the original view.
+ * @param badge The badge of the original view.
+ * @param iconOffset The amount of offset needed to match this view with the original view.
+ */
+ @UiThread
+ private void setIcon(View originalView, @Nullable Drawable drawable, @Nullable Drawable badge,
+ int iconOffset) {
+ mBadge = badge;
- AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) finalDrawable;
- Drawable background = adaptiveIcon.getBackground();
- if (background == null) {
- background = new ColorDrawable(Color.TRANSPARENT);
+ mIsAdaptiveIcon = drawable instanceof AdaptiveIconDrawable;
+ if (mIsAdaptiveIcon) {
+ boolean isFolderIcon = drawable instanceof FolderAdaptiveIcon;
+
+ AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
+ Drawable background = adaptiveIcon.getBackground();
+ if (background == null) {
+ background = new ColorDrawable(Color.TRANSPARENT);
+ }
+ mBackground = background;
+ Drawable foreground = adaptiveIcon.getForeground();
+ if (foreground == null) {
+ foreground = new ColorDrawable(Color.TRANSPARENT);
+ }
+ mForeground = foreground;
+
+ final LayoutParams lp = (LayoutParams) getLayoutParams();
+ final int originalHeight = lp.height;
+ final int originalWidth = lp.width;
+
+ int blurMargin = mBlurSizeOutline / 2;
+ mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
+
+ if (!isFolderIcon) {
+ mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
+ }
+ mForeground.setBounds(mFinalDrawableBounds);
+ mBackground.setBounds(mFinalDrawableBounds);
+
+ mStartRevealRect.set(0, 0, originalWidth, originalHeight);
+
+ if (mBadge != null) {
+ mBadge.setBounds(mStartRevealRect);
+ if (!mIsOpening && !isFolderIcon) {
+ DRAWABLE_ALPHA.set(mBadge, 0);
}
- mBackground = background;
- Drawable foreground = adaptiveIcon.getForeground();
- if (foreground == null) {
- foreground = new ColorDrawable(Color.TRANSPARENT);
+ }
+
+ if (isFolderIcon) {
+ ((FolderIcon) originalView).getPreviewBounds(sTmpRect);
+ float bgStroke = ((FolderIcon) originalView).getBackgroundStrokeWidth();
+ if (mForeground instanceof ShiftedBitmapDrawable) {
+ ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
+ sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
+ sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
}
- mForeground = foreground;
-
- final int originalHeight = lp.height;
- final int originalWidth = lp.width;
-
- int blurMargin = mBlurSizeOutline / 2;
- mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
- if (!isFolderIcon) {
- mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
+ if (mBadge instanceof ShiftedBitmapDrawable) {
+ ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mBadge;
+ sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
+ sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
}
- mForeground.setBounds(mFinalDrawableBounds);
- mBackground.setBounds(mFinalDrawableBounds);
-
- mStartRevealRect.set(0, 0, originalWidth, originalHeight);
-
- if (mBadge != null) {
- mBadge.setBounds(mStartRevealRect);
- if (!isOpening && !isFolderIcon) {
- DRAWABLE_ALPHA.set(mBadge, 0);
- }
- }
-
- if (isFolderIcon) {
- ((FolderIcon) v).getPreviewBounds(sTmpRect);
- float bgStroke = ((FolderIcon) v).getBackgroundStrokeWidth();
- if (mForeground instanceof ShiftedBitmapDrawable) {
- ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
- sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
- sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
- }
- if (mBadge instanceof ShiftedBitmapDrawable) {
- ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mBadge;
- sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
- sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
- }
- } else {
- Utilities.scaleRectAboutCenter(mStartRevealRect,
- IconShape.getNormalizationScale());
- }
-
- float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
- if (mIsVerticalBarLayout) {
- lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
- } else {
- lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
- }
- layout(lp.leftMargin, lp.topMargin, lp.leftMargin + lp.width, lp.topMargin
- + lp.height);
-
- float scale = Math.max((float) lp.height / originalHeight,
- (float) lp.width / originalWidth);
- float bgDrawableStartScale;
- if (isOpening) {
- bgDrawableStartScale = 1f;
- mOutline.set(0, 0, originalWidth, originalHeight);
- } else {
- bgDrawableStartScale = scale;
- mOutline.set(0, 0, lp.width, lp.height);
- }
- setBackgroundDrawableBounds(bgDrawableStartScale);
- mEndRevealRect.set(0, 0, lp.width, lp.height);
- setOutlineProvider(new ViewOutlineProvider() {
- @Override
- public void getOutline(View view, Outline outline) {
- outline.setRoundRect(mOutline, mTaskCornerRadius);
- }
- });
- setClipToOutline(true);
} else {
- setBackground(finalDrawable);
- setClipToOutline(false);
+ Utilities.scaleRectAboutCenter(mStartRevealRect,
+ IconShape.getNormalizationScale());
}
- if (!loadIconSignal.isCanceled()) {
- onIconLoadedRunnable.run();
+ float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
+ if (mIsVerticalBarLayout) {
+ lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
+ } else {
+ lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
}
- invalidate();
- invalidateOutline();
- });
+ layout(lp.leftMargin, lp.topMargin, lp.leftMargin + lp.width, lp.topMargin
+ + lp.height);
+
+ float scale = Math.max((float) lp.height / originalHeight,
+ (float) lp.width / originalWidth);
+ float bgDrawableStartScale;
+ if (mIsOpening) {
+ bgDrawableStartScale = 1f;
+ mOutline.set(0, 0, originalWidth, originalHeight);
+ } else {
+ bgDrawableStartScale = scale;
+ mOutline.set(0, 0, lp.width, lp.height);
+ }
+ setBackgroundDrawableBounds(bgDrawableStartScale);
+ mEndRevealRect.set(0, 0, lp.width, lp.height);
+ setOutlineProvider(new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(mOutline, mTaskCornerRadius);
+ }
+ });
+ setClipToOutline(true);
+ } else {
+ setBackground(drawable);
+ setClipToOutline(false);
+ }
+
+ invalidate();
+ invalidateOutline();
+ }
+
+ /**
+ * Checks if the icon result is loaded. If true, we set the icon immediately. Else, we add a
+ * callback to set the icon once the icon result is loaded.
+ */
+ private void checkIconResult(View originalView, boolean isOpening) {
+ CancellationSignal cancellationSignal = new CancellationSignal();
+ if (!isOpening) {
+ // Hide immediately since the floating view starts at a different location.
+ originalView.setVisibility(INVISIBLE);
+ cancellationSignal.setOnCancelListener(() -> originalView.setVisibility(VISIBLE));
+ }
+
+ if (mIconLoadResult == null) {
+ Log.w(TAG, "No icon load result found in checkIconResult");
+ return;
+ }
+
+ synchronized (mIconLoadResult) {
+ if (mIconLoadResult.isIconLoaded) {
+ setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge,
+ mIconLoadResult.iconOffset);
+ if (isOpening) {
+ originalView.setVisibility(INVISIBLE);
+ }
+ } else {
+ mIconLoadResult.onIconLoaded = () -> {
+ if (cancellationSignal.isCanceled()) {
+ return;
+ }
+ if (mIconLoadResult.isIconLoaded) {
+ setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge,
+ mIconLoadResult.iconOffset);
+ }
+ // Delay swapping views until the icon is loaded to prevent a flash.
+ setVisibility(VISIBLE);
+ originalView.setVisibility(INVISIBLE);
+ };
+ }
+ }
+ mLoadIconSignal = cancellationSignal;
}
private void setBackgroundDrawableBounds(float scale) {
@@ -521,17 +601,19 @@
@WorkerThread
@SuppressWarnings("WrongThread")
- private int getOffsetForIconBounds(Drawable drawable) {
+ private static int getOffsetForIconBounds(Launcher l, Drawable drawable, RectF position) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
!(drawable instanceof AdaptiveIconDrawable)) {
return 0;
}
+ int blurSizeOutline =
+ l.getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);
- final LayoutParams lp = (LayoutParams) getLayoutParams();
- Rect bounds = new Rect(0, 0, lp.width + mBlurSizeOutline, lp.height + mBlurSizeOutline);
- bounds.inset(mBlurSizeOutline / 2, mBlurSizeOutline / 2);
+ Rect bounds = new Rect(0, 0, (int) position.width() + blurSizeOutline,
+ (int) position.height() + blurSizeOutline);
+ bounds.inset(blurSizeOutline / 2, blurSizeOutline / 2);
- try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
+ try (LauncherIcons li = LauncherIcons.obtain(l)) {
Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(drawable, null,
null, null));
}
@@ -587,7 +669,11 @@
}
@Override
- public void onAnimationStart(Animator animator) {}
+ public void onAnimationStart(Animator animator) {
+ if (mIconLoadResult != null && mIconLoadResult.isIconLoaded) {
+ setVisibility(View.VISIBLE);
+ }
+ }
@Override
public void onAnimationCancel(Animator animator) {}
@@ -598,7 +684,8 @@
@Override
public void onGlobalLayout() {
if (mOriginalIcon.isAttachedToWindow() && mPositionOut != null) {
- float rotation = getLocationBoundsForView(mOriginalIcon, sTmpRectF);
+ float rotation = getLocationBoundsForView(mLauncher, mOriginalIcon, mIsOpening,
+ sTmpRectF);
if (rotation != mRotation || !sTmpRectF.equals(mPositionOut)) {
updatePosition(rotation, sTmpRectF, (LayoutParams) getLayoutParams());
if (mOnTargetChangeRunnable != null) {
@@ -613,6 +700,22 @@
}
/**
+ * Loads the icon drawable on a worker thread to reduce latency between swapping views.
+ */
+ @UiThread
+ public static IconLoadResult fetchIcon(Launcher l, View v, ItemInfo info, boolean isOpening) {
+ IconLoadResult result = new IconLoadResult();
+ new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
+ RectF position = new RectF();
+ getLocationBoundsForView(l, v, isOpening, position);
+ getIconResult(l, v, info, position, result);
+ });
+
+ sIconLoadResult = result;
+ return result;
+ }
+
+ /**
* Creates a floating icon view for {@param originalView}.
* @param originalView The view to copy
* @param hideOriginal If true, it will hide {@param originalView} while this view is visible.
@@ -624,38 +727,30 @@
boolean hideOriginal, RectF positionOut, boolean isOpening) {
final DragLayer dragLayer = launcher.getDragLayer();
ViewGroup parent = (ViewGroup) dragLayer.getParent();
-
FloatingIconView view = launcher.getViewCache().getView(R.layout.floating_icon_view,
launcher, parent);
view.recycle();
+ // Get the drawable on the background thread
+ boolean shouldLoadIcon = originalView.getTag() instanceof ItemInfo && hideOriginal;
+ view.mIconLoadResult = sIconLoadResult;
+ if (shouldLoadIcon && view.mIconLoadResult == null) {
+ view.mIconLoadResult = fetchIcon(launcher, originalView,
+ (ItemInfo) originalView.getTag(), isOpening);
+ }
+ sIconLoadResult = null;
+
view.mIsVerticalBarLayout = launcher.getDeviceProfile().isVerticalBarLayout();
view.mIsOpening = isOpening;
-
view.mOriginalIcon = originalView;
view.mPositionOut = positionOut;
- // Match the position of the original view.
- view.matchPositionOf(originalView, positionOut);
- // Get the drawable on the background thread
+ // Match the position of the original view.
+ view.matchPositionOf(launcher, originalView, isOpening, positionOut);
+
// Must be called after matchPositionOf so that we know what size to load.
- if (originalView.getTag() instanceof ItemInfo && hideOriginal) {
- view.mLoadIconSignal = new CancellationSignal();
- Runnable onIconLoaded = () -> {
- // Delay swapping views until the icon is loaded to prevent a flash.
- view.setVisibility(VISIBLE);
- originalView.setVisibility(INVISIBLE);
- };
- if (!isOpening) {
- // Hide immediately since the floating view starts at a different location.
- originalView.setVisibility(INVISIBLE);
- view.mLoadIconSignal.setOnCancelListener(() -> originalView.setVisibility(VISIBLE));
- }
- CancellationSignal loadIconSignal = view.mLoadIconSignal;
- new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
- view.getIcon(originalView, (ItemInfo) originalView.getTag(), isOpening,
- onIconLoaded, loadIconSignal);
- });
+ if (shouldLoadIcon) {
+ view.checkIconResult(originalView, isOpening);
}
// We need to add it to the overlay, but keep it invisible until animation starts..
@@ -779,5 +874,14 @@
mFgSpringY.cancel();
mBadge = null;
sTmpObjArray[0] = null;
+ mIconLoadResult = null;
+ }
+
+ private static class IconLoadResult {
+ Drawable drawable;
+ Drawable badge;
+ int iconOffset;
+ Runnable onIconLoaded;
+ boolean isIconLoaded;
}
}
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
index 35e44bb..dce839f 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
@@ -44,6 +44,7 @@
import com.android.launcher3.StylusEventHelper;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.util.Themes;
import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener;
/**
@@ -97,6 +98,9 @@
if (Utilities.ATLEAST_OREO) {
setExecutor(Utilities.THREAD_POOL_EXECUTOR);
}
+ if (Utilities.ATLEAST_Q && Themes.getAttrBoolean(mLauncher, R.attr.isWorkspaceDarkText)) {
+ setOnLightBackground(true);
+ }
}
@Override
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index 21d763e..9ff354a 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -16,8 +16,6 @@
package com.android.launcher3.tapl;
-import static com.android.launcher3.tapl.LauncherInstrumentation.NavigationModel.ZERO_BUTTON;
-
import android.graphics.Point;
import android.graphics.Rect;
import android.widget.TextView;
@@ -36,7 +34,6 @@
*/
public class AllApps extends LauncherInstrumentation.VisibleContainer {
private static final int MAX_SCROLL_ATTEMPTS = 40;
- private static final int MIN_INTERACT_SIZE = 100;
private final int mHeight;
@@ -65,13 +62,6 @@
}
final Rect iconBounds = icon.getVisibleBounds();
LauncherInstrumentation.log("hasClickableIcon: icon bounds: " + iconBounds);
- if (mLauncher.getNavigationModel() != ZERO_BUTTON) {
- final UiObject2 navBar = mLauncher.waitForSystemUiObject("navigation_bar_frame");
- if (iconBounds.bottom >= navBar.getVisibleBounds().top) {
- LauncherInstrumentation.log("hasClickableIcon: icon intersects with nav bar");
- return false;
- }
- }
if (iconCenterInSearchBox(allAppsContainer, icon)) {
LauncherInstrumentation.log("hasClickableIcon: icon center is under search box");
return false;
@@ -96,7 +86,7 @@
@NonNull
public AppIcon getAppIcon(String appName) {
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
- "want to get app icon " + appName + " on all apps")) {
+ "getting app icon " + appName + " on all apps")) {
final UiObject2 allAppsContainer = verifyActiveContainer();
final UiObject2 appListRecycler = mLauncher.waitForObjectInContainer(allAppsContainer,
"apps_list_view");
@@ -110,21 +100,28 @@
if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)) {
scrollBackToBeginning();
int attempts = 0;
+ int scroll = getScroll(allAppsContainer);
try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) {
- while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector) &&
- allAppsContainer.scroll(Direction.DOWN, 0.8f)) {
+ while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)) {
+ mLauncher.scroll(allAppsContainer, Direction.DOWN, 0.8f, null, 50);
+ final int newScroll = getScroll(allAppsContainer);
+ if (newScroll == scroll) break;
+
mLauncher.assertTrue(
"Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
++attempts <= MAX_SCROLL_ATTEMPTS);
verifyActiveContainer();
+ scroll = newScroll;
}
}
verifyActiveContainer();
}
+ mLauncher.assertTrue("Unable to scroll to a clickable icon: " + appName,
+ hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector));
+
final UiObject2 appIcon = mLauncher.getObjectInContainer(appListRecycler,
appIconSelector);
- ensureIconVisible(appIcon, allAppsContainer, appListRecycler);
return new AppIcon(mLauncher, appIcon);
}
}
@@ -162,24 +159,6 @@
getInt(TestProtocol.SCROLL_Y_FIELD, -1);
}
- private void ensureIconVisible(
- UiObject2 appIcon, UiObject2 allAppsContainer, UiObject2 appListRecycler) {
- final int appHeight = appIcon.getVisibleBounds().height();
- if (appHeight < MIN_INTERACT_SIZE) {
- // Try to figure out how much percentage of the container needs to be scrolled in order
- // to reveal the app icon to have the MIN_INTERACT_SIZE
- final float pct = Math.max(((float) (MIN_INTERACT_SIZE - appHeight)) / mHeight, 0.2f);
- mLauncher.scroll(appListRecycler, Direction.DOWN, pct, null, 10);
- try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
- "scrolled an icon in all apps to make it visible - and then")) {
- mLauncher.waitForIdle();
- verifyActiveContainer();
- }
- }
- mLauncher.assertTrue("Couldn't scroll app icon to not intersect with the search box",
- !iconCenterInSearchBox(allAppsContainer, appIcon));
- }
-
private UiObject2 getSearchBox(UiObject2 allAppsContainer) {
return mLauncher.waitForObjectInContainer(allAppsContainer, "search_container_all_apps");
}