Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

In this page you can find the example usage for android.graphics RectF RectF.

Prototype

public RectF() 

Source Link

Document

Create a new empty RectF.

Usage

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw cards with big single center suite
 * @param r application resources reference
 */// w w w  .ja v a2  s .  c  o  m
private void drawBigCards(final Resources r) {

    final Bitmap[] bigSuit = new Bitmap[4];
    final Bitmap[] suit = new Bitmap[4];
    Canvas canvas;
    final String[] card_values = mResources.getStringArray(R.array.card_values);
    final Paint cardFrontPaint = new Paint();
    final Paint cardBorderPaint = new Paint();
    final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT);

    Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null);

    mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888);
    canvas = new Canvas(mCardHidden);
    drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT);
    drawable.draw(canvas);

    for (int i = 0; i < 4; i++) {
        suit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(suit[i]);
        drawSuit(i, canvas, mSuitsSizeHalf);
    }

    for (int i = 0; i < 4; i++) {
        bigSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(bigSuit[i]);
        drawSuit(i, canvas, mSuitsSize);
    }

    cardBorderPaint.setARGB(255, 0, 0, 0);
    cardFrontPaint.setARGB(255, 255, 255, 255);
    RectF rectf = new RectF();
    for (int suitIdx = 0; suitIdx < 4; suitIdx++) {
        for (int valueIdx = 0; valueIdx < 13; valueIdx++) {
            mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT,
                    Bitmap.Config.ARGB_8888);
            canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]);

            drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint);
            drawCardValue(textPaintLeft, canvas, card_values[valueIdx], suit[suitIdx], suitIdx);
            // Middle
            canvas.drawBitmap(bigSuit[suitIdx], Card.WIDTH / 2 - mSuitsSizeHalf,
                    Card.HEIGHT / 2 - mSuitsSizeHalf, mSuitPaint);
        }
    }
}

From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java

private boolean checkMatrixBounds() {
    final RectF rect = getVisibleRect();
    if (rect == null) {
        return false;
    }//w  w w .  j a v  a 2  s  .  c  om

    RectF src = new RectF();
    src.set(rect);
    final float h = rect.height(), w = rect.width();
    float deltaX = 0, deltaY = 0;
    View parent = (View) mImageView.getParent();

    final int viewHeight = parent.getHeight();//getImageViewHeight(mImageView);
    final int viewWidth = parent.getWidth();//getImageViewWidth(mImageView);
    System.out.println("===============================================width:" + viewWidth + "/" + viewHeight);
    System.out
            .println("+++++++++rect.left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom);

    float scale = getScale();
    float centerX = rect.centerX();
    float centerY = rect.centerY();
    float targetW = w * scale;
    float targetH = h * scale;
    RectF targetRect = new RectF(centerX - targetW / 2, centerY - targetH / 2, centerX + targetW / 2,
            centerY + targetH / 2);

    rect.set(targetRect);
    final float height = rect.height(), width = rect.width();

    if (height <= viewHeight) {
        deltaY = (viewHeight - height) / 2 - rect.top;
    } else if (rect.top > 0) {
        deltaY = -rect.top;
    } else if (rect.bottom < viewHeight) {
        deltaY = viewHeight - rect.bottom;
    }

    if (width <= viewWidth) {
        deltaX = (viewWidth - width) / 2 - rect.left;
        mScrollEdge = EDGE_BOTH;
    } else if (rect.left > 0) {
        mScrollEdge = EDGE_LEFT;
        deltaX = -rect.left;
    } else if (rect.right < viewWidth) {
        deltaX = viewWidth - rect.right;
        mScrollEdge = EDGE_RIGHT;
    } else {
        mScrollEdge = EDGE_NONE;
    }

    // Finally actually translate the matrix
    if (!mStable) {
        System.out.println("+++++++++++deltaX:" + deltaX + "/deltaY:" + deltaY + "---" + getScale());
        postTranslate(deltaX, deltaY);
    }
    return true;
}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private void drawAlphaPanel(final Canvas canvas) {

    if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
        return;// w ww .j  av  a  2 s  . c  o  m

    final RectF rect = mAlphaRect;

    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX,
                rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
    }

    mAlphaPattern.draw(canvas);

    final float[] hsv = new float[] { mHue, mSat, mVal };
    final int color = Color.HSVToColor(hsv);
    final int acolor = Color.HSVToColor(0, hsv);

    mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP);

    mAlphaPaint.setShader(mAlphaShader);

    canvas.drawRect(rect, mAlphaPaint);

    if (mAlphaSliderText != null && mAlphaSliderText != "") {
        canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint);
    }

    final float rectWidth = 4 * mDensity / 2;

    final Point p = alphaToPoint(mAlpha);

    final RectF r = new RectF();
    r.left = p.x - rectWidth;
    r.right = p.x + rectWidth;
    r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
    r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;

    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);

}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private void drawHuePanel(final Canvas canvas) {

    final RectF rect = mHueRect;

    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX,
                rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
    }//from   w w w  .  j a va 2 s  .  c o m

    if (mHueShader == null) {
        mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null,
                TileMode.CLAMP);
        mHuePaint.setShader(mHueShader);
    }

    canvas.drawRect(rect, mHuePaint);

    final float rectHeight = 4 * mDensity / 2;

    final Point p = hueToPoint(mHue);

    final RectF r = new RectF();
    r.left = rect.left - RECTANGLE_TRACKER_OFFSET;
    r.right = rect.right + RECTANGLE_TRACKER_OFFSET;
    r.top = p.y - rectHeight;
    r.bottom = p.y + rectHeight;

    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);

}

