Ejemplo n.º 1
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    View currentFocused = findFocus();
    if (null == currentFocused || this == currentFocused) return;

    // If the currently-focused view was visible on the screen when the
    // screen was at the old height, then scroll the screen to make that
    // view visible with the new screen height.
    if (isWithinDeltaOfScreenV(currentFocused, 0, oldh)) {
      currentFocused.getDrawingRect(mTempRect);
      offsetDescendantRectToMyCoords(currentFocused, mTempRect);
      int scrollDelta = computeScrollDeltaToGetChildRectOnScreenV(mTempRect);
      doScrollY(scrollDelta);
    }

    final int maxJump = getRight() - getLeft();
    if (isWithinDeltaOfScreenH(currentFocused, maxJump)) {
      currentFocused.getDrawingRect(mTempRect);
      offsetDescendantRectToMyCoords(currentFocused, mTempRect);
      int scrollDelta = computeScrollDeltaToGetChildRectOnScreenH(mTempRect);
      doScrollX(scrollDelta);
    }
  }
  protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
      outlinePaint.setColor(Color.BLACK);
      canvas.drawRect(drawRect, outlinePaint);
    } else {
      Rect viewDrawingRect = new Rect();
      viewContext.getDrawingRect(viewDrawingRect);

      path.addRect(new RectF(drawRect), Path.Direction.CW);
      outlinePaint.setColor(highlightColor);

      if (isClipPathSupported(canvas)) {
        canvas.clipPath(path, Region.Op.DIFFERENCE);
        canvas.drawRect(viewDrawingRect, outsidePaint);
      } else {
        drawOutsideFallback(canvas);
      }

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

      if (showThirds) {
        drawThirds(canvas);
      }

      if (handleMode == HandleMode.Always
          || (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
        drawHandles(canvas);
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * @return whether the descendant of this scroll view is within delta pixels of being on the
   *     screen.
   */
  private boolean isWithinDeltaOfScreen(View descendant, int delta, int height) {
    descendant.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(descendant, mTempRect);

    return (mTempRect.bottom + delta) >= getScrollY()
        && (mTempRect.top - delta) <= (getScrollY() + height);
  }
Ejemplo n.º 4
0
  private boolean isWithinDeltaOfScreenH(View descendant, int delta) {
    descendant.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(descendant, mTempRect);

    return (mTempRect.right + delta) >= getScrollX()
        && (mTempRect.left - delta) <= (getScrollX() + getWidth());
  }
  private void drawLeftIndicator(Canvas canvas) {
    if (mLeftActiveView != null && isViewDescendant(mLeftActiveView)) {
      Integer position = (Integer) mLeftActiveView.getTag(R.id.tplActiveViewPosition);
      final int pos = position == null ? 0 : position;

      if (pos == mLeftActivePosition) {

        mLeftActiveView.getDrawingRect(mLeftActiveRect);
        offsetDescendantRectToMyCoords(mLeftActiveView, mLeftActiveRect);

        if (mLeftIndicatorAnimating) {
          final int indicatorFinalTop =
              mLeftActiveRect.top
                  + ((mLeftActiveRect.height() - mLeftActiveIndicator.getHeight()) / 2);
          final int indicatorStartTop = mLeftIndicatorStartPos;
          final int diff = indicatorFinalTop - indicatorStartTop;
          final int startOffset = (int) (diff * mLeftIndicatorOffset);
          mLeftIndicatorTop = indicatorStartTop + startOffset;
        } else {
          mLeftIndicatorTop =
              mLeftActiveRect.top
                  + ((mLeftActiveRect.height() - mLeftActiveIndicator.getHeight()) / 2);
        }
        final int right = (int) (mMiddlePane.getLeft() + Math.floor(mMiddlePane.getTranslationX()));
        final int left = right - mLeftActiveIndicator.getWidth();

        canvas.save();
        canvas.clipRect(left, 0, right, getHeight());
        canvas.drawBitmap(mLeftActiveIndicator, left, mLeftIndicatorTop, null);
        canvas.restore();
      }
    }
  }
Ejemplo n.º 6
0
 private void scrollToChild(View var1) {
   var1.getDrawingRect(this.mTempRect);
   this.offsetDescendantRectToMyCoords(var1, this.mTempRect);
   int var2 = this.computeScrollDeltaToGetChildRectOnScreen(this.mTempRect);
   if (var2 != 0) {
     this.scrollBy(0, var2);
   }
 }
 @Override
 public void requestChildFocus(View child, View focused) {
   super.requestChildFocus(child, focused);
   if (child != null) {
     Rect r = new Rect();
     child.getDrawingRect(r);
     requestRectangleOnScreen(r);
   }
 }
Ejemplo n.º 8
0
 /**
  * Scrolls the view to the given child.
  *
  * @param child the View to scroll to
  */
 private void scrollToChild(View child) {
   child.getDrawingRect(mTempRect);
   /* Offset from child's local coordinates to TwoDScrollView coordinates */
   offsetDescendantRectToMyCoords(child, mTempRect);
   int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
   if (scrollDelta != 0) {
     scrollBy(0, scrollDelta);
   }
 }
Ejemplo n.º 9
0
 protected void onSizeChanged(int var1, int var2, int var3, int var4) {
   super.onSizeChanged(var1, var2, var3, var4);
   View var5 = this.findFocus();
   if (var5 != null && this != var5 && this.isWithinDeltaOfScreen(var5, 0, var4)) {
     var5.getDrawingRect(this.mTempRect);
     this.offsetDescendantRectToMyCoords(var5, this.mTempRect);
     this.doScrollY(this.computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
   }
 }
Ejemplo n.º 10
0
  public boolean arrowScroll(int var1) {
    boolean var7 = false;
    View var9 = this.findFocus();
    View var8 = var9;
    if (var9 == this) {
      var8 = null;
    }

    var9 = FocusFinder.getInstance().findNextFocus(this, var8, var1);
    int var4 = this.getMaxScrollAmount();
    if (var9 != null && this.isWithinDeltaOfScreen(var9, var4, this.getHeight())) {
      var9.getDrawingRect(this.mTempRect);
      this.offsetDescendantRectToMyCoords(var9, this.mTempRect);
      this.doScrollY(this.computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
      var9.requestFocus(var1);
    } else {
      int var2;
      if (var1 == 33 && this.getScrollY() < var4) {
        var2 = this.getScrollY();
      } else {
        var2 = var4;
        if (var1 == 130) {
          var2 = var4;
          if (this.getChildCount() > 0) {
            int var5 = this.getChildAt(0).getBottom();
            int var6 = this.getScrollY() + this.getHeight() - this.getPaddingBottom();
            var2 = var4;
            if (var5 - var6 < var4) {
              var2 = var5 - var6;
            }
          }
        }
      }

      if (var2 == 0) {
        return var7;
      }

      if (var1 != 130) {
        var2 = -var2;
      }

      this.doScrollY(var2);
    }

    if (var8 != null && var8.isFocused() && this.isOffScreen(var8)) {
      var1 = this.getDescendantFocusability();
      this.setDescendantFocusability(131072);
      this.requestFocus();
      this.setDescendantFocusability(var1);
    }

    var7 = true;
    return var7;
  }
Ejemplo n.º 11
0
  /**
   * Handle scrolling in response to an up or down arrow click.
   *
   * @param direction The direction corresponding to the arrow key that was pressed
   * @return True if we consumed the event, false otherwise
   */
  public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this) currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
      nextFocused.getDrawingRect(mTempRect);
      offsetDescendantRectToMyCoords(nextFocused, mTempRect);
      int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
      doScrollY(scrollDelta);
      nextFocused.requestFocus(direction);
    } else {
      // no new focus
      int scrollDelta = maxJump;

      if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
        scrollDelta = getScrollY();
      } else if (direction == View.FOCUS_DOWN) {
        if (getChildCount() > 0) {
          int daBottom = getChildAt(0).getBottom();

          int screenBottom = getScrollY() + getHeight();

          if (daBottom - screenBottom < maxJump) {
            scrollDelta = daBottom - screenBottom;
          }
        }
      }
      if (scrollDelta == 0) {
        return false;
      }
      doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
      // previously focused item still has focus and is off screen, give
      // it up (take it back to ourselves)
      // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we
      // are
      // sure to
      // get it)
      final int descendantFocusability = getDescendantFocusability(); // save
      setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
      requestFocus();
      setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
  }
Ejemplo n.º 12
0
  /**
   * Scrolls the view to the given child.
   *
   * @param child the View to scroll to
   */
  private void scrollToChild(View child) {
    child.getDrawingRect(mTempRect);

    /* Offset from child's local coordinates to ScrollView coordinates */
    offsetDescendantRectToMyCoords(child, mTempRect);

    int scrollDeltaV = computeScrollDeltaToGetChildRectOnScreenV(mTempRect);
    int scrollDeltaH = computeScrollDeltaToGetChildRectOnScreenH(mTempRect);

    if (scrollDeltaH != 0 || scrollDeltaV != 0) {
      scrollBy(scrollDeltaH, scrollDeltaV);
    }
  }
Ejemplo n.º 13
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    View currentFocused = findFocus();
    if (null == currentFocused || this == currentFocused) return;

    // If the currently-focused view was visible on the screen when the
    // screen was at the old height, then scroll the screen to make that
    // view visible with the new screen height.
    currentFocused.getDrawingRect(mTempRect);
    offsetDescendantRectToMyCoords(currentFocused, mTempRect);
    int scrollDeltaX = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    int scrollDeltaY = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
    doScroll(scrollDeltaX, scrollDeltaY);
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mDragListener != null || mDropListener != null) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          int itemnum = pointToPosition(x, y);
          if (itemnum == AdapterView.INVALID_POSITION) {
            break;
          }
          ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
          mDragPoint = y - item.getTop();
          mCoordOffset = ((int) ev.getRawY()) - y;
          View dragger = item.findViewById(R.id.grabber);
          Rect r = mTempRect;
          dragger.getDrawingRect(r);
          // The dragger icon itself is quite small, so pretend the
          // touch area is bigger
          if (x < r.right * 2) {
            // Fix x position while dragging
            int[] itemPos = new int[2];
            item.getLocationOnScreen(itemPos);

            item.setDrawingCacheEnabled(true);
            // Create a copy of the drawing cache so that it does
            // not get recycled
            // by the framework when the list tries to clean up
            // memory
            Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
            startDragging(bitmap, itemPos[0], y);
            mDragPos = itemnum;
            mFirstDragPos = mDragPos;
            mHeight = getHeight();
            int touchSlop = mTouchSlop;
            mUpperBound = Math.min(y - touchSlop, mHeight / 3);
            mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
            return false;
          }
          stopDragging();
          break;
      }
    }
    return super.onInterceptTouchEvent(ev);
  }
