Пример #1
0
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    canvas.drawColor(Color.BLACK);

    Paint textPaint = new Paint();
    textPaint.setARGB(50, 254, 100, 45);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(50);
    textPaint.setTypeface(font);
    canvas.drawText("Ajith is ..", canvas.getWidth() / 2, 200, textPaint);

    canvas.drawBitmap(star, (canvas.getWidth() / 2), y, null);
    if (y < canvas.getHeight()) {
      y += 10;
    } else {
      y = 0;
    }
    Rect middlRect = new Rect();
    middlRect.set(0, 400, canvas.getWidth(), 550);
    Paint ourBlue = new Paint();
    ourBlue.setColor(Color.BLUE);
    canvas.drawRect(middlRect, ourBlue);
    invalidate();
  }
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);

    canvas.drawColor(Color.WHITE);
    Paint textPaint = new Paint();
    textPaint.setTextSize(50);
    textPaint.setARGB(50, 0, 100, 255);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTypeface(font);
    canvas.drawText("hola, soy fernando ;) ", canvas.getWidth() / 2, 250, textPaint);

    canvas.drawBitmap(gBall, (canvas.getWidth() / 2), changingY, null);
    if (changingY < canvas.getHeight()) {
      changingY += 10;
    } else {
      changingY = 0;
    }
    Rect middleRect = new Rect();
    middleRect.set(0, 400, canvas.getWidth(), 550);
    Paint ourBlue = new Paint();
    ourBlue.setColor(Color.BLUE);
    canvas.drawRect(middleRect, ourBlue);

    invalidate();
  }
Пример #3
0
  void drawFrame(Mat modified) {
    // Partly from OpenCV CameraBridgeViewBase.java
    if (mCacheBitmap == null) {
      mCacheBitmap =
          Bitmap.createBitmap(modified.width(), modified.height(), Bitmap.Config.ARGB_8888);
    }
    boolean bmpValid = true;
    if (modified != null) {
      try {
        Utils.matToBitmap(modified, mCacheBitmap);
      } catch (Exception e) {
        Log.e(TAG, "Mat type: " + modified);
        Log.e(TAG, "Bitmap type: " + mCacheBitmap.getWidth() + "*" + mCacheBitmap.getHeight());
        Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage());
        bmpValid = false;
      }
    }
    if (bmpValid && mCacheBitmap != null) {
      Canvas canvas = view.getHolder().lockCanvas();
      if (canvas != null) {
        canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
        canvas.drawBitmap(
            mCacheBitmap,
            new Rect(0, 0, mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),
            new Rect(
                (canvas.getWidth() - mCacheBitmap.getWidth()) / 2,
                (canvas.getHeight() - mCacheBitmap.getHeight()) / 2,
                (canvas.getWidth() - mCacheBitmap.getWidth()) / 2 + mCacheBitmap.getWidth(),
                (canvas.getHeight() - mCacheBitmap.getHeight()) / 2 + mCacheBitmap.getHeight()),
            null);

        view.getHolder().unlockCanvasAndPost(canvas);
      }
    }
  }
Пример #4
0
  public synchronized void render(Canvas canvas) {
    if (canvas.getWidth() != surfaceWidth || canvas.getHeight() != surfaceHeight) {
      surfaceWidth = canvas.getWidth();
      surfaceHeight = canvas.getHeight();

      setWindowScale();
    }
    /*
    while (surface == null) {
    	try {
    		wait();
    	} catch(InterruptedException e) {}
    }
    */
    canvas.save();
    canvas.scale(windowScale, windowScale, 0, 0);
    canvas.drawBitmap(screen, windowX / windowScale, windowY / windowScale, bilinearPaint);
    canvas.restore();

    // HUD - caption, subtitles, buttons
    if (gameState == GAMESTATE_LEVEL) {
      moreButtonsAnim();
      saveEffectRender(canvas);

      controls.render(canvas);
      activeFish.render(canvas, 800 - 96, 480 - 96, surfaceWidth, surfaceHeight);
    }

    // window caption
    renderCaption(canvas);
    // notifyAll();
  }
