拍摄图片onTouch在X秒 [英] taking a picture with onTouch on X seconds

查看:153
本文介绍了拍摄图片onTouch在X秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我想太感谢来这里的唐`吨知道怎么样了第一。
其次,我是相对较新至Android编程,现在做这行约2周。

First of all I want to Thank SO for being here for the don`t Know hows. Second, I am relative new to android programing and doing this for about 2 weeks now.

确定我的问题:

我真的写一个应用程序,你有,当你在屏幕上点击以ttake图片。
我设法做到这一点,但在应用程序的稍后阶段,您可以在现场摄像机视图通过更多的则1画布上滚动。
所以图片不能是当你点击屏幕上的人走,但是当你的秒X数量后点击并按住屏幕也一定要把pucture。

I`m Writing an app where you have to ttake a picture when you tap on the screen. I managed to do that, but in a later stage of the app you can scroll through more then 1 canvas in the live camera view. So the picture must not be taking when you tap ones on the screen, but when you touch and hold the screen after an X amount of seconds it must take the pucture.

所以,如果你是通过你不采取瞬间的图像画布滚动你打在屏幕上。

so that if you are scrolling through the canvases you dont take the picture on the moment you hit the screen.

如果试图注册在 ACTION_DOWN 事件中的当前时间,它与当前时间比较+ 5000(毫秒)
有没有关于如何实现这一目标的任何建议吗?

if tried to register the current time on the ACTION_DOWN event and compare it with the current time + 5000 (miliseconds) are there any sugestions on how to achieve this ?

亲切的问候


     公共布尔onTouchEvent(MotionEvent事件)
        {
         如果(event.getAction()== MotionEvent.ACTION_DOWN)
        {
            长activateTime = System.currentTimeMillis的();

public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { long activateTime = System.currentTimeMillis();

if(event.getAction() == MotionEvent.ACTION_DOWN && activateTime + 5000 == System.currentTimeMillis())
    {
        takePicture();
    }
}
return false;
};

编辑!
这个来源$ C ​​$ C对我来说是关键的。

EDIT! this source code was the key for me.

public class GestureDemo extends Activity implements OnGestureListener {

private GestureDetector gestureDetector;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

gestureDetector = new GestureDetector(this);

}

@Override

public boolean onTouchEvent(MotionEvent event) {

return gestureDetector.onTouchEvent(event);

}

@Override

public boolean onDown(MotionEvent e) {

Toast.makeText(this,"oNDown called",Toast.LENGTH_SHORT).show();

return false;

}

@Override

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

Toast.makeText(this,"oNFling called",Toast.LENGTH_SHORT).show();
return false;

}

@Override

public void onLongPress(MotionEvent e) {

Toast.makeText(this,"OnLongPress called",Toast.LENGTH_SHORT).show();

}

@Override

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,

float distanceY) {

Toast.makeText(this,"onScroll called",Toast.LENGTH_SHORT).show();

return false;

}

@Override
public void onShowPress(MotionEvent e) {

Toast.makeText(this,"onShowPress called",Toast.LENGTH_SHORT).show();

}

@Override

public boolean onSingleTapUp(MotionEvent e) {

Toast.makeText(this,"oNsingleTap called",Toast.LENGTH_SHORT).show();

return false;
}

</code>

继承人在那里我找到了链接 code

感谢您会指着我在正确的deriction。

Thank you will for pointing me in the right deriction.

推荐答案

的方式一些Android组件(如的 GestureDetector )做这件事,他们使用处理器来发送延迟的消息。因此,例如,在ACTION_DOWN事件中,你可以调用<一个href=\"http://developer.android.com/reference/android/os/Handler.html#sendEmptyMessageDelayed%28int,%20long%29\"相对=nofollow> sendEmptyMessageDelayed(INT什么,长delayMillis),并在ACTION_UP事件调用的 removeMessages(INT什么)。如果事件被传递,这意味着一个ACTION_UP从来没有发生过,这意味着用户的手指仍下跌。这忽略了用户走动有手指,虽然。所以,你会设置了坡面积,并检查他们的每ACTION_MOVE离开它。当用户的手指离开坡区域,那么您需要取消的消息。

The way some android components(such as GestureDetector) do it, is they use a Handler to send delayed messages. So for example, on a ACTION_DOWN event you could call sendEmptyMessageDelayed(int what, long delayMillis), and on ACTION_UP event call removeMessages(int what). If the event is delivered, that means a ACTION_UP never happened, which means the users finger is still down. This ignores the user moving there finger around, though. So you would have set up 'slop' area, and check if they left it with every ACTION_MOVE. Upon the users finger leaving the slop area, you would then cancel the message.

您可以阅读GestureDetector源$ C ​​$ C <一个href=\"http://www.google.com/$c$csearch#cZwlSNS7aEw/frameworks/base/core/java/android/view/GestureDetector.java&exact_package=android&q=GestureDetector&type=cs\"相对=nofollow>这里,看看他们是如何做到的。

You can read the GestureDetector source code here to see how they did it.

这篇关于拍摄图片onTouch在X秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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