Ejemplo n.º 15
0
 @Override
 public void perform(UiController uiController, View view) {
   if (isDisplayingAtLeast(90).matches(view)) {
     Log.i(TAG, "View is already displayed. Returning.");
     return;
   }
   Rect rect = new Rect();
   view.getDrawingRect(rect);
   if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
     Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled.");
   }
   uiController.loopMainThreadUntilIdle();
   if (!isDisplayingAtLeast(90).matches(view)) {
     throw new PerformException.Builder()
         .withActionDescription(this.getDescription())
         .withViewDescription(HumanReadables.describe(view))
         .withCause(
             new RuntimeException(
                 "Scrolling to view was attempted, but the view is not displayed"))
         .build();
   }
 }
  private void drawMiddleIndicator(Canvas canvas) {
    if (mMiddleActiveView != null && isViewDescendant(mMiddleActiveView)) {
      Integer position = (Integer) mMiddleActiveView.getTag(R.id.tplActiveViewPosition);
      final int pos = position == null ? 0 : position;

      if (pos == mMiddleActivePosition) {

        mMiddleActiveView.getDrawingRect(mMiddleActiveRect);
        offsetDescendantRectToMyCoords(mMiddleActiveView, mMiddleActiveRect);

        final float interpolatedRatio =
            1.f - INDICATOR_INTERPOLATOR.getInterpolation(1.0f - mOffset);
        final int interpolatedWidth = (int) (mMiddleActiveIndicator.getWidth() * interpolatedRatio);

        if (mMiddleIndicatorAnimating) {
          final int indicatorFinalTop =
              mMiddleActiveRect.top
                  + ((mMiddleActiveRect.height() - mMiddleActiveIndicator.getHeight()) / 2);
          final int indicatorStartTop = mMiddleIndicatorStartPos;
          final int diff = indicatorFinalTop - indicatorStartTop;
          final int startOffset = (int) (diff * mMiddleIndicatorOffset);
          mMiddleIndicatorTop = indicatorStartTop + startOffset;
        } else {
          mMiddleIndicatorTop =
              mMiddleActiveRect.top
                  + ((mMiddleActiveRect.height() - mMiddleActiveIndicator.getHeight()) / 2);
        }
        final int right = (int) (mRightPane.getLeft() + mRightPane.getTranslationX());
        final int left = right - interpolatedWidth;

        canvas.save();
        canvas.clipRect(left, 0, right, getHeight());
        canvas.drawBitmap(mMiddleActiveIndicator, left, mMiddleIndicatorTop, null);
        canvas.restore();
      }
    }
  }
  /*
   * Use to signal that there's a portion of this view that wants to be
   * visible to the user on the screen. This method will place the sub
   * view on the screen, and will also place as much of this view as possible
   * on the screen. If this view is smaller than the viewable area available, it
   * will be fully visible in addition to the subview.
   */
  private void requestChildViewOnScreen(View child) {
    // Take focus so the user can be prepared to interact with this question, since
    // they will need to be fixing the input
    acceptFocus();

    // Get the rectangle that wants to put itself on the screen
    Rect vitalPortion = new Rect();
    child.getDrawingRect(vitalPortion);

    // Save a reference to it in case we have to manipulate it later.
    Rect vitalPortionSaved = new Rect();
    child.getDrawingRect(vitalPortionSaved);

    // Then get the bounding rectangle for this whole view.
    Rect wholeView = new Rect();
    this.getDrawingRect(wholeView);

    // If we don't know enough about the screen, just default to asking to see the
    // subview that was requested.
    if (mFrameHeight == -1) {
      child.requestRectangleOnScreen(vitalPortion);
      return;
    }

    // If the whole view fits, just request that we display the whole thing.
    if (wholeView.height() < mFrameHeight) {
      this.requestRectangleOnScreen(wholeView);
      return;
    }

    // The whole view will not fit, we need to scale down our requested focus.
    // Trying to construct the "ideal" rectangle here is actually pretty hard
    // but the base case is just to see if we can get the view onto the screen from
    // the bottom or the top

    int topY = wholeView.top;
    int bottomY = wholeView.bottom;

    // shrink the view to contain only the current frame size.
    wholeView.inset(0, (wholeView.height() - mFrameHeight) / 2);
    wholeView.offsetTo(wholeView.left, topY);

    // The view is now the size of the frame and anchored back at the top.

    // Now let's contextualize where the child view actually is in this frame.
    this.offsetDescendantRectToMyCoords(child, vitalPortion);

    // If the newly transformed view now contains the child portion, we're good
    if (wholeView.contains(vitalPortion)) {
      this.requestRectangleOnScreen(wholeView);
      return;
    }

    // otherwise, move to the requested frame to be at the bottom of this view
    wholeView.offsetTo(wholeView.left, bottomY - wholeView.height());

    // now see if the transformed view contains the vital portion
    if (wholeView.contains(vitalPortion)) {
      this.requestRectangleOnScreen(wholeView);
      return;
    }

    // Otherwise the child is hidden in the frame, so it won't matter which
    // we choose.
    child.requestRectangleOnScreen(vitalPortionSaved);
  }
