コード例 #1
2
ファイル: NinjaWebView.java プロジェクト: treejames/BBrowser
  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
  /**
   * @Title: initViews @Description: TODO(这里用一句话描述这个方法的作用)
   *
   * @param 设定文件
   * @return void 返回类型
   * @throws
   */
  private void initViews() {
    mWebView = (CustomWebView) rootView.findViewById(R.id.webview);
    mWebView.setScrollBarStyle(0);
    WebSettings settings = mWebView.getSettings();
    settings.setDefaultTextEncodingName("utf-8"); // 避免中文乱码
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(true);
    settings.setLoadWithOverviewMode(true); // 适应屏幕
    settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    settings.setLoadsImagesAutomatically(true); // 自动加载图片
    settings.setCacheMode(WebSettings.LOAD_DEFAULT | WebSettings.LOAD_CACHE_ELSE_NETWORK);

    // 滚动事件监听
    mWebView.setOnCustomScroolChangeListener(
        new ScrollInterface() {
          @Override
          public void onScrollChanged(int l, int t, int oldl, int oldt) {
            // TODO Auto-generated method stub
            if (t == 0) { // 已经处于顶端
              mCanScrollUp = true;
            } else {
              mCanScrollUp = false;
            }
          }
        });
  }
コード例 #3
0
ファイル: WebViewFactory.java プロジェクト: jeozey/Wisp
 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);
   }*/
 }
コード例 #4
0
  @Override
  public void initComponents() {
    wvUrl = (WebView) innerView.findViewById(R.id.wvUrl);
    WebSettings ws = wvUrl.getSettings();
    ws.setAllowFileAccess(true);
    ws.setAppCacheEnabled(true);
    ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    ws.setBuiltInZoomControls(false);
    ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    ws.setDisplayZoomControls(false);
    ws.setJavaScriptEnabled(true);
    ws.setSupportZoom(false);
    ws.setDefaultTextEncodingName("GBK");

    wvUrl.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            view.post(
                new Runnable() {

                  @Override
                  public void run() {
                    view.loadUrl(url);
                  }
                });
            return false;
          }
        });
    wvUrl.setWebChromeClient(new WebChromeClient());
  }
コード例 #5
0
ファイル: WebViewActivity.java プロジェクト: omusico/hand
  @SuppressLint({"NewApi", "SetJavaScriptEnabled"})
  private void loadWebView() {
    // 实例化WebView对象
    // webview = new MyWebView(WebViewActivity.this);
    LogUtil.i(TAG, "loadWebView===实例化WebView===");
    webview = (MyWebView) findViewById(R.id.id_webview);
    new MobclickAgentJSInterface(this, webview);

    WebSettings webSettings = webview.getSettings();
    // 设置WebView属性,能够执行Javascript脚本
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    //
    webSettings.setUseWideViewPort(true); // 关键点
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);

    webSettings.setAppCacheMaxSize(8 * 1024 * 1024); // 8MB
    // webSettings.setAppCachePath(Constants.WEBVIEW_CACHE_DIR );
    String appCacheDir =
        this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
    webSettings.setAppCachePath(appCacheDir);
    webSettings.setAllowFileAccess(true);
    webSettings.setDomStorageEnabled(true);

    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    // js调用安卓方法
    webview.addJavascriptInterface(this, "RedirectListner");
  }
コード例 #6
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fun_everyday, container, false);
    menu = (ImageButton) view.findViewById(R.id.btn_header_left);
    menu.setOnClickListener(this);

    TextView headText = (TextView) view.findViewById(R.id.title_header_mid);
    headText.setText(R.string.text_menu_story);

    String url = "http://www.molegegu.com/im/webview.htm";

    mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview);
    mWebView.loadUrl(url);
    mWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    mProgressBar = (ProgressBar) view.findViewById(R.id.loadProgress);
    mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview);
    mWebView.loadUrl(url);
    mWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    // set the webview
    WebSettings settings = mWebView.getSettings();
    settings.setSupportZoom(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDefaultTextEncodingName("GBK");
    settings.setTextSize(TextSize.NORMAL);
    settings.setJavaScriptEnabled(true);
    settings.setUseWideViewPort(true);
    mWebView.setInitialScale(80);
    mWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress > 0 && newProgress < 100) {
              mProgressBar.setVisibility(View.VISIBLE);
              mProgressBar.setProgress(newProgress);
            } else if (newProgress == 100) {
              mProgressBar.setVisibility(View.GONE);
            }
          }
        });
    mWebView.requestFocusFromTouch();
    return view;
  }
