コード例 #1
0
ファイル: DialogView.java プロジェクト: johack0/telegram
  private void drawPlaceHolder(Canvas canvas) {
    placeholderPaint.setColor(layout.placeHolderColor);

    placeholderTextPaint.setAlpha(255);
    placeholderPaint.setAlpha(255);
    avatarPaint.setAlpha(255);

    rect.set(
        layout.layoutAvatarLeft,
        layout.layoutAvatarTop,
        layout.layoutAvatarLeft + layout.layoutAvatarWidth,
        layout.layoutAvatarTop + layout.layoutAvatarWidth);

    canvas.drawRect(rect, placeholderPaint);
    if (layout.usePlaceholder) {
      canvas.drawText(
          layout.placeHolderName,
          layout.placeholderLeft,
          layout.placeholderTop,
          placeholderTextPaint);
    } else {
      rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight());
      canvas.drawBitmap(placeholder, rect2, rect, avatarPaint);
    }
  }
コード例 #2
0
  /** draws the hole in the center of the chart and the transparent circle / hole */
  protected void drawHole(Canvas c) {

    if (mChart.isDrawHoleEnabled()) {

      float transparentCircleRadius = mChart.getTransparentCircleRadius();
      float holeRadius = mChart.getHoleRadius();
      float radius = mChart.getRadius();

      PointF center = mChart.getCenterCircleBox();

      // only draw the circle if it can be seen (not covered by the hole)
      if (transparentCircleRadius > holeRadius) {

        // get original alpha
        int alpha = mTransparentCirclePaint.getAlpha();
        mTransparentCirclePaint.setAlpha(
            (int) ((float) alpha * mAnimator.getPhaseX() * mAnimator.getPhaseY()));

        // draw the transparent-circle
        mBitmapCanvas.drawCircle(
            center.x, center.y, radius / 100 * transparentCircleRadius, mTransparentCirclePaint);

        // reset alpha
        mTransparentCirclePaint.setAlpha(alpha);
      }

      // draw the hole-circle
      mBitmapCanvas.drawCircle(center.x, center.y, radius / 100 * holeRadius, mHolePaint);
    }
  }
コード例 #3
0
  protected void onDraw(Canvas canvas) {
    int paintSize = ApplicationManager.getPaintSize();
    boolean showPaintSize = ApplicationManager.isShowPaintSize();
    if (paintSize > 0 && showPaintSize) {
      paint.setAlpha(100);
      canvas.drawCircle(CX, CY, paintSize / 2, paint);
      paint.setAlpha(50);
      canvas.drawCircle(CX, CY, (int) (paintSize / (1.5)), paint);
    }

    /*
    paint.setAlpha(255);
    paint.setTypeface(FontFactory.getFont1(getContext()));
    paint.setTextSize(20f);
    canvas.drawText("Choose your color here", 10, 20,paint);
    */

    // Immagini ai bordi
    /*
    if(lt != null) {
    	canvas.drawBitmap(lt, 0,0, paint);
    }
    if(lb != null) {
    	canvas.drawBitmap(lb, 0,SCREEN_HEIGHT-CORNER_DIM, paint);
    }
    if(rt != null) {
    	canvas.drawBitmap(rt, SCREEN_WIDTH-CORNER_DIM,0, paint);
    }
    if(rb != null) {
    	canvas.drawBitmap(rb, SCREEN_WIDTH-CORNER_DIM,SCREEN_HEIGHT-CORNER_DIM, paint);
    }
    */
  }
コード例 #4
0
  private void createCompassFramePicture() {
    // The inside of the compass is white and transparent
    final Paint innerPaint = new Paint();
    innerPaint.setColor(Color.WHITE);
    innerPaint.setAntiAlias(true);
    innerPaint.setStyle(Style.FILL);
    innerPaint.setAlpha(200);

    // The outer part (circle and little triangles) is gray and transparent
    final Paint outerPaint = new Paint();
    outerPaint.setColor(Color.GRAY);
    outerPaint.setAntiAlias(true);
    outerPaint.setStyle(Style.STROKE);
    outerPaint.setStrokeWidth(2.0f);
    outerPaint.setAlpha(200);

    final int picBorderWidthAndHeight = (int) ((mCompassRadius + 5) * 2 * mScale);
    final int center = picBorderWidthAndHeight / 2;

    mCompassFrameBitmap =
        Bitmap.createBitmap(picBorderWidthAndHeight, picBorderWidthAndHeight, Config.ARGB_8888);
    final Canvas canvas = new Canvas(mCompassFrameBitmap);

    // draw compass inner circle and border
    canvas.drawCircle(center, center, mCompassRadius * mScale, innerPaint);
    canvas.drawCircle(center, center, mCompassRadius * mScale, outerPaint);

    // Draw little triangles north, south, west and east (don't move)
    // to make those move use "-bearing + 0" etc. (Note: that would mean to draw the triangles
    // in the onDraw() method)
    drawTriangle(canvas, center, center, mCompassRadius * mScale, 0, outerPaint);
    drawTriangle(canvas, center, center, mCompassRadius * mScale, 90, outerPaint);
    drawTriangle(canvas, center, center, mCompassRadius * mScale, 180, outerPaint);
    drawTriangle(canvas, center, center, mCompassRadius * mScale, 270, outerPaint);
  }
