Example usage for android.graphics Canvas getHeight

List of usage examples for android.graphics Canvas getHeight

Introduction

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

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the current drawing layer

Usage

From source file:rosmi.acagild.alarmclock.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher));
    layout.addView(logo);// w  w  w.ja v  a  2  s.  c om

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher_no_bg));
    layout.addView(logo);//  w w w. ja  v  a  2s. co m

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:org.telegram.ui.Cells.ProfileSearchCell.java

@Override
protected void onDraw(Canvas canvas) {
    if (user == null && chat == null && encryptedChat == null) {
        return;//w ww  .j a va  2  s. c o  m
    }

    if (useSeparator) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1,
                    getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline),
                    getMeasuredHeight() - 1, linePaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1,
                    getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
        }
    }

    if (drawAlpha != 1) {
        canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int) (255 * drawAlpha),
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    if (drawNameLock) {
        setDrawableBounds(lockDrawable, nameLockLeft, nameLockTop);
        lockDrawable.draw(canvas);
    } else if (drawNameGroup) {
        setDrawableBounds(groupDrawable, nameLockLeft, nameLockTop);
        groupDrawable.draw(canvas);
    } else if (drawNameBroadcast) {
        setDrawableBounds(broadcastDrawable, nameLockLeft, nameLockTop);
        broadcastDrawable.draw(canvas);
    } else if (drawNameBot) {
        setDrawableBounds(botDrawable, nameLockLeft, nameLockTop);
        botDrawable.draw(canvas);
    }

    if (nameLayout != null) {
        canvas.save();
        canvas.translate(nameLeft, nameTop);
        nameLayout.draw(canvas);
        canvas.restore();
        if (drawCheck) {
            if (LocaleController.isRTL) {
                setDrawableBounds(checkDrawable,
                        nameLeft - AndroidUtilities.dp(4) - checkDrawable.getIntrinsicWidth(), nameLockTop);
            } else {
                setDrawableBounds(checkDrawable,
                        nameLeft + (int) nameLayout.getLineWidth(0) + AndroidUtilities.dp(4), nameLockTop);
            }
            checkDrawable.draw(canvas);
        }
    }

    if (onlineLayout != null) {
        canvas.save();
        canvas.translate(onlineLeft, AndroidUtilities.dp(40));
        onlineLayout.draw(canvas);
        canvas.restore();
    }

    if (countLayout != null) {
        if (MessagesController.getInstance().isDialogMuted(dialog_id)) {
            setDrawableBounds(countDrawableGrey, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawableGrey.getIntrinsicHeight());
            countDrawableGrey.draw(canvas);
        } else {
            setDrawableBounds(countDrawable, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight());
            countDrawable.draw(canvas);
        }
        canvas.save();
        canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
        countLayout.draw(canvas);
        canvas.restore();
    }

    avatarImage.draw(canvas);
}

From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private void createSharableBitmap() {
    Bitmap sharableBitmap = Bitmap.createBitmap(getView().getWidth(), getView().getHeight(),
            Bitmap.Config.ARGB_8888);// ww w . java 2s  .c  o m
    Canvas canvas = new Canvas(sharableBitmap);
    canvas.drawColor(ContextCompat.getColor(getContext(), R.color.white));

    // Load the view for the sharable. This will be drawn to the bitmap
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_sharable_tongue_twister, null);

    TextView textView = (TextView) layout.findViewById(R.id.twister_sharable_tongue_twister);
    textView.setText(mQuestion);

    textView = (TextView) layout.findViewById(R.id.twister_sharable_i_said);
    textView.setText(mUnderstoodText);

    textView = (TextView) layout.findViewById(R.id.mimic_twister_share_success);
    textView.setText(mSuccessMessage);

    // Perform the layout using the dimension of the bitmap
    int widthSpec = View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY);
    layout.measure(widthSpec, heightSpec);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    // Draw the generated view to canvas
    layout.draw(canvas);

    String title = getString(R.string.app_short_name) + ": " + getString(R.string.mimic_twister_name);
    mSharableUri = ShareFragment.saveShareableBitmap(getActivity(), sharableBitmap, title);
}

From source file:com.mylikes.likes.etchasketch.Slate.java