コード例 #7
0
ファイル: WebViewInit.java プロジェクト: XW-Cheng/LaoBanNiang
  /**
   * 初始化
   *
   * @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;
  }
コード例 #8
0
  private void init() {
    webView = (WebView) findViewById(R.id.webView);
    // WebView加载的是本地资源
    //        webView.loadUrl("file:///android_asset/example.html");
    // WebView加载的是Web资源
    webView.loadUrl("http://www.baidu.com");
    webView.loadUrl(url);
    // 覆盖WebView默认通过第三方或者是系统浏览器打开网页的行为,使得网页可以在VebView中打开
    webView.setWebViewClient(
        new WebViewClient() {
          // 返回值为true的时候,控制网页在WebView中打开,当WebView为false的时候,调用第三方或者是系统的浏览器打开
          // WebViewClient帮助WebView处理一些页面控制和请求通知
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    // 启用JavaScript
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // WebView加载页面优先使用缓存加载,其次从网络中获取
    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            // newProgress 是1-100之间的整数
            if (newProgress == 100) {
              // 网页加载完毕
              closeDialog(newProgress);
            } else {
              // 网页正在加载
              openDialog(newProgress);
            }
          }

          private void openDialog(int newProgress) {
            if (dialog == null) {
              dialog = new ProgressDialog(MainActivity.this);
              dialog.setTitle("正在加载");
              dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 横向进度条
              dialog.setProgress(newProgress);
              dialog.show();
            } else {
              dialog.setProgress(newProgress);
            }
          }

          private void closeDialog(int newProgress) {
            if (dialog != null && dialog.isShowing()) {
              dialog.dismiss();
              dialog = null;
            }
          }
        });
  }
コード例 #9
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_post_content, container, false);
    // View view = inflater.inflate(R.layout.activity_post_single, container, false);
    swipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_post_container);
    swipeRefreshLayout.setAddStatesFromChildren(false);
    // 设置刷新时动画的颜色,可以设置4个
    swipeRefreshLayout.setColorSchemeResources(
        android.R.color.holo_blue_light,
        android.R.color.holo_red_light,
        android.R.color.holo_orange_light,
        android.R.color.holo_green_light);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {

          @Override
          public void onRefresh() {
            // Toast.makeText(getApplication(), "正在刷新", Toast.LENGTH_SHORT);
            // TODO Auto-generated method stub
            new Handler()
                .postDelayed(
                    new Runnable() {

                      @Override
                      public void run() {
                        // TODO Auto-generated method stub
                        //   Toast.makeText(getApplication(), "刷新完成", Toast.LENGTH_SHORT);
                        swipeRefreshLayout.setRefreshing(false);
                      }
                    },
                    3000);
          }
        });

    postContentView = ((WebView) rootView.findViewById(R.id.post_Content));
    WebSettings Settings = postContentView.getSettings();
    Settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    Settings.setJavaScriptEnabled(true);
    Settings.setAllowFileAccess(true);
    mWebView = new MappingWebView(postContentView);
    // postContentView.addJavascriptInterface(mWebView, "JwebView");
    postContentView.addJavascriptInterface(this, "shareButton");

    basehtml = LocalFileReader.getFromAssets("index.html", getContext());

    String iniHtml =
        basehtml.replaceAll(contentReplace, "<div style=\"text-align:center\">文章加载中,请稍候……</div>");

    postContentView.loadDataWithBaseURL(null, iniHtml, "text/html", "utf-8", null);
    postContentView.setWebViewClient(new BYBlogWebViewClient(getContext()));
    SinglePostRequstAsyncTask task = new SinglePostRequstAsyncTask(1586, "王柏元的博客", "王柏元", "");
    task.execute("?ope=getPostContent&postid=" + postid);
    if (BYBlog.speaker == null) BYBlog.speaker = new TextToSpeech(getActivity(), null);

    //        }

    return rootView;
  }
コード例 #10
0
ファイル: UIUtils.java プロジェクト: hothanhhung/Android
  public static AlertDialog showAlertGetMoreApps(final Activity activity, String urlPage) {
    AlertDialog.Builder alert = new AlertDialog.Builder(activity);

    WebView wv = new WebView(activity);
    WebSettings settings = wv.getSettings();
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheMaxSize(50000 * 1024);

    progressBar1 = new ProgressBar(activity); // ,null, android.R.attr.progressBarStyleHorizontal);
    progressBar1.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    wv.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            activity.startActivity(i);
            return true;
          }
        });
    wv.setWebChromeClient(
        new WebChromeClient() {
          public void onProgressChanged(WebView view, int progress) {
            if (progress < 95) {
              progressBar1.setVisibility(View.VISIBLE);
              if (progressBar1.getProgress() < progress) {
                progressBar1.setProgress(progress);
              }
            } else {
              view.setVisibility(View.VISIBLE);
              progressBar1.setVisibility(View.GONE);
            }
          }
        });
    wv.loadUrl(urlPage);
    LinearLayout linearLayout = new LinearLayout(activity);
    if (android.os.Build.VERSION.SDK_INT >= 17) {
      // call something for API Level 11+
      linearLayout.setLayoutDirection(LinearLayout.LAYOUT_DIRECTION_LTR);
    }
    linearLayout.addView(progressBar1);
    linearLayout.addView(wv);
    alert.setView(linearLayout);
    alert.setNegativeButton(
        "Close",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
          }
        });
    // alert.setIcon(android.R.drawable.box_new)
    return alert.show();
  }
コード例 #11
0
  @SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
  private void initWebView() {
    mWebContent = (WebView) findViewById(R.id.news_detail_content);
    customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
    mWebViewClient = new CustomWebViewClient();
    mWebContent.setWebViewClient(mWebViewClient);

    mWebChromeClient = new MyWebChromeClient();
    mWebContent.addJavascriptInterface(new JavascriptCallBack(), "Android");
    mWebContent.setWebChromeClient(mWebChromeClient);
    WebSettings settings = mWebContent.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setAppCachePath(AppUtils.getWebCachePath(this));
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    mWebContent.loadUrl(url);
  }
コード例 #12
0
ファイル: BockoView.java プロジェクト: Bost/bocko-android
 public BockoView(Context context, AttributeSet attrs) {
   super(context, attrs);
   mWebView = new WebView(context);
   mWebView.setWillNotDraw(true);
   final WebSettings webSettings = mWebView.getSettings();
   webSettings.setAppCacheEnabled(false);
   webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
   webSettings.setJavaScriptEnabled(true);
   webSettings.setDefaultTextEncodingName("utf-8");
   mWebView.loadUrl(getUrl());
   mWebView.addJavascriptInterface(new JSObject(), "android");
   SurfaceHolder holder = getHolder();
   holder.addCallback(this);
 }
コード例 #13
0
  /** Initialization common for all constructors. */
  private void init() {
    WebSettings settings = getSettings();

    // Not use cache.
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // Enable JavaScript.
    settings.setJavaScriptEnabled(true);

    // Enable zoom control.
    settings.setBuiltInZoomControls(true);

    // Scroll bar
    setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
  }
