如何检查动态壁纸何时失去焦点

发布于 2024-11-07 03:11:59 字数 930 浏览 4 评论 0原文

我有一个使用振动权限的动态壁纸。当显示所有应用程序的幻灯片屏幕被拉出时...(单击时显示日历/计算器/Gmail等的灰色矩形按钮),单击时幻灯片屏幕上的图标也会显示Gmail/日历/计算器等颤动。我想知道为什么会发生这种情况,因为壁纸应该失去焦点,它的可见性应该改变,因此壁纸不应该处于活动状态。但是,当应用程序开始运行时,这种情况不会发生。它仅发生在幻灯片屏幕上。我已经实现了OnvisibilityChanged()

 public void onVisibilityChanged(boolean visible) {
     this.visible = visible;
     if (visible) {
        iteration();
        drawFrame();
     } else {
        // stop the animation
        mHandler.removeCallbacks(mIteration);
     }
  }

this.visibleonSurfaceDestroyed 中设置为 false。

我也这样做了

View view = new View(getApplicationContext());
view.setFocusableInTouchMode(true);
view.setEnabled(true);
view.requestFocusFromTouch();
if(view.hasWindowFocus())
{
 Log.v(TAG,"WindowFocus="+view.hasWindowFocus());
 vibrator.vibrate(100);
}

,但 view.hasWindowFocus 始终为 false。为什么这个窗口焦点总是错误的,如何让壁纸失去焦点?

I have a live wallpaper that uses vibrate permission. When the slide screen that shows all applications is pulled out... (the grey rectangular button which on clicking shows calendar/calculator/Gmail, etc.), the icons on the slide screen like Gmail/calendar/calculator etc. when clicked also vibrate. I wonder why that should happen, since the wallpaper should lose focus, its visibility should have changed and hence the wallpaper should not be active. However, this does not happen when the application starts running. It happens only on the slide screen. I have implemented OnvisibilityChanged().

 public void onVisibilityChanged(boolean visible) {
     this.visible = visible;
     if (visible) {
        iteration();
        drawFrame();
     } else {
        // stop the animation
        mHandler.removeCallbacks(mIteration);
     }
  }

this.visible is set to false in onSurfaceDestroyed.

I have also done

View view = new View(getApplicationContext());
view.setFocusableInTouchMode(true);
view.setEnabled(true);
view.requestFocusFromTouch();
if(view.hasWindowFocus())
{
 Log.v(TAG,"WindowFocus="+view.hasWindowFocus());
 vibrator.vibrate(100);
}

but view.hasWindowFocus is always false. Why is this window focus always false and how can I make the wallpaper lose focus?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过气美图社 2024-11-14 03:11:59

有几件事......
1) 您无法在动态壁纸中以这种方式处理视图。您必须将自己限制在从holder.lockCanvas()获取的画布上。
2) 听起来您与启动器的交互似乎很奇怪。这些事情都会发生。如果您只是处理简单的屏幕点击,您可能可以通过使用 onCommand() 检查 android.wallpaper.tap 而不是使用 onTouchEvent() 来解决您的问题。这是更好的做法,因为您只会收到对壁纸中可用空间的点击;否则,您还将获得由启动器处理的屏幕按下。这里有一些关于 onCommand 的信息: http://developer.android.com/resources /articles/live-wallpapers.html
例如这样的事情......

@Override
public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) {
    if (action.equals(WallpaperManager.COMMAND_TAP)) {
          mTouchX = x;
          mTouchY = y;
    }
    return super.onCommand(action, x, y, z, extras, resultRequested);
}

A couple of things...
1) You cannot work with views that way within live wallpaper. You must limit yourself to the canvas you get from holder.lockCanvas().
2) It sounds like you're getting a weird interaction with the launcher. These things happen. If you are just processing simple screen taps, you can probably work around your issue by using onCommand() to check for android.wallpaper.tap instead of using onTouchEvent(). That's better practice, because you will only get sent taps on free spaces in the wallpaper; otherwise you will also get screen presses that are processed by the launcher. There's a little info about onCommand here: http://developer.android.com/resources/articles/live-wallpapers.html
For instance something like this...

@Override
public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) {
    if (action.equals(WallpaperManager.COMMAND_TAP)) {
          mTouchX = x;
          mTouchY = y;
    }
    return super.onCommand(action, x, y, z, extras, resultRequested);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文