How to push new screen from global screen in blackberry? - blackberry

Here I am display push notification in globalscreen in blackberry, I need to push screen by clicking OK button of the dialog. I want to start app by clicking the ok button.
Please help me.
Thanks in advance!

I'm not 100% sure I understand what you want, but if this doesn't work, just add a comment and I'll try to give you a better answer.
First, read this on pushing global screens
and this on performing actions after receiving global alerts
Your code, if I'm understanding correctly, should be similar to the second link's example.
Then, if you implement the DialogClosedListener, like in the second link, you might have something like this:
called from the background when you get notified:
Dialog myDialog = new Dialog(Dialog.D_OK_CANCEL, "Hello", Dialog.OK, null, 0);
myDialog.setDialogClosedListener(new MyListener());
UiApplication.getUiApplication().pushGlobalScreen(myDialog, 1, true);
implementation of your dialog listener:
private class MyListener implements DialogClosedListener {
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
// ok clicked
UiApplication.getUiApplication().requestForeground();
break;
case Dialog.CANCEL:
// cancel clicked. or escape pressed
break;
default:
break;
}
}
}
And, then in your UiApplication class, you can respond to activation, which will happen if the user selects Ok from the Dialog:
public class MyApp extends UiApplication {
private boolean _nextScreenShowing = false;
public void activate() {
super.activate();
if (!_nextScreenShowing) {
pushScreen(new NextScreen());
_nextScreenShowing = true;
}
}
}
I show the _nextScreenShowing variable, just to make sure you think about whether pushing the next screen is appropriate. It probably won't be every time activate is called. You may need to keep track of that boolean flag by responding to the Application.deactivate() method, or maybe Screen.onExposed() or Screen.onObscured(). All that depends on how your app works.

Related

Double tap using Appium Java 2.0

I couldn't find an implementation of a double tap for Appium that was straightforward and allowed you to pass in the element locator strategy, so here goes:
public static void doubleTapElementBy(By by) {
WebElement el = getDriver().findElement(by);
MultiTouchAction multiTouch = new MultiTouchAction(getDriver());
TouchAction action0 = new TouchAction(getDriver()).tap(el).waitAction(50).tap(el);
try {
multiTouch.add(action0).perform();
} catch (WebDriverException e) {
logger.info("Unable to do second tap on element, probably because element requieres single tap on this Android version");
}
}
You can also try below approach using tap method in TouchAction class.
TouchAction taction = new TouchAction(driver);
taction.tap(tapOptions().withElement(ElementOption.element(YOUR_WebElement))
.withTapsCount(2)).perform();
You will need to add below static import as well:
import static io.appium.java_client.touch.TapOptions.tapOptions;
This is a workaround in pseudocode and possibly there's a more "official" way to do it, but it should do the work if no other solution is available:
Interpretmessages(){
switch(msg)
{
OnClick:
{ if (lastClicked - thisTime() < 0.2) //if it was clicked very recently
{doubleTapped()} //handle it as a double tap
else{lastClicked = thisTime()} //otherwise keep the time of the tap
} //end of OnClick
} //End of Message Handler
}//End of switch
}//End of messageHandler
If you have access to ready timer functions, you can set a function to be executed 0.2s after the click has gone off:
OnClick: if (!functionWaiting) // has the timer not been set?
{
enableTimer(); // set a function to go off in x time
clicks = 0; //we'll tell it that there's been one click in a couple of lines
} //set it for the first click
clicks++; //if it's already clicked, it'll become 2 (double tap) otherwise it's just one
So, the idea is that when you get a tap, you check if there's been another one recently (a. by checking the relative times, b. by checking if the function is still pending) and you handle it dependingly, only note that you will have to implement a timer so your function fires a bit later so you have time to get a second tap
The style draws upon the Win32's message handling, I'm pretty sure it works there, it should work for you too.
Double tap and hold -- Use below code:
new TouchAction(driver).press(112,567).release().perform().press(112,567).perform();
Double tap -- Use below code:
new TouchAction(driver).press(112,567).release().perform().press(112,567).release().perform();

How to customize the Device charm bar using C#/XAML in windows 8?

I have an requirement that, need to customize the Device charm bar in windows 8?
I need to add a button or any other control in Device charm bar.
Is it possible?
If yes, how can we customize it?
Thanks in advance.
You can certainly add commands to Device's charms bar like this:
I assume you want to add to Settings Charms bar.
Create a Class example AppSettings
public AppSetting()
{
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
SizeChanged += AppSettingSizeChanged;
}
private void OnCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
{
eventArgs.Request.ApplicationCommands.Clear();
UICommandInvokedHandler handler = new UICommandInvokedHandler(OnSettingsCommand);
// Some command
SettingsCommand someCommand = new SettingsCommand("uniqueID", "NameofLabel", handler);
eventArgs.Request.ApplicationCommands.Add(someCommand);
}
private void OnSettingsCommand(IUICommand command)
{
Logger.Log("Called");
SettingsCommand settingsCommand = (SettingsCommand)command;
string id = settingsCommand.Id as string;
switch (id)
{
case someID:
{
ShowSomeUI();
} break;
case otherID:
{
ShowSomeOtherUI();
} break;
}
}
protected void ShowSomeUI()
{
//Implement anything you want here
}
Use the above class and make the very first class of your Application inherit from this class so that the commands are added to charms bar and implement anything on their clicks.
P.S let me know if this is not clear or doesnt answer your question.