コード例 #5
0
  /**
   * Doing effects, etc, that we don't need to do every draw()
   *
   * @param bitmap
   */
  private void setAndPreprocessBitmap(Bitmap bitmap) {
    if (bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) return;
    // if (waveform != null && waveform != bitmap) waveform.recycle();
    waveform = bitmap;

    int scaledWidth = width * 2;
    int scaledHeight = height; // no change here.
    int clippedWidth = getScaledWidth(scaledWidth, bitmap);
    Bitmap clipped = clipBitmap(bitmap, clippedWidth);

    Bitmap canvasbmp = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(canvasbmp);
    Rect canvasrect = canvas.getClipBounds();
    Rect clippedrect = new Rect(0, 0, clipped.getWidth(), clipped.getHeight());

    paint.setFilterBitmap(true);
    paint.setAlpha(120);
    canvas.drawBitmap(makeBlurry(bitmap, 3), clippedrect, canvasrect, paint);
    paint.setFilterBitmap(false);
    paint.setAlpha(180);
    canvas.drawBitmap(bitmap, clippedrect, canvasrect, paint);

    oldProcessedWaveform = processedWaveform;
    processedWaveform = canvasbmp;
    timeSinceTransition = System.currentTimeMillis();
    // if (oldwaveform != null) oldwaveform.recycle();
    clipped.recycle();
  }
コード例 #6
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    mPaint.setXfermode(null);
    mPaint.setAlpha(0xFF);

    switch (item.getItemId()) {
      case COLOR_MENU_ID:
        new ColorPickerDialog(this, this, mPaint.getColor()).show();
        return true;
      case EMBOSS_MENU_ID:
        if (mPaint.getMaskFilter() != mEmboss) {
          mPaint.setMaskFilter(mEmboss);
        } else {
          mPaint.setMaskFilter(null);
        }
        return true;
      case BLUR_MENU_ID:
        if (mPaint.getMaskFilter() != mBlur) {
          mPaint.setMaskFilter(mBlur);
        } else {
          mPaint.setMaskFilter(null);
        }
        return true;
      case ERASE_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        return true;
      case SRCATOP_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        mPaint.setAlpha(0x80);
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
コード例 #7
0
ファイル: GameActivity.java プロジェクト: Xayvay/BombSurge
  public static void surgeTimer() {
    if (surger >= 1) {
      snowmanHit = true;
      dimblue.setAlpha(50);
      rateInc = rateInc - timeSurge;

    } else {
      boltHit = true;
      dimyellow.setAlpha(50);
      rateInc = GameActivity.rateInc + timeSurge;
    }

    surgeHit = false;
    CountDownTimer surgtimer =
        new CountDownTimer(11000, 1000) {

          public void onTick(long millisUntilFinished) {}

          public void onFinish() {
            if (boltHit == true) {
              GameActivity.rateInc = GameActivity.rateInc - timeSurge;
            } else {
              GameActivity.rateInc = GameActivity.rateInc + timeSurge;
            }

            boltHit = false;
            snowmanHit = false;
            dimblue.setAlpha(0);
            dimyellow.setAlpha(0);
          }
        }.start();
  }
コード例 #8
0
 @Override
 public void setAlpha(int alpha) {
   mArcPaint.setAlpha(alpha);
   mBackgroundArcPaint.setAlpha(alpha);
   mForegroundCirclePaint.setAlpha(alpha);
   mTextPaint.setAlpha(alpha);
 }
コード例 #9
0
ファイル: DragView.java プロジェクト: norain2050/daima111
  @Override
  protected void onDraw(Canvas canvas) {
    @SuppressWarnings("all")
    // suppress dead code warning
    final boolean debug = false;
    if (debug) {
      Paint p = new Paint();
      p.setStyle(Paint.Style.FILL);
      p.setColor(0x66ffffff);
      canvas.drawRect(0, 0, getWidth(), getHeight(), p);
    }

    mHasDrawn = true;
    boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null;
    if (crossFade) {
      int alpha = crossFade ? (int) (255 * (1 - mCrossFadeProgress)) : 255;
      mPaint.setAlpha(alpha);
    }
    canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
    if (crossFade) {
      mPaint.setAlpha((int) (255 * mCrossFadeProgress));
      canvas.save();
      float sX = (mBitmap.getWidth() * 1.0f) / mCrossFadeBitmap.getWidth();
      float sY = (mBitmap.getHeight() * 1.0f) / mCrossFadeBitmap.getHeight();
      canvas.scale(sX, sY);
      canvas.drawBitmap(mCrossFadeBitmap, 0.0f, 0.0f, mPaint);
      canvas.restore();
    }
  }
コード例 #10
0
  @Override
  protected void onDraw(Canvas canvas) {
    int centerX = getRootView().getWidth() / 2 - (int) (mPaint.getStrokeWidth() / 2);
    float r = CENTER_X - mPaint.getStrokeWidth() * 0.5f;

    canvas.translate(centerX, CENTER_Y);

    canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
    canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);

    if (mTrackingCenter) {
      int c = mCenterPaint.getColor();
      mCenterPaint.setStyle(Paint.Style.STROKE);

      if (mHighlightCenter) {
        mCenterPaint.setAlpha(0xFF);
      } else {
        mCenterPaint.setAlpha(0x80);
      }
      canvas.drawCircle(0, 0, CENTER_RADIUS + mCenterPaint.getStrokeWidth(), mCenterPaint);

      mCenterPaint.setStyle(Paint.Style.FILL);
      mCenterPaint.setColor(c);
    }
  }
