コード例 #1
0
ファイル: AppMenu.java プロジェクト: joone/chromium-crosswalk
  private void setPopupOffset(
      ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    int[] anchorLocation = new int[2];
    popup.getAnchorView().getLocationInWindow(anchorLocation);
    int anchorHeight = popup.getAnchorView().getHeight();

    // If we have a hardware menu button, locate the app menu closer to the estimated
    // hardware menu button location.
    if (mIsByPermanentButton) {
      int horizontalOffset = -anchorLocation[0];
      switch (screenRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
          horizontalOffset += (appRect.width() - mPopup.getWidth()) / 2;
          break;
        case Surface.ROTATION_90:
          horizontalOffset += appRect.width() - mPopup.getWidth();
          break;
        case Surface.ROTATION_270:
          break;
        default:
          assert false;
          break;
      }
      popup.setHorizontalOffset(horizontalOffset);
      // The menu is displayed above the anchored view, so shift the menu up by the bottom
      // padding of the background.
      popup.setVerticalOffset(-padding.bottom);
    } else {
      // The menu is displayed over and below the anchored view, so shift the menu up by the
      // height of the anchor view.
      popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
    }
  }
  /**
   * Shrink the {@code shrinkTarget} rectangle to snugly fit inside of {@code reference}; the aspect
   * ratio of {@code shrinkTarget} will change to be the same aspect ratio as {@code reference}.
   *
   * <p>At most a single dimension will scale (down). Both dimensions will never be scaled.
   *
   * @param reference the rectangle whose aspect ratio will be used as the new aspect ratio
   * @param shrinkTarget the rectangle which will be scaled down to have a new aspect ratio
   * @return a new rectangle, a subset of {@code shrinkTarget}, whose aspect ratio will match that
   *     of {@code reference}
   */
  private static Rect shrinkToSameAspectRatioCentered(Rect reference, Rect shrinkTarget) {
    float aspectRatioReference = reference.width() * 1.0f / reference.height();
    float aspectRatioShrinkTarget = shrinkTarget.width() * 1.0f / shrinkTarget.height();

    float cropH, cropW;
    if (aspectRatioShrinkTarget < aspectRatioReference) {
      // The new width must be smaller than the height, so scale the width by AR
      cropH = reference.height();
      cropW = cropH * aspectRatioShrinkTarget;
    } else {
      // The new height must be smaller (or equal) than the width, so scale the height by AR
      cropW = reference.width();
      cropH = cropW / aspectRatioShrinkTarget;
    }

    Matrix translateMatrix = new Matrix();
    RectF shrunkRect = new RectF(shrinkTarget);

    // Scale the rectangle down, but keep its center in the same place as before
    translateMatrix.setScale(
        cropW / reference.width(),
        cropH / reference.height(),
        shrinkTarget.exactCenterX(),
        shrinkTarget.exactCenterY());

    translateMatrix.mapRect(/*inout*/ shrunkRect);

    return ParamsUtils.createRect(shrunkRect);
  }
コード例 #3
0
ファイル: GameModel.java プロジェクト: farrantt/Cars
  /**
   * Game logic to update the game-state.
   *
   * @param rect Drawable area.
   * @param delay Time delay since last update.
   */
  public boolean update(Rect rect, int delay) {
    // Check that the drawing rectangle is valid
    if (rect.width() <= 0 || rect.width() <= 0) {
      return true;
    }

    if (!gameOver()) {
      for (Character o : obstacles) {
        o.update(rect, this);
        if (car.contains(o.s.x, o.s.y)) {
          if (o.type.equals(ObstacleType.BAD)) {
            gameOver = true;
          } else if (o.type.equals(ObstacleType.GOOD)) {
            score += 1;
            o.delete(this);
          }
        }
      }
      timeElapsed += delay;
      if (timeElapsed >= Constants.delayBetweenCars) {
        addRandomObstacle();
        timeElapsed = 0;
      }
      updateCarLane();
      return true;
    } else {
      return false;
    }
  }
コード例 #4
0
 void a(int paramInt, float paramFloat1, float paramFloat2)
 {
   Rect localRect = e();
   if (paramInt == 1);
   while (true)
   {
     return;
     if (paramInt != 32)
       break;
     b(paramFloat1 * (this.e.width() / localRect.width()), paramFloat2 * (this.e.height() / localRect.height()));
   }
   if ((paramInt & 0x6) == 0)
     paramFloat1 = 0.0F;
   if ((paramInt & 0x18) == 0)
     paramFloat2 = 0.0F;
   float f1 = paramFloat1 * (this.e.width() / localRect.width());
   float f2 = paramFloat2 * (this.e.height() / localRect.height());
   int i1;
   label120: float f3;
   if ((paramInt & 0x2) != 0)
   {
     i1 = -1;
     f3 = f1 * i1;
     if ((paramInt & 0x8) == 0)
       break label159;
   }
   label159: for (int i2 = -1; ; i2 = 1)
   {
     c(f3, f2 * i2);
     break;
     i1 = 1;
     break label120;
   }
 }
