@Override
 public void drawBitmap(
     final Bitmap bitmap, final Rect src, final Rect dst, final SafePaint paint) {
   dst.offset(xOffset, yOffset);
   getWrappedCanvas().drawBitmap(bitmap, src, dst, paint);
   dst.offset(-xOffset, -yOffset);
 }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    // TODO: handle vertical labels
    if (isEnabled() && mLabelLayout != null) {
      final int sweepHeight = mSweep.getIntrinsicHeight();
      final int templateHeight = mLabelLayout.getHeight();

      mSweepOffset.x = 0;
      mSweepOffset.y = 0;
      mSweepOffset.y = (int) ((templateHeight / 2) - getTargetInset());
      setMeasuredDimension(mSweep.getIntrinsicWidth(), Math.max(sweepHeight, templateHeight));

    } else {
      mSweepOffset.x = 0;
      mSweepOffset.y = 0;
      setMeasuredDimension(mSweep.getIntrinsicWidth(), mSweep.getIntrinsicHeight());
    }

    if (mFollowAxis == VERTICAL) {
      final int targetHeight =
          mSweep.getIntrinsicHeight() - mSweepPadding.top - mSweepPadding.bottom;
      mMargins.top = -(mSweepPadding.top + (targetHeight / 2));
      mMargins.bottom = 0;
      mMargins.left = -mSweepPadding.left;
      mMargins.right = mSweepPadding.right;
    } else {
      final int targetWidth = mSweep.getIntrinsicWidth() - mSweepPadding.left - mSweepPadding.right;
      mMargins.left = -(mSweepPadding.left + (targetWidth / 2));
      mMargins.right = 0;
      mMargins.top = -mSweepPadding.top;
      mMargins.bottom = mSweepPadding.bottom;
    }

    mContentOffset.set(0, 0, 0, 0);

    // make touch target area larger
    final int widthBefore = getMeasuredWidth();
    final int heightBefore = getMeasuredHeight();
    if (mFollowAxis == HORIZONTAL) {
      final int widthAfter = widthBefore * 3;
      setMeasuredDimension(widthAfter, heightBefore);
      mContentOffset.left = (widthAfter - widthBefore) / 2;

      final int offset = mSweepPadding.bottom * 2;
      mContentOffset.bottom -= offset;
      mMargins.bottom += offset;
    } else {
      final int heightAfter = heightBefore * 2;
      setMeasuredDimension(widthBefore, heightAfter);
      mContentOffset.offset(0, (heightAfter - heightBefore) / 2);

      final int offset = mSweepPadding.right * 2;
      mContentOffset.right -= offset;
      mMargins.right += offset;
    }

    mSweepOffset.offset(mContentOffset.left, mContentOffset.top);
    mMargins.offset(-mSweepOffset.x, -mSweepOffset.y);
  }
Ejemplo n.º 3
0
  private void initCells() {
    class _calendar {
      public int day;
      public boolean thisMonth;

      public _calendar(int d, boolean b) {
        day = d;
        thisMonth = b;
      }

      public _calendar(int d) {
        this(d, false);
      }
    };
    _calendar tmp[][] = new _calendar[6][7];

    for (int i = 0; i < tmp.length; i++) {
      int n[] = mHelper.getDigitsForRow(i);
      for (int d = 0; d < n.length; d++) {
        if (mHelper.isWithinCurrentMonth(i, d)) tmp[i][d] = new _calendar(n[d], true);
        else tmp[i][d] = new _calendar(n[d]);
      }
    }

    Calendar today = Calendar.getInstance();
    int thisDay = 0;
    mToday = null;
    if (mHelper.getYear() == today.get(Calendar.YEAR)
        && mHelper.getMonth() == today.get(Calendar.MONTH)) {
      thisDay = today.get(Calendar.DAY_OF_MONTH);
    }
    // build cells
    Rect Bound =
        new Rect(
            CELL_MARGIN_LEFT,
            CELL_MARGIN_TOP,
            CELL_WIDTH + CELL_MARGIN_LEFT,
            CELL_HEIGH + CELL_MARGIN_TOP);
    for (int week = 0; week < mCells.length; week++) {
      for (int day = 0; day < mCells[week].length; day++) {
        if (tmp[week][day].thisMonth) {
          if (day == 0 || day == 6)
            mCells[week][day] = new RedCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE);
          else mCells[week][day] = new Cell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE);
        } else
          mCells[week][day] = new GrayCell(tmp[week][day].day, new Rect(Bound), CELL_TEXT_SIZE);

        Bound.offset(CELL_WIDTH, 0); // move to next column

        // get today
        if (tmp[week][day].day == thisDay && tmp[week][day].thisMonth) {
          mToday = mCells[week][day];
          mDecoration.setBounds(mToday.getBound());
        }
      }
      Bound.offset(0, CELL_HEIGH); // move to next row and first column
      Bound.left = CELL_MARGIN_LEFT;
      Bound.right = CELL_MARGIN_LEFT + CELL_WIDTH;
    }
  }