From source file:com.larvalabs.svgandroid.SVGParser.java

/**
 * This is where the hard-to-parse paths are handled.
 * Uppercase rules are absolute positions, lowercase are relative.
 * Types of path rules://from   w  w w  . java 2  s. c  o m
 * <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;
    RectF r = new RectF();
    char cmd = 'x';
    while (ph.pos < n) {
        char next = s.charAt(ph.pos);
        if (!Character.isDigit(next) && !(next == '.') && !(next == '-')) {
            cmd = next;
            ph.advance();
        } else if (cmd == 'M') { // implied command
            cmd = 'L';
        } else if (cmd == 'm') { // implied command
            cmd = 'l';
        } else { // implied command
            // Log.d(TAG, "Implied command: " + cmd);
        }
        p.computeBounds(r, true);
        // Log.d(TAG, "  " + cmd + " " + r);
        // Util.debug("* Commands remaining: '" + path + "'.");
        boolean wasCurve = false;
        switch (cmd) {
        case 'M':
        case 'm': {
            float x = ph.nextFloat();
            float y = ph.nextFloat();
            if (cmd == 'm') {
                p.rMoveTo(x, y);
                lastX += x;
                lastY += y;
            } else {
                p.moveTo(x, y);
                lastX = x;
                lastY = y;
            }
            break;
        }
        case 'Z':
        case 'z': {
            p.close();
            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();
            if (cmd == 'a') {
                x += lastX;
                y += lastY;
            }
            drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc == 1, sweepArc == 1);
            lastX = x;
            lastY = y;
            break;
        }
        default:
            Log.d(TAG, "Invalid path command: " + cmd);
            ph.advance();
        }
        if (!wasCurve) {
            lastX1 = lastX;
            lastY1 = lastY;
        }
        ph.skipWhitespace();
    }
    return p;
}

From source file:com.pdftron.pdf.tools.Tool.java

/**
 * Constructor./* w ww  .j  av  a  2 s  . c om*/
 */
public Tool(PDFViewCtrl ctrl) {
    mPDFView = ctrl;
    mNextToolMode = ToolManager.e_pan;
    mCurrentDefaultToolMode = ToolManager.e_pan;
    mAnnot = null;
    mAnnotBBox = new RectF();
    mJustSwitchedFromAnotherTool = false;
    mForceSameNextToolMode = false;
    mAvoidLongPressAttempt = false;
    mAnnotPushedBack = false;
    mMenuShown = false;
    mPageNumPosAdjust = 0;
    mShowPageNum = false;
    mTempPageDrawingRectF = new RectF();

    mTextSize = convDp2Pix(15);
    mTextVOffset = convDp2Pix(50);
    mPaint4PageNum = new Paint();
    mPaint4PageNum.setAntiAlias(true);
    mPaint4PageNum.setTextSize(mTextSize);
    mPaint4PageNum.setStyle(Paint.Style.FILL);

    mTempMtx1 = new Matrix();
    mTempMtx2 = new Matrix();

    mPageNumberIndicatorVisible = true;

    mAllowTwoFingerScroll = false;
    mAllowOneFingerScrollWithStylus = false;
    mAllowZoom = true;

    // Disable page turning (in non-continuous page presentation mode);
    // it is only turned on in Pan tool.
    mPDFView.setBuiltInPageSlidingEnabled(false);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(ctrl.getContext());
    mEdgeEffectRight = new EdgeEffectCompat(ctrl.getContext());
}

