I need to reset the values from scrolling, I has implemented a tabbar (developing in Blackberry OS 6), with Vertical Scroll in VerticalFieldManager, but when I select another field(tab) the Vertical Scroll return me a nullpointer, the tab code is fine, so I guess is because the first scroll event saved the items lenght from the first field (tab) and when the lenght is less than the first one give me a nullpointer, I need Reset the values from scroll when I finish scrolling, I saw this
(Mannager.NO_SCROLL_RESET)
but it's deprecated. I'm using OS 6 but the tabbar must work for every devices.
public class CustomizeTabbar extends MainScreen {
private int Resolucion;
VerticalFieldManager lista;
private AbsoluteFieldManager tab1Manager;
private AbsoluteFieldManager tab2Manager;
private AbsoluteFieldManager tab3Manager;
private AbsoluteFieldManager tab4Manager;
private AbsoluteFieldManager tab5Manager; ///Detalle Nota
private AbsoluteFieldManager tabArea;
private String Token;
public CustomizeTabbar(int Res, String token) {
Resolucion=Res;
this.Token=token;
try{
///Cabecera Tabbar
HorizontalFieldManager htabbar= new HorizontalFieldManager(NO_HORIZONTAL_SCROLL|NO_VERTICAL_SCROLL|USE_ALL_WIDTH ){
//define width
public int getPreferredWidth()
{
if(Resolucion==1)
return 320;
else
return 480;
}
//define height
public int getPreferredHeight()
{
if(Resolucion==1)
return 25;
else
return 36;
}
protected void sublayout( int maxWidth, int maxHeight )
{
super.sublayout(getPreferredWidth(),
getPreferredHeight());
setExtent(getPreferredWidth(), getPreferredHeight());
}
};
final BitmapButtonField tab1= new BitmapButtonField(Bitmap.getBitmapResource("1notasactuales.png"),Bitmap.getBitmapResource("1notasactualesfocus.png"),FOCUSABLE);
final BitmapButtonField tab2= new BitmapButtonField(Bitmap.getBitmapResource("1inasistencia.png"),Bitmap.getBitmapResource("1inasistenciafocus.png"),FOCUSABLE);
final BitmapButtonField tab3= new BitmapButtonField(Bitmap.getBitmapResource("1Horario.png"),Bitmap.getBitmapResource("1HorarioFocus.png"),FOCUSABLE);
final BitmapButtonField tab4= new BitmapButtonField(Bitmap.getBitmapResource("1record.png"),Bitmap.getBitmapResource("1recordfocus.png"),FOCUSABLE);
LabelField spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
LabelField spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
LabelField spacer3 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
///Controlador del Tabbar
FieldChangeListener click=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
lista=null;
if(tabArea!=null){
try{
if(field==tab1)
{
delete(tabArea);
tabArea=NotasActualesDisplay();
add(tabArea);
}else
if(field==tab2)
{
delete(tabArea);
tabArea = InasistenciaDisplay();
add(tabArea);
}else
if(field==tab3)
{
delete(tabArea);
tabArea = HorarioDisplay();
add(tabArea);
}else
if(field==tab4)
{
delete(tabArea);
tabArea=RecordAcademicoDisplay();
add(tabArea);
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
};
tab1.setChangeListener(click);
tab2.setChangeListener(click);
tab3.setChangeListener(click);
tab4.setChangeListener(click);
htabbar.add(tab1);
htabbar.add(spacer1);
htabbar.add(tab2);
htabbar.add(spacer2);
htabbar.add(tab3);
htabbar.add(spacer3);
htabbar.add(tab4);
Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("2tabbar_pages.png"));
htabbar.setBackground(bg);
setTitle(htabbar);
/////////
tabArea = NotasActualesDisplay();
add(tabArea);
}catch (Exception e) {
// TODO: handle exception
}
}
public AbsoluteFieldManager NotasActualesDisplay() {
final VerticalFieldManager lista=new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR|Manager.NO_SCROLL_RESET){
/* Here I design the elements with JSON using FOR*/
}
return tab1Manager;
}
public AbsoluteFieldManager InasistenciaDisplay() {
VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR|Manager.NO_SCROLL_RESET){
/* Here I design the elements with JSON using FOR*/
}
return tab2Manager;
}
public AbsoluteFieldManager HorarioDisplay() {
VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR|Manager.NO_SCROLL_RESET){
/* Here I design the elements with JSON using FOR*/
}
}
return tab3Manager;
}
Related
I'm creating a BlackBerry application, and now I want to present an animation when I click on an image button. In my application, I use a splash screen, and after that a login page is shown. When I click on my login page's submit button, a home screen is displayed, and there I want to show a slide animation.
This is my code:
public class LoginPage extends MainScreen implements FieldChangeListener {
public TextField tf_username;
public TextField tf_password;
private Bitmap[] img1;
public LabelField labeluser;
public LabelField labelpass;
public static String strUsername = "";
public static String strPassword = "";
public CheckboxField objRemembercheckbox;
private ImageButton btn_login;
private ImageButton btn_clear;
public BitmapField loading = new BitmapField(Bitmap.getBitmapResource("login-bar.png"));
public H_FieldManager hfm_btn;
public VerticalFieldManager vfm_user, vfm_pass;
public PleaseWaitPopupScreen waitPopupScreen = null;
public VerticalFieldManager vfmMainManager;
public static boolean loginFlag = false;
public static boolean flagOutletButton;
public RecordStore objLoginRecordStore;
private String login_record_Store_Name = "LoginRMS";
public LoginPage() { // TODO Auto-generated constructor stub super(USE_ALL_WIDTH | USE_ALL_HEIGHT); setTitle(loading);
try {
Background bg = BackgroundFactory.createSolidTransparentBackground(
Color.BLUE, 100); getMainManager().setBackground(bg);
} catch (Exception e) { // TODO: handle exception }
labeluser = new LabelField("Enter Username : ", Field.FIELD_LEFT); labeluser.setMargin(10, 0, 0, 10); labeluser.setColor(Color.BLACK);
tf_username = new TextField(TextField.TYPE_PLAIN, Field.FIELD_HCENTER);
labelpass = new LabelField("Enter Password : ", Field.FIELD_LEFT); labelpass.setMargin(10, 0, 0, 10); labelpass.setColor(Color.BLACK);
tf_password = new TextField(TextField.TYPE_PASSWORD,
Field.FIELD_HCENTER);
objRemembercheckbox = new CheckboxField("Remember Me", false); objRemembercheckbox.setMargin(10, 0, 0, 10);
img1 = new Bitmap[3]; img1[0] = Bitmap.getBitmapResource("btn-hover.png"); img1[1] = Bitmap.getBitmapResource("btn.png"); img1[2] = Bitmap.getBitmapResource("btn.png");
btn_login = new ImageButton(img1, "Login", Field.FIELD_LEFT); btn_login.setColor(Color.WHITE); btn_clear = new ImageButton(img1, "Clear", Field.FIELD_RIGHT); btn_clear.setColor(Color.WHITE);
hfm_btn = new H_FieldManager(btn_login, btn_clear, true,
Field.FIELD_HCENTER); vfm_user = new VerticalFieldManager(); vfm_user.add(labeluser); vfm_user.add(tf_username);
vfm_pass = new VerticalFieldManager(); vfm_pass.add(labelpass); vfm_pass.add(tf_password); add(vfm_user); add(vfm_pass); add(objRemembercheckbox); add(hfm_btn);
btn_login.setChangeListener(this); btn_clear.setChangeListener(this);
}
public void fieldChanged(Field field, int context) { // TODO Auto-generated method stub if (field == btn_clear) { tf_username.setText(" "); tf_password.setText(" ");
} else if (field == btn_login) { login(); }
}
public void login() {
try {
LoginPage.strUsername = tf_username.getText().toString(); System.out.println("strUsername==" + strUsername); LoginPage.strPassword = tf_password.getText().toString(); System.out.println("strPassword==" + strPassword);
if (strUsername.length() == 0 || strPassword.length() == 0
|| strUsername == null || strPassword == null) {
Dialog.alert("You must enter credentials");
invalidate(); } else {
// strUsername=username.getText();
// strPassword=password.getText();
try {
waitPopupScreen = new PleaseWaitPopupScreen("Please wait..");
UiApplication.getUiApplication()
.pushScreen(waitPopupScreen);
new Thread() {
public void run() {
ConnectToServer objConnectToServer = new ConnectToServer();
loginFlag = objConnectToServer.loginCheck(
strUsername, strPassword);
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
UiApplication.getUiApplication()
.popScreen(waitPopupScreen);
if (loginFlag == true) {
LoginPage.flagOutletButton = false;
System.out
.println("Calling getOutletInfo");
HomeScreen objHome= new HomeScreen ();
UiApplication
.getUiApplication()
.pushScreen(objHome);
}
else {
Dialog.alert("Username Or Password Is Incorrect");
}
}
});
};
}.start();
// ConnectToServer objConnectToServer=new ConnectToServer();
//
// loginFlag=objConnectToServer.loginCheck(strUsername,
// strPassword);
System.out.println("loginFlag==" + loginFlag);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
} catch (Exception e) { // TODO: handle exception e.printStackTrace(); }
}
}
Please suggest how to implement the slide animation.
Thank you.
Try following links:
TransitionContext - The TransitionContext class contains all the necessary data to
uniquely describe a transition animation between two screens.
BlackBerry Screen Transition Sample Code
BlackBerry Java Application Screen Transitions - Sample Application Overview
Creating a screen transition Code sample
Now i have a MyScreen which extends from MainScreen containing a button. When the button clicked, it will show the PopupScreen containing list of RadioButtonFields, OK and Cancel buttons. My question is how to get RadioButtonField value from PopupScreen back to MyScreen.
Please help me in this case.
Thanks
Below is my code
MyScreen.java
public class MyScreen extends MainScreen{
private int currentValue = 0;
public MyScreen() {
LabelField lblField = new LabelField();
lblField.setText("Current Value = " + currentValue);
ButtonField btnPopup = new ButtonField("Show Popup");
btnPopup.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new MyPopupScreen());
}
});
add(lblField);
add(btnPopup);
}
}
MyPopupScreen
public class MyPopupScreen extends PopupScreen implements FieldChangeListener {
private int currentValue = -1;
public MyPopupScreen() {
super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR), Field.FOCUSABLE
);
add(new LabelField("Select Chart Type"));
RadioButtonGroup radioGroup = new RadioButtonGroup();
for (int i = 0; i < 10; i++) {
RadioButtonField radio = new RadioButtonField("Option no. " + i, radioGroup, false);
radio.setChangeListener(this);
add(radio);
}
ButtonField cancelBtn = new ButtonField("Close");
ButtonField okBtn = new ButtonField("OK");
add(okBtn);
add(cancelBtn);
cancelBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().popScreen();
}
});
okBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
//How to get radio value or index value to pass back to MyScreen
}
});
}
public void fieldChanged(Field field, int context) {
if (field instanceof RadioButtonField) {
RadioButtonField radio = (RadioButtonField) field;
currentValue = radio.getIndex();
}
}
}
As Vijay, suggested this is one way that we could achieve this using inner class. The other approach could be, using design observer design patterns.
Try understanding the below code, and use what ever is efficient for you.
MyScreen.java
public class MyScreen extends MainScreen implements MyListener {
MyScreen screen = null;
public MyScreen() {
screen = this;
LabelField lblField = new LabelField();
lblField.setText("Current Value = " + currentValue);
ButtonField btnPopup = new ButtonField("Show Popup");
btnPopup.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new MyPopupScreen(screen));
}
});
add(lblField);
add(btnPopup);
}
public void valueChanged(int selectedIdx) {
Dialog.alert(selectedIdx );
}
}
MyListener.java
public interface MyListener {
public void valueChanged(int selectedIdx);
}
MyPopupScreen.java
public class MyPopupScreen extends PopupScreen implements FieldChangeListener {
MyScreen deligate = null;
public MyPopupScreen(final MyScreen deligate) {
super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR), Field.FOCUSABLE);
this.deligate = deligate;
add(new LabelField("Select Type"));
ButtonField closeBtn = new ButtonField("Close");
ButtonField okBtn = new ButtonField("OK");
add(okBtn);
add(closeBtn);
closeBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
});
okBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
deligate.valueChanged(radioGroup.getSelectedIndex());
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
});
}
}
public class MyScreen extends MainScreen{
private int currentValue = 0;
String result; // Declare the result
public MyScreen() {
LabelField lblField = new LabelField();
lblField.setText("Current Value = " + currentValue);
ButtonField btnPopup = new ButtonField("Show Popup");
btnPopup.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new MyPopupScreen());
}
});
ButtonField btnGetResult = new ButtonField("result"); //Add new Button
btnGetResult.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.inform(result);
}
});
add(lblField);
add(btnPopup);
add(btnGetResult);// Add button to get the selected index
}
public class MyPopupScreen extends PopupScreen implements FieldChangeListener {
private int currentValue = -1;
RadioButtonField radio;
public MyPopupScreen() {
super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR), Field.FOCUSABLE
);
add(new LabelField("Select Chart Type"));
final RadioButtonGroup radioGroup = new RadioButtonGroup();
for (int i = 0; i < 10; i++) {
radio = new RadioButtonField("Option no. " + i, radioGroup, false);
radio.setChangeListener(this);
add(radio);
}
ButtonField cancelBtn = new ButtonField("Close");
ButtonField okBtn = new ButtonField("OK");
add(okBtn);
add(cancelBtn);
cancelBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().popScreen(MyPopupScreen.this);
}
});
okBtn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
result = radioGroup.getSelectedIndex()+"";
UiApplication.getUiApplication().popScreen(MyPopupScreen.this);
}
});
}
public void fieldChanged(Field field, int context) {
if (field instanceof RadioButtonField) {
RadioButtonField radio = (RadioButtonField) field;
currentValue = radio.getIndex();
}
}
}
}
I'm trying to create a custom ButtonField, whose focus (the blue highlight color) would disappear after few seconds of inactivity - like in original music player on BB phones with touchscreen.
I've almost succeeded in that with the following example:
Here are the east.png and west.png (courtesy of openclipart.org):
Here is my test code MyFocus.java:
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;
public class MyFocus extends UiApplication {
public static void main(String[] args) {
MyFocus app = new MyFocus();
app.enterEventDispatcher();
}
public MyFocus() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
public MyScreen() {
setTitle("2nd trackpad click not working");
getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.GRAY, Color.DARKGRAY, Color.GRAY));
add(new MyButton(MyButton.EAST));
add(new MyButton(MyButton.WEST));
add(NF);
}
class MyButton extends ButtonField {
public final static int EAST = 0;
public final static int WEST = 1;
public final static int WIDTH = 100;
public final static int HEIGHT = 100;
private final XYEdges EDGES = new XYEdges(0, 0, 0, 0);
private final Application _app = UiApplication.getUiApplication();
private final static long FOCUS_DURATION = 3000L;
private int _focusTimer = -1;
private final int _direction;
public MyButton(int direction) {
setMargin(EDGES);
setPadding(EDGES);
setImageSize(WIDTH, HEIGHT);
setBorder(VISUAL_STATE_NORMAL,
BorderFactory.createSimpleBorder(EDGES));
setBorder(VISUAL_STATE_FOCUS, BorderFactory.createSimpleBorder(EDGES));
setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(EDGES));
setBackground(VISUAL_STATE_NORMAL, BackgroundFactory.createSolidTransparentBackground(Color.GREEN, 0));
setBackground(VISUAL_STATE_FOCUS, BackgroundFactory.createSolidTransparentBackground(Color.BLUE, 100));
setBackground(VISUAL_STATE_ACTIVE, BackgroundFactory.createSolidTransparentBackground(Color.RED, 200));
_direction = direction;
switch(_direction) {
case EAST:
setImage(ImageFactory.createImage("east.png"));
break;
case WEST:
setImage(ImageFactory.createImage("west.png"));
break;
}
}
// display red background on long touch and hold
protected boolean touchEvent(TouchEvent event) {
if (event.getEvent() == TouchEvent.CLICK) {
applyThemeOnStateChange();
return true;
}
return super.touchEvent(event);
}
protected void onUnfocus() {
if (_focusTimer != -1) {
_app.cancelInvokeLater(_focusTimer);
_focusTimer = -1;
}
super.onUnfocus();
}
protected void onFocus(int direction) {
if (_focusTimer != -1) {
_app.cancelInvokeLater(_focusTimer);
_focusTimer = -1;
}
_focusTimer = _app.invokeLater(new Runnable() {
public void run() {
MyButton.super.onUnfocus();
_focusTimer = -1;
}
}, FOCUS_DURATION, false);
super.onFocus(direction);
}
public int getPreferredHeight(){
return HEIGHT;
}
public int getPreferredWidth(){
return WIDTH;
}
protected void layout(int width, int height) {
setExtent(WIDTH, HEIGHT);
}
}
}
My problem is visible, when I first select a button and wait few seconds for its focus to disappear. Then I click on the track pad and while the button is pushed (verified that), you don't see anything at the screen - it doesn't turn blue or red.
I've tried all combinations of navigationClick() and trackwheelUnclick() but can not fix that.
Any help please?
Alex
UPDATE 1:
I've tried the following, but it doesn't work well (focus disappears forever, probably because button thinks it is in the needed visual state already):
protected void onFocus(int direction) {
if (_focusTimer != -1) {
_app.cancelInvokeLater(_focusTimer);
_focusTimer = -1;
}
_focusTimer = _app.invokeLater(new Runnable() {
public void run() {
MyButton.this.setBorder(BorderFactory.createSimpleBorder(EDGES));
MyButton.this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.GREEN, 0));
invalidate();
_focusTimer = -1;
}
}, FOCUS_DURATION, false);
super.onFocus(direction);
}
UPDATE 2:
A try with a NullField, still not working properly:
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;
public class MyFocus extends UiApplication {
public static void main(String[] args) {
MyFocus app = new MyFocus();
app.enterEventDispatcher();
}
public MyFocus() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
static NullField NF = new NullField();
HorizontalFieldManager hfm = new HorizontalFieldManager() {
int lastFocused = -1;
protected int firstFocus(int direction) {
lastFocused = super.firstFocus(direction);
System.out.println("XXX firstFocus: " + lastFocused);
return lastFocused;
}
protected int nextFocus(final int direction, final int axis) {
if (getFieldWithFocus() == NF) {
return lastFocused;
}
lastFocused = super.nextFocus(direction, axis);
System.out.println("XXX nextFocus: " + lastFocused);
return lastFocused;
}
};
public MyScreen() {
setTitle("2nd trackpad click not working");
getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.GRAY, Color.DARKGRAY, Color.GRAY));
hfm.add(new MyButton(MyButton.WEST));
hfm.add(new MyButton(MyButton.EAST));
hfm.add(new MyButton(MyButton.EAST));
hfm.add(NF);
add(hfm);
}
class MyButton extends ButtonField {
public final static int EAST = 0;
public final static int WEST = 1;
public final static int WIDTH = 100;
public final static int HEIGHT = 100;
private final XYEdges EDGES = new XYEdges(0, 0, 0, 0);
private final Application _app = UiApplication.getUiApplication();
private final static long FOCUS_DURATION = 3000L;
private int _focusTimer = -1;
private final int _direction;
public MyButton(int direction) {
setMargin(EDGES);
setPadding(EDGES);
setImageSize(WIDTH, HEIGHT);
setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(EDGES));
setBorder(VISUAL_STATE_FOCUS, BorderFactory.createSimpleBorder(EDGES));
setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(EDGES));
setBackground(VISUAL_STATE_NORMAL, BackgroundFactory.createSolidTransparentBackground(Color.GREEN, 0));
setBackground(VISUAL_STATE_FOCUS, BackgroundFactory.createSolidTransparentBackground(Color.BLUE, 100));
setBackground(VISUAL_STATE_ACTIVE, BackgroundFactory.createSolidTransparentBackground(Color.RED, 200));
_direction = direction;
switch(_direction) {
case EAST:
setImage(ImageFactory.createImage("east.png"));
break;
case WEST:
setImage(ImageFactory.createImage("west.png"));
break;
}
}
protected boolean touchEvent(TouchEvent event) {
if (event.getEvent() == TouchEvent.CLICK) {
applyThemeOnStateChange();
return true;
}
return super.touchEvent(event);
}
protected void onUnfocus() {
if (_focusTimer != -1) {
_app.cancelInvokeLater(_focusTimer);
_focusTimer = -1;
}
super.onUnfocus();
}
protected void onFocus(int direction) {
if (_focusTimer != -1) {
_app.cancelInvokeLater(_focusTimer);
_focusTimer = -1;
}
_focusTimer = _app.invokeLater(new Runnable() {
public void run() {
MyScreen.NF.setFocus();
_focusTimer = -1;
}
}, FOCUS_DURATION, false);
super.onFocus(direction);
}
public int getPreferredHeight(){
return HEIGHT;
}
public int getPreferredWidth(){
return WIDTH;
}
protected void layout(int width, int height) {
setExtent(WIDTH, HEIGHT);
}
}
}
I would probably ovverride the drawFocus() method to check a flag _showFocus before calling super.drawFocus(), then in onFocus(), set the flag to true and schedule the Runnable to change the _showFocus flag to false and invalidate (also setting it to false in onUnfocus()). Don't have to worry about canceling timers or anything this way either, as it is just going to change a flag and invalidate, keeping it in the appropriate state.
I'm making an application in which there are few tabs on each tab click a url is called and an online xml is parsed. The data from this xml is displayed. The problem is that when the data is dispalyed the tabs disappear and only appear when i press the back button of the simulator. Whereas the data should appear below the tabs.
Please help
My UI
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen implements FocusChangeListener {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
private VerticalFieldManager tab1Manager;
private VerticalFieldManager tab2Manager;
private VerticalFieldManager tab3Manager;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// Override the paint method to draw the background image.
public void paint(Graphics graphics) {
// Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab1();
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab2();
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab3();
return true;
}
};
tab1.setFocusListener(this);
tab2.setFocusListener(this);
tab3.setFocusListener(this);
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
tab1Manager = new VerticalFieldManager();
tab2Manager = new VerticalFieldManager();
tab3Manager = new VerticalFieldManager();
tabArea = displayTab1();
add(tabArea);
}
public void focusChanged(Field field, int eventType) {
if (tabArea != null) {
if (eventType == FOCUS_GAINED) {
if (field == tab1) {
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
} else if (field == tab2) {
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
} else if (field == tab3) {
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
}
}
}
}
public VerticalFieldManager displayTab1() {
UiApplication.getUiApplication().pushScreen(new News());
return tab1Manager;
}
public VerticalFieldManager displayTab2() {
UiApplication.getUiApplication().pushScreen(new Power());
return tab2Manager;
}
public VerticalFieldManager displayTab3() {
UiApplication.getUiApplication().pushScreen(new Energy());
return tab3Manager;
}
}
}
My News Main Screen
public class News extends MainScreen {
public News() {
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Now i want to open this news screen below the tabs
Please help
For your TabControl Class
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// Override the paint method to draw the background image.
public void paint(Graphics graphics) {
// Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
return true;
}
};
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
// USELESS CODE HAS BEEN REMOVED
tabArea = displayTab1();
add(tabArea);
}
public VerticalFieldManager displayTab1() {
return new News(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab2() {
return new Power(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab3() {
return new Energy(); // RETURN THE MANAGER DIRECTLY
}
}
}
For your News class
public class News extends VerticalFieldManager { // CHANGING THE EXTENSION SUPER CLASS
public News() {
super(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR);
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Yes, create a seprate mainscreen or screen objects and from your parent screen you can execute the below code to open new screen using the below code:
UIApplication.getUiApplication().pushScreen(your custom screen object);
Thanks
You don't need to create 2 mainscreens in the scenario which you described.
Just create a VerticalFieldManager, add it to the mainscreen, then add content to it.
Here's a sample of code that can help you, apply it in your mainscreen constructor.
VerticalFieldManager VFM_Content = new VerticalFieldManager();
add(VFM_Content);
VFM_Content.add(/*put content here embedded in any field type you prefer*/);
I have created my own custom popup screen to which now I am trying to add a editfield , everything seems to be fine but the problem is that I am not able to write anything in the edit field
class sveetIt extends PopupScreen implements FieldChangeListener, DialogClosedListener {
Hashtable pitemData;
ButtonField sveetNowlabelField;
ButtonField sveetLaterlabelField;
WatingScreen watingScreen;
long scheduledTime;
Dialog updateDialog;
public sveetIt() {
super(new MyCustimGridFieldManager());
LabelField messageLabelField = new LabelField("Enter your Sveet Message:",Field.FIELD_HCENTER) {
protected void paint(Graphics graphics) {
graphics.setColor(Color.YELLOWGREEN);
super.paint(graphics);
}
};
EditField sveetTexteditField= new EditField(null, "Sveet Message", 50, EditField.FIELD_HCENTER
| EditField.FIELD_VCENTER
| EditField.NON_SPELLCHECKABLE | EditField.NO_NEWLINE);
VerticalFieldManager buttonVFManager = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
HorizontalFieldManager hfManager = new HorizontalFieldManager();
sveetNowlabelField = new ButtonField("Sveet Now");
sveetLaterlabelField = new ButtonField("Sveet Later");
sveetNowlabelField.setChangeListener(this);
sveetLaterlabelField.setChangeListener(this);
add(messageLabelField);
add(sveetTexteditField);
hfManager.add(sveetNowlabelField);
hfManager.add(sveetLaterlabelField);
buttonVFManager.add(hfManager);
add(buttonVFManager);
}
public boolean isEditable() {
return true;
}
protected boolean keyChar(char c, int status, int time) {
boolean retVal = false;
if (c == Characters.ESCAPE) {
Ui.getUiEngine().popScreen(this);
retVal = super.keyChar(c, status, time);
}
return retVal;
}
public void fieldChanged(Field field, int context) {
if (sveetNowlabelField == field) {
//Here directly starts uploading file
beginUpload();
} else if (sveetLaterlabelField == field) {
// first picks up time when to upload
scheduledTime = getScheduleTime();
if(scheduledTime!=1L) {
//now begins uploading file
beginUpload();
}
}}
class SubscribingThread extends StoppableThread {
int network = 50;
public void run() {
}
}
public void beginUpload() {
try {
watingScreen = new WatingScreen("Uploading Sveet...");
/*
* UiApplication.getUiApplication().invokeAndWait( new Runnable() {
* public void run() { Ui.getUiEngine().pushScreen(watingScreen); }
* });
*/
BaseScreen.pushScreen(watingScreen);
Thread thread = new Thread(new Runnable() {
public void run() {
uploadToServer();
}
});
thread.start();
// uploadToServer();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
}
private long getScheduleTime() {
scheduledTime = 0;
final DateTimePicker datePick = DateTimePicker.createInstance();
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
// TODO Auto-generated method stub
Calendar currentCalendar = datePick.getDateTime();
datePick.setMinimumDate(currentCalendar);
datePick.doModal();
Calendar cal = datePick.getDateTime();
if (cal.after(currentCalendar)) {
Date date = cal.getTime();
Dialog.alert("You selected " + date.toString());
scheduledTime = date.getTime();
} else {
Dialog.alert("Invalid date selection");
scheduledTime = 1L;
}
}
});
System.out.println("date in MilliSeconds is:" + scheduledTime);
return scheduledTime;
}
public void uploadToServer() {
} public void dialogClosed(Dialog arg0, int arg1) {
}
}
class MyCustimGridFieldManager extends VerticalFieldManager {
public MyCustimGridFieldManager() {
super(VERTICAL_SCROLL | USE_ALL_WIDTH | FIELD_HCENTER);
}
protected void paint(Graphics gr) {
super.paint(gr);
}
}
try this:
protected boolean keyChar(char c, int status, int time) {
if (c == Characters.ESCAPE) {
Ui.getUiEngine().popScreen(this);
}
return super.keyChar(c, status, time);
}
Try adding Field.EDITABLE to your style for the EditField.