Ejemplo n.º 4
0
 public static void scaleRectAboutCenter(Rect r, float scale) {
   int cx = r.centerX();
   int cy = r.centerY();
   r.offset(-cx, -cy);
   Utilities.scaleRect(r, scale);
   r.offset(cx, cy);
 }
  private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    final Rect r = mRectTemp;

    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i = 0; i < count; i++) {
      final DropTarget target = dropTargets.get(i);
      target.getHitRect(r);
      target.getLocationOnScreen(dropCoordinates);
      r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
      if (r.contains(x, y)) {
        dropCoordinates[0] = x - dropCoordinates[0];
        dropCoordinates[1] = y - dropCoordinates[1];
        return target;
      }
    }

    // Check for default hit if all others failed
    final DropTarget target = mDefaultDrop;
    target.getHitRect(r);
    target.getLocationOnScreen(dropCoordinates);
    r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
    if (r.contains(x, y)) {
      dropCoordinates[0] = x - dropCoordinates[0];
      dropCoordinates[1] = y - dropCoordinates[1];
      return target;
    }

    return null;
  }
Ejemplo n.º 6
0
    public void move(int s) {
      int dx = (int) Math.abs(mRect.centerX() - destination);

      if (destination < mRect.centerX()) {
        mRect.offset((dx > s) ? -s : -dx, 0);
        slaveMover(s, dx, s, dx);

      } else if (destination > mRect.centerX()) {
        mRect.offset((dx > s) ? s : dx, 0);
        slaveMover(s, dx, -s, -dx);
      }
    }
Ejemplo n.º 7
0
  private void drawSurface(Bitmap bmp) {
    if (bmp != null) {
      Rect srcRect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
      Rect dstRect = new Rect(0, 0, sv.getWidth(), sv.getHeight());
      int ew = bmp.getWidth() * sv.getHeight() / bmp.getHeight();
      if (ew < bmp.getWidth()) {
        dstRect.right = ew;
        dstRect.bottom = bmp.getHeight() * ew / bmp.getWidth();
      }
      int dx = (sv.getWidth() - dstRect.right) >> 1;
      int dy = (sv.getHeight() - dstRect.bottom) >> 1;
      dstRect.offset(dx, dy);

      synchronized (sh) {
        Log.d(TAG, "Start drawing bmp");
        Canvas canvas = sh.lockCanvas();
        if (canvas != null) {
          canvas.drawColor(Color.BLACK);
          canvas.drawBitmap(bmp, srcRect, dstRect, null);
          sh.unlockCanvasAndPost(canvas);
        }
        Log.d(TAG, "Stop bmp");
      }
    }
  }
