Merge "Extract widget picker intent extras in WidgetPickerActivity" into main

This commit is contained in:
Shamali Patwa authored and Android (Google) Code Review committed 2025-05-27 20:09:52 -07:00
commit 3b04cf3155
9 files changed
+233 -85

No files matched your search

+16
View File
@@ -26,6 +26,10 @@
Refer comments around specific entries on how to extend individual components.
-->
<!-- Permission required to start a WidgetPickerActivity. -->
<permission android:name="${applicationId}.permission.START_WIDGET_PICKER_ACTIVITY"
android:protectionLevel="signature|privileged" />
<application
android:backupAgent="com.android.launcher3.LauncherBackupAgent"
android:fullBackupOnly="true"
@@ -70,5 +74,17 @@
android:value="${packageName}.grid_control" />
</activity>
<activity android:name="com.android.launcher3.widgetpicker.WidgetPickerActivity"
android:theme="@style/WidgetPickerActivityTheme"
android:excludeFromRecents="true"
android:autoRemoveFromRecents="true"
android:launchMode="singleTop"
android:exported="true"
android:permission="${applicationId}.permission.START_WIDGET_PICKER_ACTIVITY">
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
+1 -2
View File
@@ -150,11 +150,10 @@
</intent-filter>
</activity>
<activity android:name="com.android.launcher3.WidgetPickerActivity"
<activity android:name="com.android.launcher3.QuickstepWidgetPickerActivity"
android:theme="@style/WidgetPickerActivityTheme"
android:excludeFromRecents="true"
android:autoRemoveFromRecents="true"
android:showOnLockScreen="true"
android:launchMode="singleTop"
android:exported="true"
android:permission="${applicationId}.permission.START_WIDGET_PICKER_ACTIVITY">
-12
View File
@@ -342,18 +342,6 @@
<item name="android:lineHeight">20sp</item>
</style>
<style name="WidgetPickerActivityTheme" parent="@android:style/Theme.DeviceDefault.DayNight">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="widgetsTheme">@style/WidgetContainerTheme</item>
<item name="pageIndicatorDotColor">@color/page_indicator_dot_color_light</item>
</style>
<style name="TextAppearance.Nudge.Title" parent="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
<item name="android:fontFamily">google-sans</item>
@@ -32,6 +32,7 @@ import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
import android.view.WindowInsetsController;
@@ -42,36 +43,34 @@ import android.window.OnBackInvokedDispatcher;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.compose.ComposeFacade;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherComponentProvider;
import com.android.launcher3.dragndrop.SimpleDragLayer;
import com.android.launcher3.model.StringCache;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.model.WidgetPredictionsRequester;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.util.ScreenOnTracker;
import com.android.launcher3.widget.WidgetCell;
import com.android.launcher3.widget.model.WidgetsListBaseEntriesBuilder;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.picker.WidgetCategoryFilter;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import com.android.launcher3.widget.picker.model.WidgetPickerDataProvider;
import com.android.launcher3.widgetpicker.WidgetPickerConfig;
import com.android.systemui.animation.back.FlingOnBackAnimationCallback;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
/** An Activity that can host Launcher's widget picker. */
public class WidgetPickerActivity extends BaseActivity implements
/** An Activity that can host Launcher's widget picker for additional surfaces. */
public class QuickstepWidgetPickerActivity extends
com.android.launcher3.widgetpicker.WidgetPickerActivity implements
WidgetPredictionsRequester.WidgetPredictionsListener {
private static final String TAG = "WidgetPickerActivity";
/**
@@ -113,37 +112,22 @@ public class WidgetPickerActivity extends BaseActivity implements
private static final String LOCKSCREEN_WIDGETS_HUB_UI_SURFACE = "widgets_hub";
private static final Pattern UI_SURFACE_PATTERN =
Pattern.compile("^(widgets|widgets_hub)$");
/**
* User ids that should be filtered out of the widget lists created by this activity.
*/
private static final String EXTRA_USER_ID_FILTER = "filtered_user_ids";
private SimpleDragLayer<WidgetPickerActivity> mDragLayer;
private WidgetsModel mModel;
private StringCache mStringCache;
private WidgetPredictionsRequester mWidgetPredictionsRequester;
private WidgetPickerDataProvider mWidgetPickerDataProvider;
private int mDesiredWidgetWidth;
private int mDesiredWidgetHeight;
private WidgetCategoryFilter mWidgetCategoryInclusionFilter;
private WidgetCategoryFilter mWidgetCategoryExclusionFilter;
@Nullable
private String mUiSurface;
// Widgets existing on the host surface.
@NonNull
private List<AppWidgetProviderInfo> mAddedWidgets = new ArrayList<>();
@Nullable
private String mTitle;
@Nullable
private String mDescription;
/** A set of user ids that should be filtered out from the selected widgets. */
@NonNull
Set<Integer> mFilteredUserIds = new HashSet<>();
private final ScreenOnTracker.ScreenOnListener mScreenOnListener = this::onScreenOnChange;
@Nullable
private WidgetsFullSheet mWidgetSheet;
@@ -162,26 +146,24 @@ public class WidgetPickerActivity extends BaseActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
setWidgetPickerConfig(parseIntentExtras());
super.onCreate(savedInstanceState);
LauncherAppComponent component = LauncherComponentProvider.get(this);
component.getScreenOnTracker().addListener(mScreenOnListener);
InvariantDeviceProfile idp = component.getIDP();
mDeviceProfile = idp.getDeviceProfile(this);
mModel = new WidgetsModel(getApplicationContext());
mWidgetPickerDataProvider = new WidgetPickerDataProvider();
if (!Flags.enableWidgetPickerRefactor() || !ComposeFacade.INSTANCE.isComposeAvailable()) {
if (getWidgetPickerConfig().getUiSurface().equals(LOCKSCREEN_WIDGETS_HUB_UI_SURFACE)) {
WindowInsetsController wc = getDragLayer().getWindowInsetsController();
wc.hide(navigationBars() + statusBars());
}
setContentView(R.layout.widget_picker_activity);
mDragLayer = findViewById(R.id.drag_layer);
mDragLayer.recreateControllers();
LauncherAppComponent component = LauncherComponentProvider.get(this);
InvariantDeviceProfile idp = component.getIDP();
mDeviceProfile = idp.getDeviceProfile(this);
mModel = new WidgetsModel(getApplicationContext());
mWidgetPickerDataProvider = new WidgetPickerDataProvider();
parseIntentExtras();
if (Objects.equals(mUiSurface, LOCKSCREEN_WIDGETS_HUB_UI_SURFACE)) {
WindowInsetsController wc = mDragLayer.getWindowInsetsController();
wc.hide(navigationBars() + statusBars());
refreshAndBindWidgets();
}
refreshAndBindWidgets();
}
@Override
@@ -191,9 +173,10 @@ public class WidgetPickerActivity extends BaseActivity implements
new BackAnimationCallback());
}
private void parseIntentExtras() {
mTitle = getIntent().getStringExtra(EXTRA_PICKER_TITLE);
mDescription = getIntent().getStringExtra(EXTRA_PICKER_DESCRIPTION);
@NonNull
protected WidgetPickerConfig parseIntentExtras() {
String title = getIntent().getStringExtra(EXTRA_PICKER_TITLE);
String description = getIntent().getStringExtra(EXTRA_PICKER_DESCRIPTION);
// A value of 0 for either size means that no filtering will occur in that dimension. If
// both values are 0, then no size filtering will occur.
@@ -215,23 +198,33 @@ public class WidgetPickerActivity extends BaseActivity implements
if (exclusionFilter > 0) {
Log.w(TAG, "Invalid EXTRA_CATEGORY_EXCLUSION_FILTER: " + exclusionFilter);
}
mWidgetCategoryExclusionFilter = new WidgetCategoryFilter(min(0 , exclusionFilter));
mWidgetCategoryExclusionFilter = new WidgetCategoryFilter(min(0, exclusionFilter));
String uiSurfaceParam = getIntent().getStringExtra(EXTRA_UI_SURFACE);
String uiSurface = WidgetPickerConfig.HOMESCREEN_WIDGETS_UI_SURFACE;
if (uiSurfaceParam != null && UI_SURFACE_PATTERN.matcher(uiSurfaceParam).matches()) {
mUiSurface = uiSurfaceParam;
uiSurface = uiSurfaceParam;
}
ArrayList<AppWidgetProviderInfo> addedWidgets = getIntent().getParcelableArrayListExtra(
EXTRA_ADDED_APP_WIDGETS, AppWidgetProviderInfo.class);
if (addedWidgets != null) {
mAddedWidgets = addedWidgets;
}
ArrayList<Integer> filteredUsers = getIntent().getIntegerArrayListExtra(
List<UserHandle> filteredUsers = List.of();
ArrayList<Integer> filteredUserIds = getIntent().getIntegerArrayListExtra(
EXTRA_USER_ID_FILTER);
mFilteredUserIds.clear();
if (filteredUsers != null) {
mFilteredUserIds.addAll(filteredUsers);
if (filteredUserIds != null) {
filteredUsers = filteredUserIds.stream().map(UserHandle::of).toList();
}
return new WidgetPickerConfig(
/*uiSurface=*/ uiSurface,
/*title=*/ title,
/*description=*/ description,
/*categoryInclusionFilter=*/ inclusionFilter,
/*categoryExclusionFilter=*/ exclusionFilter,
/*filteredUsers=*/ filteredUsers);
}
@NonNull
@@ -240,11 +233,6 @@ public class WidgetPickerActivity extends BaseActivity implements
return mWidgetPickerDataProvider;
}
@Override
public SimpleDragLayer<WidgetPickerActivity> getDragLayer() {
return mDragLayer;
}
@Override
public View.OnClickListener getItemOnClickListener() {
return v -> {
@@ -313,6 +301,7 @@ public class WidgetPickerActivity extends BaseActivity implements
*/
private void refreshAndBindWidgets() {
MODEL_EXECUTOR.execute(() -> {
WidgetPickerConfig config = getWidgetPickerConfig();
mModel.update(null);
StringCache stringCache = new StringCache();
@@ -323,12 +312,11 @@ public class WidgetPickerActivity extends BaseActivity implements
// Open sheet once widgets are available, so that it doesn't interrupt the open
// animation.
openWidgetsSheet();
if (mUiSurface != null) {
mWidgetPredictionsRequester = new WidgetPredictionsRequester(
getApplicationContext(), mUiSurface,
mModel.getWidgetsByComponentKeyForPicker());
mWidgetPredictionsRequester.request(mAddedWidgets, this);
}
config.getUiSurface();
mWidgetPredictionsRequester = new WidgetPredictionsRequester(
getApplicationContext(), config.getUiSurface(),
mModel.getWidgetsByComponentKeyForPicker());
mWidgetPredictionsRequester.request(mAddedWidgets, this);
});
}
@@ -353,8 +341,10 @@ public class WidgetPickerActivity extends BaseActivity implements
private void openWidgetsSheet() {
MAIN_EXECUTOR.execute(() -> {
WidgetPickerConfig config = getWidgetPickerConfig();
mWidgetSheet = WidgetsFullSheet.show(this, true);
mWidgetSheet.mayUpdateTitleAndDescription(mTitle, mDescription);
mWidgetSheet.mayUpdateTitleAndDescription(config.getTitle(),
config.getDescription());
mWidgetSheet.disableNavBarScrim(true);
mWidgetSheet.addOnCloseListener(this::finish);
});
@@ -368,19 +358,14 @@ public class WidgetPickerActivity extends BaseActivity implements
mDeviceProfile.bottomSheetOpenDuration);
}
private void onScreenOnChange(boolean on) {
if (!on) {
finish(); // auto close when user locks device.
}
}
@Override
protected void onDestroy() {
super.onDestroy();
ScreenOnTracker.INSTANCE.get(this).removeListener(mScreenOnListener);
mWidgetPickerDataProvider.destroy();
if (mWidgetPredictionsRequester != null) {
mWidgetPredictionsRequester.clear();
if (!Flags.enableWidgetPickerRefactor() || !ComposeFacade.INSTANCE.isComposeAvailable()) {
mWidgetPickerDataProvider.destroy();
if (mWidgetPredictionsRequester != null) {
mWidgetPredictionsRequester.clear();
}
}
}
@@ -437,7 +422,8 @@ public class WidgetPickerActivity extends BaseActivity implements
private boolean hasHostSizeFilters() {
// If optional filters such as size filter are present, we display them as default widgets.
return mDesiredWidgetWidth != 0 || mDesiredWidgetHeight != 0;
return mDesiredWidgetWidth != 0 ||
mDesiredWidgetHeight != 0;
}
private WidgetAcceptabilityVerdict isWidgetAcceptable(WidgetItem widget,
@@ -447,7 +433,8 @@ public class WidgetPickerActivity extends BaseActivity implements
return rejectWidget(widget, "shortcut");
}
if (mFilteredUserIds.contains(widget.user.getIdentifier())) {
WidgetPickerConfig config = getWidgetPickerConfig();
if (config.getFilteredUsers().contains(widget.user)) {
return rejectWidget(
widget,
"widget user: %d is being filtered",
@@ -464,6 +451,7 @@ public class WidgetPickerActivity extends BaseActivity implements
info.widgetCategory);
}
if (applySizeFilter) {
if (mDesiredWidgetWidth == 0 && mDesiredWidgetHeight == 0) {
// Accept the widget if the desired dimensions are unspecified.
+9 -1
View File
@@ -30,7 +30,6 @@
</style>
<style name="WidgetPickerActivityTheme" parent="@android:style/Theme.DeviceDefault.DayNight">
<item name="widgetsTheme">@style/WidgetContainerTheme.Dark</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
@@ -38,6 +37,15 @@
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<!-- Edge to edge with transparent (not translucent nav / status bars) -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:enforceNavigationBarContrast">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:enforceStatusBarContrast">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="widgetsTheme">@style/WidgetContainerTheme.Dark</item>
<item name="pageIndicatorDotColor">@color/page_indicator_dot_color_dark</item>
</style>
+21
View File
@@ -545,4 +545,25 @@
variable-title-small
</item>
</style>
<style name="WidgetPickerActivityTheme" parent="@android:style/Theme.DeviceDefault.DayNight">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<!-- Edge to edge with transparent (not translucent nav / status bars) -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:enforceNavigationBarContrast">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:enforceStatusBarContrast">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="widgetsTheme">@style/WidgetContainerTheme</item>
<item name="pageIndicatorDotColor">@color/page_indicator_dot_color_light</item>
</style>
</resources>
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2025 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.widgetpicker
import android.os.Bundle
import com.android.launcher3.BaseActivity
import com.android.launcher3.Flags
import com.android.launcher3.R
import com.android.launcher3.compose.ComposeFacade.isComposeAvailable
import com.android.launcher3.dagger.LauncherComponentProvider
import com.android.launcher3.dragndrop.SimpleDragLayer
import com.android.launcher3.util.ScreenOnTracker
/**
* Activity that shows widget picker UI; shows content only if `enableWidgetPickerRefactor` flag is
* on and compose is available.
*/
open class WidgetPickerActivity : BaseActivity() {
private var _dragLayer: SimpleDragLayer<WidgetPickerActivity>? = null
protected var widgetPickerConfig: WidgetPickerConfig = WidgetPickerConfig()
private val screenOnListener =
ScreenOnTracker.ScreenOnListener { on: Boolean -> this.onScreenOnChange(on) }
override fun getDragLayer(): SimpleDragLayer<WidgetPickerActivity>? = _dragLayer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val component = LauncherComponentProvider.get(this)
component.screenOnTracker.addListener(screenOnListener)
mDeviceProfile = component.idp.getDeviceProfile(this)
setContentView(R.layout.widget_picker_activity)
_dragLayer = findViewById(R.id.drag_layer)
checkNotNull(_dragLayer).recreateControllers()
if (Flags.enableWidgetPickerRefactor() && isComposeAvailable()) {
// TODO(b/408283627): add compose picker here.
}
}
private fun onScreenOnChange(on: Boolean) {
if (!on) {
finish() // auto close when user locks device.
}
}
override fun onDestroy() {
super.onDestroy()
ScreenOnTracker.INSTANCE[this].removeListener(screenOnListener)
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2025 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.widgetpicker
import android.os.UserHandle
/**
* Possible parameters sent over by the widget host when launching the widget picker activity.
* @param uiSurface surface string representing the host. "widgets" for home screen
* @param title an optional title that some surfaces like lockscreen may provide to change the
* title appearing in widget picker.
* @param description an optional description that some surfaces like lockscreen may provide to
* display it below the title in widget picker; by default no description is
* shown.
* @param categoryInclusionFilter mask applied to identify if a widget's category matches the
* host's category requirements and if widget can be included.
* @param categoryExclusionFilter mask applied to identify if per host requirements the widget
* should be excluded from the picker.
* @param filteredUsers users for which widgets list should be shown empty (potentially due to
* admin / enterprise restrictions); no widgets message is shown instead.
*/
data class WidgetPickerConfig(
val uiSurface: String = HOMESCREEN_WIDGETS_UI_SURFACE,
val title: String? = null,
val description: String? = null,
val categoryInclusionFilter: Int = 0,
val categoryExclusionFilter: Int = 0,
val filteredUsers: List<UserHandle> = listOf()
) {
/**
* Indicates if the intent request is for picking home screen widgets.
* If false, implies its for another surface external to launcher.
*/
val isForHomeScreen: Boolean
get() = uiSurface == HOMESCREEN_WIDGETS_UI_SURFACE
companion object {
/**
* Name of the extra (set by widget picker) in the result when the activity is launched by
* lockscreen with `startActivityForResult`; indicates that activity finished since a widget
* was being dragged.
*/
const val EXTRA_IS_PENDING_WIDGET_DRAG = "is_pending_widget_drag"
const val HOMESCREEN_WIDGETS_UI_SURFACE = "widgets"
}
}