I want to display an image at the bottom of the screen and make it clickable ,i have created a custom bitmap field ImageButtonField and trying to use it ,but i am getting ImageButtonField cannot be resolved.
public class ImageButtonField extends BitmapField
{
public ImageButtonField(Bitmap image) {
super(image);
}
public ImageButtonField(Bitmap image,Field location) {
//super(image,location);
}
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean trackwheelClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time) {
if(Characters.ENTER == character || Characters.SPACE == character) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
public NativeScreen() {
super();
LabelField title = new LabelField("Calendar DatePicker",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
hrzManager = new HorizontalFieldManager() {
protected void paintBackground(Graphics graphics) {
graphics.setBackgroundColor(0x0007F5ED);
graphics.clear();
super.paint(graphics);
}
};
hrzManager.add(title);
this.add(hrzManager);
//The background image.
backgroundBitmap = Bitmap.getBitmapResource("cryptodemo_jde.png");
// MainScreen mainScreen = new MainScreen(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_HORIZONTAL_SCROLL);
VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
BasicEditField bef = new BasicEditField("To: ","",50,BasicEditField.FILTER_EMAIL);
//The LabelField will show up through the transparent image.
LabelField labelField = new LabelField("This is a label");
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT);
//A bitmap field with a transparent image.
//The background image will show up through the transparent BitMapField image.
ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField);
BitmapField bitmapField1 = new BitmapField(Bitmap.getBitmapResource("attachmentdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField1);
//Add the fields to the manager.
// verticalFieldManager.add(bef);
// verticalFieldManager.add(labelField);
verticalFieldManager.add(horizontalFieldManager);
//Add the manager to the screen.
this.add(verticalFieldManager);
There's no constructor in your class that lets you do this:
ImageButtonField ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
The constructor that you're trying to use requires a Bitmap instance and a long primitive (for Field.FIELD_BOTTOM). You should add a constructor with the following signature for your code to work:
public ImageButtonField (Bitmap bitmap, long style){
super(bitmap, style);
}
Related
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;
}
I have created my own simple ChoiceField by extending ObjectChoiceField.. It is like..
public class MyChoiceField extends ObjectChoiceField
{
public MyChoiceField(String label ,Object[] choices)
{
super(label, choices);
}
protected void layout(int width, int height)
{
setMinimalWidth(width/2-62);
super.layout(width, height);
}
public void paint(Graphics graphics)
{
super.paint(graphics);
}
}
Now i want to display the my choices when i select MyChoiceField in custom menu(not the default popup that blackberry provides when user clicks on a ChoiceField)..
How can i achieve it? Sample codes will be appreciable..
Thanks
Try Overriding the method fieldChangeNotify(int context) of ObjectChoiceField like this:
public class MyChoiceField extends ObjectChoiceField
{
public MyChoiceField(String label ,Object[] choices)
{
super(label, choices);
}
protected void layout(int width, int height)
{
setMinimalWidth(width/2-62);
super.layout(width, height);
}
protected void fieldChangeNotify(int context) {
int index = getSelectedIndex();
try{
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(new LabelField("[Pop Up Content]\nChoice Field Changed #\n"+choices[index]+" selected."));
PopupScreen popUpScreen = new PopupScreen(vfm){
public boolean onClose()
{
this.close();
return true;
}
};
UiApplication.getUiApplication().pushScreen(popUpScreen);
} catch(Exception exc) {
System.out.println("Exception in choiceField fieldChangeNotify");
}
}
public void paint(Graphics graphics)
{
super.paint(graphics);
}
}
Use MyChoiceField now somewhat like this:
String[] choices; // Keep This Global
VerticalFieldManager vfm = new VerticalFieldManager(Manager.FIELD_VCENTER);
choices = new String[2];
choices[0] = new String("Choice1");
choices[1] = new String("Choice2");
vfm.add(new MyChoiceField("Choise", choices));
Let me know whether this solution works.
I have created one screen in which there is background.and on that i am creating a Custom Edit Fields with one button.now my problem is that my edit field is displaying on upper side.i want to make to the center of the screen.what modifications i have to do so.i am giving my code snippet.
public class CancelBooking extends MainScreen implements FieldChangeListener {
public LabelField heading;
ButtonField next;
String emp_id,emp_name,salary;
public CancelBooking(String id,String name,String sal) {
// TODO Auto-generated constructor stub
emp_id=id;
emp_name=name;
salary=sal;
}
// protected void sublayout(int width, int height){
// super.sublayout(Display.getWidth(), height);
// setExtent(Display.getWidth(), this.getPreferredHeight());
// int leftPadding = Display.getWidth()/2 -this.getPreferredWidth()/2;
// int rightPadding = Display.getWidth() - leftPadding -this.getPreferredWidth();
//
// setPadding(5,rightPadding,5,leftPadding);
// invalidate();
// }
CancelBooking()
{
heading = new LabelField(){
public void paint(Graphics g){
g.setColor(Color.WHITE);
super.paint(g);
}
};
heading.setFont(Font.getDefault().derive(Font.BOLD, Font.getDefault().getHeight()+2));
heading.setText("Check-In");
getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(
Bitmap.getBitmapResource("PlainScreen.png")));
//setTitle("First Screen");
BasicEditField id=new BasicEditField("Last Name: ","");
BasicEditField name=new BasicEditField("Confirmation Number: ","");
//BasicEditField sal=new BasicEditField("Salary: ","");
add(id);
add(name);
//add(sal);
next=new ButtonField("Next");
next.setChangeListener(this);
// add(next);
}
public void fieldChanged(Field field, int context)
{
if(field==next)
UiApplication.getUiApplication().pushScreen(new MenuScreen());
}
}
You have to add FIELD_HCENTER and FIELD_VCENTER in the style of your field.
Consider reading this link
"Managers of Blackberry docs"
How to add click event in blackberry banner ad.
Here is my code:
public class DemonstrationScreen extends MainScreen
{
public DemonstrationScreen()
{
final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder);
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager
(VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| VerticalFieldManager.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager
(HorizontalFieldManager.FIELD_HCENTER
| HorizontalFieldManager.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
FieldChangeListener listener=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if(field==bannerAd){
Dialog.alert("Banner clicked");
}
}};
bannerAd.setChangeListener(listener);
}
}
this is not working. when i click the ad, then its not showing anythig.
I do think this is unexpected/improper usage of Banner.
However you could potentially do this by overriding navigationClick() at Banner:
public class DemonstrationScreen extends MainScreen
{
public DemonstrationScreen()
{
final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder) {
protected boolean navigationClick(int status, int time) {
Dialog.alert("Banner clicked");
return super.navigationClick(status, time);
}
};
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager
(VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| VerticalFieldManager.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager
(HorizontalFieldManager.FIELD_HCENTER
| HorizontalFieldManager.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
}
}
But since RIM made Banner class final you can not do this. So I think your request has no simple solution. A hard solution would be to "figure out" what field is clicked at the MainScreen level (in navigationClick of MainScreen you can check what field is in focus and do smth).
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*/);