Skip to content

Commit

Permalink
+ Cordova 3.x Web Client Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Apr 23, 2014
1 parent 5423f3c commit 65b6c75
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/com/changeit/wmpolyfill/Cordova3WebClient.java
@@ -0,0 +1,105 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

package com.changeit.wmpolyfill;

import android.webkit.WebView;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaChromeClient;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.DroidGap;
import org.apache.cordova.CordovaInterface;

/**
* Phonegap 1.9+ compatible version of the WMP (won't compile before 1.9!)
* To use it, call the constructor of this class like this
* <pre>
* {@code
* PhonegapWebClient wmp = new PhonegapWebClient(this, appView);
* appView.setWebViewClient(wmp);
* }
* </pre>
* @author philzen
*/
public class Cordova3WebClient extends CordovaWebViewClient {

WebClient wmp;

/*
*
* @param cordova
* @param view
*/
public Cordova3WebClient(CordovaInterface cordova, CordovaWebView view) {
super(cordova, view);

CordovaActivity activity = (CordovaActivity)cordova;

if (view == null) {
// android.util.Log.d("polyfill", "CordovaWebClient: Creating View!");
view = new CordovaWebView(activity);
activity.init( view, this, new CordovaChromeClient(cordova) );
}

wmp = new WebClient(view);
view.setWebViewClient(this);
}


@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
wmp.onLoadResource(view, url);
}

/**
* Event Handler called after page has been loaded.
* If the API level is less than 11, then multitouch polyfill javascript is injected into DOM and eventHandler for Touches is registered
*
* @param view
* @param url
*/
@Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
wmp.onPageFinished(view, url);
}

/**
* Whether to polyfill all touches registered by the phone (true) or leave the already
* working touches on the WebView through (false)
*
* TODO if false, WMP doesn't interfere with the first native touch, but still polyfills all others
* as there isn't no current way to detect the number of native touches
* (thus it's currently fixed to one)
* see https://github.com/Philzen/WebView-MultiTouch-Polyfill/issues/9
*
* @param polyfillAllTouches
* @return Fluid Interface
*/
public Cordova3WebClient setPolyfillAllTouches(boolean polyfillAllTouches) {
wmp.setPolyfillAllTouches(polyfillAllTouches);
return this;
}

}


0 comments on commit 65b6c75

Please sign in to comment.