Customising the title bar in Java ME - java-me

Is it possible to customise the title bar in Java ME?

You might like to check out J2ME Polish, which provides a massive amount of UI customisation for MIDlets, including the title bar: link text

The API doesn't provide functionality for customising the default title bar, but we can attempt to write our own bar. This is in itself a minor breach of UI conventions. Some phones allow us to use setTitle(null) to remove the title. The phones in the Java mobile toolkit behave this way, but the Series 40 and 60 emulators don't seem to support this and instead generates a default title. On the other hand, the Sony Ericssons and Motorolas I've tested seem to support this.
However, we can detect whether the ability to remove the titlebar is present. We do not use the sizeChanged callback as the calling of this function may be delayed when the canvas is not visible. Instead we call getHeight both before and after removing the bar. According to the spec, getHeight should always return the correct and up to date value, even when the canvas is not being displayed. Here is code for implementing the detection:
public static boolean HIDE_TITLE_ENABLED;//Whether the implementation allows us to hide the title bar
static{
//See if we can remove the title by ensuring it is non-nil, then attempting
//to remove it. If we can't, then reset it.
Canvas c=new Canvas(){
protected void paint(Graphics g){
}
};
c.setTitle("test");
int preHeight=c.getHeight();
c.setTitle(null);
int afterHeight=c.getHeight();
HIDE_TITLE_ENABLED=preHeight!=afterHeight;
}
It is also possible to hide the title bar using full screen mode, but this hides other elements as well. This method is popular in games.

Related

Xamarin.Forms.DatePicker Text color

For Xamarin.Forms.DatePicker It is not obvious that the date field is "tapable" I want to change the text color of it to blue so the user will think it is clickable?
I see a background color property but not forecolor/text color?
Let me know how I can do that.
I did it just creating a class like that on my Android Project and making no changes on my Forms Pages:
using Xamarin.Forms;
using xxxx.Droid;
[assembly: ExportRenderer(typeof(Xamarin.Forms.DatePicker), typeof(MyDatePickerRederer))]
namespace xxxx.Droid
{
public class MyDatePickerRederer : Xamarin.Forms.Platform.Android.DatePickerRenderer
{
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.DatePicker> e)
{
base.OnElementChanged(e);
this.Control.SetTextColor(Android.Graphics.Color.Black);
}
}
}
I don't think that the forecolor/text color is accessible at this time and I'm not sure if it will be in the future or not. Typically what you would do in this scenario is create a Custom Renderer to get down into the native implementation of the UIDatePicker control for iOS and change it's properties there. The problem with that in this case is that if you look through the iOS SDK documentation as well, I don't believe there is a way to customize the text on the UIDatePicker picker control. This is why you can't do it in Xamarin.Forms either.
At this point you will probably have to create your own custom control/renderer to make such a small change. Frustrating, I know, but unfortunately that this point I don't think you can actually accomplish the simple thing you are looking to do. :-(

Show alert with Indeterminate progress indicator Nokia Full Touch j2me

Does anyone know how to show a spinner for progress bar in a j2me alert?
Here is my piece of code so far:
loadingDialog = new Alert("Please Wait","Please Wait.",null,AlertType.INFO);
Gauge gau = new Gauge( null, false,
Gauge.INDEFINITE,
Gauge.CONTINUOUS_RUNNING );
loadingDialog.setIndicator(gau);
loadingDialog.setTimeout(500000);
displays.setCurrent(loadingDialog);
I am getting a horizontal line (like a slider). What I want is a spinner in place of it.
http://www.developer.nokia.com/Resources/Library/Full_Touch/ui-components/progress-indication.html
The second image (labelled non interactive gauge) of the link is what I am looking for:
The way how you create Gauge looks about right, in accordance with instructions given at Nokia page you refer as well as with Gauge API javadocs (available online):
CONTINUOUS_RUNNING
The value representing the continuous-running state of a non-interactive Gauge with indefinite range.
...
INDEFINITE
A special value used for the maximum value in order to indicate that the Gauge has indefinite range.
Explanation at Nokia page (somewhat vague) suggests the most likely reason for the issue you describe is that Nokia shows spinner only in forms, not in alerts:
- Indefinite gauge in Java Form uses spinner.
- An Alert uses a "barber shop roll" (animated bar of fixed length).
The way to test above assumption is to put Gauge like yours into the Form instead of Alert and see how device / emulator displays it.
If Form shows spinner, then the most straightforward workaround is to use Form instead of Alert. In this case, since Form lack "dismissal" feature provided by Alert, you would have to implement it yourself - eg by using TimerTask to schedule form replacement with previous screen.
Hehehe, the clue is in the link you gave --
Java Alerts do not use spinners due to layout constraints.
So it's not possible!

JavaME Nokia Maps API: how to display additional info on marker click?

