Exemplo n.º 1
0
  private void updateLevel(int level) {
    int animationLevel = level == MAX_LEVEL ? 0 : level;

    int stateForLevel = (int) (animationLevel / MAX_LEVEL_PER_CIRCLE);
    mCurrentState = ProgressStates.values()[stateForLevel];

    resetColor(mCurrentState);
    int levelForCircle = (int) (animationLevel % MAX_LEVEL_PER_CIRCLE);

    boolean halfPassed;
    if (!goesBackward) {
      halfPassed = levelForCircle != (int) (animationLevel % (MAX_LEVEL_PER_CIRCLE / 2));
    } else {
      halfPassed = levelForCircle == (int) (animationLevel % (MAX_LEVEL_PER_CIRCLE / 2));
      levelForCircle = (int) (MAX_LEVEL_PER_CIRCLE - levelForCircle);
    }

    mFstHalfPaint.setColor(fstColor);
    mScndHalfPaint.setColor(scndColor);

    if (!halfPassed) {
      mAbovePaint.setColor(mScndHalfPaint.getColor());
    } else {
      mAbovePaint.setColor(mFstHalfPaint.getColor());
    }

    mAbovePaint.setAlpha(200 + (int) (55 * (levelForCircle / MAX_LEVEL_PER_CIRCLE)));

    mAxisValue =
        (int)
            (mControlPointMinimum
                + (mControlPointMaximum - mControlPointMinimum)
                    * (levelForCircle / MAX_LEVEL_PER_CIRCLE));
  }
    private void drawCircle(Canvas canvas, BatteryTracker tracker, float textX, RectF drawRect) {
      boolean unknownStatus = tracker.status == BatteryManager.BATTERY_STATUS_UNKNOWN;
      int animOffset = tracker.shouldIndicateCharging() ? mAnimOffset : 0;
      int level = tracker.level;
      Paint paint;

      if (unknownStatus) {
        paint = mBackPaint;
        level = 100; // Draw all the circle;
      } else {
        paint = mFrontPaint;
        paint.setColor(getColorForLevel(level));
        if (tracker.status == BatteryManager.BATTERY_STATUS_FULL) {
          level = 100;
        }
      }

      // draw thin gray ring first
      canvas.drawArc(drawRect, 270, 360, false, mBackPaint);
      // draw colored arc representing charge level
      canvas.drawArc(drawRect, 270 + animOffset, 3.6f * level, false, paint);
      // if chosen by options, draw percentage text in the middle
      // always skip percentage when 100, so layout doesnt break
      if (unknownStatus) {
        mTextPaint.setColor(paint.getColor());
        canvas.drawText("?", textX, mTextY, mTextPaint);

      } else if (tracker.shouldIndicateCharging() && (!mShowPercent || level == 100)) {
        // draw the bolt
        final float bl = (int) (drawRect.left + drawRect.width() / 3.2f);
        final float bt = (int) (drawRect.top + drawRect.height() / 4f);
        final float br = (int) (drawRect.right - drawRect.width() / 5.2f);
        final float bb = (int) (drawRect.bottom - drawRect.height() / 8f);
        if (mBoltFrame.left != bl
            || mBoltFrame.top != bt
            || mBoltFrame.right != br
            || mBoltFrame.bottom != bb) {
          mBoltFrame.set(bl, bt, br, bb);
          mBoltPath.reset();
          mBoltPath.moveTo(
              mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
              mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
          for (int i = 2; i < mBoltPoints.length; i += 2) {
            mBoltPath.lineTo(
                mBoltFrame.left + mBoltPoints[i] * mBoltFrame.width(),
                mBoltFrame.top + mBoltPoints[i + 1] * mBoltFrame.height());
          }
          mBoltPath.lineTo(
              mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
              mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
        }
        canvas.drawPath(mBoltPath, mBoltPaint);

      } else if (level < 100 && mShowPercent) {
        mTextPaint.setColor(paint.getColor());
        canvas.drawText(Integer.toString(level), textX, mTextY, mTextPaint);
      }
    }
 public static void previous(
     Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) {
   Path localPath = new Path();
   float f1 = paramInt1 - paramInt3 * 2.0F;
   float f2 = paramInt2 - paramInt3 * 2.0F;
   float f3 = f1 / 10.0F;
   Paint localPaint = new Paint();
   localPaint.setDither(true);
   localPaint.setColor(paramPaint.getColor());
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeWidth(f3);
   float f4 = paramInt3;
   float f5 = f3 / 2.0F;
   float f6 = paramInt3;
   float f7 = paramInt3;
   paramCanvas.drawLine(f5 + f4, f6, f3 / 2.0F + f7, paramInt3 + f2, localPaint);
   localPath.moveTo(paramInt3 + f3, paramInt3 + f2 / 2.0F);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2);
   localPath.lineTo(paramInt3 + f3, paramInt3 + f2 / 2.0F);
   localPath.moveTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   localPath.lineTo(paramInt3 + f1, paramInt3);
   localPath.lineTo(paramInt3 + f1, paramInt3 + f2);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   paramCanvas.drawPath(localPath, paramPaint);
 }
Exemplo n.º 4
0
  @Override
  public void draw(Canvas canvas, Paint paint) {
    // TODO 自动生成的方法存根
    if (isAlive) {
      int color = paint.getColor();

      paint.setColor(Color.BLUE);
      canvas.drawBitmap(
          Config.zombie[farmeIndex / 5], locationX, locationY - Config.deviceHeight / 25, paint);
      if (++farmeIndex > 149) {
        farmeIndex = 0;
      }
      if (stop) {

      } else {
        locationX -= Config.deviceWidth / 1000 * speed;
        if (locationX < 0) {
          isAlive = false;
        }
      }
      paint.setColor(color);

      // 碰撞检测
      GameView.getInstance().checkConllision(this, this.n);
    }
  }
Exemplo n.º 5
0
 @Override
 public void onDraw(Canvas canvas, RectF latlonBounds, RectF tilesRect, DrawSettings nightMode) {
   boolean bold = routeLayer.getHelper().isFollowingMode();
   int color = !nightMode.isNightMode() ? Color.BLACK : Color.BLACK;
   if (paintText.getColor() != color) {
     paintText.setColor(color);
     paintSubText.setColor(color);
     paintSmallText.setColor(color);
     paintSmallSubText.setColor(color);
   }
   if (paintText.isFakeBoldText() != bold) {
     paintText.setFakeBoldText(bold);
     paintSubText.setFakeBoldText(bold);
     paintSmallText.setFakeBoldText(bold);
     paintSmallSubText.setFakeBoldText(bold);
   }
   // update data on draw
   rightStack.updateInfo();
   leftStack.updateInfo();
   if (view.getRotate() != cachedRotate) {
     cachedRotate = view.getRotate();
     compassView.invalidate();
   }
   lanesControl.updateInfo();
   //		topText.setTextColor(color);
   //		String text = "Пр.Независимости";
   //		float ts = topText.getPaint().measureText(text);
   //		int wth = topText.getRight() /*- compassView.getRight()*/;
   //		while(ts > wth && topText.getTextSize() - 1 > 5) {
   //			topText.setTextSize(topText.getTextSize() - 1);
   //			ts = topText.getPaint().measureText(text);
   //		}
   //		topText.setText(text);
 }
  @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);
  }
Exemplo n.º 7
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);
    }
  }
Exemplo n.º 8
0
    @Override
    public void drawLeadingMargin(
        Canvas canvas,
        Paint paint,
        int x,
        int dir,
        int top,
        int baseline,
        int bottom,
        CharSequence charSequence,
        int start,
        int end,
        boolean first,
        Layout layout) {
      int color = paint.getColor();
      float width = paint.getStrokeWidth();

      paint.setColor(COLOR_COMMENT);
      paint.setStrokeWidth(1.0f);
      int xpos = marginText + (marginLine / 2);
      canvas.drawLine(xpos, top, xpos, bottom, paint);

      paint.setStrokeWidth(width);
      paint.setColor(color);
    }
Exemplo n.º 9
0
  @Override
  public void Draw(Canvas canvas, Paint paint) {

    Typeface tf = paint.getTypeface();
    paint.setUnderlineText(underline);
    paint.setTypeface(Typeface.create(tf, style));
    paint.setTextSize(size);
    paint.setStyle(Paint.Style.FILL);

    if (v.currBrushColor != -1) { // draw background rect
      int clr = paint.getColor();
      paint.setColor(v.currBrushColor + v.Opaque);
      canvas.drawRect(
          x - 1,
          y,
          x + paint.measureText(text) + 1,
          y - paint.ascent() + paint.descent() / 2,
          paint);
      paint.setColor(clr);
    }

    canvas.drawText(text, x, y - paint.ascent(), paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setUnderlineText(false);
    paint.setTypeface(tf);
  }
    @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;
    }
  /**
   * Draw this series in the current position calculated by the ValueAnimator.
   *
   * @param canvas Canvas used to draw
   * @param bounds Bounds to be used to draw the arc
   * @return true if drawing has already been handled
   */
  public boolean draw(Canvas canvas, RectF bounds) {
    if (!mVisible) {
      return true;
    }

    if (bounds == null || bounds.isEmpty()) {
      throw new IllegalArgumentException("Drawing bounds can not be null or empty");
    }

    processBoundsChange(bounds);

    if (mDrawMode == DecoEvent.EventType.EVENT_EFFECT) {
      // Delegate the drawing to the ArcEffect as required
      if (mEffect != null) {
        mEffect.draw(canvas, mBoundsInset, mPercentComplete, mAngleStart, mAngleSweep);
      }
      return true;
    }

    processRevealEffect();

    if (mColorAnimate != null) {
      mPaint.setColor(mColorAnimate.getColorCurrent(mPercentComplete));
    } else if (mPaint.getColor() != getSeriesItem().getColor()) {
      mPaint.setColor(getSeriesItem().getColor());
    }

    return false;
  }
 public static void next(
     Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) {
   Object localObject = new Path();
   float f1 = paramInt1 - paramInt3 * 2.0F;
   float f2 = paramInt2 - paramInt3 * 2.0F;
   float f3 = f1 / 10.0F;
   ((Path) localObject).moveTo(paramInt3, paramInt3);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   ((Path) localObject).lineTo(paramInt3, paramInt3 + f2);
   ((Path) localObject).lineTo(paramInt3, paramInt3);
   ((Path) localObject).moveTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3);
   ((Path) localObject).lineTo(paramInt3 + f1 - f3, paramInt3 + f2 / 2.0F);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3 + f2);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3);
   paramCanvas.drawPath((Path) localObject, paramPaint);
   localObject = new Paint();
   ((Paint) localObject).setDither(true);
   ((Paint) localObject).setColor(paramPaint.getColor());
   ((Paint) localObject).setStyle(Paint.Style.STROKE);
   ((Paint) localObject).setStrokeWidth(f3);
   paramCanvas.drawLine(
       paramInt3 + f1 - f3 / 2.0F,
       paramInt3,
       paramInt3 + f1 - f3 / 2.0F,
       f2 + paramInt3,
       (Paint) localObject);
 }
Exemplo n.º 13
0
 @Override
 public List<GraphLabel> getLabelInfoVerticalList() {
   final ArrayList<GraphLabel> graphLabelList = new ArrayList<GraphView.GraphLabel>();
   graphLabelList.add(
       new GraphLabel(signalText, GraphLabel.colorToHex(signalTextPaint.getColor())));
   return graphLabelList;
 }
Exemplo n.º 14
0
  @Test
  @Config(shadows = {ShadowPaintForTests.class})
  public void testNativeMethodsAreDelegated() throws Exception {
    Paint paint = new Paint();
    paint.setColor(1234);

    assertThat(paint.getColor()).isEqualTo(1234);
  }
Exemplo n.º 15
0
  /** Method to fill the screen with a color */
  private void background(int r, int g, int b) {
    int origColor = paint.getColor();

    fill(r, g, b);
    currCanvas.drawRect(0, 0, width, height, paint);

    paint.setColor(origColor);
  }
Exemplo n.º 16
0
  public void setFillColor(int fillColor) {
    boolean changed = fillColor != mFillPaint.getColor();
    mFillPaint.setColor(fillColor);

    if (changed) {
      invalidateSelf();
    }
  }
Exemplo n.º 17
0
  public void setStrokeColor(int strokeColor) {
    boolean changed = strokeColor != mStrokePaint.getColor();
    mStrokePaint.setColor(strokeColor);

    if (changed) {
      invalidateSelf();
    }
  }
 private void a(int paramInt)
 {
   if (paramInt != b.getColor())
   {
     b.setColor(paramInt);
     invalidateSelf();
   }
 }
 @Override
 protected boolean onStateChange(int[] state) {
   int newColor = mBorderColor.getColorForState(state, 0);
   if (mBorderPaint.getColor() != newColor) {
     mBorderPaint.setColor(newColor);
     return true;
   } else {
     return super.onStateChange(state);
   }
 }
Exemplo n.º 20
0
 public void onTrackPropertiesChanged() {
   if (paint.getStrokeWidth() != track.width) {
     paint.setStrokeWidth(track.width);
     preserveWidth = true;
   }
   if (paint.getColor() != track.color) {
     paint.setColor(track.color);
     preserveColor = true;
   }
 }
Exemplo n.º 21
0
 @Override
 protected void dispatchDraw(Canvas canvas) {
   super.dispatchDraw(canvas);
   int offset = (int) Utils.dip2px(getContext(), 5);
   if (mOutlinePaint.getColor() != JazzyViewPager.sOutlineColor) {
     mOutlinePaint.setColor(JazzyViewPager.sOutlineColor);
   }
   mOutlinePaint.setAlpha((int) (mAlpha * 255));
   Rect rect = new Rect(offset, offset, getMeasuredWidth() - offset, getMeasuredHeight() - offset);
   canvas.drawRect(rect, mOutlinePaint);
 }
		/**
		 * (非 Javadoc,覆写的方法) 
		 * @Title: onDraw
		 * @Description:  绘制函数,绘制色环
		 * @param canvas 
		 * @see android.view.View#onDraw(android.graphics.Canvas)
		 */
		@Override
		protected void onDraw(Canvas canvas) {
			//移动中心
            canvas.translate(mWidth / 2, mHeight / 2 - 50);
            //画中心圆
            canvas.drawCircle(0, 0, centerRadius,  mCenterPaint);
            //是否显示中心圆外的小圆环
            if (highlightCenter || highlightCenterLittle) {
                int c = mCenterPaint.getColor();
                mCenterPaint.setStyle(Paint.Style.STROKE);
                if(highlightCenter) {
                	mCenterPaint.setAlpha(0xFF);
                }else if(highlightCenterLittle) {
                	mCenterPaint.setAlpha(0x90);
                }
                canvas.drawCircle(0, 0, 
                		centerRadius + mCenterPaint.getStrokeWidth(),  mCenterPaint);
                
                mCenterPaint.setStyle(Paint.Style.FILL);
                mCenterPaint.setColor(c);
            }
            // 画色环
            canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
            // 画黑白渐变块
            if(downInCircle) {
            	mRectColors[1] = mCenterPaint.getColor();
            }
            rectShader = new LinearGradient(rectLeft, 0, rectRight, 0, mRectColors, null, Shader.TileMode.MIRROR);
            mRectPaint.setShader(rectShader);
            canvas.drawRect(rectLeft, rectTop, rectRight, rectBottom, mRectPaint);
            float offset = mLinePaint.getStrokeWidth() / 2;
            canvas.drawLine(rectLeft - offset, rectTop - offset * 2, 
            		rectLeft - offset, rectBottom + offset * 2, mLinePaint);// 左
            canvas.drawLine(rectLeft - offset * 2, rectTop - offset, 
            		rectRight + offset * 2, rectTop - offset, mLinePaint);	// 上
            canvas.drawLine(rectRight + offset, rectTop - offset * 2, 
            		rectRight + offset, rectBottom + offset * 2, mLinePaint);// 右
            canvas.drawLine(rectLeft - offset * 2, rectBottom + offset, 
            		rectRight + offset * 2, rectBottom + offset, mLinePaint);// 下
			super.onDraw(canvas);
		}
Exemplo n.º 23
0
 private void drawShadowText(Canvas cv, String text, float centerX, float centerY) {
   int c = paintTextIcon.getColor();
   paintTextIcon.setStyle(Style.STROKE);
   paintTextIcon.setColor(Color.WHITE);
   paintTextIcon.setStrokeWidth(2);
   cv.drawText(text, centerX, centerY, paintTextIcon);
   // reset
   paintTextIcon.setStrokeWidth(2);
   paintTextIcon.setStyle(Style.FILL);
   paintTextIcon.setColor(c);
   cv.drawText(text, centerX, centerY, paintTextIcon);
 }
 @Override
 protected boolean onStateChange(int[] stateSet) {
   final int newColor = mBackground.getColorForState(stateSet, mBackground.getDefaultColor());
   final boolean colorChanged = newColor != mPaint.getColor();
   if (colorChanged) {
     mPaint.setColor(newColor);
   }
   if (mTint != null && mTintMode != null) {
     mTintFilter = createTintFilter(mTint, mTintMode);
     return true;
   }
   return colorChanged;
 }
 public static void fullscreen(
     Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) {
   Object localObject = new Path();
   float f1 = paramInt3;
   float f3 = paramInt3;
   float f2;
   if (paramInt1 > paramInt2) {
     f2 = (paramInt1 - paramInt2) / 2.0F;
     f2 = f1 + f2;
     f1 = f3;
   }
   for (; ; ) {
     f3 = paramInt1 - 2.0F * f2;
     float f4 = paramInt2 - 2.0F * f1;
     ((Path) localObject).moveTo(f2, f1);
     ((Path) localObject).lineTo(f3 / 2.0F + f2, f1);
     ((Path) localObject).lineTo(f2, f4 / 2.0F + f1);
     ((Path) localObject).lineTo(f2, f1);
     ((Path) localObject).moveTo(f2 + f3, f4 / 2.0F + f1);
     ((Path) localObject).lineTo(f2 + f3, f1 + f4);
     ((Path) localObject).lineTo(f3 / 2.0F + f2, f1 + f4);
     ((Path) localObject).lineTo(f2 + f3, f4 / 2.0F + f1);
     paramCanvas.drawPath((Path) localObject, paramPaint);
     localObject = new Paint();
     ((Paint) localObject).setDither(true);
     ((Paint) localObject).setColor(paramPaint.getColor());
     ((Paint) localObject).setStyle(Paint.Style.STROKE);
     float f5 = f3 / 5.0F;
     ((Paint) localObject).setStrokeWidth(f5);
     paramCanvas.drawLine(
         f2 + f5,
         f1 + f5,
         f3 / 2.0F + f2 - f5 / 2.0F,
         f4 / 2.0F + f1 - f5 / 2.0F,
         (Paint) localObject);
     float f6 = f3 / 2.0F;
     float f7 = f5 / 2.0F;
     float f8 = f4 / 2.0F;
     paramCanvas.drawLine(
         f2 + f3 - f5, f1 + f4 - f5, f7 + (f6 + f2), f5 / 2.0F + (f8 + f1), (Paint) localObject);
     return;
     if (paramInt2 > paramInt1) {
       f3 += (paramInt2 - paramInt1) / 2.0F;
       f2 = f1;
       f1 = f3;
     } else {
       f2 = f1;
       f1 = f3;
     }
   }
 }
Exemplo n.º 26
0
 private void drawTextOnCanvas(
     Canvas cv, String text, float centerX, float centerY, Paint paint, float textShadow) {
   if (textShadow > 0) {
     int c = paintText.getColor();
     paintText.setStyle(Style.STROKE);
     paintText.setColor(Color.WHITE);
     paintText.setStrokeWidth(2 + textShadow);
     cv.drawText(text, centerX, centerY, paint);
     // reset
     paintText.setStrokeWidth(2);
     paintText.setStyle(Style.FILL);
     paintText.setColor(c);
   }
   cv.drawText(text, centerX, centerY, paint);
 }
