How to get the highlight color of the current Blackberry theme?
I've implemented some custom fields and would like the appearance to match the current Blackberry theme. So I would like the box highlight color to match the highlight color used in all BB applications.
How can I get this color?
Edit: Apparently there is no way to get these colors from any API. So is there a way around the colors?
source to share
What we can do is test colors in the drawFocus method for some custom text field:
class TestField extends TextField {
TestThemeListener mListener;
public TestField(TestThemeListener listener) {
super(EDITABLE | FOCUSABLE);
setText("Hello this is a color test");
setSelection(0, true, 10);
mListener = listener;
}
protected void drawFocus(Graphics g, boolean on) {
drawHighlightRegion(g, HIGHLIGHT_FOCUS, true, 0, 0, 50, 20);
Bitmap bmp = new Bitmap(50, 20);
Display.screenshot(bmp, 0, 0, 50, 20);
int[] argbData = new int[1];
bmp.getARGB(argbData, 0, 1, 0, 0, 1, 1);
int focusColor = argbData[0];
drawHighlightRegion(g, HIGHLIGHT_SELECT, true, 50, 0, 50, 20);
Display.screenshot(bmp, 50, 0, 50, 20);
argbData = new int[1];
bmp.getARGB(argbData, 0, 1, 0, 0, 1, 1);
int selectionColor = argbData[0];
if (null != mListener) {
mListener.themeTested(focusColor, selectionColor);
mListener = null;
}
}
}
interface TestThemeListener {
void themeTested(int focusColor, int selectionColor);
}
And use it on screen:
class Scr extends MainScreen implements TestThemeListener {
LabelField mSelectionColorName;
LabelField mFocusColorName;
public Scr() {
add(new TestField(this));
}
public void themeTested(int focusColor, int selectionColor) {
add(new LabelField("Theme colors (AARRGGBB)"));
add(new LabelField("Focus : " + focusColor));
Bitmap bmpF = new Bitmap(100, 20);
Graphics gF = new Graphics(bmpF);
gF.setColor(focusColor);
gF.fillRect(0, 0, 100, 20);
add(new BitmapField(bmpF));
add(new LabelField("Selection : " + selectionColor));
Bitmap bmpS = new Bitmap(100, 20);
Graphics gS = new Graphics(bmpS);
gS.setColor(selectionColor);
gS.fillRect(0, 0, 100, 20);
add(new BitmapField(bmpS));
}
}
screenshot of color testing app http://img188.imageshack.us/img188/8943/830001.png
source to share
This works great, but there is a problem. The application must be signed and it displays a confirmation for the user to take screenshots such as "Application xxx wants to take a screenshot. Allow?" This can be annoying to the user. This is caused by using the secure API in the device class.
Instead, try creating a new one Graphics
from Bitmap
and then drawing it.
class TestField : extends Field {
int getHighlightColor() {
Bitmap image = new Bitmap(getWidth(), getHeight());
Graphics g = new Graphics(image).
drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, true, 0, 0, getWidth(), getHeight());
paint(
argbData = new int[1];
image.getARGB(argbData, 0, 1, 0, 0, 1, 1);
return argbData[0];
}
}
source to share