06-16-2012 05:13 AM
package mypackage;
import java.util.Vector;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Color;
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.UiApplication;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
public class SingersListField extends ListField {
private Vector content = null;
private ListCallback callback = null;
private int currentPosition = 0;
/**
* Instantiates a new title list and populates it with the appropriate items.
*
* @param content The content to be loaded in the list.
*/
public SingersListField (Vector content) {
this.content = content;
initCallbackListening();
// font = this.getFont().derive(Font.BOLD, 16);
// this.setFont(font);
this.setRowHeight(100); // I think this is an important point for it to work: set the height of the row outside the draw method.
// Other possibly useful info is that the negative signal means I will multiply the font size by the number provided.
}
private void initCallbackListening() {
callback = new ListCallback();
this.setCallback(callback);
}
/**
* Callback implementation to this custom list field.
*
* @author Alaa El-Khatib
*/
private class ListCallback implements ListFieldCallback {
private Bitmap image = null;
Bitmap Arrow = Bitmap.getBitmapResource("arrow.png");
Bitmap Arrow2 = Bitmap.getBitmapResource("arrow2.png");
public ListCallback() {
}
public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
if(index!=-1){
currentPosition = listField.getSelectedIndex();
int yPos = 5 + y; // initial position will consider an offset.
int xPos = 15; // left offset, fixed for all rows in the list.
Song temp = (Song)content.elementAt(index);
image=MAMClient.sizeImage(EncodedImage.createEncod edImage(temp.getAlbumCover(), 0, temp.getAlbumCover().length),110,110).getBitmap();
graphics.drawBitmap(5, yPos, image.getWidth(), image.getHeight(), image, 0, 0);
xPos = xPos + image.getWidth();
if (graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOC US))
{
// graphics.setColor(0x858686);
Font font = getFont().derive(Font.BOLD, 32);
graphics.setFont(font);
graphics.drawText(temp.albumName, xPos , yPos,DrawStyle.ELLIPSIS,width-(image.getWidth()+Ar row2.getWidth()+10));
font = getFont().derive(Font.PLAIN, 32);
graphics.setFont(font);
graphics.drawText(temp.singerName, xPos , yPos+25,DrawStyle.ELLIPSIS,width-(image.getWidth() +Arrow2.getWidth()+10));
font = getFont().derive(Font.ITALIC, 32);
graphics.setFont(font);
graphics.drawText("ALBUM - "+temp.getPrice()+" KWD", xPos , yPos+50,DrawStyle.ELLIPSIS,width-(image.getWidth() +Arrow2.getWidth()+10));
graphics.drawBitmap(width-Arrow2.getWidth()-5, yPos, Arrow2.getWidth(), Arrow2.getHeight(), Arrow2, 0, 0);}
else
{
//graphics.setColor(0x60347A);
Font font = getFont().derive(Font.BOLD, 32);
graphics.setFont(font);
graphics.drawText(temp.albumName, xPos , yPos,DrawStyle.ELLIPSIS,width-(image.getWidth()+Ar row.getWidth()+10));
font = getFont().derive(Font.PLAIN, 32);
graphics.setFont(font);
graphics.drawText(temp.singerName, xPos , yPos+25,DrawStyle.ELLIPSIS,width-(image.getWidth() +Arrow2.getWidth()+10));
font = getFont().derive(Font.ITALIC, 32);
graphics.setFont(font);
graphics.setColor(Color.GRAY);
graphics.drawText("ALBUM - "+temp.getPrice()+" KWD", xPos , yPos+50,DrawStyle.ELLIPSIS,width-(image.getWidth() +Arrow2.getWidth()+10));
graphics.drawBitmap(width-Arrow.getWidth()-5, yPos, Arrow.getWidth(), Arrow.getHeight(), Arrow, 0, 0); }
graphics.setColor(0x60347A);
yPos = y + listField.getRowHeight() - 1;
graphics.drawLine(0, yPos,Display.getWidth(), yPos);
}}
public Object get(ListField listField, int index) {
return content.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return content.indexOf(prefix, start);
} }
// This method returns the index of the highlighted item in the list, which will be useful somewhere in my code.
public int getCurrentPosition() {
return currentPosition;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
//Song temp = (Song)content.elementAt(currentPosition);
//UiApplication.getUiApplication().pushScreen(new SingersCategory(temp.getSingerId(),temp.albumName, temp.getAlbumCover()));
return true;
}
protected void drawFocus(Graphics graphics, boolean on) {
XYRect rect = new XYRect();
getFocusRect(rect);
if (on) {
graphics.setColor(Color.PURPLE);
graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
getCallback().drawListRow(this, graphics, getSelectedIndex(), rect.y, rect.width);
}
} }
As you see I have a list, on selection of the row I highlight it purple.But since letters are black, they disappear.What advice can u offer?
Can I on selection change black text colors to white? if yes can u give how?
or i make adjustments to suitable colors?and can u advice what colors?
Solved! Go to Solution.
06-18-2012 03:04 AM
06-18-2012 03:06 AM
06-18-2012 03:17 AM
06-18-2012 03:18 AM - edited 06-18-2012 03:19 AM
argh, graphics.setcolor set the color of the highlighted row.
protected void drawFocus(Graphics graphics, boolean on) {
XYRect rect = new XYRect();
getFocusRect(rect);
if (on) {
graphics.setColor(Color.PURPLE);
graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
getCallback().drawListRow(this, graphics, getSelectedIndex(), rect.y, rect.width);
}
}
but i want to change the color of the texts inside the highlighted row to make them visible.
i want to change them from black to white on selection
06-18-2012 03:24 AM
06-18-2012 03:42 AM