ionic keyboard go button to next button - android

Reference:Change go button to next button in android
I am developing an application with sign up page using Ionic framework.
Is there any option to replace go button with next button? I want to move cursor from one field to another using next button in the keyboard.

you can use following reference to achieve your requirement in ionic.Below code is for cordova
(function($) {
$.fn.enterAsTab = function(options) {
var settings = $.extend({
'allowSubmit': false
}, options);
this.find('input, select, textarea, button').live("keypress", {localSettings: settings}, function(event) {
if (settings.allowSubmit) {
var type = $(this).attr("type");
if (type == "submit") {
return true;
}
}
if (event.keyCode == 13) {
var inputs = $(this).parents("form").eq(0).find(":input:visible:not(disabled):not([readonly])");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
idx = -1;
} else {
inputs[idx + 1].focus(); // handles submit buttons
}
try {
inputs[idx + 1].select();
}
catch (err) {
// handle objects not offering select
}
return false;
}
});
return this;
};
})(jQuery);
For adding next button , you can refer following link:
How to add Next button in Ionic soft keyboard plugin

Related

Unity GameObject "flash" after SetActive on Android Project

I have a project that use Android to display Unity Player. So I export Untiy project as Android module which implemented by Android Application.
I create buttons in Android Activity which contains UnityPlayer, And when I click button, it send a message to Unity Player to invoke C# function, just like this:
findViewById(R.id.btnChange).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mUnityPlayer.UnitySendMessage("ScriptHolder", "ChangeSkin", "");
}
});
And the function named "ChangeSkin" is just to change some GameObjects' active. Just like this:
void ChangeSkin()
{
int prefab;
if (_currentPrefab == PREFAB_DEFAULT)
{
prefab = PREFAB_PRINCESS;
}
else
{
prefab = PREFAB_DEFAULT;
}
ShowSkin(prefab);
}
private void ShowSkin(int prefab)
{
_currentPrefab = prefab;
foreach (var item in _defaultDressList)
{
item.SetActive(prefab == PREFAB_DEFAULT);
}
foreach (var item in _princessDressList)
{
item.SetActive(prefab == PREFAB_PRINCESS);
}
}
And something weird happening: when I click button to change the person's cloth in Unity, the GameObjects which called SetActive(true) show at the position above the right position for a frame and become normal, it looks like they flash. Here is the gif of the project demo:
It looks like the position offset is equal to the height of status bar. If I create a button on Unity Scene and call "ChangeSkin" function, everything will be OK.
I tried all I can to fix this but not succeed. So I hope you will help me, thx.
You should check your Unity layout. If you have a layout group that has content size fitter component, and the child objects also have it (content size fitter), this could cause these glitches.
I fixed this problem by using a flag (or trigger). Just like this:
// set value true to trigger ChangeSkin() in Update(),
// instead of invoke ChangeSkin() directly
private bool _changingSkinTrigger = false;
void ChangeSkin()
{
if (_currentPrefab == PREFAB_DEFAULT)
{
_currentPrefab = PREFAB_PRINCESS;
}
else
{
_currentPrefab = PREFAB_DEFAULT;
}
_changingSkinTrigger = true;
}
void Update()
{
if (_changingSkinTrigger)
{
_changingSkinTrigger = false;
ShowSkin();
}
}
private void ShowSkin()
{
foreach (var item in _defaultDressList)
{
item.SetActive(_currentPrefab == PREFAB_DEFAULT);
}
foreach (var item in _princessDressList)
{
item.SetActive(_currentPrefab == PREFAB_PRINCESS);
}
}
Thank #AndriyMarshalek for enlightening me.

Android WebView : Navigate to Url Hash without reloading using goBackOrForward

I want to navigate Angular single page application without reloading the webpage. On button click I'm calling following code to navigate.
String fullUrl = "https://example.com/page1";
String hashUrl = "/page1";
public void goBackInWebView(String fullUrl, String hashUrl) {
WebBackForwardList history = webview.copyBackForwardList();
int index;
int currentIndex = history.getCurrentIndex();
for (int i = 0; i < history.getSize(); i++) {
index = i - currentIndex;
if ((webview.canGoBackOrForward(1 + i)) || (webview.canGoBackOrForward(1 - i))) {
if (history.getItemAtIndex(i).getUrl().endsWith(hashUrl)) {
webview.goBackOrForward(index);
break;
} else if (i == history.getSize()) {
webview.loadUrl(fullUrl);
break;
}
} else {
//OUTER ELSE
webview.loadUrl(fullUrl);
break;
}
}
}
If the webpage is not saved in the history it will call webview.loadUrl(fullUrl); else it will load the page using webview.goBackOrForward(index);.
but is above code everytime OUTER ELSE is callling.
First of all canGoBackOrForward is used for Getting whether the page can go back or forward the given number of steps. as you mentioned in question your web page is single page so you don't need call this method. I think bellow code can solve your problem.
public void goBackInWebView(String fullUrl, String hashUrl) {
WebBackForwardList history = webview.copyBackForwardList();
if (history.getSize() == 0) {
webview.loadUrl(fullUrl);
}else {
for (int i = 0; i < history.getSize(); i++) {
if (history.getItemAtIndex(i).getUrl().endsWith(hashUrl)) {
webview.goBackOrForward(i);
break;
} else {
webview.loadUrl(fullUrl);
}
}
}
}
I find it difficult to see much relation to Android and WebView, because the problem is SPA.
Better use hashtag # navigation for SPA, because this won't request anything server-side.
The point simply is, that the back button does not matter the least, while never navigating.
One just needs to bind JavaScript, which runs whenever window.location.hash changes.