コード例 #14
0
ファイル: AdWebView.java プロジェクト: shsun/guj-ems
  public AdWebView(
      AdViewContainer parent,
      MASTAdLog log,
      DisplayMetrics metrics,
      boolean mraid,
      boolean handleClicks) {
    super(parent.getContext());
    this.setId(getIdForView());

    adViewContainer = parent;
    adLog = log;
    // this.metrics = metrics;
    supportMraid = mraid;
    // launchBrowserOnClicks = handleClicks;

    // dataToInject = null;
    defferedJavascript = new StringBuffer();

    // Clients for javascript and other integration
    setWebChromeClient(new AdWebChromeClient());
    setWebViewClient(new AdWebViewClient(parent.getContext()));

    // Customize settings for web view
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setSupportZoom(false);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // apply standard properties
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    if (supportMraid) {
      javascriptInterface = new JavascriptInterface(parent, this);
      mraidInterface = new MraidInterface(parent, this);

      /*mraidScript = FileUtils.readTextFromJar(parent.getContext(),
      "/js/mraid.js");*/
    }

    // System.out.println("mraid script read: " + mraidScript);

    if (handleClicks) {
      adClickHandler = new AdClickHandler(adViewContainer);
    }
  }
コード例 #15
0
ファイル: WebViewActivity.java プロジェクト: Hanqing/X-BAG
  private void initWebView() {
    WebSettings settings = webView.getSettings();
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setJavaScriptEnabled(true);
    webView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }

          @Override
          public void onReceivedError(
              WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
          }

          @Override
          public void onReceivedHttpError(
              WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
          }
        });
    webView.setWebChromeClient(
        new WebChromeClient() {

          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress != 100) {
              progressBar.setVisibility(View.VISIBLE);
              progressBar.setProgress(newProgress);
            } else {
              progressBar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            mToolbar.setTitle(title);
          }
        });
  }
