Пример #1
2
  private synchronized void initWebSettings() {

    if (android.os.Build.VERSION.SDK_INT >= 21) WebView.enableSlowWholeDocumentDraw();

    WebSettings webSettings = getSettings();
    userAgentOriginal = webSettings.getUserAgentString();

    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);

    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().toString());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setGeolocationDatabasePath(context.getFilesDir().toString());

    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      webSettings.setLoadsImagesAutomatically(true);
    } else {
      webSettings.setLoadsImagesAutomatically(false);
    }
  }
Пример #2
0
 public static void initializeSettings(WebSettings settings, Context context) {
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   settings.setUserAgentString(settings.getUserAgentString() + DB.USER_AGENT);
   settings.setSupportMultipleWindows(true);
   settings.setSaveFormData(false);
   settings.setSavePassword(false); // 设置为true,系统会弹出AlertDialog确认框
   if (API < 18) {
     settings.setAppCacheMaxSize(Long.MAX_VALUE);
   }
   if (API < 17) {
     settings.setEnableSmoothTransition(true);
   }
   if (API < 19) {
     settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases");
   }
   settings.setDomStorageEnabled(true);
   settings.setAppCachePath(context.getCacheDir().toString());
   settings.setAppCacheEnabled(true);
   settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
   settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath());
   settings.setAllowFileAccess(true);
   settings.setDatabaseEnabled(true);
   settings.setSupportZoom(true);
   settings.setBuiltInZoomControls(true);
   settings.setDisplayZoomControls(false);
   settings.setAllowContentAccess(true);
   settings.setDefaultTextEncodingName("utf-8");
   /*if (API > 16) {
   	settings.setAllowFileAccessFromFileURLs(false);
   	settings.setAllowUniversalAccessFromFileURLs(false);
   }*/
 }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Window win = this.getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    requestWindowFeature(Window.FEATURE_CONTEXT_MENU);
    setContentView(R.layout.bar_code);

    if (isOnline() && getAutoUpdateSetting()) {
      AutoUpdate();
      Log.i(TAG, "online");
    } else Log.i(TAG, "offline");

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    Log.i(TAG, databasePath);

    mpAudio = new MediaPlayer();
    mpAudio = MediaPlayer.create(BarcodeDemoActivity.this, R.raw.bb);
    mpAudio.setVolume(100.0f, 100.0f);

    MainWebView = (WebView) findViewById(R.id.barcode);
    MainWebView.requestFocus(View.FOCUS_DOWN);
    MainWebView.addJavascriptInterface(new runCallJavaScript(), JSInterface);

    WebSettings settings = MainWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath + File.separator + "BarcodeDemoDB");

    MainWebView.loadUrl(WebPageUrl + "?lang=" + getLangCode(getLocale()));

    MainWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              QuotaUpdater quotaUpdater) {
            Log.i(TAG, "estimatedSize=" + estimatedSize);
            quotaUpdater.updateQuota(estimatedSize * 2);
          }
        });
    MainWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView webView, String url) {
            // String lang = getLangCode(getLocale());
            // MainWebView.loadUrl("javascript:setLanguage('"+lang+"');");
          }
        });
  }
Пример #4
0
 public void initWebview(WebView paramWebView) {
   WebSettings localWebSettings = paramWebView.getSettings();
   localWebSettings.setJavaScriptEnabled(true);
   if (Build.VERSION.SDK_INT > 7) localWebSettings.setPluginState(WebSettings.PluginState.ON);
   localWebSettings.setSupportZoom(true);
   localWebSettings.setBuiltInZoomControls(true);
   localWebSettings.setAllowFileAccess(true);
   localWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
   localWebSettings.setUseWideViewPort(true);
   if (Build.VERSION.SDK_INT >= 8) {
     localWebSettings.setLoadWithOverviewMode(true);
     localWebSettings.setDatabaseEnabled(true);
     localWebSettings.setDomStorageEnabled(true);
     localWebSettings.setGeolocationEnabled(true);
     localWebSettings.setAppCacheEnabled(true);
   }
   if (Build.VERSION.SDK_INT >= 11) ;
   try {
     Class[] arrayOfClass = new Class[1];
     arrayOfClass[0] = Boolean.TYPE;
     Method localMethod =
         WebSettings.class.getDeclaredMethod("setDisplayZoomControls", arrayOfClass);
     localMethod.setAccessible(true);
     Object[] arrayOfObject = new Object[1];
     arrayOfObject[0] = Boolean.valueOf(false);
     localMethod.invoke(localWebSettings, arrayOfObject);
     return;
   } catch (Exception localException) {
     com.taobao.newxp.common.Log.e(ExchangeConstants.LOG_TAG, "", localException);
   }
 }