コード例 #11
0
  public boolean draw(GUIDrawingArea drawarea, Canvas canvas) {
    float timeDiffPercent = (float) (GUIGame.currentTime - end_time) / FADE_DELAY;
    int opa = (int) (Tools.MAX_OPA * (1 - timeDiffPercent));
    opa = (opa < 0) ? 0 : (opa > Tools.MAX_OPA) ? Tools.MAX_OPA : opa;
    if (opa > 0) {
      if (!missed) {
        float timeDiffPercentCircle = (float) (GUIGame.currentTime - circle_time) / FADE_DELAY;
        int opac = (int) (Tools.MAX_OPA * (1 - timeDiffPercentCircle));
        opac = (opa < 0) ? 0 : (opac > Tools.MAX_OPA) ? Tools.MAX_OPA : opac;
        if (opac > 0) {
          int radius = Tools.button_h / 2;
          if (timeDiffPercentCircle >= 0) {
            radius *= (1 + timeDiffPercentCircle * 0.8);
          }
          circlePaint.setAlpha(opac);
          canvas.drawCircle(cx, cy, radius, circlePaint);
        }
      }

      fadePaint.setAlpha(opa);
      canvas.drawBitmap(
          drawarea.getBitmap(
              missed ? "/osu/osu_beat_miss.png" : "/osu/osu_beat_hit.png",
              Tools.button_w,
              Tools.button_h),
          x,
          y,
          fadePaint);
      return true;
    } else {
      return false;
    }
  }
コード例 #12
0
ファイル: CircleView.java プロジェクト: GermainZ/AcDisplay
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    final float ratio = calculateRatio();
    float radius;

    // Darkening background
    canvas.drawColor(Color.argb((int) (200 * calculateRatio()), 0, 0, 0));

    if (mRadiusAimed) {

      // Indicate that target radius is aimed.
      mPaint.setAlpha(35);
      radius = (float) Math.sqrt(mRadius / 70) * 70;
      canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint);
    }

    // Draw unlock circle
    mPaint.setAlpha((int) (255 * Math.pow(ratio, 0.33f)));
    radius = (float) Math.sqrt(mRadius / 50) * 50;
    canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint);

    // Draw unlock icon at the center of circle
    float scale = 0.5f + 0.5f * ratio;
    canvas.save();
    canvas.translate(
        mPoint[0] - mDrawable.getMinimumWidth() / 2 * scale,
        mPoint[1] - mDrawable.getMinimumHeight() / 2 * scale);
    canvas.scale(scale, scale);
    mDrawable.draw(canvas);
    canvas.restore();
  }
コード例 #13
0
ファイル: GeoTrackOverlay.java プロジェクト: hsujm/android
  private void initDirectionPaint(int c) {
    // Text
    mPaint = new Paint();
    mPaint.setColor(c);
    mPaint.setAlpha(100);
    mPaint.setStyle(Style.STROKE);
    mPaint.setStrokeWidth(3);
    // Geo Point
    mGeoPointPaint = new Paint();
    mGeoPointPaint.setAntiAlias(true);
    mGeoPointPaint.setColor(c);
    mGeoPointPaint.setStyle(Style.FILL_AND_STROKE);
    mGeoPointPaint.setStrokeWidth(3);
    // Geo Point
    mGeoPointOldPaint = new Paint(mGeoPointPaint);
    mGeoPointOldPaint.setAlpha(80);

    // Localisation
    mGeoPointAccuracyCirclePaint = new Paint();
    mGeoPointAccuracyCirclePaint.setColor(c);
    mGeoPointAccuracyCirclePaint.setAntiAlias(true);
    mGeoPointAccuracyCirclePaint.setAlpha(50);
    mGeoPointAccuracyCirclePaint.setStyle(Style.FILL);

    mGeoPointAccuracyCirclePaintBorder = new Paint(mGeoPointAccuracyCirclePaint);
    mGeoPointAccuracyCirclePaintBorder.setAlpha(150);
    mGeoPointAccuracyCirclePaintBorder.setStyle(Style.STROKE);
  }