コード例 #5
0
ファイル: ExcelView.java プロジェクト: zhkqy/wangyiTrendChart
  protected void onDrawCell(Canvas canvas, Cell cell) {
    if (cell.text == null && cell.bgColor == null && cell.rtDrawable == null)
      return; // 如果无内容,且无背景色不进行绘制
    Rect rect = this.getCellRectInView(cell);
    if (cell.bgColor != null) {

      canvas.drawColor(cell.bgColor);
    }

    if (cell.ballColor != null) {
      painter.setColor(cell.ballColor);
      canvas.drawCircle(rect.centerX(), rect.centerY(), rect.height() / 2 - 1 * dp, painter);
    }
    if (cell.textColor != null) painter.setColor(cell.textColor);
    if (cell.text != null) {
      if (cell.textSize > 0) painter.setTextSize(cell.textSize);
      else painter.setTextSize(this.textSize);
      painter.setTextAlign(cell.aligin);
      int cx = rect.centerX();
      if (cell.aligin == Align.LEFT) cx = rect.left;
      else if (cell.aligin == Align.RIGHT) cx = rect.right;
      int cy = rect.centerY() + (int) (painter.getTextSize() * 2 / 5 + 0.5f);
      if (cell.fixedTextX) cx -= offX;
      if (cell.fixedTextY) cy -= offY;

      canvas.drawText(cell.text, cx, cy, painter);
    }
    if (cell.rtDrawable != null) {
      int minWidth = cell.rtDrawable.getMinimumWidth();
      if (minWidth > rect.width() / 2) minWidth = rect.width() / 2;
      cell.rtDrawable.setBounds(
          new Rect(rect.right - minWidth, rect.top, rect.right, rect.top + minWidth));
      cell.rtDrawable.draw(canvas);
    }
  }
コード例 #6
0
  private Bitmap extentSnapshot(int doc, int gs, int spaceAround, boolean transparent) {
    final LogHelper log = new LogHelper();
    final Rect extent = getDisplayExtent();

    if (!extent.isEmpty()) {
      extent.inset(-spaceAround, -spaceAround);
      extent.intersect(0, 0, mView.getView().getWidth(), mView.getView().getHeight());
    }
    if (extent.isEmpty()) {
      return null;
    }

    final Bitmap viewBitmap = mView.snapshot(doc, gs, transparent);
    if (viewBitmap == null) {
      return null;
    }

    if (extent.width() == mView.getView().getWidth()
        && extent.height() == mView.getView().getHeight()) {
      log.r(viewBitmap.getByteCount());
      return viewBitmap;
    }

    final Bitmap realBitmap =
        Bitmap.createBitmap(viewBitmap, extent.left, extent.top, extent.width(), extent.height());

    viewBitmap.recycle();
    log.r(realBitmap.getByteCount());
    return realBitmap;
  }
コード例 #7
0
ファイル: TimeBar.java プロジェクト: zst123/p201-packages
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // draw progress bars
    canvas.drawRect(mProgressBar, mProgressPaint);
    mSecondaryProgressExt.draw(canvas, mProgressBar);
    canvas.drawRect(mPlayedBar, mPlayedPaint);

    // draw scrubber and timers
    if (mShowScrubber) {
      canvas.drawBitmap(mScrubber, mScrubberLeft, mScrubberTop, null);
    }
    if (mShowTimes) {
      canvas.drawText(
          stringForTime(mCurrentTime),
          mTimeBounds.width() / 2 + getPaddingLeft(),
          mTimeBounds.height()
              + mVPaddingInPx / 2
              + mScrubberPadding
              + 1
              + mLayoutExt.getTimeOffset(),
          mTimeTextPaint);
      canvas.drawText(
          stringForTime(mTotalTime),
          getWidth() - getPaddingRight() - mTimeBounds.width() / 2,
          mTimeBounds.height()
              + mVPaddingInPx / 2
              + mScrubberPadding
              + 1
              + mLayoutExt.getTimeOffset(),
          mTimeTextPaint);
    }
    mInfoExt.draw(canvas, mLayoutExt.getInfoBounds(this, mTimeBounds));
  }
