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

Commit 2578c474 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: make long pressing recent switch to last app



With this patch, long pressing the recents key on the navigation bar
will attempt to switch to your last application in the activity stack
before the active one.

The user's current home launcher package is ignored as well as SystemUI (so that
RecentsActivity does not influence the behavior).

Change-Id: I38771e0fce16b55bb5186af47115b4e812cb60b0
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 49ae28e1
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The CyanogenMod 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.
-->

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:interpolator/linear">

    <translate android:fromXDelta="0%" android:toXDelta="-35%"
        android:zAdjustment="bottom"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <scale android:fromXScale="0.80" android:toXScale="1.0"
        android:fromYScale="0.80" android:toYScale="1.0"
        android:pivotX="50%" android:pivotY="50%"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <translate android:fromXDelta="-35%" android:toXDelta="35%"
        android:zAdjustment="top"
        android:startOffset="@android:integer/config_shortAnimTime"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <alpha android:fromAlpha="0.6" android:toAlpha="1.0"
        android:duration="@android:integer/config_shortAnimTime"
        />
</set>
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The CyanogenMod 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.
-->

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:interpolator/linear">

    <translate android:fromXDelta="-35%" android:toXDelta="35%"
        android:zAdjustment="top"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <scale android:fromXScale="1.0" android:toXScale="0.80"
        android:fromYScale="1.0" android:toYScale="0.80"
        android:pivotX="50%" android:pivotY="50%"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <translate android:fromXDelta="35%" android:toXDelta="-35%"
        android:zAdjustment="bottom"
        android:startOffset="@android:integer/config_shortAnimTime"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <alpha android:fromAlpha="1.0" android:toAlpha="0.6"
        android:duration="@android:integer/config_shortAnimTime"
        />
</set>
+6 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class NavigationBarView extends LinearLayout {
    private LockPatternUtils mLockUtils;
    private OnClickListener mRecentsClickListener;
    private OnTouchListener mRecentsPreloadListener;
    private OnLongClickListener mRecentsLongClickListener;
    private OnTouchListener mHomeSearchActionListener;

    final Display mDisplay;
@@ -324,9 +325,11 @@ public class NavigationBarView extends LinearLayout {
    }

    /* package */ void setListeners(OnClickListener recentsClickListener,
            OnTouchListener recentsPreloadListener, OnTouchListener homeSearchActionListener) {
            OnTouchListener recentsPreloadListener, OnLongClickListener recentsLongClickListener,
            OnTouchListener homeSearchActionListener) {
        mRecentsClickListener = recentsClickListener;
        mRecentsPreloadListener = recentsPreloadListener;
        mRecentsLongClickListener = recentsLongClickListener;
        mHomeSearchActionListener = homeSearchActionListener;
        updateButtonListeners();
    }
@@ -339,6 +342,7 @@ public class NavigationBarView extends LinearLayout {
            if (button instanceof KeyButtonView) {
                button.setOnClickListener(null);
                button.setOnTouchListener(null);
                button.setOnLongClickListener(null);
            }
        }
    }
@@ -348,6 +352,7 @@ public class NavigationBarView extends LinearLayout {
        if (recentView != null) {
            recentView.setOnClickListener(mRecentsClickListener);
            recentView.setOnTouchListener(mRecentsPreloadListener);
            recentView.setOnLongClickListener(mRecentsLongClickListener);
        }
        View homeView = findButton(NavbarEditor.NAVBAR_HOME);
        if (homeView != null) {
+49 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityOptions;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.StatusBarManager;
@@ -42,6 +43,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.ThemeConfig;
import android.content.res.Resources;
@@ -125,6 +127,7 @@ import com.android.systemui.statusbar.policy.OnSizeChangedListener;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        NetworkController.UpdateUIListener {
@@ -1092,6 +1095,50 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
    };

    private View.OnLongClickListener mRecentsLongPressListener = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            cancelPreloadingRecentTasksList();

            final ActivityManager am =
                    (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
            ActivityManager.RunningTaskInfo lastTask = getLastTask(am);

            if (lastTask != null) {
                if (DEBUG) Log.d(TAG, "switching to " + lastTask.topActivity.getPackageName());
                final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
                        R.anim.last_app_in, R.anim.last_app_out);
                am.moveTaskToFront(lastTask.id, ActivityManager.MOVE_TASK_NO_USER_ACTION,
                        opts.toBundle());
                return true;
            }
            return false;
        }

        private ActivityManager.RunningTaskInfo getLastTask(final ActivityManager am) {
            final String defaultHomePackage = resolveCurrentLauncherPackage();
            List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);

            for (int i = 1; i < tasks.size(); i++) {
                String packageName = tasks.get(i).topActivity.getPackageName();
                if (!packageName.equals(defaultHomePackage)
                        && !packageName.equals(mContext.getPackageName())) {
                    return tasks.get(i);
                }
            }

            return null;
        }

        private String resolveCurrentLauncherPackage() {
            final Intent launcherIntent = new Intent(Intent.ACTION_MAIN)
                    .addCategory(Intent.CATEGORY_HOME);
            final PackageManager pm = mContext.getPackageManager();
            final ResolveInfo launcherInfo = pm.resolveActivity(launcherIntent, 0);
            return launcherInfo.activityInfo.packageName;
        }
    };

    private int mShowSearchHoldoff = 0;
    private Runnable mShowSearchPanel = new Runnable() {
        public void run() {
@@ -1133,7 +1180,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private void prepareNavigationBarView() {
        mNavigationBarView.reorient();
        mNavigationBarView.setListeners(mRecentsClickListener,
                mRecentsPreloadOnTouchListener, mHomeSearchActionListener);
                mRecentsPreloadOnTouchListener, mRecentsLongPressListener,
                mHomeSearchActionListener);
        updateSearchPanel();
    }

+4 −1
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class KeyButtonView extends ImageView {
    Animator mAnimateToQuiescent = new ObjectAnimator();

    private PowerManager mPm;
    private boolean mPerformedLongClick;

    Runnable mCheckLongPress = new Runnable() {
        public void run() {
@@ -90,6 +91,7 @@ public class KeyButtonView extends ImageView {
                    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
                } else {
                    // Just an old-fashioned ImageView
                    mPerformedLongClick = true;
                    performLongClick();
                }
            }
@@ -366,13 +368,14 @@ public class KeyButtonView extends ImageView {
                    }
                } else {
                    // no key code, just a regular ImageView
                    if (doIt) {
                    if (doIt && !mPerformedLongClick) {
                        performClick();
                    }
                }
                if (supportsLongPress()) {
                    removeCallbacks(mCheckLongPress);
                }
                mPerformedLongClick = false;
                break;
        }