@Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      if (child.getVisibility() != GONE) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        int childLeft = lp.x;
        int childTop = lp.y;
        child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);

        if (lp.dropped) {
          lp.dropped = false;

          final int[] cellXY = mTmpCellXY;
          getLocationOnScreen(cellXY);
          mWallpaperManager.sendWallpaperCommand(
              getWindowToken(),
              WallpaperManager.COMMAND_DROP,
              cellXY[0] + childLeft + lp.width / 2,
              cellXY[1] + childTop + lp.height / 2,
              0,
              null);
        }
      }
    }
  }
예제 #2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      xPos = event.getX();
      yPos = event.getY();
      // kill app if touched in bottom right corner
      if (xPos > mView.getWidth() - 50 && event.getY() > mView.getHeight() - 50) finish();
      else {
        mWPM.sendWallpaperCommand(
            mView.getWindowToken(),
            WallpaperManager.COMMAND_TAP,
            (int) xPos,
            (int) event.getY(),
            0,
            null);
      }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
      xWP = xWP + (xPos - event.getX()) / 500;
      xPos = event.getX();
      if (xWP < 0) xWP = 0;
      if (xWP > 1) xWP = 1;

      yWP = yWP + (yPos - event.getY()) / 500;
      yPos = event.getY();
      if (yWP < 0) yWP = 0;
      if (yWP > 1) yWP = 1;
      mWPM.setWallpaperOffsets(mView.getWindowToken(), xWP, yWP);
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
      mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
      Log.d("Cleaner", "Lights out");
    }

    return super.onTouchEvent(event);
  }