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

Commit fd6c984a authored by Matt Garnes's avatar Matt Garnes Committed by Raj Yengisetty
Browse files

Add a custom home screen to Trebuchet.

Scrolling to the left will now open a custom home screen that can be
used to display information provided by the system or third parties
via an API.

Change-Id: I62991c0634b686ca875d04fa118695050731ba7e
parent 0ae199c3
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,16 @@
        android:protectionLevel="dangerous"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_uninstall_shortcut"
        android:label="@string/permlab_uninstall_shortcut"
        android:description="@string/permdesc_uninstall_shortcut"/>
        android:description="@string/permdesc_uninstall_shortcut"/>
    <permission
        android:name="com.android.launcher.home.permissions.HOME_APP"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous" />
    <permission
        android:name="com.android.launcher3.permission.READ_SETTINGS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_uninstall_shortcut"
        android:description="@string/permdesc_uninstall_shortcut"/>
    <permission
    <permission
        android:name="com.android.launcher3.permission.READ_SETTINGS"
        android:name="com.android.launcher3.permission.READ_SETTINGS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
+100 −0
Original line number Original line Diff line number Diff line
package com.android.launcher3;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Intent;
import android.service.gesture.EdgeGestureManager;
import com.android.internal.util.gesture.EdgeGesturePosition;

import java.util.List;

/**
 * A singleton wrapper class for GEL Integration.
 * Requires EdgeGestureManager functionality that is only available
 * in CyanogenMod.
 */
public class GelIntegrationHelper {
    // The Intent for the search activity (resolves to Google Now when installed)
    public final static String INTENT_ACTION_ASSIST = "android.intent.action.ASSIST";

    private static final String GEL_ACTIVITY = "com.google.android.velvet.ui.VelvetActivity";
    private static final String GEL_PACKAGE_NAME = "com.google.android.googlequicksearchbox";

    private static final int EDGE_GESTURE_SERVICE_RIGHT_EDGE = 4;
    private static final int EDGE_GESTURE_SERVICE_NO_EDGE = -1;

    private EdgeGestureManager.EdgeGestureActivationListener mEdgeGestureActivationListener = null;
    private static GelIntegrationHelper sInstance;

    private GelIntegrationHelper() {}

    public static GelIntegrationHelper getInstance() {
        if(sInstance == null) {
            sInstance = new GelIntegrationHelper();
        }
        return sInstance;
    }

    /**
     * 1. Registers an EdgeGestureActivationListener with the EdgeGestureManager so that
     *    the user can return to Trebuchet when they swipe from the right edge of the device.
     * 2. Starts the Google Now Activity with an exit_out_right transition animation so that
     *    the new Activity appears to slide in as another screen (similar to GEL).
     */
    public void registerSwipeBackGestureListenerAndStartGel(final Activity launcherActivity) {
        EdgeGestureManager edgeGestureManager = EdgeGestureManager.getInstance();
        if(mEdgeGestureActivationListener == null) {
            mEdgeGestureActivationListener = new EdgeGestureManager.EdgeGestureActivationListener() {
                ActivityManager mAm = (ActivityManager)
                        launcherActivity.getSystemService(Activity.ACTIVITY_SERVICE);

                @Override
                public void onEdgeGestureActivation(int touchX, int touchY,
                                                    EdgeGesturePosition position, int flags) {
                    // Retrieve the top level activity information
                    List< ActivityManager.RunningTaskInfo > taskInfo = mAm.getRunningTasks(1);
                    ComponentName topActivityComponentInfo = taskInfo.get(0).topActivity;
                    String topActivityClassName = topActivityComponentInfo.getClassName();
                    String topActivityPackageName = topActivityComponentInfo.getPackageName();

                    // If the top level activity is Google Now, return to home.
                    // Otherwise, do nothing.
                    if(GEL_ACTIVITY.equals(topActivityClassName)
                       && GEL_PACKAGE_NAME.equals(topActivityPackageName)) {
                        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
                        homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
                        homeIntent.addCategory(Intent.CATEGORY_HOME);
                        launcherActivity.startActivity(homeIntent);
                        launcherActivity.overridePendingTransition(0, 0);
                        dropEventsUntilLift();
                    }
                }
            };
            edgeGestureManager.setEdgeGestureActivationListener(mEdgeGestureActivationListener);
        }
        mEdgeGestureActivationListener.restoreListenerState();
        edgeGestureManager.updateEdgeGestureActivationListener(mEdgeGestureActivationListener,
                                                               EDGE_GESTURE_SERVICE_RIGHT_EDGE);

        // Start the Google Now Activity
        Intent i = new Intent(INTENT_ACTION_ASSIST);
        launcherActivity.startActivity(i);
        launcherActivity.overridePendingTransition(0, R.anim.exit_out_right);
    }

