Loading core/java/android/appwidget/AppWidgetHostView.java +38 −23 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * Pass the given handler to RemoteViews when updating this widget. Unless this * is done immediatly after construction, a call to {@link #updateAppWidget(RemoteViews)} * should be made. * @param handler * * @hide */ public void setInteractionHandler(InteractionHandler handler) { Loading Loading @@ -354,7 +354,6 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * the framework will be accounted for automatically. This information gets embedded into the * AppWidget options and causes a callback to the AppWidgetProvider. In addition, the list of * sizes is explicitly set to an empty list. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param newOptions The bundle of options, in addition to the size information, * can be null. Loading @@ -362,6 +361,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * @param minHeight The maximum height in dips that the widget will be displayed at. * @param maxWidth The maximum width in dips that the widget will be displayed at. * @param maxHeight The maximum height in dips that the widget will be displayed at. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * @deprecated use {@link AppWidgetHostView#updateAppWidgetSize(Bundle, List)} instead. */ @Deprecated Loading @@ -378,12 +378,14 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * This method will update the option bundle with the list of sizes and the min/max bounds for * width and height. * * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param newOptions The bundle of options, in addition to the size information. * @param sizes Sizes, in dips, the widget may be displayed at without calling the provider * again. Typically, this will be size of the widget in landscape and portrait. * On some foldables, this might include the size on the outer and inner screens. * @param sizes Sizes, in dips, the widget may be displayed at without calling the * provider * again. Typically, this will be size of the widget in landscape and * portrait. * On some foldables, this might include the size on the outer and inner * screens. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) */ public void updateAppWidgetSize(@NonNull Bundle newOptions, @NonNull List<SizeF> sizes) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(mContext); Loading Loading @@ -470,9 +472,9 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Specify some extra information for the widget provider. Causes a callback to the * AppWidgetProvider. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param options The bundle of options information. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) */ public void updateAppWidgetOptions(Bundle options) { AppWidgetManager.getInstance(mContext).updateAppWidgetOptions(mAppWidgetId, options); Loading Loading @@ -507,6 +509,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Sets whether the widget is being displayed on a light/white background and use an * alternate UI if available. * * @see RemoteViews#setLightBackgroundLayoutId(int) */ public void setOnLightBackground(boolean onLightBackground) { Loading Loading @@ -745,6 +748,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Build a {@link Context} cloned into another package name, usually for the * purposes of reading remote resources. * * @hide */ protected Context getRemoteContextEnsuringCorrectCachedApkPath() { Loading Loading @@ -839,7 +843,18 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW return defaultView; } private void onDefaultViewClicked(View view) { /** * Handles interactions on the default view of the widget. By default does not use the * {@link InteractionHandler} used by other interactions. However, this can be overridden * in order to customize the click behavior. * * @hide */ protected void onDefaultViewClicked(@NonNull View view) { final AppWidgetManager manager = AppWidgetManager.getInstance(mContext); if (manager != null) { manager.noteAppWidgetTapped(mAppWidgetId); } if (mInfo != null) { LauncherApps launcherApps = getContext().getSystemService(LauncherApps.class); List<LauncherActivityInfo> activities = launcherApps.getActivityList( Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/WidgetInteractionHandlerTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ class WidgetInteractionHandlerTest : SysuiTestCase() { assertFalse(launching!!) val parent = FrameLayout(context) val view = CommunalAppWidgetHostView(context) val view = CommunalAppWidgetHostView(context, underTest) parent.addView(view) val (fillInIntent, activityOptions) = testResponse.getLaunchOptions(view) Loading packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHost.kt +2 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ class CommunalAppWidgetHost( context: Context, private val backgroundScope: CoroutineScope, hostId: Int, interactionHandler: RemoteViews.InteractionHandler, private val interactionHandler: RemoteViews.InteractionHandler, looper: Looper, logBuffer: LogBuffer, ) : AppWidgetHost(context, hostId, interactionHandler, looper) { Loading @@ -55,7 +55,7 @@ class CommunalAppWidgetHost( appWidgetId: Int, appWidget: AppWidgetProviderInfo? ): AppWidgetHostView { return CommunalAppWidgetHostView(context) return CommunalAppWidgetHostView(context, interactionHandler) } /** Loading packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt +31 −1 Original line number Diff line number Diff line Loading @@ -17,17 +17,25 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetHostView import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProviderInfo import android.content.Context import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherApps import android.graphics.Outline import android.graphics.Rect import android.view.View import android.view.ViewOutlineProvider import android.widget.RemoteViews import android.widget.RemoteViews.RemoteResponse import com.android.systemui.animation.LaunchableView import com.android.systemui.animation.LaunchableViewDelegate /** AppWidgetHostView that displays in communal hub with support for rounded corners. */ class CommunalAppWidgetHostView(context: Context) : AppWidgetHostView(context), LaunchableView { class CommunalAppWidgetHostView( context: Context, private val interactionHandler: RemoteViews.InteractionHandler, ) : AppWidgetHostView(context, interactionHandler), LaunchableView { private val launchableViewDelegate = LaunchableViewDelegate( this, Loading Loading @@ -92,4 +100,26 @@ class CommunalAppWidgetHostView(context: Context) : AppWidgetHostView(context), launchableViewDelegate.setShouldBlockVisibilityChanges(block) override fun setVisibility(visibility: Int) = launchableViewDelegate.setVisibility(visibility) override fun onDefaultViewClicked(view: View) { AppWidgetManager.getInstance(context)?.noteAppWidgetTapped(appWidgetId) if (appWidgetInfo == null) { return } val launcherApps = context.getSystemService(LauncherApps::class.java) val activityInfo: LauncherActivityInfo = launcherApps .getActivityList(appWidgetInfo.provider.packageName, appWidgetInfo.profile) ?.getOrNull(0) ?: return val intent = launcherApps.getMainActivityLaunchIntent( activityInfo.componentName, null, activityInfo.user ) if (intent != null) { interactionHandler.onInteraction(view, intent, RemoteResponse.fromPendingIntent(intent)) } } } Loading
core/java/android/appwidget/AppWidgetHostView.java +38 −23 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * Pass the given handler to RemoteViews when updating this widget. Unless this * is done immediatly after construction, a call to {@link #updateAppWidget(RemoteViews)} * should be made. * @param handler * * @hide */ public void setInteractionHandler(InteractionHandler handler) { Loading Loading @@ -354,7 +354,6 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * the framework will be accounted for automatically. This information gets embedded into the * AppWidget options and causes a callback to the AppWidgetProvider. In addition, the list of * sizes is explicitly set to an empty list. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param newOptions The bundle of options, in addition to the size information, * can be null. Loading @@ -362,6 +361,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * @param minHeight The maximum height in dips that the widget will be displayed at. * @param maxWidth The maximum width in dips that the widget will be displayed at. * @param maxHeight The maximum height in dips that the widget will be displayed at. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * @deprecated use {@link AppWidgetHostView#updateAppWidgetSize(Bundle, List)} instead. */ @Deprecated Loading @@ -378,12 +378,14 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW * This method will update the option bundle with the list of sizes and the min/max bounds for * width and height. * * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param newOptions The bundle of options, in addition to the size information. * @param sizes Sizes, in dips, the widget may be displayed at without calling the provider * again. Typically, this will be size of the widget in landscape and portrait. * On some foldables, this might include the size on the outer and inner screens. * @param sizes Sizes, in dips, the widget may be displayed at without calling the * provider * again. Typically, this will be size of the widget in landscape and * portrait. * On some foldables, this might include the size on the outer and inner * screens. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) */ public void updateAppWidgetSize(@NonNull Bundle newOptions, @NonNull List<SizeF> sizes) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(mContext); Loading Loading @@ -470,9 +472,9 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Specify some extra information for the widget provider. Causes a callback to the * AppWidgetProvider. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) * * @param options The bundle of options information. * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle) */ public void updateAppWidgetOptions(Bundle options) { AppWidgetManager.getInstance(mContext).updateAppWidgetOptions(mAppWidgetId, options); Loading Loading @@ -507,6 +509,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Sets whether the widget is being displayed on a light/white background and use an * alternate UI if available. * * @see RemoteViews#setLightBackgroundLayoutId(int) */ public void setOnLightBackground(boolean onLightBackground) { Loading Loading @@ -745,6 +748,7 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW /** * Build a {@link Context} cloned into another package name, usually for the * purposes of reading remote resources. * * @hide */ protected Context getRemoteContextEnsuringCorrectCachedApkPath() { Loading Loading @@ -839,7 +843,18 @@ public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppW return defaultView; } private void onDefaultViewClicked(View view) { /** * Handles interactions on the default view of the widget. By default does not use the * {@link InteractionHandler} used by other interactions. However, this can be overridden * in order to customize the click behavior. * * @hide */ protected void onDefaultViewClicked(@NonNull View view) { final AppWidgetManager manager = AppWidgetManager.getInstance(mContext); if (manager != null) { manager.noteAppWidgetTapped(mAppWidgetId); } if (mInfo != null) { LauncherApps launcherApps = getContext().getSystemService(LauncherApps.class); List<LauncherActivityInfo> activities = launcherApps.getActivityList( Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/WidgetInteractionHandlerTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ class WidgetInteractionHandlerTest : SysuiTestCase() { assertFalse(launching!!) val parent = FrameLayout(context) val view = CommunalAppWidgetHostView(context) val view = CommunalAppWidgetHostView(context, underTest) parent.addView(view) val (fillInIntent, activityOptions) = testResponse.getLaunchOptions(view) Loading
packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHost.kt +2 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ class CommunalAppWidgetHost( context: Context, private val backgroundScope: CoroutineScope, hostId: Int, interactionHandler: RemoteViews.InteractionHandler, private val interactionHandler: RemoteViews.InteractionHandler, looper: Looper, logBuffer: LogBuffer, ) : AppWidgetHost(context, hostId, interactionHandler, looper) { Loading @@ -55,7 +55,7 @@ class CommunalAppWidgetHost( appWidgetId: Int, appWidget: AppWidgetProviderInfo? ): AppWidgetHostView { return CommunalAppWidgetHostView(context) return CommunalAppWidgetHostView(context, interactionHandler) } /** Loading
packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt +31 −1 Original line number Diff line number Diff line Loading @@ -17,17 +17,25 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetHostView import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProviderInfo import android.content.Context import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherApps import android.graphics.Outline import android.graphics.Rect import android.view.View import android.view.ViewOutlineProvider import android.widget.RemoteViews import android.widget.RemoteViews.RemoteResponse import com.android.systemui.animation.LaunchableView import com.android.systemui.animation.LaunchableViewDelegate /** AppWidgetHostView that displays in communal hub with support for rounded corners. */ class CommunalAppWidgetHostView(context: Context) : AppWidgetHostView(context), LaunchableView { class CommunalAppWidgetHostView( context: Context, private val interactionHandler: RemoteViews.InteractionHandler, ) : AppWidgetHostView(context, interactionHandler), LaunchableView { private val launchableViewDelegate = LaunchableViewDelegate( this, Loading Loading @@ -92,4 +100,26 @@ class CommunalAppWidgetHostView(context: Context) : AppWidgetHostView(context), launchableViewDelegate.setShouldBlockVisibilityChanges(block) override fun setVisibility(visibility: Int) = launchableViewDelegate.setVisibility(visibility) override fun onDefaultViewClicked(view: View) { AppWidgetManager.getInstance(context)?.noteAppWidgetTapped(appWidgetId) if (appWidgetInfo == null) { return } val launcherApps = context.getSystemService(LauncherApps::class.java) val activityInfo: LauncherActivityInfo = launcherApps .getActivityList(appWidgetInfo.provider.packageName, appWidgetInfo.profile) ?.getOrNull(0) ?: return val intent = launcherApps.getMainActivityLaunchIntent( activityInfo.componentName, null, activityInfo.user ) if (intent != null) { interactionHandler.onInteraction(view, intent, RemoteResponse.fromPendingIntent(intent)) } } }