Ejemplo n.º 8
0
  protected Rect getIconRect(int viewWidth, int viewHeight, int drawableWidth, int drawableHeight) {
    DragLayer dragLayer = mLauncher.getDragLayer();

    // Find the rect to animate to (the view is center aligned)
    Rect to = new Rect();
    dragLayer.getViewRectRelativeToSelf(this, to);

    final int width = drawableWidth;
    final int height = drawableHeight;

    final int left;
    final int right;

    if (Utilities.isRtl(getResources())) {
      right = to.right - getPaddingRight();
      left = right - width;
    } else {
      left = to.left + getPaddingLeft();
      right = left + width;
    }

    final int top = to.top + (getMeasuredHeight() - height) / 2;
    final int bottom = top + height;

    to.set(left, top, right, bottom);

    // Center the destination rect about the trash icon
    final int xOffset = (int) -(viewWidth - width) / 2;
    final int yOffset = (int) -(viewHeight - height) / 2;
    to.offset(xOffset, yOffset);

    return to;
  }
    @Override
    public void onChildDraw(
        Canvas c,
        RecyclerView recyclerView,
        RecyclerView.ViewHolder viewHolder,
        float dX,
        float dY,
        int actionState,
        boolean isCurrentlyActive) {
      super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
      // swipeRefresh cancels swiping left/right when accidentally moving in the y direction;
      swipeRefresh.setEnabled(!isCurrentlyActive);
      if (isCurrentlyActive) {
        Rect viewRect = new Rect();
        viewHolder.itemView.getDrawingRect(viewRect);
        float fractionMoved = Math.abs(dX / viewHolder.itemView.getMeasuredWidth());
        Drawable drawable;
        if (dX < 0) {
          drawable = markAsReadDrawable;
          viewRect.left = (int) dX + viewRect.right;
        } else {
          drawable = starredDrawable;
          viewRect.right = (int) dX - viewRect.left;
        }

        if (fractionMoved > getSwipeThreshold(viewHolder))
          drawable.setState(new int[] {android.R.attr.state_above_anchor});
        else drawable.setState(new int[] {-android.R.attr.state_above_anchor});

        viewRect.offset(0, viewHolder.itemView.getTop());
        drawable.setBounds(viewRect);
        drawable.draw(c);
      }
    }
 @Override
 public Rect getPosition(int index) {
   Rect rect = mSlotView.getSlotRect(index);
   Rect bounds = mSlotView.bounds();
   rect.offset(bounds.left - mSlotView.getScrollX(), bounds.top - mSlotView.getScrollY());
   return rect;
 }
Ejemplo n.º 11
0
  @Override
  public void onItemClick(MainEntity entity, int position) {

    View target;
    if (position == 0) {
      target =
          gridLayoutManager
              .findViewByPosition(position)
              .findViewById(R.id.list_item_header_temp_iv);
    } else {
      target =
          gridLayoutManager.findViewByPosition(position).findViewById(R.id.list_item_grid_temp_iv);
    }

    Rect startBounds = new Rect();
    target.getGlobalVisibleRect(startBounds);

    if (globalOffset == null) {
      globalOffset = new Point();
      Rect rootRect = new Rect();
      rootView.getGlobalVisibleRect(rootRect, globalOffset);
    }
    startBounds.offset(-globalOffset.x, -globalOffset.y);

    if (this.rxBus == null) {
      this.rxBus = MyApplication.get().getRxBus();
    }
    this.rxBus.postStickEvent(entity);

    DetailActivity.navigateToDetail(ListActivity.this, startBounds, globalOffset);
    overridePendingTransition(0, 0);
  }
Ejemplo n.º 12
0
  @Override
  public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
    // offset into coordinate space of this scroll view
    rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());

    return scrollToChildRect(rectangle, immediate);
  }
