summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Garnes <matt@cyngn.com>2014-01-23 08:56:37 -0800
committerAbhisek Devkota <ciwrl@cyanogenmod.com>2014-06-12 16:33:16 -0700
commit44d180199b36f1ff17edbc7c0c68c0a0298f78f4 (patch)
treee57c09184ef03b8df8a571e247af8a0ba54adf4e /src
parent9d9a1c05734ba45d117748b28de366c4c345d858 (diff)
downloadandroid_packages_apps_Trebuchet-44d180199b36f1ff17edbc7c0c68c0a0298f78f4.tar.gz
android_packages_apps_Trebuchet-44d180199b36f1ff17edbc7c0c68c0a0298f78f4.tar.bz2
android_packages_apps_Trebuchet-44d180199b36f1ff17edbc7c0c68c0a0298f78f4.zip
GEL Integration (2/2)
Launch search from extra panel to mimic Google Launcher. Changed Trebuchet to build against CM instead of the AOSP SDK. Added support to swipe left from the home screen to enter Google Now, if it is installed. A right swipe will return the user to the home screen. Change-Id: Ia1a77fedea7e67bcd54a6b6d66099f8366d6b1dc
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/DragLayer.java2
-rw-r--r--src/com/android/launcher3/GelIntegrationHelper.java100
-rw-r--r--src/com/android/launcher3/Launcher.java50
-rw-r--r--src/com/android/launcher3/OverviewSettingsPanel.java32
-rw-r--r--src/com/android/launcher3/Workspace.java53
-rw-r--r--src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java32
-rw-r--r--src/com/android/launcher3/settings/SettingsProvider.java1
7 files changed, 252 insertions, 18 deletions
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java
index b832494a2..3ff4293af 100644
--- a/src/com/android/launcher3/DragLayer.java
+++ b/src/com/android/launcher3/DragLayer.java
@@ -814,7 +814,7 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
/**
* Note: this is a reimplementation of View.isLayoutRtl() since that is currently hidden api.
*/
- private boolean isLayoutRtl() {
+ public boolean isLayoutRtl() {
return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
}
diff --git a/src/com/android/launcher3/GelIntegrationHelper.java b/src/com/android/launcher3/GelIntegrationHelper.java
new file mode 100644
index 000000000..abda537a2
--- /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);
+ homeIntent.addCategory(Intent.CATEGORY_HOME);
+ launcherActivity.startActivity(homeIntent);
+ launcherActivity.overridePendingTransition(0, R.anim.exit_out_left);
+ 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/Launcher.java b/src/com/android/launcher3/Launcher.java
index 1209355ea..d30cde45b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -241,6 +241,8 @@ public class Launcher extends Activity
private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
private static int NEW_APPS_ANIMATION_DELAY = 500;
+ private boolean mGelIntegrationEnabled = false;
+
private final BroadcastReceiver mCloseSystemDialogsReceiver
= new CloseSystemDialogsIntentReceiver();
private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
@@ -484,6 +486,8 @@ public class Launcher extends Activity
mSavedState = savedInstanceState;
restoreState(mSavedState);
+ restoreGelSetting();
+
if (PROFILE_STARTUP) {
android.os.Debug.stopMethodTracing();
}
@@ -531,6 +535,12 @@ public class Launcher extends Activity
"cyanogenmod.permission.PROTECTED_APP", null);
}
+ public void restoreGelSetting() {
+ mGelIntegrationEnabled = SettingsProvider.getBoolean(this,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH_SCREEN_LEFT,
+ R.bool.preferences_interface_homescreen_search_screen_left_default);
+ }
+
private void initializeDynamicGrid() {
LauncherAppState.setApplicationContext(getApplicationContext());
LauncherAppState app = LauncherAppState.getInstance();
@@ -539,6 +549,8 @@ public class Launcher extends Activity
SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
R.bool.preferences_interface_homescreen_hide_icon_labels_default);
+ restoreGelSetting();
+
// Determine the dynamic grid properties
Point smallestSize = new Point();
Point largestSize = new Point();
@@ -565,13 +577,41 @@ public class Launcher extends Activity
sPausedFromUserAction = true;
}
- /** To be overriden by subclasses to hint to Launcher that we have custom content */
+ /** To be overridden by subclasses to hint to Launcher that we have custom content */
protected boolean hasCustomContentToLeft() {
- return false;
+ return isGelIntegrationSupported() && isGelIntegrationEnabled();
+ }
+
+ public boolean isGelIntegrationSupported() {
+ final SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
+
+ // Currently the only custom content available is the GEL launcher integration,
+ // only supported on CyanogenMod.
+ return globalSearchActivity != null && isCM();
+ }
+
+ public boolean isGelIntegrationEnabled() {
+ return mGelIntegrationEnabled;
+ }
+
+ public void onCustomContentLaunch() {
+ if(isGelIntegrationEnabled() && isGelIntegrationSupported()) {
+ GelIntegrationHelper.getInstance().registerSwipeBackGestureListenerAndStartGel(this);
+ }
}
/**
- * To be overridden by subclasses to populate the custom content container and call
+ * Check if the device running this application is running CyanogenMod.
+ * @return true if this device is running CM.
+ */
+ protected boolean isCM() {
+ return getPackageManager().hasSystemFeature("com.cyanogenmod.android");
+ }
+
+ /**
+ * To be overridden by subclasses to create the custom content and call
* {@link #addToCustomContentPage}. This will only be invoked if
* {@link #hasCustomContentToLeft()} is {@code true}.
*/
@@ -1001,6 +1041,10 @@ public class Launcher extends Activity
}
super.onResume();
+ if(isGelIntegrationEnabled() && isGelIntegrationSupported()) {
+ GelIntegrationHelper.getInstance().handleGelResume();
+ }
+
// Restore the previous launcher state
if (mOnResumeState == State.WORKSPACE) {
showWorkspace(false);
diff --git a/src/com/android/launcher3/OverviewSettingsPanel.java b/src/com/android/launcher3/OverviewSettingsPanel.java
index fd8095f87..e3fbfa3ed 100644
--- a/src/com/android/launcher3/OverviewSettingsPanel.java
+++ b/src/com/android/launcher3/OverviewSettingsPanel.java
@@ -24,6 +24,7 @@ public class OverviewSettingsPanel {
private View mOverviewPanel;
private SettingsPinnedHeaderAdapter mSettingsAdapter;
private PinnedHeaderListView mListView;
+ private String[] mValues;
OverviewSettingsPanel(Launcher launcher, View overviewPanel) {
mLauncher = launcher;
@@ -40,11 +41,25 @@ public class OverviewSettingsPanel {
String[] headers = new String[] {
res.getString(R.string.home_screen_settings),
res.getString(R.string.drawer_settings)};
- String[] values = new String[] {
- res.getString(R.string.home_screen_search_text),
- res.getString(R.string.scroll_effect_text),
- res.getString(R.string.larger_icons_text),
- res.getString(R.string.hide_icon_labels)};
+
+ String[] values;
+ if(mLauncher.isGelIntegrationSupported()) {
+ values = new String[]{
+ res.getString(R.string.home_screen_search_text),
+ res.getString(R.string.search_screen_left_text),
+ res.getString(R.string.scroll_effect_text),
+ res.getString(R.string.larger_icons_text),
+ res.getString(R.string.hide_icon_labels)};
+ } else {
+ values = new String[]{
+ res.getString(R.string.home_screen_search_text),
+ res.getString(R.string.scroll_effect_text),
+ res.getString(R.string.larger_icons_text),
+ res.getString(R.string.hide_icon_labels)};
+ }
+
+ mValues = values;
+
String[] valuesDrawer = new String[] {
res.getString(R.string.scroll_effect_text),
res.getString(R.string.drawer_sorting_text),
@@ -162,13 +177,8 @@ public class OverviewSettingsPanel {
mSettingsAdapter.changeCursor(0, createCursor(res
.getString(R.string.home_screen_settings), new String[]{}));
} else {
- String[] values = new String[] {
- res.getString(R.string.home_screen_search_text),
- res.getString(R.string.scroll_effect_text),
- res.getString(R.string.larger_icons_text),
- res.getString(R.string.hide_icon_labels)};
mSettingsAdapter.changeCursor(0, createCursor(res
- .getString(R.string.home_screen_settings), values));
+ .getString(R.string.home_screen_settings), mValues));
}
// Make sure overview panel is drawn above apps customize and collapsed
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index bba10a118..a5a1f5460 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1257,12 +1257,13 @@ public class Workspace extends SmoothPagedView
if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) {
mCustomContentShowing = true;
+
if (mCustomContentCallbacks != null) {
mCustomContentCallbacks.onShow();
mCustomContentShowTime = System.currentTimeMillis();
mLauncher.updateVoiceButtonProxyVisible(false);
}
- } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) {
+ } else if (hasCustomContent() && mCustomContentShowing) {
mCustomContentShowing = false;
if (mCustomContentCallbacks != null) {
mCustomContentCallbacks.onHide();
@@ -1296,6 +1297,22 @@ public class Workspace extends SmoothPagedView
snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION, r);
}
+ @Override
+ protected void snapToPage(int whichPage, int delta, int duration, boolean immediate,
+ TimeInterpolator interpolator) {
+ super.snapToPage(whichPage, delta, duration, immediate, interpolator);
+
+ // Trigger onCustomContentLaunch if we have just snapped to the custom page.
+ int customPageIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID);
+ if (hasCustomContent() && whichPage == customPageIndex && !mCustomContentShowing) {
+ if(!isInOverviewMode()) {
+ mCustomContentShowing = true;
+ // Start Google Now and register the gesture to return to Trebuchet
+ mLauncher.onCustomContentLaunch();
+ }
+ }
+ }
+
protected void snapToPage(int whichPage, int duration, Runnable r) {
if (mDelayedSnapToPageRunnable != null) {
mDelayedSnapToPageRunnable.run();
@@ -1379,6 +1396,7 @@ public class Workspace extends SmoothPagedView
int firstIndex = numCustomPages();
// Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages)
int lastIndex = getChildCount() - 1 - emptyExtraPages;
+
if (isLayoutRtl()) {
int temp = firstIndex;
firstIndex = lastIndex;
@@ -1619,7 +1637,13 @@ public class Workspace extends SmoothPagedView
}
public int numCustomPages() {
- return hasCustomContent() ? 1 : 0;
+ // GEL integration is a special case (not a *real* screen) and should
+ // not be counted as custom content.
+ if(mLauncher.isGelIntegrationEnabled()) {
+ return 0;
+ } else {
+ return hasCustomContent() ? 1 : 0;
+ }
}
public boolean isOnOrMovingToCustomContent() {
@@ -1801,6 +1825,16 @@ public class Workspace extends SmoothPagedView
// Force the wallpaper offset steps to be set again, because another app might have changed
// them
mLastSetWallpaperOffsetSteps = 0f;
+
+ // 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
@@ -2082,6 +2116,11 @@ public class Workspace extends SmoothPagedView
int start = numCustomPages();
int end = getChildCount() - 1;
+ // For GEL integration, do not include the first page (GEL)
+ if(mLauncher.isGelIntegrationEnabled()) {
+ start += 1;
+ }
+
range[0] = Math.max(0, Math.min(start, getChildCount() - 1));
range[1] = Math.max(0, end);
}
@@ -4811,7 +4850,15 @@ public class Workspace extends SmoothPagedView
}
void moveToDefaultScreen(boolean animate) {
- moveToScreen(getPageIndexForScreenId(mDefaultScreenId), animate);
+ // Do not use the custom page or index -1 as default,
+ // if GEL integration is enabled.
+ int idx = getPageIndexForScreenId(mDefaultScreenId);
+ int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID);
+ if(hasCustomContent() && (idx == ccIndex || idx == -1)
+ && mLauncher.isGelIntegrationEnabled()) {
+ idx = 1;
+ }
+ moveToScreen(idx, animate);
}
void moveToCustomContentScreen(boolean animate) {
diff --git a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
index 499995375..f096ee0cb 100644
--- a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
+++ b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
@@ -10,6 +10,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
import com.android.launcher3.Launcher;
import com.android.launcher3.OverviewSettingsPanel;
import com.android.launcher3.PagedView;
@@ -119,6 +120,17 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
R.string.setting_state_on) : res.getString(
R.string.setting_state_off);
((TextView) v.findViewById(R.id.item_state)).setText(state);
+ } else if (title.equals(res
+ .getString(R.string.search_screen_left_text))) {
+ boolean current = SettingsProvider
+ .getBoolean(
+ mContext,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH_SCREEN_LEFT,
+ R.bool.preferences_interface_homescreen_search_screen_left_default);
+ String state = current ? res.getString(
+ R.string.setting_state_on) : res.getString(
+ R.string.setting_state_off);
+ ((TextView) v.findViewById(R.id.item_state)).setText(state);
}
v.setTag(partition);
@@ -228,6 +240,26 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
intent.setClassName(OverviewSettingsPanel.ANDROID_SETTINGS,
OverviewSettingsPanel.ANDROID_PROTECTED_APPS);
mLauncher.startActivity(intent);
+ } else if (value.equals(res
+ .getString(R.string.search_screen_left_text)) &&
+ ((Integer)v.getTag() == OverviewSettingsPanel.HOME_SETTINGS_POSITION)) {
+
+ boolean current = SettingsProvider.getBoolean(mContext,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH_SCREEN_LEFT,
+ R.bool.preferences_interface_homescreen_search_screen_left_default);
+
+ // If GEL integration is not supported, do not allow the user to turn it on.
+ if(!current && !mLauncher.isGelIntegrationSupported()) {
+ Toast.makeText(mLauncher.getApplicationContext(),
+ res.getString(R.string.preferences_search_screen_left_unsupported_toast),
+ Toast.LENGTH_SHORT).show();
+ } else {
+ onSettingsBooleanChanged(
+ v,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH_SCREEN_LEFT,
+ R.bool.preferences_interface_homescreen_search_screen_left_default);
+ mLauncher.updateDynamicGrid();
+ }
}
View defaultHome = mLauncher.findViewById(R.id.default_home_screen_panel);
diff --git a/src/com/android/launcher3/settings/SettingsProvider.java b/src/com/android/launcher3/settings/SettingsProvider.java
index 5be13a44d..de1d4002e 100644
--- a/src/com/android/launcher3/settings/SettingsProvider.java
+++ b/src/com/android/launcher3/settings/SettingsProvider.java
@@ -26,6 +26,7 @@ public final class SettingsProvider {
public static final String SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID = "ui_homescreen_default_screen_id";
public static final String SETTINGS_UI_HOMESCREEN_SEARCH = "ui_homescreen_search";
+ public static final String SETTINGS_UI_HOMESCREEN_SEARCH_SCREEN_LEFT = "ui_homescreen_search_screen_left";
public static final String SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS = "ui_homescreen_general_hide_icon_labels";
public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_TRANSITION_EFFECT = "ui_homescreen_scrolling_transition_effect";
public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_WALLPAPER_SCROLL = "ui_homescreen_scrolling_wallpaper_scroll";