コード例 #16
0
ファイル: FragHome.java プロジェクト: quxin/Baike
  @SuppressLint({"InflateParams", "SetJavaScriptEnabled"})
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.frag_home, null);
    webview = (WebView) view.findViewById(R.id.webView1_home);
    cookies = new ArrayList<Cookie>();
    WebSettings ws = webview.getSettings();
    ws.setJavaScriptEnabled(true);
    ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    ws.setSupportZoom(true);
    ws.setBuiltInZoomControls(true);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);

    // ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webview.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    webview.setOnKeyListener(
        new OnKeyListener() {

          @Override
          public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
            if ((arg1 == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
              webview.goBack();
              return true;
            }
            return false;
          }
        });

    setCookie(getActivity().getApplicationContext());
    webview.loadUrl(devbaseURL + "?app-default");
    return view;
  }
コード例 #17
0
  void initWebView() {
    navigation =
        (RelativeLayout) findViewById(MResource.getIdByName(getApplication(), "id", "navigation"));
    view = (WebView) findViewById(MResource.getIdByName(getApplication(), "id", "wv_main"));
    query_pro =
        (ProgressBar) findViewById(MResource.getIdByName(getApplication(), "id", "query_pro"));
    left_finish =
        (RelativeLayout) findViewById(MResource.getIdByName(getApplication(), "id", "left_finish"));

    tv_title =
        (TextView)
            findViewById(MResource.getIdByName(getApplication(), "id", "center_text_string"));
    tv_title.setMovementMethod(ScrollingMovementMethod.getInstance());
    tv_title.setSelected(true);
    left_text_string =
        (TextView) findViewById(MResource.getIdByName(getApplication(), "id", "left_text_string"));
    left_finish.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (view.canGoBack()) {
              view.goBack();
            } else {
              SdkPreferences.clear();
              finish();
            }
          }
        });
    WebSettings wSettings = view.getSettings();
    wSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    wSettings.setDomStorageEnabled(true);
    wSettings.setDisplayZoomControls(true);
    wSettings.setSupportZoom(true);
    wSettings.setBuiltInZoomControls(true);
    wSettings.setJavaScriptEnabled(true);
    wSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    view.requestFocusFromTouch();
    view.addJavascriptInterface(new JavaScriptinterface(this), "android");
    view.setWebViewClient(mWebViewClient);
    view.setWebChromeClient(mChromeClient);
    // view.loadUrl("file:///android_asset/index.html");
  }
コード例 #18
0
  @SuppressLint("SetJavaScriptEnabled")
  private void initUI() {
    showLoading();
    mContentWebView = (WebView) getView().findViewById(R.id.webview_content);

    WebSettings settings = mContentWebView.getSettings();
    // 设置支持JavaScript
    settings.setJavaScriptEnabled(true);
    // 设置不缓存
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (isSupportZoomByRatio()) {
      // 支持缩放
      settings.setSupportZoom(true);
      settings.setBuiltInZoomControls(true);
      settings.setDisplayZoomControls(false);
      // 按比例缩放
      settings.setUseWideViewPort(true);
      // 自适应屏幕
      settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
      settings.setLoadWithOverviewMode(true);
    }

    // 在本地WebView中加载网页
    mContentWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            hideLoading();
          }
        });

    String url = getUrl();
    mContentWebView.loadUrl(url);
  }
コード例 #19
0
ファイル: LoveVideoView.java プロジェクト: yuanbo1026/gank
  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);
        }
    }*/
  }
コード例 #20
0
ファイル: OAuthActivity.java プロジェクト: WillCoder/WillBo
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauthactivity_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setTitle(getString(R.string.login));
    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WeiboWebViewClient());

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
  }