Ejemplo n.º 13
0
    @Override
    public boolean onInterceptTouchEvent(View view, MotionEvent event) {
      // We need to account for scroll state for the touched view otherwise
      // tapping on an "empty" part of the view will still be considered a
      // valid touch event.
      if (view.getScrollX() != 0 || view.getScrollY() != 0) {
        Rect rect = new Rect();
        view.getHitRect(rect);
        rect.offset(-view.getScrollX(), -view.getScrollY());

        int[] viewCoords = new int[2];
        view.getLocationOnScreen(viewCoords);

        int x = (int) event.getRawX() - viewCoords[0];
        int y = (int) event.getRawY() - viewCoords[1];

        if (!rect.contains(x, y)) return false;
      }

      // If the tab tray is showing, hide the tab tray and don't send the event to content.
      if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
        mIsHidingTabs = true;
        return true;
      }
      return false;
    }
  private Bitmap getShiftedBitmap(Bitmap bitmap, int shiftX) {
    Bitmap newBitmap =
        Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas newBitmapCanvas = new Canvas(newBitmap);

    Rect srcRect1 = new Rect(shiftX, 0, bitmap.getWidth(), bitmap.getHeight());
    Rect destRect1 = new Rect(srcRect1);
    destRect1.offset(-shiftX, 0);
    newBitmapCanvas.drawBitmap(bitmap, srcRect1, destRect1, null);

    Rect srcRect2 = new Rect(0, 0, shiftX, bitmap.getHeight());
    Rect destRect2 = new Rect(srcRect2);
    destRect2.offset(bitmap.getWidth() - shiftX, 0);
    newBitmapCanvas.drawBitmap(bitmap, srcRect2, destRect2, null);

    return newBitmap;
  }
 @Override
 public boolean getClipBounds(final Rect bounds) {
   boolean success = getWrappedCanvas().getClipBounds(bounds);
   if (bounds != null) {
     bounds.offset(-xOffset, -yOffset);
   }
   return success;
 }
Ejemplo n.º 16
0
  /** This returns the coordinates of an app in a given cell, relative to the DragLayer */
  Rect getCellCoordinates(int cellX, int cellY) {
    Rect coords = new Rect();
    mContent.cellToRect(cellX, cellY, 1, 1, coords);
    int[] hotseatInParent = new int[2];
    Utilities.getDescendantCoordRelativeToParent(
        this, mLauncher.getDragLayer(), hotseatInParent, false);
    coords.offset(hotseatInParent[0], hotseatInParent[1]);

    // Center the icon
    int cWidth = mContent.getShortcutsAndWidgets().getCellContentWidth();
    int cHeight = mContent.getShortcutsAndWidgets().getCellContentHeight();
    int cellPaddingX = (int) Math.max(0, ((coords.width() - cWidth) / 2f));
    int cellPaddingY = (int) Math.max(0, ((coords.height() - cHeight) / 2f));
    coords.offset(cellPaddingX, cellPaddingY);

    return coords;
  }
Ejemplo n.º 17
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mInnerRectF.set(0, 0, canvas.getWidth(), canvas.getHeight());
    final int halfBorder = (int) (mStrokePaint.getStrokeWidth() / 2f + 0.5f);
    mInnerRectF.inset(halfBorder, halfBorder);

    canvas.drawArc(mInnerRectF, 0, 360, true, mBackgroundPaint);

    switch (mProgressFillType) {
      case FILL_TYPE_RADIAL:
        float sweepAngle = 360 * mProgress / mMax;
        canvas.drawArc(mInnerRectF, mStartAngle, sweepAngle, true, mProgressPaint);
        break;
      case FILL_TYPE_CENTER:
        float centerX = canvas.getWidth() / 2;
        float centerY = canvas.getHeight() / 2;
        float radius = (canvas.getWidth() / 2) * ((float) mProgress / mMax);
        canvas.drawCircle(
            centerX, centerY, radius + 0.5f - mStrokePaint.getStrokeWidth(), mProgressPaint);
        break;
      default:
        throw new IllegalArgumentException("Invalid Progress Fill = " + mProgressFillType);
    }

    if (!TextUtils.isEmpty(mText) && mShowText) {
      if (!TextUtils.isEmpty(mTypeface)) {
        Typeface typeface = sTypefaceCache.get(mTypeface);
        if (null == typeface && null != getResources()) {
          AssetManager assets = getResources().getAssets();
          if (null != assets) {
            typeface = Typeface.createFromAsset(assets, mTypeface);
            sTypefaceCache.put(mTypeface, typeface);
          }
        }
        mTextPaint.setTypeface(typeface);
      }
      int xPos = canvas.getWidth() / 2;
      int yPos =
          (int) ((canvas.getHeight() / 2) - ((mTextPaint.descent() + mTextPaint.ascent()) / 2));
      canvas.drawText(mText, xPos, yPos, mTextPaint);
    }

    if (null != mImage && mShowImage) {
      int drawableSize = mImage.getIntrinsicWidth();
      mImageRect.set(0, 0, drawableSize, drawableSize);
      mImageRect.offset((getWidth() - drawableSize) / 2, (getHeight() - drawableSize) / 2);
      mImage.setBounds(mImageRect);
      mImage.draw(canvas);
    }

    if (mShowStroke) {
      canvas.drawOval(mInnerRectF, mStrokePaint);
    }
  }
