Example usage for android.graphics Paint set

List of usage examples for android.graphics Paint set

Introduction

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

Prototype

public void set(Paint src) 

Source Link

Document

Copy the fields from src into this paint.

Usage

From source file:com.pipit.agc.adapter.DayPickerAdapter.java

private void refitText(TextView txtv, int targetheight) {
    if (targetheight <= 0)
        return;/*from  www.  j a  v a2  s  .  c o m*/
    Paint mTestPaint = new Paint();
    mTestPaint.set(txtv.getPaint());
    float hi = 100;
    float lo = 2;
    final float threshold = 0.5f; // How close we have to be

    while ((hi - lo) > threshold) {
        float size = (hi + lo) / 2;
        mTestPaint.setTextSize(size);
        if (mTestPaint.measureText((String) txtv.getText()) >= targetheight)
            hi = size; // too big
        else
            lo = size; // too small
    }
    // Use lo so that we undershoot rather than overshoot
    txtv.setTextSize(TypedValue.COMPLEX_UNIT_PX, lo);
}