コード例 #21
0
  private void initializeViews() {

    LayoutInflater inflater =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mLayout =
        (ViewGroup)
            inflater.inflate(com.android.internal.R.layout.google_web_content_helper_layout, null);

    mWebView = (WebView) mLayout.findViewById(com.android.internal.R.id.web);
    mWebView.setWebViewClient(new MyWebViewClient());
    WebSettings settings = mWebView.getSettings();
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    mProgressBar = mLayout.findViewById(com.android.internal.R.id.progress);
    TextView message = (TextView) mProgressBar.findViewById(com.android.internal.R.id.message);
    message.setText(com.android.internal.R.string.googlewebcontenthelper_loading);

    mTextView = (TextView) mLayout.findViewById(com.android.internal.R.id.text);
    mTextView.setText(mUnsuccessfulMessage);
  }
コード例 #22
0
  /**
   * Have to be called from WebView.WebViewClient.onPageFinished ex : mWebView.setWebViewClient(new
   * WebViewClient() { onPageFinished(WebView view, String url) { [HERE] }}); Inject a header to a
   * webview : add a margin-top="**dpx" Had to have a transparent background with a placeholder on
   * top So inject js for placeholder and setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); for
   * transparency TODO : inject JavaScript for Pre-Lolipop with loadUrl("js:...")
   *
   * @param webView
   * @param withAnimation if true, disapear with a fadein
   */
  public static void injectHeader(final WebView webView, boolean withAnimation) {
    if (webView != null) {

      MaterialViewPagerAnimator animator =
          MaterialViewPagerHelper.getAnimator(webView.getContext());
      if (animator != null) {

        WebSettings webSettings = webView.getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);

        // transparent background
        webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

        { // inject margin top
          final int marginTop = animator.getHeaderHeight() + 10;
          final String js = String.format("document.body.style.marginTop= \"%dpx\"", marginTop);
          webView.evaluateJavascript(js, null);
        }

        {
          final String js = "document.body.style.backround-color= white";
          webView.evaluateJavascript(js, null);
        }

        if (withAnimation)
          webView.postDelayed(
              new Runnable() {
                @Override
                public void run() {
                  webView.setVisibility(View.VISIBLE);
                  ObjectAnimator.ofFloat(webView, "alpha", 0, 1).start();
                }
              },
              400);
      }
    }
  }
コード例 #23
0
ファイル: ItHomeActivity.java プロジェクト: xeao/MicroReader
 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);
         }
       });
 }
コード例 #24
0
  @AfterViews
  void afterViews() {
    Log.d(TAG, "state: " + state.toString());

    commonActivityTrait.initActivity(preferences);

    urlText.setSelectAllOnFocus(true);
    urlText.setOnEditorActionListener(this);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDefaultTextEncodingName(ENCODING);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.addJavascriptInterface(
        new BrowserActivityJavaScriptInterface(this), BrowserActivityJavaScriptInterface.NAME);
    webView.setWebViewClient(new BrowserWebViewClient(this));
    webView.setActionModeListener(this);

    translatePanelFragment.setListener(this);

    Intent intent = getIntent();
    if (intent != null) {
      String action = intent.getAction();
      if (action != null && action.equals(Intent.ACTION_VIEW)) {
        Uri url = intent.getData();
        if (url != null) {
          loadUrl(url.toString());
          return;
        }
      }
    }

    if (extraUrlOrKeywords.isEmpty()) {
      loadUrl(state.getLastUrl());
    } else {
      loadUrl(extraUrlOrKeywords);
    }
  }
コード例 #25
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mProgressBar = (ProgressBar) findViewById(R.id.pb_loading);

    mWebView = (WebView) findViewById(R.id.webView);
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //        mWebView.addJavascriptInterface(new JSInterface(), "JSInterface");
    settings.setSaveFormData(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    mWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress < 100) {
              mProgressBar.setVisibility(View.VISIBLE);
              mProgressBar.setProgress(newProgress);
            } else {
              mProgressBar.setVisibility(View.GONE);
            }
          }

          @Override
          public boolean onJsAlert(
              WebView view, String url, String message, final JsResult result) {
            // 构架一个builder来显示网页中的对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
            builder.setTitle("提示");
            builder.setMessage(message);
            builder.setPositiveButton(
                android.R.string.ok,
                new AlertDialog.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // 点击确定按钮之后,继续执行网页中的操作
                    result.confirm();
                  }
                });
            builder.setCancelable(false);
            builder.create();
            builder.show();
            return true;
          }
        });
    mWebView.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // do your handling codes here, which url is the requested url
            // probably you need to open that url rather than redirect:
            Uri uri = Uri.parse(url);
            if (uri.getScheme().equals("octmobile")) {
              return false;
            } else {
              view.loadUrl(url);
              mClose.setVisibility(View.VISIBLE);
              return false;
            }
          }

          @Override
          public void onPageFinished(WebView view, String mLoadUrl) {
            mTitle.setText(view.getTitle());
            url = mLoadUrl;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            CLog.d("WebView", errorCode + " " + description);
            try {
              view.loadUrl(
                  "file:///android_asset/error.html?url=" + URLEncoder.encode(url, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
            }
          }
        });

    if (savedInstanceState != null) {
      url = savedInstanceState.getString(DATA_URL);
    } else {
      decodeUrl(getIntent().getStringExtra(DATA_URL));
    }
    mWebView.loadUrl(url);
  }
コード例 #26
0
ファイル: MainActivity.java プロジェクト: ethauvin/Clever
  @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();
  }
コード例 #27
0
  @TargetApi(18)
  protected void init()
  {
    try
    {
      this.webView = new MyWebView(this.mContext);
      WebSettings localWebSettings = this.webView.getSettings();
      if (localWebSettings != null)
      {
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setUserAgentString("Android-QingtingFM Mozilla/5.0 (Linux; U; Android 4.4.0; zh-cn; MB200 Build/GRJ22;) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
        localWebSettings.setSupportZoom(true);
        localWebSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        localWebSettings.setCacheMode(2);
        localWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      }
      WebViewPlayer.getInstance().setbackPolicy(null);
      this.webView.addJavascriptInterface(WebViewPlayer.getInstance(), "QTJsPlayer");
      this.webView.addJavascriptInterface(WebViewFunc.getInstance(), "QTJsReserve");
      this.webView.setWebChromeClient(new WebChromeClient()
      {
        public boolean onJsAlert(WebView paramAnonymousWebView, String paramAnonymousString1, String paramAnonymousString2, JsResult paramAnonymousJsResult)
        {
          AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramAnonymousWebView.getContext());
          localBuilder.setTitle("蜻蜓提示").setMessage(paramAnonymousString2).setPositiveButton("确定", null);
          localBuilder.setCancelable(false);
          localBuilder.create().show();
          paramAnonymousJsResult.confirm();
          return true;
        }

        public void onProgressChanged(WebView paramAnonymousWebView, int paramAnonymousInt)
        {
          if (paramAnonymousInt > 70)
            GroupWebView.this.removeLoading();
        }

        public void onReceivedTitle(WebView paramAnonymousWebView, String paramAnonymousString)
        {
        }
      });
      this.webView.setHorizontalScrollBarEnabled(false);
      this.webView.setVerticalScrollBarEnabled(false);
      this.webView.setWebViewClient(this.webViewClient);
      this.webView.loadUrl(getUrl());
      this.webView.setDownloadListener(new DownloadListener()
      {
        public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong)
        {
          Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString1));
          GroupWebView.this.getContext().startActivity(localIntent);
        }
      });
      WebViewPlayer.getInstance().setWebview(this.webView);
      WebViewFunc.getInstance().setWebview(this.webView);
      LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, -1);
      addView(this.webView, localLayoutParams);
      return;
    }
    catch (Exception localException)
    {
    }
  }
コード例 #28
0
  private void init() {

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

    // 加载本地文件
    webView.loadUrl("file:///android_asset/example.html");

    // 加载Web 外部资源
    webView.loadUrl("http://www.baidu.com");
    // 覆盖WebView默认通过第三方或者是系统浏览器找开网页行为,使用网页可以在WebView中打开
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {

            // 返回值是true的时候控制网页在WebView中打开,如果为false调用系统 浏览器或第三方浏览器去打开
            view.loadUrl(url);
            return true;
          }
          // WebViewClient帮助webView去处理一些页面控制和请求通知
        });
    // 启用支持JavaScript
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // WebView 优先使用缓存加载
    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

    webView.setWebChromeClient(
        new WebChromeClient() {

          // 判断页面加载的过程
          @Override
          public void onProgressChanged(WebView view, int newProgress) {

            // newProgress  1-100之间的整数
            if (newProgress == 100) {
              // 网页    加载完毕
              // 关闭
              closeDialog();
            } else {
              // 网页加载 中
              openDialog(newProgress);
            }

            super.onProgressChanged(view, newProgress);
          }

          private void closeDialog() {
            if (progressDialog != null && progressDialog.isShowing()) {
              progressDialog.dismiss();
              progressDialog = null;
            }
          }

          private void openDialog(int newProgress) {
            if (progressDialog == null) {
              progressDialog = new ProgressDialog(MainActivity.this);
              progressDialog.setTitle("正在加载");
              progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
              progressDialog.setProgress(newProgress);
              progressDialog.show();
            } else {
              progressDialog.setProgress(newProgress);
            }
          }
        });
  }