After clicking a button, how do I wait for SwingWorker to finish before proceeding?

I have the following code:
public class FileLoader extends SwingWorker(Void, Void) {
#Override
private Void doInBackground() {
loadFiles();
}
}
public class LogInPage {
private FileLoader fileLoader = new FileLoader();
public LogInPage() {
fileLoader.execute();
}
loginButtonActionPerformed(ActionEvent evt) {
//wait for files to finish loading
//while displaying a waiting cursor
showMainForm();
}
}
My question would be:
After clicking the button, I would want all the files to be loaded first (while displaying an hourglass cursor and progress bar) before showing the main form.
I have done this before with Thread's join() but was not able to do the same with SwingWorker.
I have read about overriding done() and implementing listeners but I can't apply it here.
Any help?
Thanks.
From what you're saying and contrary to what you think, I think you can actually use SwingWorker's done() method. Before execute(), disable the button, start a busy animation, whatever, then in the done() method, do whatever it is you need to do to continue the program. That's what it's for :-)
You should also look at the SwingWorker.publish() and process() to send and receive the progress bar events.
See also: How do I wait for a SwingWorker's doInBackground() method?

CheckboxField checked in Blackberry

How will i be able to recognise a check on the Checkboxfield.
Like if a user checks on a check box, a notification is generated.
BR,
Suppi
CheckBoxField class inherited from Field class, which means you should be able to create an action listener.
Use setActionListener method and override the fieldChanged method to do whatever you want.
checkBox.setChangeListener(new FieldChangeListener() {
public void fieldChanged(...params ... ) {
//your code
}
});

BlackBerry java detecting screen foreground event

In my BlackBerry application, I have a home screen. The user can then navigate to a settings screen. When the user goes back to the home screen, is there no method that is called on the home screen indicating that the screen has come to the foreground?
I have tried onFocus() with no avail.
Thanks!
Unfortunately, hooking on the onExposed is not enough. I found that in Blackberry dialogs are also screens and even context menus are screens too. They are pushed on top of your screen so you receive onExposed callback when they are dismissed.
Though it's OK in many cases, in other cases it poses a problem - e.g. if I must refresh the screen's content only when the user returns to it, but not after menus/dialogs, then how do I do that? My case is, unfortunately, one of those.
I found no documented way of detecting "covered"/"uncovered" events. Here is my approach. onCovered/onUncovered callbacks are called when the current screen is covered/uncovered by another screen of the app, but not by dialogs/menus/virtual keyboard:
public class MyAppScreen extends MainScreen {
private boolean isCovered;
protected void onExposed() {
Log.d("onExposed");
super.onExposed();
if (isCovered) {
onUncovered();
isCovered = false;
}
}
protected void onObscured() {
Log.d("onObscured");
super.onObscured();
final Screen above = getScreenAbove();
if (above != null) {
if (isMyAppScreen(above)) {
isCovered = true;
onCovered();
}
}
}
private boolean isMyAppScreen(final Screen above) {
return (above instanceof MyAppScreen);
}
protected void onUncovered() {
Log.d("onUncovered");
}
protected void onCovered() {
Log.d("onCovered");
}
protected void onUiEngineAttached(final boolean attached) {
if (attached) {
Log.d("UI Engine ATTACHED");
} else {
Log.d("UI Engine DETACHED");
}
super.onUiEngineAttached(attached);
}
protected void onFocusNotify(final boolean focus) {
if(focus){
Log.d("focus GAINED");
} else {
Log.d("focus LOST");
}
super.onFocusNotify(focus);
}
}
And a test. Try various combinations and see what events you receive in the log.
public class TestLifecycle extends MyAppScreen implements FieldChangeListener {
private final ABNTextEdit txt1;
private final ButtonField btn1;
private final ButtonField btn2;
public TestLifecycle() {
final Manager manager = getMainManager();
txt1 = new ABNTextEdit();
manager.add(txt1);
btn1 = new ButtonField("Dialog", ButtonField.CONSUME_CLICK);
btn1.setChangeListener(this);
manager.add(btn1);
btn2 = new ButtonField("Screen", ButtonField.CONSUME_CLICK);
btn2.setChangeListener(this);
manager.add(btn2);
}
public void fieldChanged(final Field field, final int context) {
if (field == btn1) {
Dialog.alert("Example alert");
} else if (field == btn2) {
UiApplication.getUiApplication().pushScreen(new TestLifecycle());
}
}
}
Update:
This method has a limitation: if a new screen is pushed when a dialog or the soft keyboard has focus your current screen will not receive onCovered/onUncovered notification.
Example A: if you have an input field of fixed size and you push a new screen when the user completes it, your current screen will not receive the notification if the user types very quickly. This happens because in the moment between you call push(newScreen) and it is actually pushed the user clicks on a letter on soft KB and it grabs the focus. So only onObscured is called, but not onCovered.
Solution: explicitly hide the soft keyboard before the push(newScreen).
Example B: if you have a customized dialog which pushes new screen and then dismisses itself, your current screen will not receive the notification. This happens because your customized dialog is not recognized as a screen, so only onObscured is called, but not onCovered.
Solution: dismiss the dialog in the first place returning a result value, and let your screen push the new screen based on that value. -OR- override isMyAppScreen() to return true also for your customized dialog.
You should be able to use protected void onExposed() to detect when it is displayed again.

Resources