From source file:org.akop.ararat.view.CrosswordView.java

public CrosswordView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (!isInEditMode()) {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }//from   w ww .  ja va 2 s. c  om

    // Set drawing defaults
    Resources r = context.getResources();
    DisplayMetrics dm = r.getDisplayMetrics();

    int cellFillColor = NORMAL_CELL_FILL_COLOR;
    int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR;
    int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR;
    int selectedWordFillColor = SELECTED_WORD_FILL_COLOR;
    int selectedCellFillColor = SELECTED_CELL_FILL_COLOR;
    int markedCellFillColor = MARKED_CELL_FILL_COLOR;
    int numberTextColor = NUMBER_TEXT_COLOR;
    int cellStrokeColor = CELL_STROKE_COLOR;
    int circleStrokeColor = CIRCLE_STROKE_COLOR;
    int answerTextColor = ANSWER_TEXT_COLOR;

    mScaledDensity = dm.scaledDensity;
    float numberTextSize = NUMBER_TEXT_SIZE * mScaledDensity;
    mAnswerTextSize = ANSWER_TEXT_SIZE * mScaledDensity;

    mCellSize = CELL_SIZE * dm.density;
    mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density;
    mIsEditable = true;
    mInputMode = INPUT_MODE_KEYBOARD;
    mSkipOccupiedOnType = false;
    mSelectFirstUnoccupiedOnNav = true;
    mMaxBitmapSize = DEFAULT_MAX_BITMAP_DIMENSION;

    // Read supplied attributes
    if (attrs != null) {
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.CrosswordView, 0, 0);

        mCellSize = a.getDimension(R.styleable.CrosswordView_cellSize, mCellSize);
        mNumberTextPadding = a.getDimension(R.styleable.CrosswordView_numberTextPadding, mNumberTextPadding);
        numberTextSize = a.getDimension(R.styleable.CrosswordView_numberTextSize, numberTextSize);
        mAnswerTextSize = a.getDimension(R.styleable.CrosswordView_answerTextSize, mAnswerTextSize);
        answerTextColor = a.getColor(R.styleable.CrosswordView_answerTextColor, answerTextColor);
        cellFillColor = a.getColor(R.styleable.CrosswordView_defaultCellFillColor, cellFillColor);
        cheatedCellFillColor = a.getColor(R.styleable.CrosswordView_cheatedCellFillColor, cheatedCellFillColor);
        mistakeCellFillColor = a.getColor(R.styleable.CrosswordView_mistakeCellFillColor, mistakeCellFillColor);
        selectedWordFillColor = a.getColor(R.styleable.CrosswordView_selectedWordFillColor,
                selectedWordFillColor);
        selectedCellFillColor = a.getColor(R.styleable.CrosswordView_selectedCellFillColor,
                selectedCellFillColor);
        markedCellFillColor = a.getColor(R.styleable.CrosswordView_markedCellFillColor, markedCellFillColor);
        cellStrokeColor = a.getColor(R.styleable.CrosswordView_cellStrokeColor, cellStrokeColor);
        circleStrokeColor = a.getColor(R.styleable.CrosswordView_circleStrokeColor, circleStrokeColor);
        numberTextColor = a.getColor(R.styleable.CrosswordView_numberTextColor, numberTextColor);
        mIsEditable = a.getBoolean(R.styleable.CrosswordView_editable, mIsEditable);
        mSkipOccupiedOnType = a.getBoolean(R.styleable.CrosswordView_skipOccupiedOnType, mSkipOccupiedOnType);
        mSelectFirstUnoccupiedOnNav = a.getBoolean(R.styleable.CrosswordView_selectFirstUnoccupiedOnNav,
                mSelectFirstUnoccupiedOnNav);

        a.recycle();
    }

    mRevealSetsCheatFlag = true;
    mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION;

    // Init paints
    mCellFillPaint = new Paint();
    mCellFillPaint.setColor(cellFillColor);
    mCellFillPaint.setStyle(Paint.Style.FILL);

    mCheatedCellFillPaint = new Paint();
    mCheatedCellFillPaint.setColor(cheatedCellFillColor);
    mCheatedCellFillPaint.setStyle(Paint.Style.FILL);

    mMistakeCellFillPaint = new Paint();
    mMistakeCellFillPaint.setColor(mistakeCellFillColor);
    mMistakeCellFillPaint.setStyle(Paint.Style.FILL);

    mSelectedWordFillPaint = new Paint();
    mSelectedWordFillPaint.setColor(selectedWordFillColor);
    mSelectedWordFillPaint.setStyle(Paint.Style.FILL);

    mSelectedCellFillPaint = new Paint();
    mSelectedCellFillPaint.setColor(selectedCellFillColor);
    mSelectedCellFillPaint.setStyle(Paint.Style.FILL);

    mMarkedCellFillPaint = new Paint();
    mMarkedCellFillPaint.setColor(markedCellFillColor);
    mMarkedCellFillPaint.setStyle(Paint.Style.FILL);

    mCellStrokePaint = new Paint();
    mCellStrokePaint.setColor(cellStrokeColor);
    mCellStrokePaint.setStyle(Paint.Style.STROKE);
    //      mCellStrokePaint.setStrokeWidth(1);

    mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleStrokePaint.setColor(circleStrokeColor);
    mCircleStrokePaint.setStyle(Paint.Style.STROKE);
    mCircleStrokePaint.setStrokeWidth(1);

    mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberTextPaint.setColor(numberTextColor);
    mNumberTextPaint.setTextAlign(Paint.Align.CENTER);
    mNumberTextPaint.setTextSize(numberTextSize);

    // Compute number height
    mNumberTextPaint.getTextBounds("0", 0, "0".length(), mTempRect);
    mNumberTextHeight = mTempRect.height();

    mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberStrokePaint.setColor(cellFillColor);
    mNumberStrokePaint.setTextAlign(Paint.Align.CENTER);
    mNumberStrokePaint.setTextSize(numberTextSize);
    mNumberStrokePaint.setStyle(Paint.Style.STROKE);
    mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * mScaledDensity);

    mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mAnswerTextPaint.setColor(answerTextColor);
    mAnswerTextPaint.setTextSize(mAnswerTextSize);

    // Init rest of the values
    mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth();
    mPuzzleCells = EMPTY_CELLS;
    mPuzzleWidth = 0;
    mPuzzleHeight = 0;
    mAllowedChars = EMPTY_CHARS;

    mRenderScale = 0;
    mBitmapOffset = new PointF();
    mCenteredOffset = new PointF();
    mTranslationBounds = new RectF();

    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());

    mContentRect = new RectF();
    mPuzzleRect = new RectF();

    mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG);

    mScroller = new Scroller(context, null, true);
    mZoomer = new Zoomer(context);
    mUndoBuffer = new Stack<>();

    setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE);
    setOnKeyListener(this);
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void processScribble(Path scribble) {
    try {//from  w  ww. j a  v a 2  s. co  m
        // the file we're given via createTempFile is unplayable, but the name creation routine is useful...
        File outputFile = File.createTempFile(getString(R.string.app_name), ".mp4", getCacheDir());
        String outputFilePath = outputFile.getAbsolutePath();
        if (outputFile.delete()) {
            // get the bounding box and add to our list
            RectF scribbleBox = new RectF();
            scribble.computeBounds(scribbleBox, true);
            Rect audioArea = new Rect();
            scribbleBox.roundOut(audioArea);
            int scribbleWidth = Math
                    .round(getResources().getDimensionPixelSize(R.dimen.scribble_stroke_width) / 2f); // expand to include stroke width (half either side of line)
            audioArea.inset(-scribbleWidth, -scribbleWidth);

            // initialise recording
            resetRecordingInterface();
            mAudioRecorder = AudioRecorder.build(PaperChainsActivity.this, outputFilePath);

            mCurrentAudioRect = audioArea;
            mImageView.addAudioAreaRect(audioArea);
            mImageView.setScribbleEnabled(false);

            // position the recording buttons
            PointF centrePoint = mImageView
                    .imagePointToScreenPoint(new Point(audioArea.centerX(), audioArea.centerY()));
            initialiseRecordingButtons(centrePoint);
        } else {
            Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                    Toast.LENGTH_SHORT).show();
        }

    } catch (IOException | IllegalArgumentException e) {
        Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw regular cards with suits representing values on card
 * @param r application resources reference
 *//*from w ww . ja  va2  s.com*/
private void drawCards(final Resources r) {

    Paint cardFrontPaint = new Paint();
    Paint cardBorderPaint = new Paint();
    Bitmap[] suit = new Bitmap[4];
    Bitmap[] revSuit = new Bitmap[4];
    Bitmap[] smallSuit = new Bitmap[4];
    Bitmap redJack;
    Bitmap redQueen;
    Bitmap redKing;
    Bitmap blackJack;
    Bitmap blackQueen;
    Bitmap blackKing;
    Canvas canvas;
    final int width = Card.WIDTH;
    final int height = Card.HEIGHT;

    final String[] card_values = mResources.getStringArray(R.array.card_values);
    final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT);
    Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null);

    mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888);
    canvas = new Canvas(mCardHidden);
    drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT);
    drawable.draw(canvas);

    for (int i = 0; i < 4; i++) {
        suit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888);
        revSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(suit[i]);
        drawSuit(i, canvas, mSuitsSize);
        canvas = new Canvas(revSuit[i]);
        canvas.rotate(180, mSuitsSize / 2, mSuitsSize / 2);
        drawSuit(i, canvas, mSuitsSize);
    }

    for (int i = 0; i < 4; i++) {
        smallSuit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(smallSuit[i]);
        drawSuit(i, canvas, mSuitsSizeHalf);
    }

    final int faceWidth = width - 20;
    final int faceHeight = height / 2 - (int) mSuitsSize;
    blackJack = createFaceBitmap(r, R.drawable.blackjack, faceWidth, faceHeight);
    blackQueen = createFaceBitmap(r, R.drawable.blackqueen, faceWidth, faceHeight);
    blackKing = createFaceBitmap(r, R.drawable.blackking, faceWidth, faceHeight);
    redJack = createFaceBitmap(r, R.drawable.redjack, faceWidth, faceHeight);
    redQueen = createFaceBitmap(r, R.drawable.redqueen, faceWidth, faceHeight);
    redKing = createFaceBitmap(r, R.drawable.redking, faceWidth, faceHeight);

    cardBorderPaint.setARGB(255, 0, 0, 0);
    cardFrontPaint.setARGB(255, 255, 255, 255);
    RectF rectf = new RectF();
    for (int suitIdx = 0; suitIdx < 4; suitIdx++) {
        for (int valueIdx = 0; valueIdx < 13; valueIdx++) {
            mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]);
            drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint);
            drawCardValue(textPaintLeft, canvas, card_values[valueIdx], smallSuit[suitIdx], suitIdx);

            if (valueIdx >= 10) {
                canvas.drawBitmap(suit[suitIdx], mSuitsSize, mSuitsSize, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], width - mSuitsSize * 2, height - mSuitsSize * 2,
                        mSuitPaint);
            }

            final float height_7th = height / 7;
            final float height_9th = height / 9;
            // Columns
            final float width_5th = width / 5;
            final float[] suitX = { width_5th, width / 2 - mSuitsSizeHalf, width - width_5th - mSuitsSize };
            // Rows
            final float[] suitY = { height_7th, // row 1
                    height_9th * 3, // row 2
                    height - (height_9th * 4) - mSuitsSizeHalf / 2, // row 4
                    height - (height_7th * 2) }; // row 5
            // Center
            final float suitMidY = height / 2 - mSuitsSizeHalf;
            switch (valueIdx + 1) {
            case 1:
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint);
                break;
            case 2:
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint);
                break;
            case 3:
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint);
                break;
            case 4:
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint);
                break;
            case 5:
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint);
                break;
            case 6:
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint);
                break;
            case 7:
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint);
                break;
            case 8:
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint);
                canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2, mSuitPaint);
                break;
            case 9:
                for (int i = 0; i < 4; i++) {
                    canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint);
                    canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint);
                }
                canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint);
                break;
            case 10:
                for (int i = 0; i < 4; i++) {
                    canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint);
                    canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint);
                }
                canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2 - mSuitsSizeHalf,
                        mSuitPaint);
                canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2 + mSuitsSizeHalf / 2,
                        mSuitPaint);
                break;

            case Card.JACK:
                if ((suitIdx & 1) == 1) {
                    drawFaceBitmap(canvas, redJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                } else {
                    drawFaceBitmap(canvas, blackJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                }
                break;
            case Card.QUEEN:
                if ((suitIdx & 1) == 1) {
                    drawFaceBitmap(canvas, redQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                } else {
                    drawFaceBitmap(canvas, blackQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                }
                break;
            case Card.KING:
                if ((suitIdx & 1) == 1) {
                    drawFaceBitmap(canvas, redKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                } else {
                    drawFaceBitmap(canvas, blackKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint);
                }
                break;
            }
        }
    }
}

From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java

private void onAccountSelected(AccountProfileImageViewHolder holder, final ParcelableAccount account) {
    if (mSwitchAccountAnimationPlaying)
        return;/*from   www  .  java  2 s.  c o m*/
    final ImageView snapshotView = mFloatingProfileImageSnapshotView;
    final ShapedImageView profileImageView = mAccountProfileImageView;
    final ShapedImageView clickedImageView = holder.getIconView();

    // Reset snapshot view position
    snapshotView.setPivotX(0);
    snapshotView.setPivotY(0);
    snapshotView.setTranslationX(0);
    snapshotView.setTranslationY(0);

    final Matrix matrix = new Matrix();
    final RectF sourceBounds = new RectF(), destBounds = new RectF(), snapshotBounds = new RectF();
    getLocationOnScreen(clickedImageView, sourceBounds);
    getLocationOnScreen(profileImageView, destBounds);
    getLocationOnScreen(snapshotView, snapshotBounds);
    final float finalScale = destBounds.width() / sourceBounds.width();
    final Bitmap snapshotBitmap = TransitionUtils.createViewBitmap(clickedImageView, matrix,
            new RectF(0, 0, sourceBounds.width(), sourceBounds.height()));
    final ViewGroup.LayoutParams lp = snapshotView.getLayoutParams();
    lp.width = clickedImageView.getWidth();
    lp.height = clickedImageView.getHeight();
    snapshotView.setLayoutParams(lp);
    // Copied from MaterialNavigationDrawer: https://github.com/madcyph3r/AdvancedMaterialDrawer/
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_X, sourceBounds.left - snapshotBounds.left,
            destBounds.left - snapshotBounds.left))
            .with(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_Y,
                    sourceBounds.top - snapshotBounds.top, destBounds.top - snapshotBounds.top))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_X, 1, finalScale))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_Y, 1, finalScale))
            .with(ObjectAnimator.ofFloat(profileImageView, View.ALPHA, 1, 0))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_X, 0, 1))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_Y, 0, 1));
    final long animationTransition = 400;
    set.setDuration(animationTransition);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListener() {

        private Drawable clickedDrawable;
        private int[] clickedColors;

        @Override
        public void onAnimationStart(Animator animation) {
            snapshotView.setVisibility(View.VISIBLE);
            snapshotView.setImageBitmap(snapshotBitmap);
            final Drawable profileDrawable = profileImageView.getDrawable();
            clickedDrawable = clickedImageView.getDrawable();
            clickedColors = clickedImageView.getBorderColors();
            final ParcelableAccount oldSelectedAccount = mAccountsAdapter.getSelectedAccount();
            mImageLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount.profile_image_url,
                    profileDrawable);
            //                mImageLoader.displayDashboardProfileImage(profileImageView,
            //                        account.profile_image_url, clickedDrawable);
            clickedImageView.setBorderColors(profileImageView.getBorderColors());
            mSwitchAccountAnimationPlaying = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            finishAnimation();
        }

        private void finishAnimation() {
            final Editor editor = mPreferences.edit();
            editor.putLong(KEY_DEFAULT_ACCOUNT_ID, account.account_id);
            editor.apply();
            mAccountsAdapter.setSelectedAccountId(account.account_id);
            mAccountOptionsAdapter.setSelectedAccount(account);
            updateAccountOptionsSeparatorLabel(clickedDrawable);
            snapshotView.setVisibility(View.INVISIBLE);
            snapshotView.setImageDrawable(null);
            profileImageView.setImageDrawable(clickedDrawable);
            profileImageView.setBorderColors(clickedColors);
            profileImageView.setAlpha(1f);
            clickedImageView.setScaleX(1);
            clickedImageView.setScaleY(1);
            clickedImageView.setAlpha(1f);
            mSwitchAccountAnimationPlaying = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            finishAnimation();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    set.start();
}