Nativescript - Keep keyboard open when TextField returned on Android

How can I keep the keyboard open after the user tap on the "Return" key on the soft keyboard?
I'm calling the focus method on "returnPress" event, which works fine on IOS but not on android:
text() {
let textFieldElement = <TextField>this.textField.nativeElement;
textFieldElement.focus();
}
So turns out I need to overrde "onEditorAction" method on the "OnEditorActionListener" like this:
let tv = <TextField>this.textField.nativeElement;
if (tv.android) {
tv.android.setOnEditorActionListener(new android.widget.TextView.OnEditorActionListener({
onEditorAction: function (callbackType, result) {
if (result == android.view.inputmethod.EditorInfo.IME_ACTION_DONE) {
// do whatever you want when user presses return
}
return true;
}
}));
}

Apply code to a gameObject with EventTrigger

I have a button for which i'd like to signify "attacking". I'm programming for android.
Basically i'd like to run this script, upon the touch of the attack button. Instead of using the F key to stop the code from rapidly repeating, i'm trying to figure out how to run an if statement for "if button is touched & !isAttacking" then go into the method.
if (Input.GetKeyDown(KeyCode.F) && !isAttacking)
{
isAttacking = true;
attackTimer = attackCD;
Debug.Log("F Pressed");
attackTrigger.enabled = true;
}
if (isAttacking)
{
if (attackTimer > 0)
{
attackTimer -= Time.deltaTime;
}
else
{
isAttacking = false;
attackTrigger.enabled = false;
}
}
I'm using Unity 5!

Back Button Issue in Android Webview

THe problem is little difficult to convey, The Actual scenario will be help you guys to understand the real problem.
In the Android Application.
I have a lot of the Jquery Mobile Page append to the android Webview.
When i select one Page (E.g) Profile , the page opens properly and if i press the back button, the application moves to the main page, if i again select profile and press back the application goes to the login page.
if i select some other page and select the profile this is not happening. this issue is not only with the single page. in all the page i have the same issue. Can some one guide me what should i have do?
The Source code of the Key Press event,
enter code here
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && webview.isEnabled()
&& !this.onLogin) {
webview.loadUrl("javascript:handleDeviceBack()");
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK && this.onLogin) {
moveTaskToBack(true);
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
webview.loadUrl("javascript:handleDeviceHome()");
return true;
}
return false;
}
In my web view,
enter code here
handleDeviceBack = function(status) {
mHealth.util.logMessage('On device Back');
var historyBack = {
"home" : "page",
"loginPage" : "page",
"welcomeMsg" : "page"
};
var moduleIndex = {
"assessNotFound" : "../../home/view/home.html",
"showActivity" : "../../home/view/home.html",
"showMessage" : "../../home/view/home.html",
"show_tracker" : "../../home/view/home.html",
"settingsPage" : "../../home/view/home.html"
};
var graphPages = {
"singlehealthdatapage" : "page",
"multiplehealthdatapage" : "page"
};
var otherShortcuts = {
"show_tracker_view" : "../../trackers/view/showtracker.html",
"detailMessage" : "../../messages/view/showmessage.html",
"alfrescoDIV" : "../../messages/view/showmessage.html"
};
// var exitAppCriteria={ "home" : "page","loginPage" : "page","welcomeMsg" :
// "page"};
if($('.ui-page-active').attr('id')=="condition_index")
{
$.mobile.changePage("../../home/view/history.html");
}
else if (historyBack[$('.ui-page-active').attr('id')]
|| $('body').children().is('#tandcPage')) {
Android.finishActivity();
} else if (moduleIndex[$('.ui-page-active').attr('id')]) {
Android.highlightHome();
$('.ui-alert-wallpaper').detach();
$.mobile.changePage(moduleIndex[$('.ui-page-active').attr('id')]);
} else if (graphPages[$('.ui-page-active').attr('id')]) {
Android.showTab();
Android.pageHistory();
} else if (otherShortcuts[$('.ui-page-active').attr('id')]) {
$.mobile.changePage(otherShortcuts[$('.ui-page-active').attr('id')]);
} else {
$('.dw').detach();
$('.dwo').detach();
$('.dw').detach();
$('.ui-alert-wallpaper').detach();
Android.showTab();
Android.pageHistory();
}
};
I found the problem is with the Android.pageHistory();
enter code here
public void pageHistory() {
this.activity.runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
WebContainerActivity.webview.goBack();
}
});
}
Where First time its running properly but if the function called repeatly the web view.go back to the first page.
In your activity override backpressed method like this
#Override
public void onBackPressed() {
webview.loadUrl(sameurl);
}
Hard coded the URL by their ID and solved the issue temporarily.

Categories

Resources