コード例 #8
0
  private static void testProgressValues(ProgressValues progress, Rect bounds) {
    // Ensure that the percent progress is valid.
    assertTrue(progress.getPercent() >= 0);
    assertTrue(progress.getPercent() <= 100);

    // Ensure that the text rect is valid.
    final Rect textRect = progress.getCurrentRect();
    assertTrue(textRect.left <= textRect.right);
    assertTrue(textRect.top <= textRect.bottom);

    // Text rect must match the bounds of the image or sub-rectangle used.
    assertEquals(textRect.height(), bounds.height());
    assertEquals(textRect.width(), bounds.width());

    // Ensure that the word rect is valid.
    final Rect wordRect = progress.getCurrentWordRect();
    assertTrue(textRect.left <= textRect.right);
    assertTrue(textRect.top <= textRect.bottom);

    // Ensure the word rect falls within the text rect.
    final Rect absoluteWordRect =
        new Rect(
            textRect.left + wordRect.left,
            textRect.top + wordRect.top,
            textRect.left + wordRect.right,
            textRect.top + wordRect.bottom);
    assertTrue(textRect.contains(absoluteWordRect));
  }
コード例 #9
0
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mapView == null || mapView.isClickable()) {
      return;
    }

    if (doMeasureMode) {
      int cWidth = canvas.getWidth();
      canvas.drawPath(measurePath, measurePaint);
      int upper = 70;
      int delta = 5;
      measureTextPaint.getTextBounds(distanceString, 0, distanceString.length(), rect);
      int textWidth = rect.width();
      int textHeight = rect.height();
      int x = cWidth / 2 - textWidth / 2;
      canvas.drawText(distanceString, x, upper, measureTextPaint);
      String distanceText = String.valueOf((int) measuredDistance);
      // String distanceText = distanceText((int) measuredDistance, imperial, nautical);
      measureTextPaint.getTextBounds(distanceText, 0, distanceText.length(), rect);
      textWidth = rect.width();
      x = cWidth / 2 - textWidth / 2;
      canvas.drawText(distanceText, x, upper + delta + textHeight, measureTextPaint);
      if (GPLog.LOG_HEAVY)
        GPLog.addLogEntry(this, "Drawing measure path text: " + upper); // $NON-NLS-1$
    } else if (doInfoMode) {
      canvas.drawRect(rect, infoRectPaintFill);
      canvas.drawRect(rect, infoRectPaintStroke);
    }
  }
コード例 #10
0
  private void init() {
    if (mPaint == null) {
      mPaint = new Paint();
      mPaint.setColor(Color.WHITE);
      mPaint.setAntiAlias(true);
      mPaint.setStyle(Paint.Style.FILL);
    }

    int count = (mPoints - 1) * 4;
    posX = new float[count];
    posY = new float[count];

    Rect bounds = new Rect();
    bounds.set(getBounds());
    bounds.inset(mPadding, mPadding);

    // circumference
    float circ = (float) (Math.PI * (float) Math.min(bounds.width(), bounds.height()));
    float arcLength = circ / count;

    mSize = (float) ((arcLength) / (2 * Math.PI));

    double degrees = Math.toRadians((float) 360 / (float) count);
    for (int i = 0; i < count; i++) {
      posX[i] = (float) (bounds.exactCenterX() - (bounds.width() / 2) * Math.sin(degrees * i));
      posY[i] = (float) (bounds.exactCenterY() + (bounds.height() / 2) * Math.cos(degrees * i));
    }
  }
コード例 #11
0
ファイル: Button.java プロジェクト: KitoHo/nds4ios
  static Button load(
      Context context,
      int id,
      int resId,
      boolean landscape,
      boolean is565,
      Rect screen,
      Rect space,
      boolean forceLoad) {

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final String prefLayoutBase = "Controls." + (landscape ? "Landscape." : "Portrait.");
    final String prefBase = prefLayoutBase + getButtonName(id) + ".";
    final Button template = landscape ? landscapeToDefault.get(id) : portraitToDefault.get(id);
    if (forceLoad || prefs.getBoolean(prefLayoutBase + "Draw", true)) {
      float controlxscale = (float) screen.width() / (float) space.width();
      float controlyscale = (float) screen.height() / (float) space.height();

      final Rect finalRect =
          new Rect(
              prefs.getInt(prefBase + "Left", (int) (template.position.left * controlxscale)),
              prefs.getInt(prefBase + "Top", (int) (template.position.top * controlyscale)),
              prefs.getInt(prefBase + "Right", (int) (template.position.right * controlxscale)),
              prefs.getInt(prefBase + "Bottom", (int) (template.position.bottom * controlyscale)));

      final BitmapFactory.Options controlOptions = new BitmapFactory.Options();
      if (is565) controlOptions.inPreferredConfig = Bitmap.Config.RGB_565;
      final Bitmap originalControls =
          BitmapFactory.decodeResource(context.getResources(), resId, controlOptions);
      final Bitmap controls =
          Bitmap.createScaledBitmap(originalControls, finalRect.width(), finalRect.height(), true);
      return new Button(finalRect, id, controls);
    } else return new Button(template.position, id);
  }
コード例 #12
0
  @Override
  public void draw(Canvas canvas) {

    Rect bounds = getBounds();
    if (bounds.width() == 0 || bounds.height() == 0) {
      return;
    }

    if (mPaint == null) {
      mPaint = new Paint();
      mPaint.setAntiAlias(true);
      mPaint.setColor(Color.BLACK);
      onPreparePaint(mPaint);
    }
    mPaint.setAlpha(mAlpha);
    ColorFilter colorFilter = mColorFilter != null ? mColorFilter : mTintFilter;
    mPaint.setColorFilter(colorFilter);

    int saveCount = canvas.save();

    canvas.translate(bounds.left, bounds.top);
    if (needMirroring()) {
      canvas.translate(bounds.width(), 0);
      canvas.scale(-1, 1);
    }

    onDraw(canvas, bounds.width(), bounds.height(), mPaint);

    canvas.restoreToCount(saveCount);
  }
コード例 #13
0
ファイル: C07_MemoryPower.java プロジェクト: byunwoo/AndExam
    public void onDraw(Canvas canvas) {
      // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴
      canvas.drawColor(Color.BLACK);
      if (status == BLANK) {
        return;
      }

      // 도형 목록을 순회하면서 도형 정보대로 출력한다.
      int idx;
      for (idx = 0; idx < arShape.size(); idx++) {
        Paint Pnt = new Paint();
        Pnt.setAntiAlias(true);
        Pnt.setColor(arShape.get(idx).color);

        Rect rt = arShape.get(idx).rt;
        switch (arShape.get(idx).what) {
          case Shape.RECT:
            canvas.drawRect(rt, Pnt);
            break;
          case Shape.CIRCLE:
            canvas.drawCircle(
                rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt);
            break;
          case Shape.TRIANGLE:
            Path path = new Path();
            path.moveTo(rt.left + rt.width() / 2, rt.top);
            path.lineTo(rt.left, rt.bottom);
            path.lineTo(rt.right, rt.bottom);
            canvas.drawPath(path, Pnt);
            break;
        }
      }
    }
コード例 #14
0
  public void draw(Canvas canvas) {
    super.draw(canvas);
    float scale = getResources().getDisplayMetrics().density;
    int paddSize = (int) (GAPPING * scale + 0.5f);
    int bmWidth = bg.getBitmap().getWidth();
    Rect rect = new Rect(0, 0, getWidth(), getHeight());
    for (int x = 0; x < rect.width(); x += bmWidth) {
      RectF dstRect = new RectF(x, paddSize, getWidth() + x, getHeight() - paddSize);
      canvas.drawBitmap(bg.getBitmap(), null, dstRect, null);
    }
    bmWidth = midBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - midBg.getIntrinsicHeight() - paddSize,
              midBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(midBg.getBitmap(), null, dstRectMid, null);
    }

    bmWidth = forBg.getIntrinsicWidth();
    for (int x = 0; x < rect.width(); x += bmWidth) {
      Rect dstRectMid =
          new Rect(
              x,
              getHeight() - forBg.getIntrinsicHeight() - paddSize,
              forBg.getIntrinsicWidth() + x,
              getHeight() - paddSize);
      canvas.drawBitmap(forBg.getBitmap(), null, dstRectMid, null);
    }
  }
コード例 #15
0
  private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners =
        new float[] {
          halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize
        };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
  }
コード例 #16
0
  /** @brief update helper function for the polaroid bg layer */
  private void updatePolaroidDrawable(Rect bounds) {
    PDEColor highColor;
    PDEColor lowColor;
    float red, green, blue;
    Rect frameRect = new Rect(0, 0, bounds.width(), bounds.height());

    mElementCornerRadius = bounds.width() * 0.07f;
    // update Frame
    mElementPolaroidDrawable.setBounds(frameRect);
    mElementPolaroidDrawable.setElementCornerRadius(mElementCornerRadius);
    mElementPolaroidDrawable.setElementBorderColor(mElementPolaroidFrameColor);
    // todo: this border stuff does not work properly!!! So we take a workaround.
    // mElementPolaroidDrawable.setElementBorderWidth(polaroidRelativeValue(2.5f));
    int border = Math.round(polaroidRelativeValue(2.5f));
    mElementGradientDrawable.setBounds(
        frameRect.left + border,
        frameRect.top + border,
        frameRect.right - border,
        frameRect.bottom - border);

    red = mElementPolaroidFrameColor.getRed();
    blue = mElementPolaroidFrameColor.getBlue();
    green = mElementPolaroidFrameColor.getGreen();

    highColor = new PDEColor(red, green, blue, 0.0f);
    lowColor = new PDEColor(red - 0.33f, green - 0.33f, blue - 0.33f, 0.75f);
    mElementGradientDrawable.setElementBackgroundGradientColors(highColor, highColor, lowColor);
    mElementGradientDrawable.setElementGradientDistributionPositions(0.0f, 0.85f, 1.0f);

    // set other layer data
    mElementPolaroidDrawable.setElementBackgroundColor(mElementPolaroidFrameColor);
    mElementGradientDrawable.setElementCornerRadius(mElementCornerRadius);
    mElementGradientDrawable.setElementBorderColor(PDEColor.valueOf("DTTransparentBlack"));
  }
コード例 #17
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    View childView = getChildAt(mCurrentSelection);
    TextView childTextView = null;
    if (childView instanceof TextView) {
      childTextView = (TextView) childView;
    }

    if (childTextView != null
        && !TextUtils.isEmpty(childTextView.getText())
        && getVisibility() == View.VISIBLE
        && childTextView.getVisibility() == View.VISIBLE) {
      Rect childRect = new Rect();
      childTextView.getLocalVisibleRect(childRect);

      float childViewX = childTextView.getX() + childTextView.getWidth() / 2;
      float childViewY = childTextView.getY() + childTextView.getHeight() / 2;

      int top = (int) (childViewY - mSelectedRect.height() / 2);
      int left = (int) (childViewX - mSelectedRect.width() / 2);

      mSelectedRect.set(left, top, left + mSelectedRect.width(), top + mSelectedRect.height());

      if (isShowSelected && !mSelectedRect.isEmpty()) {
        final Drawable selectedBg = mSelectedBg;
        selectedBg.setBounds(mSelectedRect);
        selectedBg.draw(canvas);
      }
    }

    super.dispatchDraw(canvas);
  }
コード例 #18
0
  /**
   * Method that load the gles texture and apply to the requestor frame (which includes fix the
   * aspect ratio and/or effects and borders)
   *
   * @param requestor The requestor target
   * @param ti The original texture information (the one with the bitmap one)
   */
  private void applyToRequestor(TextureRequestor requestor, GLESTextureInfo ti) {
    // Transform requestor dimensions to screen dimensions
    RectF dimens = requestor.getRequestorDimensions();
    Rect pixels =
        new Rect(
            0,
            0,
            (int) (mScreenDimensions.width() * dimens.width() / 2),
            (int) (mScreenDimensions.height() * dimens.height() / 2));

    final Disposition disposition = requestor.getDisposition();
    synchronized (mEffectsSync) {
      if (disposition.hasFlag(Disposition.EFFECT_FLAG)) {
        ti.effect = mEffects.getNextEffect();
      }
      if (disposition.hasFlag(Disposition.BORDER_FLAG)) {
        ti.border = mBorders.getNextBorder();
      }
    }

    // Check if we have to apply any correction to the image
    GLESTextureInfo dst;
    if (ti.bitmap != null && Preferences.General.isFixAspectRatio(mContext)) {

      // Create a texture of power of two here to avoid scaling the bitmap twice
      int w = pixels.width();
      int h = pixels.height();
      if (!BitmapUtils.isPowerOfTwo(w, h)
          && PreferencesProvider.Preferences.General.isPowerOfTwo(mContext)) {
        w = h = BitmapUtils.calculateUpperPowerOfTwo(Math.min(w, h));
      }

      // Create a thumbnail of the image
      Bitmap thumb = BitmapUtils.createScaledBitmap(ti.bitmap, w, h, BitmapUtils.ScalingLogic.CROP);
      if (!thumb.equals(ti.bitmap)) {
        ti.bitmap.recycle();
      }
      dst = GLESUtil.loadTexture(mContext, thumb, ti.effect, ti.border, pixels);
    } else {
      // Load the texture without any correction
      dst = GLESUtil.loadTexture(mContext, ti.bitmap, ti.effect, ti.border, pixels);
    }

    // Swap references
    ti.bitmap = dst.bitmap;
    ti.handle = dst.handle;
    ti.effect = null;
    ti.border = null;
    dst.handle = 0;
    dst.bitmap = null;

    // And notify to the requestor
    requestor.setTextureHandle(ti);

    // Clean up memory
    if (ti.bitmap != null) {
      ti.bitmap.recycle();
      ti.bitmap = null;
    }
  }
コード例 #19
0
ファイル: CameraManager.java プロジェクト: NemesisAW/Edible
  /**
   * Changes the size of the framing rect.
   *
   * @param deltaWidth Number of pixels to adjust the width
   * @param deltaHeight Number of pixels to adjust the height
   */
  public synchronized void adjustFramingRect(int deltaWidth, int deltaHeight) {
    if (initialized) {
      Point screenResolution = configManager.getScreenResolution();

      // Set maximum and minimum sizes
      if ((framingRect.width() + deltaWidth > screenResolution.x - 4)
          || (framingRect.width() + deltaWidth < 50)) {
        deltaWidth = 0;
      }
      if ((framingRect.height() + deltaHeight > screenResolution.y - 4)
          || (framingRect.height() + deltaHeight < 50)) {
        deltaHeight = 0;
      }

      int newWidth = framingRect.width() + deltaWidth;
      int newHeight = framingRect.height() + deltaHeight;
      int leftOffset = (screenResolution.x - newWidth) / 2;
      int topOffset = (screenResolution.y - newHeight) / 2;
      framingRect = new Rect(leftOffset, topOffset, leftOffset + newWidth, topOffset + newHeight);
      framingRectInPreview = null;
    } else {
      requestedFramingRectWidth = deltaWidth;
      requestedFramingRectHeight = deltaHeight;
    }
  }
コード例 #20
0
ファイル: WaterfallSerie.java プロジェクト: josercl/Chartlib
  @Override
  public void draw(Canvas canvas, Rect chartArea) {
    int n = points.size();
    scaledGap = barGap * (float) (chartArea.width() / (maxX - minX));
    barWidth = (chartArea.width() - scaledGap * (n - 1)) / n;

    Point p;
    double scaledY;
    double yMax = chartArea.top;

    for (int i = 0; i < points.size(); i++) {

      y0 = chartArea.top + chartArea.height();

      p = points.get(i);
      scaledY = (p.getY() - minY + barGap) * (chartArea.height()) / (maxY - minY + 2 * barGap);
      double scaledX = i * (barWidth + scaledGap);

      if (!areSum.get(i)) {
        y0 = yMax + scaledY;
        drawPoint(canvas, scaledX + chartArea.left, yMax, colors.get(i));
        yMax += scaledY;
      } else {
        drawPoint(
            canvas,
            scaledX + chartArea.left,
            chartArea.top + chartArea.height() - scaledY,
            colors.get(i));
      }
    }
  }
コード例 #21
0
  void updateDstRect() {
    if (mApplyGravity) {
      if (mIsCircular) {
        final int minDimen = Math.min(mBitmapWidth, mBitmapHeight);
        gravityCompatApply(mGravity, minDimen, minDimen, getBounds(), mDstRect);

        // inset the drawing rectangle to the largest contained square,
        // so that a circle will be drawn
        final int minDrawDimen = Math.min(mDstRect.width(), mDstRect.height());
        final int insetX = Math.max(0, (mDstRect.width() - minDrawDimen) / 2);
        final int insetY = Math.max(0, (mDstRect.height() - minDrawDimen) / 2);
        mDstRect.inset(insetX, insetY);
        mCornerRadius = 0.5f * minDrawDimen;
      } else {
        gravityCompatApply(mGravity, mBitmapWidth, mBitmapHeight, getBounds(), mDstRect);
      }
      mDstRectF.set(mDstRect);

      if (mBitmapShader != null) {
        // setup shader matrix
        mShaderMatrix.setTranslate(mDstRectF.left, mDstRectF.top);
        mShaderMatrix.preScale(
            mDstRectF.width() / mBitmap.getWidth(), mDstRectF.height() / mBitmap.getHeight());
        mBitmapShader.setLocalMatrix(mShaderMatrix);
        mPaint.setShader(mBitmapShader);
      }

      mApplyGravity = false;
    }
  }
コード例 #22
0
ファイル: CellEnum.java プロジェクト: danieltf/buscaminas
 public void paintBitmap(Context context, Canvas c, Rect dest) {
   int color0 = Color.argb(0xFF, 196, 181, 51);
   int color1 = Color.argb(0xFF, 251, 219, 39);
   int color2 = Color.argb(0xFF, 255, 239, 151);
   int border = Color.argb(0xFF, 220, 200, 80);
   Paint p = new Paint();
   p.setAntiAlias(true);
   float width = dest.width() / 20.0f;
   float insideSize = dest.width() - 2 * width;
   RectF inside1 =
       new RectF(
           dest.left + width - 1,
           dest.top + width - 1,
           dest.right - width + 1,
           dest.bottom - width + 1);
   RectF inside =
       new RectF(dest.left + width, dest.top + width, dest.right - width, dest.bottom - width);
   LinearGradient linear =
       new LinearGradient(
           inside1.left,
           inside1.top + insideSize / 3,
           inside1.right,
           inside1.top + 2 * insideSize / 3,
           new int[] {color0, color1, color2},
           null,
           Shader.TileMode.CLAMP);
   p.setShader(linear);
   c.drawRoundRect(inside1, width, width, p);
   p.setShader(null);
   p.setColor(border);
   Path path = new Path();
   path.addRoundRect(inside, width, width, Path.Direction.CCW);
   path.addRect(new RectF(dest), Path.Direction.CW);
   c.drawPath(path, p);
 }
