In my app i am setting bitmap image of verticalFieldManager but it is repeating. For setting image i am using
VerticalFieldManager vertical=new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH )
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(), Display.getHeight());
setExtent(Display.getWidth(), Display.getHeight());
}
};
vertical.setBackground(BackgroundFactory.createBitmapBackground(
Bitmap.getBitmapResource( "bg_640.png" ) ));
It is showing like
I am stuck here. Any idea will be apperciated.
Thanks
Instead of calling
vertical.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("bg_640.png")));
use this version of createBitmapBackground(Bitmap, int, int, int)
and pass parameters like this:
vertical.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("bg_640.png"),
Background.POSITION_X_LEFT,
Background.POSITION_Y_TOP,
Background.REPEAT_NONE));
Related
I am using EditField in my application. The EditField is editable while using virtual keyboard but it requires long press to edit with quetry keypad. I tried all possible way which I can but didn't find what is causing the problem.
I am testing it in Torch 9800. Is there any clue about it please welcome.
//FOR NICKNAME SEARCH
nicknameSearchHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH){
protected void sublayout(int width, int height) {
setPositionChild(getField(0),0,10);
layoutChild(getField(0),150,height+5);
setPositionChild(
getField(1), Display.getWidth()/2+35,
0);
layoutChild(
getField(1),
width+16,
height);
setExtent(width, 50);
}
};
_nickname = new EditField("" ,_initialName){
protected void onFocus(int direction) {
super.onFocus(direction);
this.setText("");
invalidate();
}
};
//_nickname.setMargin(10,50,5,5);
_nickname.setBorder(roundedBorder);
_findByNickName = new ButtonField(" Search " ,ButtonField.CONSUME_CLICK);
_findByNickName.setMargin(7,5,5,5);
_findByNickName.setChangeListener(this);
nicknameSearchHFM.setMargin(20,0,0,10);
nicknameSearchHFM.add(_nickname);
nicknameSearchHFM.add(_findByNickName);
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.
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);
}
};
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);
}
};