Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50c69b5d authored by Michael Jurka's avatar Michael Jurka Committed by Android (Google) Code Review
Browse files

Merge "Preload recents on phones with hard nav keys"

parents 6ef1eeda 7f2668c8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -35,5 +35,7 @@ oneway interface IStatusBar
    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
    void setHardKeyboardStatus(boolean available, boolean enabled);
    void toggleRecentApps();
    void preloadRecentApps();
    void cancelPreloadRecentApps();
}
+2 −0
Original line number Diff line number Diff line
@@ -47,4 +47,6 @@ interface IStatusBarService
    void setSystemUiVisibility(int vis);
    void setHardKeyboardEnabled(boolean enabled);
    void toggleRecentApps();
    void preloadRecentApps();
    void cancelPreloadRecentApps();
}
+10 −4
Original line number Diff line number Diff line
@@ -456,6 +456,9 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener

        mPreloadTasksRunnable = new Runnable() {
            public void run() {
                // If we set our visibility to INVISIBLE here, we avoid an extra call to
                // onLayout later when we become visible (because onLayout is always called
                // when going from GONE)
                if (!mShowing) {
                    setVisibility(INVISIBLE);
                    refreshRecentTasksList();
@@ -562,9 +565,6 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        if (!mShowing) {
            int action = ev.getAction() & MotionEvent.ACTION_MASK;
            if (action == MotionEvent.ACTION_DOWN) {
                // If we set our visibility to INVISIBLE here, we avoid an extra call to
                // onLayout later when we become visible (because onLayout is always called
                // when going from GONE)
                post(mPreloadTasksRunnable);
            } else if (action == MotionEvent.ACTION_CANCEL) {
                setVisibility(GONE);
@@ -583,9 +583,15 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        return false;
    }

    public void preloadRecentTasksList() {
        if (!mShowing) {
            mPreloadTasksRunnable.run();
        }
    }

    public void clearRecentTasksList() {
        // Clear memory used by screenshots
        if (mRecentTaskDescriptions != null) {
        if (!mShowing && mRecentTaskDescriptions != null) {
            mRecentTasksLoader.cancelLoadingThumbnailsAndIcons();
            mRecentTaskDescriptions.clear();
            mListAdapter.notifyDataSetInvalidated();
+140 −1
Original line number Diff line number Diff line
@@ -19,31 +19,53 @@ package com.android.systemui.statusbar;
import java.util.ArrayList;

import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.util.Slog;
import android.view.Display;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import android.widget.LinearLayout;

import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarIconList;
import com.android.internal.statusbar.StatusBarNotification;
import com.android.systemui.SystemUI;
import com.android.systemui.recent.RecentsPanelView;
import com.android.systemui.recent.RecentTasksLoader;
import com.android.systemui.recent.TaskDescription;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.tablet.StatusBarPanel;

import com.android.systemui.R;

public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Callbacks {
public abstract class BaseStatusBar extends SystemUI implements
    CommandQueue.Callbacks, RecentsPanelView.OnRecentsPanelVisibilityChangedListener {
    static final String TAG = "StatusBar";
    private static final boolean DEBUG = false;

    protected static final int MSG_OPEN_RECENTS_PANEL = 1020;
    protected static final int MSG_CLOSE_RECENTS_PANEL = 1021;
    protected static final int MSG_PRELOAD_RECENT_APPS = 1022;
    protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;

    protected CommandQueue mCommandQueue;
    protected IStatusBarService mBarService;
    protected H mHandler = createHandler();

    // Recent apps
    protected RecentsPanelView mRecentsPanel;
    protected RecentTasksLoader mRecentTasksLoader;

    // UI-specific methods
    
@@ -162,4 +184,121 @@ public abstract class BaseStatusBar extends SystemUI implements CommandQueue.Cal
    public void dismissIntruder() {
        // pass
    }

    @Override
    public void toggleRecentApps() {
        int msg = (mRecentsPanel.getVisibility() == View.VISIBLE)
            ? MSG_CLOSE_RECENTS_PANEL : MSG_OPEN_RECENTS_PANEL;
        mHandler.removeMessages(msg);
        mHandler.sendEmptyMessage(msg);
    }

    @Override
    public void preloadRecentApps() {
        int msg = MSG_PRELOAD_RECENT_APPS;
        mHandler.removeMessages(msg);
        mHandler.sendEmptyMessage(msg);
    }

    @Override
    public void cancelPreloadRecentApps() {
        int msg = MSG_CANCEL_PRELOAD_RECENT_APPS;
        mHandler.removeMessages(msg);
        mHandler.sendEmptyMessage(msg);
    }

    @Override
    public void onRecentsPanelVisibilityChanged(boolean visible) {
    }

    protected abstract WindowManager.LayoutParams getRecentsLayoutParams(
            LayoutParams layoutParams);

    protected void updateRecentsPanel() {
        // Recents Panel
        boolean visible = false;
        ArrayList<TaskDescription> recentTasksList = null;
        boolean firstScreenful = false;
        if (mRecentsPanel != null) {
            visible = mRecentsPanel.isShowing();
            WindowManagerImpl.getDefault().removeView(mRecentsPanel);
            if (visible) {
                recentTasksList = mRecentsPanel.getRecentTasksList();
                firstScreenful = mRecentsPanel.getFirstScreenful();
            }
        }

        // Provide RecentsPanelView with a temporary parent to allow layout params to work.
        LinearLayout tmpRoot = new LinearLayout(mContext);
        mRecentsPanel = (RecentsPanelView) LayoutInflater.from(mContext).inflate(
                 R.layout.status_bar_recent_panel, tmpRoot, false);
        mRecentsPanel.setRecentTasksLoader(mRecentTasksLoader);
        mRecentTasksLoader.setRecentsPanel(mRecentsPanel);
        mRecentsPanel.setOnTouchListener(
                 new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, mRecentsPanel));
        mRecentsPanel.setVisibility(View.GONE);


        WindowManager.LayoutParams lp = getRecentsLayoutParams(mRecentsPanel.getLayoutParams());

        WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
        mRecentsPanel.setBar(this);
        if (visible) {
            mRecentsPanel.show(true, false, recentTasksList, firstScreenful);
        }

    }

    H createHandler() {
         return new H();
    }

    protected class H extends Handler {
        public void handleMessage(Message m) {
            switch (m.what) {
             case MSG_OPEN_RECENTS_PANEL:
                  if (DEBUG) Slog.d(TAG, "opening recents panel");
                  if (mRecentsPanel != null) {
                      mRecentsPanel.show(true, true);
                  }
                  break;
             case MSG_CLOSE_RECENTS_PANEL:
                  if (DEBUG) Slog.d(TAG, "closing recents panel");
                  if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
                      mRecentsPanel.show(false, true);
                  }
                  break;
             case MSG_PRELOAD_RECENT_APPS:
                  if (DEBUG) Slog.d(TAG, "preloading recents");
                  mRecentsPanel.preloadRecentTasksList();
                  break;
             case MSG_CANCEL_PRELOAD_RECENT_APPS:
                  if (DEBUG) Slog.d(TAG, "cancel preloading recents");
                  mRecentsPanel.clearRecentTasksList();
                  break;
            }
        }
    }

    public class TouchOutsideListener implements View.OnTouchListener {
        private int mMsg;
        private StatusBarPanel mPanel;

        public TouchOutsideListener(int msg, StatusBarPanel panel) {
            mMsg = msg;
            mPanel = panel;
        }

        public boolean onTouch(View v, MotionEvent ev) {
            final int action = ev.getAction();
            if (action == MotionEvent.ACTION_OUTSIDE
                || (action == MotionEvent.ACTION_DOWN
                    && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
                mHandler.removeMessages(mMsg);
                mHandler.sendEmptyMessage(mMsg);
                return true;
            }
            return false;
        }
    }
}
+25 −1
Original line number Diff line number Diff line
@@ -61,8 +61,10 @@ public class CommandQueue extends IStatusBar.Stub {
    private static final int MSG_SET_HARD_KEYBOARD_STATUS = 10 << MSG_SHIFT;
    
    private static final int MSG_TOGGLE_RECENT_APPS       = 11 << MSG_SHIFT;
    private static final int MSG_PRELOAD_RECENT_APPS      = 12 << MSG_SHIFT;
    private static final int MSG_CANCEL_PRELOAD_RECENT_APPS       = 13 << MSG_SHIFT;

    private static final int MSG_SET_NAVIGATION_ICON_HINTS = 13 << MSG_SHIFT;
    private static final int MSG_SET_NAVIGATION_ICON_HINTS = 14 << MSG_SHIFT;

    private StatusBarIconList mList;
    private Callbacks mCallbacks;
@@ -92,6 +94,8 @@ public class CommandQueue extends IStatusBar.Stub {
        public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
        public void setHardKeyboardStatus(boolean available, boolean enabled);
        public void toggleRecentApps();
        public void preloadRecentApps();
        public void cancelPreloadRecentApps();
        public void setNavigationIconHints(int hints);
    }

@@ -199,6 +203,20 @@ public class CommandQueue extends IStatusBar.Stub {
        }
    }

    public void preloadRecentApps() {
        synchronized (mList) {
            mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
            mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
        }
    }

    public void cancelPreloadRecentApps() {
        synchronized (mList) {
            mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
            mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
        }
    }

    public void setNavigationIconHints(int hints) {
        synchronized (mList) {
            mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS);
@@ -275,6 +293,12 @@ public class CommandQueue extends IStatusBar.Stub {
                case MSG_TOGGLE_RECENT_APPS:
                    mCallbacks.toggleRecentApps();
                    break;
                case MSG_PRELOAD_RECENT_APPS:
                    mCallbacks.preloadRecentApps();
                    break;
                case MSG_CANCEL_PRELOAD_RECENT_APPS:
                    mCallbacks.cancelPreloadRecentApps();
                    break;
                case MSG_SET_NAVIGATION_ICON_HINTS:
                    mCallbacks.setNavigationIconHints(msg.arg1);
                    break;
Loading