Arthur
Arthur

Reputation: 1548

Android widget text looks blurry

Drawing widget text looks very blurry compared to launcher icon text of roughly the same size. Found some tricks here at Stackoverflow but they didn't help.

How can I use the same sharp font as the launcher?

Screenshot

Code used to draw:

Bitmap drawWidget(JSONArray result) {
    int pixelsize = (int)Math.round(72.0 * SettingsActivity.density);
    if (pixelsize > 0) {
        Log.i(TAG, "pixel size = " + pixelsize);
        Bitmap b = Bitmap.createBitmap(pixelsize, pixelsize, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        Paint p = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        p.setAntiAlias(true);
        p.setStyle(Paint.Style.FILL);
        p.setColor(Color.WHITE);
        p.setTextSize(10f);

        int y = 10;

        for (TemperatureItem t : temperatureItems) {
            double temp = getTemperature(result, t.getName());
            c.drawText(t.getName() + ": " + temp, 0, y, p);
            y += 10;
        }
        c.drawText(new SimpleDateFormat("HH:mm:ss").format(new Date()), 0, y, p);
        return b;
    } else {
        return null;
    }

Widget provider:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/widgetlayout"
    android:minHeight="72dp"
    android:minWidth="72dp"
    android:updatePeriodMillis="1800000" >

</appwidget-provider> 

Widget layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="0dip"
    android:background="#000000" >

    <ImageView
        android:id="@+id/update"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center_horizontal|center_vertical"
        android:layout_margin="0dip"
        android:text="Static Text" >
    </ImageView>
</LinearLayout>

Upvotes: 0

Views: 587

Answers (1)

snachmsm
snachmsm

Reputation: 19273

try another flag Paint.SUBPIXEL_TEXT_FLAG

Upvotes: 1

Related Questions