Setup SoftKeyBoard Cordova Plugin - android

I would like to hide the softkeyboard onBlur.
Therefore, I found the softkeyboard plugin, and I suppose I installed it properly, following numerous threads posts.
However, this is the first time I use a plugin for cordova, and I get this error, so I guess something is missing:
Cannot read property 'SoftKeyBoard' of undefined
This refers to the js call in the html file:
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
Does not window.cordova.plugins exist?
In order to set up the plugin, I did the following:
copy SoftKeyBoard.java to src/org.apache.cordova.plugins.SoftKeyBoard. I also rewrote the first line package accordingly.
copy the js file, and link it to the html file
add this line to res/xml/config.xml:
<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
In this XML, it's located in <cordova><plugins>
Is there anything else I should have done?

Related

Nativescript and FontAwesome

I am trying to use icon font FontAwesome in Nativescript application, which is possible according to this article https://www.nativescript.org/blog/mobile-app-best-practices---use-font-instead-of-image-to-show-an-icon
I did everything that is described in that article:
Added .ttf in app/fonts
Added class in app.css
.fa{
font-family: "FontAwesome";
}
Used it in XML like so
text="" class="fa"
But result is rather disappointing:
I also tried the "\uf230" syntax, but that renders as plain text.
What am I doing wrong?
Could be a few things. Does it work on iOS? As your CSS definition is iOS compatible, not Android as Android needs the actual filename (without extension) whereas iOS needs the font name. So I have this to be xplatform-ready (the file is 'fontawesome-webfont.ttf'):
.fa {
font-family: 'FontAwesome', fontawesome-webfont;
}
The \f005 syntax is OK (<Label class="fa" [text]="'\uf005'"></Label>), but I'm using the splendid nativescript-ngx-fonticon plugin (there's also a non-Angular one) to be able to do this instead:
<Label class="fa" [text]="'fa-shopping-basket' | fonticon"></Label>
To make it work, you must make sure that the "fonts" directory is inside the "app" folder and that the following files exist:
font-awesome.eot
font-awesome.ttf
I opted to adopt this font as the default of my application, so I do not have to worry about where I'm going to use it and how much to enter the right class, everything is getting very good and the result is perfect.
In CSS, you only have to define a selector according to your interest for the source to be used, so just use the directive:
page {
font-family: 'FontAwesome'
}
Then where you want an icon, just use an html entity that represents it as it searches the site: http://fontawesome.io/icons/
See images:
You can see this video where I was based to start. It corrects in the video the extension used to be attentive.

Unable to manipulate DOM content of Ionic Android app