コード例 #23
0
 /**
  * A factory method to build the appropriate LuminanceSource object based on the format of the
  * preview buffers, as described by Camera.Parameters.
  *
  * @param data A preview frame.
  * @param width The width of the image.
  * @param height The height of the image.
  * @return A PlanarYUVLuminanceSource instance.
  */
 public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
   Rect rect = getFramingRectInPreview();
   int previewFormat = configManager.getPreviewFormat();
   String previewFormatString = configManager.getPreviewFormatString();
   switch (previewFormat) {
       // This is the standard Android format which all devices are REQUIRED to
       // support.
       // In theory, it's the only one we should ever care about.
     case PixelFormat.YCbCr_420_SP:
       // This format has never been seen in the wild, but is compatible as
       // we only care
       // about the Y channel, so allow it.
     case PixelFormat.YCbCr_422_SP:
       return new PlanarYUVLuminanceSource(
           data, width, height, rect.left, rect.top, rect.width(), rect.height());
     default:
       // The Samsung Moment incorrectly uses this variant instead of the
       // 'sp' version.
       // Fortunately, it too has all the Y data up front, so we can read
       // it.
       if ("yuv420p".equals(previewFormatString)) {
         return new PlanarYUVLuminanceSource(
             data, width, height, rect.left, rect.top, rect.width(), rect.height());
       }
   }
   throw new IllegalArgumentException(
       "Unsupported picture format: " + previewFormat + '/' + previewFormatString);
 }
コード例 #24
0
    private void calculatePosition() {
      paint.getTextBounds(value, 0, value.length(), bounds);

      final int paddingLeft = padding;
      final int paddingRight = padding;
      final int paddingTop = padding;
      final int paddingBottom = padding;

      switch (direction) {
        case up:
        case down:
          offset.x = -paddingLeft - bounds.width() - bounds.left;
          if (direction == DragDirection.up) {
            offset.y = paddingTop + fixedTextHeight;
          } else {
            offset.y = -paddingBottom;
          }
          break;
        case left:
        case right:
          if (direction == DragDirection.left) {
            offset.x = paddingLeft;
          } else {
            offset.x = -paddingRight - bounds.width();
          }
          offset.y = (paddingTop - paddingBottom) / 2 + fixedTextHeight / 2;
          break;
      }
    }
コード例 #25
0
ファイル: TimeBar.java プロジェクト: Snotbob/chanu
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);

    // draw progress bars
    canvas.drawRect(progressBar, progressPaint);
    canvas.drawRect(playedBar, playedPaint);

    // draw scrubber and timers
    if (showScrubber) {
      canvas.drawBitmap(scrubber, scrubberLeft, scrubberTop, null);
    }
    if (showTimes) {
      canvas.drawText(
          stringForTime(currentTime),
          timeBounds.width() / 2 + getPaddingLeft(),
          timeBounds.height() + vPaddingInPx / 2 + scrubberPadding + 1,
          timeTextPaint);
      canvas.drawText(
          stringForTime(totalTime),
          getWidth() - getPaddingRight() - timeBounds.width() / 2,
          timeBounds.height() + vPaddingInPx / 2 + scrubberPadding + 1,
          timeTextPaint);
    }
  }
コード例 #26
0
ファイル: cursorImg.java プロジェクト: oldThing/PlayerMp3
 /** 计算出圆的半径 */
 private void computeRadious() {
   Rect bounds = getBounds();
   radious =
       bounds.width() < bounds.height()
           ? bounds.width() / 2f - mMargin
           : bounds.height() / 2f - mMargin;
 }
