Multiple consecutive alerts in Java ME - 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);
}
}

Related

RecyclerView SCROLL_STATE_IDLE is being called late

On RecyclerView addOnScrollListener the property SCROLL_STATE_IDLE takes time to get called at end of the item size and when scrolled up to the top of the RecyclerView. But it works fine in middle of the scrolling.
The root view of the layout is CoordinatorLayout.
Having the same issue, the only workaround I've found is to send a stopScroll() whenever the RecyclerView gets a SCROLL_STATE_SETTLING, though not the ideal solution. Probably would be better to detect if it has reached the top or bottom edge, taking into account the scrolling direction, and then call stopScroll():
#Override
public void onScrollStateChanged(final int state)
{
super.onScrollStateChanged(state);
if (state == RecyclerView.SCROLL_STATE_SETTLING)
{
this.stopScroll();
}
}
Update
This issue seems to be a bug in the support library, though it was reported as fixed its clear that the problem still exists, so hopefully we should see an adequate solution in the future:
https://issuetracker.google.com/issues/66996774
Invoke stopScroll() when your recyclerview has been reached to to bottom.
I think Since it's support library version up, velocity is calulated and it makes delay a little.

GXT live grid not scrolling to bottom

I have a GXT LiveGridView grid - works great, loading fine, but will not scroll all the way to the bottom record using the scroll bar. The only way to see the last record is to select the last visible record and use the down arrow key to force the display down, one record at a time.
By overriding the 'getCalculatedRowHeight' method, since it was returning a wrong value (compared with the Firebug analysis) the issue was resolved.
private class MyLiveGridView<T> extends LiveGridView<T> {
// deal with wrong value of 22 from this method currently.
#Override
protected int getCalculatedRowHeight(){
return 28;
}
}
(A real fix would be to dynamically acquire the correct row height. For now this will suffice since I'm on the hook for a lot of code still).

How do I know when all paintings are finished?

My program is fullscreen application. On start I use some checks and if something is wrong, error dialog is shown. I need two windows (main fullscreen, and dialog) were here and all graphics were ok.
When I use this code:
primaryStage.show();
/*..some checks*/
dialogStage.show();
.. there is no fullscreen. It's somehow overlapped by other windows.
This one works better:
stage.setOnShown( new EventHandler<WindowEvent>() {
public void handle(WindowEvent windowEvent) {
/*..some checks*/
dialogStage.show();
}
});
primaryStage.show();
But... I can see task panel from Windows. It becomes hidden when dialog is closed.
And also I can see default java icon there. Although I've set custom icon before.
Looks like setOnShown() is called before all graphical updates are done.
Is there any event or something to know it?
I also tried Timeline from animation to call a small delay. But without success.
The same with calling dialog from additional thread (with Platform.runLater() of course :) ). This way fullscreen hides at all.
Maybe on JavaFX8 things are better?

Hiding master UISplitViewController for only certain views

I have a UISplitViewController which has a UINavigationController in the master and a UIViewController in the detail. When the device is orientated into landscape mode I want the normal behaviour to be preserved. I.e. The master gets shown in landscape and hidden in portrait.
However depending what the user clicks in the master depends on which UIViewController is loaded into the detail part of the UISplitViewController. What I would like is for the master to be hidden in landscape mode when a user clicks on a button in the detail UIViewController. The problem is I can't get this to work.
My delegate looks like this (have removed some lines for simpler viewing):
public class SplitControllerDelegate : UISplitViewControllerDelegate {
SplitViewController incomingController;
private bool hideMaster = false;
public override bool ShouldHideViewController (UISplitViewController svc,
UIViewController viewController,
UIInterfaceOrientation inOrientation) {
return hideMaster;
}
public void SetHideMaster(bool value) {
hideMaster = value;
}
}
I then call it from the detail UIViewController like
splitControllerDelegate.SetHideMaster(value);
However nothing changes. I'm unsure of how to make it perform the change? Should the master disappear immediately? What causes the WillHideViewController to fire?
Thanks
Mike
What you're trying to do cannot be done officially. ShouldHideViewController() is called only upon device rotation. So unless you rotate forth and back, your controller won't disappear.
You have various options:
Don't use UIListViewController but some other third party replacement
Use UIViewController containment feature of iOS5 and implement your own split view
Apply a hack to UISplitViewController
About the last point. You should be able to force ShouldHideViewController() being called if you set the Delegate property to NULL and then assign a new delegate. Afterwards, call the WillRotate() method of the split view controller using the current orientation.
I'd go for the 2nd option.
By design you cannot do much with the standard UISplitView, try that third party control :
https://github.com/mattgemmell/MGSplitViewController

Customising the title bar in 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.

Resources