Fields Summary |
---|
private static final int | MIN_SIZE |
private static final int | MAX_SIZE |
private static final float | SCALE_X_RANGE |
private static final int | MAX_SCALE_X |
private static final int | MIN_SCALE_X |
private static final String[] | sText |
private static final String[] | sStyleName |
private static final String[] | sTypefaceName |
private static final android.graphics.Typeface[] | sTypeface |
private static final int | FONT_INDEX_SANS |
private static final int | FONT_INDEX_SERIF |
private static final int | FONT_INDEX_MONO |
private MenuItem.OnMenuItemClickListener | mFontClickListener |
private MenuItem.OnMenuItemClickListener | mStyleClickListener |
private MenuItem.OnMenuItemClickListener | mFlagClickListener |
private int | mGamma |
MenuItem.OnMenuItemClickListener | mTextCallback |
private static final int | BACKGROUND_PICKED |
private android.widget.TextView | mColumn1 |
private android.widget.TextView | mColumn2 |
private android.view.View | mContentView |
private int | mFontIndex |
private int | mFontStyle |
private int | mFontSize |
private int | mTextIndex |
private int | mTextScaleXDelta |
Methods Summary |
---|
private void | addFlagMenu(android.view.Menu menu, int paintFlag, java.lang.String label, char shortCut)
MenuItem item = menu.add(0, paintFlag, 0, label);
item.setCheckable(true);
item.setOnMenuItemClickListener(mFlagClickListener);
item.setChecked((mColumn1.getPaintFlags() & paintFlag) != 0);
if (shortCut != 0) {
item.setAlphabeticShortcut(shortCut);
}
|
private void | addFontMenu(android.view.Menu menu, int index)
MenuItem item = menu.add(0, index, 0, sTypefaceName[index]);
item.setCheckable(true);
item.setOnMenuItemClickListener(mFontClickListener);
item.setChecked(index == mFontIndex);
|
private static void | addListenerMenu(android.view.MenuItem item, MenuItem.OnMenuItemClickListener listener, char keyChar)
item.setOnMenuItemClickListener(listener);
if (keyChar != '\0") {
item.setAlphabeticShortcut(keyChar);
}
|
private void | addStyleMenu(android.view.Menu menu, int style, char shortCut)
MenuItem item = menu.add(0, style, 0, (style == Typeface.BOLD) ? "Bold" : "Italic");
item.setCheckable(true);
item.setOnMenuItemClickListener(mStyleClickListener);
item.setChecked((mFontStyle & style) != 0);
item.setVisible(canSupportStyle(sTypeface[mFontIndex], style));
if (shortCut != 0) {
item.setAlphabeticShortcut(shortCut);
}
|
private static boolean | canSupportStyle(android.graphics.Typeface tf, int styleBits) // index into sTypeface
tf = Typeface.create(tf, styleBits);
return (tf.getStyle() & styleBits) == styleBits;
|
private void | changeGamma(int delta) // current default is 1.4 (* 20)
int gamma = Math.min(100, Math.max(1, mGamma + delta));
if (gamma != mGamma) {
mGamma = gamma;
updateTitle();
// Paint.setTextGamma(mGamma / 20.f);
mContentView.invalidate();
android.util.Log.d("skia", "setTextGamma " + mGamma);
}
|
protected void | onActivityResult(int requestCode, int resultCode, java.lang.String data, java.util.Map extras)
if (resultCode == RESULT_OK) {
switch (requestCode) {
case BACKGROUND_PICKED:
{
int color = ((Integer)extras.get("text")).intValue();
mColumn1.setTextColor(color);
mColumn2.setTextColor(color);
int colorTranslucent = (color & 0x00FFFFFF) + 0x77000000;
setTitleColor(color);
Integer texture = (Integer)extras.get("texture");
if (texture != null) {
mContentView.setBackgroundResource(texture.intValue());
} else {
color = ((Integer)extras.get("bgcolor")).intValue();
mContentView.setBackgroundColor(color);
}
}
break;
}
}
|
public void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
setContentView(R.layout.font_lab);
mColumn1 = (TextView)findViewById(R.id.column1);
mColumn2 = (TextView)findViewById(R.id.column2);
mContentView = findViewById(R.id.content);
mColumn1.setTextSize(mFontSize);
mColumn2.setTextSize(mFontSize);
mColumn1.setTextColor(Color.BLACK);
mColumn1.setBackgroundDrawable(new PaintDrawable(Color.WHITE));
mColumn2.setTextColor(Color.WHITE);
mColumn2.setBackgroundDrawable(new PaintDrawable(Color.BLACK));
refreshFont();
updateTitle();
updateText();
setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT);
|
public boolean | onCreateOptionsMenu(android.view.Menu menu)
super.onCreateOptionsMenu(menu);
return true;
|
public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)
int size = mFontSize;
int scaleX = mTextScaleXDelta;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_DOWN:
size -= 1;
break;
case KeyEvent.KEYCODE_DPAD_UP:
size += 1;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
scaleX += 1;
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
scaleX -= 1;
break;
/*
case KeyEvent.KEYCODE_U:
changeGamma(1);
return true;
case KeyEvent.KEYCODE_D:
changeGamma(-1);
return true;
*/
default:
return super.onKeyDown(keyCode, event);
}
size = Math.min(MAX_SIZE, Math.max(MIN_SIZE, size));
if (size != mFontSize) {
mFontSize = size;
mColumn1.setTextSize(mFontSize);
mColumn2.setTextSize(mFontSize);
updateTitle();
return true;
}
scaleX = Math.min(MAX_SCALE_X, Math.max(MIN_SCALE_X, scaleX));
if (scaleX != mTextScaleXDelta) {
mTextScaleXDelta = scaleX;
mColumn1.setTextScaleX(1 + scaleX / SCALE_X_RANGE);
mColumn2.setTextScaleX(1 + scaleX / SCALE_X_RANGE);
updateTitle();
return true;
}
return super.onKeyDown(keyCode, event);
|
public boolean | onPrepareOptionsMenu(android.view.Menu menu)
super.onPrepareOptionsMenu(menu);
menu.clear();
addFontMenu(menu, FONT_INDEX_SANS);
addFontMenu(menu, FONT_INDEX_SERIF);
addFontMenu(menu, FONT_INDEX_MONO);
addStyleMenu(menu, Typeface.BOLD, 'b");
addStyleMenu(menu, Typeface.ITALIC, 'i");
addFlagMenu(menu, Paint.DEV_KERN_TEXT_FLAG, "DevKern", 'k");
menu.add(0, 0, 0, "Text").setOnMenuItemClickListener(mTextCallback).setAlphabeticShortcut('t");
return true;
|
protected void | onRestoreInstanceState(android.os.Bundle state)Called when it is time to initialize the activity state.
super.onRestoreInstanceState(state);
|
protected void | onResume()
super.onResume();
|
private void | refreshFont()
Typeface tf = Typeface.create(sTypeface[mFontIndex], mFontStyle);
mColumn1.setTypeface(tf);
mColumn2.setTypeface(tf);
updateTitle();
|
private void | setFont(android.widget.TextView t, android.widget.TextView f, java.util.Map extras)
int style = ((Integer)extras.get("style")).intValue();
String font = (String)extras.get("font");
t.setTypeface(Typeface.create(font, style));
f.setText((String)extras.get("title"));
|
private void | updateText()
mTextIndex %= sText.length;
String s = sText[mTextIndex];
mColumn1.setText(s);
mColumn2.setText(s);
|
private void | updateTitle()
Typeface tf = mColumn1.getTypeface();
String title = " ps=" + mFontSize + " scaleX="
+ (1 + mTextScaleXDelta/SCALE_X_RANGE)
+ " gamma=" + (mGamma/20.f)
+ " " + sTypefaceName[mFontIndex]
+ " " + sStyleName[tf.getStyle()]
;
setTitle(title);
|