I’m working on an application (on Galaxy Nexus), and I noticed that Google has implemented the Google Now application when you scroll from the bottom of the panel to the screen (the Chrome browser also did this for a while, not sure if it still does ) I searched around, but could not determine how they did it. Is there an easy way to handle gestures that start in a frame rather than on the screen?
I checked the developer pages for reference, but the only article I could find was here:
http://developer.android.com/design/patterns/gestures.html
Is there anywhere else where this information will be available?
[edit]
I tried very unsuccessfully to process gestures based on the Lain_B method, but I cannot get it to work. Here is the code I use to try to detect gestures, but logcat always outputs zero ...
public class MainActivity extends Activity implements OnGestureListener {
private GestureDetector myGesture;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myGesture = new GestureDetector(getBaseContext(),
(OnGestureListener) this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.e("Flags Touch", "Flags: " + event.getEdgeFlags());
return myGesture.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
Log.e("Flags", "Flags: " + e.getEdgeFlags());
Log.e("Event", "onDown");
return false;
}
@Override
public void onLongPress(MotionEvent e) {
Log.e("Event", "onLongPress");
}
@Override
public void onShowPress(MotionEvent e) {
Log.e("Flags", "Flags: " + e.getEdgeFlags());
Log.e("Event", "onShowPress");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.e("Event", "onSingleTapUp");
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.e("Event", "onFling");
Log.e("Flags", "Flags: " + e1.getEdgeFlags());
if (e1.getEdgeFlags() == MotionEvent.EDGE_LEFT) {
Log.e("!!!!!", "Edge fling!");
}
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
}
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
}
} catch (Exception e) {
}
return false;
}
}
[Edit 2]
With the request Lain_B ...
(using Nexus 7) ... Starting from the maximum possible left point on the panel and scrolling straight to the middle (ish).
08-16 16:44:13.674: I/Fling(16702): Flags: 0
08-16 16:44:13.674: I/Fling(16702): e1: 2.5 711.5152
08-16 16:44:13.674: I/Fling(16702): e2: 215.4591 717.08105
Scrolling from the center point of the screen, from the screen (to the right)
08-16 16:46:37.364: I/Fling(16702): Flags: 0
08-16 16:46:37.364: I/Fling(16702): e1: 392.5 758.1818
08-16 16:46:37.364: I/Fling(16702): e2: 783.4375 743.3334