コード例 #14
0
  private void drawTail(Canvas canvas, long timeDiff, long currentTime) {

    final int step = 255 / tail.length;
    int alpha = 255;
    for (Rect tailPoint : tail) {
      fillPaint.setAlpha(alpha);
      canvas.drawRect(bounds, fillPaint);
      canvas.drawRect(tailPoint, fillPaint);
      alpha -= step;
    }
    fillPaint.setAlpha(255);

    taleUpdateTime = 0;
    Rect first = tail[tail.length - 1];
    System.arraycopy(tail, 0, tail, 1, tail.length - 1);
    tail[0] = first;
    tail[0].offsetTo(bounds.left, bounds.top);

    //		if (taleUpdateTime > 50) {
    //			taleUpdateTime = 0;
    //			Rect first = tail[tail.length - 1];
    //			System.arraycopy(tail, 0, tail, 1, tail.length - 1);
    //			tail[0] = first;
    //			tail[0].offsetTo(bounds.left, bounds.top);
    //		} else {
    //			taleUpdateTime += timeDiff;
    //		}
  }
コード例 #15
0
ファイル: ImageTextView.java プロジェクト: yezesong/Albums
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mPaint.setAlpha(120);
        break;
      case MotionEvent.ACTION_MOVE:
        x2 = event.getX();
        y2 = event.getY();
        break;
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        if ((5 <= x2 && mWidth >= x2) && (0 <= y2 && mHeight >= y2)) {
          if (mImageTextViewClick != null) {
            mImageTextViewClick.doClick(mViewId);
          }
        }
        mPaint.setAlpha(240);
        // invalidate();
        break;
        // return true;
    }

    invalidate();
    return true; // super.onTouchEvent(event);
  }
コード例 #16
0
    @Override
    protected void onDraw(Canvas canvas) {
      float r = CENTER_X - mPaint.getStrokeWidth() * 0.5f;

      canvas.translate(CENTER_X, CENTER_X);
      int c = mCenterPaint.getColor();

      if (mRedrawHSV) {
        mHSVColors[1] = c;
        mHSVPaint.setShader(
            new LinearGradient(-100, 0, 100, 0, mHSVColors, null, Shader.TileMode.CLAMP));
      }

      canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
      canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);
      canvas.drawRect(new RectF(-100, 130, 100, 110), mHSVPaint);

      if (mTrackingCenter) {
        mCenterPaint.setStyle(Paint.Style.STROKE);

        if (mHighlightCenter) {
          mCenterPaint.setAlpha(0xFF);
        } else {
          mCenterPaint.setAlpha(0x80);
        }
        canvas.drawCircle(0, 0, CENTER_RADIUS + mCenterPaint.getStrokeWidth(), mCenterPaint);

        mCenterPaint.setStyle(Paint.Style.FILL);
        mCenterPaint.setColor(c);
      }

      mRedrawHSV = true;
    }
コード例 #17
0
  public void draw(Canvas c, float mOffset) {

    c.save();
    c.drawColor(map.getColor());
    if (processedWaveform != null) {
      float offset = mOffset * -(processedWaveform.getWidth() - c.getClipBounds().width());

      long time = System.currentTimeMillis();

      if (time - timeSinceTransition < transitionTime) {
        // transition mode.
        float progress = (float) (time - timeSinceTransition) / (float) transitionTime;
        displaypaint.setAlpha((int) ((1 - progress) * 255));
        long before = System.currentTimeMillis();
        if (oldProcessedWaveform != null)
          c.drawBitmap(oldProcessedWaveform, offset, 0, displaypaint);
        displaypaint.setAlpha((int) (progress * 255));
        c.drawBitmap(processedWaveform, offset, 0, displaypaint);
        long after = System.currentTimeMillis();
        Log.d("WaveformDrawer", "Time to draw transition: " + (after - before));
      } else {
        //        		int ms = Math.abs((int)(time % 5000) - 2500);
        //        		displaypaint.setAlpha(200+ms/50);
        displaypaint.setAlpha(255);
        long before = System.currentTimeMillis();
        c.drawBitmap(processedWaveform, offset, 0, null);
        long after = System.currentTimeMillis();
        Log.d("WaveformDrawer", "Time to draw bitmap: " + (after - before));
      }
    }
    c.restore();
  }
コード例 #18
0
 @Override
 public void setAlpha(int alpha) {
   mPaint1.setAlpha(alpha);
   mPaint2.setAlpha(alpha);
   mPaint3.setAlpha(alpha);
   mPaint4.setAlpha(alpha);
 }
