Merge "Folder preview polish." into sc-dev
diff --git a/quickstep/res/values/config.xml b/quickstep/res/values/config.xml
index b2ff770..f22a9d7 100644
--- a/quickstep/res/values/config.xml
+++ b/quickstep/res/values/config.xml
@@ -37,5 +37,5 @@
<string name="wellbeing_provider_pkg" translatable="false"/>
- <integer name="max_depth_blur_radius">150</integer>
+ <integer name="max_depth_blur_radius">72</integer>
</resources>
diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
index c13225a..1bf3627 100644
--- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
@@ -37,6 +37,7 @@
import android.os.CancellationSignal;
import android.os.IBinder;
import android.view.View;
+import android.window.SplashScreen;
import androidx.annotation.Nullable;
@@ -435,6 +436,7 @@
ActivityOptionsCompat.setLauncherSourceInfo(
activityOptions.options, mLastTouchUpTime);
}
+ activityOptions.options.setSplashscreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON);
addLaunchCookie(item, activityOptions.options);
return activityOptions;
}
diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java
index d43bb24..6852642 100644
--- a/quickstep/src/com/android/quickstep/RecentsActivity.java
+++ b/quickstep/src/com/android/quickstep/RecentsActivity.java
@@ -40,6 +40,7 @@
import android.os.Looper;
import android.view.SurfaceControl.Transaction;
import android.view.View;
+import android.window.SplashScreen;
import androidx.annotation.Nullable;
@@ -222,9 +223,11 @@
wrapper, RECENTS_LAUNCH_DURATION,
RECENTS_LAUNCH_DURATION - STATUS_BAR_TRANSITION_DURATION
- STATUS_BAR_TRANSITION_PRE_DELAY);
- return new ActivityOptionsWrapper(
+ final ActivityOptionsWrapper activityOptions = new ActivityOptionsWrapper(
ActivityOptionsCompat.makeRemoteAnimation(adapterCompat),
onEndCallback);
+ activityOptions.options.setSplashscreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON);
+ return activityOptions;
}
/**
diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationController.java b/quickstep/src/com/android/quickstep/RecentsAnimationController.java
index 50d0569..0ebe13b 100644
--- a/quickstep/src/com/android/quickstep/RecentsAnimationController.java
+++ b/quickstep/src/com/android/quickstep/RecentsAnimationController.java
@@ -18,6 +18,7 @@
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+import android.view.IRecentsAnimationController;
import android.view.SurfaceControl;
import android.window.PictureInPictureSurfaceTransaction;
@@ -163,6 +164,14 @@
}
/**
+ * @see IRecentsAnimationController#animateNavigationBarToApp(long)
+ */
+ @UiThread
+ public void animateNavigationBarToApp(long duration) {
+ UI_HELPER_EXECUTOR.execute(() -> mController.animateNavigationBarToApp(duration));
+ }
+
+ /**
* Sets the final surface transaction on a Task. This is used by Launcher to notify the system
* that animating Activity to PiP has completed and the associated task surface should be
* updated accordingly. This should be called before `finish`
diff --git a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java
index 4ec1c15..a078bf3 100644
--- a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java
+++ b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java
@@ -30,6 +30,7 @@
import android.os.Handler;
import android.os.Looper;
import android.view.View;
+import android.window.SplashScreen;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
@@ -165,6 +166,9 @@
dismissTaskMenuView(mTarget);
ActivityOptions options = mFactory.makeLaunchOptions(mTarget);
+ if (options != null) {
+ options.setSplashscreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON);
+ }
if (options != null
&& ActivityManagerWrapper.getInstance().startActivityFromRecents(taskId,
options)) {
diff --git a/quickstep/src/com/android/quickstep/TaskViewUtils.java b/quickstep/src/com/android/quickstep/TaskViewUtils.java
index a59ba51..59bd1ed 100644
--- a/quickstep/src/com/android/quickstep/TaskViewUtils.java
+++ b/quickstep/src/com/android/quickstep/TaskViewUtils.java
@@ -263,6 +263,14 @@
finalParams.applySurfaceParams(navBuilder.build());
}
});
+ } else if (inLiveTileMode) {
+ // There is no transition animation for app launch from recent in live tile mode so
+ // we have to trigger the navigation bar animation from system here.
+ final RecentsAnimationController controller =
+ recentsView.getRecentsAnimationController();
+ if (controller != null) {
+ controller.animateNavigationBarToApp(RECENTS_LAUNCH_DURATION);
+ }
}
topMostSimulator = tsv;
}
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 74906dd..7991614 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1358,7 +1358,7 @@
mOrientationHandler);
int taskWidth = mTempRect.width();
int taskHeight = mTempRect.height();
- if (mRunningTaskId != -1) {
+ if (mFocusedTaskId != -1) {
int boxLength = Math.max(taskWidth, taskHeight);
if (mFocusedTaskRatio > 1) {
taskWidth = boxLength;
@@ -2198,7 +2198,7 @@
.setDampingRatio(rp.getFloat(R.dimen.dismiss_task_trans_y_damping_ratio))
.setStiffness(rp.getFloat(R.dimen.dismiss_task_trans_y_stiffness));
FloatProperty<TaskView> dismissingTaskViewTranslate =
- taskView.getSecondaryDissmissTranslationProperty();;
+ taskView.getSecondaryDissmissTranslationProperty();
// TODO(b/186800707) translate entire grid size distance
int translateDistance = mOrientationHandler.getSecondaryDimension(taskView);
int positiveNegativeFactor = mOrientationHandler.getSecondaryTranslationDirectionFactor();
@@ -2231,7 +2231,7 @@
anim.add(ObjectAnimator.ofFloat(taskView, dismissingTaskViewTranslate,
positiveNegativeFactor * translateDistance * 2).setDuration(duration), LINEAR, sp);
- if (LIVE_TILE.get() && taskView.isRunningTask()) {
+ if (LIVE_TILE.get() && mEnableDrawingLiveTile && taskView.isRunningTask()) {
anim.addOnFrameCallback(() -> {
mLiveTileTaskViewSimulator.taskSecondaryTranslation.value =
mOrientationHandler.getSecondaryValue(
@@ -2311,6 +2311,15 @@
anim.setFloat(child, translationProperty, scrollDiff, clampToProgress(LINEAR,
Utilities.boundToRange(INITIAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET
+ additionalDismissDuration, 0f, 1f), 1));
+ if (LIVE_TILE.get() && mEnableDrawingLiveTile && child instanceof TaskView
+ && ((TaskView) child).isRunningTask()) {
+ anim.addOnFrameCallback(() -> {
+ mLiveTileTaskViewSimulator.taskPrimaryTranslation.value =
+ mOrientationHandler.getPrimaryValue(child.getTranslationX(),
+ child.getTranslationY());
+ redrawLiveTile();
+ });
+ }
needsCurveUpdates = true;
}
} else if (child instanceof TaskView) {
@@ -2391,6 +2400,7 @@
startHome();
} else {
snapToPageImmediately(pageToSnapTo);
+ dispatchScrollChanged();
// Grid got messed up, reapply.
updateGridProperties(true);
if (showAsGrid() && getFocusedTaskView() == null
@@ -3843,4 +3853,10 @@
// The Black blending is temporary until we have the proper color token.
return ColorUtils.blendARGB(Color.BLACK, baseColor, 0.25f);
}
+
+ /** Get the RecentsAnimationController */
+ @Nullable
+ public RecentsAnimationController getRecentsAnimationController() {
+ return mRecentsAnimationController;
+ }
}
diff --git a/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java b/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
index 4ca1f59..ea7b7f5 100644
--- a/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
+++ b/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
@@ -79,10 +79,7 @@
* directly (ex: new LinearLayout)
* Using ExtendedMockito: Mocking static methods from platform classes (loaded in zygote) makes
* the main thread extremely slow and untestable
- *
- * Suppressed until b/141579810 is resolved
*/
-@Suppress
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ViewInflationDuringSwipeUp extends AbstractQuickStepTest {
@@ -137,6 +134,7 @@
@Test
@NavigationModeSwitch(mode = ZERO_BUTTON)
+ @Suppress // until b/190729479 is fixed
public void testSwipeUpFromApp_widget_update() {
String stubText = "Some random stub text";
@@ -149,6 +147,7 @@
@Test
@NavigationModeSwitch(mode = ZERO_BUTTON)
+ @Suppress // until b/190729479 is fixed
public void testSwipeUp_with_list_widgets() {
SimpleViewsFactory viewFactory = new SimpleViewsFactory();
viewFactory.viewCount = 1;
@@ -188,6 +187,11 @@
LauncherSettings.Settings.call(mResolver,
LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
+ // Make sure the widget is big enough to show a list of items
+ info.minSpanX = 2;
+ info.minSpanY = 2;
+ info.spanX = 2;
+ info.spanY = 2;
LauncherAppWidgetInfo item = createWidgetInfo(info, getTargetContext(), true);
addItemToScreen(item);
diff --git a/res/drawable/work_apps_toggle_background.xml b/res/drawable/work_apps_toggle_background.xml
new file mode 100644
index 0000000..a04d269
--- /dev/null
+++ b/res/drawable/work_apps_toggle_background.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_enabled="false">
+ <shape android:shape="rectangle">
+ <corners android:radius="@dimen/work_fab_radius" />
+ <solid android:color="?android:attr/colorControlHighlight" />
+ <padding android:left="@dimen/work_fab_radius" android:right="@dimen/work_fab_radius" />
+ </shape>
+ </item>
+ <item>
+ <shape android:shape="rectangle">
+ <corners android:radius="@dimen/work_fab_radius" />
+ <solid android:color="?android:attr/colorAccent" />
+ <padding android:left="@dimen/work_fab_radius" android:right="@dimen/work_fab_radius" />
+ </shape>
+ </item>
+</selector>
diff --git a/res/layout/app_widget_resize_frame.xml b/res/layout/app_widget_resize_frame.xml
index 53db5ed..249e42c 100644
--- a/res/layout/app_widget_resize_frame.xml
+++ b/res/layout/app_widget_resize_frame.xml
@@ -83,7 +83,8 @@
android:layout_marginEnd="@dimen/widget_reconfigure_button_margin"
android:src="@drawable/widget_reconfigure_button_frame"
android:background="?android:attr/selectableItemBackground"
- android:visibility="gone" />
+ android:visibility="gone"
+ android:contentDescription="@string/widget_reconfigure_button_content_description" />
</FrameLayout>
</com.android.launcher3.AppWidgetResizeFrame>
\ No newline at end of file
diff --git a/res/layout/arrow_toast.xml b/res/layout/arrow_toast.xml
index aee00a9..9a6f8c3 100644
--- a/res/layout/arrow_toast.xml
+++ b/res/layout/arrow_toast.xml
@@ -28,13 +28,14 @@
android:padding="16dp"
android:background="@drawable/arrow_toast_rounded_background"
android:elevation="2dp"
+ android:outlineProvider="none"
android:textColor="@color/arrow_tip_view_content"
android:textSize="14sp"/>
<View
android:id="@+id/arrow"
android:elevation="2dp"
+ android:outlineProvider="none"
android:layout_width="@dimen/arrow_toast_arrow_width"
- android:layout_height="8dp"
- android:layout_marginTop="-2dp"/>
+ android:layout_height="10dp"/>
</merge>
diff --git a/res/layout/work_mode_fab.xml b/res/layout/work_mode_fab.xml
new file mode 100644
index 0000000..21f269f
--- /dev/null
+++ b/res/layout/work_mode_fab.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<com.android.launcher3.allapps.WorkModeSwitch
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/work_mode_toggle"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_height="@dimen/work_fab_height"
+ android:layout_width="wrap_content"
+ android:gravity="center"
+ android:includeFontPadding="false"
+ android:drawableTint="@android:color/white"
+ android:textColor="@android:color/white"
+ android:background="@drawable/work_apps_toggle_background"
+ android:drawablePadding="16dp"
+ android:drawableStart="@drawable/ic_corp_off"
+ android:elevation="10dp"
+ android:layout_marginBottom="@dimen/work_fab_margin"
+ android:layout_marginEnd="@dimen/work_fab_margin"
+ android:text="@string/work_apps_pause_btn_text" />
\ No newline at end of file
diff --git a/res/layout/work_mode_switch.xml b/res/layout/work_mode_switch.xml
index 31953c7..538a180 100644
--- a/res/layout/work_mode_switch.xml
+++ b/res/layout/work_mode_switch.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
+<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2017 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.
@@ -13,8 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<com.android.launcher3.allapps.WorkModeSwitch
- xmlns:android="http://schemas.android.com/apk/res/android"
+<com.android.launcher3.allapps.WorkModeSwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/PrimaryHeadline"
@@ -35,5 +33,4 @@
android:paddingBottom="@dimen/work_profile_footer_padding"
android:paddingLeft="@dimen/work_profile_footer_padding"
android:paddingRight="@dimen/work_profile_footer_padding"
- android:paddingTop="@dimen/work_profile_footer_padding"
-/>
+ android:paddingTop="@dimen/work_profile_footer_padding" />
diff --git a/res/layout/work_profile_edu.xml b/res/layout/work_profile_edu.xml
deleted file mode 100644
index c3c7010..0000000
--- a/res/layout/work_profile_edu.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!-- 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.
--->
-<com.android.launcher3.views.WorkEduView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:gravity="bottom"
- android:orientation="vertical">
-
- <View
- android:layout_width="match_parent"
- android:layout_height="32dp"
- android:background="@drawable/bottom_sheet_top_border"
- android:backgroundTint="?attr/eduHalfSheetBGColor" />
-
- <LinearLayout
- android:id="@+id/view_wrapper"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/eduHalfSheetBGColor"
- android:orientation="vertical"
- android:paddingLeft="@dimen/bottom_sheet_edu_padding"
- android:paddingRight="@dimen/bottom_sheet_edu_padding">
-
- <TextView
- android:id="@+id/content_text"
- style="@style/TextHeadline"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="48dp"
- android:layout_marginBottom="48dp"
- android:gravity="center"
- android:text="@string/work_profile_edu_personal_apps"
- android:textAlignment="center"
- android:textColor="@android:color/white"
- android:textSize="20sp" />
-
- <Button
- android:id="@+id/proceed"
- android:layout_width="wrap_content"
- android:layout_height="48dp"
- android:layout_gravity="end"
- android:background="?android:attr/selectableItemBackground"
- android:gravity="center"
- android:text="@string/work_profile_edu_next"
- android:textAlignment="center"
- android:textColor="@android:color/white" />
- </LinearLayout>
-</com.android.launcher3.views.WorkEduView>
\ No newline at end of file
diff --git a/res/values-v28/dimens.xml b/res/values-v28/dimens.xml
index ffa8cc4..3f118cd 100644
--- a/res/values-v28/dimens.xml
+++ b/res/values-v28/dimens.xml
@@ -1,5 +1,5 @@
<?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");
you may not use this file except in compliance with the License.
diff --git a/res/values-v31/colors.xml b/res/values-v31/colors.xml
index 7b37001..a9721a4 100644
--- a/res/values-v31/colors.xml
+++ b/res/values-v31/colors.xml
@@ -37,4 +37,6 @@
<color name="wallpaper_popup_scrim">@android:color/system_neutral1_900</color>
+ <color name="folder_dot_color">@android:color/system_accent2_50</color>
+
</resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index c2b07e0..7aab4fa 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -59,6 +59,8 @@
<color name="folder_hint_text_color_light">#FFF</color>
<color name="folder_hint_text_color_dark">#FF000000</color>
+ <color name="folder_dot_color">?attr/colorPrimary</color>
+
<color name="text_color_primary_dark">#FFFFFFFF</color>
<color name="text_color_secondary_dark">#FFFFFFFF</color>
<color name="text_color_tertiary_dark">#CCFFFFFF</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d065611..06bdd49 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -61,6 +61,7 @@
<dimen name="widget_reconfigure_button_padding">6dp</dimen>
<dimen name="widget_reconfigure_button_margin">32dp</dimen>
<dimen name="widget_reconfigure_button_size">36dp</dimen>
+ <dimen name="widget_reconfigure_tip_top_margin">16dp</dimen>
<!-- Fast scroll -->
<dimen name="fastscroll_track_min_width">6dp</dimen>
@@ -115,6 +116,10 @@
<dimen name="all_apps_divider_margin_vertical">8dp</dimen>
+<!-- Floating action button inside work tab to toggle work profile -->
+ <dimen name="work_fab_height">48dp</dimen>
+ <dimen name="work_fab_radius">24dp</dimen>
+ <dimen name="work_fab_margin">18dp</dimen>
<dimen name="work_profile_footer_padding">20dp</dimen>
<dimen name="work_profile_footer_text_size">16sp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c851cf8..2a27828 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -105,9 +105,18 @@
<!-- Dialog text. This dialog lets a user know how they can use widgets on their phone.
[CHAR_LIMIT=NONE] -->
<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] -->
<string name="widget_education_close_button">Got it</string>
+ <!-- Spoken text for screen readers. This text is for an icon that lets the user change a
+ widget's settings. [CHAR_LIMIT=50] -->
+ <string name="widget_reconfigure_button_content_description">Change widget settings</string>
+
<!-- All Apps -->
<!-- Search bar text in the apps view. [CHAR_LIMIT=50] -->
<string name="all_apps_search_bar_hint">Search apps</string>
@@ -389,27 +398,24 @@
<string name="work_profile_edu_accept">Got it</string>
<!--- heading shown when user opens work apps tab while work apps are paused -->
- <string name="work_apps_paused_title">Work profile is paused</string>
+ <string name="work_apps_paused_title">Work apps are off</string>
<!--- body shown when user opens work apps tab while work apps are paused -->
- <string name="work_apps_paused_body">Work apps can’t send you notifications, use your battery, or access your location</string>
+ <string name="work_apps_paused_body">Your work apps can’t send you notifications, use your battery, or access your location</string>
<!-- content description for paused work apps list -->
- <string name="work_apps_paused_content_description">Work profile is paused. Work apps can’t send you notifications, use your battery, or access your location</string>
+ <string name="work_apps_paused_content_description">Work apps are off. Your work apps can’t send you notifications, use your battery, or access your location</string>
<!-- string shown in educational banner about work profile -->
<string name="work_apps_paused_edu_banner">Work apps are badged and visible to your IT admin</string>
<!-- button string shown to dismiss work tab education -->
<string name="work_apps_paused_edu_accept">Got it</string>
<!-- button string shown pause work profile -->
- <string name="work_apps_pause_btn_text">Pause work apps</string>
+ <string name="work_apps_pause_btn_text">Turn off work apps</string>
<!-- button string shown enable work profile -->
- <string name="work_apps_enable_btn_text">Turn on</string>
+ <string name="work_apps_enable_btn_text">Turn on work apps</string>
<!-- A hint shown in launcher settings develop options filter box -->
<string name="developer_options_filter_hint">Filter</string>
- <!-- A tip shown pointing at work toggle -->
- <string name="work_switch_tip">Pause work apps and notifications</string>
-
<!-- Failed action error message: e.g. Failed: Pause -->
<string name="remote_action_failed">Failed: <xliff:g id="what" example="Pause">%1$s</xliff:g></string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 86dcf4c..571377c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -47,7 +47,7 @@
<item name="workspaceKeyShadowColor">#89000000</item>
<item name="workspaceStatusBarScrim">@drawable/workspace_bg</item>
<item name="widgetsTheme">@style/WidgetContainerTheme</item>
- <item name="folderDotColor">?android:attr/colorPrimary</item>
+ <item name="folderDotColor">@color/folder_dot_color</item>
<item name="folderFillColor">?android:attr/colorBackgroundFloating</item>
<item name="folderIconBorderColor">?android:attr/colorPrimary</item>
<item name="folderTextColor">?android:attr/textColorPrimary</item>
@@ -86,7 +86,7 @@
<item name="workspaceKeyShadowColor">@android:color/transparent</item>
<item name="isWorkspaceDarkText">true</item>
<item name="workspaceStatusBarScrim">@null</item>
- <item name="folderDotColor">#FF464646</item>
+ <item name="folderDotColor">@color/folder_dot_color</item>
<item name="folderFillColor">?android:attr/colorBackgroundFloating</item>
<item name="folderIconBorderColor">#FF80868B</item>
<item name="folderTextColor">?attr/workspaceTextColor</item>
@@ -108,7 +108,7 @@
<item name="popupColorSecondary">@color/popup_color_secondary_dark</item>
<item name="popupColorTertiary">@color/popup_color_tertiary_dark</item>
<item name="widgetsTheme">@style/WidgetContainerTheme.Dark</item>
- <item name="folderDotColor">?android:attr/colorPrimary</item>
+ <item name="folderDotColor">@color/folder_dot_color</item>
<item name="folderFillColor">?android:attr/colorBackgroundFloating</item>
<item name="folderIconBorderColor">?android:attr/colorPrimary</item>
<item name="folderTextColor">?android:attr/textColorPrimary</item>
diff --git a/robolectric_tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java b/robolectric_tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
index d18138f..c7286e5 100644
--- a/robolectric_tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
+++ b/robolectric_tests/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfoTest.java
@@ -40,6 +40,8 @@
public final class LauncherAppWidgetProviderInfoTest {
private static final int CELL_SIZE = 50;
+ private static final int NUM_OF_COLS = 4;
+ private static final int NUM_OF_ROWS = 5;
private Context mContext;
@@ -76,6 +78,33 @@
}
@Test
+ public void
+ initSpans_minWidthLargerThanGridColumns_shouldInitializeSpansToAtMostTheGridColumns() {
+ LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
+ info.minWidth = CELL_SIZE * (NUM_OF_COLS + 1);
+ info.minHeight = 20;
+ InvariantDeviceProfile idp = createIDP();
+
+ info.initSpans(mContext, idp);
+
+ assertThat(info.spanX).isEqualTo(NUM_OF_COLS);
+ assertThat(info.spanY).isEqualTo(1);
+ }
+
+ @Test
+ public void initSpans_minHeightLargerThanGridRows_shouldInitializeSpansToAtMostTheGridRows() {
+ LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
+ info.minWidth = 20;
+ info.minHeight = 50 * (NUM_OF_ROWS + 1);
+ InvariantDeviceProfile idp = createIDP();
+
+ info.initSpans(mContext, idp);
+
+ assertThat(info.spanX).isEqualTo(1);
+ assertThat(info.spanY).isEqualTo(NUM_OF_ROWS);
+ }
+
+ @Test
public void initSpans_minResizeWidthUnspecified_shouldInitializeMinSpansToOne() {
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
InvariantDeviceProfile idp = createIDP();
@@ -153,6 +182,49 @@
assertThat(info.minSpanY).isEqualTo(3);
}
+ @Test
+ public void isMinSizeFulfilled_minWidthAndHeightWithinGridSize_shouldReturnTrue() {
+ LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
+ info.minWidth = 80;
+ info.minHeight = 80;
+ info.minResizeWidth = 50;
+ info.minResizeHeight = 50;
+ InvariantDeviceProfile idp = createIDP();
+
+ info.initSpans(mContext, idp);
+
+ assertThat(info.isMinSizeFulfilled()).isTrue();
+ }
+
+ @Test
+ public void
+ isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse() {
+ LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
+ info.minWidth = CELL_SIZE * (NUM_OF_COLS + 2);
+ info.minHeight = 80;
+ info.minResizeWidth = CELL_SIZE * (NUM_OF_COLS + 1);
+ info.minResizeHeight = 50;
+ InvariantDeviceProfile idp = createIDP();
+
+ info.initSpans(mContext, idp);
+
+ assertThat(info.isMinSizeFulfilled()).isFalse();
+ }
+
+ @Test
+ public void isMinSizeFulfilled_minHeightAndMinResizeHeightExceededGridRows_shouldReturnFalse() {
+ LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
+ info.minWidth = 80;
+ info.minHeight = CELL_SIZE * (NUM_OF_ROWS + 2);
+ info.minResizeWidth = 50;
+ info.minResizeHeight = CELL_SIZE * (NUM_OF_ROWS + 1);
+ InvariantDeviceProfile idp = createIDP();
+
+ info.initSpans(mContext, idp);
+
+ assertThat(info.isMinSizeFulfilled()).isFalse();
+ }
+
private InvariantDeviceProfile createIDP() {
DeviceProfile profile = Mockito.mock(DeviceProfile.class);
doAnswer(i -> {
@@ -163,6 +235,8 @@
InvariantDeviceProfile idp = new InvariantDeviceProfile();
idp.supportedProfiles.add(profile);
+ idp.numColumns = NUM_OF_COLS;
+ idp.numRows = NUM_OF_ROWS;
return idp;
}
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index 5d9797f..9e21e1a 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -4,7 +4,6 @@
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
-import static com.android.launcher3.Utilities.ATLEAST_S;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RESIZE_COMPLETED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RESIZE_STARTED;
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X;
@@ -13,42 +12,42 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
-import android.appwidget.AppWidgetHostView;
-import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
-import android.content.ComponentName;
import android.content.Context;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
-import android.os.Bundle;
import android.util.AttributeSet;
-import android.util.SizeF;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
+import androidx.annotation.Nullable;
+import androidx.annotation.Px;
+
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.PendingRequestArgs;
+import com.android.launcher3.views.ArrowTipView;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
+import com.android.launcher3.widget.util.WidgetSizes;
import java.util.ArrayList;
import java.util.List;
-import java.util.stream.Collectors;
public class AppWidgetResizeFrame extends AbstractFloatingView implements View.OnKeyListener {
private static final int SNAP_DURATION = 150;
private static final float DIMMED_HANDLE_ALPHA = 0f;
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 int HANDLE_COUNT = 4;
@@ -245,6 +244,15 @@
mWidgetView.getAppWidgetId(),
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
@@ -415,90 +423,12 @@
mRunningHInc += hSpanDelta;
if (!onDismiss) {
- updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY);
+ WidgetSizes.updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY);
}
}
mWidgetView.requestLayout();
}
- public static void updateWidgetSizeRanges(
- AppWidgetHostView widgetView, Context context, int spanX, int spanY) {
- List<SizeF> sizes = getWidgetSizes(context, spanX, spanY);
- if (ATLEAST_S) {
- widgetView.updateAppWidgetSize(new Bundle(), sizes);
- } else {
- Rect bounds = getMinMaxSizes(sizes);
- widgetView.updateAppWidgetSize(new Bundle(), bounds.left, bounds.top, bounds.right,
- bounds.bottom);
- }
- }
-
- /** Returns the list of sizes for a widget of given span, in dp. */
- public static ArrayList<SizeF> getWidgetSizes(Context context, int spanX, int spanY) {
- ArrayList<SizeF> sizes = new ArrayList<>(2);
- final float density = context.getResources().getDisplayMetrics().density;
- Point cellSize = new Point();
-
- for (DeviceProfile profile : LauncherAppState.getIDP(context).supportedProfiles) {
- final float hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacingPx;
- final float vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacingPx;
- profile.getCellSize(cellSize);
- sizes.add(new SizeF(
- ((spanX * cellSize.x) + hBorderSpacing) / density,
- ((spanY * cellSize.y) + vBorderSpacing) / density));
- }
- return sizes;
- }
-
- /**
- * Returns the bundle to be used as the default options for a widget with provided size
- */
- public static Bundle getWidgetSizeOptions(
- Context context, ComponentName provider, int spanX, int spanY) {
- ArrayList<SizeF> sizes = getWidgetSizes(context, spanX, spanY);
- Rect padding = getDefaultPaddingForWidget(context, provider, null);
- float density = context.getResources().getDisplayMetrics().density;
- float xPaddingDips = (padding.left + padding.right) / density;
- float yPaddingDips = (padding.top + padding.bottom) / density;
-
- ArrayList<SizeF> paddedSizes = sizes.stream()
- .map(size -> new SizeF(
- Math.max(0.f, size.getWidth() - xPaddingDips),
- Math.max(0.f, size.getHeight() - yPaddingDips)))
- .collect(Collectors.toCollection(ArrayList::new));
-
- Rect rect = AppWidgetResizeFrame.getMinMaxSizes(paddedSizes);
- Bundle options = new Bundle();
- options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, rect.left);
- options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, rect.top);
- options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, rect.right);
- options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, rect.bottom);
- options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, paddedSizes);
- return options;
- }
-
- /**
- * Returns the min and max widths and heights given a list of sizes, in dp.
- *
- * @param sizes List of sizes to get the min/max from.
- * @return A rectangle with the left (resp. top) is used for the min width (resp. height) and
- * the right (resp. bottom) for the max. The returned rectangle is set with 0s if the list is
- * empty.
- */
- private static Rect getMinMaxSizes(List<SizeF> sizes) {
- if (sizes.isEmpty()) {
- return new Rect();
- } else {
- SizeF first = sizes.get(0);
- Rect result = new Rect((int) first.getWidth(), (int) first.getHeight(),
- (int) first.getWidth(), (int) first.getHeight());
- for (int i = 1; i < sizes.size(); i++) {
- result.union((int) sizes.get(i).getWidth(), (int) sizes.get(i).getHeight());
- }
- return result;
- }
- }
-
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
@@ -764,4 +694,25 @@
|| keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END
|| 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;
+ }
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 9aa7168..578379b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1076,9 +1076,10 @@
getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
}
- if (mPrevLauncherState != state && !ALL_APPS.equals(state)
+ if (ALL_APPS.equals(mPrevLauncherState) && !ALL_APPS.equals(state)
// Making sure mAllAppsSessionLogId is not null to avoid double logging.
&& mAllAppsSessionLogId != null) {
+ getAppsView().getSearchUiManager().resetSearch();
getStatsLogManager().logger().log(LAUNCHER_ALLAPPS_EXIT);
mAllAppsSessionLogId = null;
}
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index c7323d0..ff3584a 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -27,10 +27,10 @@
import android.os.CancellationSignal;
import android.os.Process;
import android.os.UserHandle;
-import android.util.ArrayMap;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.Pair;
+import android.util.Size;
import androidx.annotation.Nullable;
@@ -50,6 +50,7 @@
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.WidgetCell;
import com.android.launcher3.widget.WidgetManagerHelper;
+import com.android.launcher3.widget.util.WidgetSizes;
import java.util.ArrayList;
import java.util.Collections;
@@ -79,9 +80,6 @@
private final UserCache mUserCache;
private final CacheDb mDb;
- private final UserHandle mMyUser = Process.myUserHandle();
- private final ArrayMap<UserHandle, Bitmap> mUserBadges = new ArrayMap<>();
-
public WidgetPreviewLoader(Context context, IconCache iconCache) {
mContext = context;
mIconCache = iconCache;
@@ -366,9 +364,9 @@
previewHeight = drawable.getIntrinsicHeight();
} else {
DeviceProfile dp = launcher.getDeviceProfile();
- int tileSize = Math.min(dp.cellWidthPx, dp.cellHeightPx);
- previewWidth = tileSize * spanX;
- previewHeight = tileSize * spanY;
+ Size widgetSize = WidgetSizes.getWidgetSizePx(dp, spanX, spanY);
+ previewWidth = widgetSize.getWidth();
+ previewHeight = widgetSize.getHeight();
}
// Scale to fit width only - let the widget preview be clipped in the
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index d136cda..17c8edc 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -114,6 +114,7 @@
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetManagerHelper;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
+import com.android.launcher3.widget.util.WidgetSizes;
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
import java.util.ArrayList;
@@ -1854,7 +1855,7 @@
item.spanX = resultSpan[0];
item.spanY = resultSpan[1];
AppWidgetHostView awhv = (AppWidgetHostView) cell;
- AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0],
+ WidgetSizes.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0],
resultSpan[1]);
}
@@ -2528,8 +2529,7 @@
((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
if (finalView != null && updateWidgetSize) {
- AppWidgetResizeFrame.updateWidgetSizeRanges(finalView, mLauncher, item.spanX,
- item.spanY);
+ WidgetSizes.updateWidgetSizeRanges(finalView, mLauncher, item.spanX, item.spanY);
}
int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 2b36f19..9faac5b 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -21,7 +21,6 @@
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
-import com.android.launcher3.AppWidgetResizeFrame;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.ButtonDropTarget;
import com.android.launcher3.CellLayout;
@@ -51,6 +50,7 @@
import com.android.launcher3.views.OptionsPopupView;
import com.android.launcher3.views.OptionsPopupView.OptionItem;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
+import com.android.launcher3.widget.util.WidgetSizes;
import java.util.ArrayList;
import java.util.Collections;
@@ -367,7 +367,7 @@
}
layout.markCellsAsOccupiedForView(host);
- AppWidgetResizeFrame.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mLauncher,
+ WidgetSizes.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mLauncher,
info.spanX, info.spanY);
host.requestLayout();
mLauncher.getModelWriter().updateItemInDatabase(info);
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index cb20fec..7249aaf 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -228,7 +228,7 @@
}
private void resetWorkProfile() {
- mWorkModeSwitch.update(!mAllAppsStore.hasModelFlag(FLAG_QUIET_MODE_ENABLED));
+ mWorkModeSwitch.updateCurrentState(!mAllAppsStore.hasModelFlag(FLAG_QUIET_MODE_ENABLED));
mAH[AdapterHolder.WORK].setupOverlay();
mAH[AdapterHolder.WORK].applyPadding();
}
@@ -482,7 +482,7 @@
private void setupWorkToggle() {
if (Utilities.ATLEAST_P) {
mWorkModeSwitch = (WorkModeSwitch) mLauncher.getLayoutInflater().inflate(
- R.layout.work_mode_switch, this, false);
+ R.layout.work_mode_fab, this, false);
this.addView(mWorkModeSwitch);
mWorkModeSwitch.setInsets(mInsets);
mWorkModeSwitch.post(this::resetWorkProfile);
@@ -669,30 +669,10 @@
}
public void onPull(float deltaDistance, float displacement) {
- absorbPullDeltaDistance(PULL_MULTIPLIER * deltaDistance,
- PULL_MULTIPLIER * displacement);
- // ideally, this should be done using EdgeEffect.onPush to create squish effect.
- // However, until such method is available, launcher to simulate the onPush method.
- mHeader.setTranslationY(-.5f * mHeaderTop * deltaDistance);
- getRecyclerViewContainer().setTranslationY(-mHeaderTop * deltaDistance);
- }
-
- public void onRelease() {
- ValueAnimator anim1 = ValueAnimator.ofFloat(1f, 0f);
- final float floatingHeaderHeight = getFloatingHeaderView().getTranslationY();
- final float recyclerViewHeight = getRecyclerViewContainer().getTranslationY();
- anim1.setDuration(200);
- anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator valueAnimator) {
- getFloatingHeaderView().setTranslationY(
- ((float) valueAnimator.getAnimatedValue()) * floatingHeaderHeight);
- getRecyclerViewContainer().setTranslationY(
- ((float) valueAnimator.getAnimatedValue()) * recyclerViewHeight);
- }
- });
- anim1.start();
- super.onRelease();
+ absorbPullDeltaDistance(PULL_MULTIPLIER * deltaDistance, PULL_MULTIPLIER * displacement);
+ // Current motion spec is to actually push and not pull
+ // on this surface. However, until EdgeEffect.onPush (b/190612804) is
+ // implemented at view level, we will simply pull
}
@Override
diff --git a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
index 16ae250..1eb726c 100644
--- a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
@@ -25,7 +25,6 @@
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.statemanager.StateManager.StateListener;
-import com.android.launcher3.views.WorkEduView;
/**
* AllAppsContainerView with launcher specific callbacks
@@ -88,13 +87,6 @@
@Override
public void onActivePageChanged(int currentActivePage) {
super.onActivePageChanged(currentActivePage);
- if (mUsingTabs) {
- if (currentActivePage == AdapterHolder.WORK) {
- WorkEduView.showWorkEduIfNeeded(mLauncher);
- } else {
- mWorkTabListener = WorkEduView.showEduFlowIfNeeded(mLauncher, mWorkTabListener);
- }
- }
}
@Override
diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java
index 4567ee6..c742909 100644
--- a/src/com/android/launcher3/allapps/WorkModeSwitch.java
+++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java
@@ -15,108 +15,57 @@
*/
package com.android.launcher3.allapps;
+import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
+
import android.content.Context;
-import android.content.SharedPreferences;
import android.graphics.Rect;
-import android.os.AsyncTask;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.ViewConfiguration;
-import android.widget.Switch;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
-import com.android.launcher3.Utilities;
import com.android.launcher3.pm.UserCache;
-import com.android.launcher3.views.ArrowTipView;
-
-import java.lang.ref.WeakReference;
/**
* Work profile toggle switch shown at the bottom of AllApps work tab
*/
-public class WorkModeSwitch extends Switch implements Insettable {
-
- private static final int WORK_TIP_THRESHOLD = 2;
- public static final String KEY_WORK_TIP_COUNTER = "worked_tip_counter";
+public class WorkModeSwitch extends Button implements Insettable, View.OnClickListener {
private Rect mInsets = new Rect();
-
- private final float[] mTouch = new float[2];
- private int mTouchSlop;
+ private boolean mWorkEnabled;
public WorkModeSwitch(Context context) {
- super(context);
- init();
+ this(context, null, 0);
}
public WorkModeSwitch(Context context, AttributeSet attrs) {
- super(context, attrs);
- init();
+ this(context, attrs, 0);
}
public WorkModeSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- init();
- }
-
- private void init() {
- ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext());
- mTouchSlop = viewConfiguration.getScaledTouchSlop();
}
@Override
- public void setChecked(boolean checked) { }
-
- @Override
- public void toggle() {
- // don't show tip if user uses toggle
- Utilities.getPrefs(getContext()).edit().putInt(KEY_WORK_TIP_COUNTER, -1).apply();
- trySetQuietModeEnabledToAllProfilesAsync(isChecked());
- }
-
- /**
- * Sets the enabled or disabled state of the button
- * @param isChecked
- */
- public void update(boolean isChecked) {
- super.setChecked(isChecked);
- setCompoundDrawablesRelativeWithIntrinsicBounds(
- isChecked ? R.drawable.ic_corp : R.drawable.ic_corp_off, 0, 0, 0);
- setEnabled(true);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
- mTouch[0] = ev.getX();
- mTouch[1] = ev.getY();
- } else if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
- if (Math.abs(mTouch[0] - ev.getX()) > mTouchSlop
- || Math.abs(mTouch[1] - ev.getY()) > mTouchSlop) {
- int action = ev.getAction();
- ev.setAction(MotionEvent.ACTION_CANCEL);
- super.onTouchEvent(ev);
- ev.setAction(action);
- return false;
- }
- }
- return super.onTouchEvent(ev);
- }
-
- private void trySetQuietModeEnabledToAllProfilesAsync(boolean enabled) {
- new SetQuietModeEnabledAsyncTask(enabled, new WeakReference<>(this)).execute();
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ setOnClickListener(this);
}
@Override
public void setInsets(Rect insets) {
int bottomInset = insets.bottom - mInsets.bottom;
mInsets.set(insets);
- setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
- getPaddingBottom() + bottomInset);
+ ViewGroup.MarginLayoutParams marginLayoutParams =
+ (ViewGroup.MarginLayoutParams) getLayoutParams();
+ if (marginLayoutParams != null) {
+ marginLayoutParams.bottomMargin = bottomInset + marginLayoutParams.bottomMargin;
+ }
}
/**
@@ -125,78 +74,41 @@
public void setWorkTabVisible(boolean workTabVisible) {
clearAnimation();
if (workTabVisible) {
+ setEnabled(true);
setVisibility(VISIBLE);
setAlpha(0);
animate().alpha(1).start();
- showTipIfNeeded();
} else {
animate().alpha(0).withEndAction(() -> this.setVisibility(GONE)).start();
}
}
- private static final class SetQuietModeEnabledAsyncTask
- extends AsyncTask<Void, Void, Boolean> {
-
- private final boolean enabled;
- private final WeakReference<WorkModeSwitch> switchWeakReference;
-
- SetQuietModeEnabledAsyncTask(boolean enabled,
- WeakReference<WorkModeSwitch> switchWeakReference) {
- this.enabled = enabled;
- this.switchWeakReference = switchWeakReference;
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- WorkModeSwitch workModeSwitch = switchWeakReference.get();
- if (workModeSwitch != null) {
- workModeSwitch.setEnabled(false);
- }
- }
-
- @Override
- protected Boolean doInBackground(Void... voids) {
- WorkModeSwitch workModeSwitch = switchWeakReference.get();
- if (workModeSwitch == null || !Utilities.ATLEAST_P) {
- return false;
- }
-
- Context context = workModeSwitch.getContext();
- UserManager userManager = context.getSystemService(UserManager.class);
- boolean showConfirm = false;
- for (UserHandle userProfile : UserCache.INSTANCE.get(context).getUserProfiles()) {
- if (Process.myUserHandle().equals(userProfile)) {
- continue;
- }
- showConfirm |= !userManager.requestQuietModeEnabled(enabled, userProfile);
- }
- return showConfirm;
- }
-
- @Override
- protected void onPostExecute(Boolean showConfirm) {
- if (showConfirm) {
- WorkModeSwitch workModeSwitch = switchWeakReference.get();
- if (workModeSwitch != null) {
- workModeSwitch.setEnabled(true);
- }
- }
- }
+ @Override
+ public void onClick(View view) {
+ setEnabled(false);
+ UI_HELPER_EXECUTOR.post(() -> setToState(!mWorkEnabled));
}
/**
- * Shows a work tip on the Nth work tab open
+ * Sets the enabled or disabled state of the button
*/
- public void showTipIfNeeded() {
- Context context = getContext();
- SharedPreferences prefs = Utilities.getPrefs(context);
- int tipCounter = prefs.getInt(KEY_WORK_TIP_COUNTER, WORK_TIP_THRESHOLD);
- if (tipCounter < 0) return;
- if (tipCounter == 0) {
- new ArrowTipView(context)
- .show(context.getString(R.string.work_switch_tip), getTop());
+ public void updateCurrentState(boolean active) {
+ mWorkEnabled = active;
+ setEnabled(true);
+ setCompoundDrawablesRelativeWithIntrinsicBounds(
+ active ? R.drawable.ic_corp_off : R.drawable.ic_corp, 0, 0, 0);
+ setText(active ? R.string.work_apps_pause_btn_text : R.string.work_apps_enable_btn_text);
+ }
+
+ protected Boolean setToState(boolean toState) {
+ UserManager userManager = getContext().getSystemService(UserManager.class);
+ boolean showConfirm = false;
+ for (UserHandle userProfile : UserCache.INSTANCE.get(getContext()).getUserProfiles()) {
+ if (Process.myUserHandle().equals(userProfile)) {
+ continue;
+ }
+ showConfirm |= !userManager.requestQuietModeEnabled(!toState, userProfile);
}
- prefs.edit().putInt(KEY_WORK_TIP_COUNTER, tipCounter - 1).apply();
+ return showConfirm;
}
}
diff --git a/src/com/android/launcher3/anim/AlphaUpdateListener.java b/src/com/android/launcher3/anim/AlphaUpdateListener.java
index eabd283..8dad1b4 100644
--- a/src/com/android/launcher3/anim/AlphaUpdateListener.java
+++ b/src/com/android/launcher3/anim/AlphaUpdateListener.java
@@ -17,6 +17,7 @@
package com.android.launcher3.anim;
import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.view.View;
@@ -25,7 +26,7 @@
/**
* A convenience class to update a view's visibility state after an alpha animation.
*/
-public class AlphaUpdateListener extends AnimationSuccessListener
+public class AlphaUpdateListener extends AnimatorListenerAdapter
implements AnimatorUpdateListener {
public static final float ALPHA_CUTOFF_THRESHOLD = 0.01f;
@@ -41,7 +42,7 @@
}
@Override
- public void onAnimationSuccess(Animator animator) {
+ public void onAnimationEnd(Animator animator) {
updateVisibility(mView);
}
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index ab72a07..0e710b7 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -93,7 +93,7 @@
// Keep as DeviceFlag to allow remote disable in emergency.
public static final BooleanFlag ENABLE_SUGGESTED_ACTIONS_OVERVIEW = new DeviceFlag(
- "ENABLE_SUGGESTED_ACTIONS_OVERVIEW", true, "Show chip hints on the overview screen");
+ "ENABLE_SUGGESTED_ACTIONS_OVERVIEW", false, "Show chip hints on the overview screen");
public static final BooleanFlag ENABLE_DEVICE_SEARCH = new DeviceFlag(
diff --git a/src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java b/src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java
index 003b3bd..658c6e1 100644
--- a/src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java
+++ b/src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java
@@ -26,13 +26,13 @@
import androidx.annotation.Nullable;
-import com.android.launcher3.AppWidgetResizeFrame;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
+import com.android.launcher3.widget.util.WidgetSizes;
/**
* Represents a widget (either instantiated or about to be) in the Launcher.
@@ -196,7 +196,7 @@
*/
public void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) {
if (!mHasNotifiedInitialWidgetSizeChanged) {
- AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
+ WidgetSizes.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
mHasNotifiedInitialWidgetSizeChanged = true;
}
}
diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java
index 22c3f58..23ee251 100644
--- a/src/com/android/launcher3/qsb/QsbContainerView.java
+++ b/src/com/android/launcher3/qsb/QsbContainerView.java
@@ -20,8 +20,6 @@
import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_PROVIDER;
-import static com.android.launcher3.AppWidgetResizeFrame.getWidgetSizeOptions;
-
import android.app.Activity;
import android.app.Fragment;
import android.app.SearchManager;
@@ -49,6 +47,7 @@
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.FragmentWithPreview;
+import com.android.launcher3.widget.util.WidgetSizes;
/**
* A frame layout which contains a QSB. This internally uses fragment to bind the view, which
@@ -292,7 +291,8 @@
protected Bundle createBindOptions() {
InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
- return getWidgetSizeOptions(getContext(), mWidgetInfo.provider, idp.numColumns, 1);
+ return WidgetSizes.getWidgetSizeOptions(getContext(), mWidgetInfo.provider,
+ idp.numColumns, 1);
}
protected View getDefaultView(ViewGroup container, boolean showSetupIcon) {
diff --git a/src/com/android/launcher3/views/ArrowTipView.java b/src/com/android/launcher3/views/ArrowTipView.java
index 07d3776..e449a4b 100644
--- a/src/com/android/launcher3/views/ArrowTipView.java
+++ b/src/com/android/launcher3/views/ArrowTipView.java
@@ -17,8 +17,10 @@
package com.android.launcher3.views;
import android.content.Context;
+import android.content.res.Configuration;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
+import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable;
import android.os.Handler;
import android.util.Log;
@@ -53,9 +55,10 @@
protected final BaseDraggingActivity mActivity;
private final Handler mHandler = new Handler();
- private final boolean mIsPointingUp;
private final int mArrowWidth;
+ private boolean mIsPointingUp;
private Runnable mOnClosed;
+ private View mArrowView;
public ArrowTipView(Context context) {
this(context, false);
@@ -73,6 +76,9 @@
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
close(true);
+ if (mActivity.getDragLayer().isEventOverView(this, ev)) {
+ return true;
+ }
}
return false;
}
@@ -106,24 +112,8 @@
inflate(context, R.layout.arrow_toast, this);
setOrientation(LinearLayout.VERTICAL);
- View arrowView = findViewById(R.id.arrow);
- ViewGroup.LayoutParams arrowLp = arrowView.getLayoutParams();
- 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);
+ mArrowView = findViewById(R.id.arrow);
+ updateArrowTipInView();
}
/**
@@ -136,10 +126,10 @@
/**
* Show the ArrowTipView (tooltip) center, start, or end aligned.
*
- * @param text The text to be shown in the tooltip.
- * @param gravity The gravity aligns the tooltip center, start, or end.
+ * @param text The text to be shown in the tooltip.
+ * @param gravity The gravity aligns the tooltip center, start, or end.
* @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.
*/
public ArrowTipView show(String text, int gravity, int arrowMarginStart, int top) {
@@ -149,8 +139,7 @@
DragLayer.LayoutParams params = (DragLayer.LayoutParams) getLayoutParams();
params.gravity = gravity;
- LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) findViewById(
- R.id.arrow).getLayoutParams();
+ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mArrowView.getLayoutParams();
lp.gravity = gravity;
if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
@@ -166,6 +155,9 @@
params.leftMargin = mActivity.getDeviceProfile().workspacePadding.left;
params.rightMargin = mActivity.getDeviceProfile().workspacePadding.right;
post(() -> setY(top - (mIsPointingUp ? 0 : getHeight())));
+
+ mIsOpen = true;
+ mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
setAlpha(0);
animate()
.alpha(1f)
@@ -178,18 +170,61 @@
}
/**
- * 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 arrowXCoord The X coordinate for the arrow on the tip. The arrow is usually in the
- * center of ArrowTipView unless the ArrowTipView goes beyond screen margin.
- * @param yCoord The Y coordinate of the bottom of the tooltip.
- * @return The tool tip view.
+ * @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 yCoord The Y coordinate of the pointed tip end of the tooltip.
+ * @return The tool tip view. {@code null} if the tip can not be shown.
*/
- @Nullable
- public ArrowTipView showAtLocation(String text, int arrowXCoord, int yCoord) {
+ @Nullable public ArrowTipView showAtLocation(String text, @Px int arrowXCoord, @Px 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();
@Px int parentViewWidth = parent.getWidth();
+ @Px int parentViewHeight = parent.getHeight();
@Px int maxTextViewWidth = getContext().getResources()
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_max_width);
@Px int minViewMargin = getContext().getResources()
@@ -206,22 +241,45 @@
requestLayout();
post(() -> {
+ // Adjust the tooltip horizontally.
float halfWidth = getWidth() / 2f;
float xCoord;
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;
} 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();
} else {
+ // Place the tooltip such that its center is at arrowXCoord.
xCoord = arrowXCoord - halfWidth;
}
setX(xCoord);
- setY(yCoord - getHeight());
- View arrowView = findViewById(R.id.arrow);
- arrowView.setX(arrowXCoord - xCoord - arrowView.getWidth() / 2f);
+
+ // Adjust the tooltip vertically.
+ @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();
});
+ mIsOpen = true;
+ mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
setAlpha(0);
animate()
.alpha(1f)
@@ -233,6 +291,27 @@
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
*/
@@ -240,4 +319,10 @@
mOnClosed = runnable;
return this;
}
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ close(/* animate= */ false);
+ }
}
diff --git a/src/com/android/launcher3/views/SpringRelativeLayout.java b/src/com/android/launcher3/views/SpringRelativeLayout.java
index 8342d3e..8e3ac20 100644
--- a/src/com/android/launcher3/views/SpringRelativeLayout.java
+++ b/src/com/android/launcher3/views/SpringRelativeLayout.java
@@ -93,7 +93,7 @@
invalidate();
}
- protected void onRelease() {
+ public void onRelease() {
mEdgeGlowBottom.onRelease();
}
diff --git a/src/com/android/launcher3/views/WorkEduView.java b/src/com/android/launcher3/views/WorkEduView.java
deleted file mode 100644
index 6be0c23..0000000
--- a/src/com/android/launcher3/views/WorkEduView.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * 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.
- */
-package com.android.launcher3.views;
-
-
-import android.animation.Animator;
-import android.animation.ObjectAnimator;
-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 android.widget.Button;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.android.launcher3.Insettable;
-import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherState;
-import com.android.launcher3.R;
-import com.android.launcher3.allapps.AllAppsContainerView;
-import com.android.launcher3.allapps.AllAppsPagedView;
-import com.android.launcher3.anim.AnimationSuccessListener;
-import com.android.launcher3.anim.Interpolators;
-import com.android.launcher3.statemanager.StateManager.StateListener;
-
-/**
- * On boarding flow for users right after setting up work profile
- */
-public class WorkEduView extends AbstractSlideInView<Launcher>
- implements Insettable, StateListener<LauncherState> {
-
- private static final int DEFAULT_CLOSE_DURATION = 200;
- public static final String KEY_WORK_EDU_STEP = "showed_work_profile_edu";
- public static final String KEY_LEGACY_WORK_EDU_SEEN = "showed_bottom_user_education";
-
- private static final int WORK_EDU_NOT_STARTED = 0;
- private static final int WORK_EDU_PERSONAL_APPS = 1;
- private static final int WORK_EDU_WORK_APPS = 2;
-
- protected static final int FINAL_SCRIM_BG_COLOR = 0x88000000;
-
-
- private Rect mInsets = new Rect();
- private View mViewWrapper;
- private Button mProceedButton;
- private TextView mContentText;
-
- private int mNextWorkEduStep = WORK_EDU_PERSONAL_APPS;
-
-
- public WorkEduView(Context context, AttributeSet attr) {
- this(context, attr, 0);
- }
-
- public WorkEduView(Context context, AttributeSet attrs,
- int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- mContent = this;
- }
-
- @Override
- protected void handleClose(boolean animate) {
- mActivityContext.getSharedPrefs().edit()
- .putInt(KEY_WORK_EDU_STEP, mNextWorkEduStep).apply();
- handleClose(true, DEFAULT_CLOSE_DURATION);
- }
-
- @Override
- protected void onCloseComplete() {
- super.onCloseComplete();
- mActivityContext.getStateManager().removeStateListener(this);
- }
-
- @Override
- protected boolean isOfType(int type) {
- return (type & TYPE_ON_BOARD_POPUP) != 0;
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mViewWrapper = findViewById(R.id.view_wrapper);
- mProceedButton = findViewById(R.id.proceed);
- mContentText = findViewById(R.id.content_text);
-
- // make sure layout does not shrink when we change the text
- mContentText.post(() -> mContentText.setMinLines(mContentText.getLineCount()));
-
- mProceedButton.setOnClickListener(view -> {
- if (getAllAppsPagedView() != null) {
- getAllAppsPagedView().snapToPage(AllAppsContainerView.AdapterHolder.WORK);
- }
- goToWorkTab(true);
- });
- }
-
- private void goToWorkTab(boolean animate) {
- mProceedButton.setText(R.string.work_profile_edu_accept);
- if (animate) {
- ObjectAnimator animator = ObjectAnimator.ofFloat(mContentText, ALPHA, 0);
- animator.addListener(new AnimationSuccessListener() {
- @Override
- public void onAnimationSuccess(Animator animator) {
- mContentText.setText(
- mActivityContext.getString(R.string.work_profile_edu_work_apps));
- ObjectAnimator.ofFloat(mContentText, ALPHA, 1).start();
- }
- });
- animator.start();
- } else {
- mContentText.setText(mActivityContext.getString(R.string.work_profile_edu_work_apps));
- }
- mNextWorkEduStep = WORK_EDU_WORK_APPS;
- mProceedButton.setOnClickListener(v -> handleClose(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);
- mViewWrapper.setPaddingRelative(mViewWrapper.getPaddingStart(),
- mViewWrapper.getPaddingTop(), mViewWrapper.getPaddingEnd(), bottomInset);
- }
-
- private void show() {
- attachToContainer();
- animateOpen();
- mActivityContext.getStateManager().addStateListener(this);
- }
-
- @Override
- protected int getScrimColor(Context context) {
- return FINAL_SCRIM_BG_COLOR;
- }
-
- private void goToFirstPage() {
- if (getAllAppsPagedView() != null) {
- getAllAppsPagedView().snapToPageImmediately(AllAppsContainerView.AdapterHolder.MAIN);
- }
- }
-
- private void animateOpen() {
- if (mIsOpen || mOpenCloseAnimator.isRunning()) {
- return;
- }
- mIsOpen = true;
- mOpenCloseAnimator.setValues(
- PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
- mOpenCloseAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
- mOpenCloseAnimator.start();
- }
-
- private AllAppsPagedView getAllAppsPagedView() {
- View v = mActivityContext.getAppsView().getContentView();
- return (v instanceof AllAppsPagedView) ? (AllAppsPagedView) v : null;
- }
-
- /**
- * Checks if user has not seen onboarding UI yet and shows it when user navigates to all apps
- */
- public static StateListener<LauncherState> showEduFlowIfNeeded(Launcher launcher,
- @Nullable StateListener<LauncherState> oldListener) {
- if (oldListener != null) {
- launcher.getStateManager().removeStateListener(oldListener);
- }
- if (hasSeenLegacyEdu(launcher) || launcher.getSharedPrefs().getInt(KEY_WORK_EDU_STEP,
- WORK_EDU_NOT_STARTED) != WORK_EDU_NOT_STARTED) {
- return null;
- }
-
- StateListener<LauncherState> listener = new StateListener<LauncherState>() {
- @Override
- public void onStateTransitionComplete(LauncherState finalState) {
- if (finalState != LauncherState.ALL_APPS) return;
- LayoutInflater layoutInflater = LayoutInflater.from(launcher);
- WorkEduView v = (WorkEduView) layoutInflater.inflate(
- R.layout.work_profile_edu, launcher.getDragLayer(),
- false);
- v.show();
- v.goToFirstPage();
- launcher.getStateManager().removeStateListener(this);
- }
- };
- launcher.getStateManager().addStateListener(listener);
- return listener;
- }
-
- /**
- * Shows work apps edu if user had dismissed full edu flow
- */
- public static void showWorkEduIfNeeded(Launcher launcher) {
- if (hasSeenLegacyEdu(launcher) || launcher.getSharedPrefs().getInt(KEY_WORK_EDU_STEP,
- WORK_EDU_NOT_STARTED) != WORK_EDU_PERSONAL_APPS) {
- return;
- }
- LayoutInflater layoutInflater = LayoutInflater.from(launcher);
- WorkEduView v = (WorkEduView) layoutInflater.inflate(
- R.layout.work_profile_edu, launcher.getDragLayer(), false);
- v.show();
- v.goToWorkTab(false);
- }
-
- private static boolean hasSeenLegacyEdu(Launcher launcher) {
- return launcher.getSharedPrefs().getBoolean(KEY_LEGACY_WORK_EDU_SEEN, false);
- }
-
- @Override
- public void onStateTransitionComplete(LauncherState finalState) {
- close(false);
- }
-}
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index edd42b4..3bf993e 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -207,16 +207,18 @@
if (view == null || !ViewCompat.isLaidOut(view)) {
return null;
}
-
- mActivityContext.getSharedPrefs().edit()
- .putBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, true).apply();
int[] coords = new int[2];
view.getLocationOnScreen(coords);
- ArrowTipView arrowTipView = new ArrowTipView(mActivityContext);
- return arrowTipView.showAtLocation(
- getContext().getString(R.string.long_press_widget_to_add),
- /* arrowXCoord= */coords[0] + view.getWidth() / 2,
- /* yCoord= */coords[1]);
+ ArrowTipView arrowTipView =
+ new ArrowTipView(mActivityContext, /* isPointingUp= */ false).showAtLocation(
+ getContext().getString(R.string.long_press_widget_to_add),
+ /* arrowXCoord= */coords[0] + view.getWidth() / 2,
+ /* 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}. */
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
index 14108f6..5a29171 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
@@ -32,13 +32,44 @@
public static final String CLS_CUSTOM_WIDGET_PREFIX = "#custom-widget-";
+ /**
+ * The desired number of cells that this widget occupies horizontally in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int spanX;
+
+ /**
+ * The desired number of cells that this widget occupies vertically in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int spanY;
+
+ /**
+ * The minimum number of cells that this widget can occupy horizontally in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int minSpanX;
+
+ /**
+ * The minimum number of cells that this widget can occupy vertically in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int minSpanY;
+
+ /**
+ * The maximum number of cells that this widget can occupy horizontally in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int maxSpanX;
+
+ /**
+ * The maximum number of cells that this widget can occupy vertically in
+ * {@link com.android.launcher3.CellLayout}.
+ */
public int maxSpanY;
+ private boolean mIsMinSizeFulfilled;
+
public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context,
AppWidgetProviderInfo info) {
final LauncherAppWidgetProviderInfo launcherInfo;
@@ -133,8 +164,20 @@
this.minSpanY = minSpanY;
this.maxSpanX = maxSpanX;
this.maxSpanY = maxSpanY;
- this.spanX = spanX;
- this.spanY = spanY;
+ this.mIsMinSizeFulfilled = Math.min(spanX, minSpanX) <= idp.numColumns
+ && Math.min(spanY, minSpanY) <= idp.numRows;
+ // Ensures the default span X and span Y will not exceed the current grid size.
+ this.spanX = Math.min(spanX, idp.numColumns);
+ this.spanY = Math.min(spanY, idp.numRows);
+ }
+
+ /**
+ * Returns {@code true} if the widget's minimum size requirement can be fulfilled in the device
+ * grid setting, {@link InvariantDeviceProfile}, that was passed in
+ * {@link #initSpans(Context, InvariantDeviceProfile)}.
+ */
+ public boolean isMinSizeFulfilled() {
+ return mIsMinSizeFulfilled;
}
private int getSpanX(Rect widgetPadding, int widgetWidth, int cellSpacing, float cellWidth) {
diff --git a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
index 3377abb..c04c8dc 100644
--- a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
@@ -15,7 +15,6 @@
*/
package com.android.launcher3.widget;
-import static com.android.launcher3.AppWidgetResizeFrame.getWidgetSizeOptions;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY;
import android.appwidget.AppWidgetHostView;
@@ -24,6 +23,7 @@
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.PendingAddItemInfo;
+import com.android.launcher3.widget.util.WidgetSizes;
/**
* Meta data used for late binding of {@link LauncherAppWidgetProviderInfo}.
@@ -61,6 +61,6 @@
}
public Bundle getDefaultSizeOptions(Context context) {
- return getWidgetSizeOptions(context, componentName, spanX, spanY);
+ return WidgetSizes.getWidgetSizeOptions(context, componentName, spanX, spanY);
}
}
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index e1999c9..b1ccfd9 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -21,12 +21,12 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.CancellationSignal;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.Size;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@@ -48,6 +48,7 @@
import com.android.launcher3.icons.FastBitmapDrawable;
import com.android.launcher3.icons.RoundDrawableWrapper;
import com.android.launcher3.model.WidgetItem;
+import com.android.launcher3.widget.util.WidgetSizes;
/**
* Represents the individual cell of the widget inside the widget tray. The preview is drawn
@@ -96,7 +97,7 @@
protected final BaseActivity mActivity;
private final CheckLongPressHelper mLongPressHelper;
private final float mEnforcedCornerRadius;
- private final int mPreviewPadding;
+ private final int mShortcutPreviewPadding;
private RemoteViews mRemoteViewsPreview;
private NavigableAppWidgetHostView mAppWidgetHostViewPreview;
@@ -114,14 +115,14 @@
mActivity = BaseActivity.fromContext(context);
mLongPressHelper = new CheckLongPressHelper(this);
-
mLongPressHelper.setLongPressTimeoutFactor(1);
+
setContainerWidth();
setWillNotDraw(false);
setClipToPadding(false);
setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(context);
- mPreviewPadding =
+ mShortcutPreviewPadding =
2 * getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
}
@@ -200,6 +201,8 @@
mWidgetPreviewLoader = loader;
if (item.activityInfo != null) {
setTag(new PendingAddShortcutInfo(item.activityInfo));
+ mPreviewWidth += mShortcutPreviewPadding;
+ mPreviewHeight += mShortcutPreviewPadding;
} else {
setTag(new PendingAddWidgetInfo(item.widgetInfo));
}
@@ -251,8 +254,6 @@
}
appWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right,
padding.bottom);
- mPreviewWidth += padding.left + padding.right;
- mPreviewHeight += padding.top + padding.bottom;
appWidgetHostViewPreview.updateAppWidget(remoteViews);
}
@@ -299,7 +300,7 @@
float scale = 1f;
if (getWidth() > 0 && getHeight() > 0) {
// Scale down the preview size if it's wider than the cell.
- float maxWidth = getWidth() - mPreviewPadding;
+ float maxWidth = getWidth();
float previewWidth = drawable.getIntrinsicWidth() * mPreviewScale;
scale = Math.min(maxWidth / previewWidth, 1);
}
@@ -355,11 +356,9 @@
/** Sets the widget preview image size, in number of cells, and preview scale. */
public void setPreviewSize(int spanX, int spanY, float previewScale) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
- Point cellSize = deviceProfile.getCellSize();
- mPreviewWidth = cellSize.x * spanX + mPreviewPadding
- + deviceProfile.cellLayoutBorderSpacingPx * (spanX - 1);
- mPreviewHeight = cellSize.y * spanY + mPreviewPadding
- + deviceProfile.cellLayoutBorderSpacingPx * (spanY - 1);
+ Size widgetSize = WidgetSizes.getWidgetSizePx(deviceProfile, spanX, spanY);
+ mPreviewWidth = widgetSize.getWidth();
+ mPreviewHeight = widgetSize.getHeight();
mPreviewScale = previewScale;
}
diff --git a/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java b/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
index 826c244..150bd99 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsListAdapter.java
@@ -202,11 +202,16 @@
mDiffReporter.process(mVisibleEntries, newVisibleEntries, mRowComparator);
}
+ /** Returns whether {@code entry} matches {@link #mWidgetsContentVisiblePackageUserKey}. */
private boolean isHeaderForVisibleContent(WidgetsListBaseEntry entry) {
+ return isHeaderForPackageUserKey(entry, mWidgetsContentVisiblePackageUserKey);
+ }
+
+ /** Returns whether {@code entry} matches {@code key}. */
+ private boolean isHeaderForPackageUserKey(WidgetsListBaseEntry entry, PackageUserKey key) {
return (entry instanceof WidgetsListHeaderEntry
|| entry instanceof WidgetsListSearchHeaderEntry)
- && new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)
- .equals(mWidgetsContentVisiblePackageUserKey);
+ && new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user).equals(key);
}
/**
@@ -270,36 +275,68 @@
@Override
public void onHeaderClicked(boolean showWidgets, PackageUserKey packageUserKey) {
+ // Ignore invalid clicks, such as collapsing a package that isn't currently expanded.
+ if (!showWidgets && !packageUserKey.equals(mWidgetsContentVisiblePackageUserKey)) return;
+
if (showWidgets) {
mWidgetsContentVisiblePackageUserKey = packageUserKey;
- updateVisibleEntries();
- // Scroll the layout manager to the header position to keep it anchored to the same
- // position.
- scrollToPositionAndMaintainOffset(getSelectedHeaderPosition());
mLauncher.getStatsLogManager().logger().log(LAUNCHER_WIDGETSTRAY_APP_EXPANDED);
- } else if (packageUserKey.equals(mWidgetsContentVisiblePackageUserKey)) {
- OptionalInt previouslySelectedPosition = getSelectedHeaderPosition();
-
+ } else {
mWidgetsContentVisiblePackageUserKey = null;
- updateVisibleEntries();
-
- // Scroll to the header that was just collapsed so it maintains its scroll offset.
- scrollToPositionAndMaintainOffset(previouslySelectedPosition);
}
+
+ // Get the current top of the header with the matching key before adjusting the visible
+ // entries.
+ OptionalInt topForPackageUserKey =
+ getOffsetForPosition(getPositionForPackageUserKey(packageUserKey));
+
+ updateVisibleEntries();
+
+ // Get the position for the clicked header after adjusting the visible entries. The
+ // position may have changed if another header had previously been expanded.
+ OptionalInt positionForPackageUserKey = getPositionForPackageUserKey(packageUserKey);
+ scrollToPositionAndMaintainOffset(positionForPackageUserKey, topForPackageUserKey);
}
- private OptionalInt getSelectedHeaderPosition() {
+ /**
+ * Returns the position of {@code key} in {@link #mVisibleEntries}, or empty if it's not
+ * present.
+ */
+ private OptionalInt getPositionForPackageUserKey(PackageUserKey key) {
return IntStream.range(0, mVisibleEntries.size())
- .filter(index -> isHeaderForVisibleContent(mVisibleEntries.get(index)))
+ .filter(index -> isHeaderForPackageUserKey(mVisibleEntries.get(index), key))
.findFirst();
}
/**
- * Scrolls to the selected header position. LinearLayoutManager scrolls the minimum distance
- * necessary, so this will keep the selected header in place during clicks, without interrupting
- * the animation.
+ * Returns the top of {@code positionOptional} in the recycler view, or empty if its view
+ * can't be found for any reason, including the position not being currently visible. The
+ * returned value does not include the top padding of the recycler view.
*/
- private void scrollToPositionAndMaintainOffset(OptionalInt positionOptional) {
+ private OptionalInt getOffsetForPosition(OptionalInt positionOptional) {
+ if (!positionOptional.isPresent() || mRecyclerView == null) return OptionalInt.empty();
+
+ RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
+ if (layoutManager == null) return OptionalInt.empty();
+
+ View view = layoutManager.findViewByPosition(positionOptional.getAsInt());
+ if (view == null) return OptionalInt.empty();
+
+ return OptionalInt.of(layoutManager.getDecoratedTop(view));
+ }
+
+ /**
+ * Scrolls to the selected header position with the provided offset. LinearLayoutManager
+ * scrolls the minimum distance necessary, so this will keep the selected header in place during
+ * clicks, without interrupting the animation.
+ *
+ * @param positionOptional The position too scroll to. No scrolling will be done if empty.
+ * @param offsetOptional The offset from the top to maintain. If empty, then the list will
+ * scroll to the top of the position.
+ */
+ private void scrollToPositionAndMaintainOffset(
+ OptionalInt positionOptional,
+ OptionalInt offsetOptional) {
if (!positionOptional.isPresent() || mRecyclerView == null) return;
int position = positionOptional.getAsInt();
@@ -317,12 +354,9 @@
// Scroll to the header view's current offset, accounting for the recycler view's padding.
// If the header view couldn't be found, then it will appear at the top of the list.
- View headerView = layoutManager.findViewByPosition(position);
- int targetHeaderViewTop =
- headerView == null ? 0 : layoutManager.getDecoratedTop(headerView);
layoutManager.scrollToPositionWithOffset(
position,
- targetHeaderViewTop - mRecyclerView.getPaddingTop());
+ offsetOptional.orElse(0) - mRecyclerView.getPaddingTop());
}
/**
diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
index 62ef4ff..fe42ddf 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.Size;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@@ -33,6 +34,7 @@
import com.android.launcher3.R;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.widget.WidgetCell;
+import com.android.launcher3.widget.util.WidgetSizes;
import java.util.ArrayList;
import java.util.List;
@@ -43,8 +45,8 @@
private static final float DOWN_SCALE_RATIO = 0.9f;
private static final float MAX_DOWN_SCALE_RATIO = 0.5f;
private final float mWidgetsRecommendationTableVerticalPadding;
+ private final float mWidgetCellVerticalPadding;
private final float mWidgetCellTextViewsHeight;
- private final float mWidgetPreviewPadding;
private float mRecommendationTableMaxHeight = Float.MAX_VALUE;
@Nullable private OnLongClickListener mWidgetCellOnLongClickListener;
@@ -59,10 +61,10 @@
super(context, attrs);
// There are 1 row for title, 1 row for dimension and 2 rows for description.
mWidgetsRecommendationTableVerticalPadding = 2 * getResources()
+ .getDimensionPixelSize(R.dimen.recommended_widgets_table_vertical_padding);
+ mWidgetCellVerticalPadding = 2 * getResources()
.getDimensionPixelSize(R.dimen.widget_cell_vertical_padding);
mWidgetCellTextViewsHeight = 4 * getResources().getDimension(R.dimen.widget_cell_font_size);
- mWidgetPreviewPadding = 2 * getResources()
- .getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
}
/** Sets a {@link android.view.View.OnLongClickListener} for all widget cells in this table. */
@@ -149,9 +151,12 @@
List<WidgetItem> widgetItems = recommendedWidgetsInTable.get(i);
float rowHeight = 0;
for (int j = 0; j < widgetItems.size(); j++) {
- float previewHeight = widgetItems.get(j).spanY * deviceProfile.cellHeightPx
- * previewScale + mWidgetPreviewPadding;
- rowHeight = Math.max(rowHeight, previewHeight + mWidgetCellTextViewsHeight);
+ WidgetItem widgetItem = widgetItems.get(j);
+ Size widgetSize = WidgetSizes.getWidgetSizePx(
+ deviceProfile, widgetItem.spanX, widgetItem.spanY);
+ float previewHeight = widgetSize.getHeight() * previewScale;
+ rowHeight = Math.max(rowHeight,
+ previewHeight + mWidgetCellTextViewsHeight + mWidgetCellVerticalPadding);
}
totalHeight += rowHeight;
}
diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java
new file mode 100644
index 0000000..5c8ea72
--- /dev/null
+++ b/src/com/android/launcher3/widget/util/WidgetSizes.java
@@ -0,0 +1,145 @@
+/*
+ * 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.widget.util;
+
+import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;
+
+import static com.android.launcher3.Utilities.ATLEAST_S;
+
+import android.annotation.SuppressLint;
+import android.appwidget.AppWidgetHostView;
+import android.appwidget.AppWidgetManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.Bundle;
+import android.util.Size;
+import android.util.SizeF;
+
+import androidx.annotation.Nullable;
+
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.LauncherAppState;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** A utility class for widget sizes related calculations. */
+public final class WidgetSizes {
+
+ /**
+ * Returns the list of all possible sizes, in dp, for a widget of given spans on this device.
+ */
+ public static ArrayList<SizeF> getWidgetSizes(Context context, int spanX, int spanY) {
+ ArrayList<SizeF> sizes = new ArrayList<>(2);
+ final float density = context.getResources().getDisplayMetrics().density;
+ final Point cellSize = new Point();
+
+ for (DeviceProfile profile : LauncherAppState.getIDP(context).supportedProfiles) {
+ Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY, cellSize);
+ sizes.add(new SizeF(widgetSizePx.getWidth() / density,
+ widgetSizePx.getHeight() / density));
+ }
+ return sizes;
+ }
+
+ /** Returns the size, in pixels, a widget of given spans & {@code profile}. */
+ public static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY) {
+ return getWidgetSizePx(profile, spanX, spanY, /* recycledCellSize= */ null);
+ }
+
+ private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,
+ @Nullable Point recycledCellSize) {
+ final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacingPx;
+ final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacingPx;
+ if (recycledCellSize == null) {
+ recycledCellSize = new Point();
+ }
+ profile.getCellSize(recycledCellSize);
+ return new Size(((spanX * recycledCellSize.x) + hBorderSpacing),
+ ((spanY * recycledCellSize.y) + vBorderSpacing));
+ }
+
+ /**
+ * Updates a given {@code widgetView} with size, {@code spanX}, {@code spanY}.
+ *
+ * <p>On Android S+, it also updates the given {@code widgetView} with a list of sizes derived
+ * from {@code spanX}, {@code spanY} in all supported device profiles.
+ */
+ @SuppressLint("NewApi") // Already added API check.
+ public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Context context,
+ int spanX, int spanY) {
+ List<SizeF> sizes = getWidgetSizes(context, spanX, spanY);
+ if (ATLEAST_S) {
+ widgetView.updateAppWidgetSize(new Bundle(), sizes);
+ } else {
+ Rect bounds = getMinMaxSizes(sizes);
+ widgetView.updateAppWidgetSize(new Bundle(), bounds.left, bounds.top, bounds.right,
+ bounds.bottom);
+ }
+ }
+
+ /**
+ * Returns the bundle to be used as the default options for a widget with provided size.
+ */
+ public static Bundle getWidgetSizeOptions(Context context, ComponentName provider, int spanX,
+ int spanY) {
+ ArrayList<SizeF> sizes = getWidgetSizes(context, spanX, spanY);
+ Rect padding = getDefaultPaddingForWidget(context, provider, null);
+ float density = context.getResources().getDisplayMetrics().density;
+ float xPaddingDips = (padding.left + padding.right) / density;
+ float yPaddingDips = (padding.top + padding.bottom) / density;
+
+ ArrayList<SizeF> paddedSizes = sizes.stream()
+ .map(size -> new SizeF(
+ Math.max(0.f, size.getWidth() - xPaddingDips),
+ Math.max(0.f, size.getHeight() - yPaddingDips)))
+ .collect(Collectors.toCollection(ArrayList::new));
+
+ Rect rect = getMinMaxSizes(paddedSizes);
+ Bundle options = new Bundle();
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, rect.left);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, rect.top);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, rect.right);
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, rect.bottom);
+ options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, paddedSizes);
+ return options;
+ }
+
+ /**
+ * Returns the min and max widths and heights given a list of sizes, in dp.
+ *
+ * @param sizes List of sizes to get the min/max from.
+ * @return A rectangle with the left (resp. top) is used for the min width (resp. height) and
+ * the right (resp. bottom) for the max. The returned rectangle is set with 0s if the list is
+ * empty.
+ */
+ private static Rect getMinMaxSizes(List<SizeF> sizes) {
+ if (sizes.isEmpty()) {
+ return new Rect();
+ } else {
+ SizeF first = sizes.get(0);
+ Rect result = new Rect((int) first.getWidth(), (int) first.getHeight(),
+ (int) first.getWidth(), (int) first.getHeight());
+ for (int i = 1; i < sizes.size(); i++) {
+ result.union((int) sizes.get(i).getWidth(), (int) sizes.get(i).getHeight());
+ }
+ return result;
+ }
+ }
+}
diff --git a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
index 8f9cdc8..59ada7b 100644
--- a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
+++ b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
@@ -126,6 +126,7 @@
@Override
public void setActiveMarker(int activePage) {
updateTabTextColor(activePage);
+ updateIndicatorPosition(activePage);
if (mOnActivePageChangedListener != null && mLastActivePage != activePage) {
mOnActivePageChangedListener.onActivePageChanged(activePage);
}
diff --git a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
index be18e54..51c5b12 100644
--- a/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
+++ b/src_shortcuts_overrides/com/android/launcher3/model/WidgetsModel.java
@@ -254,13 +254,11 @@
}
// Ensure that all widgets we show can be added on a workspace of this size
- int minSpanX = Math.min(item.widgetInfo.spanX, item.widgetInfo.minSpanX);
- int minSpanY = Math.min(item.widgetInfo.spanY, item.widgetInfo.minSpanY);
- if (minSpanX > mIdp.numColumns || minSpanY > mIdp.numRows) {
+ if (!item.widgetInfo.isMinSizeFulfilled()) {
if (DEBUG) {
Log.d(TAG, String.format(
- "Widget %s : (%d X %d) can't fit on this device",
- item.componentName, minSpanX, minSpanY));
+ "Widget %s : can't fit on this device with a grid size: %dx%d",
+ item.componentName, mIdp.numColumns, mIdp.numRows));
}
return false;
}