Пример #5
0
  @Override
  protected void onDraw(Canvas canvas) {
    float left = getPaddingLeft() + mUnreachedWidth / 2;
    float top = getPaddingTop() + mUnreachedWidth / 2;
    float right = canvas.getWidth() - getPaddingRight() - mUnreachedWidth / 2;
    float bottom = canvas.getHeight() - getPaddingBottom() - mUnreachedWidth / 2;
    float centerX = (left + right) / 2;
    float centerY = (top + bottom) / 2;

    float wheelRadius =
        (canvas.getWidth() - getPaddingLeft() - getPaddingRight()) / 2 - mUnreachedWidth / 2;

    if (isHasCache) {
      if (mCacheCanvas == null) {
        buildCache(centerX, centerY, wheelRadius);
      }
      canvas.drawBitmap(mCacheBitmap, 0, 0, null);
    } else {
      canvas.drawCircle(centerX, centerY, wheelRadius, mWheelPaint);
    }

    // 画选中区域
    canvas.drawArc(
        new RectF(left, top, right, bottom), -90, (float) mCurAngle, false, mReachedPaint);

    // 画锚点
    canvas.drawCircle(mWheelCurX, mWheelCurY, mPointerRadius, mPointerPaint);
  }
Пример #6
0
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub

    super.onDraw(canvas);
    // canvas
    canvas.drawLine(
        canvas.getWidth() / 2 - 200,
        canvas.getHeight() / 2 + 50,
        canvas.getWidth(),
        canvas.getHeight() / 2 + 50,
        red); // xaxis
    canvas.drawLine(
        canvas.getWidth() / 2 - 150,
        canvas.getHeight() / 2 - 800,
        canvas.getWidth() / 2 - 150,
        canvas.getHeight() / 2 + 100,
        red); // yaxis

    for (int i = 0; i <= 720; i++) // curve
    {
      int x = i + (canvas.getWidth() / 2 - 150);
      int y =
          (int) ((canvas.getHeight() / 2 + 50) + ((float) Math.sin(Math.toRadians(2 * i))) * 100);
      canvas.drawPoint(x, y, blue);
    }
  }
Пример #7
0
  void drawProgress(Canvas canvas) {
    mPaint.setColor(mProgressBarColor);

    final float progress = Math.max(Math.min(mProgress / (float) mProgressMax, 1f), 0f);
    final float barWidth = progress * canvas.getWidth();
    final float l = (canvas.getWidth() - barWidth) / 2f;

    mDrawRect.set(l, 0f, l + barWidth, canvas.getHeight());
    canvas.drawRoundRect(mDrawRect, mProgressBarRadiusPx, mProgressBarRadiusPx, mPaint);
  }
  @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);
    }
  }
Пример #9
0
  @Override
  public void draw(Canvas canvas) {
    mCanvasWidth = canvas.getWidth();
    mCanvasHeight = canvas.getHeight();

    mRadius =
        map(
            getLevel(),
            0,
            DRAWABLE_MAX_LEVEL,
            0,
            diagonalLength(canvas.getWidth(), canvas.getHeight()) / 2);
    canvas.drawCircle(canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f, mRadius, mPaint);
  }
 protected void onDraw(Canvas canvas) {
   paint.setColor(Color.YELLOW);
   paint.setTypeface(font);
   paint.setTextSize(28);
   paint.setTextAlign(Paint.Align.CENTER);
   canvas.drawText("Esto seria una prueba de fuente", canvas.getWidth() / 2, 100, paint);
   String text = "Esto es otra prueba copada de fuente!";
   paint.setColor(Color.WHITE);
   paint.setTextSize(18);
   paint.setTextAlign(Paint.Align.LEFT);
   paint.getTextBounds(text, 0, text.length(), bounds);
   canvas.drawText(text, canvas.getWidth() - bounds.width(), 140, paint);
   invalidate();
 }
Пример #11
0
 @Override
 protected void onDraw(Canvas canvas) {
   if (imageOffset != 0) {
     canvas.save();
     canvas.translate(0f, imageOffset);
     canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset);
     super.onDraw(canvas);
     canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
     canvas.restore();
   } else {
     super.onDraw(canvas);
     canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
   }
 }