Ejemplo n.º 18
0
  public GLPicture(BitmapRegionLoader bitmapRegionLoader, int maxHeight) {
    if (bitmapRegionLoader == null || maxHeight == 0) {
      return;
    }

    mHasContent = true;
    mVertexBuffer = GLUtil.newFloatBuffer(mVertices.length);
    mTextureCoordsBuffer = GLUtil.asFloatBuffer(SQUARE_TEXTURE_VERTICES);

    int originalWidth = bitmapRegionLoader.getWidth();
    int originalHeight = bitmapRegionLoader.getHeight();
    int sampleSize = 1;
    while (originalHeight / (sampleSize << 1) > maxHeight) {
      sampleSize <<= 1;
    }

    mWidth = originalWidth / sampleSize;
    mHeight = originalHeight / sampleSize;

    mTileSize = Math.min(512, sMaxTextureSize);
    int unsampledTileSize = mTileSize * sampleSize;
    int leftoverHeight = originalHeight % unsampledTileSize;

    // Load m x n textures
    mCols = mWidth / (mTileSize + 1) + 1;
    mRows = mHeight / (mTileSize + 1) + 1;

    mTextureHandles = new int[mCols * mRows];

    Bitmap tileBitmap = Bitmap.createBitmap(mTileSize, mTileSize, Bitmap.Config.ARGB_8888);
    Rect rect = new Rect();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;
    options.inBitmap = tileBitmap;
    for (int y = 0; y < mRows; y++) {
      for (int x = 0; x < mCols; x++) {
        rect.set(
            x * unsampledTileSize,
            (mRows - y - 1) * unsampledTileSize,
            (x + 1) * unsampledTileSize,
            (mRows - y) * unsampledTileSize);
        // The bottom tiles must be full tiles for drawing, so only allow edge tiles
        // at the top
        if (leftoverHeight > 0) {
          rect.offset(0, -unsampledTileSize + leftoverHeight);
        }
        rect.intersect(0, 0, originalWidth, originalHeight);
        Bitmap useBitmap = bitmapRegionLoader.decodeRegion(rect, options);
        mTextureHandles[y * mCols + x] = GLUtil.loadTexture(useBitmap);
        if (useBitmap != tileBitmap) {
          useBitmap.recycle();
        }
      }
    }
  }
Ejemplo n.º 19
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // prevent ray cast of touch events to actions container
    getHitRect(mHitRect);
    mHitRect.offset(-getScrollX(), -getScrollY());
    if (mHitRect.contains((int) event.getX(), (int) event.getY())) {
      return true;
    }

    return super.onTouchEvent(event);
  }
