am b49dbeef: Merge "Refactoring recents search bar widget logic." into mnc-dev

* commit 'b49dbeef5253c346a172b7516c4526fa79dadd77':
  Refactoring recents search bar widget logic.
This commit is contained in:
Winson Chung
2015-06-25 17:35:06 +00:00
committed by Android Git Automerger
8 changed files with 136 additions and 199 deletions

View File

@@ -44,6 +44,7 @@ public final class Prefs {
}) })
public @interface Key { public @interface Key {
String SEARCH_APP_WIDGET_ID = "searchAppWidgetId"; String SEARCH_APP_WIDGET_ID = "searchAppWidgetId";
String SEARCH_APP_WIDGET_PACKAGE = "searchAppWidgetPackage";
String DEBUG_MODE_ENABLED = "debugModeEnabled"; String DEBUG_MODE_ENABLED = "debugModeEnabled";
String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed"; String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed"; String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed";
@@ -80,6 +81,14 @@ public final class Prefs {
get(context).edit().putLong(key, value).apply(); 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) { public static Map<String, ?> getAll(Context context) {
return get(context).getAll(); return get(context).getAll();
} }

View File

@@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.ITaskStackListener; import android.app.ITaskStackListener;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetProviderInfo; import android.appwidget.AppWidgetProviderInfo;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -37,11 +36,10 @@ import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.MutableBoolean; import android.util.MutableBoolean;
import android.util.Pair;
import android.view.Display; import android.view.Display;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import com.android.systemui.Prefs;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.RecentsComponent; import com.android.systemui.RecentsComponent;
import com.android.systemui.SystemUI; import com.android.systemui.SystemUI;
@@ -170,6 +168,7 @@ public class Recents extends SystemUI
Handler mHandler; Handler mHandler;
TaskStackListenerImpl mTaskStackListener; TaskStackListenerImpl mTaskStackListener;
RecentsOwnerEventProxyReceiver mProxyBroadcastReceiver; RecentsOwnerEventProxyReceiver mProxyBroadcastReceiver;
RecentsAppWidgetHost mAppWidgetHost;
boolean mBootCompleted; boolean mBootCompleted;
boolean mStartAnimationTriggered; boolean mStartAnimationTriggered;
boolean mCanReuseTaskStackViews = true; boolean mCanReuseTaskStackViews = true;
@@ -235,6 +234,7 @@ public class Recents extends SystemUI
mSystemServicesProxy = new SystemServicesProxy(mContext); mSystemServicesProxy = new SystemServicesProxy(mContext);
mHandler = new Handler(); mHandler = new Handler();
mTaskStackBounds = new Rect(); mTaskStackBounds = new Rect();
mAppWidgetHost = new RecentsAppWidgetHost(mContext, Constants.Values.App.AppWidgetHostId);
// Register the task stack listener // Register the task stack listener
mTaskStackListener = new TaskStackListenerImpl(mHandler); mTaskStackListener = new TaskStackListenerImpl(mHandler);
@@ -255,7 +255,7 @@ public class Recents extends SystemUI
// Initialize some static datastructures // Initialize some static datastructures
TaskStackViewLayoutAlgorithm.initializeCurve(); TaskStackViewLayoutAlgorithm.initializeCurve();
// Load the header bar layout // Load the header bar layout
reloadHeaderBarLayout(true); reloadHeaderBarLayout();
// When we start, preload the data associated with the previous recent tasks. // 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. // 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 // Don't reuse task stack views if the configuration changes
mCanReuseTaskStackViews = false; mCanReuseTaskStackViews = false;
// Reload the header bar layout // Reload the header bar layout
reloadHeaderBarLayout(false); reloadHeaderBarLayout();
} }
/** Prepares the header bar layout. */ /** Prepares the header bar layout. */
void reloadHeaderBarLayout(boolean reloadWidget) { void reloadHeaderBarLayout() {
Resources res = mContext.getResources(); Resources res = mContext.getResources();
mWindowRect = mSystemServicesProxy.getWindowRect(); mWindowRect = mSystemServicesProxy.getWindowRect();
mStatusBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 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); mNavBarWidth = res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
mConfig = RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy); mConfig = RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy);
mConfig.updateOnConfigurationChange(); mConfig.updateOnConfigurationChange();
if (reloadWidget) { Rect searchBarBounds = new Rect();
// Reload the widget id before we get the task stack bounds // Try and pre-emptively bind the search widget on startup to ensure that we
reloadSearchBarAppWidget(mContext, mSystemServicesProxy); // 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(), mConfig.getAvailableTaskStackBounds(mWindowRect.width(), mWindowRect.height(),
mStatusBarHeight, (mConfig.hasTransposedNavBar ? mNavBarWidth : 0), mStatusBarHeight, (mConfig.hasTransposedNavBar ? mNavBarWidth : 0), searchBarBounds,
mTaskStackBounds); mTaskStackBounds);
if (mConfig.isLandscape && mConfig.hasTransposedNavBar) { if (mConfig.isLandscape && mConfig.hasTransposedNavBar) {
mSystemInsets.set(0, mStatusBarHeight, mNavBarWidth, 0); 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 */ /** Toggles the recents activity */
void toggleRecentsActivity() { void toggleRecentsActivity() {
// If the user has toggled it too quickly, then just eat up the event here (it's better than // 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 // 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 // use a quick home transition and do the animation from home
if (hasRecentTasks) { if (hasRecentTasks) {
// Get the home activity info
String homeActivityPackage = mSystemServicesProxy.getHomeActivityPackageName(); String homeActivityPackage = mSystemServicesProxy.getHomeActivityPackageName();
// Get the search widget info String searchWidgetPackage =
AppWidgetProviderInfo searchWidget = null; Prefs.getString(mContext, Prefs.Key.SEARCH_APP_WIDGET_PACKAGE, 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;
}
// Determine whether we are coming from a search owned home activity
boolean fromSearchHome = (homeActivityPackage != null) &&
homeActivityPackage.equals(searchWidgetPackage);
ActivityOptions opts = getHomeTransitionActivityOptions(fromSearchHome); ActivityOptions opts = getHomeTransitionActivityOptions(fromSearchHome);
startAlternateRecentsActivity(topTask, opts, true /* fromHome */, fromSearchHome, startAlternateRecentsActivity(topTask, opts, true /* fromHome */, fromSearchHome,
false /* fromThumbnail */, stackVr); false /* fromThumbnail */, stackVr);

View File

@@ -28,7 +28,6 @@ import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Pair;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewStub; import android.view.ViewStub;
@@ -50,7 +49,6 @@ import com.android.systemui.recents.views.SystemBarScrimViews;
import com.android.systemui.recents.views.ViewAnimation; import com.android.systemui.recents.views.ViewAnimation;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@@ -75,9 +73,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
RecentsResizeTaskDialog mResizeTaskDebugDialog; RecentsResizeTaskDialog mResizeTaskDebugDialog;
// Search AppWidget // Search AppWidget
AppWidgetProviderInfo mSearchAppWidgetInfo; AppWidgetProviderInfo mSearchWidgetInfo;
RecentsAppWidgetHost mAppWidgetHost; RecentsAppWidgetHost mAppWidgetHost;
RecentsAppWidgetHostView mSearchAppWidgetHostView; RecentsAppWidgetHostView mSearchWidgetHostView;
// Runnables to finish the Recents activity // Runnables to finish the Recents activity
FinishRecentsRunnable mFinishLaunchHomeRunnable; FinishRecentsRunnable mFinishLaunchHomeRunnable;
@@ -168,8 +166,10 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
// When the screen turns off, dismiss Recents to Home // When the screen turns off, dismiss Recents to Home
dismissRecentsToHome(false); dismissRecentsToHome(false);
} else if (action.equals(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED)) { } else if (action.equals(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED)) {
// When the search activity changes, update the Search widget // When the search activity changes, update the search widget view
refreshSearchWidget(); 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()) { if (mRecentsView.hasValidSearchBar()) {
mRecentsView.setSearchBarVisibility(View.VISIBLE); mRecentsView.setSearchBarVisibility(View.VISIBLE);
} else { } else {
addSearchBarAppWidgetView(); refreshSearchWidgetView();
} }
} }
@@ -261,60 +261,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
mScrimViews.prepareEnterRecentsAnimation(); 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 */ /** Dismisses recents if we are already visible and the intent is to toggle the recents view */
boolean dismissRecentsToFocusedTaskOrHome(boolean checkFilteredStackState) { boolean dismissRecentsToFocusedTaskOrHome(boolean checkFilteredStackState) {
SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy(); SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
@@ -393,7 +339,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
inflateDebugOverlay(); inflateDebugOverlay();
// Bind the search app widget when we first start up // 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 // Register the broadcast receiver to handle messages when the screen is turned off
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
@@ -498,7 +444,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null); ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null);
ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t); ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);
mRecentsView.startEnterRecentsAnimation(ctx); mRecentsView.startEnterRecentsAnimation(ctx);
if (mConfig.searchBarAppWidgetId >= 0) {
if (mSearchWidgetInfo != null) {
final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> cbRef = final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> cbRef =
new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>( new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>(
RecentsActivity.this); RecentsActivity.this);
@@ -654,9 +601,22 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
/**** RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks Implementation ****/ /**** RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks Implementation ****/
@Override @Override
public void refreshSearchWidget() { public void refreshSearchWidgetView() {
bindSearchBarAppWidget(); if (mSearchWidgetInfo != null) {
addSearchBarAppWidgetView(); 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 ****/ /**** DebugOverlayView.DebugOverlayViewCallbacks ****/

View File

@@ -20,26 +20,20 @@ import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo; import android.appwidget.AppWidgetProviderInfo;
import android.content.Context; 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 */ /** Our special app widget host for the Search widget */
public class RecentsAppWidgetHost extends AppWidgetHost { public class RecentsAppWidgetHost extends AppWidgetHost {
/* Callbacks to notify when an app package changes */ /* Callbacks to notify when an app package changes */
interface RecentsAppWidgetHostCallbacks { interface RecentsAppWidgetHostCallbacks {
public void refreshSearchWidget(); void refreshSearchWidgetView();
} }
Context mContext;
RecentsAppWidgetHostCallbacks mCb; RecentsAppWidgetHostCallbacks mCb;
RecentsConfiguration mConfig;
boolean mIsListening; boolean mIsListening;
public RecentsAppWidgetHost(Context context, int hostId) { public RecentsAppWidgetHost(Context context, int hostId) {
super(context, hostId); super(context, hostId);
mContext = context;
mConfig = RecentsConfiguration.getInstance();
} }
public void startListening(RecentsAppWidgetHostCallbacks cb) { public void startListening(RecentsAppWidgetHostCallbacks cb) {
@@ -57,7 +51,6 @@ public class RecentsAppWidgetHost extends AppWidgetHost {
} }
// Ensure that we release any references to the callbacks // Ensure that we release any references to the callbacks
mCb = null; mCb = null;
mContext = null;
mIsListening = false; mIsListening = false;
} }
@@ -67,18 +60,14 @@ public class RecentsAppWidgetHost extends AppWidgetHost {
return new RecentsAppWidgetHostView(context); return new RecentsAppWidgetHostView(context);
} }
/**
* Note: this is only called for packages that have updated, not removed.
*/
@Override @Override
protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) { protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) {
if (mCb == null) return; super.onProviderChanged(appWidgetId, appWidgetInfo);
if (mContext == null) return; if (mIsListening && mCb != null) {
mCb.refreshSearchWidgetView();
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();
} }
} }
} }

View File

@@ -18,6 +18,7 @@ package com.android.systemui.recents;
import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetHostView;
import android.content.Context; import android.content.Context;
import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
public class RecentsAppWidgetHostView extends AppWidgetHostView { public class RecentsAppWidgetHostView extends AppWidgetHostView {
@@ -37,6 +38,14 @@ public class RecentsAppWidgetHostView extends AppWidgetHostView {
super.updateAppWidget(remoteViews); 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. * Updates the last orientation that this widget was inflated.
*/ */

View File

@@ -73,7 +73,6 @@ public class RecentsConfiguration {
public int maxNumTasksToLoad; public int maxNumTasksToLoad;
/** Search bar */ /** Search bar */
int searchBarAppWidgetId = -1;
public int searchBarSpaceHeightPx; public int searchBarSpaceHeightPx;
/** Task stack */ /** Task stack */
@@ -207,8 +206,6 @@ public class RecentsConfiguration {
// Search Bar // Search Bar
searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
searchBarAppWidgetId = Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID,
-1 /* defaultValue */);
// Task stack // Task stack
taskStackScrollDuration = taskStackScrollDuration =
@@ -279,12 +276,6 @@ public class RecentsConfiguration {
systemInsets.set(insets); 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. */ /** Updates the states that need to be re-read whenever we re-initialize. */
void updateOnReinitialize(Context context, SystemServicesProxy ssp) { void updateOnReinitialize(Context context, SystemServicesProxy ssp) {
// Check if the developer options are enabled // Check if the developer options are enabled
@@ -304,11 +295,6 @@ public class RecentsConfiguration {
launchedHasConfigurationChanged = true; 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. */ /** Returns whether the status bar scrim should be animated when shown for the first time. */
public boolean shouldAnimateStatusBarScrim() { public boolean shouldAnimateStatusBarScrim() {
return launchedFromHome; return launchedFromHome;
@@ -335,9 +321,7 @@ public class RecentsConfiguration {
* the system insets. * the system insets.
*/ */
public void getAvailableTaskStackBounds(int windowWidth, int windowHeight, int topInset, public void getAvailableTaskStackBounds(int windowWidth, int windowHeight, int topInset,
int rightInset, Rect taskStackBounds) { int rightInset, Rect searchBarBounds, Rect taskStackBounds) {
Rect searchBarBounds = new Rect();
getSearchBarBounds(windowWidth, windowHeight, topInset, searchBarBounds);
if (isLandscape && hasTransposedSearchBar) { if (isLandscape && hasTransposedSearchBar) {
// In landscape, the search bar appears on the left, but we overlay it on top // In landscape, the search bar appears on the left, but we overlay it on top
taskStackBounds.set(0, topInset, windowWidth - rightInset, windowHeight); taskStackBounds.set(0, topInset, windowWidth - rightInset, windowHeight);
@@ -355,10 +339,6 @@ public class RecentsConfiguration {
Rect searchBarSpaceBounds) { Rect searchBarSpaceBounds) {
// Return empty rects if search is not enabled // Return empty rects if search is not enabled
int searchBarSize = searchBarSpaceHeightPx; int searchBarSize = searchBarSpaceHeightPx;
if (!Constants.DebugFlags.App.EnableSearchLayout || !hasSearchBarAppWidget()) {
searchBarSize = 0;
}
if (isLandscape && hasTransposedSearchBar) { if (isLandscape && hasTransposedSearchBar) {
// In landscape, the search bar appears on the left // In landscape, the search bar appears on the left
searchBarSpaceBounds.set(0, topInset, searchBarSize, windowHeight); searchBarSpaceBounds.set(0, topInset, searchBarSize, windowHeight);

View File

@@ -62,9 +62,11 @@ import android.view.DisplayInfo;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import com.android.systemui.Prefs;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.recents.Constants; import com.android.systemui.recents.Constants;
import com.android.systemui.recents.Recents; import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsAppWidgetHost;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; 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 * Returns the current search widget id.
* assist activity.
*/ */
public AppWidgetProviderInfo resolveSearchAppWidget() { public int getSearchAppWidgetId(Context context) {
if (mAwm == null) return null; return Prefs.getInt(context, Prefs.Key.SEARCH_APP_WIDGET_ID, -1);
if (mAssistComponent == null) return null; }
// Find the first Recents widget from the same package as the global assist activity /**
* 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;
}
/**
* Returns the first Recents widget from the same package as the global assist activity.
*/
private AppWidgetProviderInfo resolveSearchAppWidget() {
List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders( List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders(
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
for (AppWidgetProviderInfo info : widgets) { 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. * 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 (mAwm == null) return null;
if (mAssistComponent == 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) // Allocate a new widget id and try and bind the app widget (if that fails, then just skip)
int searchWidgetId = host.allocateAppWidgetId(); int searchWidgetId = host.allocateAppWidgetId();
Bundle opts = new Bundle(); Bundle opts = new Bundle();
opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, searchWidgetInfo.provider, opts)) { if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, resolvedSearchWidgetInfo.provider, opts)) {
host.deleteAppWidgetId(searchWidgetId); host.deleteAppWidgetId(searchWidgetId);
return null; return null;
} }
return new Pair<Integer, AppWidgetProviderInfo>(searchWidgetId, searchWidgetInfo); return new Pair<>(searchWidgetId, resolvedSearchWidgetInfo);
}
/**
* 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);
} }
/** /**

View File

@@ -287,17 +287,14 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
/** Adds the search bar */ /** Adds the search bar */
public void setSearchBar(RecentsAppWidgetHostView searchBar) { public void setSearchBar(RecentsAppWidgetHostView searchBar) {
// Create the search bar (and hide it if we have no recent tasks) // Remove the previous search bar if one exists
if (Constants.DebugFlags.App.EnableSearchLayout) { if (mSearchBar != null && indexOfChild(mSearchBar) > -1) {
// Remove the previous search bar if one exists removeView(mSearchBar);
if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { }
removeView(mSearchBar); // Add the new search bar
} if (searchBar != null) {
// Add the new search bar mSearchBar = searchBar;
if (searchBar != null) { addView(mSearchBar);
mSearchBar = searchBar;
addView(mSearchBar);
}
} }
} }
@@ -324,8 +321,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
int height = MeasureSpec.getSize(heightMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec);
// Get the search bar bounds and measure the search bar layout // Get the search bar bounds and measure the search bar layout
Rect searchBarSpaceBounds = new Rect();
if (mSearchBar != null) { if (mSearchBar != null) {
Rect searchBarSpaceBounds = new Rect();
mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds); mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds);
mSearchBar.measure( mSearchBar.measure(
MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
@@ -334,7 +331,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
Rect taskStackBounds = new Rect(); Rect taskStackBounds = new Rect();
mConfig.getAvailableTaskStackBounds(width, height, mConfig.systemInsets.top, 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 // Measure each TaskStackView with the full width and height of the window since the
// transition view is a child of that stack view // transition view is a child of that stack view