In my application there is one MainScreen .This screen contain lots of Vertical and Horizontal field manager and all content display successfully with scroll .
This is my main VerticalFieldmanager code .
vfm_Main = new VerticalFieldManager()
{
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,mybackgroundImage.getWidth(),mybackgroundImage.getHeight(),mybackgroundImage,0,0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
there is one background image draw for this screen . When i scroll this screen to see the full content of this screen my Background image also scroll with the content ..for that reason background image looks so blury and it is repeat at the bottom of the screen .
i want to scroll only the content of that screen .so how to implement this ..?
i had try alot but not getting any suggetion and hits to prevent that ?
if any one facing this problem or have any idea please help me ...
Thanks in Advance !!!
You have to do like this:
vfm_Main = new VerticalFieldManager()
{
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,mybackgroundImage.getWidth(),mybackgroundImage.getHeight(),mybackgroundImage,0,0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
subver=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight()-3);//here we scroll the inner vertical
setExtent(Display.getWidth(),Display.getHeight()-3);
}
}
//Write all the code here;
subver.setpadding(1,0,0,0);
vfm_main.add(subver);
add(vfm_Main);
Like this Image:
Enough;
I too faced the same issue once. I fixed it by using 2 field managers like this.
VerticalFieldManager mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
{
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
//this manager is used for adding the componentes
VerticalFieldManager subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
Related
I am working on a logic where I have to align the label caption in vertically center but it's not working.
I have tried to set text padding but the whole label with background is shifting.Is there any way to solve this.
Here is my code:
final Bitmap tabBackGroundImage1 = Bitmap.getBitmapResource("box_img.png");
homeContentManager.setBorder( BorderFactory.createBitmapBorder(
new XYEdges(16,16,16,16), tabBackGroundImage));
//homeContentManager.setBorder(roundedBourder);
//HOME SCREEN HORIZONTAL MANAGER
buddiesLabel=new LabelField("Buddies");
_bitmap = EncodedImage.getEncodedImageResource("buddies.png");
final BitmapField buddiesBmp = new BitmapField(Constant.sizePic(_bitmap,
_bitmap.getHeight(), _bitmap.getWidth()));
buddiesBmp.setMargin(3,5,0,5);
if(BuddyListField.onlineBuddyCount < 1000) {
buddyCount=new LabelField(" "+BuddyListField.onlineBuddyCount+" "){
/*public void setText(String text,int offset,int length){
text = String.valueOf(BuddyListField.onlineBuddyCount);
offset = 200;
length = 5;
super.setText(text, offset, length);
}*/
public int getPreferredHeight() {
return tabBackGroundImage1.getHeight();
}
public int getPreferredWidth() {
return tabBackGroundImage1.getWidth();
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent(Math.min(width, tabBackGroundImage1.getWidth()), Math.min(height, tabBackGroundImage1.getHeight()));
}
protected void paint(Graphics graphics) {
int deviceWidth=net.rim.device.api.system.Display.getWidth();
int deviceHeight=net.rim.device.api.system.Display.getHeight();
graphics.clear();
graphics.drawBitmap(0, 0, deviceWidth,
deviceHeight, tabBackGroundImage1, 0, 0);
super.paint(graphics);
}
};
This is the output:
But I need to set zero to vertically center in background.
Try like this
protected void paint(Graphics graphics) {
int deviceWidth=net.rim.device.api.system.Display.getWidth();
int deviceHeight=net.rim.device.api.system.Display.getHeight();
graphics.clear();
graphics.drawBitmap(0, 0, deviceWidth,
deviceHeight, tabBackGroundImage1, 0, 0);
graphics.drawText((getPreferredWidth()-getText())/2,(getPreferredHeight()-graphics.getFont().getHeight())/2,getText);
// super.paint(graphics);
}
i want to set background image in Vertical field manager. i had try but it not fill with height you can see that in my screen. and Following in my code what i am doing mistake please help me.
vfmCenter = new VerticalFieldManager(FIELD_HCENTER)
{
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0,deviceWidth,deviceHeight,newimg,0,0);
super.paint(graphics);
}
protected void sublayout( int maxWidth, int maxHeight)
{
int width = Display.getWidth();
int height = Display.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
vfmMain.add(vfmCenter);
this.add(vfmMain);
I was also facing the same issue earlier.. I solved my problem with this..
class MyClass extends MainScreen
{
// function for scaling your image to fit the screen
public EncodedImage scaleImage(EncodedImage source, int requiredWidth, int requiredHeight)
{
int currentWidthFixed32 = Fixed32.toFP(source.getWidth());
int requiredWidthFixed32 = Fixed32.toFP(requiredWidth);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int currentHeightFixed32 = Fixed32.toFP(source.getHeight());
int requiredHeightFixed32 = Fixed32.toFP(requiredHeight);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
return source.scaleImage32(scaleXFixed32, scaleYFixed32);
}
public MyClass
{
ei = EncodedImage.getEncodedImageResource("res/background_image");
ei1= scaleImage(ei,requires_width,required_height);
vfm= new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.USE_ALL_WIDTH);
vfm.setBackground(BackgroundFactory.createBitmapBackground(ei1.getBitmap()));
vfm.add(new LabelField("hello notice the background behind me");
add(vfm);
}
}
Try this. I think it will work for you!!
Try like this:
VerticalFieldManager vertical=new VerticalFieldManager()
{
protected void paint(Graphics g)
{
g.drawBitmap(0, 0,Display.getWidth(), Display.getHeight(), bitmap, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
add(vertical);
you can get.
This is the simple using getMainManager but whole background not a particular Field Manager
getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png")));
This is may be old question but i dont get proper solution
if it is wrong please ignore otherwise please halp me
I have one main screen with two verticleManagers
1)For browserField
2)one button
first i add successfully My Browserfield to First verticlemanger and also add button to second verticlemanager
finally two verticlemanager added to main screen.
in OS6 i dont get any problem it works fine
but in OS5 i got problem that is
once the Browserfield is getting focus, it never release its focus so i am unable to navigate downside of the Browserfield. Means i am unable to click on blackberry advertisement Banner.i am unable to navigate down from browserfield using trackpad
this is my sample code
class browserScreen extends MainScreen
{
String url;
BrowserField browserField;
public browserScreen() {
VerticalFieldManager main_mgr=new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
VerticalFieldManager browserfield_mgr=new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight()-50);
setExtent(Display.getWidth(),Display.getHeight()-50);
}
};
url="http://www.google.com";
BrowserFieldConfig browserFieldConfig = new BrowserFieldConfig();
browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
browserFieldConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);
browserFieldConfig.setProperty(BrowserFieldConfig.ALLOW_CS_XHR,Boolean.TRUE);
browserField=new BrowserField(browserFieldConfig);
browserField.requestContent(url);
browserfield_mgr.add(browserField);
main_mgr.add(browserfield_mgr);
VerticalFieldManager button_mgr=new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
button_mgr.add(new SeparatorField());
ButtonField btn=new ButtonField("BUTTON MANAGER");
button_mgr.add(btn);
main_mgr.add(button_mgr);
add(main_mgr);
}
}
any help can be appreciated
After i googled a lot i conclude that This is OS 5 issue. it wont resolve it in OS5. It resolved In OS6. You have to provide a way to move the focus off the BrowserField yourself. I have tried a variety of mechanisms to do this, like detecting Escape in the Screen's keyChar method, the best I have found so far is to use the Menu and give the users the option of swapping focus out of the BrowserField. In general I do not recommend sharing the Screen between a Web Field and any other.
public class LoadingScreen extends MainScreen
{
VerticalFieldManager vertical;
HorizontalFieldManager hor;
String url;
BrowserField browserField;
Banner bannerAd ;
private static boolean flag=false;
public LoadingScreen()
{
//
VerticalFieldManager Veret=new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL|Manager.NO_HORIZONTAL_SCROLL){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
//Veret.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
VerticalFieldManager main_mgr=new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL|Manager.NO_HORIZONTAL_SCROLL){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight()-50);
setExtent(Display.getWidth(),Display.getHeight()-50);
}
};
url="http://www.google.com";
BrowserFieldConfig browserFieldConfig = new BrowserFieldConfig();
browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
browserFieldConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);
browserFieldConfig.setProperty(BrowserFieldConfig.ALLOW_CS_XHR,Boolean.TRUE);
browserField=new BrowserField(browserFieldConfig);
browserField.requestContent(url);
main_mgr.add(browserField);
Veret.add(main_mgr);
final Bitmap ad_bg=Bitmap.getBitmapResource("add_bg.png");
VerticalFieldManager add_back=new VerticalFieldManager(USE_ALL_WIDTH|Field.FOCUSABLE){
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, ad_bg.getWidth(), ad_bg.getHeight(), ad_bg, 0, 0);
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(ad_bg.getWidth(), ad_bg.getHeight());
setExtent(ad_bg.getWidth(), ad_bg.getHeight());
}
};
try{
Bitmap customPlaceholder = Bitmap.getBitmapResource("add_bg.png");
bannerAd = new Banner(31848, null, 100000, customPlaceholder);
bannerAd.setBorderColor(Color.RED);
int i=(Display.getWidth()-320)/2;
bannerAd.setPadding(0, 0, 0, i);
bannerAd.setBannerTransitionColor(Color.RED);
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
// Dialog.inform(""+bannerAd.getMMASize());
}catch (Exception e) {
Dialog.inform(e.getMessage());
}
add_back.add(bannerAd);
Veret.add(add_back);
add(Veret);
}
protected void makeMenu(Menu menu, int instance)
{
int i=Integer.parseInt(StartUp.getOsVersion().substring(0, 1));
if(i<6)
menu.add(_testItem);
}
private MenuItem _testItem = new MenuItem("Go to Advertise", 100, 9)
{
public void run(){
bannerAd.setFocus();
}
};
}
This is a bug in OS5. Its been fixed in os6 and upwards . These are the reasons why you are seeing the strange behaviour. You cannot get the same behaviour in os5. The only thing you could do is a hack, which is to setfocus on the button_mgr . The code will look like this.
// override the invokeAction method
public boolean invokeAction(int action) {
Field f = getFieldWithFocus();
// check the type of field you are looking for ,
//here i am checking if its a verticalfieldmanager
if (f instanceof VerticalFieldManager) {
button_mgr.setFocus();
return true;
}
return super.invokeAction(action);
}
this will setfocus on your button.
When the user hovers over editfield below the touch screen keyboard does not display. What is displayed is a white area that is same size as keyboard. This is an issue on BlackBerry Torch. I would expect the touch screen keyboard to appear correctly using below code ?
BasicEditField nameField =
new BasicEditField(
" "+Local.getInfo8()+ " : ", "", 100, BasicEditField.FILTER_DEFAULT)
{
private int iRectX = getFont().getAdvance(getLabel());
private int iRectWidth = backgroundButtonBitmap.getWidth() - iRectX - 4;
public int getPreferredHeight() {
return backgroundButtonBitmap.getHeight() / 2;
}
public void layout(int width, int height) {
//setExtent(width, getPreferredHeight());
super.layout(width, getPreferredHeight());
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.setBackgroundColor(Color.WHITE);
//g.drawRect(iRectX, 0, iRectWidth, 20);
super.paint(g);
}
};
On the display screen, the method sublayout was being overriden -
protected void sublayout( int maxWidth, int maxHeight ) {
super.sublayout( maxWidth, maxHeight );
setExtent(maxWidth,Constants.BACKGROUND_IMAGE.getHeight());
}
The line - setExtent(maxWidth,Constants.BACKGROUND_IMAGE.getHeight()); is causing the issue.
What I try to do is to simply change the height of an EditField.
This sounds pretty easy but I facing a problem that drives me crazy.
Here is my code:
public class CMainManager extends HorizontalFieldManager
{
EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);
/* Constructeur */
public CMainManager()
{
add(mtxt);
}
public int getPreferredHeight()
{
return Display.getHeight();
}
public int getPreferredWidth()
{
return Display.getWidth();
}
protected void sublayout(int width, int height)
{
layoutChild(mtxt, 50, 500);
setPositionChild(mtxt, 0, 10);
mtxt.setBackground(
BackgroundFactory.createSolidBackground(0x000000FF));
setExtent(width, height);
}
}
The line layoutChild(mtxt, 50, 500); should set the width and height of my EditField. It does, but only with the width. The height is constant. If I set it to 500 I get the same result as if I set it to 10.
Any idea of what I'm missing ? because I'm sure this is a stupid error I'm doing...
Thanks
==edit
After jproffit help, I've understood what I did wrong. However now that it works (I can set the height) I have another problem. Here is me code:
private EditField m_Txt=new EditField(EditField.FOCUSABLE |
EditField.FILTER_DEFAULT) {
protected void layout(int width, int height)
{
setExtent(Display.getWidth(), m_TxtHeight);
}
public boolean isFocusable()
{
return true;
}
protected void onFocus(int direction)
{
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
};
With this code I cannot manage the focus correctly. What do I forget ? I cannot see the cursor in my field.
Any idea ?
Thanks
You aren't telling it the dimensions to take, you're specifying the maximum amount of space it can take up. So when you tell it 10, 50, or 500, if it only want to use a height of 8 that's all it will be. You'll have to override layout() on the EditField if you want to control its dimensions as well.
Try doing like this..
create a custom editfield and inside the layout method
_editField = new EditField("", initialValueOfTextField)
{
protected void layout(int maxWidth, int maxHeight)
{
int myWidth = getMaxSize() * getFont().getAdvance("W");// define your req width
int myHeight= 50 // your required height
super.layout(myWidth, myHeight);
}
};