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:com.github.kubatatami.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());
    bounds.bottom = paint.descent() - paint.ascent();
    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);// ww  w  . j a  v  a  2s  .c o  m

    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (imageOffset != 0) {
        canvas.save();/*from  w w w .ja  v a  2 s .c o  m*/
        canvas.translate(0f, imageOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset);
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
        canvas.restore();
    } else {
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
    }
}

From source file:com.github.kubatatami.RoundedView.java

private void drawChecked(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_check);

    float posX = (canvas.getWidth() - bitmap.getWidth()) / 2;
    float posY = (canvas.getHeight() - bitmap.getHeight()) / 2;

    canvas.drawBitmap(bitmap, posX, posY, paint);
}

From source file:com.forrestguice.suntimeswidget.LightMapView.java

private void drawRect(Canvas c, Paint p) {
    int w = c.getWidth();
    int h = c.getHeight();
    c.drawRect(0, 0, w, h, p);//  w w  w .  ja  v  a 2 s.  co m
}

From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Fragment rawFragment = getTargetFragment();
    if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
        throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface");
    }//  w  w w .ja v a 2 s  .  c  o m

    final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;

    final String key = getArguments().getString(ARG_KEY);
    if (savedInstanceState == null) {
        mPreference = (DialogPreference) fragment.findPreference(key);
        mDialogTitle = mPreference.getDialogTitle();
        mPositiveButtonText = mPreference.getPositiveButtonText();
        mNegativeButtonText = mPreference.getNegativeButtonText();
        mDialogMessage = mPreference.getDialogMessage();
        mDialogLayoutRes = mPreference.getDialogLayoutResource();

        final Drawable icon = mPreference.getDialogIcon();
        if (icon == null || icon instanceof BitmapDrawable) {
            mDialogIcon = (BitmapDrawable) icon;
        } else {
            final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            icon.draw(canvas);
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    } else {
        mDialogTitle = savedInstanceState.getCharSequence(SAVE_STATE_TITLE);
        mPositiveButtonText = savedInstanceState.getCharSequence(SAVE_STATE_POSITIVE_TEXT);
        mNegativeButtonText = savedInstanceState.getCharSequence(SAVE_STATE_NEGATIVE_TEXT);
        mDialogMessage = savedInstanceState.getCharSequence(SAVE_STATE_MESSAGE);
        mDialogLayoutRes = savedInstanceState.getInt(SAVE_STATE_LAYOUT, 0);
        final Bitmap bitmap = savedInstanceState.getParcelable(SAVE_STATE_ICON);
        if (bitmap != null) {
            mDialogIcon = new BitmapDrawable(getResources(), bitmap);
        }
    }
}

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());

    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());

    bounds.bottom = paint.descent() - paint.ascent();

    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);/*from  ww w . j a  va2  s  . c om*/
    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:ecust.news.myWidgetTabPageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    ///*from  w w  w  .j  av  a 2 s . c om*/
    int w = Global.dimenConvert.dip2px(dp_FocusedLineHeight) / 2;
    int y = canvas.getHeight() - w / 2;

    paint.setColor(Color.WHITE);
    paint.setStrokeWidth(w);
    canvas.drawLine(0, y, canvas.getMaximumBitmapWidth(), y, paint);
}

From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java

private void rotateArrow() {
    final Drawable drawable = mHeaderArrow.getDrawable();
    final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Config.ARGB_8888);//from  w w  w. ja  va 2 s. co m
    final Canvas canvas = new Canvas(bitmap);
    canvas.save();
    canvas.rotate(180.0f, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    canvas.restore();
    mHeaderArrow.setImageBitmap(bitmap);
}

From source file:com.huahcoding.metrojam.BackTrackActivity.java

/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa./* w w  w.  j  a  va  2  s .  c om*/
 * <p>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    mMap.getUiSettings().setZoomControlsEnabled(false);

    // Show Lima
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chileLatLng, 15));

    mMap.setOnMapLongClickListener(this);
    mMap.setMyLocationEnabled(true);
    mMap.setTrafficEnabled(true);

    // Instantiates a new Polyline object and adds points to define a rectangle
    PolylineOptions rectOptions = new PolylineOptions();
    double[] route = RouteTestData.getChilePoints3();
    for (int i = 0; i < route.length - 1; i += 2) {
        LatLng ll = new LatLng(route[i], route[i + 1]);
        if (i > 1) {
            double lat = (route[i] + route[i - 2]) / 2.0;
            double lng = (route[i + 1] + route[i + 1 - 2]) / 2.0;
            double dist = distance(route[i], route[i + 1], route[i - 2], route[i + 1 - 2]);
            String pretty = getPrettyDistance(dist);

            LatLng ll2 = new LatLng(lat, lng);
            String strText = pretty;
            Rect boundsText = new Rect();
            Paint textPaint = new Paint();
            textPaint.setTextSize(18);
            textPaint.getTextBounds(strText, 0, strText.length(), boundsText);

            textPaint.setColor(Color.RED);

            Bitmap.Config conf = Bitmap.Config.ARGB_8888;
            Bitmap bmpText = Bitmap.createBitmap(boundsText.width() * 3, boundsText.height(), conf);

            Canvas canvasText = new Canvas(bmpText);
            canvasText.drawText(strText, canvasText.getWidth() / 2, canvasText.getHeight(), textPaint);

            MarkerOptions markerOptions = new MarkerOptions().position(ll2)
                    .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1);
            mMap.addMarker(markerOptions);
        }
        rectOptions.add(ll);
    }
    //         rectOptions.
    // Get back the mutable Polyline
    mMap.addPolyline(rectOptions);
}

From source file:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (imageOffset != 0) {
        canvas.save();/*from w ww  .  j ava  2  s . co  m*/
        canvas.translate(0f, imageOffset);
        Log.i("imageOffset", "onDraw: " + imageOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset);
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
        canvas.restore();
    } else {
        super.onDraw(canvas);
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
    }
}