开发者

How to check when live wallpaper loses focus

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.hasW开发者_如何学运维indowFocus());
 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?


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