Пример #12
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (mShowcaseX < 0 || mShowcaseY < 0 || mIsRedundant) {
      super.dispatchDraw(canvas);
      return;
    }

    boolean recalculatedCling = mShowcaseDrawer.calculateShowcaseRect(mShowcaseX, mShowcaseY);
    boolean recalculateText = recalculatedCling || mAlteredText;
    mAlteredText = false;

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && !mHasNoTarget) {
      Path path = new Path();
      path.addCircle(mShowcaseX, mShowcaseY, mShowcaseRadius, Path.Direction.CW);
      canvas.clipPath(path, Op.DIFFERENCE);
    }

    // Draw background color
    canvas.drawColor(mBackgroundColor);

    // Draw the showcase drawable
    if (!mHasNoTarget) {
      mShowcaseDrawer.drawShowcase(
          canvas, mShowcaseX, mShowcaseY, mScaleMultiplier, mShowcaseRadius);
    }

    // Draw the text on the screen, recalculating its position if necessary
    if (recalculateText) {
      mTextDrawer.calculateTextPosition(canvas.getWidth(), canvas.getHeight(), this);
    }
    mTextDrawer.draw(canvas, recalculateText);

    super.dispatchDraw(canvas);
  }
 public final boolean draw(Canvas canvas, float left, float top, Paint paint) {
   if (bitmapArray != null) {
     for (int i = 0; i < bitmapArray.length; i++) {
       for (int j = 0; j < bitmapArray[i].length; j++) {
         Bitmap bmp = bitmapArray[i][j];
         if (bmp != null && !bmp.isRecycled()) {
           float dleft = left + j * bmp.getWidth();
           if (dleft > canvas.getWidth() || dleft + bmp.getWidth() < 0) {
             continue;
           }
           float dtop = top + i * bmp.getHeight();
           if (dtop > canvas.getHeight() || dtop + bmp.getHeight() < 0) {
             continue;
           }
           canvas.drawBitmap(bmp, dleft, dtop, paint);
         }
       }
     }
     return true;
   } else if (bitmap != null && !bitmap.isRecycled()) {
     canvas.drawBitmap(bitmap, left, top, paint);
     return true;
   }
   return false;
 }