コード例 #29
0
  @Override
  protected void onStart() {
    super.onStart();

    try {
      jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js");
      androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js");
    } catch (IOException e1) {
      throw new RuntimeException(e1);
    }

    mObserver = new HtmlEventObserver();

    // TODO
    // RpcReceiverManager mFacadeManager = getRpcReceiverManager();
    // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver);
    // mAPIWrapperSource = generateAPIWrapper();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG());
    mWebView.setKeepScreenOn(true);

    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mWebView.setScrollbarFadingEnabled(false);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setScrollContainer(false);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);

    webSettings.setSupportZoom(false);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper");
    mWebView.addJavascriptInterface(
        new Object() {

          @SuppressWarnings("unused")
          public void register(String event, int id) {
            mObserver.register(event, id);
          }
        },
        "_callback_wrapper");

    if (Build.VERSION.SDK_INT >= 5) {
      try {
        Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE});
        m1.invoke(webSettings, Boolean.TRUE);

        Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE});
        m2.invoke(webSettings, Boolean.TRUE);

        Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class});
        m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    mWebView.setWebChromeClient(new WebChromeClient() {});

    mWebView.setWebViewClient(
        new WebViewClient() {
          //        	public void onReceivedError(WebView view, int errorCode, String description,
          // String failingUrl) {
          //        		Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show();
          //        	}
        });

    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);

    if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) {
      mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN);
    } else if (Build.VERSION.SDK_INT >= 14) {
      mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

    mWebView.loadUrl("javascript:" + jsonSrc);
    mWebView.loadUrl("javascript:" + androidJsSrc);
    mWebView.loadUrl("javascript:" + mAPIWrapperSource);
    Log.d(
        config.getLOG_TAG(),
        "Launch Webview: "
            + "file://"
            + this.getFilesDir().getAbsolutePath()
            + "/"
            + config.getMAIN_SCRIPT_NAME());
    mWebView.loadUrl(
        "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME());
  }
コード例 #30
0
ファイル: ZtspeechWeiboDC.java プロジェクト: hai8108/ztspeech
  private void setWebView() {
    webSet = web.getSettings();
    webSet.setSavePassword(false);
    webSet.setAllowFileAccess(false);
    webSet.setJavaScriptEnabled(true);
    webSet.setSaveFormData(false);
    webSet.setSupportZoom(true);
    webSet.setBuiltInZoomControls(true);
    webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
    layout.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);

    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    web.setWebChromeClient(
        new WebChromeClient() { // 设置网页加载的进度条
          public void onProgressChanged(WebView view, int newProgress) {
            if (dialog_flag == true) {
              _showLoading();
              dialog_flag = false;
            }
            if (newProgress == 100) {
              dismissLoading();
              dialog_flag = true;
            }
          }

          // 设置应用程序的标题
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
          }
        });
    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    /*
     *
     * URL = ztspeechandroid://OAuthActivity?oauth_token=
     * f11203c98d813b227204254e3c148884&oauth_verifier=871525
     */
    web.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            LogInfo.LogOut(TAG, "WebView onPageStarted...");
            LogInfo.LogOut(TAG, "URL = " + url);
            if (url != null) {
              if (url.indexOf("checkType=verifycode") != -1) {
                int start = url.indexOf("checkType=verifycode&v=") + 23;
                String verifyCode = url.substring(start, start + 6);
                oAuth.setOauthVerifier(verifyCode);
                view.destroyDrawingCache();
                handler.sendMessage(
                    Message.obtain(
                        handler, ZtspeechWeiboManager.CONSTENT_TENCENT_WEIBO_REGIST, oAuth));
              } else if (url.contains("ztspeechandroid")) {
                // handler.sendMessage(Message.obtain(handler,
                // ZtspeechWeiboManager.CONSTENT_SINA_WEIBO_REGIST,
                // url));
              }
            }
            super.onPageStarted(view, url, favicon);
          }
        });
  }