Пример #5
0
  /**
   * 初始化
   *
   * @param web_view
   * @param activity
   * @return
   */
  public static WebView WebSettingInit(WebView web_view, final Activity activity) {
    WebSettings ws = web_view.getSettings();
    ws.setJavaScriptEnabled(true); // 支持js
    ws.setBuiltInZoomControls(false); // 支持缩放按钮
    ws.setUseWideViewPort(true); // 设置此属性,可任意比例缩放 将图片调整到适合webview的大小
    ws.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
    ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    ws.setSupportZoom(false); // 支持缩放
    // 设置 缓存模式
    ws.setCacheMode(WebSettings.LOAD_NO_CACHE); // 关闭webview中缓存

    web_view.clearCache(true);
    web_view.setTag(true);
    // 开启 DOM storage API 功能
    ws.setDomStorageEnabled(true);

    ws.setRenderPriority(RenderPriority.HIGH);
    // 开启 database storage API 功能
    ws.setDatabaseEnabled(false);

    web_view.setWebChromeClient(
        new WebChromeClient() {

          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
          }
        });
    return web_view;
  }
Пример #6
0
  private void initializeSettings(WebSettings settings) {
    settings.setJavaScriptEnabled(true);

    // configure local storage apis and their database paths.
    settings.setAppCachePath(getDir("appcache", 0).getPath());
    settings.setGeolocationDatabasePath(getDir("geolocation", 0).getPath());
    settings.setDatabasePath(getDir("databases", 0).getPath());

    settings.setAppCacheEnabled(true);
    settings.setGeolocationEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
  /** Create and initialize web container. */
  public void init() {
    LOG.d(TAG, "DroidGap.init()");

    // Create web container
    this.appView = new WebView(DroidGap.this);
    this.appView.setId(100);

    this.appView.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F));

    this.appView.setWebChromeClient(new CordovaChromeClient(DroidGap.this));
    this.setWebViewClient(this.appView, new CordovaWebViewClient(this));

    this.appView.setInitialScale(0);
    this.appView.setVerticalScrollBarEnabled(false);
    this.appView.requestFocusFromTouch();

    // Enable JavaScript
    WebSettings settings = this.appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC
    settings.setNavDump(true);

    // Enable database
    settings.setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Add web view but make it invisible while loading URL
    this.appView.setVisibility(View.INVISIBLE);
    root.addView(this.appView);
    setContentView(root);

    // Clear cancel flag
    this.cancelLoadUrl = false;
  }
Пример #8
0
  void init() {
    setWebViewClient(new LoveClient());
    setWebChromeClient(new Chrome());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setUseWideViewPort(true);

    /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (BuildConfig.DEBUG) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }*/
  }
Пример #9
0
  /**
   * Construct a new {@link ScriptResolver}
   *
   * @param id the id of this {@link ScriptResolver}
   * @param tomahawkApp referenced {@link TomahawkApp}, needed to report our results in the {@link
   *     PipeLine}
   * @param scriptPath {@link String} containing the path to our javascript file
   */
  public ScriptResolver(int id, TomahawkApp tomahawkApp, String scriptPath) {
    mReady = false;
    mStopped = true;
    mId = id;
    mTomahawkApp = tomahawkApp;
    mScriptEngine = new WebView(mTomahawkApp);
    WebSettings settings = mScriptEngine.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
    mScriptEngine.setWebChromeClient(new TomahawkWebChromeClient());
    mScriptEngine.setWebViewClient(new ScriptEngine(this));
    final ScriptInterface scriptInterface = new ScriptInterface(this);
    mScriptEngine.addJavascriptInterface(scriptInterface, SCRIPT_INTERFACE_NAME);
    String[] tokens = scriptPath.split("/");
    mName = tokens[tokens.length - 1];
    mIcon = mTomahawkApp.getResources().getDrawable(R.drawable.ic_resolver_default);
    mScriptFilePath = scriptPath;

    init();
  }
Пример #10
0
  /** Initialize the WebView options to the ones define by user. */
  public void initializeOptions() {
    WebSettings settings = getSettings();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
    settings.setSaveFormData(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
    settings.setSavePassword(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
    settings.setDefaultZoom(
        ZoomDensity.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
    settings.setUserAgentString(
        prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));

    settings.setPluginState(
        PluginState.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance()
        .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true));

    // Technical settings
    // settings.setUseWideViewPort(true);
    settings.setSupportMultipleWindows(true);
    setLongClickable(true);
    setScrollbarFadingEnabled(true);
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setDrawingCacheEnabled(true);

    settings.setAppCacheEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
Пример #11
0
 private void setWebView() {
   WebSettings settings = wvIt.getSettings();
   settings.setDomStorageEnabled(true);
   settings.setAppCacheEnabled(true);
   settings.setJavaScriptEnabled(true);
   settings.setPluginState(WebSettings.PluginState.ON);
   settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
   settings.setDomStorageEnabled(true);
   settings.setDatabaseEnabled(true);
   settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache");
   settings.setAppCacheEnabled(true);
   settings.setLoadWithOverviewMode(true);
   wvIt.setWebViewClient(
       new WebViewClient() {
         @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url);
           return true;
         }
       });
   wvIt.setWebChromeClient(
       new WebChromeClient() {
         @Override
         public void onProgressChanged(WebView view, int newProgress) {
           if (pbWeb != null) { // 修复未加载完成,用户返回会崩溃
             if (newProgress == 100) {
               pbWeb.setVisibility(View.GONE);
             } else {
               if (pbWeb.getVisibility() == View.GONE) {
                 pbWeb.setVisibility(View.VISIBLE);
               }
               pbWeb.setProgress(newProgress);
             }
           }
           super.onProgressChanged(view, newProgress);
         }
       });
 }
 static void a_(WebSettings webSettings, boolean z) {
   webSettings.setDatabaseEnabled(z);
 }
Пример #13
0
  @SuppressLint("SetJavaScriptEnabled")
  @SuppressWarnings("deprecation")
  private void initWebViewSettings() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    // TODO: The Activity is the one that should call requestFocus().
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    // Enable JavaScript
    final WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean
    // 4.2)
    try {
      Method gingerbread_getMethod =
          WebSettings.class.getMethod("setNavDump", new Class[] {boolean.class});

      String manufacturer = android.os.Build.MANUFACTURER;
      Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
      if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB
          && android.os.Build.MANUFACTURER.contains("HTC")) {
        gingerbread_getMethod.invoke(settings, true);
      }
    } catch (NoSuchMethodException e) {
      Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
      Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
      Log.d(
          TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
      Log.d(
          TAG,
          "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }

    // We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
      Level16Apis.enableUniversalAccess(settings);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Level17Apis.setMediaPlaybackRequiresUserGesture(settings, false);
    }
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath =
        getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);

    // Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
        && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
      enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    settings.getUserAgentString();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
      this.receiver =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              settings.getUserAgentString();
            }
          };
      getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
  }
Пример #14
0
  @SuppressLint("SetJavaScriptEnabled")
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
      // get url and navigatio preference (default true)
      final String url = getIntent().getStringExtra(getPackageName() + ".URL");
      final boolean navigation =
          getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true);

      setContentView(R.layout.webviewnav);

      // if we want navigation bar and not hide it, make it visible. Make it invisible if not.
      if (navigation && !hideNavigationBar) {
        findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE);
      } else {
        findViewById(R.id.webBottomBar).setVisibility(View.GONE);
      }

      mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack);
      mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward);
      mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop);

      mProgressView = (ProgressBar) findViewById(R.id.progressBar);
      mProgressView.setIndeterminate(true);

      // init webview
      mWebView = (WebView) findViewById(R.id.webView);

      // disable hw accel as it creates flickering pages, html5 video won't work with this
      if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16)
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

      // This hides white bar on the right
      mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

      WebSettings settings = mWebView.getSettings();
      // enable plugins before java script
      settings.setPluginState(PluginState.ON);

      // TODO test these two settings with a big webpage (cafe lotty?)
      settings.setLoadWithOverviewMode(true);
      settings.setUseWideViewPort(true);
      // enable javascript and zoom controls
      settings.setJavaScriptEnabled(true);
      settings.setBuiltInZoomControls(true);
      settings.setGeolocationEnabled(true);
      settings.setDatabaseEnabled(true);
      String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath();
      settings.setDatabasePath(databasePath);
      settings.setGeolocationDatabasePath(databasePath);
      settings.setDomStorageEnabled(true);
      settings.setAppCacheEnabled(true);

      // allow XMLHttpRequests
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        settings.setAllowUniversalAccessFromFileURLs(true);

      MetaioWebViewClient client = new MetaioWebViewClient();
      mWebView.setWebViewClient(client);
      mWebView.setWebChromeClient(new MetaioWebChromeClient());

      registerForContextMenu(mWebView);

      if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
      } else {

        // if we don't have to override the url, load it in the webview
        if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url);
      }
    } catch (Exception e) {
      MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e);
    }
  }