Пример #14
0
  public void Down() {
    width = refCanvas.getWidth();
    height = refCanvas.getHeight();

    m.setRotate(degree);

    refCanvas.drawBitmap(
        Bitmap.createBitmap(panda, 0, 0, panda.getWidth(), panda.getHeight(), m, false),
        x,
        y,
        null);

    y += 20;
    degree += 15;
    if (degree > 360) degree -= 360;
    if (y > height && state == 3) {
      y = 0;
      state = 4;
    }
    if (y > height * 3 / 4 && state == 4) {
      wind.stop();
      wind = new MediaPlayer();
      wind = MediaPlayer.create(cont, R.raw.splash);
      wind.start();
      state = 5;
      long time = System.currentTimeMillis();
      while (System.currentTimeMillis() < time + 1000) ;
    }
  }
  /** Draws the generated bitmap to the canvas */
  public void run() {
    mThreadRun = true;
    while (mThreadRun) {
      Bitmap bmp = null;

      synchronized (this) {
        try {
          this.wait();
          bmp = processFrame(mFrame);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      if (bmp != null) {
        Canvas canvas = mHolder.lockCanvas();
        if (canvas != null) {
          canvas.drawBitmap(
              bmp,
              (canvas.getWidth() - getFrameWidth()) / 2,
              (canvas.getHeight() - getFrameHeight()) / 2,
              null);
          mHolder.unlockCanvasAndPost(canvas);
        }
        bmp.recycle();
      }
    }
  }
Пример #16
0
  public static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;

    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
      if (bitmapDrawable.getBitmap() != null) {
        return bitmapDrawable.getBitmap();
      }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
      bitmap =
          Bitmap.createBitmap(
              1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
    } else {
      bitmap =
          Bitmap.createBitmap(
              drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
  }
Пример #17
0
  // rotates the map according to bearing
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (bearing >= 0) // if the bearing is greater than 0
    {
      // get canvas dimensions
      int canvasWidth = canvas.getWidth();
      int canvasHeight = canvas.getHeight();

      // dimensions of the scaled canvas
      int width = scale;
      int height = scale;

      // center of scaled canvas
      int centerXScaled = width / 2;
      int centerYScaled = height / 2;

      // center of screen canvas
      int centerX = canvasWidth / 2;
      int centerY = canvasHeight / 2;

      // move center of scaled area to center of actual screen
      canvas.translate(-(centerXScaled - centerX), -(centerYScaled - centerY));

      // rotate around center of screen
      canvas.rotate(-bearing, centerXScaled, centerYScaled);
    } // end if

    super.dispatchDraw(canvas); // draw child Views of this layout
  } // end method dispatchDraw
  // TODO control the width of the image so no exceed the layout width
  private Bitmap composeImage(int maxHeight) {
    Bitmap source = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
    int rgbAvg[] = getAverageColorRGB(source);
    Log.d(TAG, "Avg color = " + rgbAvg);
    String nearestColor = Colors.nearestMaterialColor(Color.rgb(rgbAvg[0], rgbAvg[1], rgbAvg[2]));
    Log.d(TAG, "nearestColor = " + nearestColor);
    int complColor = Colors.getMaterialColor(Colors.complementMaterialColor(nearestColor));
    Log.d(TAG, "complColor = " + Colors.complementMaterialColor(nearestColor));

    double ratio = source.getWidth() / (double) source.getHeight();

    int newWidth = (int) (ratio * maxHeight);
    Matrix matrix = new Matrix();
    matrix.postTranslate(5, 5);
    matrix.postScale(
        ((float) newWidth) / source.getWidth(), ((float) maxHeight) / source.getHeight());

    // TODO use dp instead of px in the image border
    Bitmap imageBitmap =
        Bitmap.createBitmap(newWidth + 10, maxHeight + 10, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(imageBitmap);
    Paint paintComp = new Paint();
    paintComp.setStyle(Paint.Style.FILL);
    paintComp.setAntiAlias(true);
    paintComp.setColor(complColor);
    Path path = getRoundedRectPath(0, 0, canvas.getWidth(), canvas.getHeight(), 5, 5);
    canvas.drawPath(path, paintComp);
    canvas.drawBitmap(source, matrix, null);

    return imageBitmap;
  }
Пример #19
0
 // DIRECT repaint method
 public void repaint2() {
   Canvas c = null;
   try {
     c = getHolder().lockCanvas();
     if (c != null) {
       // enable anti-aliasing
       c.setDrawFilter(new PaintFlagsDrawFilter(1, Paint.ANTI_ALIAS_FLAG));
       // clean background
       Paint paint = new Paint();
       paint.setColor(drawable.getBackground().getAndroidColor());
       c.drawRect(0, 0, c.getWidth(), c.getHeight(), paint);
       // set dimensions
       drawable.setWidth(getWidth());
       drawable.setHeight(getHeight());
       // do the drawing
       drawable.draw(new Graphics(c));
     }
   } catch (Exception e) {
     // ignore
   } finally {
     if (c != null) {
       getHolder().unlockCanvasAndPost(c);
     }
   }
 }
Пример #20
0
  /**
   * The graphical representation of a path.
   *
   * @param canvas the canvas to paint to
   * @param points the points that are contained in the path to paint
   * @param paint the paint to be used for painting
   * @param circular if the path ends with the start point
   */
  protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) {
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

    float[] tempDrawPoints;
    if (points.length < 4) {
      return;
    }
    tempDrawPoints = calculateDrawPoints(points[0], points[1], points[2], points[3], height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);

    for (int i = 4; i < points.length; i += 2) {
      if ((points[i - 1] < 0 && points[i + 1] < 0)
          || (points[i - 1] > height && points[i + 1] > height)) {
        continue;
      }
      tempDrawPoints =
          calculateDrawPoints(
              points[i - 2], points[i - 1], points[i], points[i + 1], height, width);
      if (!circular) {
        path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
      }
      path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
      path.lineTo(points[0], points[1]);
    }
    canvas.drawPath(path, paint);
  }
Пример #21
0
  @Override
  public void onDraw(Canvas canvas) {
    loadBitmap();

    if (image != null) {
      shader =
          new BitmapShader(
              Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false),
              Shader.TileMode.CLAMP,
              Shader.TileMode.CLAMP);
      paint.setShader(shader);
      int circleCenter = viewWidth / 2;

      canvas.drawCircle(
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          circleCenter + borderWidth - 4.0f,
          paintBorder);

      if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
          == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        canvas.drawCircle(
            circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 2.0f, paint);

      } else {
        canvas.drawCircle(
            circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint);
      }

      //			canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter -
      // 4.0f, paint);
    }
  }
