Back to previous page in j2me with lwuit using Command - java-me

In my project I am going to on one List then clicking on the item of that List going to new Form there is another List on which by clicking going to next Form.
These Forms are not different Forms, they are in a single Form but they are added in a Container and as click on List item it is visualized. The problem is I have a back Button on each Container but I have to code all time when I need to go to back to previous page.
I need a solution such that there will only one back Command on which by clicking it should go to it's current page's previous page. Need only one Command on which by clicking it goes to its previous page.
I know how to code this with COMMAND.BACK in lcdui but need suggestion for LWUIT.

I wouldn't use a Buttonto do this stuff. My suggestion is, use a Command and implement a switch or some if else to set the different back functionality. So:
int pressed = 0;
Command c = new Command("Back"){
public void actionPerformed(ActionEvent evt) {
super.actionPerformed(evt);
switch(pressed){
case 0:
//Functionality for first case
case 1:
//Functionality for second case
case 2:
//Functionality for third case
}
}
};
form.addCommmand(c);
increment the pressed variable every time you press in the Container. and reset it when its necessary.

Related

Show back button even if no pages are in back stack

I'm making a Master/Details app with Template 10. The Master/Details Template 10 sample uses a CommandBar to get full control over when the back button is shown, but I'd like to show the back button on a PageHeader or on the shell. The problem is, since there is no back stack, the button refuses to be shown. How should I handle this?
Override the OnNavigatedTo event and set AppViewBackButtonVisibility to Visible in the code-behind file for each page that you want to enable the title bar back button.
Take a look here: http://grogansoft.com/blog/?p=1116
The important part is "AppViewBackButtonVisibility"
if (rootFrame.CanGoBack)
{
// Show UI in title bar if opted-in and in-app backstack is not empty.
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Visible;
}
I also suggest you take a look at the AppBar properties.
Especially the Visibility which gets or sets the visibility of a UIElement and you could force the visibility of an item:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.appbar.aspx
So I've created a hacky solution to this. Basically I'm adding a dummy value onto the stack so that the back button thinks there is something to go back to.
var entry = new PageStackEntry(typeof(bool), null, null);
Frame.BackStack.Insert(0, entry);
Then I've added a BootStrapper.BackRequested event which sets HandledEventArgs.Handled to true so Template10 doesnt actually pop the page. That way I've got full control over the back stack and the back visibility.

Messed up BackStage with Universal App (Windows Phone 8.1)

