Here i use a value changing effect on a slider; if i move the slider, it will scroll and display updated values in an edit field, as per the moving of the slider bar. Also, there is an edit field effect where the slider should be moved as per the values entered into the edit field; but it is not working.
When i comment out part of the edit field effect, it is working properly but when i apply that edit field effect again, then it is not working ...
// for slider move
FieldChangeListener listenerslider1 = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
try {
if (field == serumosmslider) {
int serumosmslidervalue = serumosmslider.getValue();
String strplasmaslidervalue = Integer
.toString(serumosmslidervalue);
edtserumosm.setText(strplasmaslidervalue);
}
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
};
serumosmslider.setChangeListener(listenerslider1);
// for editfield
FieldChangeListener listenereditslider1 = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
hfmslider1.deleteAll();
String stredtweight = edtserumosm.getText().toString();
int editweight = Integer.parseInt(stredtweight);
SliderField theSlider = new SliderField(slider2thumb,
slider2progress, slider2base, slider2thumbfoc,
slider2progressfoc, slider2basefoc, 201,
editweight, 10, 10);
hfmslider1.add(theSlider);
hfmslider1.invalidate();
}
};
edtserumosm.setChangeListener(listenereditslider1);
You appear to be recreating your SliderField every time the EditField's value changes.
SliderField theSlider = new SliderField(slider2thumb,
slider2progress, slider2base, slider2thumbfoc,
slider2progressfoc, slider2basefoc, 201,
editweight, 10, 10);
hfmslider1.add(theSlider);
I don't think you want to do that. Just like you update the EditField text when the slider field changes, I think you should update the SliderField value when the EditField text is changed. So, something like this:
FieldChangeListener listenereditslider1 = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (field == edtserumosm && context != FieldChangeListener.PROGRAMMATIC) {
String stredtweight = edtserumosm.getText().toString();
try {
int editweight = Integer.parseInt(stredtweight);
serumosmslider.setValue(editweight);
} catch (NumberFormatException nfe) {
// TODO: anything?
}
}
}
};
edtserumosm.setChangeListener(listenereditslider1);
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
I want to display button and drop down on a same screen and want to capture it using fieldChnageListener ,i am not able to get how to add these both on the same screen.I have the following code :
ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
FieldListener listener = new FieldListener();
//assign that listener to the button
btnSubmit.setChangeListener(listener);
add(btnSubmit);
class FieldListener implements FieldChangeListener {
public void fieldChanged(Field f, int context){
//if the submit button is clicked
if (f == btnSubmit){
getCalender();
//if the EditField is empty
if(editField.getText().equals("")){
Dialog.alert("Please enter timezone in the field.");
}else{ // if it is not empty, display the message
Dialog.alert("TimeZone is"+editField.getText()+"!");
timeZone = editField.getText();
}
}
if(f == editField) {
//text changed in the ef-Field (EditField)
}
}
}
how to add a drop down here?
here how can you do this ..
If your class is implementing FieldChangeListner then in its fieldChanged method do like this
public class Demo extends mainScreen implements FieldChangeListener {
public Demo () {
ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
//assign that listener to the button
btnSubmit.setChangeListener(this);
add(btnSubmit);
}
public void fieldChanged(Field f, int context) {
//if the submit button is clicked
if (f == btnSubmit){
getCalender();
//if the EditField is empty
if(editField.getText().equals("")){
Dialog.alert("Please enter timezone in the field.");
}else{ // if it is not empty, display the message
Dialog.alert("TimeZone is"+editField.getText()+"!");
timeZone = editField.getText();
}
}
if(f == editField) {
//text changed in the ef-Field (EditField)
}
}
}
this should work.
I have a main class and a screen class. I have a button that launches a datepicker. When the datepicker is closed I need the label of the button to be refreshed with the selected value. How should I do that?
I tried with invalidate, creating a CustomButtonField that implements different onFocus, onUnFocus, and some other stuff but I guess I implemented them in a wrong way...
My two clases are these ones...
Main...
public class TestClass extends UiApplication
{
public static Calendar alarm1time = Calendar.getInstance(TimeZone.getTimeZone("GMT-3"));
public static void main(String[] args)
{
TestClass testClass = new TestClass ();
testClass.enterEventDispatcher();
}
public TestClass()
{
pushScreen(new TestClassScreen());
}
}
Screen...
public final class TestClassScreen extends MainScreen
{
public TestClassScreen()
{
ButtonField alarm1 = new ButtonField("Alarm : " + TestClass.alarm1time.get(Calendar.HOUR_OF_DAY) + ":" + TestClass.alarm1time.get(Calendar.MINUTE) ,ButtonField.FOCUSABLE)
{
public boolean navigationClick (int status , int time)
{
datePicker(1);
return true;
}
};
setTitle("Test Alarm");
add(new RichTextField(" "));
add(alarm1 );
}
public void datePicker(final int alarmNumber)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
DateTimePicker datePicker = null;
datePicker = DateTimePicker.createInstance(TestClass.alarm1time, null, "HH:mm");
if(datePicker.doModal())
{
Calendar cal = datePicker.getDateTime();
TestClass.alarm1time = cal;
//Here I need the label to be refreshed, after the datePicker is Ok
}
}
});
}
}
I found one way in the Blackberry Development Forum...
public boolean navigationClick (int status , int time)
{
datePicker(1, this);
return true;
}
public void datePicker(final int alarmNumber, final ButtonField buttonToUpdate)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
DateTimePicker datePicker = null;
datePicker = DateTimePicker.createInstance(TestClass.alarm1time, null, "HH:mm");
if(datePicker.doModal())
{
Calendar cal = datePicker.getDateTime();
TestClass.alarm1time = cal;
buttonToUpdate.setLabel(....)
}
}
});
}
A more usual way would be to have change listener listen for Button Clicks and do similar processing in there.
I think, this helps you:
public class Def extends MainScreen
{
ButtonField show;
LabelField label;
String str="";
ObjectChoiceField choiceField;
public Def()
{
createGUI();
}
private void createGUI()
{
String st_ar[]={"Date Picker"};
choiceField=new ObjectChoiceField("Select Date: ", st_ar)
{
protected boolean navigationClick(int status, int time)
{
DateTimePicker datePicker = DateTimePicker.createInstance( Calendar.getInstance(), "yyyy-MM-dd", null);
datePicker.doModal();
Calendar calendar=datePicker.getDateTime();
str=String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))+"-"+String.valueOf(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.YEAR);
return true;
}
};
add(choiceField);
label=new LabelField("",Field.NON_FOCUSABLE);
add(label);
show=new ButtonField("Show");
show.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
label.setText("Time is: "+str);
}
});
add(show);
}
}
How to implement click event on a image in picture scroll field?
sorry, but override touchEvent doesn't work, but try to override trackwheelClick:
PictureScrollField pictureScrollField = new PictureScrollField(150, 100){
protected boolean trackwheelClick(int status, int time) {
return super.trackwheelClick(status,time);
};
};
you can override touchEvent
PictureScrollField pictureScrollField = new PictureScrollField(150, 100) {
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
return true;
}
return super.touchEvent(message);
}
};
and then add FieldChangeListener:
pictureScrollField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (context == 1) {
Dialog.alert("click:" + ((PictureScrollField)field).getCurrentImageIndex());
}
}
});
I'm trying to set the text on a button when it is clicked. I'm initialising a BigVector which will update the text of the button with its value. I'm using a counter value to determine wihcih BigVector value should be selected. The problem is, the below code is expecting the counter value to be final.
A better methodology for updating the text on a Field when it is clicked is most welcome.
Here is my code -
final BigVector bigStringVectorA = new BigVector();
bigStringVectorA.addElement("A Test answer 1");
bigStringVectorA.addElement("A Test answer 2");
bigStringVectorA.addElement("A Test answer 3");
aAnswerOptionButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
aAnswerOptionButton.setText((String)bigStringVectorA.elementAt(counter));
}
});
Thanks
You can make the counter an instance variable, either in the outer class or in the anonymous FieldChangeListener:
aAnswerOptionButton.setChangeListener(new FieldChangeListener() {
private int counter = 0;
public void fieldChanged(Field field, int context) {
counter++;
if (counter > bigStringVectorA.size()) {
counter = 0;
}
aAnswerOptionButton.setText((String)bigStringVectorA.elementAt(counter));
}
});
You can try to call the invalidate() method of that field and that should force the redraw of that button.
aAnswerOptionButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
aAnswerOptionButton.setText((String)bigStringVectorA.elementAt(counter));
aAnswerOptionButton.invalidate();
}
});