Skip to content

Commit

Permalink
Merge pull request #78 from simonfriesenbichler/master
Browse files Browse the repository at this point in the history
cordova 5 fixes
  • Loading branch information
simonfriesenbichler committed May 6, 2015
2 parents e42a9c9 + 154cd02 commit a5f0573
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion plugin.xml
Expand Up @@ -138,7 +138,6 @@
<feature name="WikitudePlugin">
<param name="ios-package" value="WTWikitudePlugin"/>
</feature>
<access origin="*" />
</config-file>


Expand Down
29 changes: 14 additions & 15 deletions src/android/WikitudePlugin.java
Expand Up @@ -662,9 +662,9 @@ private void addArchitectView( final String apiKey, String filePath, int feature
if ( this.architectView == null ) {

WikitudePlugin.releaseFocusInCordovaWebView(cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content));

this.architectView = new ArchitectViewPhoneGap( this.cordova.getActivity() , new OnKeyUpDownListener() {

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (architectView!=null && keyCode == KeyEvent.KEYCODE_BACK) {
Expand All @@ -673,11 +673,12 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
}
removeArchitectView();
return true;

} else {
return false;
}
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return architectView!=null && keyCode == KeyEvent.KEYCODE_BACK;
Expand Down Expand Up @@ -735,25 +736,25 @@ public void onLocationChanged( final Location location ) {

/* also a fake-life-cycle call (the last one before it is really shown in UI */
this.architectView.onResume();

if ((features & StartupConfiguration.Features.Geo) == features) {
this.locationProvider = new LocationProvider( this.cordova.getActivity(), this.locationListener );
this.locationProvider.onResume();
}
}

// hide keyboard when adding AR view on top of views
InputMethodManager inputManager = (InputMethodManager)
(this.cordova.getActivity()).getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow((this.cordova.getActivity()).getCurrentFocus().getWindowToken(),
InputMethodManager inputManager = (InputMethodManager)
(this.cordova.getActivity()).getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow((this.cordova.getActivity()).getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}


private static void releaseFocusInCordovaWebView(View rootView) {
if (rootView instanceof CordovaWebView) {
((CordovaWebView)rootView).clearFocus();
}
else if (rootView instanceof ViewGroup) {
if (rootView instanceof CordovaWebView) {
((CordovaWebView)rootView).getView().clearFocus();
} else if (rootView instanceof ViewGroup) {
final int childCount = ((ViewGroup)rootView).getChildCount();
for (int i=0; i< childCount; i++) {
WikitudePlugin.releaseFocusInCordovaWebView(((ViewGroup)rootView).getChildAt(i));
Expand All @@ -767,9 +768,7 @@ else if (rootView instanceof ViewGroup) {
*/
private static void handleResumeInCordovaWebView(final View rootView) {
if (rootView instanceof CordovaWebView) {
((CordovaWebView)rootView).handleResume(true, true);
((CordovaWebView)rootView).clearFocus();
((CordovaWebView)rootView).requestFocus();
((CordovaWebView)rootView).handleResume(true);
}
else if (rootView instanceof ViewGroup) {
final int childCount = ((ViewGroup)rootView).getChildCount();
Expand All @@ -780,7 +779,7 @@ else if (rootView instanceof ViewGroup) {
}


protected static class ArchitectViewPhoneGap extends ArchitectView{
protected static class ArchitectViewPhoneGap extends ArchitectView {
public static interface OnKeyUpDownListener {
public boolean onKeyDown(int keyCode, KeyEvent event);

Expand All @@ -805,7 +804,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
// forward onKeyDown events to listener
return this.onKeyUpDownListener!=null && this.onKeyUpDownListener.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// forward onKeyUp events to listener
Expand Down
13 changes: 13 additions & 0 deletions www/WikitudePlugin.js
Expand Up @@ -88,6 +88,7 @@
// We add an event listener on the resume and pause event of the application life-cycle
document.addEventListener("resume", this.onResume, false);
document.addEventListener("pause", this.onPause, false);
document.addEventListener("backbutton", this.onBackButton, false);
};

/* Managing the Wikitude SDK Lifecycle */
Expand All @@ -98,6 +99,7 @@

document.removeEventListener("pause", this.onPause, false);
document.removeEventListener("resume", this.onResume, false);
document.removeEventListener("backbutton", this.onBackButton, false);

cordova.exec(this.onWikitudeOK, this.onWikitudeError, "WikitudePlugin", "close", [""]);
};
Expand Down Expand Up @@ -195,6 +197,17 @@
cordova.exec(this.onWikitudeOK, this.onWikitudeError, "WikitudePlugin", "onResume", [""]);
};

/* Lifecycle updates */
/**
* This function gets called every time the application did become active.
*/
WikitudePlugin.prototype.onBackButton = function() {

// Call the Wikitude SDK that it should resume.
//cordova.exec(this.onWikitudeOK, this.onWikitudeError, "WikitudePlugin", "close", [""]);
WikitudePlugin.prototype.close();
};

/**
* This function gets called every time the application is about to become inactive.
*/
Expand Down

0 comments on commit a5f0573

Please sign in to comment.