I'm having problems with the Navigation in my windows phone 8.1 part of a universal app I created. I'll try to explain.
I have the following (sorry my spacing/tabbing appears to be messed up below!)
1) Home Page (click on a + on the app bar and it navigates to 2)
->> 2) New Item Page (click on the image preview and it navigates to 3)
->> 3) Capture Page (tap on a button)
->> From Cam button (not implemented)
->> From Photo button
->> 4) Select from album or Take a photo
[- -----Tap Accept and it goes back to New Item (2) and
display the photo as a preview.
But when I click on the back key, it should technically bring me back
to my Home Page(1) but instead it does the following:
First back press: Goes back to Capture Page (3)
Second back press: Goes back to New Item Page (2)
Third back press: Goes back to Home (1)
I'm using the WP File Picker to select a photo, but whether I select
one or press the back key, it goes to my OnActivated event located in
my App.xaml.cs
In the async Method (WPPickedFile) which is called when selecting a
photo or pressing the back key, it checks if args.Files.Count has
returned a photo or not and I've added the following lines of code to
see if it would make a difference:
if (((Frame)Window.Current.Content).BackStackDepth > 2)
((Frame)Window.Current.Content).BackStack.Remove(((Frame)
Window.Current.Content).BackStack[2]);
if (((Frame)Window.Current.Content).BackStackDepth > 1)
((Frame)Window.Current.Content).BackStack.Remove(((Frame)
Window.Current.Content).BackStack[1]);
but it doesn't make one bit of difference. If I press the back key
instead of selecting a photo, my BackStageDepth is 2 and it
contains the Home Page (1) and New Item Page (2). If I select a photo,
it contains these 2 and it also contains the Capture Page (3).
But here is the weird behaviour I don't get. Assume that I press the back
key and did not select a photo. My BackStageDepth is 2 and contains only
the Home Page (1) and the New Item Page (2) so when I get the the lines
described above, it skips the one with > 2 and it removes the New Item
Page (2). When I check it is removed and my BackStageDepth has dropped to 1.
This is not what I want to achieve but I'm trying to understand what's
going on. Anyway, when I continue running the code, I get my New Item Page (2)
displayed and my preview image remains empty since I pressed the back key
on the WP File Picker.
Now the strange is that when I press the back key once again, I put a
break point on the HardwareButtons_BackPressed which is located in
the NavigationHelper but if I check (Frame)
Window.Current.Content).BackStackDepth, it's now telling me that it 2
rather than 1. If I check it, (Frame)Window.Current.Content).BackStack[0]
is still my Home Page (1) but (Frame)Window.Current.Content).BackStack[1]
is now set to the Capture Page (3) which wasn't listed when I checked it
in the method WPPickedFile.
Why is that? I'm totally confused but I can't figure out what I'm doing wrong but it's obviously related to the fact that I'm leaving the app when the WP File Picker is launched as if I don't i.e. go from Home Page(1) to
Capture Page (3) without clicking on the button to launch the WP File Picker,
the navigation works as expected.
Any suggestions would be appreciated
Thanks.
PS: Sorry for the poor formatting but I couldn't fix it!
My backstack wasn't actually messed up. I found out the hard way that windows phone 8.1 could have multiple frames and I totally
In regards to navigating back to the previous page before the one that's calling the FilePicker, I finally figured out a way, which appears to be clean and doesn't call the nagivation and therefore the page to the backstack
#if WINDOWS_PHONE_APP
protected async override void OnActivated(IActivatedEventArgs e)
{
base.OnActivated(e);
continuationManager = new ContinuationManager();
Frame rootFrame = CreateRootFrame();
await RestoreStatusAsync(e.PreviousExecutionState);
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(LocationsPage));
}
var continuationEventArgs = e as IContinuationActivatedEventArgs;
if (continuationEventArgs != null)
{
if (rootFrame.Content is CaptureTypePage)
{
if (rootFrame.CanGoBack)
rootFrame.GoBack();
}
// Call ContinuationManager to handle continuation activation
continuationManager.Continue(continuationEventArgs, rootFrame);
}
Window.Current.Activate();
}
#endif
The important part is:
if (rootFrame.Content is CaptureTypePage)
{
if (rootFrame.CanGoBack)
rootFrame.GoBack();
}
continuationManager.Continue(continuationEventArgs, rootFrame);
By calling the GoBack, it removes the CaptureTypePage and sets the CurrentSourcePageType of the rootFrame to the 'New Item Page' where the preview window is.
I then implemented the interface IFileOpenPickerContinuable on the 'New Item Page' and this is called by the continuationManager.Continue function i.e.
case ActivationKind.PickSaveFileContinuation:
var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable;
if (fileSavePickerPage != null)
{
fileSavePickerPage.ContinueFileSavePicker(args as
FileSavePickerContinuationEventArgs);
}
break;
I hope this helps someone else and won't waste time the way I did! If you have a cleaner way of doing this, please add to this post. I'd love to know.
Thanks.

#SetViewInfo - Issue when clearing filter

