blob: 6dd9c0e3276fb7ac6b90fef11aa01da3551de304 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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);
}
}
}
|