Widget Picker: Update the launcher integration to support shortcuts
Updates drag and drop, tap to add and preview related code. Bug: 370950552 Flag: com.android.launcher3.enable_widget_picker_refactor Test: Drag and drop shortcuts on home screen Change-Id: Iccfe329296dbf4b0770628e77df5cd9b42ac9b21
This commit is contained in:
1 parent
d885e21660
commit
077234aff5
7 files changed
+197
-148
No files matched your search
+96
-89
@@ -18,8 +18,8 @@ package com.android.launcher3.widgetpicker
|
||||
|
||||
import android.app.Activity.RESULT_OK
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import android.content.Intent
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -33,7 +33,6 @@ import com.android.launcher3.compose.core.widgetpicker.WidgetPickerComposeWrappe
|
||||
import com.android.launcher3.concurrent.annotations.BackgroundContext
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.util.ApiWrapper
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerConfig
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerConfig.Companion.EXTRA_IS_PENDING_WIDGET_DRAG
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository
|
||||
@@ -42,15 +41,16 @@ import com.android.launcher3.widgetpicker.listeners.WidgetPickerAddItemListener
|
||||
import com.android.launcher3.widgetpicker.listeners.WidgetPickerDragItemListener
|
||||
import com.android.launcher3.widgetpicker.shared.model.HostConstraint
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.isAppWidget
|
||||
import com.android.launcher3.widgetpicker.theme.darkWidgetPickerColors
|
||||
import com.android.launcher3.widgetpicker.theme.lightWidgetPickerColors
|
||||
import com.android.launcher3.widgetpicker.ui.WidgetInteractionInfo
|
||||
import com.android.launcher3.widgetpicker.ui.WidgetPickerEventListeners
|
||||
import com.android.launcher3.widgetpicker.ui.theme.WidgetPickerTheme
|
||||
import com.android.launcher3.widgetpicker.theme.darkWidgetPickerColors
|
||||
import com.android.launcher3.widgetpicker.theme.lightWidgetPickerColors
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* An helper that bootstraps widget picker UI (from [WidgetPickerComponent]) in to
|
||||
@@ -58,21 +58,21 @@ import kotlin.coroutines.CoroutineContext
|
||||
*
|
||||
* Sets up the bindings necessary for widget picker component.
|
||||
*/
|
||||
class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
class WidgetPickerComposeWrapperImpl
|
||||
@Inject
|
||||
constructor(
|
||||
private val widgetPickerComponentProvider: Provider<WidgetPickerComponent.Factory>,
|
||||
private val widgetsRepository: WidgetsRepository,
|
||||
private val widgetUsersRepository: WidgetUsersRepository,
|
||||
private val widgetAppIconsRepository: WidgetAppIconsRepository,
|
||||
@BackgroundContext
|
||||
private val backgroundContext: CoroutineContext,
|
||||
@ApplicationContext
|
||||
private val appContext: Context,
|
||||
@BackgroundContext private val backgroundContext: CoroutineContext,
|
||||
@ApplicationContext private val appContext: Context,
|
||||
private val apiWrapper: ApiWrapper,
|
||||
) : WidgetPickerComposeWrapper {
|
||||
|
||||
override fun showAllWidgets(
|
||||
activity: WidgetPickerActivity,
|
||||
widgetPickerConfig: WidgetPickerConfig
|
||||
widgetPickerConfig: WidgetPickerConfig,
|
||||
) {
|
||||
val widgetPickerComponent = newWidgetPickerComponent(widgetPickerConfig)
|
||||
val callbacks = activity.buildEventListeners(widgetPickerConfig, apiWrapper)
|
||||
@@ -85,11 +85,12 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
val scope = rememberCoroutineScope()
|
||||
val view = LocalView.current
|
||||
|
||||
val widgetPickerColors = if (isSystemInDarkTheme()) {
|
||||
darkWidgetPickerColors()
|
||||
} else {
|
||||
lightWidgetPickerColors()
|
||||
}
|
||||
val widgetPickerColors =
|
||||
if (isSystemInDarkTheme()) {
|
||||
darkWidgetPickerColors()
|
||||
} else {
|
||||
lightWidgetPickerColors()
|
||||
}
|
||||
|
||||
MaterialTheme { // TODO(b/408283627): Use launcher theme.
|
||||
WidgetPickerTheme(colors = widgetPickerColors) {
|
||||
@@ -99,13 +100,9 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
}
|
||||
|
||||
DisposableEffect(view) {
|
||||
scope.launch {
|
||||
initializeRepositories()
|
||||
}
|
||||
scope.launch { initializeRepositories() }
|
||||
|
||||
onDispose {
|
||||
cleanUpRepositories()
|
||||
}
|
||||
onDispose { cleanUpRepositories() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,19 +113,22 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
private fun newWidgetPickerComponent(
|
||||
widgetPickerConfig: WidgetPickerConfig
|
||||
): WidgetPickerComponent {
|
||||
return widgetPickerComponentProvider.get()
|
||||
return widgetPickerComponentProvider
|
||||
.get()
|
||||
.build(
|
||||
widgetsRepository = widgetsRepository,
|
||||
widgetUsersRepository = widgetUsersRepository,
|
||||
widgetAppIconsRepository = widgetAppIconsRepository,
|
||||
widgetHostInfo = WidgetHostInfo(
|
||||
title = widgetPickerConfig.title
|
||||
?: appContext.resources.getString(R.string.widget_button_text),
|
||||
description = widgetPickerConfig.description,
|
||||
constraints = widgetPickerConfig.asHostConstraints(),
|
||||
showDragShadow = !widgetPickerConfig.isForHomeScreen
|
||||
),
|
||||
backgroundContext = backgroundContext
|
||||
widgetHostInfo =
|
||||
WidgetHostInfo(
|
||||
title =
|
||||
widgetPickerConfig.title
|
||||
?: appContext.resources.getString(R.string.widget_button_text),
|
||||
description = widgetPickerConfig.description,
|
||||
constraints = widgetPickerConfig.asHostConstraints(),
|
||||
showDragShadow = !widgetPickerConfig.isForHomeScreen,
|
||||
),
|
||||
backgroundContext = backgroundContext,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -150,20 +150,21 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
|
||||
private fun WidgetPickerActivity.buildEventListeners(
|
||||
widgetPickerConfig: WidgetPickerConfig,
|
||||
apiWrapper: ApiWrapper
|
||||
) = object : WidgetPickerEventListeners {
|
||||
override fun onClose() {
|
||||
finish()
|
||||
}
|
||||
apiWrapper: ApiWrapper,
|
||||
) =
|
||||
object : WidgetPickerEventListeners {
|
||||
override fun onClose() {
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onWidgetInteraction(widgetInteractionInfo: WidgetInteractionInfo) {
|
||||
if (widgetPickerConfig.isForHomeScreen) {
|
||||
handleWidgetInteractionForHomeScreen(widgetInteractionInfo, apiWrapper)
|
||||
} else {
|
||||
handleWidgetInteractionForExternalHost(widgetInteractionInfo)
|
||||
override fun onWidgetInteraction(widgetInteractionInfo: WidgetInteractionInfo) {
|
||||
if (widgetPickerConfig.isForHomeScreen) {
|
||||
handleWidgetInteractionForHomeScreen(widgetInteractionInfo, apiWrapper)
|
||||
} else {
|
||||
handleWidgetInteractionForExternalHost(widgetInteractionInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles communication with the home screen about the "add" and "drag" interactions on
|
||||
@@ -171,37 +172,38 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
*
|
||||
* For home screen, we register a listener that is called back when home screen is shown;
|
||||
* - WidgetPickerDragItemListener: bootstraps the drag helper that displays the shadow and
|
||||
* handles the drag until completion.
|
||||
* handles the drag until completion.
|
||||
* - WidgetPickerAddItemListener: once launcher is shown, triggers the flow to add the
|
||||
* widget to workspace.
|
||||
* widget to workspace.
|
||||
*/
|
||||
private fun WidgetPickerActivity.handleWidgetInteractionForHomeScreen(
|
||||
interactionInfo: WidgetInteractionInfo,
|
||||
apiWrapper: ApiWrapper
|
||||
apiWrapper: ApiWrapper,
|
||||
) {
|
||||
val interactionListener = when (interactionInfo) {
|
||||
is WidgetInteractionInfo.WidgetDragInfo ->
|
||||
WidgetPickerDragItemListener(
|
||||
mimeType = interactionInfo.mimeType,
|
||||
appWidgetProviderInfo = interactionInfo.providerInfo,
|
||||
widgetPreview = interactionInfo.previewInfo,
|
||||
previewRect = interactionInfo.bounds,
|
||||
previewWidth = interactionInfo.widthPx
|
||||
)
|
||||
val interactionListener =
|
||||
when (interactionInfo) {
|
||||
is WidgetInteractionInfo.WidgetDragInfo ->
|
||||
WidgetPickerDragItemListener(
|
||||
mimeType = interactionInfo.mimeType,
|
||||
widgetInfo = interactionInfo.widgetInfo,
|
||||
widgetPreview = interactionInfo.previewInfo,
|
||||
previewRect = interactionInfo.bounds,
|
||||
previewWidth = interactionInfo.widthPx,
|
||||
)
|
||||
|
||||
is WidgetInteractionInfo.WidgetAddInfo ->
|
||||
WidgetPickerAddItemListener(interactionInfo.providerInfo)
|
||||
}
|
||||
is WidgetInteractionInfo.WidgetAddInfo ->
|
||||
WidgetPickerAddItemListener(interactionInfo.widgetInfo)
|
||||
}
|
||||
Launcher.ACTIVITY_TRACKER.registerCallback(
|
||||
interactionListener,
|
||||
HOME_SCREEN_WIDGET_INTERACTION_REASON_STRING
|
||||
HOME_SCREEN_WIDGET_INTERACTION_REASON_STRING,
|
||||
)
|
||||
startActivity(
|
||||
/*intent=*/ Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_HOME)
|
||||
.setPackage(packageName)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
/*options=*/ apiWrapper.createFadeOutAnimOptions().toBundle()
|
||||
/*options=*/ apiWrapper.createFadeOutAnimOptions().toBundle(),
|
||||
)
|
||||
finish()
|
||||
}
|
||||
@@ -209,30 +211,35 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
/**
|
||||
* Handles communication with the external host about the "add" and "drag" interactions on
|
||||
* widgets within widget picker.
|
||||
*
|
||||
* - In case of drag and drop, finishes the activity with result indicating that there is a
|
||||
* pending drag [EXTRA_IS_PENDING_WIDGET_DRAG] (that would contain the widget info as part
|
||||
* of clip data) that the host should be handling.
|
||||
* pending drag [EXTRA_IS_PENDING_WIDGET_DRAG] (that would contain the widget info as part
|
||||
* of clip data) that the host should be handling.
|
||||
* - In case of add, finishes the activity with result containing extra information about
|
||||
* the widget being added (namely [Intent.EXTRA_COMPONENT_NAME] and [Intent.EXTRA_USER].
|
||||
* the widget being added (namely [Intent.EXTRA_COMPONENT_NAME] and [Intent.EXTRA_USER].
|
||||
*/
|
||||
private fun WidgetPickerActivity.handleWidgetInteractionForExternalHost(
|
||||
widgetInteractionInfo: WidgetInteractionInfo,
|
||||
widgetInteractionInfo: WidgetInteractionInfo
|
||||
) {
|
||||
when (widgetInteractionInfo) {
|
||||
is WidgetInteractionInfo.WidgetDragInfo ->
|
||||
setResult(
|
||||
RESULT_OK,
|
||||
Intent().putExtra(EXTRA_IS_PENDING_WIDGET_DRAG, true)
|
||||
)
|
||||
setResult(RESULT_OK, Intent().putExtra(EXTRA_IS_PENDING_WIDGET_DRAG, true))
|
||||
|
||||
is WidgetInteractionInfo.WidgetAddInfo -> {
|
||||
val providerInfo = widgetInteractionInfo.providerInfo
|
||||
setResult(
|
||||
RESULT_OK, Intent()
|
||||
.putExtra(Intent.EXTRA_COMPONENT_NAME, providerInfo.provider)
|
||||
.putExtra(Intent.EXTRA_USER, providerInfo.profile)
|
||||
)
|
||||
val widgetInfo = widgetInteractionInfo.widgetInfo
|
||||
if (widgetInfo.isAppWidget()) {
|
||||
val providerInfo = widgetInfo.appWidgetProviderInfo
|
||||
setResult(
|
||||
RESULT_OK,
|
||||
Intent().apply {
|
||||
putExtra(Intent.EXTRA_COMPONENT_NAME, providerInfo.provider)
|
||||
putExtra(Intent.EXTRA_USER, providerInfo.profile)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
throw IllegalStateException(
|
||||
"AppWidgetInfo not provided for external host drag"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,21 +247,21 @@ class WidgetPickerComposeWrapperImpl @Inject constructor(
|
||||
}
|
||||
|
||||
/** Builds the host constraints to provide to the widget picker module. */
|
||||
fun WidgetPickerConfig.asHostConstraints() =
|
||||
buildList {
|
||||
if (filteredUsers.isNotEmpty()) {
|
||||
add(HostConstraint.HostUserConstraint(filteredUsers))
|
||||
}
|
||||
if (categoryInclusionFilter != 0
|
||||
|| categoryExclusionFilter != 0
|
||||
) {
|
||||
add(
|
||||
HostConstraint.HostCategoryConstraint(
|
||||
categoryInclusionMask = categoryInclusionFilter,
|
||||
categoryExclusionMask = categoryExclusionFilter,
|
||||
)
|
||||
)
|
||||
}
|
||||
fun WidgetPickerConfig.asHostConstraints() = buildList {
|
||||
if (filteredUsers.isNotEmpty()) {
|
||||
add(HostConstraint.HostUserConstraint(filteredUsers))
|
||||
}
|
||||
if (!isForHomeScreen) {
|
||||
add(HostConstraint.NoShortcutsConstraint)
|
||||
}
|
||||
if (categoryInclusionFilter != 0 || categoryExclusionFilter != 0) {
|
||||
add(
|
||||
HostConstraint.HostCategoryConstraint(
|
||||
categoryInclusionMask = categoryInclusionFilter,
|
||||
categoryExclusionMask = categoryExclusionFilter,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-10
@@ -16,14 +16,17 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker.listeners
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.view.View
|
||||
import com.android.launcher3.Launcher
|
||||
import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY
|
||||
import com.android.launcher3.PendingAddItemInfo
|
||||
import com.android.launcher3.logging.StatsLogManager.LauncherEvent
|
||||
import com.android.launcher3.pm.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO
|
||||
import com.android.launcher3.util.ContextTracker.SchedulerCallback
|
||||
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo
|
||||
import com.android.launcher3.widget.PendingAddShortcutInfo
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetInfo
|
||||
|
||||
/**
|
||||
* A callback listener (for tap-to-add flow) that handles adding a widget from a separate widget
|
||||
@@ -31,26 +34,38 @@ import com.android.launcher3.widget.PendingAddWidgetInfo
|
||||
*
|
||||
* Also logs to stats logger once widget is added.
|
||||
*/
|
||||
class WidgetPickerAddItemListener(private val providerInfo: AppWidgetProviderInfo) :
|
||||
class WidgetPickerAddItemListener(private val widgetInfo: WidgetInfo) :
|
||||
SchedulerCallback<Launcher> {
|
||||
override fun init(launcher: Launcher?, isHomeStarted: Boolean): Boolean {
|
||||
checkNotNull(launcher)
|
||||
|
||||
val launcherProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(launcher, providerInfo)
|
||||
val pendingAddWidgetInfo =
|
||||
PendingAddWidgetInfo(launcherProviderInfo, CONTAINER_WIDGETS_TRAY)
|
||||
val pendingAddItemInfo: PendingAddItemInfo =
|
||||
when (widgetInfo) {
|
||||
is WidgetInfo.AppWidgetInfo -> {
|
||||
val launcherProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(
|
||||
launcher,
|
||||
widgetInfo.appWidgetProviderInfo,
|
||||
)
|
||||
PendingAddWidgetInfo(launcherProviderInfo, CONTAINER_WIDGETS_TRAY)
|
||||
}
|
||||
|
||||
is WidgetInfo.ShortcutInfo ->
|
||||
PendingAddShortcutInfo(
|
||||
ShortcutConfigActivityInfoVO(widgetInfo.launcherActivityInfo)
|
||||
)
|
||||
}
|
||||
|
||||
val view = View(launcher)
|
||||
view.tag = pendingAddWidgetInfo
|
||||
view.tag = pendingAddItemInfo
|
||||
|
||||
launcher.accessibilityDelegate?.addToWorkspace(
|
||||
/*item=*/ pendingAddWidgetInfo,
|
||||
/*accessibility=*/ false
|
||||
/*item=*/ pendingAddItemInfo,
|
||||
/*accessibility=*/ false,
|
||||
) {
|
||||
launcher.statsLogManager
|
||||
.logger()
|
||||
.withItemInfo(pendingAddWidgetInfo)
|
||||
.withItemInfo(pendingAddItemInfo)
|
||||
.log(LauncherEvent.LAUNCHER_WIDGET_ADD_BUTTON_TAP)
|
||||
}
|
||||
return false // don't receive any more callbacks as we got launcher and handled it
|
||||
|
||||
+61
-33
@@ -16,72 +16,100 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker.listeners
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY
|
||||
import com.android.launcher3.PendingAddItemInfo
|
||||
import com.android.launcher3.dragndrop.BaseItemDragListener
|
||||
import com.android.launcher3.pm.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO
|
||||
import com.android.launcher3.widget.DatabaseWidgetPreviewLoader.WidgetPreviewInfo
|
||||
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo
|
||||
import com.android.launcher3.widget.PendingAddShortcutInfo
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo
|
||||
import com.android.launcher3.widget.PendingItemDragHelper
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
import com.android.launcher3.widgetpicker.shared.model.isAppWidget
|
||||
|
||||
/**
|
||||
* A callback listener of type [BaseItemDragListener] that handles widget drag and drop from widget
|
||||
* picker hosted in a separate activity than home screen.
|
||||
*
|
||||
* Responsible for initializing the [PendingItemDragHelper] that then handles the rest of the
|
||||
* drag and drop (including showing a drag shadow for the widget).
|
||||
* Responsible for initializing the [PendingItemDragHelper] that then handles the rest of the drag
|
||||
* and drop (including showing a drag shadow for the widget).
|
||||
*
|
||||
* @param mimeType a mime type used by widget picker when attaching this listener for a specific
|
||||
* widget's drag and drop session.
|
||||
* @param appWidgetProviderInfo provider info of the widget being dragged
|
||||
* widget's drag and drop session.
|
||||
* @param widgetInfo metadata of the widget being dragged
|
||||
* @param widgetPreview provides the preview information for widgets
|
||||
* @param previewRect the bounds of widget's preview offset by the point of long press
|
||||
* @param previewWidth width of the preview as it appears in the widget picker.
|
||||
*/
|
||||
class WidgetPickerDragItemListener(
|
||||
private val mimeType: String,
|
||||
private val appWidgetProviderInfo: AppWidgetProviderInfo,
|
||||
private val widgetInfo: WidgetInfo,
|
||||
private val widgetPreview: WidgetPreview,
|
||||
previewRect: Rect,
|
||||
previewWidth: Int
|
||||
previewWidth: Int,
|
||||
) : BaseItemDragListener(previewRect, previewWidth, previewWidth) {
|
||||
override fun getMimeType(): String = mimeType
|
||||
|
||||
override fun createDragHelper(): PendingItemDragHelper {
|
||||
val launcherProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mLauncher, appWidgetProviderInfo)
|
||||
val pendingAddWidgetInfo =
|
||||
PendingAddWidgetInfo(launcherProviderInfo, CONTAINER_WIDGETS_TRAY)
|
||||
val pendingAddItemInfo: PendingAddItemInfo =
|
||||
when (widgetInfo) {
|
||||
is WidgetInfo.AppWidgetInfo -> {
|
||||
val launcherProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(
|
||||
mLauncher,
|
||||
widgetInfo.appWidgetProviderInfo,
|
||||
)
|
||||
PendingAddWidgetInfo(launcherProviderInfo, CONTAINER_WIDGETS_TRAY)
|
||||
}
|
||||
|
||||
is WidgetInfo.ShortcutInfo ->
|
||||
PendingAddShortcutInfo(
|
||||
ShortcutConfigActivityInfoVO(widgetInfo.launcherActivityInfo)
|
||||
)
|
||||
}
|
||||
|
||||
val view = View(mLauncher)
|
||||
view.tag = pendingAddWidgetInfo
|
||||
view.tag = pendingAddItemInfo
|
||||
|
||||
val dragHelper = PendingItemDragHelper(view)
|
||||
|
||||
val info = WidgetPreviewInfo()
|
||||
when (widgetPreview) {
|
||||
is WidgetPreview.BitmapWidgetPreview -> {
|
||||
info.previewBitmap = widgetPreview.bitmap
|
||||
info.providerInfo = appWidgetProviderInfo
|
||||
}
|
||||
|
||||
is WidgetPreview.ProviderInfoWidgetPreview -> {
|
||||
info.providerInfo = widgetPreview.providerInfo
|
||||
}
|
||||
|
||||
is WidgetPreview.RemoteViewsWidgetPreview -> {
|
||||
info.remoteViews = widgetPreview.remoteViews
|
||||
info.providerInfo = appWidgetProviderInfo
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException(
|
||||
"Unsupported preview type when dropping widget to launcher"
|
||||
)
|
||||
}
|
||||
dragHelper.setWidgetPreviewInfo(info)
|
||||
if (widgetInfo.isAppWidget()) {
|
||||
setAppWidgetPreviewInfo(widgetPreview, widgetInfo, dragHelper)
|
||||
} // shortcut preview is fetched by home screen.
|
||||
|
||||
return dragHelper
|
||||
}
|
||||
|
||||
private fun setAppWidgetPreviewInfo(
|
||||
appWidgetPreview: WidgetPreview,
|
||||
widgetInfo: WidgetInfo.AppWidgetInfo,
|
||||
dragHelper: PendingItemDragHelper,
|
||||
) {
|
||||
val info = WidgetPreviewInfo()
|
||||
when (appWidgetPreview) {
|
||||
is WidgetPreview.BitmapWidgetPreview -> {
|
||||
info.previewBitmap = appWidgetPreview.bitmap
|
||||
info.providerInfo = widgetInfo.appWidgetProviderInfo
|
||||
}
|
||||
|
||||
is WidgetPreview.ProviderInfoWidgetPreview -> {
|
||||
info.providerInfo = appWidgetPreview.providerInfo
|
||||
}
|
||||
|
||||
is WidgetPreview.RemoteViewsWidgetPreview -> {
|
||||
info.remoteViews = appWidgetPreview.remoteViews
|
||||
info.providerInfo = widgetInfo.appWidgetProviderInfo
|
||||
}
|
||||
|
||||
else ->
|
||||
throw IllegalStateException(
|
||||
"Unsupported preview type when dropping widget to launcher"
|
||||
)
|
||||
}
|
||||
dragHelper.setWidgetPreviewInfo(info)
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import com.android.launcher3.util.ui.PortraitLandscapeRunner.PortraitLandscape
|
||||
import com.android.launcher3.util.ui.TestViewHelpers
|
||||
import com.android.launcher3.util.workspace.FavoriteItemsTransaction
|
||||
import com.android.launcher3.widgetpicker.listeners.WidgetPickerAddItemListener
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetInfo
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@@ -83,10 +84,10 @@ class AddWidgetConfigTest : BaseLauncherActivityTest<Launcher>() {
|
||||
|
||||
// Add widget to home screen
|
||||
val monitor = WidgetConfigStartupMonitor()
|
||||
launcherActivity.executeOnLauncher({ l: Launcher ->
|
||||
val addItemListener = WidgetPickerAddItemListener(widgetInfo)
|
||||
launcherActivity.executeOnLauncher { l: Launcher ->
|
||||
val addItemListener = WidgetPickerAddItemListener(WidgetInfo.AppWidgetInfo(widgetInfo))
|
||||
addItemListener.init(l, /* isHomeStarted= */ true)
|
||||
})
|
||||
}
|
||||
|
||||
uiDevice.waitForIdle()
|
||||
|
||||
|
||||
+7
-9
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker.ui
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.graphics.Rect
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
|
||||
/**
|
||||
* General interface that clients can implement to listen to events from different types of
|
||||
* widget picker.
|
||||
* General interface that clients can implement to listen to events from different types of widget
|
||||
* picker.
|
||||
*/
|
||||
interface WidgetPickerEventListeners {
|
||||
/** Called when the widget picker is dismissed. */
|
||||
@@ -37,7 +37,7 @@ sealed class WidgetInteractionInfo {
|
||||
/**
|
||||
* Information passed in event listener when a widget is dragged.
|
||||
*
|
||||
* @param providerInfo metadata for the provider of the widget being dragged.
|
||||
* @param widgetInfo metadata for the provider of the widget being dragged.
|
||||
* @param bounds current bounds of the widget's preview considering the drag offset and scale.
|
||||
* @param widthPx measured width of the preview.
|
||||
* @param heightPx measured height of the preview.
|
||||
@@ -45,7 +45,7 @@ sealed class WidgetInteractionInfo {
|
||||
* @param mimeType a unique mime type set on clip data for the drag session
|
||||
*/
|
||||
data class WidgetDragInfo(
|
||||
val providerInfo: AppWidgetProviderInfo,
|
||||
val widgetInfo: WidgetInfo,
|
||||
val bounds: Rect,
|
||||
val widthPx: Int,
|
||||
val heightPx: Int,
|
||||
@@ -56,9 +56,7 @@ sealed class WidgetInteractionInfo {
|
||||
/**
|
||||
* Information passed in event listener when a widget is added using tap to add.
|
||||
*
|
||||
* @param providerInfo metadata for the provider of the widget being added.
|
||||
* @param widgetInfo metadata for the provider of the widget being added.
|
||||
*/
|
||||
data class WidgetAddInfo(
|
||||
val providerInfo: AppWidgetProviderInfo
|
||||
) : WidgetInteractionInfo()
|
||||
data class WidgetAddInfo(val widgetInfo: WidgetInfo) : WidgetInteractionInfo()
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||
|
||||
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
|
||||
import static com.android.launcher3.icons.FastBitmapDrawable.getDisabledColorFilter;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
@@ -635,7 +636,8 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
// When widgets are dropped from another window, we don't want to remove the
|
||||
// dragView on resume of launcher.
|
||||
if (Flags.enableWidgetPickerRefactor()
|
||||
&& ((DragView<?>) child).mItemType != ITEM_TYPE_APPWIDGET) {
|
||||
&& ((DragView<?>) child).mItemType != ITEM_TYPE_APPWIDGET
|
||||
&& ((DragView<?>) child).mItemType != ITEM_TYPE_DEEP_SHORTCUT) {
|
||||
dragLayer.removeView(child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ import com.android.launcher3.pm.ShortcutConfigActivityInfo;
|
||||
import com.android.launcher3.util.CancellableTask;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.LooperExecutor;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.widget.util.WidgetSizes;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -272,8 +271,7 @@ public class DatabaseWidgetPreviewLoader {
|
||||
|
||||
private Bitmap generateShortcutPreview(
|
||||
ShortcutConfigActivityInfo info, int maxWidth, int maxHeight) {
|
||||
int iconSize = ActivityContext.lookupContext(
|
||||
mContext).getDeviceProfile().getAllAppsProfile().getIconSizePx();
|
||||
int iconSize = mDeviceProfile.getAllAppsProfile().getIconSizePx();
|
||||
int padding = mContext.getResources()
|
||||
.getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
|
||||
|
||||
|
||||
Reference in new issue
Block a user