public void setMagnifiedRegionBorderShownLocked(boolean shown, boolean animate) {
   if (shown) {
     mFullRedrawNeeded = true;
     mOldMagnifiedBounds.set(0, 0, 0, 0);
   }
   mWindow.setShown(shown, animate);
 }
 public void setBounds(Region bounds) {
   synchronized (mWindowManagerService.mWindowMap) {
     if (mBounds.equals(bounds)) {
       return;
     }
     mBounds.set(bounds);
     invalidate(mDirtyRect);
     if (DEBUG_VIEWPORT_WINDOW) {
       Slog.i(LOG_TAG, "ViewportWindow set bounds: " + bounds);
     }
   }
 }
 /** Sets the touchable region of this popup to be the area occupied by its content. */
 private void setContentAreaAsTouchableSurface() {
   if (!mPopupWindow.isShowing()) {
     mContentContainer.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
   }
   int width = mContentContainer.getMeasuredWidth();
   int height = mContentContainer.getMeasuredHeight();
   mTouchableRegion.set(
       (int) mContentContainer.getX(),
       (int) mContentContainer.getY(),
       (int) mContentContainer.getX() + width,
       (int) mContentContainer.getY() + height);
 }
    public void recomputeBoundsLocked() {
      mWindowManager.getDefaultDisplay().getRealSize(mTempPoint);
      final int screenWidth = mTempPoint.x;
      final int screenHeight = mTempPoint.y;

      Region magnifiedBounds = mMagnifiedBounds;
      magnifiedBounds.set(0, 0, 0, 0);

      Region availableBounds = mTempRegion1;
      availableBounds.set(0, 0, screenWidth, screenHeight);

      Region nonMagnifiedBounds = mTempRegion4;
      nonMagnifiedBounds.set(0, 0, 0, 0);

      SparseArray<WindowStateInfo> visibleWindows = mTempWindowStateInfos;
      visibleWindows.clear();
      getWindowsOnScreenLocked(visibleWindows);

      final int visibleWindowCount = visibleWindows.size();
      for (int i = visibleWindowCount - 1; i >= 0; i--) {
        WindowStateInfo info = visibleWindows.valueAt(i);
        if (info.mWindowState.mAttrs.type
            == WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY) {
          continue;
        }

        Region windowBounds = mTempRegion2;
        Matrix matrix = mTempMatrix;
        populateTransformationMatrix(info.mWindowState, matrix);
        RectF windowFrame = mTempRectF;

        if (mWindowManagerService.mPolicy.canMagnifyWindow(info.mWindowState.mAttrs.type)) {
          windowFrame.set(info.mWindowState.mFrame);
          windowFrame.offset(-windowFrame.left, -windowFrame.top);
          matrix.mapRect(windowFrame);
          windowBounds.set(
              (int) windowFrame.left,
              (int) windowFrame.top,
              (int) windowFrame.right,
              (int) windowFrame.bottom);
          magnifiedBounds.op(windowBounds, Region.Op.UNION);
          magnifiedBounds.op(availableBounds, Region.Op.INTERSECT);
        } else {
          windowFrame.set(info.mTouchableRegion);
          windowFrame.offset(-info.mWindowState.mFrame.left, -info.mWindowState.mFrame.top);
          matrix.mapRect(windowFrame);
          windowBounds.set(
              (int) windowFrame.left,
              (int) windowFrame.top,
              (int) windowFrame.right,
              (int) windowFrame.bottom);
          nonMagnifiedBounds.op(windowBounds, Region.Op.UNION);
          windowBounds.op(magnifiedBounds, Region.Op.DIFFERENCE);
          availableBounds.op(windowBounds, Region.Op.DIFFERENCE);
        }

        Region accountedBounds = mTempRegion2;
        accountedBounds.set(magnifiedBounds);
        accountedBounds.op(nonMagnifiedBounds, Region.Op.UNION);
        accountedBounds.op(0, 0, screenWidth, screenHeight, Region.Op.INTERSECT);

        if (accountedBounds.isRect()) {
          Rect accountedFrame = mTempRect1;
          accountedBounds.getBounds(accountedFrame);
          if (accountedFrame.width() == screenWidth && accountedFrame.height() == screenHeight) {
            break;
          }
        }
      }

      for (int i = visibleWindowCount - 1; i >= 0; i--) {
        WindowStateInfo info = visibleWindows.valueAt(i);
        info.recycle();
        visibleWindows.removeAt(i);
      }

      magnifiedBounds.op(
          mHalfBorderWidth,
          mHalfBorderWidth,
          screenWidth - mHalfBorderWidth,
          screenHeight - mHalfBorderWidth,
          Region.Op.INTERSECT);

      if (!mOldMagnifiedBounds.equals(magnifiedBounds)) {
        Region bounds = Region.obtain();
        bounds.set(magnifiedBounds);
        mHandler
            .obtainMessage(MyHandler.MESSAGE_NOTIFY_MAGNIFIED_BOUNDS_CHANGED, bounds)
            .sendToTarget();

        mWindow.setBounds(magnifiedBounds);
        Rect dirtyRect = mTempRect1;
        if (mFullRedrawNeeded) {
          mFullRedrawNeeded = false;
          dirtyRect.set(
              mHalfBorderWidth,
              mHalfBorderWidth,
              screenWidth - mHalfBorderWidth,
              screenHeight - mHalfBorderWidth);
          mWindow.invalidate(dirtyRect);
        } else {
          Region dirtyRegion = mTempRegion3;
          dirtyRegion.set(magnifiedBounds);
          dirtyRegion.op(mOldMagnifiedBounds, Region.Op.UNION);
          dirtyRegion.op(nonMagnifiedBounds, Region.Op.INTERSECT);
          dirtyRegion.getBounds(dirtyRect);
          mWindow.invalidate(dirtyRect);
        }

        mOldMagnifiedBounds.set(magnifiedBounds);
      }
    }
Пример #5
0
  /**
   * Draw.
   *
   * @param canvas the canvas
   */
  public void draw(Canvas canvas) {
    if (mHidden) {
      return;
    }
    canvas.save();
    Path path = new Path();
    if (!hasFocus()) {
      mOutlinePaint.setColor(0xFF000000);
      canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
      Rect viewDrawingRect = new Rect();
      mContext.getDrawingRect(viewDrawingRect);
      if (mCircle) {
        float width = mDrawRect.width();
        float height = mDrawRect.height();
        path.addCircle(
            mDrawRect.left + (width / 2),
            mDrawRect.top + (height / 2),
            width / 2,
            Path.Direction.CW);
        mOutlinePaint.setColor(0xFFEF04D6);
      } else {
        path.addRect(new RectF(mDrawRect), Path.Direction.CW);
        mOutlinePaint.setColor(0xFFFF8A00);
      }
      Region region = new Region();
      region.set(viewDrawingRect);
      region.op(mDrawRect, Region.Op.DIFFERENCE);
      RegionIterator iter = new RegionIterator(region);
      Rect r = new Rect();
      while (iter.next(r)) {
        canvas.drawRect(r, hasFocus() ? mFocusPaint : mNoFocusPaint);
      }
      // android 4.0 Support bad.java.lang.UnsupportedOperationException
      // canvas.clipPath(path, Region.Op.DIFFERENCE);
      // canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

      canvas.restore();
      canvas.drawPath(path, mOutlinePaint);

      if (mMode == ModifyMode.Grow) {
        if (mCircle) {
          int width = mResizeDrawableDiagonal.getIntrinsicWidth();
          int height = mResizeDrawableDiagonal.getIntrinsicHeight();

          int d = (int) Math.round(Math.cos(/* 45deg */ Math.PI / 4D) * (mDrawRect.width() / 2D));
          int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
          int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
          mResizeDrawableDiagonal.setBounds(
              x,
              y,
              x + mResizeDrawableDiagonal.getIntrinsicWidth(),
              y + mResizeDrawableDiagonal.getIntrinsicHeight());
          mResizeDrawableDiagonal.draw(canvas);
        } else {
          //                    int left = mDrawRect.left + 1;
          //                    int right = mDrawRect.right + 1;
          //                    int top = mDrawRect.top + 4;
          //                    int bottom = mDrawRect.bottom + 3;
          //
          //                    int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
          //                    int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
          //                    int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
          //                    int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;
          //
          //                    int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) /
          // 2);
          //                    int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) /
          // 2);
          //
          //                    mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle -
          // widthHeight, left + widthWidth, yMiddle
          //                            + widthHeight);
          //                    mResizeDrawableWidth.draw(canvas);
          //
          //                    mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle -
          // widthHeight, right + widthWidth, yMiddle
          //                            + widthHeight);
          //                    mResizeDrawableWidth.draw(canvas);
          //
          //                    mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top -
          // heightHeight, xMiddle + heightWidth, top
          //                            + heightHeight);
          //                    mResizeDrawableHeight.draw(canvas);
          //
          //                    mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom -
          // heightHeight, xMiddle + heightWidth, bottom
          //                            + heightHeight);
          //                    mResizeDrawableHeight.draw(canvas);
        }
      }
      if (mCircle) {

      } else {
        int left = mDrawRect.left + 1;
        int right = mDrawRect.right + 1;
        int top = mDrawRect.top + 4;
        int bottom = mDrawRect.bottom + 3;

        int widthWidth = mResizeDrawableDiagonal.getIntrinsicWidth() / 2;
        int widthHeight = mResizeDrawableDiagonal.getIntrinsicHeight() / 2;

        mResizeDrawableDiagonal2.setBounds(
            left - widthWidth, top - widthHeight, left + widthWidth, top + widthHeight);
        mResizeDrawableDiagonal2.draw(canvas);
        mResizeDrawableDiagonal.setBounds(
            right - widthWidth, top - widthHeight, right + widthWidth, top + widthHeight);
        mResizeDrawableDiagonal.draw(canvas);
        mResizeDrawableDiagonal.setBounds(
            left - widthWidth, bottom - widthHeight, left + widthWidth, bottom + widthHeight);
        mResizeDrawableDiagonal.draw(canvas);
        mResizeDrawableDiagonal2.setBounds(
            right - widthWidth, bottom - widthHeight, right + widthWidth, bottom + widthHeight);
        mResizeDrawableDiagonal2.draw(canvas);
      }
    }
  }