Exemplo n.º 27
0
  private void drawDone(Canvas canvas) {

    int beforeColor = mOutPaint.getColor();
    if (getDoneRatio() < 0.3) {
      canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
      int innerY = PULL_HEIGHT - PULL_DELTA / 2 - mRadius * 2;
      canvas.drawCircle(mWidth / 2, innerY, mRadius, mBallPaint);
      int outerR = (int) (mRadius + 10 + 10 * getDoneRatio() / 0.3f);
      int afterColor =
          Color.argb(
              (int) (0xff * (1 - getDoneRatio() / 0.3f)),
              Color.red(beforeColor),
              Color.green(beforeColor),
              Color.blue(beforeColor));
      mOutPaint.setColor(afterColor);
      canvas.drawArc(
          new RectF(mWidth / 2 - outerR, innerY - outerR, mWidth / 2 + outerR, innerY + outerR),
          0,
          360,
          false,
          mOutPaint);
    }
    mOutPaint.setColor(beforeColor);

    if (getDoneRatio() >= 0.3 && getDoneRatio() < 0.7) {
      canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
      float fraction = (getDoneRatio() - 0.3f) / 0.4f;
      int startCentY = PULL_HEIGHT - PULL_DELTA / 2 - mRadius * 2;
      int curCentY = (int) (startCentY + (PULL_DELTA / 2 + mRadius * 2) * fraction);
      canvas.drawCircle(mWidth / 2, curCentY, mRadius, mBallPaint);
      if (curCentY >= PULL_HEIGHT - mRadius * 2) {
        drawTail(canvas, curCentY, PULL_HEIGHT, (1 - fraction));
      }
    }

    if (getDoneRatio() >= 0.7 && getDoneRatio() <= 1) {
      float fraction = (getDoneRatio() - 0.7f) / 0.3f;
      canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
      int leftX = (int) (mWidth / 2 - mRadius - 2 * mRadius * fraction);
      mPath.reset();
      mPath.moveTo(leftX, PULL_HEIGHT);
      mPath.quadTo(
          mWidth / 2, PULL_HEIGHT - (mRadius * (1 - fraction)), mWidth - leftX, PULL_HEIGHT);
      canvas.drawPath(mPath, mBallPaint);
    }
  }
Exemplo n.º 28
0
  public TrackOverlay(final Activity mapActivity, final Track aTrack) {
    this(mapActivity);

    track = aTrack;
    if (track.width > 0) {
      paint.setStrokeWidth(track.width);
      preserveWidth = true;
    } else {
      track.width = (int) paint.getStrokeWidth();
    }
    if (track.color != -1) {
      paint.setColor(track.color);
      preserveColor = true;
    } else {
      track.color = paint.getColor();
    }
  }
Exemplo n.º 29
0
 public void addPoint(double value, boolean isSum, Integer color) {
   if (!isSum) {
     suma -= value;
     super.addPoint(new Point(0, value));
   } else {
     if (points.isEmpty()) {
       suma = value;
     }
     super.addPoint(new Point(0, suma));
   }
   if (color != null) {
     colors.add(color);
   } else {
     colors.add(parentPaint.getColor());
   }
   areSum.add(isSum);
 }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      float x = event.getX() - CENTER_X;
      float y = event.getY() - CENTER_Y;
      boolean inCenter = Math.sqrt(x * x + y * y) <= CENTER_RADIUS;

      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          mTrackingCenter = inCenter;
          if (inCenter) {
            mHighlightCenter = true;
            invalidate();
            break;
          }
        case MotionEvent.ACTION_MOVE:
          if (mTrackingCenter) {
            if (mHighlightCenter != inCenter) {
              mHighlightCenter = inCenter;
              invalidate();
            }
          } else {
            float angle = (float) Math.atan2(y, x);
            // need to turn angle [-PI ... PI] into unit [0....1]
            float unit = angle / (2 * PI);
            if (unit < 0) {
              unit += 1;
            }
            mCenterPaint.setColor(interpColor(mColors, unit));
            invalidate();
          }
          break;
        case MotionEvent.ACTION_UP:
          playSoundEffect(
              SoundEffectConstants.CLICK); // play the default button click (respects prefs)
          if (mTrackingCenter) {
            if (inCenter) {
              mListener.colorChanged(mCenterPaint.getColor());
            }
            mTrackingCenter = false; // so we draw w/o halo
            invalidate();
          }
          break;
      }
      return true;
    }