Hi developers I have a screen with transparent background(bitmap). I have a list field placed on top of it, but the issue is the transparent background is not showing the previous screen, instead it shows white screen with listfield.
public class IndexScreen extends MainScreen implements ListFieldCallback {
private Vector rows;
ListField listItems;
int listItem;
int listFieldIndex = -1;
TableRowManager row;
Bitmap indexBox = Bitmap.getBitmapResource("res/screens/Index_Box.png");
public IndexScreen() {
listItems = new ListField() {
listItems.setRowHeight(20);
listItems.setCallback(this);
rows = new Vector();
listItems.setSize(rows.size());
_listVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL) {
public void paint(Graphics g) {
g.drawBitmap(0, 0, UIinitialize.screenWidth,
UIinitialize.screenHeight, indexBox, 0, 0);
super.paint(g);
}
protected boolean navigationMovement(int dx, int dy, int status,
int time) {
return super.navigationMovement(dx, dy, status, time);
}
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(listItems, maxWidth, maxHeight);
setPositionChild(listItems, 5, 0);
setExtent(maxWidth, 255);
}
};
_listVfm.add(listItems);
add(_listVfm);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
listItems.invalidate();
}
}, 500, true);
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
TableRowManager rowManager = (TableRowManager) rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, listItems.getRowHeight());
}
class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, 250);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.popContext();
}
protected void sublayout(int width, int height) {
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth, height);
setPositionChild(field, 0, 0);
setExtent(width, height);
}
public int getPreferredWidth() {
return listItems.getWidth();
}
public int getPreferredHeight() {
return listItems.getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
The above code is the part of the code that I am using.How can I implement to view the transparent background.Can anybody please help me.Thanks.
MainScreen includes its own non-transparent background. You'll have to extend Screen if you want to have a transparent/translucent background.
Another option, which I've used in my apps, is using FullScreen instead of MainScreen. FullScreen allows transparent backgrounds. If you're using setStatus or setTitle you'll have to find another method of displaying that data, but otherwise it's very similar.
From your code, though, extending Screen instead of MainScreen would likely by more appropriate.
Related
Hi Friend's in my BlackBerry Application i use a list Field, and over this list Field i add a drop down. Now my problem is how do i select the drop down which i added over the list Field.Now i only select list field and not the drop down but my requirement is first i should select the drop down and then list field. I have included my code here please check it.
public class TaskListField extends ListField implements ListFieldCallback, KeypadListener {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
public LoginPage objLoginPage;
public String[] data={"Call","Visit"};
public String strIndex = null;
public int tempIndex = 0;
public int intvalue;
public int id;
public int value;
public boolean hasFocus = false;
public static String[] arrOutletName = { "Dosa Store", "Benfish Bhawan",
"Nalban Park", "Korunamoyee", "206 Bus Stop", "aaaaaaaa",
"bbbbbbbb", "ccccccccc", "dddddddd", "eeeeeee" };
public ObjectChoiceField ocf;
public TaskListField() {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
setCallback(this);
p1 = Bitmap.getBitmapResource("name.png");
p2 = Bitmap.getBitmapResource("name.png");
rows = new Vector();
for (int x = 0; x < XmlHander.vectSrno.size(); x++) {
TableRowManager row = new TableRowManager();
strIndex = String.valueOf(x);
String strVectno = XmlHander.vectSrno.elementAt(x).toString();
String strSLADate = XmlHander.vectSldate.elementAt(x).toString();
if (x % 2 == 0) {
row.add(new BitmapField(null));
}
else {
row.add(new BitmapField(null));
}
LabelField task = new LabelField(" ");
if (x % 15 == 0) {
task.setFont(Font.getDefault().derive(Font.BOLD | Font.UNDERLINED));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}
row.add(task);
row.add(new LabelField(strVectno, DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
// graphics.setColor(Color.PINK);
super.paint(graphics);
}
});
row.add(ocf=new ObjectChoiceField("",data){
protected void paint(Graphics graphics){
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
ocf.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC)
Dialog.alert(data[ocf.getSelectedIndex()]);
}
});
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
TaskListField list = (TaskListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
protected boolean navigationClick(int status, int time) {
final int index;
index = this.getFieldWithFocusIndex() - 1;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new Details(id));
}
});
return false;
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
id = this.getSelectedIndex();
invalidate();
return super.moveFocus(amount, status, time);
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
System.out.println("direction==" + direction);
invalidate();
}
public void onUnfocus() {
updateLayout();
super.onUnfocus();
invalidate();
}
private int getFieldWithFocusIndex() {
return 0;
}
}
I used the below code for edit text where I give the width and the height for the edit text and once the text fills the given height the field will scroll its content, but I want to make this code more dynamic. I want this editfield with only one line and it will grow for a number of lines done 3 or 4 and after this is done the field should scroll what it contains. Any help with that?
public class TextBoxField extends VerticalFieldManager {
private int managerWidth;
private int managerHeight;
private EditField editField;
public TextBoxField(int width, int height) {
super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
editField = new EditField(){
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}
};
vfm.add(editField);
add(vfm);
}
public void paint(Graphics g) {
super.paint(g);
g.drawRect(0, 0, getWidth(), getHeight());
}
public void sublayout(int width, int height) {
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth,managerHeight);
}
public String getText() {
return editField.getText();
}
public void setText(String text) {
editField.setText(text);
}
}
I'd like to create an Image Button that has three states:
Normal
Focused
Pressed (or "down" or "active" whatever you call it)
Normal and Focused is pretty straightforward. I used the well-known classes BaseButtonField and BitmapButtonField as a bases. My Problem is that
protected boolean trackwheelClick(int status, int time)
is not called. My Button extends from Field and has Field.FOCUSABLE | Field.EDITABLE as styles. What am I missing?
You can try with "Tutorial: Creating a custom button" of the official RIM docs.
I think it is what your looking for
The below code is a custom button field for bottom menu bar. This will be useful for your task.
public class PictureBackgroundButtonField extends BitmapField {
MyTooltip _tooltip;
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;
String text;
int mWidth;
int mHeight;
int xpos1;
public PictureBackgroundButtonField(String text,Bitmap normal, Bitmap focused, int xpos)
{
super(normal,FOCUSABLE);
mNormal = normal;
mFocused = focused;
mWidth = mNormal.getWidth();
mHeight = mNormal.getHeight();
this.text=text;
setMargin(0, 0, 0, 0);
setPadding(0, 0, 0, 0);
xpos1 = xpos;
}
public String getText()
{
return text;
}
public void setText(String text)
{
this.text=text;
}
protected void paint(Graphics graphics) {
Bitmap bitmap = mNormal;
if(isFocus())
{
bitmap = mFocused;
}
else
{
bitmap = mNormal;
}
graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0);
}
protected void drawFocus(Graphics graphics, boolean on) {
}
protected void onFocus(int direction) {
//lbt.setText(text);
invalidate();
super.onFocus(direction);
if ( _tooltip != null ) {
_tooltip.removeToolTip();
_tooltip = null;
}
// Display tooltip at 50,50 for 5 seconds
_tooltip = MyTooltip.addToolTip(UiApplication.getUiApplication(), text, xpos1, 270, 1);
}
protected void onUnfocus() {
//lbt.setText("");
invalidate();
super.onUnfocus();
if ( _tooltip != null ) {
// We have displayed a Tooltip - remove it
_tooltip.removeToolTip();
_tooltip = null;
}
}
public int getPreferredWidth() {
return mWidth;
}
public int getPreferredHeight() {
return mHeight;
}
protected void layout(int width, int height) {
setExtent(mWidth, mHeight);
}
}
When a field is in the 'active' or 'pressed' state its visual state is set to Field.VISUAL_STATE_ACTIVE. If you check for this in your paint() method by calling Field.getVisualState() you'll be able to change how your button is displayed when it's pressed.
hi all The below is my code .i try to remove black border color from popup window .i tried this but still i get small black border .
public class S2SPopup extends PopupScreen
{
public S2SPopup()
{
super(new VerticalFieldManager()
{
public void paint(Graphics g)
{
int a = g.getGlobalAlpha();
int c = g.getColor();
g.setColor(c);
g.drawBitmap(0, 0, HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight(),HomeScreen.popupimg, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
setExtent( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
}
});
setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
VerticalFieldManager vfm_Label = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth,150);
setExtent(maxWidth, 150);
}
};
vfm_Label.setMargin(80, 0, 0, 0);
ButtonField btnclose = new ButtonField("",ButtonField.RIGHT)
{
public void paint(Graphics g)
{
//setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
int c = g.getGlobalAlpha();
g.setBackgroundColor(c);
super.paint(g);
}
};
btnclose.setMargin(0, 0, 0, 250);
btnclose.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
close();
}
});
LabelField s2sLabelField = new LabelField()
{
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
super.paint(g);
}
protected void layout(int width, int height)
{
super.layout(width, 150);
setExtent(width, 150);
}
};
s2sLabelField.setPadding(0, 50, 0, 30);
s2sLabelField.setText("lasjdfljlsjlfj ljsfdl jsflljfiowurnowncnvouern.zvovn ljlsfdjj jlj" +
"jsljfdlj ljsfl sjfl jfjsljdfljslfu jsjf;ujerpljsfdjpn sdflsajf ss23s mail jsldfjlfdju nsfjljljlfjmnn,nsf,n,nlojljlsndf,n,ljnsjfdljjufsn jj" +
"sjfd;jjljlsduflja;sfj ljsldfujrqnfqperiujf.zvnpqrue 33333333333333333333333333333333333333 ");
add(btnclose);
vfm_Label.add(s2sLabelField);
add(vfm_Label);
} //end of constructor
} // end of main screen
Override applyTheme with an empty implementation, and the black border goes away. You can't fix this from the constructor alone:
protected void applyTheme(){}
I doubt that it will correct this, but you may try giving your delegate manager a margin of 0 just to be certain that there isn't one on it and background color is creeping in from the theme. A solution that I have implemented in the past is to create your own custom Screen
public class CustomPopup extends Screen {
public CustomPopup() {
super(new VerticalFieldManager() {
//your custom code or a custom manager class (which is what I did)
);
setBackground(BackgroundFactory.createSolidTransparentBackground(0x000000, 0));
}
protected void sublayout(int width, int height) {
//make this screen take up the entire display
setPosition(0, 0);
setExtent(Display.getWidth(), Display.getHeight());
//and layout the delegate
setPositionDelegate(some_x, some_y);
layoutDelegate(some_width, some_height);
}
}
You'll have to add your own buttons and other graphics to it, but This should at least help point you in the right direction.
how to create a list field as same style as Black Berry facebook ?
the RIM list field contains only text, i want to create list field that can contains other fields such as image, text area and href link .
I managed to create it ,and it works fine but the the fields inside the list item never gain focus , any idea how do it ?
public class RichListField extends ListField implements ListFieldCallback {
private Vector rows;
public RichListField(String emtpyString, RichListItem[] items) {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString(emtpyString, DrawStyle.HCENTER);
setCallback(this);
rows = new Vector();
for (int i = 0; i < items.length; i++) {
TableRowManager row = new TableRowManager();
row.add(new BitmapField(items[i].getBitmap()));
LabelField itemLabel = new LabelField(items[i].getLabel(),
DrawStyle.ELLIPSIS);
// mark selected
// itemLabel.setFont(Font.getDefault().derive(
// Font.BOLD | Font.UNDERLINED));
itemLabel.setFont(Font.getDefault().derive(Font.BOLD));
row.add(itemLabel);
// SET THE LIST Item description
row.add(new LabelField(items[i].getDescription(),
DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
row.add(items[i].getLink());
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
RichListField list = (RichListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
// set the label field
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the description label field
field = getField(2);
layoutChild(field, preferredWidth, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the Href field
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
//To set the required dimensions for the field
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Display.getWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
public class RichListItem {
private String label;
private Bitmap bitmap;
private String description;
private HrefField link;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public HrefField getLink() {
return link;
}
public void setLink(HrefField link) {
this.link = link;
}
public RichListItem(String label, Bitmap bitmap, String description,
HrefField link) {
super();
this.label = label;
this.bitmap = bitmap;
this.description = description;
this.link = link;
}
}
You just need to add 2 lines of code at drawListRow when implement interface ListFieldCallback.
if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) rowColor = Color.RED;
else rowColor = Color.GRAY
If all you want to do is change the color when a row has focus, you could override ListField.drawFocus():
protected void drawFocus(Graphics graphics, boolean on) {
if (on) {
graphics.setColor(focusColor);
graphics.setBackgroundColor(focusBackgroundColor);
super.drawFocus(graphics, on);
/**
You may have to play with the call to super.drawFocus() depending on
what it actually does. For example:
super.drawFocus(graphics, false);
may work better. Or you may have to draw the field yourself.
*/
}
}