コード例 #27
0
  // Handles motion (dx, dy) in screen space.
  // The "edge" parameter specifies which edges the user is dragging.
  void handleMotion(int edge, float dx, float dy) {

    Rect r = computeLayout();
    if (edge == GROW_NONE) {
      return;
    } else if (edge == MOVE) {
      // Convert to image space before sending to moveBy().
      moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height()));
    } else {
      if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) {
        dx = 0;
      }

      if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) {
        dy = 0;
      }

      // Convert to image space before sending to growBy().
      float xDelta = dx * (mCropRect.width() / r.width());
      float yDelta = dy * (mCropRect.height() / r.height());
      growBy(
          (((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta,
          (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta);
    }
  }
コード例 #28
0
  /** 画面サイズから自位置を決定します。 */
  private void updateViewLayout() {
    cancelAnimation();

    // 前の画面座標を保存
    final int oldScreenHeight = mMetrics.heightPixels;
    final int oldScreenWidth = mMetrics.widthPixels;
    final int oldPositionLimitWidth = mPositionLimitRect.width();
    final int oldPositionLimitHeight = mPositionLimitRect.height();

    // 新しい座標情報に切替
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    final int newScreenWidth = mMetrics.widthPixels;
    final int newScreenHeight = mMetrics.heightPixels;

    // 移動範囲の設定
    mMoveLimitRect.set(-width, -height * 2, newScreenWidth + width, newScreenHeight + height);
    mPositionLimitRect.set(
        -mOverMargin,
        0,
        newScreenWidth - width + mOverMargin,
        newScreenHeight - mStatusBarHeight - height);

    // 縦横切替の場合
    if (oldScreenWidth != newScreenWidth || oldScreenHeight != newScreenHeight) {
      // 画面端に移動する場合は現在の位置から左右端を設定
      if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_DEFAULT) {
        // 右半分にある場合
        if (mParams.x > (newScreenWidth - width) / 2) {
          mParams.x = mPositionLimitRect.right;
        }
        // 左半分にある場合
        else {
          mParams.x = mPositionLimitRect.left;
        }
      }
      // 左端に移動
      else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_LEFT) {
        mParams.x = mPositionLimitRect.left;
      }
      // 右端に移動
      else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_RIGHT) {
        mParams.x = mPositionLimitRect.right;
      }
      // 画面端に移動しない場合は画面座標の比率から計算
      else {
        final int newX =
            (int) (mParams.x * mPositionLimitRect.width() / (float) oldPositionLimitWidth + 0.5f);
        mParams.x = Math.min(Math.max(mPositionLimitRect.left, newX), mPositionLimitRect.right);
      }

      // スクリーン位置の比率からY座標を設定(四捨五入)
      final int newY =
          (int) (mParams.y * mPositionLimitRect.height() / (float) oldPositionLimitHeight + 0.5f);
      mParams.y = Math.min(Math.max(mPositionLimitRect.top, newY), mPositionLimitRect.bottom);
      mWindowManager.updateViewLayout(this, mParams);
    }
  }
コード例 #29
0
 protected void onDraw(Canvas paramCanvas) {
   // today round
   if (mIsToday) {
     Paint painta = new Paint();
     painta.setStyle(Paint.Style.STROKE);
     painta.setColor(Color.BLACK);
     painta.setAntiAlias(true);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 5, getMeasuredHeight() / 5, painta);
     Paint paintb = new Paint();
     paintb.setColor(Color.GRAY);
     paintb.setAntiAlias(true);
     paintb.setAlpha(50);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 6, getMeasuredWidth() / 6, paintb);
   }
   // solar text
   Paint paint1 = new Paint();
   paint1.setAntiAlias(true);
   paint1.setFakeBoldText(true);
   paint1.setTextSize(getMeasuredWidth() / 2);
   if (mDay.mIsWeekEnd) {
     paint1.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint1.setColor(Color.BLACK);
   }
   Rect text = new Rect();
   paint1.getTextBounds(mDay.mSolarDay, 0, mDay.mSolarDay.length(), text);
   int w = getMeasuredWidth();
   int w1 = text.width();
   float fw = (w - w1) / 2;
   float fh = getMeasuredHeight() / 2 + 1;
   paramCanvas.drawText(mDay.mSolarDay, fw, fh, paint1);
   // lunar text
   Paint paint2 = new Paint();
   paint2.setAntiAlias(true);
   paint2.setTextSize(getMeasuredWidth() / 4);
   if (mDay.mIsFestival) {
     paint2.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint2.setColor(Color.BLACK);
   }
   paint2.getTextBounds(mDay.mLunarDay, 0, mDay.mLunarDay.length(), text);
   w1 = text.width();
   fw = (w - w1) / 2;
   fh = getMeasuredHeight() / 2 + 2 + text.height();
   paramCanvas.drawText(mDay.mLunarDay, fw, fh, paint2);
   if (mDay.mHasDiary) {
     Paint pd = new Paint();
     pd.setStyle(Paint.Style.STROKE);
     pd.setColor(ECalendarActivity.mHolidayColor);
     pd.setStrokeWidth(2);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawLine(rt.left + rt.width() / 4, rt.top, rt.right - rt.width() / 4, rt.top, pd);
   }
 }
コード例 #30
0
 private void updateGradient() {
   float x0 = mLeftToRight ? 0 : mForegroundRect.width();
   float x1 = mLeftToRight ? mForegroundRect.width() : 0;
   mLeftToRightGradient =
       new LinearGradient(x0, 0f, x1, 0f, mGradientColor, 0, Shader.TileMode.CLAMP);
   mRightToLeftGradient =
       new LinearGradient(x1, 0f, x0, 0f, mGradientColor, 0, Shader.TileMode.CLAMP);
 }