how screen layout takes place in blackberry? Let’s analyse with a simple experiment.
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
public class Test extends UiApplication {
Test() {
System.out.println("app:main constructor");
TestScreen screen = new TestScreen();
pushScreen(screen);
}
public static void main(String[] arg) {
System.out.println("app:main");
Test app = new Test();
app.enterEventDispatcher();
}
// protected boolean acceptsForeground() {
// System.out.println("app:acceptsForeground");
// return super.acceptsForeground();
// }
public void activate() {
System.out.println("app:foreground");
super.activate();
}
public void deactivate() {
System.out.println("app:background");
super.deactivate();
}
// public boolean hasEventThread() {
// System.out.println("app:has event thread");
// return super.hasEventThread();
// }
//
// public boolean isEventThread() {
// System.out.println("app:is event thread");
// return super.isEventThread();
// }
}
class TestScreen extends MainScreen {
ButtonField button;
TestScreen() {
System.out.println("app:screen constructor");
button = new ButtonField("click") {
protected void fieldChangeNotify(int context) {
Dialog.alert("hi");
super.fieldChangeNotify(context);
}
protected void layout(int width, int height) {
System.out.println("app:field layout");
super.layout(width, height);
}
protected void paint(Graphics graphics) {
System.out.println("app:field paint");
super.paint(graphics);
}
protected void drawFocus(Graphics graphics, boolean on) {
System.out.println("app:field draw focus");
super.drawFocus(graphics, on);
}
};
add(button);
}
protected void sublayout(int width, int height) {
System.out.println("app:delegate manager sublayout");
super.sublayout(width, height);
}
protected void subpaint(Graphics graphics) {
button.setLabel("chagne");
System.out.println("app:delegate manager subpaint");
super.subpaint(graphics);
}
protected void onUiEngineAttached(boolean attached) {
if (attached) {
System.out.println("app:onUiEngineAttached");
} else {
System.out.println("app:onUiEngine dettached");
}
super.onUiEngineAttached(attached);
}
protected void onVisibilityChange(boolean visible) {
if (visible) {
System.out.println("app:Visibility true");
} else {
System.out.println("app:Visibility false");
}
super.onVisibilityChange(visible);
}
protected void onObscured() {
System.out.println("app:onObscured");
super.onObscured();
}
protected boolean onSave() {
System.out.println("app:on save");
return super.onSave();
}
protected void onExposed() {
System.out.println("app:on exposed");
super.onExposed();
}
protected boolean onSavePrompt() {
System.out.println("app:on save prompt");
return super.onSavePrompt();
}
}
I have commented isEventThread and hasEventThread because
isEventThread called many times and that makes difficult to
analyse output.
1. Just run the application
Starting test
Started test(127)
app:main
Foreground test(127)
app:screen constructor
app:delegate manager sublayout
app:field layout
app:onUiEngineAttached
app:Visibility true
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus gained; App test; Component TestScreen$1
app:foreground
app:field paint
app:field draw focus
app:field paint
Analysis:
layout called before paint so we can place all calculation of paint to layout method.
2. Now click on the button one dialog will appear.
app:onObscured
FocusHistory: Focus lost; App test; Component TestScreen$1
FocusHistory: Focus gained; App test; Component net.rim.device.api.ui.component.ButtonField
Analysis:
here we can see the difference between visibility and onObscured
3 click ok button.
app:on exposed
4. press on Esc button of blackberry.
app:on save prompt
app:onObscured
5. Click on save button
app:on exposed
app:on save
app:Visibility false
app:onUiEngine detached
Exit test(127)
Foreground net_rim_bb_ribbon_app(70)
FocusHistory: Focus gained; App NoName; Component TestScreen$1
FocusHistory: Focus lost; App NoName; Component TestScreen$1
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
6. Click on the End button of blackberry to place this application to background.
Foreground net_rim_bb_ribbon_app(70)
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
app:background
FocusHistory: Focus lost; App test; Component TestScreen$1
app:onObscured
app:Visibility false
7. From switch application menu make this application foreground.
switch
Foreground test(129)
app:foreground
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.api.ui.menu.DefaultMenuListField
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus gained; App test; Component TestScreen$1
app:on exposed
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
app:Visibility true
app:field paint
app:field draw focus
app:field paint
Incoming search terms:
- Ribbon Launcher App (46)
- blackberry layout (22)
- ribbonlauncherapp (6)
- blackberry public void activate() { super activate (2)
- FocusHistory: Focus lost; App Universal; Component (2)
- a ui npwe ribbon launcher app (1)
- q10 blackberry scrren layout reconsilation (1)
- ribbon launcer app is @16 (1)
- ribbon launcher (1)
- ribbon launcher app blackberry (1)