コード例 #19
0
  @Override
  public void onDraw(Canvas canvas) {
    // 中间的扫描框,你要修改扫描框的大小,去CameraManager里面修改
    frame = CameraManager.get().getFramingRect();
    if (frame == null) {
      return;
    }
    if (!isFirst) {
      isFirst = true;
      slideBottom = START_SCAN_Y + frame.width();
    }
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    // 绘制扫描区域外的阴影
    drawScanArea(canvas);
    if (resultBitmap != null) {
      // Draw the opaque result bitmap over the scanning rectangle
      paint.setAlpha(OPAQUE);
      canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
    } else {
      // 绘制扫描区域的四角
      drawArc(canvas);
      // 绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCE
      slideTop += SPEEN_DISTANCE;
      if (slideTop >= slideBottom) {
        slideTop = START_SCAN_Y;
      }
      canvas.drawRect(
          frame.left + MIDDLE_LINE_PADDING,
          slideTop - MIDDLE_LINE_WIDTH / 2,
          frame.right - MIDDLE_LINE_PADDING,
          slideTop + MIDDLE_LINE_WIDTH / 2,
          paint);
      // 画扫描框下面的字
      drawText(canvas);

      Collection<ResultPoint> currentPossible = possibleResultPoints;
      Collection<ResultPoint> currentLast = lastPossibleResultPoints;
      if (currentPossible.isEmpty()) {
        lastPossibleResultPoints = null;
      } else {
        possibleResultPoints = new HashSet<ResultPoint>(5);
        lastPossibleResultPoints = currentPossible;
        paint.setAlpha(OPAQUE);
        paint.setColor(resultPointColor);
        for (ResultPoint point : currentPossible) {
          canvas.drawCircle(frame.left + point.getX(), START_SCAN_Y + point.getY(), 6.0f, paint);
        }
      }
      if (currentLast != null) {
        paint.setAlpha(OPAQUE / 2);
        paint.setColor(resultPointColor);
        for (ResultPoint point : currentLast) {
          canvas.drawCircle(frame.left + point.getX(), START_SCAN_Y + point.getY(), 3.0f, paint);
        }
      }
      // 只刷新扫描框的内容,其他地方不刷新
      postInvalidateDelayed(ANIMATION_DELAY, frame.left, START_SCAN_Y, frame.right, slideBottom);
    }
  }
コード例 #20
0
  /**
   * トランジションの各領域ごとに呼ばれる 吉里吉里は画面を更新するときにいくつかの領域に分割しながら処理を行うので このメソッドは通常、画面更新一回につき複数回呼ばれる
   *
   * @param data には領域や画像に関する情報が入っている
   *     <p>data.Left, data.Top, data.Width, data.Height で示される矩形に のみ転送する必要がある。
   * @throws TJSException
   */
  @Override
  public int process(DivisibleData data) throws TJSException {
    Bitmap dest = (Bitmap) data.Dest.getScanLineForWrite().getImage();
    Bitmap src1 = (Bitmap) data.Src1.getScanLine().getImage();
    Bitmap src2 = (Bitmap) data.Src2.getScanLine().getImage();
    final int bs = mCurBlockSize;
    final int hb = bs / 2;
    final int destLeft = data.DestLeft - hb;
    final int src1Left = data.Src1Left;
    final int src2Left = data.Src2Left;
    final int h = data.Height;
    final int w = data.Width;
    final int destTop = data.DestTop - hb;
    final int src1Top = data.Src1Top;
    final int src2Top = data.Src2Top;
    final int bw = w / bs;
    final int bh = h / bs;

    mPaint.setAlpha(255);
    mSrcRect.set(src1Left, src1Top, src1Left + w, src1Top + h);
    mDstRect.set(0, 0, bw, bh);
    mWorkCanvas.drawBitmap(src1, mSrcRect, mDstRect, mPaint);

    Canvas c = new Canvas(dest);
    mSrcRect.set(0, 0, bw, bh);
    mDstRect.set(destLeft, destTop, destLeft + w, destTop + h);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(bw - 1, 0, bw, bh);
    mDstRect.set(destLeft + w, destTop, destLeft + w + hb, destTop + h);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(0, bh - 1, bw, bh);
    mDstRect.set(destLeft, destTop + h, destLeft + w, destTop + h + hb);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(bw - 1, bh - 1, bw, bh);
    mDstRect.set(destLeft + w, destTop + h, destLeft + w + hb, destTop + h + hb);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);

    mSrcRect.set(src2Left, src2Top, src2Left + w, src2Top + h);
    mDstRect.set(0, 0, bw, bh);
    mWorkCanvas.drawBitmap(src2, mSrcRect, mDstRect, mPaint);

    mPaint.setAlpha(mBlendRatio);
    mSrcRect.set(0, 0, bw, bh);
    mDstRect.set(destLeft, destTop, destLeft + w, destTop + h);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(bw - 1, 0, bw, bh);
    mDstRect.set(destLeft + w, destTop, destLeft + w + hb, destTop + h);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(0, bh - 1, bw, bh);
    mDstRect.set(destLeft, destTop + h, destLeft + w, destTop + h + hb);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    mSrcRect.set(bw - 1, bh - 1, bw, bh);
    mDstRect.set(destLeft + w, destTop + h, destLeft + w + hb, destTop + h + hb);
    c.drawBitmap(mWorkImage, mSrcRect, mDstRect, mPaint);
    c = null;

    return Error.S_OK;
  }
コード例 #21
0
ファイル: ColorPicker.java プロジェクト: hsujm/android
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // Convert coordinates to our internal coordinate system
    float x = event.getX() - mTranslationOffset;
    float y = event.getY() - mTranslationOffset;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // Check whether the user pressed on the pointer.
        float[] pointerPosition = calculatePointerPosition(mAngle);
        if (x >= (pointerPosition[0] - mColorPointerHaloRadius)
            && x <= (pointerPosition[0] + mColorPointerHaloRadius)
            && y >= (pointerPosition[1] - mColorPointerHaloRadius)
            && y <= (pointerPosition[1] + mColorPointerHaloRadius)) {
          mUserIsMovingPointer = true;
          invalidate();
        }
        // Check wheter the user pressed on the center.
        if (x >= -mColorCenterRadius
            && x <= mColorCenterRadius
            && y >= -mColorCenterRadius
            && y <= mColorCenterRadius) {
          mCenterHaloPaint.setAlpha(0x50);
          setColor(getOldCenterColor());
          mCenterNewPaint.setColor(getOldCenterColor());
          invalidate();
        }
        break;
      case MotionEvent.ACTION_MOVE:
        if (mUserIsMovingPointer) {
          mAngle = (float) java.lang.Math.atan2(y, x);
          mPointerColor.setColor(calculateColor(mAngle));

          // Check wheter there is a Saturation/Value bar or/and
          // OpacityBar connected.
          if (mSVbar != null && mOpacityBar == null) {
            mSVbar.setColor(mColor);
          } else if (mSVbar == null && mOpacityBar != null) {
            mOpacityBar.setColor(mColor);
          } else if (mSVbar != null && mOpacityBar != null) {
            mOpacityBar.setColor(mColor);
            mSVbar.setColor(mColor);
          } else {
            setNewCenterColor(mCenterNewColor = calculateColor(mAngle));
          }
          invalidate();
        }
        break;
      case MotionEvent.ACTION_UP:
        mUserIsMovingPointer = false;
        mCenterHaloPaint.setAlpha(0x00);
        invalidate();
        break;
    }
    getParent().requestDisallowInterceptTouchEvent(true);
    return true;
  }
コード例 #22
0
ファイル: BurnText.java プロジェクト: CarlosKweak/HTextView
  @Override
  public void onDraw(Canvas canvas) {
    float offset = startX;
    float oldOffset = oldStartX;

    int maxLength = Math.max(mText.length(), mOldText.length());
    float percent = progress / (charTime + charTime / mostCount * (mText.length() - 1));

    for (int i = 0; i < maxLength; i++) {

      // draw new text
      if (i < mText.length()) {

        if (!CharacterUtils.stayHere(i, differentList)) {

          paint.setAlpha(255);
          paint.setTextSize(textSize);
          float width = paint.measureText(mText.charAt(i) + "");
          canvas.drawText(mText.charAt(i) + "", 0, 1, offset, startY, paint);
          canvas.drawRect(
              offset,
              startY * 1.2f - (1 - percent) * (upDistance + startY * 0.2f),
              offset + gaps[i],
              startY * 1.2f,
              backPaint);
          if (percent < 1) {
            drawSparkle(canvas, offset, startY - (1 - percent) * upDistance, width);
          }
        }
        offset += gaps[i];
      }
      // draw old text
      if (i < mOldText.length()) {
        canvas.save();
        //
        float pp = progress / (charTime + charTime / mostCount * (mText.length() - 1));

        oldPaint.setTextSize(textSize);
        int move = CharacterUtils.needMove(i, differentList);
        if (move != -1) {
          oldPaint.setAlpha(255);
          float p = pp * 7f;
          p = p > 1 ? 1 : p;
          float distX = CharacterUtils.getOffset(i, move, p, startX, oldStartX, gaps, oldGaps);
          canvas.drawText(mOldText.charAt(i) + "", 0, 1, distX, startY, oldPaint);
        } else {

          float p = pp * 3.5f;
          p = p > 1 ? 1 : p;
          oldPaint.setAlpha((int) (255 * (1 - p)));
          canvas.drawText(mOldText.charAt(i) + "", 0, 1, oldOffset, startY, oldPaint);
        }
        oldOffset += oldGaps[i];
      }
    }
  }
コード例 #23
0
  protected void drawMyLocation(
      final Canvas canvas,
      final MapView mapView,
      final Location lastFix,
      final GeoPoint myLocation) {

    final Projection pj = mapView.getProjection();
    pj.toMapPixels(mMyLocation, mMapCoords);

    if (mDrawAccuracyEnabled) {
      final float radius = pj.metersToEquatorPixels(lastFix.getAccuracy());

      mCirclePaint.setAlpha(50);
      mCirclePaint.setStyle(Style.FILL);
      canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, mCirclePaint);

      mCirclePaint.setAlpha(150);
      mCirclePaint.setStyle(Style.STROKE);
      canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, mCirclePaint);
    }

    canvas.getMatrix(mMatrix);
    mMatrix.getValues(mMatrixValues);

    if (DEBUGMODE) {
      final float tx = (-mMatrixValues[Matrix.MTRANS_X] + 20) / mMatrixValues[Matrix.MSCALE_X];
      final float ty = (-mMatrixValues[Matrix.MTRANS_Y] + 90) / mMatrixValues[Matrix.MSCALE_Y];
      canvas.drawText("Lat: " + lastFix.getLatitude(), tx, ty + 5, mPaint);
      canvas.drawText("Lon: " + lastFix.getLongitude(), tx, ty + 20, mPaint);
      canvas.drawText("Cog: " + lastFix.getBearing(), tx, ty + 35, mPaint);
      canvas.drawText("Acc: " + lastFix.getAccuracy(), tx, ty + 50, mPaint);
      canvas.drawText("Kts: " + lastFix.getSpeed() / 1.94384449, tx, ty + 65, mPaint);
    }

    // TODO: read from compass if available for bearing
    if (lastFix.hasBearing()) {
      /*
       * Rotate the direction-Arrow according to the bearing we are driving. And draw it
       * to the canvas.
       */
      directionRotater.setRotate(
          lastFix.getBearing(), DIRECTION_ARROW_CENTER_X, DIRECTION_ARROW_CENTER_Y);

      directionRotater.postTranslate(-DIRECTION_ARROW_CENTER_X, -DIRECTION_ARROW_CENTER_Y);
      directionRotater.postScale(
          1 / mMatrixValues[Matrix.MSCALE_X], 1 / mMatrixValues[Matrix.MSCALE_Y]);
      directionRotater.postTranslate(mMapCoords.x, mMapCoords.y);
      canvas.drawBitmap(DIRECTION_ARROW, directionRotater, mPaint);
    } else {
      directionRotater.setTranslate(-NULLDIRECTION_ICON_CENTER_X, -NULLDIRECTION_ICON_CENTER_Y);
      directionRotater.postScale(
          1 / mMatrixValues[Matrix.MSCALE_X], 1 / mMatrixValues[Matrix.MSCALE_Y]);
      directionRotater.postTranslate(mMapCoords.x, mMapCoords.y);
      canvas.drawBitmap(NULLDIRECTION_ICON, directionRotater, mPaint);
    }
  }
コード例 #24
0
  public Paint setAlpha(boolean isDownloading) { // альфа для стрелочек
    Paint paint = new Paint();
    if (isDownloading) {
      paint.setAlpha(128);
    } else {
      paint.setAlpha(255);
    }

    return paint;
  }
コード例 #25
0
 private void init(Context context) {
   scale = context.getResources().getDisplayMetrics().density;
   polygonBitmap =
       BitmapFactory.decodeResource(context.getResources(), R.drawable.d156_select_region);
   paint.setColor(COLOR);
   paint.setAlpha(ALPHA);
   paint.setAntiAlias(true);
   polygonPaint.setColor(COLOR);
   polygonPaint.setAntiAlias(true);
   polygonPaint.setAlpha(150);
 }
コード例 #26
0
ファイル: TouchView.java プロジェクト: evernote/kgb
  @Override
  protected void onDraw(Canvas canvas) {
    if (paint == null) {
      paint = new Paint();
      textPaint = new Paint();
      textPaint.setTextSize(11);
      textPaint.setTextAlign(Paint.Align.CENTER);
    }

    paint.setColor(Color.RED);
    paint.setAlpha(80);
    for (int row = 0; row < kgb.numRows; row++) {
      canvas.drawLine(
          0,
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding),
          getWidth(),
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding),
          paint);
      canvas.drawLine(
          0,
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding) - kgb.keyHeight,
          getWidth(),
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding) - kgb.keyHeight,
          paint);
    }

    for (KeyInfo keyInfo : kgb.foundKeys.values()) {
      canvas.drawCircle(
          keyInfo.getLocation().getAbsoluteX(),
          keyInfo.getLocation().getAbsoluteY(),
          TOUCH_RADIUS,
          paint);
      canvas.drawText(
          keyInfo.getKey().getCharacter(),
          keyInfo.getLocation().getAbsoluteX(),
          keyInfo.getLocation().getAbsoluteY(),
          textPaint);
    }

    paint.setColor(Color.BLUE);
    long curTime = System.currentTimeMillis();
    for (Iterator<Touch> iterator = touches.iterator(); iterator.hasNext(); ) {
      Touch touch = iterator.next();
      long age = curTime - touch.t;
      if (age > TOUCH_DECAY_MS) {
        iterator.remove();
      } else {
        paint.setAlpha((int) (255 * (1 - ((float) age / TOUCH_DECAY_MS))));
        canvas.drawCircle(touch.x, touch.y, TOUCH_RADIUS, paint);
      }
    }
    // canvas.drawRect(5, 5, getWidth() - 5, getHeight() - 5, paint);
  }
コード例 #27
0
ファイル: FlipView.java プロジェクト: Y-bao/Android
 /**
  * will draw a shade if flipping on the previous(top/left) half and a shine if flipping on the
  * next(bottom/right) half
  *
  * @param canvas
  */
 private void drawFlippingShadeShine(Canvas canvas) {
   final float degreesFlipped = getDegreesFlipped();
   if (degreesFlipped < 90) {
     final int alpha = (int) ((degreesFlipped / 90f) * MAX_SHINE_ALPHA);
     mShinePaint.setAlpha(alpha);
     canvas.drawRect(isFlippingVertically() ? mBottomRect : mRightRect, mShinePaint);
   } else {
     final int alpha = (int) ((Math.abs(degreesFlipped - 180) / 90f) * MAX_SHADE_ALPHA);
     mShadePaint.setAlpha(alpha);
     canvas.drawRect(isFlippingVertically() ? mTopRect : mLeftRect, mShadePaint);
   }
 }
コード例 #28
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);
  }
コード例 #29
0
  @Override
  public void onDraw(Canvas canvas) {
    int viewWidth = getWidth();
    if (viewWidth == 0 || !mIsInitialized) {
      return;
    }

    if (!mDrawValuesReady) {
      mXCenter = getWidth() / 2;
      mYCenter = getHeight() / 2;
      mCircleRadius = (int) (Math.min(mXCenter, mYCenter) * mCircleRadiusMultiplier);

      if (!mIs24HourMode) {
        // We'll need to draw the AM/PM circles, so the main circle will need to have
        // a slightly higher center. To keep the entire view centered vertically, we'll
        // have to push it up by half the radius of the AM/PM circles.
        int amPmCircleRadius = (int) (mCircleRadius * mAmPmCircleRadiusMultiplier);
        mYCenter -= amPmCircleRadius / 2;
      }

      mSelectionRadius = (int) (mCircleRadius * mSelectionRadiusMultiplier);

      mDrawValuesReady = true;
    }

    // Calculate the current radius at which to place the selection circle.
    mLineLength = (int) (mCircleRadius * mNumbersRadiusMultiplier * mAnimationRadiusMultiplier);
    int pointX = mXCenter + (int) (mLineLength * Math.sin(mSelectionRadians));
    int pointY = mYCenter - (int) (mLineLength * Math.cos(mSelectionRadians));

    // Draw the selection circle.
    mPaint.setAlpha(51);
    canvas.drawCircle(pointX, pointY, mSelectionRadius, mPaint);

    if (mForceDrawDot | mSelectionDegrees % 30 != 0) {
      // We're not on a direct tick (or we've been told to draw the dot anyway).
      mPaint.setAlpha(255);
      canvas.drawCircle(pointX, pointY, (mSelectionRadius * 2 / 7), mPaint);
    } else {
      // We're not drawing the dot, so shorten the line to only go as far as the edge of the
      // selection circle.
      int lineLength = mLineLength;
      lineLength -= mSelectionRadius;
      pointX = mXCenter + (int) (lineLength * Math.sin(mSelectionRadians));
      pointY = mYCenter - (int) (lineLength * Math.cos(mSelectionRadians));
    }

    // Draw the line from the center of the circle.
    mPaint.setAlpha(255);
    mPaint.setStrokeWidth(1);
    canvas.drawLine(mXCenter, mYCenter, pointX, pointY, mPaint);
  }
コード例 #30
0
  private void createCompassRosePicture() {
    // Paint design of north triangle (it's common to paint north in red color)
    final Paint northPaint = new Paint();
    northPaint.setColor(0xFFA00000);
    northPaint.setAntiAlias(true);
    northPaint.setStyle(Style.FILL);
    northPaint.setAlpha(220);

    // Paint design of south triangle (black)
    final Paint southPaint = new Paint();
    southPaint.setColor(Color.BLACK);
    southPaint.setAntiAlias(true);
    southPaint.setStyle(Style.FILL);
    southPaint.setAlpha(220);

    // Create a little white dot in the middle of the compass rose
    final Paint centerPaint = new Paint();
    centerPaint.setColor(Color.WHITE);
    centerPaint.setAntiAlias(true);
    centerPaint.setStyle(Style.FILL);
    centerPaint.setAlpha(220);

    // final int picBorderWidthAndHeight = (int) ((mCompassRadius + 5) * 2 * mScale);
    final int picBorderWidthAndHeight = (int) ((mCompassRadius + 5) * 2);
    final int center = picBorderWidthAndHeight / 2;

    final Canvas canvas =
        mCompassRose.beginRecording(picBorderWidthAndHeight, picBorderWidthAndHeight);

    // Blue triangle pointing north
    final Path pathNorth = new Path();
    pathNorth.moveTo(center, center - (mCompassRadius - 3) * mScale);
    pathNorth.lineTo(center + 4 * mScale, center);
    pathNorth.lineTo(center - 4 * mScale, center);
    pathNorth.lineTo(center, center - (mCompassRadius - 3) * mScale);
    pathNorth.close();
    canvas.drawPath(pathNorth, northPaint);

    // Red triangle pointing south
    final Path pathSouth = new Path();
    pathSouth.moveTo(center, center + (mCompassRadius - 3) * mScale);
    pathSouth.lineTo(center + 4 * mScale, center);
    pathSouth.lineTo(center - 4 * mScale, center);
    pathSouth.lineTo(center, center + (mCompassRadius - 3) * mScale);
    pathSouth.close();
    canvas.drawPath(pathSouth, southPaint);

    // Draw a little white dot in the middle
    canvas.drawCircle(center, center, 2, centerPaint);

    mCompassRose.endRecording();
  }