02-25-2010 06:25 AM
Hi
I am developing a blackberry application using RIM apis I am using the MainScreen and in my application i want to restrict the screen size so that the battery icon the network symbol etc is visible to the user. Is there any way i can restrict the fullscreen size of the Main screen ???
02-25-2010 07:17 AM
no, this is not possible. you can implement your own header bar with the desired information. i posted a code sample from jfisher in some other thread, his side is offline but you can find it using archive.org
02-25-2010 08:07 AM
hi
can u tell me where i can find the code sample
I couldnt find in the jonathan fisher site
If u have the link please send me
02-25-2010 08:12 AM
http://web.archive.org/web/*/http://www.jonathanhfisher.co.uk/b2/
04-13-2010 08:11 PM
I was looking to see if anyone has gotten a Banner that is avalible to anyone, came across his post. WebAchive was fine but very slow, also there is no real way to find the post. After some searching I found it and to save the trouble of anyone else looking for it I posted his source code file here:
import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.RadioInfo;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
public class HeaderBar extends Field implements DrawStyle{
private Font headerFont = SmallFont();
private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private String timeString;
private String dateString;
private String title;
private boolean showSignal;
private boolean showBattery;
private boolean showDate;
private boolean showTime;
private boolean showTitle;
private int fieldWidth;
private int fieldHeight;
private int fontColour;
private int backgroundColour;
private int batteryBackground;
private Timer headerTimer = new Timer();
private TimerTask headerTask;
public HeaderBar(String _title) {
super(Field.NON_FOCUSABLE);
title = _title;
showSignal = true;
showBattery = true;
showDate = true;
showTime = true;
showTitle = true;
fieldHeight = 12;
fieldWidth = Graphics.getScreenWidth();
fontColour = 0x888888;
backgroundColour = 0;
batteryBackground = 0x999999;
headerTask = new TimerTask() {
public void run() {
invalidate();
}
};
headerTimer.scheduleAtFixedRate(headerTask, 1000, 1000);
}
public void setTitle(String _title){
title = _title;
invalidate();
}
public void setFontColour(int _fontColour){
fontColour = _fontColour;
invalidate();
}
public void setBatteryBackground(int _batteryBackground){
batteryBackground = _batteryBackground;
invalidate();
}
public void setBackgroundColour(int _backgroundColour){
backgroundColour = _backgroundColour;
invalidate();
}
public void showSignal(boolean bool){
showSignal = bool;
invalidate();
}
public void showBattery(boolean bool){
showBattery = bool;
invalidate();
}
public void showDate(boolean bool){
showDate = bool;
invalidate();
}
public void showTime(boolean bool){
showTime = bool;
invalidate();
}
public void showTitle(boolean bool){
showTitle = bool;
invalidate();
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
public int getPreferredWidth() {
return fieldWidth;
}
public int getPreferredHeight() {
return fieldHeight;
}
protected void paint(Graphics graphics) {
graphics.setFont(headerFont);
int graphicsDiff = 0;
if(backgroundColour != 0){
graphics.setColor(backgroundColour);
graphics.fillRect(0, 0, this.getPreferredWidth(), this.getPreferredHeight());
}
if(showSignal){
graphicsDiff = graphicsDiff + 28;
graphics.setColor(0x999999);
//draw blank background
graphics.fillRect(this.getPreferredWidth() - 26, 8, 6, 4);
graphics.fillRect(this.getPreferredWidth() - 21, 6, 6, 6);
graphics.fillRect(this.getPreferredWidth() - 16, 4, 6, 8);
graphics.fillRect(this.getPreferredWidth() - 11, 2, 6, 10);
graphics.fillRect(this.getPreferredWidth() - 6, 0, 6, 12);
int signalLevel = RadioInfo.getSignalLevel();
if(signalLevel > -77){
//5 bands
graphics.setColor(0xEFEFEF);
graphics.fillRect(this.getPreferredWidth() - 25,9,4,2);
graphics.fillRect(this.getPreferredWidth() - 20,7,4,4);
graphics.fillRect(this.getPreferredWidth() - 15,5,4,6);
graphics.fillRect(this.getPreferredWidth() - 10,3,4,8);
graphics.fillRect(this.getPreferredWidth() - 5, 1, 4, 10);
}else if(signalLevel > -86){
//4 bands
graphics.setColor(0xEFEFEF);
graphics.fillRect(this.getPreferredWidth() - 25,9,4,2);
graphics.fillRect(this.getPreferredWidth() - 20,7,4,4);
graphics.fillRect(this.getPreferredWidth() - 15,5,4,6);
graphics.fillRect(this.getPreferredWidth() - 10,3,4,8);
}else if(signalLevel > -92){
//3 bands
graphics.setColor(0xEFEFEF);
graphics.fillRect(this.getPreferredWidth() - 25,9,4,2);
graphics.fillRect(this.getPreferredWidth() - 20,7,4,4);
graphics.fillRect(this.getPreferredWidth() - 15,5,4,6);
}else if(signalLevel > -101){
//2 bands
graphics.setColor(0xEFEFEF);
graphics.fillRect(this.getPreferredWidth() - 25,9,4,2);
graphics.fillRect(this.getPreferredWidth() - 20,7,4,4);
}else if(signalLevel > -120){
//1 band
graphics.setColor(0xEFEFEF);
graphics.fillRect(this.getPreferredWidth() - 25,9,4,2);
}
}
if(showBattery){
int batteryLevel = DeviceInfo.getBatteryLevel();
graphics.setColor(batteryBackground);
graphics.fillRect(this.getPreferredWidth()-23-grap hicsDiff,2,20,8);
graphics.fillRect(this.getPreferredWidth()-3-graph icsDiff,4,1,4);
if(batteryLevel > 75){
graphics.setColor(0x28f300);
}else if(batteryLevel > 50){
graphics.setColor(0x91dc00);
}else if(batteryLevel > 25){
graphics.setColor(0xefec00);
}else{
graphics.setColor(0xff2200);
}
double powerLong = ((18.00/100)*batteryLevel);
int power = (int)powerLong;
graphics.fillRect(this.getPreferredWidth()-22-grap hicsDiff,3,power,6);
graphicsDiff = graphicsDiff + 24;
}
graphics.setColor(fontColour);
if(showTime){
timeString = " " + timeFormat.formatLocal(System.currentTimeMillis()) + " ";
}else{
timeString = "";
}
if(showDate){
dateString = " " + dateFormat.formatLocal(System.currentTimeMillis()) + " ";
}else{
dateString = "";
}
graphics.drawText(dateString + timeString, this.getPreferredWidth()-headerFont.getAdvance(dat eString + timeString)-graphicsDiff, 1);
if(showTitle){
int limit = 0;
if(showSignal)limit = limit + 28;
if(showBattery)limit = limit + 25;
if(showTime)limit = limit + headerFont.getAdvance(timeString);
if(showDate)limit = limit + headerFont.getAdvance(dateString);
if(headerFont.getAdvance(title) > this.getPreferredWidth() - limit){
int elippsy = headerFont.getAdvance("...");
int availableWidth = this.getPreferredWidth() - limit - elippsy;
String _txt = "";
String shorterTitle = "";
for(int i = 1 ; i < title.length(); i++){
_txt = title.substring(0, i);
if(headerFont.getAdvance(_txt) < availableWidth){
shorterTitle = _txt;
}
}
title = shorterTitle + "...";
}
graphics.drawText(title, 1, 0);
}
}
public static Font SmallFont(){
try {
FontFamily theFam = FontFamily.forName("SYSTEM");
return theFam.getFont(net.rim.device.api.ui.Font.PLAIN, 10);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
}Thank you Mr. Fisher
04-13-2010 08:33 PM
I seem to remember there being a problem with this header. Every header starts up a new timer and Timer task, but only to update the clock, which is displayed in minutes. I think each Timer = a new Thread, so if you use this header on more than about 10 screens, you will run out of Threads. Instead I suggest that you have each Header implement RealTimeClockListener and use clockUpdated() to invalidate() and so update the time.
04-13-2010 09:38 PM - edited 04-13-2010 09:41 PM
I see many thing in it that I want to change but I was just posting the original code.
I did a little test and ran pushed 70 screens (because I can) with this on there and it the console does say "too many threads" and "unable to run <application name:thread> but it never throws an exception, it just makes the (in my case) Simulator slow to a halt and do a lot of cleanup when I restart it. It was just to see what would happen but it never throws an exception, just freezes the BlackBerry.
I wish RIM would expose the built-in Banner class (assuming they have one). Then theme, notifications, etc. can be shown without needing to do any complex coding (has anyone even managed to get the icon of a 3rd party notification?)
04-13-2010 10:20 PM
Kill the thread on obscured and restart it when it is shown.
04-13-2010 11:22 PM
You don't have control of the Thread. You can kill the Timer and restart it when visible again but you would have to keep a timer going to so that the new Timer continues to update as if it never went away.
04-13-2010 11:36 PM - edited 04-13-2010 11:39 PM
What exactly do you mean?
Why would you need to have any thread or timer running while the header is not visible? (I'm assuming we're talking about the implementation in code above).
Upon visibility state change just enable, disable the timer, thread, whatever you're using.
On a seprate note, I'm wondering what are the differences between implementing Runnable and using TimerTasks for this implementation. Both are taking up a thread, whats the benefit of using TimerTask?