I am trying to design a splash screen with an activity indicator on it.
I am successfully creating a splash screen but my indicator is not being added to it,
it is being hidden below the image while i am setting its layout.
How can I fix this?
Here is my code:
package mypackage;
import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorController;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorModel;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorView;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
//import net.rim.device.api.ui.extension.container.EyelidFieldManager;
public final class SplashScreen extends SplashScreenPage
{
public SplashScreen()
{
super(Bitmap.getBitmapResource("splash-blackberry.png"),2);
}
}
class SplashScreenPage extends MainScreen
{
VerticalFieldManager vfm= new VerticalFieldManager(Field.FIELD_VCENTER);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_VCENTER)
{
protected void sublayout( int maxWidth, int maxHeight )
{
super.sublayout(360,60);
setExtent(360, 60);
Field field = getField(0);
layoutChild(field,140, 60);
setPositionChild(field, 100,200);
}
public void paint(Graphics graphics)
{
//Draw the background image and then call paint.
// super.paint(graphics);
//graphics.clear();
// graphics.setBackgroundColor(0x000000);
//graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);
// super.paint(graphics);
// graphics.clear();
// graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);
}
};
ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH);
ActivityIndicatorModel model = new ActivityIndicatorModel();
ActivityIndicatorController controller = new ActivityIndicatorController();
boolean notlogged = false;
Bitmap popup;
SplashScreenPage screen1 = this;
private Timer splashTimer = new Timer();
private TimerTask splashTask;
int count = 0;
int screenWidth = Display.getWidth();
int screenHeight = Display.getHeight();
int yCoord;
int xCoord;
boolean showSplash = true;
boolean splashDisplayed = false;
//SplashScreen page is here
public SplashScreenPage(Bitmap popup, final int seconds)
{
view.setController(controller);
view.setModel(model);
view.setLabel("Loading");
controller.setModel(model);
controller.setView(view);
model.setController(controller);
Bitmap bitmap = Bitmap.getBitmapResource("images.jpeg");
view.createActivityImageField(bitmap, 5, Field.FIELD_BOTTOM);
// add(view);
add(hfm);
hfm.add(view);
// add(vfm);
// vfm.add(Bitmap.getBitmapResource("splash-blackberry.png"));
this.popup = popup;
xCoord = (screenWidth - popup.getWidth()) / 2;
yCoord = (screenHeight - popup.getHeight()) / 2;
splashTask = new TimerTask() {
public void run() {
if (showSplash && !splashDisplayed) {
count++;
if (count == seconds * 15) {
showSplash = false;
splashDisplayed = true;
splashTimer.cancel();
invalidate();
synchronized (Application.getEventLock()){
UiApplication.getUiApplication().pushScreen(new secondscreen());
notlogged = true;
}
}
}
}
};
splashTimer.scheduleAtFixedRate(splashTask, 100, 100);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (showSplash && !splashDisplayed) {
graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0);
// super.paint(graphics);
// graphics.clear();
}
}
protected void onUiEngineAttached(boolean attached) {
showSplash = true;
invalidate();
super.onUiEngineAttached(attached);
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return DismissSplash();
}
protected boolean navigationClick(int status, int time) {
return DismissSplash();
}
protected boolean keyChar(char c, int status, int time) {
return DismissSplash();
}
private boolean DismissSplash() {
if (showSplash) {
showSplash = false;
splashDisplayed = true;
invalidate();
return true;
}else{
return false;
}
}
public void onExposed() {
if( notlogged)
UiApplication.getUiApplication().popScreen(this);
}
}
In your HorizontalFieldManager that you are adding view to, you need to make sure you are calling super.paint() because it called subpaint() which will tell its child Fields (view in this case) to paint themselves. I see that you have it commented out, so you've probably been messing with that. Also, be sure that you do your background painting before you call super.paint() so you don't cover up the ActivityIndicatorView with your own painting.
Would it be possible for you to go through and clean up the code (removing the commented out code that isn't important) to a point where you would expect it to work so it is a littler easier to distinguish between "trying anything you can" code and "working" code.
Related
I am developing an app in which I need to display products in an expandable list. So I have tried an example which was given in stackoverflow... So, it is working good, but my problem is the divider that will not wrap (expand) based on content expanding, like in screen ...
as you can see, in the screen the date2 field is not displayed properly ..
for that, is there any scrolling facility or can this expand automatically?
Here is my code
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.Touchscreen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
class UiMainscreen extends MainScreen implements FieldChangeListener
{
private CustomListField cu_field[];
private Bitmap image=null;
int size=8;
public UiMainscreen() {
VerticalFieldManager vmanager=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
cu_field=new CustomListField[size];
for(int i=0;i<size;i++){
image=Bitmap.getBitmapResource("sample_"+i+".jpg");
cu_field[i]=new CustomListField("BlackBerry models that had a built-in mobile phone, were the first models that natively ran Java, and transmitted data over the normal 2G cellular network. RIM began to advertise these devices as email-capable mobile phones rather than as 2-way pagers.", image, "jan2011", 100, 100,Color.LIGHTGREEN);
cu_field[i].setChangeListener(this);
vmanager.add(new SeparatorField());
vmanager.add(cu_field[i]);
}
add(vmanager);
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
for(int i=0;i<size;i++){
if(field==cu_field[i]){
final int k=i;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("You click on Item No "+k);
}
});
}
}
}
}
class CustomListField extends HorizontalFieldManager{
private Bitmap scale_image;
private int width=0;
private int height=0;
private int background_color=0;
private BitmapField bitmap_field;
private boolean flag=false;
Bitmap logingBg;
public CustomListField(String title, Bitmap image, String date,int image_width,int image_height,int background_color){
super(NO_HORIZONTAL_SCROLL|USE_ALL_WIDTH);
this.background_color=background_color;
width=image_width;
height=image_width;
if(image!=null){
scale_image=new Bitmap(image_width, image_height);
image.scaleInto(scale_image, Bitmap.FILTER_LANCZOS);
bitmap_field=new BitmapField(scale_image);
flag=false;
bitmap_field.setMargin(5, 5, 5, 5);
add(bitmap_field);
}
VerticalFieldManager vmanager=new VerticalFieldManager(USE_ALL_WIDTH|Field.FIELD_VCENTER){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
};
///////////////////////////////////////////
/* Bitmap logingBg = Bitmap.getBitmapResource("myorderdatebackground.png");
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(Field.FIELD_HCENTER);
ButtonField btnext = new ButtonField("btn");
CustomButtonField btnSignIn = new CustomButtonField(0, "", logingBg,
logingBg, Field.FOCUSABLE, Color.WHITE);
hfm2.add(btnext);
hfm.add(btnSignIn);
hfm.add(hfm2);
vmanager.add(hfm);*/
logingBg = Bitmap.getBitmapResource("myorderdatebackground.png");
HorizontalFieldManager HFM = new HorizontalFieldManager(USE_ALL_WIDTH) {
public void paint(Graphics g) {
//g.setBackgroundColor(Color.BLUE);
g.clear();
g.drawBitmap(0, 0, Display.getWidth(),
logingBg.getHeight(), logingBg, 0, 0);
super.paint(g);
}
};
HorizontalFieldManager lableRegistHFM = new HorizontalFieldManager(
FIELD_VCENTER);
LabelField RegistrationLbl = new LabelField("My Orders",Field.FIELD_HCENTER);
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font11 = fontFamily[1].getFont(FontFamily.CBTF_FONT, 12);
font11 = fontFamily[1].getFont(Font.BOLD, 18);
RegistrationLbl.setFont(font11);
RegistrationLbl.setMargin(0, 0, 0, (Display.getWidth() / 3));
lableRegistHFM.add(RegistrationLbl);
HFM.add(lableRegistHFM);
vmanager.add(HFM);
/**************************************************************/
LabelField title_lbl=new LabelField("Title: "+title,Field.NON_FOCUSABLE|DrawStyle.ELLIPSIS);
vmanager.add(title_lbl);
LabelField date_lbl=new LabelField("Date: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl);
LabelField date_lbl3=new LabelField("Date2: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl3);
LabelField date_lbl4=new LabelField("Date2: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl4);
Font fon=title_lbl.getFont();
int title_height=fon.getHeight();
Font font=date_lbl.getFont();
int date_height=font.getHeight();
int pad=title_height+date_height;
title_lbl.setPadding((height-pad)/2, 0, 0, 0);
add(vmanager);
add(new NullField(FOCUSABLE));
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
protected void paint(Graphics graphics) {
if(flag)
graphics.setBackgroundColor(background_color);
graphics.clear();
super.paint(graphics);
}
protected void onFocus(int direction) {
super.onFocus(direction);
flag=true;
invalidate();
}
protected void onUnfocus() {
invalidate();
flag=false;
}
protected boolean navigationClick(int status, int time) {
if(Touchscreen.isSupported()){
return false;
}else{
fieldChangeNotify(1);
return true;
}
}
protected boolean touchEvent(TouchEvent message)
{
if (TouchEvent.CLICK == message.getEvent())
{
FieldChangeListener listener = getChangeListener();
if (null != listener)
this.setFocus();
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
}
The issue is here:
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
You're giving manager height less that it needs for content (only image_width).
Also here is possible error:
width=image_width;
height=image_width;
You should use image_height for the height.
And sure you could use scrolling for VerticalManager - add style VERTICAL_SCROLL to constructor. But as user I will find the User Experience (UX) strange in this case.
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.
Hello Sir I m making an app in which i got stuck in a problem please help me out ...
in one page i m getting the data from server and displaying that data on the page now i m use Focusable for highlighting them ...now my requirement is that when focus come on any data the it should change the field ie exmple: printing the name on which focus is present ..
following is the code which is showing the data on the page now it is working on field change where i need to click the label field ....
package com.Tally.app;
import com.Tally.screenParams.BankList;
import com.Tally.screenParams.CrDrList;
import com.Tally.screenParams.SearchList;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class LowerCreditors extends VerticalFieldManager implements
FieldChangeListener {
// class Lower extends
static LabelField[] CrDrLabels;
public LowerCreditors() throws Exception {
super(VerticalFieldManager.VERTICAL_SCROLL);
CrDrLabels = new LabelField[CrDrList.VendorNameArr.length];
for (int i = 0; i < CrDrLabels.length; i++) {
final int t = i;
VerticalFieldManager hfm = new VerticalFieldManager(USE_ALL_WIDTH) {
protected void sublayout(int Width, int Height) {
// TODO Auto-generated method stub
super.sublayout(Width, Height);
setPositionChild(getField(0), 15, 0);
setPositionChild(getField(1), Display.getWidth()
- getFont().getAdvance(CrDrList.VendorValArr[t])
- 10, 0);
}
};
CrDrLabels[i] = new LabelField(CrDrList.VendorNameArr[i],
LabelField.FOCUSABLE ) {
public int getPreferredWidth()
{
return 210; // fix width
}
protected boolean navigationClick(int status, int time) {
fieldChanged(this, 0);
return true;
};
};
LabelField Value = new LabelField(CrDrList.VendorValArr[i]);
hfm.add(CrDrLabels[i]);
hfm.add(Value);
add(hfm);
}
}
protected void paintBackground(Graphics g) {
// TODO Auto-generated method stub
g.setColor(0xB8E0B8);
g.fillRect(0, 0, net.rim.device.api.system.Display.getWidth(),
net.rim.device.api.system.Display.getHeight() + 2000);
g.setColor(Color.BLUE);
super.paintBackground(g);
}
protected void paint(Graphics graphics) {
graphics.setColor(0xB8E0B8);
graphics.fillRect(0, 0, Display.getWidth(), 20);
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
setExtent(net.rim.device.api.system.Display.getWidth(),
net.rim.device.api.system.Display.getHeight());
super.sublayout(net.rim.device.api.system.Display.getWidth(),
net.rim.device.api.system.Display.getHeight());
}
public void fieldChanged1(Field field, int context) {
// TODO Auto-generated method stub
}
protected boolean abc(int status, int time) {
navigationClick(1, 1);
Dialog.alert("Called......");
return false;
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
for (int i = 0; i < CrDrList.VendorNameArr.length; i++) {
if (field == CrDrLabels[i]) {
String LN = CrDrLabels[i].getText();
// SearchList.cname=cn;
CrDrList.cname1 = LN;
LabelField cname1 = CrDrLabels[i];
System.out.println("cnnnnnnnnnnnnnn : "+ cname1);
CrDrList.selLad = CrDrLabels[i];
System.out.println("Creddddddddddddddrrrrrrr"+CrDrList.selLad);
abc(i, i);
}
}
}
}
waitng for reply ..
Couple things you could do:
You can set a FocusChangeListener on each Field and do whatever needs done in the focusChanged() method.
Use getFieldWithFocus() or getLeafWithFocus()
Override each LabelField's onFocus() method
Edit for comment
Overriding onFocus() on your LabelField. Just add this to the other methods you're overriding:
protected void onFocus(int direction) {
//do things that need done when the label gets focus
}
And if it needs to do something when it loses focus
protected void onUnfocus() {
//do things that need done when the label loses focus
}
on navigation movment try this.
protected boolean navigationMovement(int dx, int dy, int status, int time){
System.out.println("field name with focus is...."+getLeafFieldWithFocus());
return super.navigationMovement(dx,dy,status,time);
}
The below splashscreen is not displaying correctly. It works fine when I push just the splashscreen but not when I push the splashscreen and then another screen. Welcome screen is the splashscreen.
So this works -
pushScreen(new WelcomeScreen());
But not this -
pushScreen(new WelcomeScreen());
pushScreen(new MenuScreen());
In the second scenario the menuscreen is displayed straight away but not the splashscreen.
Here is the splash screen code - two classes.
package screens;
import com.src.driver.Driver;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.LabelField;
public class WelcomeScreen extends SplashScreen {
public WelcomeScreen() {
super(Bitmap.getBitmapResource("icon.png"), 5);
//normal mainscreen items:
//setTitle("SplashScreen Test");
//add(new LabelField("HelloWorld!"));
}
}
package screens;
import java.util.Timer;
import java.util.TimerTask;
import com.src.driver.Driver;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.MainScreen;
public class SplashScreen extends MainScreen {
Bitmap popup;
SplashScreen screen = this;
private Timer splashTimer = new Timer();
private TimerTask splashTask;
int count = 0;
int screenWidth = Display.getWidth();
int screenHeight = Display.getHeight();
int yCoord;
int xCoord;
boolean showSplash = true;
boolean splashDisplayed = false;
public SplashScreen(Bitmap popup, final int seconds) {
this.popup = popup;
xCoord = (screenWidth - popup.getWidth()) / 2;
yCoord = (screenHeight - popup.getHeight()) / 2;
splashTask = new TimerTask() {
public void run() {
if (showSplash && !splashDisplayed) {
count++;
if (count == seconds * 10) {
showSplash = false;
splashDisplayed = true;
splashTimer.cancel();
invalidate();
}
}
}
};
splashTimer.scheduleAtFixedRate(splashTask, 100, 100);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (showSplash && !splashDisplayed) {
graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0);
//draw border, delete if not needed:
//graphics.setColor(0xcccccc);
//graphics.drawRect(xCoord, yCoord, popup.getWidth(), popup.getHeight());
}
}
protected void onUiEngineAttached(boolean attached) {
showSplash = true;
invalidate();
super.onUiEngineAttached(attached);
}
//allow user to dismiss splash screen:
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return DismissSplash();
}
protected boolean navigationClick(int status, int time) {
return DismissSplash();
}
protected boolean keyChar(char c, int status, int time) {
return DismissSplash();
}
private boolean DismissSplash() {
if (showSplash) {
showSplash = false;
splashDisplayed = true;
invalidate();
return true;
}else{
return false;
}
}
}
Thank you
It looks like the problem is that MenuScreen is pushed immediately after WelcomeScreen. You will need to put in some kind of mechanism that waits for WelcomeScreen to "finish" before pushing the MenuScreen.
Maybe create a Listener object that is passed into WelcomeScreen. Then when WelcomeScreen "finishes" it would call the Listener (e.g. myListener.splashScreenFinished()). Then the implementation of the Listener would create and push the MenuScreen.
This might look something like this:
interface MyListener {
public void splashScreenFinished();
}
class MyApp implements MyListener {
...
public void splashScreenFinished() {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
pushScreen(new MenuScreen());
}
});
}
public void startupApp() {
pushScreen(new WelcomeScreen(this));
}
...
}
class WelcomeScreen {
private MyListener l;
public WelcomeScreen(MyListener listener) {
l = listener;
...
}
protected onSplashTimerDone() {
if (l != null)
l.splashScreenFinished();
}
}
In Blackberry I want to create a class that extends HorizontalFieldManager so that I can display a label and an image on the same line with the label to the left and the image to the right.
I want the user to be able to interact with the HorizontalFieldManager as if it were a single field. I also want each HorizontalFieldManager to be focusable when added to a VeriticalFieldManager. I also want the clcik action events.
Sounds like you'll be wanting to start writing your own Field classes, here's an example to get you started:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class SimpleField extends Field {
private String label;
private Bitmap image;
private int fieldWidth;
private int fieldHeight;
private boolean hover = false;
private int focusColor = 0xcccccc;
public SimpleField(String label, Bitmap image) {
super(Field.FOCUSABLE);
this.label = label;
this.image = image;
fieldWidth = Display.getWidth();
fieldHeight = image.getHeight();
}
protected void onFocus(int direction) {
hover = true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
hover = false;
invalidate();
super.onUnfocus();
}
public int getPreferredWidth() {
return fieldWidth;
}
public int getPreferredHeight() {
return fieldHeight;
}
protected void layout(int width, int height) {
setExtent(fieldWidth, fieldHeight);
}
protected void paint(Graphics graphics) {
if(hover){
graphics.setColor(focusColor);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}
graphics.drawText(label, 0, (fieldHeight - graphics.getFont().getHeight()) / 2);
graphics.drawBitmap(graphics.getFont().getAdvance(label), 0, image.getWidth(), image.getHeight(), image, 0, 0);
}
}