Ejemplo n.º 20
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (userLocation == null || !userLocation.hasAccuracy() || displayState == null) {
      return;
    }
    // Figure out distance from user location to screen center point
    float[] mapLonLat = displayState.getScreenCenterGeoLocation();
    screenCenterLocation.setLatitude(mapLonLat[1]);
    screenCenterLocation.setLongitude(mapLonLat[0]);
    int distanceM = Math.round(userLocation.distanceTo(screenCenterLocation));
    int accuracyM = Math.round(userLocation.getAccuracy());

    // Don't draw if centered
    if (distanceM == 0) {
      return;
    }

    // Format the distance and accuracy nicely
    String distanceStr;
    if (PreferenceStore.instance(getContext()).isMetric()) {
      distanceStr = getMetricDistanceString(distanceM, accuracyM);
    } else {
      distanceStr = getEnglishDistanceString(distanceM, accuracyM);
    }

    // Compute the pixel size of the distanceStr
    // -- set font size based on canvas density (dpi)
    textPaint.setTextSize(ptsToPixels(textSizePt, canvas));
    Rect distanceBox = new Rect();
    textPaint.getTextBounds(distanceStr, 0, distanceStr.length(), distanceBox);
    distanceBox.offsetTo(0, 0);
    int padding = Math.round(ptsToPixels(paddingPt, canvas));
    distanceBox.right += 2 * padding;
    distanceBox.bottom += 2 * padding;
    distanceBox.offset((getWidth() - distanceBox.width()) / 2, getHeight() - distanceBox.height());
    float baseline = distanceBox.bottom - padding;
    backgroundPaint.setAlpha(192);
    backgroundPaint.setStyle(Paint.Style.FILL);
    textPaint.setStrokeWidth(1f);
    textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    canvas.drawRoundRect(new RectF(distanceBox), padding, padding, backgroundPaint);
    canvas.drawText(distanceStr, distanceBox.exactCenterX(), baseline, textPaint);

    // Draw center circles
    int x = getWidth() / 2;
    int y = getHeight() / 2;
    backgroundPaint.setAlpha(255);
    backgroundPaint.setStyle(Paint.Style.STROKE);
    textPaint.setStrokeWidth(2f);
    textPaint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(x, y, 5, backgroundPaint);
    canvas.drawCircle(x, y, 5, textPaint);
  }
Ejemplo n.º 21
0
  /**
   * Adjusts a drawable's bounds so that (0,0) is a pixel in the location described by the hotspot
   * parameter. Useful for "pin"-like graphics. For convenience, returns the same drawable that was
   * passed in.
   *
   * @param marker the drawable to adjust
   * @param hotspot the hotspot for the drawable
   * @return the same drawable that was passed in.
   */
  protected synchronized Drawable boundToHotspot(final Drawable marker, HotspotPlace hotspot) {
    final int markerWidth = marker.getIntrinsicWidth();
    final int markerHeight = marker.getIntrinsicHeight();

    mRect.set(0, 0, 0 + markerWidth, 0 + markerHeight);

    if (hotspot == null) {
      hotspot = HotspotPlace.BOTTOM_CENTER;
    }

    switch (hotspot) {
      default:
      case NONE:
        break;
      case CENTER:
        mRect.offset(-markerWidth / 2, -markerHeight / 2);
        break;
      case BOTTOM_CENTER:
        mRect.offset(-markerWidth / 2, -markerHeight);
        break;
      case TOP_CENTER:
        mRect.offset(-markerWidth / 2, 0);
        break;
      case RIGHT_CENTER:
        mRect.offset(-markerWidth, -markerHeight / 2);
        break;
      case LEFT_CENTER:
        mRect.offset(0, -markerHeight / 2);
        break;
      case UPPER_RIGHT_CORNER:
        mRect.offset(-markerWidth, 0);
        break;
      case LOWER_RIGHT_CORNER:
        mRect.offset(-markerWidth, -markerHeight);
        break;
      case UPPER_LEFT_CORNER:
        mRect.offset(0, 0);
        break;
      case LOWER_LEFT_CORNER:
        mRect.offset(0, -markerHeight);
        break;
    }
    marker.setBounds(mRect);
    return marker;
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mRect == null) {
      mRect = new Rect(0, 0, SIZE, SIZE);
      int left = (canvas.getWidth() - SIZE) / 2;
      int top = (canvas.getHeight() - SIZE) / 2;
      mRect.offset(left, top);
    }

    canvas.drawRect(mRect, PAINT);
  }
Ejemplo n.º 23
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getAction();
   float newX = event.getX(), newY = event.getY();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       if (ballRect.contains((int) newX, (int) newY)) {
         initX = newX;
         initY = newY;
         move = true;
       } else {
         move = false;
       }
       break;
     case MotionEvent.ACTION_MOVE:
       if (move) {
         ballRect.offset((int) (newX - initX), (int) (newY - initY));
         initX = newX;
         initY = newY;
         if ((!rect.contains(ballRect) && !rect2.contains(ballRect))
             && !conRect.contains(ballRect)) {
           move = false;
           ballRect.offsetTo(ballRectX, ballRectY);
           Toast.makeText(mContext, "out of bounds", Toast.LENGTH_SHORT).show();
         } else if (ballRect.contains(goal.centerX(), goal.centerY())) {
           ballRect.offset(-30, 0);
           Toast.makeText(mContext, "Congratulations\n Get UP!", Toast.LENGTH_SHORT).show();
           AlarmDialog.vibrator.cancel();
           ((Activity) getContext()).finish();
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       ballRect.offsetTo(ballRectX, ballRectY);
       break;
   }
   return (true);
 }
