diff options
author | Matt Garnes <matt@cyngn.com> | 2014-06-12 15:07:36 -0700 |
---|---|---|
committer | Raj Yengisetty <rajesh@cyngn.com> | 2015-07-24 19:20:36 -0700 |
commit | fd6c984ae46a61eeda176085df696eefbe3ec2f9 (patch) | |
tree | 08238fe16040c1c8b24cab03e3d504a5db6dceb9 | |
parent | 0ae199c39a8f0bcfe37a733ec6dd60b2b3ab7e71 (diff) | |
download | android_packages_apps_Trebuchet-fd6c984ae46a61eeda176085df696eefbe3ec2f9.tar.gz android_packages_apps_Trebuchet-fd6c984ae46a61eeda176085df696eefbe3ec2f9.tar.bz2 android_packages_apps_Trebuchet-fd6c984ae46a61eeda176085df696eefbe3ec2f9.zip |
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
-rw-r--r-- | AndroidManifest.xml | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/GelIntegrationHelper.java | 100 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 29 | ||||
-rw-r--r-- | src/org/cyanogenmod/trebuchet/TrebuchetLauncher.java | 19 |
4 files changed, 145 insertions, 13 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7fc84eddf..a90b96fb0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -40,6 +40,16 @@ android:label="@string/permlab_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 android:name="com.android.launcher3.permission.READ_SETTINGS" android:permissionGroup="android.permission-group.SYSTEM_TOOLS" android:protectionLevel="normal" diff --git a/src/com/android/launcher3/GelIntegrationHelper.java b/src/com/android/launcher3/GelIntegrationHelper.java new file mode 100644 index 000000000..6dd9c0e32 --- /dev/null +++ b/src/com/android/launcher3/GelIntegrationHelper.java @@ -0,0 +1,100 @@ +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); + } + } + +} diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 8f5d9f0a2..913728bbd 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1291,14 +1291,15 @@ public class Workspace extends SmoothPagedView super.notifyPageSwitchListener(); Launcher.setScreen(getNextPage()); - if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) { + int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID); + if (hasCustomContent() && getNextPage() == ccIndex && !mCustomContentShowing) { mCustomContentShowing = true; if (mCustomContentCallbacks != null) { mCustomContentCallbacks.onShow(false); mCustomContentShowTime = System.currentTimeMillis(); mLauncher.updateVoiceButtonProxyVisible(false); } - } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) { + } else if (hasCustomContent() && getNextPage() != ccIndex && mCustomContentShowing) { mCustomContentShowing = false; if (mCustomContentCallbacks != null) { 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 // them 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 @@ -1836,6 +1852,8 @@ public class Workspace extends SmoothPagedView mWallpaperOffset.jumpToFinal(); } super.onLayout(changed, left, top, right, bottom); + + moveAwayFromCustomContentIfRequired(); } @Override @@ -4336,7 +4354,12 @@ public class Workspace extends SmoothPagedView } 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; } /** diff --git a/src/org/cyanogenmod/trebuchet/TrebuchetLauncher.java b/src/org/cyanogenmod/trebuchet/TrebuchetLauncher.java index 12e04cb16..ec91e10d7 100644 --- a/src/org/cyanogenmod/trebuchet/TrebuchetLauncher.java +++ b/src/org/cyanogenmod/trebuchet/TrebuchetLauncher.java @@ -38,11 +38,16 @@ import com.android.launcher3.R; import org.cyanogenmod.trebuchet.home.HomeUtils; import org.cyanogenmod.trebuchet.home.HomeWrapper; +import java.lang.Override; + public class TrebuchetLauncher extends Launcher { 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 final int mUid; @@ -112,7 +117,6 @@ public class TrebuchetLauncher extends Launcher { private CustomContentCallbacks mCustomContentCallbacks = new CustomContentCallbacks() { @Override public void onShow() { - updateQsbBarColorState(0); if (mCurrentHomeApp != null) { mCurrentHomeApp.mInstance.onShow(); } @@ -128,7 +132,6 @@ public class TrebuchetLauncher extends Launcher { @Override public void onHide() { - updateQsbBarColorState(255); if (mCurrentHomeApp != null) { mCurrentHomeApp.mInstance.onHide(); } @@ -153,7 +156,7 @@ public class TrebuchetLauncher extends Launcher { mQsbInitialAlphaState = res.getInteger(R.integer.qsb_initial_alpha_state); mQsbEndAlphaState = res.getInteger(R.integer.qsb_end_alpha_state); mQsbButtonsEndColorFilter = res.getInteger(R.integer.qsb_buttons_end_colorfilter); - updateQsbBarColorState(0); + updateQsbBarColorState(MIN_PROGRESS); // Obtain the user-defined Home app or a valid one obtainCurrentHomeAppStubLocked(true); @@ -195,7 +198,7 @@ public class TrebuchetLauncher extends Launcher { @Override protected boolean hasCustomContentToLeft() { - return mCurrentHomeApp != null; + return mCurrentHomeApp != null && super.hasCustomContentToLeft(); } @Override @@ -205,7 +208,7 @@ public class TrebuchetLauncher extends Launcher { } @Override - protected void addCustomContentToLeft() { + protected void populateCustomContentContainer() { if (mCurrentHomeApp != null) { mQsbScroller = addToCustomContentPage(mCurrentHomeApp.mInstance.createCustomView(), mCustomContentCallbacks, mCurrentHomeApp.mInstance.getName()); @@ -316,16 +319,12 @@ public class TrebuchetLauncher extends Launcher { if (voiceButton != null) { if (progress > 0) { voiceButton.setColorFilter(color, PorterDuff.Mode.SRC_IN); - } else { - voiceButton.clearColorFilter(); } } ImageView searchButton = getQsbBarSearchButton(); if (searchButton != null) { if (progress > 0) { searchButton.setColorFilter(color, PorterDuff.Mode.SRC_IN); - } else { - searchButton.clearColorFilter(); } } } |