-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experiments with 2.0 and backwards compatibility
- Loading branch information
Joe Bowser
committed
Nov 26, 2009
1 parent
556c3a8
commit 21a8e4d
Showing
3 changed files
with
141 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.phonegap; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.util.Log; | ||
import android.webkit.JsResult; | ||
import android.webkit.WebChromeClient; | ||
import android.webkit.WebStorage; | ||
import android.webkit.WebView; | ||
|
||
|
||
public class GapClient extends WebChromeClient { | ||
|
||
private static final String LOG_TAG = "DroidGap"; | ||
private long MAX_QUOTA = 2000000; | ||
private WebChromeClient mInstance; | ||
|
||
/* class initialization fails when this throws an exception */ | ||
static { | ||
try { | ||
|
||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
Context mCtx; | ||
GapClient(Context ctx) | ||
{ | ||
mCtx = ctx; | ||
} | ||
|
||
@Override | ||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) { | ||
Log.d(LOG_TAG, message); | ||
// This shows the dialog box. This can be commented out for dev | ||
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx); | ||
alertBldr.setMessage(message); | ||
alertBldr.setTitle("Alert"); | ||
alertBldr.show(); | ||
result.confirm(); | ||
return true; | ||
} | ||
|
||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, | ||
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) | ||
{ | ||
|
||
if( estimatedSize < MAX_QUOTA) | ||
{ | ||
long newQuota = estimatedSize; | ||
quotaUpdater.updateQuota(newQuota); | ||
} | ||
else | ||
{ | ||
// Set the quota to whatever it is and force an error | ||
// TODO: get docs on how to handle this properly | ||
quotaUpdater.updateQuota(currentQuota); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.phonegap; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
import android.webkit.WebSettings; | ||
|
||
public class WebViewReflect { | ||
private static Method mWebSettings_setDatabaseEnabled; | ||
|
||
static | ||
{ | ||
checkCompatibility(); | ||
} | ||
|
||
private static void setDatabaseEnabled(boolean e) throws IOException { | ||
try | ||
{ | ||
mWebSettings_setDatabaseEnabled.invoke(e); | ||
} | ||
catch (InvocationTargetException ite) { | ||
/* unpack original exception when possible */ | ||
Throwable cause = ite.getCause(); | ||
if (cause instanceof IOException) { | ||
throw (IOException) cause; | ||
} else if (cause instanceof RuntimeException) { | ||
throw (RuntimeException) cause; | ||
} else if (cause instanceof Error) { | ||
throw (Error) cause; | ||
} else { | ||
/* unexpected checked exception; wrap and re-throw */ | ||
throw new RuntimeException(ite); | ||
} | ||
} catch (IllegalAccessException ie) { | ||
System.err.println("unexpected " + ie); | ||
} | ||
} | ||
|
||
public static void checkCompatibility() { | ||
try { | ||
mWebSettings_setDatabaseEnabled = WebSettings.class.getMethod( | ||
"setDatabaseEnabled", new Class[] { boolean.class } ); | ||
/* success, this is a newer device */ | ||
} catch (NoSuchMethodException nsme) { | ||
/* failure, must be older device */ | ||
} | ||
} | ||
|
||
|
||
public static void setStorage(WebSettings setting, boolean enable, String path) { | ||
if (mWebSettings_setDatabaseEnabled != null) { | ||
/* feature is supported */ | ||
setting.setDatabaseEnabled(enable); | ||
setting.setDatabasePath(path); | ||
} else { | ||
/* feature not supported, do something else */ | ||
System.out.println("dump not supported"); | ||
} | ||
} | ||
} |