summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-06-25 17:24:53 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-25 17:24:55 +0000
commitb49dbeef5253c346a172b7516c4526fa79dadd77 (patch)
treef4a2fbabefa13d0d81b3e11de65f5aa4497adea4 /packages
parentefb49bd81101046ced1f75aeef81dcda27580514 (diff)
parentaf3bb6936786a8c14ac01da3d81d196d17b68b96 (diff)
downloadframeworks_base-b49dbeef5253c346a172b7516c4526fa79dadd77.zip
frameworks_base-b49dbeef5253c346a172b7516c4526fa79dadd77.tar.gz
frameworks_base-b49dbeef5253c346a172b7516c4526fa79dadd77.tar.bz2
Merge "Refactoring recents search bar widget logic." into mnc-dev
Diffstat (limited to 'packages')
-rw-r--r--packages/SystemUI/src/com/android/systemui/Prefs.java9
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/Recents.java66
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java92
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java25
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java9
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java22
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java89
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java23
8 files changed, 136 insertions, 199 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/Prefs.java b/packages/SystemUI/src/com/android/systemui/Prefs.java
index 29d2a01..3657cf2 100644
--- a/packages/SystemUI/src/com/android/systemui/Prefs.java
+++ b/packages/SystemUI/src/com/android/systemui/Prefs.java
@@ -44,6 +44,7 @@ public final class Prefs {
})
public @interface Key {
String SEARCH_APP_WIDGET_ID = "searchAppWidgetId";
+ String SEARCH_APP_WIDGET_PACKAGE = "searchAppWidgetPackage";
String DEBUG_MODE_ENABLED = "debugModeEnabled";
String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed";
@@ -80,6 +81,14 @@ public final class Prefs {
get(context).edit().putLong(key, value).apply();
}
+ public static String getString(Context context, @Key String key, String defaultValue) {
+ return get(context).getString(key, defaultValue);
+ }
+
+ public static void putString(Context context, @Key String key, String value) {
+ get(context).edit().putString(key, value).apply();
+ }
+
public static Map<String, ?> getAll(Context context) {
return get(context).getAll();
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
index 89c456c..6a45369 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
@@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ITaskStackListener;
-import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
@@ -37,11 +36,10 @@ import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.MutableBoolean;
-import android.util.Pair;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
-
+import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.RecentsComponent;
import com.android.systemui.SystemUI;
@@ -170,6 +168,7 @@ public class Recents extends SystemUI
Handler mHandler;
TaskStackListenerImpl mTaskStackListener;
RecentsOwnerEventProxyReceiver mProxyBroadcastReceiver;
+ RecentsAppWidgetHost mAppWidgetHost;
boolean mBootCompleted;
boolean mStartAnimationTriggered;
boolean mCanReuseTaskStackViews = true;
@@ -235,6 +234,7 @@ public class Recents extends SystemUI
mSystemServicesProxy = new SystemServicesProxy(mContext);
mHandler = new Handler();
mTaskStackBounds = new Rect();
+ mAppWidgetHost = new RecentsAppWidgetHost(mContext, Constants.Values.App.AppWidgetHostId);
// Register the task stack listener
mTaskStackListener = new TaskStackListenerImpl(mHandler);
@@ -255,7 +255,7 @@ public class Recents extends SystemUI
// Initialize some static datastructures
TaskStackViewLayoutAlgorithm.initializeCurve();
// Load the header bar layout
- reloadHeaderBarLayout(true);
+ reloadHeaderBarLayout();
// When we start, preload the data associated with the previous recent tasks.
// We can use a new plan since the caches will be the same.
@@ -488,11 +488,11 @@ public class Recents extends SystemUI
// Don't reuse task stack views if the configuration changes
mCanReuseTaskStackViews = false;
// Reload the header bar layout
- reloadHeaderBarLayout(false);
+ reloadHeaderBarLayout();
}
/** Prepares the header bar layout. */
- void reloadHeaderBarLayout(boolean reloadWidget) {
+ void reloadHeaderBarLayout() {
Resources res = mContext.getResources();
mWindowRect = mSystemServicesProxy.getWindowRect();
mStatusBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
@@ -500,12 +500,16 @@ public class Recents extends SystemUI
mNavBarWidth = res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
mConfig = RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy);
mConfig.updateOnConfigurationChange();
- if (reloadWidget) {
- // Reload the widget id before we get the task stack bounds
- reloadSearchBarAppWidget(mContext, mSystemServicesProxy);
+ Rect searchBarBounds = new Rect();
+ // Try and pre-emptively bind the search widget on startup to ensure that we
+ // have the right thumbnail bounds to animate to.
+ // Note: We have to reload the widget id before we get the task stack bounds below
+ if (mSystemServicesProxy.getOrBindSearchAppWidget(mContext, mAppWidgetHost) != null) {
+ mConfig.getSearchBarBounds(mWindowRect.width(), mWindowRect.height(),
+ mStatusBarHeight, searchBarBounds);
}
mConfig.getAvailableTaskStackBounds(mWindowRect.width(), mWindowRect.height(),
- mStatusBarHeight, (mConfig.hasTransposedNavBar ? mNavBarWidth : 0),
+ mStatusBarHeight, (mConfig.hasTransposedNavBar ? mNavBarWidth : 0), searchBarBounds,
mTaskStackBounds);
if (mConfig.isLandscape && mConfig.hasTransposedNavBar) {
mSystemInsets.set(0, mStatusBarHeight, mNavBarWidth, 0);
@@ -532,24 +536,6 @@ public class Recents extends SystemUI
}
}
- /** Prepares the search bar app widget */
- void reloadSearchBarAppWidget(Context context, SystemServicesProxy ssp) {
- // Try and pre-emptively bind the search widget on startup to ensure that we
- // have the right thumbnail bounds to animate to.
- if (Constants.DebugFlags.App.EnableSearchLayout) {
- // If there is no id, then bind a new search app widget
- if (mConfig.searchBarAppWidgetId < 0) {
- AppWidgetHost host = new RecentsAppWidgetHost(context,
- Constants.Values.App.AppWidgetHostId);
- Pair<Integer, AppWidgetProviderInfo> widgetInfo = ssp.bindSearchAppWidget(host);
- if (widgetInfo != null) {
- // Save the app widget id into the settings
- mConfig.updateSearchBarAppWidgetId(context, widgetInfo.first);
- }
- }
- }
- }
-
/** Toggles the recents activity */
void toggleRecentsActivity() {
// If the user has toggled it too quickly, then just eat up the event here (it's better than
@@ -799,27 +785,13 @@ public class Recents extends SystemUI
// If there is no thumbnail transition, but is launching from home into recents, then
// use a quick home transition and do the animation from home
if (hasRecentTasks) {
- // Get the home activity info
String homeActivityPackage = mSystemServicesProxy.getHomeActivityPackageName();
- // Get the search widget info
- AppWidgetProviderInfo searchWidget = null;
- String searchWidgetPackage = null;
- if (mConfig.hasSearchBarAppWidget()) {
- searchWidget = mSystemServicesProxy.getAppWidgetInfo(
- mConfig.searchBarAppWidgetId);
- } else {
- searchWidget = mSystemServicesProxy.resolveSearchAppWidget();
- }
- if (searchWidget != null && searchWidget.provider != null) {
- searchWidgetPackage = searchWidget.provider.getPackageName();
- }
- // Determine whether we are coming from a search owned home activity
- boolean fromSearchHome = false;
- if (homeActivityPackage != null && searchWidgetPackage != null &&
- homeActivityPackage.equals(searchWidgetPackage)) {
- fromSearchHome = true;
- }
+ String searchWidgetPackage =
+ Prefs.getString(mContext, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE, null);
+ // Determine whether we are coming from a search owned home activity
+ boolean fromSearchHome = (homeActivityPackage != null) &&
+ homeActivityPackage.equals(searchWidgetPackage);
ActivityOptions opts = getHomeTransitionActivityOptions(fromSearchHome);
startAlternateRecentsActivity(topTask, opts, true /* fromHome */, fromSearchHome,
false /* fromThumbnail */, stackVr);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index da7247c..bf15c68 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -28,7 +28,6 @@ import android.content.IntentFilter;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.UserHandle;
-import android.util.Pair;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewStub;
@@ -50,7 +49,6 @@ import com.android.systemui.recents.views.SystemBarScrimViews;
import com.android.systemui.recents.views.ViewAnimation;
import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
/**
@@ -75,9 +73,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
RecentsResizeTaskDialog mResizeTaskDebugDialog;
// Search AppWidget
- AppWidgetProviderInfo mSearchAppWidgetInfo;
+ AppWidgetProviderInfo mSearchWidgetInfo;
RecentsAppWidgetHost mAppWidgetHost;
- RecentsAppWidgetHostView mSearchAppWidgetHostView;
+ RecentsAppWidgetHostView mSearchWidgetHostView;
// Runnables to finish the Recents activity
FinishRecentsRunnable mFinishLaunchHomeRunnable;
@@ -168,8 +166,10 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
// When the screen turns off, dismiss Recents to Home
dismissRecentsToHome(false);
} else if (action.equals(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED)) {
- // When the search activity changes, update the Search widget
- refreshSearchWidget();
+ // When the search activity changes, update the search widget view
+ SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
+ mSearchWidgetInfo = ssp.getOrBindSearchAppWidget(context, mAppWidgetHost);
+ refreshSearchWidgetView();
}
}
};
@@ -253,7 +253,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
if (mRecentsView.hasValidSearchBar()) {
mRecentsView.setSearchBarVisibility(View.VISIBLE);
} else {
- addSearchBarAppWidgetView();
+ refreshSearchWidgetView();
}
}
@@ -261,60 +261,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
mScrimViews.prepareEnterRecentsAnimation();
}
- /** Attempts to allocate and bind the search bar app widget */
- void bindSearchBarAppWidget() {
- if (Constants.DebugFlags.App.EnableSearchLayout) {
- SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
-
- // Reset the host view and widget info
- mSearchAppWidgetHostView = null;
- mSearchAppWidgetInfo = null;
-
- // Try and load the app widget id from the settings
- int appWidgetId = mConfig.searchBarAppWidgetId;
- if (appWidgetId >= 0) {
- mSearchAppWidgetInfo = ssp.getAppWidgetInfo(appWidgetId);
- if (mSearchAppWidgetInfo == null) {
- // If there is no actual widget associated with that id, then delete it and
- // prepare to bind another app widget in its place
- ssp.unbindSearchAppWidget(mAppWidgetHost, appWidgetId);
- appWidgetId = -1;
- }
- }
-
- // If there is no id, then bind a new search app widget
- if (appWidgetId < 0) {
- Pair<Integer, AppWidgetProviderInfo> widgetInfo =
- ssp.bindSearchAppWidget(mAppWidgetHost);
- if (widgetInfo != null) {
- // Save the app widget id into the settings
- mConfig.updateSearchBarAppWidgetId(this, widgetInfo.first);
- mSearchAppWidgetInfo = widgetInfo.second;
- }
- }
- }
- }
-
- /** Creates the search bar app widget view */
- void addSearchBarAppWidgetView() {
- if (Constants.DebugFlags.App.EnableSearchLayout) {
- int appWidgetId = mConfig.searchBarAppWidgetId;
- if (appWidgetId >= 0) {
- mSearchAppWidgetHostView = (RecentsAppWidgetHostView) mAppWidgetHost.createView(
- this, appWidgetId, mSearchAppWidgetInfo);
- Bundle opts = new Bundle();
- opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
- AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
- mSearchAppWidgetHostView.updateAppWidgetOptions(opts);
- // Set the padding to 0 for this search widget
- mSearchAppWidgetHostView.setPadding(0, 0, 0, 0);
- mRecentsView.setSearchBar(mSearchAppWidgetHostView);
- } else {
- mRecentsView.setSearchBar(null);
- }
- }
- }
-
/** Dismisses recents if we are already visible and the intent is to toggle the recents view */
boolean dismissRecentsToFocusedTaskOrHome(boolean checkFilteredStackState) {
SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
@@ -393,7 +339,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
inflateDebugOverlay();
// Bind the search app widget when we first start up
- bindSearchBarAppWidget();
+ mSearchWidgetInfo = ssp.getOrBindSearchAppWidget(this, mAppWidgetHost);
// Register the broadcast receiver to handle messages when the screen is turned off
IntentFilter filter = new IntentFilter();
@@ -498,7 +444,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null);
ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);
mRecentsView.startEnterRecentsAnimation(ctx);
- if (mConfig.searchBarAppWidgetId >= 0) {
+
+ if (mSearchWidgetInfo != null) {
final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> cbRef =
new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>(
RecentsActivity.this);
@@ -654,9 +601,22 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
/**** RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks Implementation ****/
@Override
- public void refreshSearchWidget() {
- bindSearchBarAppWidget();
- addSearchBarAppWidgetView();
+ public void refreshSearchWidgetView() {
+ if (mSearchWidgetInfo != null) {
+ SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
+ int searchWidgetId = ssp.getSearchAppWidgetId(this);
+ mSearchWidgetHostView = (RecentsAppWidgetHostView) mAppWidgetHost.createView(
+ this, searchWidgetId, mSearchWidgetInfo);
+ Bundle opts = new Bundle();
+ opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
+ AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
+ mSearchWidgetHostView.updateAppWidgetOptions(opts);
+ // Set the padding to 0 for this search widget
+ mSearchWidgetHostView.setPadding(0, 0, 0, 0);
+ mRecentsView.setSearchBar(mSearchWidgetHostView);
+ } else {
+ mRecentsView.setSearchBar(null);
+ }
}
/**** DebugOverlayView.DebugOverlayViewCallbacks ****/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java
index d4e50f8..0102332 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java
@@ -20,26 +20,20 @@ import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
-import com.android.systemui.recents.misc.SystemServicesProxy;
-import com.android.systemui.recents.model.RecentsTaskLoader;
/** Our special app widget host for the Search widget */
public class RecentsAppWidgetHost extends AppWidgetHost {
/* Callbacks to notify when an app package changes */
interface RecentsAppWidgetHostCallbacks {
- public void refreshSearchWidget();
+ void refreshSearchWidgetView();
}
- Context mContext;
RecentsAppWidgetHostCallbacks mCb;
- RecentsConfiguration mConfig;
boolean mIsListening;
public RecentsAppWidgetHost(Context context, int hostId) {
super(context, hostId);
- mContext = context;
- mConfig = RecentsConfiguration.getInstance();
}
public void startListening(RecentsAppWidgetHostCallbacks cb) {
@@ -57,7 +51,6 @@ public class RecentsAppWidgetHost extends AppWidgetHost {
}
// Ensure that we release any references to the callbacks
mCb = null;
- mContext = null;
mIsListening = false;
}
@@ -67,18 +60,14 @@ public class RecentsAppWidgetHost extends AppWidgetHost {
return new RecentsAppWidgetHostView(context);
}
+ /**
+ * Note: this is only called for packages that have updated, not removed.
+ */
@Override
protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) {
- if (mCb == null) return;
- if (mContext == null) return;
-
- SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
- if (appWidgetId > -1 && appWidgetId == mConfig.searchBarAppWidgetId) {
- // The search provider may have changed, so just delete the old widget and bind it again
- ssp.unbindSearchAppWidget(this, appWidgetId);
- // Update the search widget
- mConfig.updateSearchBarAppWidgetId(mContext, -1);
- mCb.refreshSearchWidget();
+ super.onProviderChanged(appWidgetId, appWidgetInfo);
+ if (mIsListening && mCb != null) {
+ mCb.refreshSearchWidgetView();
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java
index 1ed755a..672d602 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java
@@ -18,6 +18,7 @@ package com.android.systemui.recents;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
+import android.view.View;
import android.widget.RemoteViews;
public class RecentsAppWidgetHostView extends AppWidgetHostView {
@@ -37,6 +38,14 @@ public class RecentsAppWidgetHostView extends AppWidgetHostView {
super.updateAppWidget(remoteViews);
}
+ @Override
+ protected View getErrorView() {
+ // Just return an empty view as the error view when failing to inflate the Recents search
+ // bar widget (this is mainly to catch the case where we try and inflate the widget view
+ // while the search provider is updating)
+ return new View(mContext);
+ }
+
/**
* Updates the last orientation that this widget was inflated.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
index 244fada..dfe7e96 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
@@ -73,7 +73,6 @@ public class RecentsConfiguration {
public int maxNumTasksToLoad;
/** Search bar */
- int searchBarAppWidgetId = -1;
public int searchBarSpaceHeightPx;
/** Task stack */
@@ -207,8 +206,6 @@ public class RecentsConfiguration {
// Search Bar
searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
- searchBarAppWidgetId = Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID,
- -1 /* defaultValue */);
// Task stack
taskStackScrollDuration =
@@ -279,12 +276,6 @@ public class RecentsConfiguration {
systemInsets.set(insets);
}
- /** Updates the search bar app widget */
- public void updateSearchBarAppWidgetId(Context context, int appWidgetId) {
- searchBarAppWidgetId = appWidgetId;
- Prefs.putInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, appWidgetId);
- }
-
/** Updates the states that need to be re-read whenever we re-initialize. */
void updateOnReinitialize(Context context, SystemServicesProxy ssp) {
// Check if the developer options are enabled
@@ -304,11 +295,6 @@ public class RecentsConfiguration {
launchedHasConfigurationChanged = true;
}
- /** Returns whether the search bar app widget exists. */
- public boolean hasSearchBarAppWidget() {
- return searchBarAppWidgetId >= 0;
- }
-
/** Returns whether the status bar scrim should be animated when shown for the first time. */
public boolean shouldAnimateStatusBarScrim() {
return launchedFromHome;
@@ -335,9 +321,7 @@ public class RecentsConfiguration {
* the system insets.
*/
public void getAvailableTaskStackBounds(int windowWidth, int windowHeight, int topInset,
- int rightInset, Rect taskStackBounds) {
- Rect searchBarBounds = new Rect();
- getSearchBarBounds(windowWidth, windowHeight, topInset, searchBarBounds);
+ int rightInset, Rect searchBarBounds, Rect taskStackBounds) {
if (isLandscape && hasTransposedSearchBar) {
// In landscape, the search bar appears on the left, but we overlay it on top
taskStackBounds.set(0, topInset, windowWidth - rightInset, windowHeight);
@@ -355,10 +339,6 @@ public class RecentsConfiguration {
Rect searchBarSpaceBounds) {
// Return empty rects if search is not enabled
int searchBarSize = searchBarSpaceHeightPx;
- if (!Constants.DebugFlags.App.EnableSearchLayout || !hasSearchBarAppWidget()) {
- searchBarSize = 0;
- }
-
if (isLandscape && hasTransposedSearchBar) {
// In landscape, the search bar appears on the left
searchBarSpaceBounds.set(0, topInset, searchBarSize, windowHeight);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index 272d39a..b60c66f 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -62,9 +62,11 @@ import android.view.DisplayInfo;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
+import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.recents.Constants;
import com.android.systemui.recents.Recents;
+import com.android.systemui.recents.RecentsAppWidgetHost;
import java.io.IOException;
import java.util.ArrayList;
@@ -527,14 +529,57 @@ public class SystemServicesProxy {
}
/**
- * Resolves and returns the first Recents widget from the same package as the global
- * assist activity.
+ * Returns the current search widget id.
*/
- public AppWidgetProviderInfo resolveSearchAppWidget() {
- if (mAwm == null) return null;
- if (mAssistComponent == null) return null;
+ public int getSearchAppWidgetId(Context context) {
+ return Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, -1);
+ }
+
+ /**
+ * Returns the current search widget info, binding a new one if necessary.
+ */
+ public AppWidgetProviderInfo getOrBindSearchAppWidget(Context context, AppWidgetHost host) {
+ int searchWidgetId = Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, -1);
+ AppWidgetProviderInfo searchWidgetInfo = mAwm.getAppWidgetInfo(searchWidgetId);
+ AppWidgetProviderInfo resolvedSearchWidgetInfo = resolveSearchAppWidget();
+
+ // Return the search widget info if it hasn't changed
+ if (searchWidgetInfo != null && resolvedSearchWidgetInfo != null &&
+ searchWidgetInfo.provider.equals(resolvedSearchWidgetInfo.provider)) {
+ if (Prefs.getString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE, null) == null) {
+ Prefs.putString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE,
+ searchWidgetInfo.provider.getPackageName());
+ }
+ return searchWidgetInfo;
+ }
+
+ // Delete the old widget
+ if (searchWidgetId != -1) {
+ host.deleteAppWidgetId(searchWidgetId);
+ }
+
+ // And rebind a new search widget
+ if (resolvedSearchWidgetInfo != null) {
+ Pair<Integer, AppWidgetProviderInfo> widgetInfo = bindSearchAppWidget(host,
+ resolvedSearchWidgetInfo);
+ if (widgetInfo != null) {
+ Prefs.putInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, widgetInfo.first);
+ Prefs.putString(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE,
+ widgetInfo.second.provider.getPackageName());
+ return widgetInfo.second;
+ }
+ }
+
+ // If we fall through here, then there is no resolved search widget, so clear the state
+ Prefs.remove(context, Prefs.Key.SEARCH_APP_WIDGET_ID);
+ Prefs.remove(context, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE);
+ return null;
+ }
- // Find the first Recents widget from the same package as the global assist activity
+ /**
+ * Returns the first Recents widget from the same package as the global assist activity.
+ */
+ private AppWidgetProviderInfo resolveSearchAppWidget() {
List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders(
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
for (AppWidgetProviderInfo info : widgets) {
@@ -548,45 +593,21 @@ public class SystemServicesProxy {
/**
* Resolves and binds the search app widget that is to appear in the recents.
*/
- public Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host) {
+ private Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host,
+ AppWidgetProviderInfo resolvedSearchWidgetInfo) {
if (mAwm == null) return null;
if (mAssistComponent == null) return null;
- // Find the first Recents widget from the same package as the global assist activity
- AppWidgetProviderInfo searchWidgetInfo = resolveSearchAppWidget();
-
- // Return early if there is no search widget
- if (searchWidgetInfo == null) return null;
-
// Allocate a new widget id and try and bind the app widget (if that fails, then just skip)
int searchWidgetId = host.allocateAppWidgetId();
Bundle opts = new Bundle();
opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
- if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, searchWidgetInfo.provider, opts)) {
+ if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, resolvedSearchWidgetInfo.provider, opts)) {
host.deleteAppWidgetId(searchWidgetId);
return null;
}
- return new Pair<Integer, AppWidgetProviderInfo>(searchWidgetId, searchWidgetInfo);
- }
-
- /**
- * Returns the app widget info for the specified app widget id.
- */
- public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
- if (mAwm == null) return null;
-
- return mAwm.getAppWidgetInfo(appWidgetId);
- }
-
- /**
- * Destroys the specified app widget.
- */
- public void unbindSearchAppWidget(AppWidgetHost host, int appWidgetId) {
- if (mAwm == null) return;
-
- // Delete the app widget
- host.deleteAppWidgetId(appWidgetId);
+ return new Pair<>(searchWidgetId, resolvedSearchWidgetInfo);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index fa97a86..6cb11b1 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -287,17 +287,14 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
/** Adds the search bar */
public void setSearchBar(RecentsAppWidgetHostView searchBar) {
- // Create the search bar (and hide it if we have no recent tasks)
- if (Constants.DebugFlags.App.EnableSearchLayout) {
- // Remove the previous search bar if one exists
- if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
- removeView(mSearchBar);
- }
- // Add the new search bar
- if (searchBar != null) {
- mSearchBar = searchBar;
- addView(mSearchBar);
- }
+ // Remove the previous search bar if one exists
+ if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
+ removeView(mSearchBar);
+ }
+ // Add the new search bar
+ if (searchBar != null) {
+ mSearchBar = searchBar;
+ addView(mSearchBar);
}
}
@@ -324,8 +321,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
int height = MeasureSpec.getSize(heightMeasureSpec);
// Get the search bar bounds and measure the search bar layout
+ Rect searchBarSpaceBounds = new Rect();
if (mSearchBar != null) {
- Rect searchBarSpaceBounds = new Rect();
mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds);
mSearchBar.measure(
MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
@@ -334,7 +331,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
Rect taskStackBounds = new Rect();
mConfig.getAvailableTaskStackBounds(width, height, mConfig.systemInsets.top,
- mConfig.systemInsets.right, taskStackBounds);
+ mConfig.systemInsets.right, searchBarSpaceBounds, taskStackBounds);
// Measure each TaskStackView with the full width and height of the window since the
// transition view is a child of that stack view