Search code examples
user-interfaceblackberrythemeslook-and-feel

How do I get the highlight color of the current Blackberry theme?


I've implemented some custom fields and would like to keep the look-and-feel consistent with the current Blackberry theme. So I would like the highlighting color of the fields to be consistent with the highlight color used throughout the BB apps.

How can I get the this color?

Edit: Apparently, there's no way to get those kinds of colors from any API. So is there a work-around way to getting these colors?


Solution

  • What we can do is test colors on drawFocus method of 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 the 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));
        }
    }
    

    color test app screenshot http://img188.imageshack.us/img188/8943/830001.png