Пример #15
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
    linearLayout.setBackgroundColor(Color.BLACK);

    // Navbar setup

    navbar = (LinearLayout) findViewById(R.id.navbar);
    goButton = (Button) findViewById(R.id.go_button);
    urlField = (EditText) findViewById(R.id.url);

    goButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doNav();
          }
        });

    urlField.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_GO) {

              doNav();

              handled = true;
            }
            return handled;
          }
        });

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    String lastUrl = settings.getString("lastUrl", "");

    urlField.setText(lastUrl);

    // Navbar animation settings

    AnimationListener slideListener =
        new AnimationListener() {
          @Override
          public void onAnimationEnd(Animation animation) {
            if (animation.equals(slideUp)) {
              navbar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}

          @Override
          public void onAnimationStart(Animation animation) {
            if (animation.equals(slideDown)) {
              navbar.setVisibility(View.VISIBLE);
            }
          }
        };

    slideUp =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f);
    slideUp.setDuration(500);
    slideUp.setAnimationListener(slideListener);

    slideDown =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f);
    slideDown.setDuration(500);
    slideDown.setAnimationListener(slideListener);

    // WebView setup

    webView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = webView.getSettings();

    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageFinished(WebView view, String url) {

            Log.d("scale", view.getScale() + "");

            Log.d("pageFinished", url);

            view.setInitialScale(70);

            if (url.equalsIgnoreCase(HOME_PAGE)) {
              // navbar.setVisibility(View.VISIBLE);
              navbar.startAnimation(slideDown);
            }
          }

          @Override
          public void onScaleChanged(WebView view, float oldScale, float newScale) {

            Log.d("scale changed", oldScale + " - " + newScale);

            if (newScale > 0.7) {

              Log.d("scale", "reset");
              // view.setInitialScale(70);

            }
          }
        });

    webView.setInitialScale(70);

    webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    webView.setVerticalScrollBarEnabled(false);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);

    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setSupportZoom(true);

    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(
        "/data/data/" + webView.getContext().getPackageName() + "/databases/");
    webSettings.setSaveFormData(false);
    webSettings.setLightTouchEnabled(false);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webSettings.setRenderPriority(RenderPriority.HIGH);
    webSettings.setUserAgentString(
        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");

    final Intent intent = getIntent();
    if ((intent.getAction() == Intent.ACTION_VIEW) && (intent.getData() != null)) {
      final String url = intent.getDataString();
      urlField.setText(url);
      webView.loadUrl(url);
      navbar.setVisibility(View.GONE);
    } else {
      webView.loadUrl(HOME_PAGE);
    }

    webView.requestFocus();
  }
Пример #16
0
  // 封装WebView
  public static void wrapWebView(Context context, WebView webView, WebViewClient webclient) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSupportZoom(false);

    // 设置定位可用
    if (context != null) {
      webSettings.setDatabaseEnabled(true);
      String dir =
          context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();

      // 启用地理定位
      webSettings.setGeolocationEnabled(true);
      // 设置定位的数据库路径
      webSettings.setGeolocationDatabasePath(dir);

      // 最重要的方法,一定要设置,这就是出不来的主要原因

      webSettings.setDomStorageEnabled(true);
    }
    //
    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
            callback.invoke(origin, true, false);
            super.onGeolocationPermissionsShowPrompt(origin, callback);
          }
        });
    webView.setWebViewClient(webclient);
    // webView.setWebViewClient(new WebViewClient() {
    //
    // // 加载链接
    // @Override
    // public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // view.loadUrl(url);
    // return true;
    // }
    //
    // // 链接开始加载时
    // @Override
    // public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // super.onPageStarted(view, url, favicon);
    // if (progress != null) {
    // progress.setVisibility(View.VISIBLE);
    // }
    // }
    //
    // // 链接加载完成
    // @Override
    // public void onPageFinished(WebView view, String url) {
    // super.onPageFinished(view, url);
    // if (progress != null) {
    // progress.setVisibility(View.GONE);
    // }
    // }
    //
    // @Override
    // public void onReceivedSslError(WebView view, SslErrorHandler handler,
    // SslError error) {
    // super.onReceivedSslError(view, handler, error);
    // }
    //
    // // webview无网络情况下的人性化处理
    // @Override
    // public void onReceivedError(WebView view, int errorCode, String
    // description, String failingUrl) {
    // super.onReceivedError(view, errorCode, description, failingUrl);
    // view.loadData("", "text/html", "utf-8");
    // Toast.makeText(view.getContext(), "网络不给力",
    // android.widget.Toast.LENGTH_LONG).show();
    // }
    // });
  }
Пример #17
0
  /** 初始化主页面视图 * */
  private void initContentWebView() {
    contentWebView = (WebView) this.findViewById(R.id.webView1);

    contentWebView.setWebChromeClient(new WebChromeClientEx(PortalActivity.this));
    contentWebView.setWebViewClient(new WebViewClientEx(this));
    contentWebView.setInitialScale(0);
    contentWebView.setScrollBarStyle(0); // 滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上
    contentWebView.setVerticalScrollBarEnabled(false);
    contentWebView.requestFocusFromTouch();

    // Enable JavaScript
    WebSettings settings = contentWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);

    // Set the nav dump for HTC
    settings.setNavDump(true);

    // 支持html5的localStorage
    settings.setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Clear cancel flag
    this.cancelLoadUrl = false;

    String version = android.os.Build.VERSION.RELEASE;
    if (version != null && version.indexOf("4.0") != -1) {
      this.clearCache();
    }
    contentWebView.addJavascriptInterface(
        new Object() {
          @SuppressWarnings("unused")
          public void eventHandle(String params) {
            appEventHandle(new AppEvent(params));
          }

          @SuppressWarnings("unused")
          public String getAndroidVersion() {
            return android.os.Build.VERSION.RELEASE;
          }

          @SuppressWarnings("unused")
          public void openAppSetting() {
            openSettingDlg();
          }

          @SuppressWarnings("unused")
          public void checkPage(String success) {
            if ("true".equalsIgnoreCase(success)) {
              loadSuccess = true;
              spinnerStop();
            } else {
              PortalActivity me = PortalActivity.this;
              me.runOnUiThread(
                  new Runnable() {
                    public void run() {
                      showErrorTip("连接超时,似乎加载的页面不正常!请检查网络和配置");
                      openSettingDlg();
                    }
                  });
            }
          }
        },
        "nativeApp");
    contentWebView.addJavascriptInterface(
        new Object() {
          @SuppressWarnings("unused")
          public void testCall() {
            injectJSObject();
          }
        },
        "justepApp");

    contentWebView.setDownloadListener(new JustepAppWebViewDownLoadListener());

    /**
     * contentWebView.setWebViewClient(new WebViewClient() {
     *
     * <p>});
     */
  }
Пример #18
0
  public TiUIWebView(TiViewProxy proxy) {
    super(proxy);
    this.isFocusable = true;
    TiWebView webView =
        isHTCSenseDevice()
            ? new TiWebView(proxy.getActivity())
            : new NonHTCWebView(proxy.getActivity());
    webView.setVerticalScrollbarOverlay(true);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAllowFileAccess(true);
    settings.setDomStorageEnabled(
        true); // Required by some sites such as Twitter. This is in our iOS WebView too.
    File path = TiApplication.getInstance().getFilesDir();
    if (path != null) {
      settings.setDatabasePath(path.getAbsolutePath());
      settings.setDatabaseEnabled(true);
    }

    File cacheDir = TiApplication.getInstance().getCacheDir();
    if (cacheDir != null) {
      settings.setAppCacheEnabled(true);
      settings.setAppCachePath(cacheDir.getAbsolutePath());
    }

    // enable zoom controls by default
    boolean enableZoom = true;

    if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
      enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS));
    }

    settings.setBuiltInZoomControls(enableZoom);
    settings.setSupportZoom(enableZoom);

    if (TiC.JELLY_BEAN_OR_GREATER) {
      settings.setAllowUniversalAccessFromFileURLs(
          true); // default is "false" for JellyBean, TIMOB-13065
    }

    // We can only support webview settings for plugin/flash in API 8 and higher.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) {
      initializePluginAPI(webView);
    }

    boolean enableJavascriptInterface =
        TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true);
    chromeClient = new TiWebChromeClient(this);
    webView.setWebChromeClient(chromeClient);
    client = new TiWebViewClient(this, webView);
    webView.setWebViewClient(client);
    if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) {
      client.getBinding().addJavascriptInterfaces();
    }
    webView.client = client;

    if (proxy instanceof WebViewProxy) {
      WebViewProxy webProxy = (WebViewProxy) proxy;
      String username = webProxy.getBasicAuthenticationUserName();
      String password = webProxy.getBasicAuthenticationPassword();
      if (username != null && password != null) {
        setBasicAuthentication(username, password);
      }
      webProxy.clearBasicAuthentication();
    }

    TiCompositeLayout.LayoutParams params = getLayoutParams();
    params.autoFillsHeight = true;
    params.autoFillsWidth = true;

    setNativeView(webView);
  }