@Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    boolean needsInvalidate = false;

    if (mTopGlow != null && !mTopGlow.isFinished()) {
      final int restore = c.save();
      if (getClipToPadding(parent)) {
        c.translate(parent.getPaddingLeft(), parent.getPaddingTop());
      }
      //noinspection ConstantConditions
      needsInvalidate |= mTopGlow.draw(c);
      c.restoreToCount(restore);
    }

    if (mBottomGlow != null && !mBottomGlow.isFinished()) {
      final int restore = c.save();
      c.rotate(180);
      if (getClipToPadding(parent)) {
        c.translate(
            -parent.getWidth() + parent.getPaddingRight(),
            -parent.getHeight() + parent.getPaddingBottom());
      } else {
        c.translate(-parent.getWidth(), -parent.getHeight());
      }
      needsInvalidate |= mBottomGlow.draw(c);
      c.restoreToCount(restore);
    }

    if (needsInvalidate) {
      ViewCompat.postInvalidateOnAnimation(parent);
    }
  }
  private void drawEdges(Canvas canvas) {

    if (mEdgeGlowLeft != null) {
      if (!mEdgeGlowLeft.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight();

        canvas.rotate(-90);
        canvas.translate(-height / 1.5f, 0);
        mEdgeGlowLeft.setSize((int) (height / 2.5f), height / 5);

        if (mEdgeGlowLeft.draw(canvas)) {
          invalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
      if (!mEdgeGlowRight.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight();

        canvas.translate(getScrollX() + width, height / 3f);
        canvas.rotate(90);
        mEdgeGlowRight.setSize((int) (height / 2.5f), height / 5);
        if (mEdgeGlowRight.draw(canvas)) {
          invalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    int save;

    if (!mPathValid) {
      generatePath();
    }

    final float primaryLeftPoint = mHoriz.convertToPoint(mPrimaryLeft);
    final float primaryRightPoint = mHoriz.convertToPoint(mPrimaryRight);

    if (mEstimateVisible) {
      save = canvas.save();
      canvas.clipRect(0, 0, getWidth(), getHeight());
      canvas.drawPath(mPathEstimate, mPaintEstimate);
      canvas.restoreToCount(save);
    }

    save = canvas.save();
    canvas.clipRect(0, 0, primaryLeftPoint, getHeight());
    canvas.drawPath(mPathFill, mPaintFillSecondary);
    canvas.restoreToCount(save);

    save = canvas.save();
    canvas.clipRect(primaryRightPoint, 0, getWidth(), getHeight());
    canvas.drawPath(mPathFill, mPaintFillSecondary);
    canvas.restoreToCount(save);

    save = canvas.save();
    canvas.clipRect(primaryLeftPoint, 0, primaryRightPoint, getHeight());
    canvas.drawPath(mPathFill, mPaintFill);
    canvas.drawPath(mPathStroke, mPaintStroke);
    canvas.restoreToCount(save);
  }
    @Override
    protected void onDraw(Canvas canvas) {

      canvas.translate(20, 100);
      int source = canvas.save();
      canvas.drawBitmap(def, 0, 0, null);
      canvas.translate(320, 0);
      canvas.drawBitmap(one, 0, 0, null);
      canvas.translate(120, 0);
      canvas.drawBitmap(two, 0, 0, null);
      canvas.translate(120, 0);
      canvas.drawBitmap(three, 0, 0, null);
      canvas.translate(120, 0);
      canvas.drawBitmap(four, 0, 0, null);
      canvas.restoreToCount(source);

      canvas.translate(0, 320);
      source = canvas.save();
      for (int i = 0; i < bs.length; i++) {
        if (bs[i] != null) {
          final Bitmap b = bs[i];
          canvas.drawBitmap(b, i * (200 + 20), 0, null);
        }
      }
      canvas.restoreToCount(source);
      canvas.translate(0, 220);
      source = canvas.save();
      canvas.drawBitmap(sum, 0, 0, null);
    }
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);
    if (leftGlow != null) {
      final int scrollX = getScrollX();
      if (!leftGlow.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), Math.min(0, scrollX));
        leftGlow.setSize(height, getWidth());
        if (leftGlow.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
      if (!rightGlow.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), -(Math.max(getScrollRange(), scrollX) + width));
        rightGlow.setSize(height, width);
        if (rightGlow.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
  private void drawEdges(Canvas canvas) {

    if (mEdgeGlowLeft != null) {

      final int width = getWidth();
      final int height = getHeight() - getPaddingTop() - getPaddingBottom();

      if (!mEdgeGlowLeft.isFinished()) {
        final int restoreCount = canvas.save();

        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), 0);
        mEdgeGlowLeft.setSize(height, width);
        if (mEdgeGlowLeft.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }

      if (!mEdgeGlowRight.isFinished()) {
        final int restoreCount = canvas.save();

        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), -(mTouchX + width));
        mEdgeGlowRight.setSize(height, width);

        if (mEdgeGlowRight.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
  @Override
  protected void onDraw(final Canvas canvas) {
    if (recycled) return;

    final int canvasSave = canvas.save();

    canvas.translate(getPaddingLeft(), getPaddingTop());
    canvas.scale(scale, scale);

    canvas.drawBitmap(genBackgroundBitmap, 0, 0, bitmapPaint);

    final boolean drawSignal = signalMin != null && signalMax != null;
    if (drawSignal) {
      signalTextPaint.setTextAlign(Align.LEFT);
      canvas.drawText(
          String.format("– %s", signalText), coordFW(9, relW), coordFH(130, relH), signalTextPaint);
      signalTextPaint.setTextAlign(Align.RIGHT);
      canvas.drawText(
          Integer.toString(signalMin), coordFW(72, relW), coordFH(195, relH), signalTextPaint);
      canvas.drawText(
          Integer.toString(signalMax), coordFW(72, relW), coordFH(58, relH), signalTextPaint);
    }

    canvas.drawBitmap(gridBitmap, gridX, gridY, bitmapPaint);

    final int canvasSave2 = canvas.save();
    canvas.translate(graphX, graphY);

    for (final GraphService graph : graphs) graph.draw(canvas);

    canvas.restoreToCount(canvasSave2);

    canvas.restoreToCount(canvasSave);
  }
 @Override
 public void onDraw(Canvas canvas) {
   float alpha = 1;
   if (mXFade != null) {
     alpha = mXFade.getValue();
   } else if (mFadeIn != null) {
     alpha = mFadeIn.getValue();
   }
   int state = canvas.save();
   if (mFadeIn != null) {
     float sf = 0.9f + alpha * 0.1f;
     canvas.scale(sf, sf, mCenter.x, mCenter.y);
   }
   drawFocus(canvas);
   if (mState == STATE_FINISHING) {
     canvas.restoreToCount(state);
     return;
   }
   if ((mOpenItem == null) || (mXFade != null)) {
     // draw base menu
     for (PieItem item : mItems) {
       drawItem(canvas, item, alpha);
     }
   }
   if (mOpenItem != null) {
     for (PieItem inner : mOpenItem.getItems()) {
       drawItem(canvas, inner, (mXFade != null) ? (1 - 0.5f * alpha) : 1);
     }
   }
   canvas.restoreToCount(state);
 }
Beispiel #9
0
  /** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */
  private void drawEdgeGlow(Canvas canvas) {
    if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) {
      // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the left
      // side.
      final int restoreCount = canvas.save();
      final int height = getHeight();

      canvas.rotate(-90, 0, 0);
      canvas.translate(-height + getPaddingBottom(), 0);

      mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth());
      if (mEdgeGlowLeft.draw(canvas)) {
        invalidate();
      }

      canvas.restoreToCount(restoreCount);
    } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) {
      // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the
      // right side.
      final int restoreCount = canvas.save();
      final int width = getWidth();

      canvas.rotate(90, 0, 0);
      canvas.translate(getPaddingTop(), -width);
      mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth());
      if (mEdgeGlowRight.draw(canvas)) {
        invalidate();
      }

      canvas.restoreToCount(restoreCount);
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    final int width = getWidth();
    final int height = getHeight() - getPaddingBottom();

    final Drawable secondary = mSecondary;
    if (secondary != null) {
      final int secondaryHeight = secondary.getIntrinsicHeight();

      final float[] vertTicks = mVert.getTickPoints();
      for (float y : vertTicks) {
        final int bottom = (int) Math.min(y + secondaryHeight, height);
        secondary.setBounds(0, (int) y, width, bottom);
        secondary.draw(canvas);
      }
    }

    final Drawable primary = mPrimary;
    if (primary != null) {
      final int primaryWidth = primary.getIntrinsicWidth();
      final int primaryHeight = primary.getIntrinsicHeight();

      final float[] horizTicks = mHoriz.getTickPoints();
      for (float x : horizTicks) {
        final int right = (int) Math.min(x + primaryWidth, width);
        primary.setBounds((int) x, 0, right, height);
        primary.draw(canvas);
      }
    }

    mBorder.setBounds(0, 0, width, height);
    mBorder.draw(canvas);

    final int padding = mLabelStart != null ? mLabelStart.getHeight() / 8 : 0;

    final Layout start = mLabelStart;
    if (start != null) {
      final int saveCount = canvas.save();
      canvas.translate(0, height + padding);
      start.draw(canvas);
      canvas.restoreToCount(saveCount);
    }

    final Layout mid = mLabelMid;
    if (mid != null) {
      final int saveCount = canvas.save();
      canvas.translate((width - mid.getWidth()) / 2, height + padding);
      mid.draw(canvas);
      canvas.restoreToCount(saveCount);
    }

    final Layout end = mLabelEnd;
    if (end != null) {
      final int saveCount = canvas.save();
      canvas.translate(width - end.getWidth(), height + padding);
      end.draw(canvas);
      canvas.restoreToCount(saveCount);
    }
  }
Beispiel #11
0
 protected void onDraw(Canvas canvas)
 {
     super.onDraw(canvas);
     if (getBackground() != null)
     {
         if (mShader != null && mShaderMatrix != null)
         {
             int i = mShaderWidth / 2;
             int l = getPositionFromValue(mCurrentValue);
             mShaderMatrix.setTranslate(l - i, 0.0F);
             mShader.setLocalMatrix(mShaderMatrix);
             canvas.drawRect(mEdgeOffset, 0.0F, (float)getWidth() - mEdgeOffset, getHeight(), mLinesPaint);
         }
         canvas.translate(0.0F, mHeightDiff);
         mShadowBottom.draw(canvas);
         canvas.translate(0.0F, -mHeightDiff);
         if (debugPaint != null)
         {
             debugPaint.setColor(-1);
             debugPaint.setAlpha(127);
             canvas.drawLine(mMinX, 0.0F, mMinX, getHeight(), debugPaint);
             canvas.drawLine(mMaxX, 0.0F, mMaxX, getHeight(), debugPaint);
             canvas.drawLine(getWidth() / 2, 0.0F, getWidth() / 2, getHeight(), debugPaint);
         }
         if (mEdgeLeft != null)
         {
             if (!mEdgeLeft.isFinished())
             {
                 int j = canvas.save();
                 canvas.concat(mEdgeMatrixLeft);
                 if (mEdgeLeft.draw(canvas))
                 {
                     postInvalidate();
                 }
                 canvas.restoreToCount(j);
             }
             if (!mEdgeRight.isFinished())
             {
                 int k = canvas.save();
                 canvas.concat(mEdgeMatrixRight);
                 if (mEdgeRight.draw(canvas))
                 {
                     postInvalidate();
                 }
                 canvas.restoreToCount(k);
                 return;
             }
         }
     }
 }
 private void drawShadow(Canvas canvas) {
   float f = -mCornerRadius - mShadowSize;
   float f1 = mCornerRadius + (float) mInsetShadow + mRawShadowSize / 2.0F;
   int i;
   boolean flag;
   int j;
   if (mCardBounds.width() - 2.0F * f1 > 0.0F) {
     i = 1;
   } else {
     i = 0;
   }
   if (mCardBounds.height() - 2.0F * f1 > 0.0F) {
     flag = true;
   } else {
     flag = false;
   }
   j = canvas.save();
   canvas.translate(mCardBounds.left + f1, mCardBounds.top + f1);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (i != 0) {
     canvas.drawRect(0.0F, f, mCardBounds.width() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(j);
   j = canvas.save();
   canvas.translate(mCardBounds.right - f1, mCardBounds.bottom - f1);
   canvas.rotate(180F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (i != 0) {
     float f2 = mCardBounds.width();
     float f3 = -mCornerRadius;
     canvas.drawRect(0.0F, f, f2 - 2.0F * f1, mShadowSize + f3, mEdgeShadowPaint);
   }
   canvas.restoreToCount(j);
   i = canvas.save();
   canvas.translate(mCardBounds.left + f1, mCardBounds.bottom - f1);
   canvas.rotate(270F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (flag) {
     canvas.drawRect(0.0F, f, mCardBounds.height() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(i);
   i = canvas.save();
   canvas.translate(mCardBounds.right - f1, mCardBounds.top + f1);
   canvas.rotate(90F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (flag) {
     canvas.drawRect(0.0F, f, mCardBounds.height() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(i);
 }
 private void drawShadow(Canvas canvas) {
   final float edgeShadowTop = -mCornerRadius - mShadowSize;
   final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
   final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
   final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
   // LT
   int saved = canvas.save();
   canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawHorizontalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // RB
   saved = canvas.save();
   canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
   canvas.rotate(180f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawHorizontalEdges) {
     canvas.drawRect(
         0,
         edgeShadowTop,
         mCardBounds.width() - 2 * inset,
         -mCornerRadius + mShadowSize,
         mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // LB
   saved = canvas.save();
   canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
   canvas.rotate(270f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawVerticalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // RT
   saved = canvas.save();
   canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
   canvas.rotate(90f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawVerticalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
 }
  @Override
  public void draw(Canvas canvas) {

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

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

    int saveCount = canvas.save();

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

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

    canvas.restoreToCount(saveCount);
  }
Beispiel #15
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    final int saveCount = canvas.save();

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

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

    super.dispatchDraw(canvas);

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

    canvas.restoreToCount(saveCount);
  }
Beispiel #16
0
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);

    float x =
        (mDrawRect.width() - mThumbRadius * 2) * mThumbPosition + mDrawRect.left + mThumbRadius;
    if (mIsRtl) x = 2 * mDrawRect.centerX() - x;
    float y = mDrawRect.centerY();

    getTrackPath(x, y, mThumbRadius);
    mPaint.setColor(
        ColorUtil.getMiddleColor(getTrackColor(false), getTrackColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(mTrackPath, mPaint);

    if (mShadowSize > 0) {
      int saveCount = canvas.save();
      canvas.translate(x, y + mShadowOffset);
      canvas.drawPath(mShadowPath, mShadowPaint);
      canvas.restoreToCount(saveCount);
    }

    mPaint.setColor(
        ColorUtil.getMiddleColor(getThumbColor(false), getThumbColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(x, y, mThumbRadius, mPaint);
  }
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);

    int width = getWidth();
    int height = getHeight();
    if (mInsets != null && mInsetForeground != null) {
      int sc = canvas.save();
      canvas.translate(getScrollX(), getScrollY());

      // Top
      mTempRect.set(0, 0, width, mInsets.top);
      mInsetForeground.setBounds(mTempRect);
      mInsetForeground.draw(canvas);

      // Bottom
      mTempRect.set(0, height - mInsets.bottom, width, height);
      mInsetForeground.setBounds(mTempRect);
      mInsetForeground.draw(canvas);

      // Left
      mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
      mInsetForeground.setBounds(mTempRect);
      mInsetForeground.draw(canvas);

      // Right
      mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
      mInsetForeground.setBounds(mTempRect);
      mInsetForeground.draw(canvas);

      canvas.restoreToCount(sc);
    }
  }
  @Override
  protected void dispatchDraw(Canvas canvas) {
    boolean restore = false;
    int restoreCount = 0;

    if (mItemCount < 1) return;

    boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING && mNextScreen == INVALID_SCREEN;
    // If we are not scrolling or flinging, draw only the current screen
    if (fastDraw) {
      drawChild(canvas, getChildAt(mCurrentScreen - mFirstPosition), getDrawingTime());
    } else {
      final long drawingTime = getDrawingTime();
      final float scrollPos = (float) getScrollX() / getTotalWidth();
      final int leftScreen = (int) scrollPos;
      final int rightScreen = leftScreen + 1;
      if (leftScreen >= 0) {
        drawChild(canvas, getChildAt(leftScreen - mFirstPosition), drawingTime);
      }
      if (scrollPos != leftScreen && rightScreen < mItemCount) {
        drawChild(canvas, getChildAt(rightScreen - mFirstPosition), drawingTime);
      }
    }

    if (mEdgeGlowLeft != null) {
      drawEdges(canvas);
    }

    if (restore) {
      canvas.restoreToCount(restoreCount);
    }
  }
Beispiel #19
0
  public void drawFromThread(Canvas canvas) {
    final float scaleFactorX = getWidth() / (WIDTH * 1.f);
    final float scaleFactorY = getHeight() / (HEIGHT * 1.f);

    if (canvas != null) {
      final int savedState = canvas.save();
      canvas.scale(scaleFactorX, scaleFactorY);
      bg.draw(canvas);
      if (!dissapear) {
        player.draw(canvas);
      }
      // draw smokepuffs
      for (Smokepuff sp : smoke) {
        sp.draw(canvas);
      }
      // draw missiles
      for (Missile m : missiles) {
        m.draw(canvas);
      }
      // draw topborder
      for (TopBorder tb : topborder) {
        tb.draw(canvas);
      }
      // draw botborder
      for (BotBorder bb : botborder) {
        bb.draw(canvas);
      }
      // draw explosion
      if (started) {
        explosion.draw(canvas);
      }
      drawText(canvas);
      canvas.restoreToCount(savedState);
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable mDrawable = getDrawable();
    if (mDrawable == null) {
      return;
    }

    if (mDrawable.getIntrinsicWidth() == 0 || mDrawable.getIntrinsicHeight() == 0) {
      return; // nothing to draw (empty bounds)
    }

    if (null == maskBitmap) {
      return;
    }

    int saveCount = canvas.getSaveCount();
    canvas.save();
    paint.setFilterBitmap(false);
    paint.setXfermode(mXfermode);
    canvas.drawBitmap(maskBitmap, null, mRoundRect, paint);
    paint.setXfermode(null);
    canvas.restoreToCount(saveCount);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    if (mDeltX > 0 || mDeltX == 0 && mSwitchOn) {
      if (mSrc != null) {
        mSrc.set(
            mMoveLength - mDeltX, 0, mSwitchBottom.getWidth() - mDeltX, mSwitchFrame.getHeight());
      }
    } else if (mDeltX < 0 || mDeltX == 0 && !mSwitchOn) {
      if (mSrc != null) {
        mSrc.set(-mDeltX, 0, mSwitchFrame.getWidth() - mDeltX, mSwitchFrame.getHeight());
      }
    }

    int count =
        canvas.saveLayer(
            new RectF(mDest),
            null,
            Canvas.MATRIX_SAVE_FLAG
                | Canvas.CLIP_SAVE_FLAG
                | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
                | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
                | Canvas.CLIP_TO_LAYER_SAVE_FLAG);

    canvas.drawBitmap(mSwitchBottom, mSrc, mDest, null);
    canvas.drawBitmap(mSwitchThumb, mSrc, mDest, null);
    canvas.drawBitmap(mSwitchFrame, 0, 0, null);
    canvas.drawBitmap(mSwitchMask, 0, 0, mPaint);
    canvas.restoreToCount(count);
  }
  private Bitmap createDraggingItemImage(View v, NinePatchDrawable shadow) {
    int width = v.getWidth() + mShadowPadding.left + mShadowPadding.right;
    int height = v.getHeight() + mShadowPadding.top + mShadowPadding.bottom;

    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmap);

    if (shadow != null) {
      shadow.setBounds(0, 0, width, height);
      shadow.draw(canvas);
    }

    final int savedCount = canvas.save(Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
    // NOTE: Explicitly set clipping rect. This is required on Gingerbread.
    canvas.clipRect(
        mShadowPadding.left,
        mShadowPadding.top,
        width - mShadowPadding.right,
        height - mShadowPadding.bottom);
    canvas.translate(mShadowPadding.left, mShadowPadding.top);
    v.draw(canvas);
    canvas.restoreToCount(savedCount);

    return bitmap;
  }
Beispiel #23
0
 protected void onDraw(Canvas paramCanvas) {
   Drawable localDrawable = getDrawable();
   if (localDrawable == null) return;
   try {
     if (this.paint == null) {
       Paint localPaint1 = new Paint();
       this.paint = localPaint1;
       this.paint.setFilterBitmap(false);
       Paint localPaint2 = this.paint;
       Xfermode localXfermode1 = MASK_XFERMODE;
       @SuppressWarnings("unused")
       Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
     }
     float f1 = getWidth();
     float f2 = getHeight();
     int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
     int j = getWidth();
     int k = getHeight();
     localDrawable.setBounds(0, 0, j, k);
     localDrawable.draw(paramCanvas);
     if ((this.mask == null) || (this.mask.isRecycled())) {
       Bitmap localBitmap1 = createMask();
       this.mask = localBitmap1;
     }
     Bitmap localBitmap2 = this.mask;
     Paint localPaint3 = this.paint;
     paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
     paramCanvas.restoreToCount(i);
     return;
   } catch (Exception localException) {
     StringBuilder localStringBuilder =
         new StringBuilder().append("Attempting to draw with recycled bitmap. View ID = ");
     System.out.println("localStringBuilder==" + localStringBuilder);
   }
 }
  public static Bitmap capture(
      View view, float width, float height, boolean scroll, Bitmap.Config config) {
    if (!view.isDrawingCacheEnabled()) view.setDrawingCacheEnabled(true);

    Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, config);
    bitmap.eraseColor(Color.WHITE);

    Canvas canvas = new Canvas(bitmap);
    int left = view.getLeft();
    int top = view.getTop();
    if (scroll) {
      left = view.getScrollX();
      top = view.getScrollY();
    }
    int status = canvas.save();
    canvas.translate(-left, -top);

    float scale = width / view.getWidth();
    canvas.scale(scale, scale, left, top);

    view.draw(canvas);
    canvas.restoreToCount(status);

    Paint alphaPaint = new Paint();
    alphaPaint.setColor(Color.TRANSPARENT);

    canvas.drawRect(0f, 0f, 1f, height, alphaPaint);
    canvas.drawRect(width - 1f, 0f, width, height, alphaPaint);
    canvas.drawRect(0f, 0f, width, 1f, alphaPaint);
    canvas.drawRect(0f, height - 1f, width, height, alphaPaint);
    canvas.setBitmap(null);

    return bitmap;
  }
 private void getScreenBitmap() {
   mView.getRootView().destroyDrawingCache();
   mView.getGlobalVisibleRect(mRect, point);
   realheight = mView.getHeight();
   realwidth = mView.getWidth();
   dst.set(0, 0, realwidth, realheight);
   int w = Math.round(realwidth * BITMAP_RATIO);
   int h = Math.round(realheight * BITMAP_RATIO);
   w = w & ~0x03;
   h = h & ~0x03;
   if (w <= 0 || h <= 0) return;
   if (bitmap == null || bitmap.getWidth() != w || bitmap.getHeight() != h) {
     bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
     mMatrix.setScale(BITMAP_RATIO, BITMAP_RATIO);
     mMatrix.invert(mDrawMatrix);
     src.set(0, 0, w, h);
   }
   float dx = -(Math.min(0, mView.getLeft()) + mRect.left);
   float dy = (-point.y);
   mCanvas.restoreToCount(1);
   mCanvas.setBitmap(bitmap);
   mCanvas.setMatrix(mMatrix);
   mCanvas.translate(dx, dy);
   mCanvas.save();
   mView.getRootView().draw(mCanvas);
 }
 private void drawBg(Canvas paramCanvas) {
   int i = paramCanvas.save();
   paramCanvas.clipRect(
       0, getTopMargin(), this.standardLayout.width, getTopMargin() + getThisHeight());
   paramCanvas.drawColor(-1);
   paramCanvas.restoreToCount(i);
 }
 private void drawBg(Canvas paramCanvas) {
   if ((isItemPressed()) && (this.mSelectedIndex == 0)) {
     int i = paramCanvas.save();
     paramCanvas.clipRect(0, 0, this.itemLayout.width, this.mItemHeight);
     paramCanvas.drawColor(SkinManager.getItemHighlightMaskColor_new());
     paramCanvas.restoreToCount(i);
   }
 }
 public void draw(Canvas paramCanvas)
 {
   Rect localRect = getBounds();
   int i = paramCanvas.save();
   paramCanvas.rotate(mRotation, localRect.exactCenterX(), localRect.exactCenterY());
   mRing.draw(paramCanvas, localRect);
   paramCanvas.restoreToCount(i);
 }
 @Override
 public void draw(Canvas c) {
   final Rect bounds = getBounds();
   final int saveCount = c.save();
   c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
   mRing.draw(c, bounds);
   c.restoreToCount(saveCount);
 }
 private void drawHighlight(Canvas paramCanvas, int paramInt1, int paramInt2) {
   int i = paramCanvas.save();
   paramCanvas.clipRect(
       paramInt1,
       paramInt2,
       paramInt1 + this.itemLayout.width,
       paramInt2 + this.itemLayout.height);
   paramCanvas.drawColor(SkinManager.getItemHighlightMaskColor());
   paramCanvas.restoreToCount(i);
 }