Search in sources :

Example 46 with Typeface

use of android.graphics.Typeface in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class Protocol method createOled1line.

public static byte[] createOled1line(Context context, String icon, String line) {
    int offset = 0;
    if (icon != null)
        offset += 17;
    Bitmap image = Bitmap.createBitmap(80, 16, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTextSize(16);
    Typeface typeface = Typeface.createFromAsset(context.getAssets(), "metawatch_16pt_11pxl.ttf");
    paint.setTypeface(typeface);
    canvas.drawColor(Color.WHITE);
    canvas.drawText(line, offset, 14, paint);
    if (icon != null) {
        canvas.drawBitmap(Utils.loadBitmapFromAssets(context, icon), 0, 0, null);
    }
    int[] poleInt = new int[16 * 80];
    image.getPixels(poleInt, 0, 80, 0, 0, 80, 16);
    byte[] display = new byte[160];
    for (int i = 0; i < 160; i++) {
        boolean[] column = new boolean[8];
        for (int j = 0; j < 8; j++) {
            if (i < 80) {
                if (poleInt[80 * j + i] == Color.WHITE)
                    column[j] = false;
                else
                    column[j] = true;
            } else {
                if (poleInt[80 * 8 + 80 * j + i - 80] == Color.WHITE)
                    column[j] = false;
                else
                    column[j] = true;
            }
        }
        for (int j = 0; j < 8; j++) {
            if (column[j])
                display[i] += Math.pow(2, j);
        }
    }
    return display;
}
Also used : Bitmap(android.graphics.Bitmap) Typeface(android.graphics.Typeface) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 47 with Typeface

use of android.graphics.Typeface in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class Protocol method createTextBitmap.

public static Bitmap createTextBitmap(Context context, String text) {
    String font = null;
    int size = 8;
    switch(Preferences.fontSize) {
        case FontSize.SMALL:
            font = "metawatch_8pt_5pxl_CAPS.ttf";
            break;
        case FontSize.MEDIUM:
            font = "metawatch_8pt_7pxl_CAPS.ttf";
            break;
        case FontSize.LARGE:
            font = "metawatch_16pt_11pxl.ttf";
            size = 16;
            break;
    }
    Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTextSize(size);
    Typeface typeface = Typeface.createFromAsset(context.getAssets(), font);
    paint.setTypeface(typeface);
    canvas.drawColor(Color.WHITE);
    canvas = breakText(canvas, text, paint, 0, 0);
    /*
		FileOutputStream fos = new FileOutputStream("/sdcard/test.png");
		image.compress(Bitmap.CompressFormat.PNG, 100, fos);
		fos.close();
		Log.d("ow", "bmp ok");
		*/
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Typeface(android.graphics.Typeface) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 48 with Typeface

use of android.graphics.Typeface in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class Protocol method createOled2linesLong.

public static int createOled2linesLong(Context context, String line, byte[] display) {
    int offset = 0 - 79;
    /*
		if (logo)
			offset += 17;
		*/
    final int width = 800;
    Bitmap image = Bitmap.createBitmap(width, 8, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTextSize(8);
    Typeface typeface = Typeface.createFromAsset(context.getAssets(), "metawatch_8pt_5pxl_CAPS.ttf");
    paint.setTypeface(typeface);
    canvas.drawColor(Color.WHITE);
    canvas.drawText(line, offset, 7, paint);
    /*
		if (logo) {
			Bitmap imageImmutable = BitmapFactory.decodeResource(context.getResources(), iconType);
			Bitmap imageIcon = imageImmutable.copy(Bitmap.Config.RGB_565, true);
			canvas.drawBitmap(imageIcon, 0, 0, null);
		}
		*/
    int[] poleInt = new int[8 * width];
    image.getPixels(poleInt, 0, width, 0, 0, width, 8);
    for (int i = 0; i < width; i++) {
        boolean[] column = new boolean[8];
        for (int j = 0; j < 8; j++) {
            if (poleInt[width * j + i] == Color.WHITE)
                column[j] = false;
            else
                column[j] = true;
        }
        for (int j = 0; j < 8; j++) {
            if (column[j])
                display[i] += Math.pow(2, j);
        }
    }
    int len = (int) paint.measureText(line);
    return (int) paint.measureText(line) - 79;
}
Also used : Bitmap(android.graphics.Bitmap) Typeface(android.graphics.Typeface) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 49 with Typeface

use of android.graphics.Typeface in project Carbon by ZieIony.

the class Button method setTextAppearanceInternal.

private void setTextAppearanceInternal(int resid) {
    TypedArray appearance = getContext().obtainStyledAttributes(resid, R.styleable.TextAppearance);
    if (appearance != null) {
        for (int i = 0; i < appearance.getIndexCount(); i++) {
            int attr = appearance.getIndex(i);
            if (attr == R.styleable.TextAppearance_carbon_textAllCaps) {
                setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_carbon_textAllCaps, true));
            } else if (!isInEditMode() && attr == R.styleable.TextAppearance_carbon_fontPath) {
                String path = appearance.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setTypeface(typeface);
            } else if (attr == R.styleable.TextAppearance_carbon_fontFamily) {
                int textStyle = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), appearance.getString(attr), textStyle);
                setTypeface(typeface);
            }
        }
        appearance.recycle();
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint)

Example 50 with Typeface

use of android.graphics.Typeface in project Carbon by ZieIony.

the class EditText method setTextAppearanceInternal.

private void setTextAppearanceInternal(int resid) {
    TypedArray appearance = getContext().obtainStyledAttributes(resid, R.styleable.TextAppearance);
    if (appearance != null) {
        for (int i = 0; i < appearance.getIndexCount(); i++) {
            int attr = appearance.getIndex(i);
            if (attr == R.styleable.TextAppearance_carbon_textAllCaps) {
                setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_carbon_textAllCaps, true));
            } else if (!isInEditMode() && attr == R.styleable.TextAppearance_carbon_fontPath) {
                String path = appearance.getString(attr);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
                setTypeface(typeface);
            } else if (attr == R.styleable.TextAppearance_carbon_fontFamily) {
                int textStyle = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0);
                Typeface typeface = TypefaceUtils.getTypeface(getContext(), appearance.getString(attr), textStyle);
                setTypeface(typeface);
            }
        }
        appearance.recycle();
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint)

Aggregations

Typeface (android.graphics.Typeface)266 Paint (android.graphics.Paint)57 TextPaint (android.text.TextPaint)40 TypedArray (android.content.res.TypedArray)34 TextView (android.widget.TextView)21 View (android.view.View)20 Canvas (android.graphics.Canvas)15 Bitmap (android.graphics.Bitmap)13 Context (android.content.Context)11 Resources (android.content.res.Resources)10 Test (org.junit.Test)8 ColorStateList (android.content.res.ColorStateList)7 Legend (com.github.mikephil.charting.components.Legend)7 File (java.io.File)7 Intent (android.content.Intent)6 Attributes (com.cengalabs.flatui.Attributes)6 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 ContentResolver (android.content.ContentResolver)5 Drawable (android.graphics.drawable.Drawable)5