Ejemplo n.º 18
0
  public boolean onTouch(View view, MotionEvent event) {
    float scale;
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        view.setBackgroundResource(R.drawable.border);
        garbage.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
        _xDelta = X - lParams.leftMargin;
        _yDelta = Y - lParams.topMargin;

        start.set(event.getX(), event.getY());
        mode = DRAG;
        break;
      case MotionEvent.ACTION_UP:
        Iterator<View> iterator;
        mode = NONE;
        garbage.setVisibility(View.INVISIBLE);
        view.setBackgroundResource(R.color.none);
        if (event.getRawY() > 1530) {
          if (position_status == FRONT) {
            iterator = ViewList.iterator();
          } else {
            iterator = ViewListBack.iterator();
          }
          view.setVisibility(View.GONE);

          while (iterator.hasNext()) {
            View i = iterator.next();
            if (i == view) {
              iterator.remove();
            }
          }
        }
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 8f) {
          RelativeLayout.LayoutParams zParams =
              (RelativeLayout.LayoutParams) view.getLayoutParams();
          midPoint(mid, event);
          _xDelta = (int) mid.x - zParams.leftMargin;
          _yDelta = (int) mid.y - zParams.topMargin;
          mode = ZOOM;
        }
        break;
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
      case MotionEvent.ACTION_MOVE:
        RelativeLayout.LayoutParams layoutParams =
            (RelativeLayout.LayoutParams) view.getLayoutParams();
        if (mode == DRAG) {
          layoutParams.leftMargin = X - _xDelta;
          layoutParams.topMargin = Y - _yDelta;
          layoutParams.rightMargin = -250;
          layoutParams.bottomMargin = -250;
          view.setLayoutParams(layoutParams);
          rectView = new Rect();
          view.getDrawingRect(rectView);
          if (event.getRawY() > 1530) {
            view.setBackgroundResource(R.color.deletecolor);
          } else view.setBackgroundResource(R.drawable.border);

        } else if (mode == ZOOM) {
          // pinch zooming
          float newDist = spacing(event);
          if (newDist > 8f) {
            // setting the scaling of the
            scale = newDist / oldDist;

            if (view instanceof ImageView) {
              int imgSizeH = view.getHeight();
              int imgSizeW = view.getWidth();
              imgSizeH = (int) (imgSizeH * scale);
              imgSizeW = (int) (imgSizeW * scale);
              layoutParams.width = imgSizeW;
              layoutParams.height = imgSizeH;
              layoutParams.leftMargin = (int) mid.x - _xDelta;
              layoutParams.topMargin = (int) mid.y - _yDelta;
              layoutParams.rightMargin = -250;
              layoutParams.bottomMargin = -250;
              view.setLayoutParams(layoutParams);

            } else if (view instanceof TextView) {
              // textSize = ((TextView) view).getTextSize();
              textSize = textSize * scale;
              ((TextView) view).setTextSize(textSize);
            }
            oldDist = newDist;
          }
        }
        break;
    }
    mRrootLayout.invalidate();
    return true;
  }
