Beispiel #1
0
  private void bindBrowser(WebView appView) {
    gap = new Device(appView, this);
    accel = new AccelBroker(appView, this);
    launcher = new CameraLauncher(appView, this);
    mContacts = new ContactManager(appView, this);
    fs = new FileUtils(appView);
    netMan = new NetworkManager(appView, this);
    mCompass = new CompassListener(appView, this);
    crypto = new CryptoHandler(appView);
    mKey = new BrowserKey(appView, this);
    audio = new AudioHandler(appView, this);
    uiControls = new UIControls(appView, this);

    // This creates the new javascript interfaces for PhoneGap
    appView.addJavascriptInterface(gap, "DroidGap");
    appView.addJavascriptInterface(accel, "Accel");
    appView.addJavascriptInterface(launcher, "GapCam");
    appView.addJavascriptInterface(mContacts, "ContactHook");
    appView.addJavascriptInterface(fs, "FileUtil");
    appView.addJavascriptInterface(netMan, "NetworkManager");
    appView.addJavascriptInterface(mCompass, "CompassHook");
    appView.addJavascriptInterface(crypto, "GapCrypto");
    appView.addJavascriptInterface(mKey, "BackButton");
    appView.addJavascriptInterface(audio, "GapAudio");
    appView.addJavascriptInterface(uiControls, "UIControlsHook");

    if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
      cupcakeStorage = new Storage(appView);
      geo = new GeoBroker(appView, this);
      appView.addJavascriptInterface(cupcakeStorage, "droidStorage");
      appView.addJavascriptInterface(geo, "Geo");
    }
  }
Beispiel #2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    // This builds the view.  We could probably get away with NOT having a LinearLayout, but I like
    // having a bucket!

    LinearLayout.LayoutParams containerParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F);

    LinearLayout.LayoutParams webviewParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F);

    root = new LinearLayout(this);
    root.setOrientation(LinearLayout.VERTICAL);
    root.setBackgroundColor(Color.BLACK);
    root.setLayoutParams(containerParams);

    appView = new WebView(this);
    appView.setLayoutParams(webviewParams);

    WebViewReflect.checkCompatibility();

    if (android.os.Build.VERSION.RELEASE.startsWith("2."))
      appView.setWebChromeClient(new EclairClient(this));
    else {
      appView.setWebChromeClient(new GapClient(this));
    }

    appView.setInitialScale(100);
    appView.setVerticalScrollBarEnabled(false);

    WebSettings settings = appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    Package pack = this.getClass().getPackage();
    String appPackage = pack.getName();

    WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/");

    // Disable cookies
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(false);

    // Turn on DOM storage!
    WebViewReflect.setDomStorage(settings);
    // Turn off native geolocation object in browser - we use our own :)
    WebViewReflect.setGeolocationEnabled(settings, true);
    /* Bind the appView object to the gap class methods */
    bindBrowser(appView);
    if (cupcakeStorage != null) cupcakeStorage.setStorage(appPackage);

    root.addView(appView);

    setContentView(root);
  }