表圈搭配Android的手势 [英] Bezel Gestures with Android

查看:138
本文介绍了表圈搭配Android的手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作的应用程序(在Galaxy Nexus的),我注意到,谷歌实施了谷歌现在,应用程序时,你从挡板底部向上滑动到屏幕(Chrome浏览器也这样做了同时,不知道这是否仍然如此)。我一直在四处寻找,但一直无法确定他们是如何做到了这一点。有一个简单的方法来处理,在面板而不是屏幕?

在开始手势

我检查的参考开发者页面,但我唯一能找到的文章在这里:

http://developer.android.com/design/patterns/gestures.html

还有其它地方在这个信息将可?

我一直很失败让边缘手势的工作基础上Lain_B的方法,但不能使它发挥作用。这里的code,我使用尝试检测手势,但logcat中总是输出零...

 公共类MainActivity扩展活动实现OnGestureListener {私人GestureDetector myGesture;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    myGesture =新GestureDetector(getBaseContext()
            (OnGestureListener)本);
}@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
    。getMenuInflater()膨胀(R.menu.activity_main,菜单);
    返回true;
}@覆盖
公共布尔onTouchEvent(MotionEvent事件){
    Log.e(旗触摸,标志:+ event.getEdgeFlags());
    返回myGesture.onTouchEvent(事件);
}@覆盖
公共布尔onDown(MotionEvent五){
    Log.e(标志,标志:+ e.getEdgeFlags());
    Log.e(事件,onDown);
    // TODO自动生成方法存根
    返回false;
}@覆盖
公共无效onLong preSS(MotionEvent五){
    Log.e(事件,onLong preSS);
    // TODO自动生成方法存根}@覆盖
公共无效昂秀preSS(MotionEvent五){
    Log.e(标志,标志:+ e.getEdgeFlags());
    Log.e(事件,昂秀preSS);
    // TODO自动生成方法存根}@覆盖
公共布尔onSingleTapUp(MotionEvent五){
    Log.e(事件,onSingleTapUp);
    // TODO自动生成方法存根
    返回false;
}@覆盖
公共布尔onScroll(MotionEvent E1,E2 MotionEvent,浮distanceX,
        浮动distanceY){
    // Log.e(事件,onScroll);
    返回false;
}//这些常数被用于onFling
私有静态最终诠释SWIPE_MIN_DISTANCE = 120;
私有静态最终诠释SWIPE_MAX_OFF_PATH = 250;
私有静态最终诠释SWIPE_THRESHOLD_VELOCITY = 200;@覆盖
公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,
        浮动velocityY){    Log.e(事件,onFling);
    Log.e(标志,标志:+ e1.getEdgeFlags());    如果(e1.getEdgeFlags()== MotionEvent.EDGE_LEFT){
        // code,以处理从左侧边缘滑动
        Log.e(!!!!!,边缘一扔!);
    }    尝试{
        //没有做任何事情,如果刷卡没有达到一定的长度
        距离//
        如果(Math.abs(e1.getY() - e2.getY())> SWIPE_MAX_OFF_PATH)
            返回false;        //从右向左轻扫
        如果(e1.getX() - e2.getX()> SWIPE_MIN_DISTANCE
                &功放;&安培; Math.abs(velocityX)LT; SWIPE_THRESHOLD_VELOCITY){        }
        //左到右轻扫
        否则如果(e2.getX() - e1.getX()> SWIPE_MIN_DISTANCE
                &功放;&安培; Math.abs(velocityX)LT; SWIPE_THRESHOLD_VELOCITY){        }
    }赶上(例外五){
        //什么
    }
    返回false;}
}

使用Lain_B的请求的输出...

(使用的Nexus 7)...从最远可以点左侧挡板上的开始,右滑动到中间(ISH)。

  08-16 16:44:13.674:I /一扔(16702):标志:0
08-16 16:44:13.674:I /一扔(16702):E1:2.5 711.5152
08-16 16:44:13.674:I /一扔(16702):E2:215.4591 717.08105

从屏幕的中心点刷卡,关闭屏幕(向右侧)

  08-16 16:46:37.364:I /一扔(16702):标志:0
08-16 16:46:37.364:I /一扔(16702):E1:392.5 758.1818
08-16 16:46:37.364:I /一扔(16702):E2:783.4375 743.3334


解决方案

我想的 MotionEvent.getEdgeFlags()是你在找什么。然后,您可以比较 EDGE_LEFT ,EDGE_RIGHT,等返回值看哪个边缘被感动了。

 如果(event1.getEdgeFlags()及!MotionEvent.EDGE_LEFT = 0){
    // code,以处理从左侧边缘滑动
}

 如果(e1.getX()< 5.0F){
    //从左侧边缘滑动手柄
}

I'm working on an application (on a Galaxy Nexus), and I noticed that Google implemented the "Google Now" application when you swipe from the bottom of the bezel onto the screen (the chrome browser also did this for a while, not sure if it still does). I've been looking around but have been unable to determine how they accomplished this. Is there an easy way to handle gestures that begin in the bezel 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 would be available?

[Edit]

I've been trying very unsuccessfully to get edge gestures working based on Lain_B's method, but cannot make it work. Here's the code that I'm using to try and detect the gestures, but logcat is always outputting a 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");
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onLongPress(MotionEvent e) {
    Log.e("Event", "onLongPress");
    // TODO Auto-generated method stub

}

@Override
public void onShowPress(MotionEvent e) {
    Log.e("Flags", "Flags: " + e.getEdgeFlags());
    Log.e("Event", "onShowPress");
    // TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    Log.e("Event", "onSingleTapUp");
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    // Log.e("Event", "onScroll");
    return false;
}

// these constants are used for onFling
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) {
        // code to handle swipe from left edge
        Log.e("!!!!!", "Edge fling!");
    }

    try {
        // do not do anything if the swipe does not reach a certain length
        // of distance
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
            return false;

        // right to left swipe
        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {

        }
        // left to right swipe
        else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {

        }
    } catch (Exception e) {
        // nothing
    }
    return false;

}
}

[Edit 2]

With Lain_B's requested output...

(Using Nexus 7)... Starting from farthest possible left point on the bezel, and swiping right 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

Swiping from the center point of the screen, off the screen (to the right side)

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

解决方案

I think MotionEvent.getEdgeFlags() is what you're looking for. You can then compare the returned value with EDGE_LEFT , EDGE_RIGHT , etc to see which edge was touched.

if( event1.getEdgeFlags()&MotionEvent.EDGE_LEFT != 0 ){
    //code to handle swipe from left edge
}

or

if( e1.getX() < 5.0f ){
    //handle swipe from left edge
}

这篇关于表圈搭配Android的手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