I need to display an additional info for a marker when it's clicked. I expected to find a way how to display a popup window (like a tooltip) with a short description on marker click, but failed.
I use MapMarker class for my markers because I need custom icons.
The MapMarker and MapStandardMarker classes do not have the functionality I need.
As I understand, I need something like Android MapView Balloons
I've solved the problem.
I use the popup dialog similar to the one implemented in "Meet Me For Dinner" sample application. All necessary info can be found here.
I met the problem with detecting a click on marker. For this I used MapDisplay.getObjectAt () method. But it looks like that method doesn't take into account the marker's anchor point. So, I had to use the following work-around for this:
final MapObject mapObj = mapDisp.getObjectAt ( new Point (
clickX + m_markerIconSize.getWidth (),
clickY + m_markerIconSize.getHeight () )
);
if ( (mapObj != null) && (mapObj instanceof MapMarker) ) {
I worked on Google MID-MAPS, There is no any method to show balloon in MapMarker but you can try with your own method create your own balloon. When user clicks particular position of map you can show your balloon. I never tried this but lets try and let me know also.
Thanks

How to set background image for Dialog?

I am trying to do this:
public class DialogMenuHawaii extends Dialog {
Style s = UiFactory.getBaseStyle();
s.setBgTransparency(0);
s.setBgImage( <my image >);
this.setUnselectedStyle(s);
}
but it doesn't work.
First, I suggest you use a theme. We constantly change small implementation details e.g. customizations like the one you are doing will not be portable between LWUIT 1.4 and 1.5. There is no reason whatsoever not to use a theme for something like this.
If you are interested in the pain and suffering of manually coding view logic into your application you can use several methods such as getDialogComponent() to get the style from them and manipulate that. Dialog is a complex beast due to the fact that its really a form padded away from the edges.
Open your '.res' file in resource Editor and select your preferred theme,
Under 'Unselected' tab open the DialogContentPane style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background image to the image you need to show as Dialog bg
Under 'Unselected' tab open the DialogBody style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background transparency as '0' and also make sure the background image type is NONE
NOTE: The above code will reflect for all the Dialogs in your application. If you want a particular dialog with background image than derive new styles from these default styles, and follow the above steps to apply it to your DialogMenuHawaii or any runtime Dialogs.
HOW TO: I would recommend you to go through the Shai's blog posts LWUIT Resource Editor Tutorial Part 1 till part 10. To better understand the Resouce Editor its features and capabilities.
:
:
:
PS: Programmatic-ally i haven't been able to achieve it using TextArea which is the case for default Dialog's. If you replace the dialog body component with Label if works fine, the code sample is given below. I haven't delved much into why is it so ? maybe will do it in my free time. Hence i have proposed a working alternative solution which is scripted above using Resource Editor and below using the code
class MyDialog extends Dialog {
public void show() {
Container octnPane = this.getDialogComponent();
octnPane.getUnselectedStyle().setBgTransparency(0, false);
Container ctnPane = (Container)((BorderLayout)octnPane.getLayout()).getCenter();
ctnPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED, false);
ctnPane.getUnselectedStyle().setBgImage(myImage, false);
Label t = new Label("Dialog");
t.setUIID("DialogBody");
t.getUnselectedStyle().setBgTransparency(0, false);
ctnPane.addComponent(t);
super.show();
}
}
This is for Dialog background.
Dialog dialog = new Dialog();
dialog.getDialogStyle().setBgImage(Image.createImage("/image/image.png"));
If you want to set transparency of Dialog with image.
dialog.getStyle().setBgImage(Image.createImage("/image/image.png");

Multiple consecutive alerts in Java ME

According to the documentation, Display.setCurrent doesn't work if the current displayable is an alert. This is a problem as I would like to pop up another alert when the user selects a command. Does anyone know how to work around this so that we can go from one alert to another? I am using CLDC 1.0 and MIDP 2.0.
Additional Information
The spec does allow us to edit an alert while it is on screen, but some Nokia phones don't handle it well at all. So I am now trying to go from the alert to a blank canvas, then back to the alert. Of course I don't want the user to interact with the previous canvas, so it seems that I am forced to create a new blank canvas. As a sidenote, this has the slight disadvantage of looking worse on phones which still have the previous screen when an alert is shown.
The bigger problem is how to transition from the blank canvas back to an alert once the canvas is loaded. Testing on the Motorola emulator revealed that showNotify is not called after returning from an alert to the previous screen. I guess I could create the next alert in the paint method, but this seems like a ugly hack.
OK, so your problem is that you can't set it up to do:
Display.setCurrent(alert1, alert2);
and
Display.setCurrent(alert2);
is also not possible if the current Displayable is already alert1.
So how about put an intermediate Displayable item that is blank and that immediately changes to the next alert? Assuming the current Displayable is alert1, like this in your alert1's command block:
Display.setCurrent(blankForm);
Display.setCurrent(alert2);
That should work assuming you are not using the default 'Dismiss' command. So basically it goes from alert1->(blankForm->alert2).
I couldn't find a way around this, so I just used the paint hack.
public class AlertPage extends Canvas{
MIDlet midlet;
Alert alert;
private AlertPage(MIDlet midlet){
this.midlet=midlet;
}
protected void paint(Graphics arg0){
//Yep, this is a hack, but showNotify doesn't seem to work well for Motorola
if(alert!=null){
Display d=Display.getDisplay(midlet);
d.setCurrent(alert);
alert=null;
}
}
public static void showAlert(MIDlet m, Alert a){
AlertPage page=new AlertPage(m);
Display d=Display.getDisplay(m);
page.alert=a;
d.setCurrent(page);
}
}

Resources