Android动态壁纸如何实现双击?
我想为 Android 动态壁纸实现双击事件。 遗憾的是,我找不到任何具体的代码来实现这一点。
目前,我找到了使用 Engine 类的 onTouchEvent 方法的解决方法:
public void onTouchEvent(MotionEvent event) {
long time = android.os.SystemClock.currentThreadTimeMillis();
if(((time - mLastTouchTime) < 500) && ((time - mLastTouchTime) > 100))
{
if(!mIsPlayed && mSound)
{
mIsPlayed = true;
int sound = R.raw.hell;
if(mTheme.equals("rose"))
sound = R.raw.rose;
if(mTheme.equals("greed"))
sound = R.raw.greed;
MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound);
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
mIsPlayed = false;
}
});
}
}
mLastTouchTime = time;
super.onTouchEvent(event);
}
嗯,这不是一个优雅的解决方案。我知道有些壁纸实现了双击。但我不知道如何自己做。
因此,朝正确的方向“点击”会很好。如果有必要,我会接受“双击”。 :D
你好, 罗伯特
I want to implement a double tap event for a Android live wallpaper.
Sadly, I couldn´t find any specific code how to do that.
At the moment I´ve found a workarround using the onTouchEvent-method of the Engine-class:
public void onTouchEvent(MotionEvent event) {
long time = android.os.SystemClock.currentThreadTimeMillis();
if(((time - mLastTouchTime) < 500) && ((time - mLastTouchTime) > 100))
{
if(!mIsPlayed && mSound)
{
mIsPlayed = true;
int sound = R.raw.hell;
if(mTheme.equals("rose"))
sound = R.raw.rose;
if(mTheme.equals("greed"))
sound = R.raw.greed;
MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound);
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
mIsPlayed = false;
}
});
}
}
mLastTouchTime = time;
super.onTouchEvent(event);
}
Well, that´s not an elegant solution. I know there are wallpapers which implemented the double tap. But I have no idea, how to do it on my own.
So a "tap" in the right direction would be nice. If nescessary, I will accept a "double tap". :D
Greetings,
Robert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 http://developer.android.com/reference/android/view/GestureDetector。例如
:
Use http://developer.android.com/reference/android/view/GestureDetector.html
for example: