private Path getLinePath(Canvas canvas, float side, float width) {
   Rect bound = getBounds();
   Path result = new Path();
   result.moveTo(bound.right - side, bound.bottom);
   result.rLineTo(-width, 0f);
   result.lineTo(bound.right, bound.bottom - side - width);
   result.rLineTo(0f, width);
   result.close();
   return result;
 }
  @Override
  public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    final boolean isRtl = isLayoutRtl();
    // Interpolated widths of arrow bars
    final float arrowSize = lerp(mBarSize, mTopBottomArrowSize, mProgress);
    final float middleBarSize = lerp(mBarSize, mMiddleArrowSize, mProgress);
    // Interpolated size of middle bar
    final float middleBarCut = lerp(0, mBarThickness / 2, mProgress);
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(isRtl ? 180 : 0, isRtl ? 0 : 180, mProgress);
    final float topBottomBarOffset = lerp(mBarGap + mBarThickness, 0, mProgress);
    mPath.rewind();

    final float arrowEdge = -middleBarSize / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + middleBarCut, 0);
    mPath.rLineTo(middleBarSize - middleBarCut, 0);

    final float arrowWidth = Math.round(arrowSize * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowSize * Math.sin(rotation));

    // top bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // bottom bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);
    mPath.moveTo(0, 0);
    mPath.close();

    canvas.save();
    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    if (mSpin) {
      canvas.rotate(
          canvasRotate * ((mVerticalMirror ^ isRtl) ? -1 : 1), bounds.centerX(), bounds.centerY());
    } else if (isRtl) {
      canvas.rotate(-180, bounds.centerX(), bounds.centerY());
    }
    canvas.translate(bounds.centerX(), bounds.centerY());
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
  }
 private void buildShadowCorners() {
   Object obj = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
   Object obj1 = new RectF(((RectF) (obj)));
   ((RectF) (obj1)).inset(-mShadowSize, -mShadowSize);
   float f;
   float f1;
   float f2;
   float f3;
   int i;
   int j;
   int k;
   if (mCornerShadowPath == null) {
     mCornerShadowPath = new Path();
   } else {
     mCornerShadowPath.reset();
   }
   mCornerShadowPath.setFillType(android.graphics.Path.FillType.EVEN_ODD);
   mCornerShadowPath.moveTo(-mCornerRadius, 0.0F);
   mCornerShadowPath.rLineTo(-mShadowSize, 0.0F);
   mCornerShadowPath.arcTo(((RectF) (obj1)), 180F, 90F, false);
   mCornerShadowPath.arcTo(((RectF) (obj)), 270F, -90F, false);
   mCornerShadowPath.close();
   f = mCornerRadius / (mCornerRadius + mShadowSize);
   obj = mCornerShadowPaint;
   f1 = mCornerRadius;
   f2 = mShadowSize;
   i = mShadowStartColor;
   j = mShadowStartColor;
   k = mShadowEndColor;
   obj1 = android.graphics.Shader.TileMode.CLAMP;
   ((Paint) (obj))
       .setShader(
           new RadialGradient(
               0.0F,
               0.0F,
               f1 + f2,
               new int[] {i, j, k},
               new float[] {0.0F, f, 1.0F},
               ((android.graphics.Shader.TileMode) (obj1))));
   obj = mEdgeShadowPaint;
   f = -mCornerRadius;
   f1 = mShadowSize;
   f2 = -mCornerRadius;
   f3 = mShadowSize;
   i = mShadowStartColor;
   j = mShadowStartColor;
   k = mShadowEndColor;
   obj1 = android.graphics.Shader.TileMode.CLAMP;
   ((Paint) (obj))
       .setShader(
           new LinearGradient(
               0.0F,
               f + f1,
               0.0F,
               f2 - f3,
               new int[] {i, j, k},
               new float[] {0.0F, 0.5F, 1.0F},
               ((android.graphics.Shader.TileMode) (obj1))));
   mEdgeShadowPaint.setAntiAlias(false);
 }
Example #4
0
  private void parsePath() {
    mPath = new Path();
    char method;

    Scanner in = new Scanner(mPathData);

    while (in.hasNextLine()) {
      // Handle first string, which is a letter indicating which path method to use
      method = in.next().charAt(0);

      switch (method) {
        case 'M':
          mPath.moveTo(in.nextFloat(), in.nextFloat());
          break;
        case 'c':
          mPath.rCubicTo(
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat());
          break;
        case 'C':
          mPath.cubicTo(
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat(),
              in.nextFloat());
          break;
        case 'L':
          mPath.lineTo(in.nextFloat(), in.nextFloat());
          break;
        case 'l':
          mPath.rLineTo(in.nextFloat(), in.nextFloat());
          break;
        case 'z':
          mPath.close();
          break;
      }
    }
  }
Example #5
0
  private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);

    if (mCornerShadowPath == null) {
      mCornerShadowPath = new Path();
    } else {
      mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();

    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(
        new RadialGradient(
            0,
            0,
            mCornerRadius + mShadowSize,
            new int[] {mShadowStartColor, mShadowStartColor, mShadowEndColor},
            new float[] {0f, startRatio, 1f},
            Shader.TileMode.CLAMP));

    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(
        new LinearGradient(
            0,
            -mCornerRadius + mShadowSize,
            0,
            -mCornerRadius - mShadowSize,
            new int[] {mShadowStartColor, mShadowStartColor, mShadowEndColor},
            new float[] {0f, .5f, 1f},
            Shader.TileMode.CLAMP));
  }
  /**
   * This is where the hard-to-parse paths are handled. Uppercase rules are absolute positions,
   * lowercase are relative. Types of path rules:
   *
   * <p>
   *
   * <ol>
   *   <li>M/m - (x y)+ - Move to (without drawing)
   *   <li>Z/z - (no params) - Close path (back to starting point)
   *   <li>L/l - (x y)+ - Line to
   *   <li>H/h - x+ - Horizontal ine to
   *   <li>V/v - y+ - Vertical line to
   *   <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to
   *   <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from
   *       previous C/S is the x1, y1 of this bezier)
   *   <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to
   *   <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection"
   *       of last one w.r.t. to current point)
   * </ol>
   *
   * <p>Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting,
   * (ie. begin with a - sign)
   *
   * @param s the path string from the XML
   */
  private static Path doPath(String s) {
    int n = s.length();
    ParserHelper ph = new ParserHelper(s, 0);
    ph.skipWhitespace();
    Path p = new Path();
    float lastX = 0;
    float lastY = 0;
    float lastX1 = 0;
    float lastY1 = 0;
    float subPathStartX = 0;
    float subPathStartY = 0;
    char prevCmd = 0;
    while (ph.pos < n) {
      char cmd = s.charAt(ph.pos);
      switch (cmd) {
        case '-':
        case '+':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          if (prevCmd == 'm' || prevCmd == 'M') {
            cmd = (char) (((int) prevCmd) - 1);
            break;
          } else if (prevCmd == 'c' || prevCmd == 'C') {
            cmd = prevCmd;
            break;
          } else if (prevCmd == 'l' || prevCmd == 'L') {
            cmd = prevCmd;
            break;
          }
        default:
          {
            ph.advance();
            prevCmd = cmd;
          }
      }

      boolean wasCurve = false;
      switch (cmd) {
        case 'M':
        case 'm':
          {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'm') {
              subPathStartX += x;
              subPathStartY += y;
              p.rMoveTo(x, y);
              lastX += x;
              lastY += y;
            } else {
              subPathStartX = x;
              subPathStartY = y;
              p.moveTo(x, y);
              lastX = x;
              lastY = y;
            }
            break;
          }
        case 'Z':
        case 'z':
          {
            p.close();
            p.moveTo(subPathStartX, subPathStartY);
            lastX = subPathStartX;
            lastY = subPathStartY;
            lastX1 = subPathStartX;
            lastY1 = subPathStartY;
            wasCurve = true;
            break;
          }
        case 'L':
        case 'l':
          {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'l') {
              p.rLineTo(x, y);
              lastX += x;
              lastY += y;
            } else {
              p.lineTo(x, y);
              lastX = x;
              lastY = y;
            }
            break;
          }
        case 'H':
        case 'h':
          {
            float x = ph.nextFloat();
            if (cmd == 'h') {
              p.rLineTo(x, 0);
              lastX += x;
            } else {
              p.lineTo(x, lastY);
              lastX = x;
            }
            break;
          }
        case 'V':
        case 'v':
          {
            float y = ph.nextFloat();
            if (cmd == 'v') {
              p.rLineTo(0, y);
              lastY += y;
            } else {
              p.lineTo(lastX, y);
              lastY = y;
            }
            break;
          }
        case 'C':
        case 'c':
          {
            wasCurve = true;
            float x1 = ph.nextFloat();
            float y1 = ph.nextFloat();
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'c') {
              x1 += lastX;
              x2 += lastX;
              x += lastX;
              y1 += lastY;
              y2 += lastY;
              y += lastY;
            }
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
          }
        case 'S':
        case 's':
          {
            wasCurve = true;
            float x2 = ph.nextFloat();
            float y2 = ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 's') {
              x2 += lastX;
              x += lastX;
              y2 += lastY;
              y += lastY;
            }
            float x1 = 2 * lastX - lastX1;
            float y1 = 2 * lastY - lastY1;
            p.cubicTo(x1, y1, x2, y2, x, y);
            lastX1 = x2;
            lastY1 = y2;
            lastX = x;
            lastY = y;
            break;
          }
        case 'A':
        case 'a':
          {
            float rx = ph.nextFloat();
            float ry = ph.nextFloat();
            float theta = ph.nextFloat();
            int largeArc = (int) ph.nextFloat();
            int sweepArc = (int) ph.nextFloat();
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc);
            lastX = x;
            lastY = y;
            break;
          }
      }
      if (!wasCurve) {
        lastX1 = lastX;
        lastY1 = lastY;
      }
      ph.skipWhitespace();
    }
    return p;
  }
Example #7
0
  // Show(or hide) one view with some effects
  private void showView(int viewId, int delay, int b) {
    View myView = findViewById(viewId);
    final int behavior = b;

    if (android.os.Build.VERSION.SDK_INT >= 21) {

      float x = myView.getX();
      float y = myView.getY();

      Path path1 = new Path();
      Path path2 = new Path();

      // Show with bounce effect
      if (behavior == 0) {
        path1.moveTo(x, y + 100);
        path1.rLineTo(0, -100);
        path2.moveTo(0, 0);
        path2.lineTo(1, 1);
      }
      // Show with bounce effect(and drop from top)
      else if (behavior == 1) {
        path1.moveTo(x, y - 300);
        path1.rLineTo(0, 300);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Show with inflate effect
      else if (behavior == 2) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(10, 10);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 3) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(10, 10);
        path2.lineTo(1, 1);
      }
      // Fade in and float
      else if (behavior == 4) {
        path1.moveTo(x, y + 50);
        path1.rLineTo(0, -50);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Fade out
      else if (behavior == 5) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Hide with deflate effect
      else if (behavior == 6) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(0, 0);
      }
      // Show with inflate effect
      else if (behavior == 7) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(20, 20);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 8) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(20, 20);
        path2.lineTo(1, 1);
      }
      // This effect only used for the flipTimes label
      else if (behavior == 9) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
        path2.lineTo(2, 2);
      }

      ObjectAnimator mAnimator1, mAnimator2, mAnimator3;
      mAnimator1 = ObjectAnimator.ofFloat(myView, View.X, View.Y, path1);
      mAnimator2 = ObjectAnimator.ofFloat(myView, View.SCALE_X, View.SCALE_Y, path2);
      mAnimator1.setDuration(300);
      mAnimator2.setDuration(300);
      mAnimator1.setStartDelay(delay);
      mAnimator2.setStartDelay(delay);

      if (behavior == 0 || behavior == 1) {
        mAnimator1.setInterpolator(new BounceInterpolator());
        mAnimator2.setInterpolator(new BounceInterpolator());
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(10);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 2 || behavior == 7) {
        myView.bringToFront();
        FrameLayout menuLayout = (FrameLayout) findViewById(R.id.menu);
        menuLayout.requestLayout();
        menuLayout.invalidate();

        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.TRANSPARENT);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new AccelerateInterpolator());
        mAnimator2.setInterpolator(new AccelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.WHITE);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay + 200);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 4) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 5) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 6) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 9) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", 1, 0);
        mAnimator2.setDuration(1000);
        mAnimator3.setDuration(1000);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setRepeatCount(Animation.INFINITE);
        mAnimator3.setRepeatCount(Animation.INFINITE);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      }
      if (behavior == 0 || behavior == 1 || behavior == 4) {
        mAnimator1.start();
      }
      mAnimator2.start();

      mAnimator1.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              if (behavior == 0) {
                mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
              }
            }

            @Override
            public void onAnimationEnd(Animator animation) {}

            @Override
            public void onAnimationCancel(Animator animation) {}

            @Override
            public void onAnimationRepeat(Animator animation) {}
          });
    }
    // If the device OS is below Lollipop, the animation feature will be lost
    else {
      if (behavior == 5 || behavior == 6) {
        myView.setAlpha(0);
      } else {
        myView.setAlpha(1);
      }

      if (behavior == 2) {
        myView.setScaleX(10);
        myView.setScaleY(10);
        ((Button) myView).setTextColor(Color.TRANSPARENT);
      } else if (behavior == 3) {
        myView.setScaleX(1);
        myView.setScaleY(1);
        ((Button) myView).setTextColor(Color.WHITE);
      }

      if (behavior == 0) {
        mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
      } else if (behavior == 2 || behavior == 7) {
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 6) {
        mSound.play(mSoundID[SOUND_CLICK], 1, 1, 1, 0, 1);
      }
    }
  }
  @Override
  public void onLoadFinished(Loader<Cursor> ldr, Cursor data) {
    int l = data.getCount();
    data.moveToFirst();
    long maxCents = 0;
    long minCents = Long.MAX_VALUE;
    long maxTime = 0;
    long minTime = Long.MAX_VALUE;
    for (int i = 0; i != l; ++i) {
      long cents = data.getLong(0);
      if (cents > maxCents) maxCents = cents;
      if (cents < minCents) minCents = cents;
      long time = data.getLong(3);
      if (time > maxTime) maxTime = time;
      if (time < minTime) minTime = time;
      data.moveToNext();
    }

    ImageView view = (ImageView) getView();
    int cardSpacing = getActivity().getResources().getDimensionPixelSize(R.dimen.cardSpacing);
    int cardPadding = getActivity().getResources().getDimensionPixelSize(R.dimen.cardPadding);
    int textSize = cardPadding * 2;
    int width =
        getActivity().getWindow().getWindowManager().getDefaultDisplay().getWidth()
            - 2 * (cardSpacing)
            - 2 * (cardPadding);
    Log.d("Budget", "GraphFragment.onLoadFinished(): width=" + width);
    int height = getActivity().getResources().getDimensionPixelSize(R.dimen.graphHeight);
    Log.d("Budget", "GraphFragment.onLoadFinished(): height=" + height);
    Bitmap chart = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas chartCanvas = new Canvas(chart);
    chartCanvas.drawColor(Color.TRANSPARENT);
    Paint pen = new Paint();
    pen.setColor(0xFF000000);
    pen.setTextAlign(Paint.Align.CENTER);
    pen.setTextSize(textSize);
    Paint brush = new Paint();
    brush.setDither(true);
    brush.setHinting(Paint.HINTING_ON);
    brush.setStyle(Paint.Style.STROKE);
    float stroke = getActivity().getResources().getDimension(R.dimen.graphStroke);
    brush.setStrokeWidth(stroke);
    int currentEnvelope = -1;
    Path currentPath = null;
    float usableHeight = height - (2 * stroke) - textSize - cardPadding;
    float usableWidth = width - (2 * stroke) - textSize;

    data.moveToFirst();
    for (int i = 0; i != l; ++i) {
      int envelope = data.getInt(1);
      long cents = data.getLong(0);
      long time = data.getLong(3);
      float pointHeight =
          usableHeight
              - (float) ((cents - minCents) * usableHeight / ((double) (maxCents - minCents)))
              + stroke;
      float pointPosition =
          (float) ((time - minTime) * usableWidth / ((double) (maxTime - minTime)))
              + stroke
              + textSize;
      Log.d("Budget", "GraphFragment.onLoadFinished(): envelope=" + envelope);
      Log.d("Budget", "GraphFragment.onLoadFinished(): envelope.name=" + data.getString(4));
      Log.d("Budget", "GraphFragment.onLoadFinished(): cents=" + cents);
      Log.d("Budget", "GraphFragment.onLoadFinished(): pointHeight=" + pointHeight);
      Log.d("Budget", "GraphFragment.onLoadFinished(): time=" + time);
      Log.d("Budget", "GraphFragment.onLoadFinished(): pointPosition=" + pointPosition);
      if (envelope != currentEnvelope) {
        if (currentPath != null) {
          currentPath.rLineTo(usableWidth, 0);
          chartCanvas.drawPath(currentPath, brush);
        }
        int color = data.getInt(2);
        // brush = new Paint(brush);
        brush.setColor(color);
        currentEnvelope = envelope;
        currentPath = new Path();
        currentPath.moveTo(pointPosition, pointHeight);
      } else {
        currentPath.lineTo(pointPosition, pointHeight);
      }
      data.moveToNext();
    }
    if (currentPath != null) {
      currentPath.rLineTo(usableWidth, 0);
      chartCanvas.drawPath(currentPath, brush);
    }
    Path side = new Path();
    side.moveTo(textSize, height);
    side.lineTo(textSize, 0);
    chartCanvas.drawTextOnPath(
        getActivity().getString(R.string.envelopeDetails_balance), side, 0, 0, pen);
    Path bottom = new Path();
    bottom.moveTo(0, height - cardPadding);
    bottom.lineTo(width, height - cardPadding);
    chartCanvas.drawTextOnPath(getActivity().getString(R.string.graph_time), bottom, 0, 0, pen);
    if (maxTime != 0) {
      Date maxTimeD = new Date(maxTime);
      Date minTimeD = new Date(minTime);
      DateFormat timeFormat = android.text.format.DateFormat.getDateFormat(getActivity());
      pen.setTextAlign(Paint.Align.LEFT);
      chartCanvas.drawTextOnPath(timeFormat.format(minTimeD), bottom, 0, 0, pen);
      pen.setTextAlign(Paint.Align.RIGHT);
      chartCanvas.drawTextOnPath(timeFormat.format(maxTimeD), bottom, 0, 0, pen);
    }
    view.setImageBitmap(chart);
  }
