diff options
author | Winson Chung <winsonc@google.com> | 2014-12-03 18:10:36 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-12-03 18:10:38 +0000 |
commit | de9848c641e1b1e0f73e5655c3f8c0c3b34a011c (patch) | |
tree | 00d8040429aec9dc3ec1b0a4a01c7e3ae3cbe4bc /packages | |
parent | 5ce118d1f4bdaaa1e85626d06d473b2dece949c3 (diff) | |
parent | 740c3ac782675d190941b2ab1905e56f246c1b11 (diff) | |
download | frameworks_base-de9848c641e1b1e0f73e5655c3f8c0c3b34a011c.zip frameworks_base-de9848c641e1b1e0f73e5655c3f8c0c3b34a011c.tar.gz frameworks_base-de9848c641e1b1e0f73e5655c3f8c0c3b34a011c.tar.bz2 |
Merge "Initial changes to add callback on task stack changes. (Bug 17672056, Bug 18291345)" into lmp-mr1-dev
Diffstat (limited to 'packages')
6 files changed, 72 insertions, 32 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java index 29f291d..4f0700e 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java @@ -19,6 +19,7 @@ package com.android.systemui.recents; 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; @@ -56,6 +57,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; + /** A proxy implementation for the recents component */ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationStartedListener { @@ -79,6 +81,28 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta final static String sRecentsPackage = "com.android.systemui"; final static String sRecentsActivity = "com.android.systemui.recents.RecentsActivity"; + /** + * An implementation of ITaskStackListener, that allows us to listen for changes to the system + * task stacks and update recents accordingly. + */ + class TaskStackListenerImpl extends ITaskStackListener.Stub { + @Override + public void onTaskStackChanged() { + RecentsConfiguration config = RecentsConfiguration.getInstance(); + if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) { + // Load the next task only if we aren't svelte + RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); + RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); + loader.preloadTasks(plan, true /* isTopTaskHome */); + RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); + launchOpts.numVisibleTasks = 1; + launchOpts.numVisibleTaskThumbnails = 1; + launchOpts.onlyLoadForCache = true; + loader.loadTasks(mContext, plan, launchOpts); + } + } + } + static RecentsComponent.Callbacks sRecentsComponentCallbacks; static RecentsTaskLoadPlan sInstanceLoadPlan; @@ -86,6 +110,7 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta LayoutInflater mInflater; SystemServicesProxy mSystemServicesProxy; Handler mHandler; + TaskStackListenerImpl mTaskStackListener; boolean mBootCompleted; boolean mStartAnimationTriggered; boolean mCanReuseTaskStackViews = true; @@ -116,6 +141,10 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta mSystemServicesProxy = new SystemServicesProxy(context); mHandler = new Handler(); mTaskStackBounds = new Rect(); + + // Register the task stack listener + mTaskStackListener = new TaskStackListenerImpl(); + mSystemServicesProxy.registerTaskStackListener(mTaskStackListener); } public void onStart() { diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index 6dc2edb..a37bc54 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -167,10 +167,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView if (action.equals(Intent.ACTION_SCREEN_OFF)) { // When the screen turns off, dismiss Recents to Home dismissRecentsToHome(false); - // Preload the metadata for all tasks in the background - RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); - RecentsTaskLoadPlan plan = loader.createLoadPlan(context); - loader.preloadTasks(plan, true /* isTopTaskHome */); } else if (action.equals(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED)) { // When the search activity changes, update the Search widget refreshSearchWidget(); @@ -437,22 +433,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView onEnterAnimationTriggered(); } - // Start listening for widget package changes if there is one bound, post it since we don't - // want it stalling the startup - if (mConfig.searchBarAppWidgetId >= 0) { - final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> callback = - new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>(this); - mRecentsView.post(new Runnable() { - @Override - public void run() { - RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks cb = callback.get(); - if (cb != null) { - mAppWidgetHost.startListening(cb); - } - } - }); - } - mStatusBar = ((SystemUIApplication) getApplication()) .getComponent(PhoneStatusBar.class); } @@ -539,15 +519,29 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView unregisterReceiver(mSystemBroadcastReceiver); // Stop listening for widget package changes if there was one bound - if (mAppWidgetHost.isListening()) { - mAppWidgetHost.stopListening(); - } + mAppWidgetHost.stopListening(); } public void onEnterAnimationTriggered() { // Try and start the enter animation (or restart it on configuration changed) ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null); - mRecentsView.startEnterRecentsAnimation(new ViewAnimation.TaskViewEnterContext(t)); + ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t); + mRecentsView.startEnterRecentsAnimation(ctx); + if (mConfig.searchBarAppWidgetId >= 0) { + final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> cbRef = + new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>( + RecentsActivity.this); + ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() { + @Override + public void run() { + // Start listening for widget package changes if there is one bound + RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks cb = cbRef.get(); + if (cb != null) { + mAppWidgetHost.startListening(cb); + } + } + }); + } // Animate the SystemUI scrim views mScrimViews.startEnterRecentsAnimation(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java index a63e167..5bae37a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsAppWidgetHost.java @@ -43,23 +43,23 @@ public class RecentsAppWidgetHost extends AppWidgetHost { public void startListening(RecentsAppWidgetHostCallbacks cb) { mCb = cb; - mIsListening = true; - super.startListening(); + if (!mIsListening) { + mIsListening = true; + super.startListening(); + } } @Override public void stopListening() { - super.stopListening(); + if (mIsListening) { + super.stopListening(); + } // Ensure that we release any references to the callbacks mCb = null; mContext = null; mIsListening = false; } - public boolean isListening() { - return mIsListening; - } - @Override protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) { if (mCb == null) return; 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 9a4bd08..3fbd5a6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -21,6 +21,7 @@ import android.app.ActivityManagerNative; import android.app.ActivityOptions; import android.app.AppGlobals; import android.app.IActivityManager; +import android.app.ITaskStackListener; import android.app.SearchManager; import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; @@ -536,4 +537,15 @@ public class SystemServicesProxy { e.printStackTrace(); } } + + /** Registers a task stack listener with the system. */ + public void registerTaskStackListener(ITaskStackListener listener) { + if (mIam == null) return; + + try { + mIam.registerTaskStackListener(listener); + } catch (Exception e) { + e.printStackTrace(); + } + } } 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 46a5d8d..746a7df 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -204,6 +204,10 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV /** Requests all task stacks to start their enter-recents animation */ public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { + // We have to increment/decrement the post animation trigger in case there are no children + // to ensure that it runs + ctx.postAnimationTrigger.increment(); + int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); @@ -212,6 +216,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV stackView.startEnterRecentsAnimation(ctx); } } + ctx.postAnimationTrigger.decrement(); } /** Requests all task stacks to start their exit-recents animation */ diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java b/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java index 4586f12..e1d80fd 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java @@ -27,7 +27,7 @@ public class ViewAnimation { public static class TaskViewEnterContext { // A trigger to run some logic when all the animations complete. This works around the fact // that it is difficult to coordinate ViewPropertyAnimators - ReferenceCountedTrigger postAnimationTrigger; + public ReferenceCountedTrigger postAnimationTrigger; // An update listener to notify as the enter animation progresses (used for the home transition) ValueAnimator.AnimatorUpdateListener updateListener; |