private void drawStrokeDebugInfo(Canvas c) {
    final int ROW_HEIGHT = 24;
    final int ROW_MARGIN = 6;
    final int COLUMN_WIDTH = 55;

    final float FIRM_PRESSURE_LOW = 0.85f;
    final float FIRM_PRESSURE_HIGH = 1.25f;

    if (mStrokeDebugGraph == null) {
        final int width = c.getWidth() - 128;
        final int height = ROW_HEIGHT * mStrokes.length + 2 * ROW_MARGIN;
        mStrokeDebugGraph = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        if (mStrokeDebugGraph == null) {
            throw new RuntimeException(
                    "drawStrokeDebugInfo: couldn't create debug bitmap (" + width + "x" + height + ")");
        }//from   w w  w  . ja v  a2s .  c o  m
        mGraphPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    Canvas graph = new Canvas(mStrokeDebugGraph);
    graph.save();
    graph.clipRect(new Rect(0, 0, COLUMN_WIDTH, graph.getHeight()));
    graph.drawColor(0, PorterDuff.Mode.CLEAR);
    graph.restore();

    int left = 4;
    int bottom = graph.getHeight() - ROW_MARGIN;
    final int STEP = 4;
    for (MarkersPlotter st : mStrokes) {
        float r = st.getLastPressure();

        if (r >= FIRM_PRESSURE_LOW && r <= FIRM_PRESSURE_HIGH)
            mGraphPaint1.setColor(0xFF33FF33);
        else if (r < FIRM_PRESSURE_LOW)
            mGraphPaint1.setColor(0xFF808080);
        else
            mGraphPaint1.setColor(0xFFFF8000);

        String s = (r < 0) ? "--"
                : String.format("%s %.4f", ((st.getLastTool() == MotionEvent.TOOL_TYPE_STYLUS) ? "S" : "F"), r);

        graph.drawText(s, left, bottom - 2, mGraphPaint1);

        if (mGraphX + COLUMN_WIDTH > graph.getWidth()) {
            mGraphX = 0;
            graph.save();
            graph.clipRect(new Rect(30, 0, graph.getWidth(), graph.getHeight()));
            graph.drawColor(0, PorterDuff.Mode.CLEAR);
            graph.restore();
        }

        if (r >= 0) {
            int barsize = (int) (r * ROW_HEIGHT);
            graph.drawRect(mGraphX + COLUMN_WIDTH, bottom - barsize, mGraphX + COLUMN_WIDTH + STEP, bottom,
                    mGraphPaint1);
        } else {
            graph.drawPoint(mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1);
        }
        bottom -= (ROW_HEIGHT + ROW_MARGIN);
    }

    mGraphX += STEP;

    final int x = 96;
    final int y = 64;

    c.drawBitmap(mStrokeDebugGraph, x, y, null);
    invalidate(new Rect(x, y, x + c.getWidth(), y + c.getHeight()));
}

From source file:com.tbse.mywearapplication.WatchFaceDrawer.java

void onDraw(Context context, IWatchFaceConfig config, Canvas canvas, Rect bounds) {
    final Calendar calendar = config.getCalendar();
    final boolean isAmbient = config.isAmbient();
    final boolean isRound = config.isRound();
    final boolean useLightTheme = !isAmbient && config.isLightTheme();

    mBackgroundPaint.setColor(ContextCompat.getColor(context,
            useLightTheme ? R.color.watchface_background_light : R.color.watchface_background));

    /////////////////////////////////////////////////////////////////////
    // Draw your watch face here, using the provided canvas and bounds //
    /////////////////////////////////////////////////////////////////////

    final int width = bounds.width();
    final int height = bounds.height();

    // Find the center. Ignore the window insets so that, on round
    // watches with a "chin", the watch face is centered on the entire
    // screen, not just the usable portion.
    final float centerX = width / 2f;
    final float centerY = height / 2f;

    // Draw the background.
    if (mIsMobilePreview) {
        if (isRound) {
            canvas.drawCircle(centerX, centerY, centerX, mPreviewBorderPaint);
        } else {//from   w  ww .jav a2  s.c o m
            final float radius = mPreviewSquareRadius;
            final RectF rectF = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
            canvas.drawRoundRect(rectF, radius, radius, mPreviewBorderPaint);
        }

        final float translateXY = width * 0.05f;
        canvas.translate(translateXY, translateXY);
        canvas.scale(0.9f, 0.9f);

        if (isRound) {
            canvas.drawCircle(centerX, centerY, centerX, mBackgroundPaint);
        } else {
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
        }
    } else {
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
    }

    // Draw weather icon
    if (image != null) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(50, 90);
        matrix.preScale(0.2f, 0.2f);
        canvas.drawBitmap(image, matrix, null);
    }

    final float secRot = calendar.get(Calendar.SECOND) / 30f * (float) Math.PI;
    final int minutes = calendar.get(Calendar.MINUTE);
    final float minRot = minutes / 30f * (float) Math.PI;
    final float hrRot = ((calendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI;

    final float secLength = centerX - mSecondOuterOffset;
    final float minLength = centerX - mMinuteOuterOffset;
    final float hrLength = centerX - mHourOuterOffset;

    if (!isAmbient) {
        final float secX = (float) Math.sin(secRot) * secLength;
        final float secY = (float) -Math.cos(secRot) * secLength;
        canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mSecondHandPaint);
    }

    final float minX = (float) Math.sin(minRot) * minLength;
    final float minY = (float) -Math.cos(minRot) * minLength;
    canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mMinuteHandPaint);

    final float hrX = (float) Math.sin(hrRot) * hrLength;
    final float hrY = (float) -Math.cos(hrRot) * hrLength;
    canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHourHandPaint);

    // Draw weather text
    canvas.drawText(day, 50, 50, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(low, 50, 65, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(high, 80, 65, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(weatherDescription, 50, 80, isAmbient ? ambientTextPaint : textPaint);

}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
protected void onDraw(Canvas canvas) {
    try {/*  w w w.  jav  a 2 s. c  o  m*/

        app.killOnError(); // ?  ?

        // ? ??  (? ???  ?)
        MixView.dWindow.setWidth(canvas.getWidth());
        MixView.dWindow.setHeight(canvas.getHeight());
        MixView.dWindow.setCanvas(canvas); //  

        // ??   ? ?   
        if (!MixView.getDataView().isInited()) {
            MixView.getDataView().init(MixView.dWindow.getWidth(), MixView.dWindow.getHeight());
        }

        // ?? ? ??? ?? 
        MixView.getDataView().draw(MixView.dWindow);

    } catch (Exception ex) {
        app.doError(ex);
    }
}

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

@Override
public boolean onDrawEdgeEffects(Canvas canvas, int width, int verticalOffset) {
    boolean needsInvalidate = false;

    if (!mEdgeEffectLeft.isFinished()) {
        canvas.save();/*  ww w  .jav  a  2  s.  c o m*/
        try {
            canvas.translate(0, canvas.getHeight() + verticalOffset);
            canvas.rotate(-90, 0, 0);
            mEdgeEffectLeft.setSize(canvas.getHeight(), canvas.getWidth());
            if (mEdgeEffectLeft.draw(canvas)) {
                needsInvalidate = true;
            }
        } finally {
            canvas.restore();
        }
    }

    if (!mEdgeEffectRight.isFinished()) {
        canvas.save();
        try {
            canvas.translate(width, verticalOffset);
            canvas.rotate(90, 0, 0);
            mEdgeEffectRight.setSize(canvas.getHeight(), canvas.getWidth());
            if (mEdgeEffectRight.draw(canvas)) {
                needsInvalidate = true;
            }
        } finally {
            canvas.restore();
        }
    }
    return needsInvalidate;
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the horizontal axis title if/*w ww  .  j a v  a2 s. c o  m*/
 * it is set
 * @param canvas canvas
 */
protected void drawHorizontalAxisTitle(Canvas canvas) {
    if (mHorizontalAxisTitle != null && mHorizontalAxisTitle.length() > 0) {
        mPaintAxisTitle.setColor(getHorizontalAxisTitleColor());
        mPaintAxisTitle.setTextSize(getHorizontalAxisTitleTextSize());
        float x = canvas.getWidth() / 2;
        float y = canvas.getHeight() - mStyles.padding;
        canvas.drawText(mHorizontalAxisTitle, x, y, mPaintAxisTitle);
    }
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the vertical axis title if//w w  w .ja  v  a  2s .co m
 * it is set
 * @param canvas canvas
 */
protected void drawVerticalAxisTitle(Canvas canvas) {
    if (mVerticalAxisTitle != null && mVerticalAxisTitle.length() > 0) {
        mPaintAxisTitle.setColor(getVerticalAxisTitleColor());
        mPaintAxisTitle.setTextSize(getVerticalAxisTitleTextSize());
        float x = getVerticalAxisTitleWidth();
        float y = canvas.getHeight() / 2;
        canvas.save();
        canvas.rotate(-90, x, y);
        canvas.drawText(mVerticalAxisTitle, x, y, mPaintAxisTitle);
        canvas.restore();
    }
}