Ejemplo n.º 24
0
  public boolean getScaleFinalBounds(int position) {
    GridView gridView = ((MainActivity) mContext).gridView;
    View childView = gridView.getChildAt(position);

    startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    try {
      childView.getGlobalVisibleRect(startBounds);
    } catch (Exception e) {
      return false;
    }
    ((Activity) mContext)
        .findViewById(R.id.container)
        .getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    if ((float) finalBounds.width() / finalBounds.height()
        > (float) startBounds.width() / startBounds.height()) {
      // Extend start bounds horizontally
      startScale = (float) startBounds.height() / finalBounds.height();
      float startWidth = startScale * finalBounds.width();
      float deltaWidth = (startWidth - startBounds.width()) / 2;
      startBounds.left -= deltaWidth;
      startBounds.right += deltaWidth;
    } else {
      // Extend start bounds vertically
      startScale = (float) startBounds.width() / finalBounds.width();
      float startHeight = startScale * finalBounds.height();
      float deltaHeight = (startHeight - startBounds.height()) / 2;
      startBounds.top -= deltaHeight;
      startBounds.bottom += deltaHeight;
    }
    startScaleFinal = startScale;
    return true;
  }
Ejemplo n.º 25
0
  public Ball(Context context, int canvasWidth, int canvasHeight) {
    size = (int) su.levenetc.android.interactivecanvas.samples.utils.Utils.dpToPx(context, 50);
    fillPaint.setColor(Color.CYAN);
    fillPaint.setStyle(Paint.Style.FILL);
    fillPaint.setAntiAlias(true);

    bounds.set(0, 0, size, size);
    bounds.offset(canvasHeight / 2, canvasHeight / 2);

    for (int i = 0; i < tail.length; i++) tail[i] = new Rect(bounds);

    vector.set(
        (float) Math.random() * (Math.random() > 0.5f ? 1 : -1),
        (float) Math.random() * (Math.random() > 0.5f ? 1 : -1));
  }
  private AccessibilityNodeInfoCompat populateNodeForItemInternal(
      T item, AccessibilityNodeInfoCompat node) {
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    node.setEnabled(true);

    // Allow the client to populate the node.
    populateNodeForItem(item, node);

    if (TextUtils.isEmpty(node.getText()) && TextUtils.isEmpty(node.getContentDescription())) {
      throw new RuntimeException(
          "You must add text or a content description in populateNodeForItem()");
    }

    // Don't allow the client to override these properties.
    node.setPackageName(mParentView.getContext().getPackageName());
    node.setClassName(item.getClass().getName());
    node.setParent(mParentView);
    node.setSource(mParentView, virtualDescendantId);

    if (mFocusedItemId == virtualDescendantId) {
      node.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
      node.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }

    node.getBoundsInParent(mTempParentRect);
    if (mTempParentRect.isEmpty()) {
      throw new RuntimeException("You must set parent bounds in populateNodeForItem()");
    }

    // Set the visibility based on the parent bound.
    if (intersectVisibleToUser(mTempParentRect)) {
      node.setVisibleToUser(true);
      node.setBoundsInParent(mTempParentRect);
    }

    // Calculate screen-relative bound.
    mParentView.getLocationOnScreen(mTempGlobalRect);
    final int offsetX = mTempGlobalRect[0];
    final int offsetY = mTempGlobalRect[1];
    mTempScreenRect.set(mTempParentRect);
    mTempScreenRect.offset(offsetX, offsetY);
    node.setBoundsInScreen(mTempScreenRect);

    return node;
  }
  private Rect getChildViewRect(View parentView, View childView) {
    final Rect childRect =
        new Rect(
            childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom());
    if (parentView == childView) {
      return childRect;
    }

    ViewGroup parent;
    while ((parent = (ViewGroup) childView.getParent()) != parentView) {
      childRect.offset(parent.getLeft(), parent.getTop());
      childView = parent;
    }

    return childRect;
  }
 private AccessibilityNodeInfoCompat createNodeForChild(int i) {
   AccessibilityNodeInfoCompat accessibilitynodeinfocompat = AccessibilityNodeInfoCompat.obtain();
   accessibilitynodeinfocompat.setEnabled(true);
   accessibilitynodeinfocompat.setClassName(DEFAULT_CLASS_NAME);
   onPopulateNodeForVirtualView(i, accessibilitynodeinfocompat);
   if (accessibilitynodeinfocompat.getText() == null
       && accessibilitynodeinfocompat.getContentDescription() == null) {
     throw new RuntimeException(
         "Callbacks must add text or a content description in populateNodeForVirtualViewId()");
   }
   accessibilitynodeinfocompat.getBoundsInParent(mTempParentRect);
   if (mTempParentRect.isEmpty()) {
     throw new RuntimeException(
         "Callbacks must set parent bounds in populateNodeForVirtualViewId()");
   }
   int j = accessibilitynodeinfocompat.getActions();
   if ((j & 0x40) != 0) {
     throw new RuntimeException(
         "Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
   }
   if ((j & 0x80) != 0) {
     throw new RuntimeException(
         "Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
   }
   accessibilitynodeinfocompat.setPackageName(mView.getContext().getPackageName());
   accessibilitynodeinfocompat.setSource(mView, i);
   accessibilitynodeinfocompat.setParent(mView);
   if (mFocusedVirtualViewId == i) {
     accessibilitynodeinfocompat.setAccessibilityFocused(true);
     accessibilitynodeinfocompat.addAction(128);
   } else {
     accessibilitynodeinfocompat.setAccessibilityFocused(false);
     accessibilitynodeinfocompat.addAction(64);
   }
   if (intersectVisibleToUser(mTempParentRect)) {
     accessibilitynodeinfocompat.setVisibleToUser(true);
     accessibilitynodeinfocompat.setBoundsInParent(mTempParentRect);
   }
   mView.getLocationOnScreen(mTempGlobalRect);
   i = mTempGlobalRect[0];
   j = mTempGlobalRect[1];
   mTempScreenRect.set(mTempParentRect);
   mTempScreenRect.offset(i, j);
   accessibilitynodeinfocompat.setBoundsInScreen(mTempScreenRect);
   return accessibilitynodeinfocompat;
 }
Ejemplo n.º 29
0
  private void applyZoomToCurrentRect(float animationProgress) {
    if (mSourceRect == null) return;
    if (mCurrentRect == null) mCurrentRect = new Rect();

    mCurrentRect.set(
        mSourceRect.left + (((int) (mCurrentZoom * mSourceRect.width()) / 2)),
        mSourceRect.top + (((int) (mCurrentZoom * mSourceRect.height()) / 2)),
        mSourceRect.right - (((int) (mCurrentZoom * mSourceRect.width()) / 2)),
        mSourceRect.bottom - (((int) (mCurrentZoom * mSourceRect.height()) / 2)));

    if (mFocalPoint != null)
      mCurrentRect.offset(
          ((int) ((mFocalPoint.x - mSourceRect.exactCenterX()) * animationProgress)),
          ((int) ((mFocalPoint.y - mSourceRect.exactCenterY()) * animationProgress)));

    fixCurrentRectBounds();
  }
Ejemplo n.º 30
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mController.isIgnoringTouchEvents()) return false;

    // prevent ray cast of touch events to actions container
    getHitRect(mHitRect);
    mHitRect.offset(-getScrollX(), -getScrollY());

    // applying effects
    mEffectedHitRect.set(mHitRect);
    mController.getEffectsMatrix().mapRect(mEffectedHitRect);

    if (mEffectedHitRect.contains((int) event.getX(), (int) event.getY())) {
      return true;
    }

    return super.onTouchEvent(event);
  }