    /**
     * Handle necessary cleanup and reset tasks for GEL integration, to be called from onResume.
     */
    public void handleGelResume() {
        // If there is an active EdgeGestureActivationListener for GEL integration,
        // it should stop listening when we have resumed the launcher.
        if(mEdgeGestureActivationListener != null) {
            EdgeGestureManager edgeGestureManager = EdgeGestureManager.getInstance();
            // Update the listener so it is not listening to any postions (-1)
            edgeGestureManager.updateEdgeGestureActivationListener(mEdgeGestureActivationListener,
                                                                   EDGE_GESTURE_SERVICE_NO_EDGE);
        }
    }

}
+26 −3
Original line number Original line Diff line number Diff line
@@ -1291,14 +1291,15 @@ public class Workspace extends SmoothPagedView
        super.notifyPageSwitchListener();
        super.notifyPageSwitchListener();
        Launcher.setScreen(getNextPage());
        Launcher.setScreen(getNextPage());


        if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) {
        int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID);
        if (hasCustomContent() && getNextPage() == ccIndex && !mCustomContentShowing) {
            mCustomContentShowing = true;
            mCustomContentShowing = true;
            if (mCustomContentCallbacks != null) {
            if (mCustomContentCallbacks != null) {
                mCustomContentCallbacks.onShow(false);
                mCustomContentCallbacks.onShow(false);
                mCustomContentShowTime = System.currentTimeMillis();
                mCustomContentShowTime = System.currentTimeMillis();
                mLauncher.updateVoiceButtonProxyVisible(false);
                mLauncher.updateVoiceButtonProxyVisible(false);
            }
            }
        } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) {
        } else if (hasCustomContent() &&  getNextPage() != ccIndex && mCustomContentShowing) {
            mCustomContentShowing = false;
            mCustomContentShowing = false;
            if (mCustomContentCallbacks != null) {
            if (mCustomContentCallbacks != null) {
                mCustomContentCallbacks.onHide();
                mCustomContentCallbacks.onHide();
@@ -1826,6 +1827,21 @@ public class Workspace extends SmoothPagedView
        // Force the wallpaper offset steps to be set again, because another app might have changed
        // Force the wallpaper offset steps to be set again, because another app might have changed
        // them
        // them
        mLastSetWallpaperOffsetSteps = 0f;
        mLastSetWallpaperOffsetSteps = 0f;

        moveAwayFromCustomContentIfRequired();
    }

    public void moveAwayFromCustomContentIfRequired() {
        // Never resume to the custom page if GEL integration is enabled.
        int customPageIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID);
        // mCustomContentShowing can be lost if the Activity is recreated,
        // So make sure it is set to the right value.
        mCustomContentShowing = mCustomContentShowing
                                || (customPageIndex == getCurrentPage()
                                    && hasCustomContent());
        if (mCustomContentShowing && mLauncher.isGelIntegrationEnabled()) {
            moveToScreen((customPageIndex + 1), true);
        }
    }
    }


    @Override
    @Override
@@ -1836,6 +1852,8 @@ public class Workspace extends SmoothPagedView
            mWallpaperOffset.jumpToFinal();
            mWallpaperOffset.jumpToFinal();
        }
        }
        super.onLayout(changed, left, top, right, bottom);
        super.onLayout(changed, left, top, right, bottom);

        moveAwayFromCustomContentIfRequired();
    }
    }


    @Override
    @Override
