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;
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations