Exemplo n.º 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);
    }
  }
Exemplo n.º 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;
            }
          }
        });
  }
Exemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.showevent_activity);
    layout = (LinearLayout) this.findViewById(R.id.show_mark);
    infotitle = (TextView) findViewById(R.id.toolbar_title);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setLogo(R.mipmap.ic_launcher);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    ab.setDisplayShowTitleEnabled(false);
    getSupportActionBar()
        .setDisplayShowHomeEnabled(
            true); // BACK botton which just available on Android 5.0, and have to set
                   // parentActivity.

    Bundle extras = getIntent().getExtras();

    String myURL = extras.getString("url");
    infotitle.setText(extras.getString("title"));

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

    WebSettings websettings = myBrowser.getSettings();
    websettings.setSupportZoom(true);
    websettings.setBuiltInZoomControls(true);
    websettings.setJavaScriptEnabled(true);

    myBrowser.setWebViewClient(new WebViewClient());
    myBrowser.loadUrl(myURL);
  }
Exemplo n.º 4
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);
   }*/
 }
  @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());
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
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);
   }
 }
  @TargetApi(8)
  private void load() {
    final String uri = getPath();
    final WebSettings settings = wv.getSettings();

    if (uri.endsWith(".swf") && ActivityUtil.isGreaterThan_2_1()) // android 2.2
    {
      wv.setWebChromeClient(new WebChromeClient());
      // settings.setPluginState(PluginState.ON);
      wv.loadUrl(uri);

      getSupportActionBar().setTitle("查看视频");
    } else { // images

      settings.setSupportZoom(true);
      settings.setBuiltInZoomControls(true);
      settings.setUseWideViewPort(true);
      if (ActivityUtil.isGreaterThan_2_1()) settings.setLoadWithOverviewMode(true);
      // settings.setUserAgentString(IPHONE_UA);
      wv.setWebViewClient(
          new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              // TODO Auto-generated method stub
              return false;
            }
          });
      wv.loadUrl(uri);
      getSupportActionBar().setTitle("查看图片");
    }
  }
Exemplo n.º 9
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;
  }
Exemplo n.º 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
    mContext = this;
    mUrl = getIntent().getStringExtra(EXTRA_URL);
    mTitle = getIntent().getStringExtra(EXTRA_TITLE);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setAppCacheEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new LoveClient());

    mWebView.loadUrl(mUrl);

    mTextSwitcher.setFactory(
        () -> {
          TextView textView = new TextView(this);
          textView.setTextAppearance(this, R.style.WebTitle);
          textView.setSingleLine(true);
          textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
          textView.postDelayed(() -> textView.setSelected(true), 1738);
          return textView;
        });
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
    if (mTitle != null) setTitle(mTitle);
  }
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    Bundle bundle = getIntent().getExtras();
    String url = bundle.getString("url");
    String title = bundle.getString("title");
    current_url = url;

    WebViewActivity.this.setTitle(title);

    final Context myApp = this;
    setContentView(R.layout.activity_webview);

    CookieSyncManager.createInstance(myApp);

    WebSettings settings = getWebView().getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    // settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);

    final WebView webview = (WebView) getWebView();
    webview.setWebViewClient(new MyWebViewClient());
    webview.setWebChromeClient(new MyWebChromeClient());

    webview.loadUrl(url);
  }
Exemplo n.º 12
0
  @SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    mWebView = (WebView) findViewById(R.id.id_webview);
    mText = (TextView) findViewById(R.id.id_tv);
    mButton = (Button) findViewById(R.id.id_btn);

    mButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            mWebView.loadUrl("javascript:javacalljs()");
          }
        });

    WebSettings webSettings = mWebView.getSettings();

    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new MyWebChromeClient());

    mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "android");
    mWebView.loadUrl("file:///android_asset/index.html"); // 转义符
  }
Exemplo n.º 13
0
  /**
   * @author lijing
   * @time 2014-7-22 下午3:31:38
   */
  private void initInfo() {
    webview = (WebView) layout.findViewById(R.id.webview);

    WebSettings webSettings = webview.getSettings(); // webView: 类WebView的实例
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setSupportZoom(true);
    // webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(true);

    webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // 就是这句
    pb = (ProgressBar) layout.findViewById(R.id.pb);
    pb.setMax(100);
    if (TextUtils.isEmpty(url)) return;
    webview.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    webview.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            pb.setProgress(newProgress);
            if (newProgress == 100) {
              pb.setVisibility(View.GONE);
            }
            super.onProgressChanged(view, newProgress);
          }
        });
    webview.loadUrl(url);
  }
Exemplo n.º 14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    webView = (WebView) findViewById(R.id.webview);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true); // 设置可以运行JS脚本
    //		settings.setTextZoom(120);//Sets the text zoom of the page in percent. The default is 100.
    settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    //		settings.setUseWideViewPort(true); //打开页面时, 自适应屏幕
    //		settings.setLoadWithOverviewMode(true);//打开页面时, 自适应屏幕
    settings.setSupportZoom(false); // 用于设置webview放大
    settings.setBuiltInZoomControls(false);
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {

            return false;
          }
        });
    new AsyncTask<String, Void, String>() {

      @Override
      protected String doInBackground(String... arg0) {
        BufferedReader bufferedReader = null;
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        String data = null;
        try {
          request.setURI(new URI(arg0[0]));
          HttpResponse response = client.execute(request);
          bufferedReader =
              new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
          StringBuffer sBuffer = new StringBuffer();
          String line = "";
          while ((line = bufferedReader.readLine()) != null) {
            sBuffer.append(line);
          }
          bufferedReader.close();
          data = sBuffer.toString();
        } catch (URISyntaxException e) {
          e.printStackTrace();
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        return data;
      }

      @Override
      protected void onPostExecute(String result) {
        webView.loadDataWithBaseURL(null, result, "text/html", "utf-8", null);
      }
    }.execute("http://baidu.com");
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_show_webview);

    String title = this.getIntent().getStringExtra("title");
    String url = this.getIntent().getStringExtra("url");

    backBtn = (Button) this.findViewById(R.id.backBtn);
    backBtn.setOnClickListener(this);

    shareBtn = (Button) this.findViewById(R.id.shareBtn);
    shareBtn.setOnClickListener(this);

    // 是否显示分享,默认不显示
    boolean showShareBtn = this.getIntent().getBooleanExtra("SHOW_SHARE", false);
    shareBtn.setVisibility(showShareBtn ? View.VISIBLE : View.GONE);

    titleTextView = (TextView) this.findViewById(R.id.titleTextView);
    titleTextView.setText(title);

    webView = (NoZoomControllWebView) this.findViewById(R.id.webview);
    WebSettings setting = webView.getSettings();

    setting.setJavaScriptEnabled(true);
    setting.setJavaScriptCanOpenWindowsAutomatically(true);

    setting.setSupportZoom(true);
    setting.setLoadsImagesAutomatically(true);

    setting.setBuiltInZoomControls(true);

    setting.setUseWideViewPort(true);
    setting.setLoadWithOverviewMode(true);
    setting.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);

    webView.loadUrl(url);

    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
  }
Exemplo n.º 16
0
  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);
    }
  }
Exemplo n.º 17
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webpage);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setElevation(0);
    setTitle(getIntent().getExtras().getString("name"));

    WebView wb = (WebView) findViewById(R.id.webView);
    wb.getSettings().setBuiltInZoomControls(true);
    wb.getSettings().setDisplayZoomControls(false);
    WebSettings webSettings = wb.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    wb.setWebViewClient(new WebViewClient());
    wb.loadUrl(checkURL(getIntent().getExtras().getString("address")));
  }
Exemplo n.º 18
0
 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
   setContentView(R.layout.main2);
   mWebView = (WebView) findViewById(R.id.webview);
   Bundle b = getIntent().getExtras();
   urll = b.getString("imageurl");
   width = b.getInt("width");
   height = b.getInt("height");
   WebSettings webSettings = mWebView.getSettings();
   webSettings.setJavaScriptEnabled(true);
   webSettings.setSupportZoom(true);
   mWebView.setWebChromeClient(new MyWebChromeClient());
   mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
   mWebView.getSettings().setJavaScriptEnabled(true);
   mWebView.loadUrl("file:///android_asset/maphub.html");
 }
Exemplo n.º 19
0
  // 初始化广告栏
  @SuppressLint("SetJavaScriptEnabled")
  private void initWebView() {
    webview = (WebView) _getView(R.id.acty_main_webview);
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);
    webSettings.setLoadsImagesAutomatically(true); // 自动加载图片
    webSettings.setBuiltInZoomControls(false);

    webview.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onLoadResource(WebView view, String url) {
            // toast("onLoadResource-->"+url);
          }

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 自行处理点击事件!
            Intent intent = new Intent(Main.this, Browser.class);
            intent.putExtra("url", url);
            openActivity(intent);
            return true;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            webview.setVisibility(View.INVISIBLE);
            isError = true;
          }
        });
    webview.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100 && !isError) {
              webview.setVisibility(View.VISIBLE);
            } else {
              webview.setVisibility(View.INVISIBLE);
            }
          }
        });
    webview.loadUrl(RestClient.BASE_URL + "/ad/index.html");
  }
Exemplo n.º 20
0
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.sousuoactivity1);

      editText = (EditText) findViewById(R.id.editText);
      tips = (TextView) findViewById(R.id.tips);
      submit1 = (Button) findViewById(R.id.submit);
      webView = (WebView) findViewById(R.id.toutput);

      webSettings = webView.getSettings();
      webSettings.setSaveFormData(false);
      webSettings.setSavePassword(false);
      webSettings.setSupportZoom(false);

      webView.setWebViewClient(
          new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
              return true;
            }
          });

      submit1.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Toast.makeText(Search.this, "aaaaaaaaaaaa", Toast.LENGTH_SHORT).show();
              if (editText.getText().toString().length() == 0) {
                Toast.makeText(Search.this, "请输入查询的词", Toast.LENGTH_SHORT).show();
                return;
              } else {
                tips.setVisibility(TextView.VISIBLE);
                webView.setVisibility(WebView.VISIBLE);
                handler.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        webView.loadUrl(
                            "http://www.baike.com/wiki/" + editText.getText().toString());
                      }
                    });
              }
            }
          });
    }
Exemplo n.º 21
0
  @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;
  }
Exemplo n.º 22
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");
  }
Exemplo n.º 23
0
  private void initView() {
    // To change body of created methods use File | Settings | File Templates.

    webView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    webView.setOnTouchListener(this);

    if (mNavLeftButton == null) {
      mNavLeftButton = (ImageView) findViewById(R.id.nav_left_image);
    }
    mNavLeftButton.setVisibility(View.VISIBLE);
    mNavLeftButton.setOnClickListener(this);

    loadData();
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);

    if (getArguments() != null) {
      mURL = getArguments().getString("URL");
    }

    if (mURL != null) {
      mWebView.loadUrl(mURL);
    }

    mWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            showProgressBar();
          }

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

    mWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            setProgressBar(newProgress);
          }
        });
  }
Exemplo n.º 25
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);
  }
Exemplo n.º 26
0
  // 初始化
  private void InitialComponent() {
    btnHome = (Button) findViewById(R.id.btnForgetPwdGoHome);
    btnHome.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            GoToHome(); // 回首頁
          }
        });

    wvForgetPwd = (WebView) findViewById(R.id.wvForgetPwd);
    wvForgetPwd.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    WebSettings websettings = wvForgetPwd.getSettings(); // 取得webview的設定
    websettings.setJavaScriptEnabled(true); // 預設會限制JavaScript,所以要打開他

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    progressbar = (ProgressBar) findViewById(R.id.myProgressBarForgetPwd);
    progressbar.setVisibility(View.VISIBLE);

    // 檢查有網路連線再讓她顯示讀取以及跑出網頁
    if (checkInternet(ActForgetPwd.this) == true) {
      progressBar = ProgressDialog.show(ActForgetPwd.this, "MarcOrder", "讀取中...");

      // 啟用內置的縮放功能.
      websettings.setSupportZoom(true);
      websettings.setBuiltInZoomControls(true);

      // 設定開啟的瀏覽器為目前的webView,避免打開或點其他網址的時候會用Chrome等其他瀏覽器開啟,使用者就無法停在此頁
      wvForgetPwd.setWebViewClient(mWebViewClient);

      wvForgetPwd.setWebChromeClient(mWebChromeClient); // 如果有標頭才有用
      wvForgetPwd.loadUrl("http://mymarcorder.azurewebsites.net/ForgetPassword.aspx");
      fun_thread(); // 同時偵測是否連線超過設定的秒數,免的因為讀取不到網頁而讓使用者一直卡在這頁
      // wvFans.loadUrl("https://m.facebook.com/mosburger.tw?_rdr");
      // wvFans.loadUrl("http://case.518.com.tw/workroom-index-1825771.html");
    }
    // 若沒有則不讓使用者連線
    else {
      MyToast.Show(ActForgetPwd.this, "偵測到網路連線不太穩定噢。\n檢查一下你的網路有沒有問題呦~^.<");
      fileList();
    }
  }
  private void initWebView() {
    //		try {
    //			System.out.println("yzj " + TuringUtils.decodeUnicode(wordApi("好")));
    //		} catch (JSONException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}

    myWebView = (WebView) findViewById(R.id.webview);
    myWebView.setInitialScale(200); // 为25%,最小缩放等级
    //		myWebView.setBackgroundColor(Color.argb(232, 0, 0, 0));
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.setOnKeyListener(
        new OnKeyListener() {
          @Override
          public boolean onKey(View arg0, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
              myWebView.goBack();
              return true;
            }
            return false;
          }
        });
    myWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            System.out.println("yzj ax onPageFinished = ");
            if (myWebView.getScrollX() != 215 && myWebView.getScrollY() != 160) {
              myWebView.scrollTo(215, 160);
            }
          }
        });
    SharedPreferences sp = tempContext.getSharedPreferences("SP", Context.MODE_PRIVATE);
    lastUrl = sp.getString("lastUrl", "http://www.baidu.com");
    myWebView.loadUrl(lastUrl);
  }
Exemplo n.º 28
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_PROGRESS);
    super.onCreate(savedInstanceState);
    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    webview.requestFocus();
    String authornizeUrl =
        OAuthConstants.OAUTH_V1_AUTHORIZE_URL + "?oauth_token=" + oauth.getOauthToken();
    webview.loadUrl(authornizeUrl);
    webview.setWebChromeClient(
        new WebChromeClient() {

          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            pb.setProgress(newProgress);
            if (newProgress == 100) {
              pb.setVisibility(View.GONE);
            }
          }
        });
    client =
        new WebViewClient() {

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (url.indexOf("checkType=verifycode") != -1) {
              int start = url.indexOf("checkType=verifycode&v") + 23;
              int end = start + 6;
              String verifyCode = url.substring(start, end);
              oauth.setOauthVerifier(verifyCode);
              Intent intent = new Intent();
              intent.putExtra("oauth", oauth);
              setResult(RESULT_CODE, intent);
              view.destroyDrawingCache();
              finish();
            }
          }
        };
    webview.setWebViewClient(client);
  }
Exemplo n.º 29
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    mWebView = (WebView) findViewById(R.id.webview);

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

    mWebView.setWebChromeClient(new MyWebChromeClient());

    mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");

    setCustomUserAgent();

    mWebView.loadUrl("file:///android_asset/demo.html");
  }
Exemplo n.º 30
0
  private void initWebView() {
    mSettings = webView.getSettings();
    mSettings.setSupportZoom(true); // 支持缩放
    mSettings.setBuiltInZoomControls(true); // 启用内置缩放装置
    // mSettings.setJavaScriptEnabled(true); // 启用JS脚本
    // 当点击链接时,希望覆盖而不是打开新窗口
    webView.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url); // 加载新的url
            return true; // 返回true,代表事件已处理,事件流到此终止
          };
        });
    // 点击后退按钮,让WebView后退一页(也可以覆写Activity的onKeyDown方法)
    webView.setOnKeyListener(
        new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
              if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                webView.goBack(); // 后退
                return true; // 已处理
              }
            }
            return false;
          }
        });

    webView.setWebChromeClient(
        new WebChromeClient() {
          // 当WebView进度改变时更新窗口进度
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            // Activity的进度范围在0到10000之间,所以这里要乘以100
            setProgress(newProgress * 100);
          }
        });
    webView.loadUrl(url); // 加载url
    webView.requestFocus(); // 获取焦点
  }