Android Open Source - webview-gm Web View Gm






From Project

Back to project page webview-gm.

License

The source code is released under:

Apache License

If you think the Android project webview-gm listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *    Copyright 2012 Werner Bayer/*from  w  w w .  j  a  v  a  2s .c o  m*/
 *
 *    Licensed 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 at.pardus.android.webview.gm.run;

import java.util.UUID;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView;
import at.pardus.android.webview.gm.store.ScriptStore;

/**
 * A user script enabled WebView.
 * 
 * Initializes the WebView with a WebViewClientGm. If this object is inflated by
 * XML run setScriptStore to enable script support.
 */
public class WebViewGm extends WebView {

  private static final String JSBRIDGENAME = "WebViewGM";

  private ScriptStore scriptStore;

  private WebViewClientGm webViewClient;

  /**
   * Constructs a new WebViewGm initializing it with a ScriptStore.
   * 
   * @param context
   *            the application's context
   * @param scriptStore
   *            the script database to use
   */
  public WebViewGm(Context context, ScriptStore scriptStore) {
    super(context);
    init();
    setScriptStore(scriptStore);
  }

  /**
   * Constructs a new WebViewGm with a Context object.
   * 
   * @param context
   *            the application's context
   */
  public WebViewGm(Context context) {
    super(context);
    init();
  }

  /**
   * Constructs a new WebViewGm with layout parameters.
   * 
   * @param context
   *            the application's context
   * @param attrs
   *            layout parameters
   */
  public WebViewGm(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  /**
   * Constructs a new WebViewGm with layout parameters and a default style.
   * 
   * @param context
   *            the application's context
   * @param attrs
   *            layout parameters
   * @param defStyle
   *            default style resource ID
   */
  public WebViewGm(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  /**
   * Called by the constructors to set up the WebView to enable user scripts.
   */
  private void init() {
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    webViewClient = new WebViewClientGm(scriptStore, JSBRIDGENAME,
        generateSecret());
    setWebViewClient(webViewClient);
  }

  /**
   * @return the scriptStore
   */
  public ScriptStore getScriptStore() {
    return scriptStore;
  }

  /**
   * @param scriptStore
   *            the scriptStore to set
   */
  public void setScriptStore(ScriptStore scriptStore) {
    this.scriptStore = scriptStore;
    addJavascriptInterface(
        new WebViewGmApi(scriptStore, webViewClient.getSecret()),
        JSBRIDGENAME);
    webViewClient.setScriptStore(scriptStore);
  }

  /**
   * @return the webViewClient
   */
  public WebViewClientGm getWebViewClient() {
    return webViewClient;
  }

  /**
   * @param webViewClient
   *            the WebViewClientGm to set as WebViewClient
   */
  public void setWebViewClient(WebViewClientGm webViewClient) {
    this.webViewClient = webViewClient;
    super.setWebViewClient(webViewClient);
  }

  /**
   * @return a random string to use in GM API calls
   */
  private static String generateSecret() {
    return UUID.randomUUID().toString();
  }

}




Java Source Code List

at.pardus.android.webview.gm.WebViewGmImpl.java
at.pardus.android.webview.gm.model.ScriptCriteria.java
at.pardus.android.webview.gm.model.ScriptId.java
at.pardus.android.webview.gm.model.ScriptMetadata.java
at.pardus.android.webview.gm.model.Script.java
at.pardus.android.webview.gm.run.WebViewClientGm.java
at.pardus.android.webview.gm.run.WebViewGmApi.java
at.pardus.android.webview.gm.run.WebViewGm.java
at.pardus.android.webview.gm.store.ScriptStoreSQLite.java
at.pardus.android.webview.gm.store.ScriptStore.java
at.pardus.android.webview.gm.store.ui.ScriptBrowser.java
at.pardus.android.webview.gm.store.ui.ScriptEditor.java
at.pardus.android.webview.gm.store.ui.ScriptList.java
at.pardus.android.webview.gm.store.ui.ScriptManagerActivity.java
at.pardus.android.webview.gm.util.CriterionMatcher.java
at.pardus.android.webview.gm.util.UnicodeReader.java