I have a problem that have me stumped.
I have been searching for a solution, but haven't found a working one yet. The solutions I seen introduces other issues.
Here is the scenario:
I have a frameset with two frames: 'Navigator' and 'Main'.
In the 'Navigator' frame I display a form called 'Navigator'. It contains an outline, to display a menu.
In the 'Main' frame I display the view selected by the user in the navigator.
So this is a very traditional Notes client application.
I now want to add a checkbox at the top of the view (in the action bar), allowing the user to filter the view by his/her own name. I use #SetViewInfo for this, and it all works perfect.
The issue is when the user switch views. The #SetViewInfo filter stays active when switching to a different view, so after some searching I found some solutions:
In http://www-01.ibm.com/support/docview.wss?uid=swg21204481 IBM suggests to put the following code in the QuerySave event:
#SetViewInfo([SetViewFilter]; temp ; 0 ;1)
When I am switching view or closing the view, I get the error message "Cannot execute the specified command".
In http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/using-setviewinfo-in-a-notes-client-application-to-create-a-user-specific-view Andre Guirard suggests to put the following code in the QuerySave event:
#SetTargetFrame("frameName");
#UpdateFormulaContext;
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "columnName"; 1)
I modify this to match my frame name and the programatic name of the first column in my view:
#SetTargetFrame("Main");
#UpdateFormulaContext;
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "Adjuster"; 1)
This works perfectly when switching between view. But when I close the application while I am in this particular filtered view, the application is re-opened automatically. This happens no matter if the filter is enabled or not when closing the view.
However, when the view repopens, the frameset is not reloaded, it is just the view with the built-in view navigator to the left.
I finally got this to work by (in the built-in view navigator) selecting another view that the one where I filter data. This fixed the issue for a while, but then it starts again, and the filtered view is active in the navigator.
Obviously it is the OpenView command that is causing this, but if I remove just that line, I get the "Cannot execute the specified command" error again.
Any suggestions/pointers? I am using Notes 8.5.3 running on Windows 7 Professional.
This question can also be found in the IBM developerWorks forum for Notes 8.5:
http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllThreadedWeb/08c73910571306c485257b2b0061ef91
First thing, I would suggest to make sure your view frame is always called "NotesView". You will have much less compatibility issues if you do this.
Secondly, I presume when you say you put it in the QuerySave event you really mean the QueryClose event? Views do not have a QuerySave event.
Thirdly, I find the #UpdateFormulaContext line is not needed. This is what I have in my view QueryClose...
#SetTargetFrame("NotesView");
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "<programmaticColumnName>"; 1)
And I can close the app while in the view without any problems.

Watir : How do we capture the subitems displayed by doing mouseover on a particular item

I am trying to work with mouseover on a particular Item in my application by using the following command
{
ie.text_field(:xpath, "//a[contains(text(),'Deal')]").fire_event('onmouseover')
}
On doing mouseover on a item, two subitems are displayed.
Is there any way to capture the sub items which are part of the Item by doing mouseover with which we can report that our test is pass or fail.
Please suggest.
Additional Information :
If we take example,On the StackOver flow page, If i do mouseover on my name, i get a window where i see activity, privileges, Logout and other stuff. This is really what i was looking for. Is there a way to capture the items displayed on the window on doing mouseover.
I also tried to capture the subitems with the following :
{
text=ie.text_field(:xpath, "//a[contains(text(),'Deal')]").fire_event('onmouseover')
puts(text.inspect)
}
On doing this "text" value is displayed as 'nil'.
My general tactic for such things is a combination of using IRB and the IE Developer tool, or Firebug.
using IRB, type out (or cut and paste) the watir statement to fire the onmouseover command to the proper element on the page.
Then have the developer tool rescan the DOM (there's a little refresh icon you can click) The use the tool to point to an element to point to one of the items in the stuff exposed by the onmouseover. Using the info from that, you can then figure out how to address those elements to get the text from the proper div, etc.
If I do that here to the info that opens up when I float the mouse over my name I can find out that it is a table of class "profile-recent-summary" Furthermore I can then look at the way the table is made up and see for example that the 'today' reputation value is in the second cell on that row.. The row also has the text 'reputation' in it.. so
browser.table(:class, 'profile-recent-summary').row(:text, /reputation/).cell(:index, 2).flash
Should flash the cell I want (index might be 1 if using firewatir or webdriver) I can then replace the .flash with something else like .text if I want to get the text from that cell (which is actually inside a link that sits in the cell)..
without seeing your code, I would 'inspect' the element that you are trying to verify and when_present (text) assert that its true

UITabBarController tab to act as a Logout button instead of showing the corresponding view

I have a UITabBarController based iphone application. I added a new tab called Log Out via the Interface Builder.
However I don't need its corresponding view. I want the Log Out tab to redirect to the Login view as soon as it is clicked (of course some session clearing code is executed as well).
The nearest I've got so far is to redirect from the Log Out View using the viewWillAppear. The result is the same but it doesnt look great because it goes into a blank screen for a couple of seconds and then it redirect to the login screen.
Any help would be appreciated.
You can use UITabbarDelegate methods to accomplish this
Use following delegate method to check for logout buttons index and if found then perform your tasks
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if (tabBarController.selectedIndex == 4)
{
// perform logout tasks
}
}

Resources