diff options
4 files changed, 76 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index f014f09834ed..130d3bca608d 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -19,7 +19,6 @@ package com.android.systemui.recents; import android.app.Activity; import android.app.ActivityOptions; import android.app.SearchManager; -import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProviderInfo; import android.content.BroadcastReceiver; @@ -35,7 +34,6 @@ import android.view.KeyEvent; import android.view.View; import android.view.ViewStub; import android.widget.Toast; - import com.android.systemui.R; import com.android.systemui.recents.misc.DebugTrigger; import com.android.systemui.recents.misc.ReferenceCountedTrigger; @@ -49,8 +47,6 @@ import com.android.systemui.recents.views.DebugOverlayView; import com.android.systemui.recents.views.RecentsView; import com.android.systemui.recents.views.SystemBarScrimViews; import com.android.systemui.recents.views.ViewAnimation; -import com.android.systemui.statusbar.phone.PhoneStatusBar; -import com.android.systemui.SystemUIApplication; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; @@ -78,9 +74,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView RecentsResizeTaskDialog mResizeTaskDebugDialog; // Search AppWidget - RecentsAppWidgetHost mAppWidgetHost; AppWidgetProviderInfo mSearchAppWidgetInfo; - AppWidgetHostView mSearchAppWidgetHostView; + RecentsAppWidgetHost mAppWidgetHost; + RecentsAppWidgetHostView mSearchAppWidgetHostView; // Runnables to finish the Recents activity FinishRecentsRunnable mFinishLaunchHomeRunnable; @@ -245,7 +241,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView if (mEmptyView != null) { mEmptyView.setVisibility(View.GONE); } - if (mRecentsView.hasSearchBar()) { + if (mRecentsView.hasValidSearchBar()) { mRecentsView.setSearchBarVisibility(View.VISIBLE); } else { addSearchBarAppWidgetView(); @@ -295,8 +291,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView if (Constants.DebugFlags.App.EnableSearchLayout) { int appWidgetId = mConfig.searchBarAppWidgetId; if (appWidgetId >= 0) { - mSearchAppWidgetHostView = mAppWidgetHost.createView(this, appWidgetId, - mSearchAppWidgetInfo); + mSearchAppWidgetHostView = (RecentsAppWidgetHostView) mAppWidgetHost.createView( + this, appWidgetId, mSearchAppWidgetInfo); Bundle opts = new Bundle(); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java index 5bae37a0c5d5..02a7b94b93c1 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java @@ -17,6 +17,7 @@ package com.android.systemui.recents; import android.appwidget.AppWidgetHost; +import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import com.android.systemui.recents.misc.SystemServicesProxy; @@ -61,6 +62,12 @@ public class RecentsAppWidgetHost extends AppWidgetHost { } @Override + protected AppWidgetHostView onCreateView(Context context, int appWidgetId, + AppWidgetProviderInfo appWidget) { + return new RecentsAppWidgetHostView(context); + } + + @Override protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) { if (mCb == null) return; diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java new file mode 100644 index 000000000000..1ed755ab0db0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHostView.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.recents; + +import android.appwidget.AppWidgetHostView; +import android.content.Context; +import android.widget.RemoteViews; + +public class RecentsAppWidgetHostView extends AppWidgetHostView { + + private Context mContext; + private int mPreviousOrientation; + + public RecentsAppWidgetHostView(Context context) { + super(context); + mContext = context; + } + + @Override + public void updateAppWidget(RemoteViews remoteViews) { + // Store the orientation in which the widget was inflated + updateLastInflationOrientation(); + super.updateAppWidget(remoteViews); + } + + /** + * Updates the last orientation that this widget was inflated. + */ + private void updateLastInflationOrientation() { + mPreviousOrientation = mContext.getResources().getConfiguration().orientation; + } + + /** + * @return whether the search widget was updated while Recents was in a different orientation + * in the background. + */ + public boolean isReinflateRequired() { + // Re-inflate is required if the orientation has changed since last inflated. + int orientation = mContext.getResources().getConfiguration().orientation; + if (mPreviousOrientation != orientation) { + return true; + } + return false; + } +} 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 abed7a5b7ccd..13779757afc5 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -34,6 +34,7 @@ import android.view.WindowInsets; import android.widget.FrameLayout; import com.android.systemui.R; import com.android.systemui.recents.Constants; +import com.android.systemui.recents.RecentsAppWidgetHostView; import com.android.systemui.recents.RecentsConfiguration; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.recents.model.RecentsPackageMonitor; @@ -69,7 +70,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV ArrayList<TaskStack> mStacks; List<TaskStackView> mTaskStackViews = new ArrayList<>(); - View mSearchBar; + RecentsAppWidgetHostView mSearchBar; RecentsViewCallbacks mCb; public RecentsView(Context context) { @@ -278,7 +279,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV } /** Adds the search bar */ - public void setSearchBar(View searchBar) { + 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 @@ -294,8 +295,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV } /** Returns whether there is currently a search bar */ - public boolean hasSearchBar() { - return mSearchBar != null; + public boolean hasValidSearchBar() { + return mSearchBar != null && !mSearchBar.isReinflateRequired(); } /** Sets the visibility of the search bar */ |