Пример #22
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    final int saveCount = canvas.save();

    final Matrix m = mController.getEffectsMatrix();
    if (!m.isIdentity()) canvas.concat(m);

    final float alpha = mController.getEffectsAlpha();
    if (alpha != 1f)
      canvas.saveLayerAlpha(
          0,
          0,
          canvas.getWidth(),
          canvas.getHeight(),
          (int) (255 * alpha),
          Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);

    super.dispatchDraw(canvas);

    final int fadeFactor = mController.getFadeFactor();
    if (fadeFactor > 0f) {
      mFadePaint.setColor(Color.argb(fadeFactor, 0, 0, 0));
      canvas.drawRect(0, 0, getWidth(), getHeight(), mFadePaint);
    }

    canvas.restoreToCount(saveCount);
  }
  public void run() {
    Log.i(TAG, "Starting processing thread");
    while (true) {
      Bitmap bmp = null;

      synchronized (this) {
        if (mCamera == null) break;

        if (!mCamera.grab()) {
          Log.e(TAG, "mCamera.grab() failed");
          break;
        }

        bmp = processFrame(mCamera);
      }

      if (bmp != null) {
        Canvas canvas = mHolder.lockCanvas();
        if (canvas != null) {
          canvas.drawBitmap(
              bmp,
              (canvas.getWidth() - bmp.getWidth()) / 2,
              (canvas.getHeight() - bmp.getHeight()) / 2,
              null);
          mHolder.unlockCanvasAndPost(canvas);
        }
        //                bmp.recycle();
      }
    }

    Log.i(TAG, "Finishing processing thread");
  }
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {
    switch (this.showViewTypeEnum) {
      case Download_Status: // 下载状态
        drawOnSuccessfulConnect(canvas, true);
        break;
      case Suspended_state: // 暂停状态
        drawOnSuccessfulConnect(canvas, false);
        break;
      case Networking_status: // 联网状态
        canvas.rotate(degress, canvas.getWidth() / 2, canvas.getHeight() / 2);
        degress += 10;
        drawOnConnecting(canvas);

        Timer timer = new Timer();
        timer.schedule(
            new TimerTask() {
              @Override
              public void run() {
                handler.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        CircleProgressBar.this.invalidate();
                      }
                    });
              }
            },
            25);
        break;
      default:
        break;
    }
  }
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int count = mPagesCount;
    if (count == 0) {
      return;
    }
    float cx = canvas.getWidth() >> 1;
    float cy = canvas.getHeight() >> 1;
    int totalCount = 2 * count - 1;
    int halfCount = totalCount / 2;
    float itemWithOffset = mIndicatorElementSize + mIndicatorElementSpacing;
    float halfItemWithOffset = mIndicatorElementSize / 2 + mIndicatorElementSpacing;
    float halfSize = mIndicatorElementSize / 2f;
    float halfSpacing = mIndicatorElementSpacing / 2f;
    float startX = cx - halfCount * (mIndicatorElementSize + mIndicatorElementSpacing);
    float top = cy - halfSize;
    float bottom = cy + halfSize;
    // if we have odd elements - need to set indicators in center
    if (totalCount % 2 != 0) {
      startX -= halfSize + halfSpacing;
    }

    int i;
    for (i = 0; i < totalCount; i++) {
      // skip empty spaces
      if (i % 2 != 0) {
        continue;
      }
      float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * i;
      float right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      mRenderer.draw(canvas, mElementBounds, mIndicatorPaint, false);
    }

    // multiply on 2 because there are spaces between elements
    float activeItemOffset = (mSelectedPosition + mScrolledOffset) * 2;
    float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * activeItemOffset;
    float right = left + mIndicatorElementSize;
    mElementBounds.set(left, top, right, bottom);

    canvas.clipRect(mClipBounds);

    canvas.save();
    canvas.rotate(ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
    mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
    canvas.restore();

    if (mIsInfiniteScroll && mSelectedPosition == mPagesCount - 1) { // isInfinite && isEnd
      activeItemOffset = (1f - mScrolledOffset) * 2;
      left = mClipBounds.left - itemWithOffset * activeItemOffset + halfItemWithOffset;
      right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      canvas.save();
      canvas.rotate(
          ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
      mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
      canvas.restore();
    }
  }
Пример #26
0
    @Override
    /** Draw the UAV, the position desired, and the camera POI */
    protected void onDraw(Canvas canvas) {
      draw(
          canvas,
          R.drawable.map_positioner_uav,
          (int) m_to_px(this, pos_x),
          (int) m_to_px(this, pos_y));
      draw(
          canvas,
          R.drawable.map_positioner_waypoint,
          (int) m_to_px(this, desired_x),
          (int) -m_to_px(this, desired_y));
      // draw(canvas, R.drawable.map_positioner_poi, (int) m_to_px(this, poi_x), (int)
      // -m_to_px(this, poi_y));

      // Annotate the desired position
      canvas.drawText(
          "("
              + String.format("%.1f", desired_x)
              + ","
              + String.format("%.1f", desired_y)
              + ","
              + String.format("%.1f", desired_z)
              + ")",
          m_to_px(this, desired_x) + canvas.getWidth() / 2 + 25,
          -m_to_px(this, desired_y) + canvas.getHeight() / 2,
          paint);
    }
Пример #27
0
  @SuppressLint("DrawAllocation")
  @Override
  public void onDraw(Canvas canvas) {
    // load the bitmap
    loadBitmap();

    // init shader
    if (image != null) {
      shader =
          new BitmapShader(
              Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false),
              Shader.TileMode.CLAMP,
              Shader.TileMode.CLAMP);
      paint.setShader(shader);
      int circleCenter = viewWidth / 2;

      // circleCenter is the x or y of the view's center
      // radius is the radius in pixels of the cirle to be drawn
      // paint contains the shader that will texture the shape
      canvas.drawCircle(
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          paintBorder);
      canvas.drawCircle(
          circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paint);
    }
  }
 @Override
 public void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   if (mService.isScrimSrcModeEnabled()) {
     // We need to ensure that our window is always drawn fully even when we have paddings,
     // since we simulate it to be opaque.
     int paddedBottom = getHeight() - getPaddingBottom();
     int paddedRight = getWidth() - getPaddingRight();
     if (getPaddingTop() != 0) {
       canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
     }
     if (getPaddingBottom() != 0) {
       canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
     }
     if (getPaddingLeft() != 0) {
       canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom, mTransparentSrcPaint);
     }
     if (getPaddingRight() != 0) {
       canvas.drawRect(
           paddedRight, getPaddingTop(), getWidth(), paddedBottom, mTransparentSrcPaint);
     }
   }
   if (DEBUG) {
     Paint pt = new Paint();
     pt.setColor(0x80FFFF00);
     pt.setStrokeWidth(12.0f);
     pt.setStyle(Paint.Style.STROKE);
     canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
   }
 }
Пример #29
0
  private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
      return null;
    }

    if (drawable instanceof BitmapDrawable) {
      return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
      Bitmap bitmap;

      if (drawable instanceof ColorDrawable) {
        bitmap =
            Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
      } else {
        bitmap =
            Bitmap.createBitmap(
                drawable.getIntrinsicWidth() + 1, drawable.getIntrinsicHeight() + 1, BITMAP_CONFIG);
      }

      Canvas canvas = new Canvas(bitmap);
      drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
      drawable.draw(canvas);
      return bitmap;
    } catch (OutOfMemoryError e) {
      return null;
    }
  }
 /*
  * Drawing
  */
 @Override
 public void draw(Canvas canvas) {
   final boolean positionChanged = adapterPositionChanged();
   if (rippleOverlay) {
     if (!positionChanged) {
       rippleBackground.draw(canvas);
     }
     super.draw(canvas);
     if (!positionChanged) {
       if (rippleRoundedCorners != 0) {
         Path clipPath = new Path();
         RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
         clipPath.addRoundRect(
             rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
         canvas.clipPath(clipPath);
       }
       canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
     }
   } else {
     if (!positionChanged) {
       rippleBackground.draw(canvas);
       canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
     }
     super.draw(canvas);
   }
 }