@@ -4336,7 +4354,12 @@ public class Workspace extends SmoothPagedView
    }
    }


    public int getCurrentPageOffsetFromCustomContent() {
    public int getCurrentPageOffsetFromCustomContent() {
        return getNextPage() - numCustomPages();
        int numCustomPages = numCustomPages();
        // Special case where the Gel Integration page must be counted below
        if(mLauncher.isGelIntegrationEnabled() && mLauncher.isGelIntegrationSupported()) {
            numCustomPages += 1;
        }
        return getNextPage() - numCustomPages;
    }
    }


    /**
    /**
+9 −10
Original line number Original line Diff line number Diff line
@@ -38,11 +38,16 @@ import com.android.launcher3.R;
import org.cyanogenmod.trebuchet.home.HomeUtils;
import org.cyanogenmod.trebuchet.home.HomeUtils;
import org.cyanogenmod.trebuchet.home.HomeWrapper;
import org.cyanogenmod.trebuchet.home.HomeWrapper;


import java.lang.Override;

public class TrebuchetLauncher extends Launcher {
public class TrebuchetLauncher extends Launcher {


    private static final String TAG = "TrebuchetLauncher";
    private static final String TAG = "TrebuchetLauncher";


    private static final boolean DEBUG = true;
    private static final boolean DEBUG = false;
    private static final float MIN_PROGRESS = 0;
    private static final float MAX_PROGRESS = 1;



    private static class HomeAppStub {
    private static class HomeAppStub {
        private final int mUid;
        private final int mUid;
@@ -112,7 +117,6 @@ public class TrebuchetLauncher extends Launcher {
    private CustomContentCallbacks mCustomContentCallbacks = new CustomContentCallbacks() {
    private CustomContentCallbacks mCustomContentCallbacks = new CustomContentCallbacks() {
        @Override
        @Override
        public void onShow() {
        public void onShow() {
            updateQsbBarColorState(0);
            if (mCurrentHomeApp != null) {
            if (mCurrentHomeApp != null) {
                mCurrentHomeApp.mInstance.onShow();
                mCurrentHomeApp.mInstance.onShow();
            }
            }
@@ -128,7 +132,6 @@ public class TrebuchetLauncher extends Launcher {


        @Override
        @Override
        public void onHide() {
        public void onHide() {
            updateQsbBarColorState(255);
            if (mCurrentHomeApp != null) {
            if (mCurrentHomeApp != null) {
                mCurrentHomeApp.mInstance.onHide();
                mCurrentHomeApp.mInstance.onHide();
            }
            }
@@ -153,7 +156,7 @@ public class TrebuchetLauncher extends Launcher {
        mQsbInitialAlphaState = res.getInteger(R.integer.qsb_initial_alpha_state);
        mQsbInitialAlphaState = res.getInteger(R.integer.qsb_initial_alpha_state);
        mQsbEndAlphaState = res.getInteger(R.integer.qsb_end_alpha_state);
        mQsbEndAlphaState = res.getInteger(R.integer.qsb_end_alpha_state);
        mQsbButtonsEndColorFilter = res.getInteger(R.integer.qsb_buttons_end_colorfilter);
        mQsbButtonsEndColorFilter = res.getInteger(R.integer.qsb_buttons_end_colorfilter);
        updateQsbBarColorState(0);
        updateQsbBarColorState(MIN_PROGRESS);


        // Obtain the user-defined Home app or a valid one
        // Obtain the user-defined Home app or a valid one
        obtainCurrentHomeAppStubLocked(true);
        obtainCurrentHomeAppStubLocked(true);
@@ -195,7 +198,7 @@ public class TrebuchetLauncher extends Launcher {


    @Override
    @Override
    protected boolean hasCustomContentToLeft() {
    protected boolean hasCustomContentToLeft() {
        return mCurrentHomeApp != null;
        return mCurrentHomeApp != null && super.hasCustomContentToLeft();
    }
    }


    @Override
    @Override
@@ -205,7 +208,7 @@ public class TrebuchetLauncher extends Launcher {
    }
    }


    @Override
    @Override
    protected void addCustomContentToLeft() {
    protected void populateCustomContentContainer() {
        if (mCurrentHomeApp != null) {
        if (mCurrentHomeApp != null) {
            mQsbScroller = addToCustomContentPage(mCurrentHomeApp.mInstance.createCustomView(),
            mQsbScroller = addToCustomContentPage(mCurrentHomeApp.mInstance.createCustomView(),
                    mCustomContentCallbacks, mCurrentHomeApp.mInstance.getName());
                    mCustomContentCallbacks, mCurrentHomeApp.mInstance.getName());
@@ -316,16 +319,12 @@ public class TrebuchetLauncher extends Launcher {
            if (voiceButton != null) {
            if (voiceButton != null) {
                if (progress > 0) {
                if (progress > 0) {
                    voiceButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                    voiceButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                } else {
                    voiceButton.clearColorFilter();
                }
                }
            }
            }
            ImageView searchButton = getQsbBarSearchButton();
            ImageView searchButton = getQsbBarSearchButton();
            if (searchButton != null) {
            if (searchButton != null) {
                if (progress > 0) {
                if (progress > 0) {
                    searchButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                    searchButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                } else {
                    searchButton.clearColorFilter();
                }
                }
            }
            }
        }
        }