angular.module("app.categories").controller("CategoryController", t), t.$inject = ["$scope", "$stateParams", "$state", "categoryManager"]
angular.module("app", ["ionic", ["app.home","app.products",...]);
angular.module("app").run(["$templateCache", function(t) {
t.put("app/scripts/about/about.html", '<ion- view>.....'),t.put("app/scripts/home/block.html", '<div>....')}]); //this is how the page content is loaded
I am running this app in the browser using Ionic ('Ionic serve' in the root directory). I am not able to run basic JavaScript on the page who's content has been loaded like this. After a timeout if DOMContentLoaded is called, the element is picked up but running the following only manipulated the id of element, not the html or the value
setTimeout(function(){
document.addEventListener('DOMContentLoaded',function(){
document.getElementById('customBox').id = 'changed'; //to test, id changes
document.getElementById('customBox').innerHtml = '<h1> test </h1>'; //does not change anything, no errors in console
document.getElementById('customBox').text= '<h1> test </h1>'; //does not change anything, no errors in console
document.getElementById('customBox').html= '<h1> test </h1>'; //does not change anything, no errors in console
});
},2000);
Is there anything that's preventing any change to the page content in the browser? How to make changes in the DOM content using simple JavaScript for this Ionic Android app?
Don't try to manipulate the html of an angular app directly unless you have written a custom directive. If you want to change the innerHtml use ng-bind-html on the div and just modify your scope.
Also, don't use setTimeout in an angular app, always use the $timeout or $interval services instead.
So your code, somewhere inside a controller, should just look like this:
$scope.testContent = '<h1> tet </h1>';
and the html:
<div id='customBox' ng-bind-html="testContent"></div>
Although the main reason your code doesn't work is that as soon as you've changed the id to "changed" all the other getElementById calls won't find the div.
Try using angular.element like this
angular.element( document.getElementById('customBox') ).innerHtml = '<h1> test </h1>';
Visit this link for detail https://docs.angularjs.org/api/ng/function/angular.element

Can't use relative paths in object tags in Cordova/Phonegap?

I noticed that I can't use relative paths in my Cordova project when referencing them in object tags. For example, this works on the browser but not in Phonegap:
<object id="pause" type="image/svg+xml" data="img/icons/pause.svg" class="icon clickable hidden"></object>
However, this functions perfectly fine in both Phonegap and the browser:
<img id="pause" src="img/icons/pause.svg">
Using a remote path also works in Cordova, but everything falls apart when I use a local/relative one. Here's what Android spits back:
<img src="file:///android_asset/webkit/android-weberror.png" align="top">
<h2>Webpage not available</h2>
<p>The webpage at file:///android_asset/www/img/logo.svg could not be loaded because:</p>
<!-- The net::ERR_FILE_NOT_FOUND is replaced by a localized error string -->
<p>net::ERR_FILE_NOT_FOUND</p>
Unfortunately, I can't use a remote location (since that won't let me execute the onclick and onmousedown events inside the SVGs). Also, avoiding <object> tags altogether is not an option, since I need to execute and change some of the code inside the objects (like changing the fill color).
Is this a bug? If not, what can I do to get my code to work?
A jacky workaround to this is reading the file manually using Javascript and putting the contents directly into the data attribute so that it reads <object data="data:image/svg+xml;utf8,[FILECONTENTS]"></object>. It's not elegant, but it works fine.

android phonegap/cordova change property on webview

In the past, I have changed a normal Webview property on Android. For example:
wv.getSettings().setAllowUniversalAccessFromFileURLs(true);
where wv is a variable of webview. Now, I have an phonegap/cordova app, and I want to change
the same line of code, I have been trying the the following way:
super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
and also like:
super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
I don't get any compiling errors, but when I add that line of code on the onCreate method, the app just closes. I have been trying to add the line on the onCreate method at different places, like, before and after the super.onCreate and before and after loading the html (super.loadUrl("file:///android_asset/www/index.html"), but the app always closes. Any of you know if it is possible to change that property on phonegap/cordova ?
That code is already in our web view so you don't need to set it. Probably the reason it is crashing is that you are not running on an ICS device. That method is only available in ICS or better.
If you really want to add it do:
if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}

How do you hide notification/title bar in an AS3/Air Android App?

I'm using FlashDevelop to create a simple Adobe AS3/Air game for Android and can't figure out how to hide the notification bar. I'm sure it's something easy that I'm missing.
In the application xml file, you need to set the <fullScreen> xml element to true:
<application>
...
<initialWindow>
...
<fullScreen>true</fullScreen>
...
</initialWindow>
...
</application>
Follow these simple steps and get hide notification bar
Modify main Windowed Application tag as below:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" showNotificationbar="false" showTitleBar="false">
Open AIR application’s configuration xml file that gets generated automatically while creating new application.
uncomment this line. Change should look like below:
<systemChrome></systemChrome>
Modify the above mentioned line to match the following:
<systemChrome>none</systemChrome>
That's it….
If you are using starling, you can also call this during runtime:
Starling.current.nativeStage.displayState = StageDisplayState.FULL_SCREEN;
In starling, when you lose application context (e.g. while using CameraRoll), status bar may be shown even if you have following lines in your app-description xml:
<fullScreen>true</fullScreen>
<systemChrome>none</systemChrome>
Solution of this, is to call same line again after losing context:
Starling.current.nativeStage.displayState = StageDisplayState.FULL_SCREEN;
Hope it helps.

Categories

Resources