Ionic Background to Foreground using Local Notification - angularjs

First sorry for my bad English.
I'm new on Ionic and I'm trying to pass my app from background to foreground when local notification trigger. I'm using the Katzer API (https://github.com/katzer/cordova-plugin-local-notifications), and I want to show a view (skype style incoming call) for stop or postpone a notification. This example works ok, but I need a method or something in order to show the postpone screen even when the screen is locked.
cordova.plugins.notification.local.on('trigger', function (notification) {
alert("triggered");
}
Thanks in advance.

After more deeper researching I managed to do it, so I'll answer to myself and leave it here for anybody who needs it.
If you want to show your application in foreground when the notification is triggered you should modify the AbstractTriggerReceiver.java
I added this method in AbstractTriggerReceiver.java:
public void launchApp() {
Context context = getContextForApp();
String pkgName = context.getPackageName();
Intent intent = context
.getPackageManager()
.getLaunchIntentForPackage(pkgName);
intent.addFlags(
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
So in your TriggerReceiver.java you can call launchApp(); in your onTrigger() method.

There isn't an easy solution for this, since you need to work mainly in the native layer.
E.g. In Android you should create an activity visible over the default lock screen, show it when the notification is triggered and start the Cordova activity on a button click.

Related

Extjs widget Column with widget as button

I have a situation where I need to disable the button(added as widget for widget column) when I receive one web socket event. When receiving the web socket I might be in any page. So how to get the reference of that button widget and disable it.
I have created a fiddle WidgetTestFiddle
Can anyone please help.
Thanks in advance
You could use the Ext.ComponentQuery.
Using the query method you can search for the buttons inside your grid.
You probably want to give your buttons an itemId (e.g. itemId: 'widgetcolumn-button-switch') to ensure that you only find the buttons you want.
Using the itemId your search query would look like this: 'button[itemId="widgetcolumn-button-switch"]'
I forked your fiddle and created my own version to illustrate my point: Sencha fiddle example
I think there are several ways to achieve your wanted result.
KaMuns answer will work, but can be tricky in case you use a buffered store / grid. Because the pages in this case are handled internally by the store. Using a static itemId wont work in this case out of the box.
I would suggest you rely on the record data.
Everytime you recieve a websocket message, update the store and refresh the grid view can be an option.
I have modified your fiddle here:
https://fiddle.sencha.com/#view/editor&fiddle/3a87
Here are is the most relevant part:
var grid = btn.up('grid');
var models = grid.getStore().getData().getRange(); // of cause you can use find or another way here
var model = models.filter(mod => mod.get('actualRole') === 'Follower');
model[0].set('showBtn', false);
grid.getView().refresh(); // get ref to view and refresh because data changed
On top you can have a look on the defaultBindProperties and may change this to the hidden key of the button.

CodenameOne Navigating from Splash Screen to "first time use" form in UIBuilder app

I have a tricky situation that only appears in mobile devices, not the simulator, so I need some expert help to troubleshoot. It's like the stateMachine takes me back to the SplashScreen briefly (or does some strange back-transition) after displaying my "FirstTimeSetup" form.
Here's my setup: I used the GUIBuilder to build the app with a form SplashScreen that will show first and then auto-transition to a form Main after some network connections happen in processBackground.
That works fine but on the First time starting, (when a Preference is not set) I want to display a different form: FirstTimeSetup. The best way I could see to do this was the following:
1) in processBackground, immediately return false if it's the first time running so that it doesn't transition to Main.
protected boolean processBackground(Form f) {
if ("SplashScreen".equals(f.getName())) {
if (Preferences.get(PREFS_FIRST_TIME_SETUP,true)){
//return false to indicate that we should not proceed to next_form specified in property
//we do this because postSplashScreen will trigger the load of the "FirstTimeSetup" form
return false;
}
//...continue with normal app initialization if this is not the first time
2) In postSplashScreen, I again check if it's a first-time load and then disable back-commands and call showForm to the First Time Setup form.
#Override
protected void postSplashScreen(Form f) {
if (Preferences.get(PREFS_FIRST_TIME_SETUP, true)) {
//disable back command for this form
setBackCommandEnabled(false);
showForm("FirstTimeSetup", null);
}
}
3) in postFirstTimeSetup method, I display some dialogs to explain the next steps to the user, do some network checks to ensure we can proceed with registration, and then end the method so the user can interact with the dialog and register. It's at this point when on the iOS or Android Device, I see a slide transition to the SplashScreen and then immediately it re-displays the FirstTimeSetup form, and it does this twice before the user is able to interact with the form.
4) Sometimes (it's inconsistent), the postFirstTimeSetup method will execute again (the same dialog boxes prompting the user are displayed again!).
It feels like some SplashScreen automatic transition is still trying to execute after I've returned false from processBackground and the postSplashScreen method is already complete... any suggestions would be helpful to eliminate this strange double-transition!
UPDATE:
With further tweaking and Investigating I realized that this appears to be caused by Android Permissions dialogs which is why it only happens on initially installing the app.
In processBackground, I make the first network calls (prompting network usage permission dialog) and access the device parameters IMEI And UUID to get a device identifier (prompting the "allow access to Phone" permission). After dismissing each dialog, the SplashScreen form appears to be re-entered causing a re-display of the form with transition animation (and I think also re-running the processBackground! re-doing all my splash screen initialization work!).
So here's the updated question: How can I get the Android Permissions dialogs to stop the SpashScreen from reloading?
I've tried moving the commands that trigger out to initVars, but then I get the permissions dialogs on a Blank screen, and then the splash screen just transitions twice rapidly like I shared in this video: youtu.be/2QpdaeigNZ8
I've tried wrapping the two "triggers" (commands that cause the permissions) in a callSerially() so that it would delay the dialogs until the SplashScreen form is at least displayed, but then the form displays, and a permission dialog shows, I click "allow" and then the splashScreen Form display again, then the second permission dialog pops up. I clock allow and then AGAIN a re-display of splashScreen.
The solution is to perform your logic in processBackground() and get rid of postSplashScreen, then return false at the end of this method.
#Override
protected boolean processBackground(final Form f) {
if ("SplashScreen".equalsIgnoreCase(f.getName())) {
new UITimer(() -> {
if (Preferences.get(PREFS_FIRST_TIME_SETUP, true)) {
showForm("FirstTimeSetup", null);
} else {
showForm("Main", null);// or any other form you want to show
}
}).schedule(3000, false, f); //wait 3 seconds before proceeding
}
return false; //always return false at the end
}
Then in your FirstTimeSetup form's postShow() (i.e. postFirstTimeSetup() method), remember to set PREFS_FIRST_TIME_SETUP to false.
Preferences.set(PREFS_FIRST_TIME_SETUP, false);

Angular Material: Update Text Content in Toast

I am attempting to use $mdToast.updateTextContent() to update a toast and am unsuccessful. The docs don't go into detail on how to call it with a new message. My desire result would have the first toast display 'Adding account' then change to 'account successfully added'. Any help would be greatly appreciated.
I think the correct way to approach this using material design standards would be to only use the toast once the account has been added. The loading could be a spinner or maybe a loading bar (maybe like this http://materializecss.com/preloader.html)
Once the $mdToast is open, you're able to call updateTextContent (as you stated)
$scope.onAccountAdded = function() {
$mdToast.updateTextContent('Account successfully added')
};
We're watching the variable for changes and update the view automatically, once the value has changed.
https://github.com/angular/material/blob/master/src/components/toast/toast.js#L299
Here is a demo, which shows how it works.
http://codepen.io/DevVersion/pen/qNWewJ

angular with firebase event handling

Im making a poll app where people can create a new poll (question and responses) then that gets pushed to my firebase database and the questions get populated as a list in the left side bar. I got that far and it works great.
Now i'm trying to make the take a poll feature so when a person clicks on the question they want to respond to, it updates the view for just that one question and ng-repeat for the number of responses there are.
Is there a firebase event handling similar to jquerys on click for .this to do this? How can I accomplish this, I feel stuck.
So I figured it out. For the nav bar on the left in my anchor tag within a ng repeat. I used a ng-click = "select(poll)" where poll being the ng-repeat = poll in polls
then in my controller I have this simple function
$scope.select = function(poll){
$scope.selected = poll;
};
which then in my takeApollview (i'm using ui-router) I just use the selected to display all the key values.
Msg me if anyone has a similar problem and needs guidance.

Show custom pop up warning message when user changes any value (text box/LOV) on page

I have requirement to show custom pop up warning message when user changes any value (text box/LOV) on page and close tab/cancel button by mistake.
Option I tried are:
a) Within application we are using a complex task flow/RegionModel for 7 different scenario's. Also requirement is to display custom message - Hence could not use approach "unsaveddatawarning"
http://www.oracle.com/technetwork/developer-tools/adf/unsaveddatawarning-100139.html
b) Second option I tried was to have custom region controller:
CustomRegionController implements RegionController
Inside validateRegion(RegionContext regionContext) thought to find if page data is dirty
AdfFacesContext.getCurrentInstance().getDirtyPageHandler().isDataDirty();
or
DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCDataControl cDataControl = dcBindings.getDataControl();
boolean dirtyFlag = cDataControl.isTransactionModified();
In both scenario it always gives true (seems due to common set of VO/View Link application module always gets dirty when data is being rendered on page load).
Last option I am left with is to invoke valueChangeListener for each element (textbaox, LOV, Check box). I do not like this option at all. Please suggest if there can be better way to handle this scenario.
Why is using a value change listener a problem? Have each input component call the same VCL method in the backing bean. If necessary you can get the component id from the vcl event object.

Resources