Ejemplo n.º 19
0
  protected 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);
      }
      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);
        }
      }
    }
  }
Ejemplo n.º 20
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);
      }
    }
  }
Ejemplo n.º 21
0
 private boolean isWithinDeltaOfScreen(View var1, int var2, int var3) {
   var1.getDrawingRect(this.mTempRect);
   this.offsetDescendantRectToMyCoords(var1, this.mTempRect);
   return this.mTempRect.bottom + var2 >= this.getScrollY()
       && this.mTempRect.top - var2 <= this.getScrollY() + var3;
 }
Ejemplo n.º 22
0
  /**
   * Handle scrolling in response to an up or down arrow click.
   *
   * @param direction The direction corresponding to the arrow key that was pressed
   * @return True if we consumed the event, false otherwise
   */
  public boolean arrowScroll(int direction, boolean horizontal) {
    View currentFocused = findFocus();
    if (currentFocused == this) currentFocused = null;
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    final int maxJump = horizontal ? getMaxScrollAmountHorizontal() : getMaxScrollAmountVertical();

    if (!horizontal) {
      if (nextFocused != null) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScroll(0, scrollDelta);
        nextFocused.requestFocus(direction);
      } else {
        // no new focus
        int scrollDelta = maxJump;
        if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
          scrollDelta = getScrollY();
        } else if (direction == View.FOCUS_DOWN) {
          if (getChildCount() > 0) {
            int daBottom = getChildAt(0).getBottom();
            int screenBottom = getScrollY() + getHeight();
            if (daBottom - screenBottom < maxJump) {
              scrollDelta = daBottom - screenBottom;
            }
          }
        }
        if (scrollDelta == 0) {
          return false;
        }
        doScroll(0, direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
      }
    } else {
      if (nextFocused != null) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScroll(scrollDelta, 0);
        nextFocused.requestFocus(direction);
      } else {
        // no new focus
        int scrollDelta = maxJump;
        if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
          scrollDelta = getScrollY();
        } else if (direction == View.FOCUS_DOWN) {
          if (getChildCount() > 0) {
            int daBottom = getChildAt(0).getBottom();
            int screenBottom = getScrollY() + getHeight();
            if (daBottom - screenBottom < maxJump) {
              scrollDelta = daBottom - screenBottom;
            }
          }
        }
        if (scrollDelta == 0) {
          return false;
        }
        doScroll(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta, 0);
      }
    }
    return true;
  }