/**
* Add a WebChromeClient to WebView1.
* The WebChromeClient will handle console logging and javascript modal dialogs.
* It also overrides the default onExceededDatabaseQuota method, which enables the WebView to create and use the Database Storage API.
*
* WebView1 - The WebView to add the WebChromeClient to.
*/
public static final void addWebChromeClient(final BA pBA, final WebView WebView1, final String EventName) {
WebView1.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(final ConsoleMessage consoleMessage1) {
String logMessage = consoleMessage1.message() + " in " + consoleMessage1.sourceId() + " (Line: " + consoleMessage1.lineNumber() + ")";
switch (consoleMessage1.messageLevel()) {
case DEBUG:
Log.d("B4A", logMessage);
break;
case ERROR:
Log.e("B4A", logMessage);
break;
case LOG:
Log.i("B4A", logMessage);
break;
case TIP:
Log.v("B4A", logMessage);
break;
case WARNING:
Log.w("B4A", logMessage);
break;
default:
// log all other message types with Log.i (info)
// this condition currently will never occur but is included for future compatibility
Log.i("B4A", logMessage);
}
return true;
}
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(estimatedSize * 2);
}
@Override
public void onGeolocationPermissionsShowPrompt(String pOrigin, Callback pCallback) {
// default does nothing
// super.onGeolocationPermissionsShowPrompt(pOrigin, pCallback);
// Log.d("B4A", "onGeolocationPermissionsShowPrompt");
// auto allow permission but do not remember
// parameters are origin, allow, remember
// handle permission in B4A
int permission=(Integer) pBA.raiseEvent(this, EventName.toLowerCase(BA.cul)+"_geolocationpermissionsrequest", new Object[0]);
switch(permission){
case GEOLOCATION_PERMISSION_ALLOW:{
pCallback.invoke(pOrigin, true, false);
break;
}
case GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER:{
pCallback.invoke(pOrigin, true, true);
break;
}
case GEOLOCATION_PERMISSION_DISALLOW:{
pCallback.invoke(pOrigin, false, false);
break;
}
case GEOLOCATION_PERMISSION_DISALLOW_AND_REMEMBER:{
pCallback.invoke(pOrigin, false, true);
}
}
}
// For Android 3.0+
public void openFileChooser(final ValueCallback<Uri> pUloadMessage, String pAcceptType) {
Log.d("B4A", "openFileChooser 3.00+");
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
// i.setType("image/*"); // original code
i.setType(pAcceptType); // my code
IOnActivityResult IOnActivityResult1 = new IOnActivityResult() {
@Override
public void ResultArrived(int pResultCode, Intent pIntent) {
// pResultCode 0 is cancelled, -1 is file chosen?
Log.d("B4A", "ResultArrived");
Log.d("B4A", "pResultCode=" + pResultCode);
if (pIntent == null) {
pUloadMessage.onReceiveValue(null);
} else {
pUloadMessage.onReceiveValue(pIntent.getData());
}
}
};
pBA.startActivityForResult(IOnActivityResult1, Intent.createChooser(i, "Select a file"));
}
// For Android < 3.0
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> pUploadMessage) {
Log.d("B4A", "openFileChooser < 3.00");
openFileChooser(pUploadMessage, "*/*");
}
});
}