Example #9
0
  public Bitmap getRoundedCornerBitmap1(Bitmap bitmap, int row, int column, float radius) {
    float[] radii = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int bmsIndex = 0;

    {
      bmsIndex = 4;
      if (column == 0) {
        bmsIndex = 3;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 5;
      }
    }
    if (row == 0) {
      bmsIndex = 1;
      if (column == 0) {
        bmsIndex = 0;
        radii[0] = radii[1] = radius;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 2;
        radii[2] = radii[3] = radius;
      }
    }
    if (row == mNumRows - 1) {
      bmsIndex = 7;
      if (column == 0) {
        bmsIndex = 6;
        radii[6] = radii[7] = radius;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 8;
        radii[4] = radii[5] = radius;
      }
    }

    if (bms[bmsIndex] != null) return bms[bmsIndex];

    bms[bmsIndex] = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Bitmap output = bms[bmsIndex];
    // Bitmap output = Bitmap.createBitmap(w,h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // We have to make sure our rounded corners have an alpha channel in most cases
    // color is arbitrary. This could be any color that was fully opaque (alpha = 255)
    int color = 0xff429242;

    // We're just reusing xferPaint to paint a normal looking rounded box,
    // the roundPx is the amount we're rounding by.
    final Paint paint = new Paint();
    int x1 = 0, y1 = 0, x2 = w, y2 = h;

    paint.setAntiAlias(true);
    paint.setStrokeWidth(1);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    /*
    if (row==0) {
    	if (column==0)
    	    radii[0] = radii[1]= radius;
        if (column==mNumColumns-1)
    	    radii[2] = radii[3]= radius;
    }


    if (row==mNumRows-1) {
    	if (column==0)
    	    radii[6] = radii[7]= radius;
        if (column==mNumColumns-1)
    	    radii[4] = radii[5]= radius;
       }
       */

    if (row == 0) y1 = MARGIN;
    if (column == mNumColumns - 1) x2 = w - MARGIN;
    if (column == 0) x1 = MARGIN;
    if (row == mNumRows - 1) y2 = h - MARGIN;

    Rect rect = new Rect(x1, y1, x2, y2);
    RectF rectF = new RectF(rect);
    Path path = new Path();
    path.addRoundRect(rectF, radii, Path.Direction.CW);
    canvas.drawPath(path, paint);

    // We're going to apply this paint using a porter-duff xfer mode.
    // This will allow us to only overwrite certain pixels.
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    paint.setTextSize(32);
    canvas.drawBitmap(bitmap, rect, rect, paint);

    paint.setColor(0xFFBBBBFF);
    canvas.drawText("Slate-" + row + "," + column, w / 4, h / 4, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 2, h / 4, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 4, h / 2, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 2, h / 2, paint);
    paint.setColor(color);

    path.rewind();

    final RectF cornerRect = new RectF(MARGIN, MARGIN, radius * 2 + MARGIN, radius * 2 + MARGIN);
    if (row == 0) {
      if (column == 0) {
        path.addArc(cornerRect, 180.0f, 90.0f);
      }
      if ((column == mNumColumns - 1)) {
        cornerRect.offsetTo(w - 2 * radius - MARGIN, MARGIN);
        path.addArc(cornerRect, 270.0f, 90.0f);
      }
    }
    if (row == mNumRows - 1) {
      if (column == mNumColumns - 1) {
        cornerRect.offsetTo(w - 2 * radius - MARGIN, h - 2 * radius - MARGIN);
        path.addArc(cornerRect, 0.0f, 90.0f);
      }
      if (column == 0) {
        cornerRect.offsetTo(MARGIN, h - radius * 2 - MARGIN);
        path.addArc(cornerRect, 90.0f, 90.0f);
      }
    }
    if (row == 0) {
      if ((column >= 0) && (column < mNumColumns - 1)) {
        path.moveTo(radius + MARGIN, MARGIN);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
        path.rLineTo(radius, 0);
      }
      if ((column > 0) && (column <= mNumColumns - 1)) {
        path.moveTo(0, MARGIN);
        path.rLineTo(radius, 0);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
      }
    }
    if (column == mNumColumns - 1) {
      if ((row >= 0) && (row < mNumRows - 1)) {
        path.moveTo(w - MARGIN, radius + MARGIN);
        path.rLineTo(0, h - 2 * radius - MARGIN);
        path.rLineTo(0, radius);
      }
      if ((row > 0) && (row <= mNumColumns - 1)) {
        path.moveTo(w - MARGIN, 0);
        path.rLineTo(0, radius);
        path.rLineTo(0, h - 2 * radius - MARGIN);
      }
    }
    if (column == 0) {
      if ((row >= 0) && (row < mNumRows - 1)) {
        path.moveTo(MARGIN, radius + MARGIN);
        path.rLineTo(0, h - 2 * radius - MARGIN);
        path.rLineTo(0, radius);
      }
      if ((row > 0) && (row <= mNumRows - 1)) {
        path.moveTo(MARGIN, 0);
        path.rLineTo(0, radius);
        path.rLineTo(0, h - 2 * radius - MARGIN);
      }
    }
    if (row == mNumRows - 1) {
      if ((column >= 0) && (column < mNumColumns - 1)) {
        path.moveTo(radius + MARGIN, h - MARGIN);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
        path.rLineTo(radius, 0);
      }
      if ((column > 0) && (column <= mNumColumns - 1)) {
        path.moveTo(0, h - MARGIN);
        path.rLineTo(radius, 0);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
      }
    }

    color = 0xff444444;
    final Paint paint1 = new Paint();
    paint1.setAntiAlias(true);
    paint1.setColor(color);
    paint1.setStyle(Style.STROKE);
    paint1.setStrokeWidth(4);
    paint1.setShadowLayer(10, 4, 4, R.color.magic_flame);
    canvas.drawPath(path, paint1);

    return output;
  }
Example #10
0
  // draw path 96x96
  public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
    if (turnType == null) {
      return;
    }
    pathForTurn.reset();

    int c = 48;
    int w = 16;
    pathForTurn.moveTo(c, 94);
    float sarrowL = 30; // side of arrow
    float harrowL = (float) Math.sqrt(2) * sarrowL; // hypotenuse of arrow
    float spartArrowL = (float) ((sarrowL - w / Math.sqrt(2)) / 2);
    float hpartArrowL = (float) (harrowL - w) / 2;

    if (TurnType.C.equals(turnType.getValue())) {
      int h = 65;

      pathForTurn.rMoveTo(w / 2, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(-harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-harrowL / 2, harrowL / 2);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TR.equals(turnType.getValue()) || TurnType.TL.equals(turnType.getValue())) {
      int b = TurnType.TR.equals(turnType.getValue()) ? 1 : -1;
      int h = 36;
      float quadShiftX = 22;
      float quadShiftY = 22;

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -quadShiftY, b * quadShiftX, -quadShiftY);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rLineTo(b * harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-b * harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rQuadTo(-b * (quadShiftX + w), 0, -b * (quadShiftX + w), quadShiftY + w);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSLR.equals(turnType.getValue())
        || TurnType.TSLL.equals(turnType.getValue())) {
      int b = TurnType.TSLR.equals(turnType.getValue()) ? 1 : -1;
      int h = 40;
      int quadShiftY = 22;
      float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2)));
      float nQuadShiftX = (sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShifty = quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 4, 0);
      pathForTurn.rLineTo(0, -h /* + partArrowL */);
      pathForTurn.rQuadTo(
          0,
          -quadShiftY + quadShiftX /*- partArrowL*/,
          b * quadShiftX,
          -quadShiftY /*- partArrowL*/);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(0, -sarrowL); // center
      pathForTurn.rLineTo(-b * sarrowL, 0);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSHR.equals(turnType.getValue())
        || TurnType.TSHL.equals(turnType.getValue())) {
      int b = TurnType.TSHR.equals(turnType.getValue()) ? 1 : -1;
      int h = 45;
      float quadShiftX = 22;
      float quadShiftY = -(float) (quadShiftX / (1 + Math.sqrt(2)));
      float nQuadShiftX = -(sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShiftY = -quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftX - quadShiftY), b * quadShiftX, quadShiftY);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(b * sarrowL, 0); // center
      pathForTurn.rLineTo(0, -sarrowL);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rCubicTo(
          b * nQuadShiftX / 2,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TU.equals(turnType.getValue())) {
      int h = 54;
      float quadShiftX = 13;
      float quadShiftY = 13;

      pathForTurn.rMoveTo(28, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftY + w), -(quadShiftX + w), -(quadShiftY + w));
      pathForTurn.rQuadTo(-(quadShiftX + w), 0, -(quadShiftX + w), (quadShiftY + w));
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rLineTo(harrowL / 2, harrowL / 2); // center
      pathForTurn.rLineTo(harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rQuadTo(0, -quadShiftX, quadShiftX, -quadShiftY);
      pathForTurn.rQuadTo(quadShiftX, 0, quadShiftX, quadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (turnType != null && turnType.isRoundAbout()) {
      float t = turnType.getTurnAngle();
      if (t >= 170 && t < 220) {
        t = 220;
      } else if (t > 160 && t < 170) {
        t = 160;
      }
      float sweepAngle = (t - 360) - 180;
      if (sweepAngle < -360) {
        sweepAngle += 360;
      }
      float r1 = 32f;
      float r2 = 24f;
      float angleToRot = 0.3f;

      pathForTurn.moveTo(48, 48 + r1 + 8);
      pathForTurn.lineTo(48, 48 + r1);
      RectF r = new RectF(48 - r1, 48 - r1, 48 + r1, 48 + r1);
      pathForTurn.arcTo(r, 90, sweepAngle);
      float angleRad = (float) ((180 + sweepAngle) * Math.PI / 180f);

      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad), 48 - (r1 + 4) * FloatMath.cos(angleRad));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad + angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad + angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 12) * FloatMath.sin(angleRad - angleToRot / 2),
          48 - (r1 + 12) * FloatMath.cos(angleRad - angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad - 3 * angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad - 3 * angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad - angleToRot),
          48 - (r1 + 4) * FloatMath.cos(angleRad - angleToRot));
      pathForTurn.lineTo(
          48 + r2 * FloatMath.sin(angleRad - angleToRot),
          48 - r2 * FloatMath.cos(angleRad - angleToRot));

      r.set(48 - r2, 48 - r2, 48 + r2, 48 + r2);
      pathForTurn.arcTo(r, 360 + sweepAngle + 90, -sweepAngle);
      pathForTurn.lineTo(40, 48 + r2);
      pathForTurn.lineTo(40, 48 + r1 + 8);
      pathForTurn.close();
    }
    pathForTurn.close();
    if (transform != null) {
      pathForTurn.transform(transform);
    }
  }
 public void draw(Canvas paramCanvas)
 {
   Rect localRect = getBounds();
   int i1;
   float f1;
   float f2;
   switch (n)
   {
   case 2: 
   default: 
     if (fv.a.d(this) == 1)
     {
       i1 = 1;
       f1 = (float)Math.sqrt(d * d * 2.0F);
       f2 = e;
       float f6 = f2 + (f1 - f2) * l;
       f1 = e;
       float f3 = f1 + (f - f1) * l;
       float f4 = Math.round(0.0F + m * l);
       float f7 = 0.0F + c * l;
       if (i1 == 0) {
         break label480;
       }
       f1 = 0.0F;
       label144:
       if (i1 == 0) {
         break label487;
       }
       f2 = 180.0F;
       label152:
       float f5 = l;
       float f8 = (float)Math.round(f6 * Math.cos(f7));
       f6 = (float)Math.round(f6 * Math.sin(f7));
       i.rewind();
       f7 = g + b.getStrokeWidth();
       f7 += (-m - f7) * l;
       float f9 = -f3 / 2.0F;
       i.moveTo(f9 + f4, 0.0F);
       i.rLineTo(f3 - f4 * 2.0F, 0.0F);
       i.moveTo(f9, f7);
       i.rLineTo(f8, f6);
       i.moveTo(f9, -f7);
       i.rLineTo(f8, -f6);
       i.close();
       paramCanvas.save();
       f3 = b.getStrokeWidth();
       f3 = (float)(((int)(localRect.height() - 3.0F * f3 - g * 2.0F) / 4 << 1) + (f3 * 1.5D + g));
       paramCanvas.translate(localRect.centerX(), f3);
       if (!h) {
         break label498;
       }
       if ((i1 ^ k) == 0) {
         break label492;
       }
       i1 = -1;
       label407:
       paramCanvas.rotate(i1 * ((f2 - f1) * f5 + f1));
     }
     break;
   }
   for (;;)
   {
     paramCanvas.drawPath(i, b);
     paramCanvas.restore();
     return;
     i1 = 0;
     break;
     i1 = 1;
     break;
     if (fv.a.d(this) == 0)
     {
       i1 = 1;
       break;
     }
     i1 = 0;
     break;
     i1 = 0;
     break;
     label480:
     f1 = -180.0F;
     break label144;
     label487:
     f2 = 0.0F;
     break label152;
     label492:
     i1 = 1;
     break label407;
     label498:
     if (i1 != 0) {
       paramCanvas.rotate(180.0F);
     }
   }
 }