Exemple #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);
    }
  }
  @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);
  }
  /**
   * Convenience method to set some generic defaults for a given WebView
   *
   * @param webView
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
      // Hide the zoom controls for HONEYCOMB+
      settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }

    // We set the WebViewClient to ensure links are consumed by the WebView rather
    // than passed to a browser if it can
    webView.setWebViewClient(new WebViewClient());
  }
  @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());
  }
  @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("查看图片");
    }
  }
  @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);
  }
 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);
   }
 }
Exemple #8
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);
   }*/
 }
  @SuppressLint("SetJavaScriptEnabled")
  private void initView() {
    // TODO Auto-generated method stub
    product_detail_listview_image = (ImageView) findViewById(R.id.product_detail_listview_image);
    product_detail_listview_text_name =
        (TextView) findViewById(R.id.product_detail_listview_text_name);
    product_detail_listview_text_price =
        (TextView) findViewById(R.id.product_detail_listview_text_price);
    product_detail_listview_text_describe =
        (TextView) findViewById(R.id.product_detail_listview_text_describe);
    productWebView = (WebView) findViewById(R.id.product_webview);
    WebSettings webSettings = productWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

    webViewUtil = new WebViewUtil();

    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    options =
        new DisplayImageOptions.Builder()
            .displayer(new RoundedBitmapDisplayer(0xff000000, 10))
            .cacheInMemory()
            .cacheOnDisc()
            .build();

    product_detail_listview_text_name.setText(product.getProductName());
    product_detail_listview_text_price.setText(product.getProductPrice());
    product_detail_listview_text_describe.setText(product.getProductDescribe());
    imageLoader.displayImage(product.getImageUrl(), product_detail_listview_image, options);
  }
Exemple #10
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;
  }
Exemple #11
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d();
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mBrowser = this;

    mVizWebViewClient = new VizWebViewClient(this);
    mWebChromeClient = new VizWebChromeClient(this);

    mVizWebView = new WebView(getActivity()); // get attributes?
    mVizWebView.setWebViewClient(mVizWebViewClient);
    mVizWebView.setWebChromeClient(mWebChromeClient);
    if (savedInstanceState != null) {
      Log.d("restoring web view state");
      mVizWebView.restoreState(savedInstanceState);
    }
    WebSettings s = mVizWebView.getSettings();
    s.setJavaScriptEnabled(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setBuiltInZoomControls(true);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSaveFormData(true);

    mVizWebView.setId(61377); // PhoneWindow complained about no id (focus couldn't be saved)

    // Loading homepage here results in an exception on ICS, not sure why.
    // Update: post-poning until onCreatingView doesn't entirely fix the
    // issue either.
    // mVizWebView.loadUrl(defaultURL);
  }
  private void initViewer() {
    settings.setLoadsImagesAutomatically(true);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLightTouchEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);

    viewer.setInitialScale(0);
    viewer.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    viewer.setHorizontalScrollBarEnabled(false);
    viewer.setVerticalScrollBarEnabled(false);
    viewer.setBackgroundColor(0x000000);
    viewer.clearCache(true);
    viewer.setFocusable(false);

    viewer.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {}

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {}

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    edtUrl = (EditText) findViewById(R.id.Input_Text);
    btnGo = (Button) findViewById(R.id.Go_Btn);
    btnBack = (Button) findViewById(R.id.Back_Btn);
    web = (WebView) findViewById(R.id.webView1);

    web.setWebViewClient(new CookWebViewClient());

    WebSettings webSet = web.getSettings();
    webSet.setBuiltInZoomControls(true);

    btnGo.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View v) {
            web.loadUrl("http://" + edtUrl.getText().toString());
          }
        });

    btnBack.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View v) {
            web.goBack();
          }
        });
  }
  @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");
  }
Exemple #15
0
  /** Sets up the WebView object and loads the URL of the page * */
  private void setupWebView() {

    final WebView webview = getWebView();
    webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setWebViewClient(new MapWebViewClient(getActivity()));
    loadUrl(mUri.toString());

    final WebSettings settings = webview.getSettings();
    settings.setBuiltInZoomControls(false);

    /** Allows JavaScript calls to access application resources * */
    webview.addJavascriptInterface(new JavaScriptInterface(), "android");
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_innerweb);
    ButterKnife.bind(this);

    StatusBarHelper.setStatusBar(this);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    WebSettings webSettings = wbInnerweb.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSaveFormData(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    wbInnerweb.requestFocus();
    wbInnerweb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    wbInnerweb.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.indexOf("tel:") < 0) {
              view.loadUrl(url);
            }
            return true;
          }

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            pbLoading.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            pbLoading.setVisibility(View.GONE);
            wbInnerweb.setVisibility(View.VISIBLE);
            super.onPageFinished(view, url);
          }
        });

    mUrl = getIntent().getStringExtra(PARAM_WEB_URL);
    wbInnerweb.loadUrl(mUrl);
  }
  /* Initialize the Web view with some custom web settings that's helpful in previewing web data */
  private void initWebView(final String content) {

    WebViewClient wvClient = new BaseWebviewClient(this);
    webView.setWebViewClient(wvClient);

    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);

    final String mimeType = "text/html";
    final String encoding = "UTF-8";

    webView.loadDataWithBaseURL("", content, mimeType, encoding, "");
  }
  /** 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);
  }
  @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;
          }
        });
  }
Exemple #20
0
 @SuppressLint("NewApi")
 private void init() {
   initBackBtn();
   WebView wv = (WebView) findViewById(R.id.wv);
   // wv.getSettings()// ¿ÉÓÃJS
   WebSettings ws = wv.getSettings();
   // ws.setJavaScriptEnabled(true);
   ws.setBuiltInZoomControls(true);
   if (Build.VERSION.SDK_INT >= 11) {
     ws.setDisplayZoomControls(true);
   }
   wv.setScrollBarStyle(0);
   wv.getSettings().setLoadWithOverviewMode(true);
   wv.getSettings().setUseWideViewPort(true);
   wv.loadUrl("file:///android_asset/about.html");
 }
Exemple #21
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");
  }
Exemple #22
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_about_app);
   about = (WebView) findViewById(R.id.about_webview);
   WebSettings webSettings = about.getSettings();
   // 设置WebView属性,能够执行Javascript脚本
   webSettings.setJavaScriptEnabled(true);
   // 设置可以访问文件
   webSettings.setAllowFileAccess(true);
   // 设置支持缩放
   webSettings.setBuiltInZoomControls(true);
   // 设置Web视图
   about.setWebViewClient(new webViewClient());
   // 加载需要显示的网页
   about.loadUrl(
       "http://mp.weixin.qq.com/s?__biz=MzA4ODY3MTU0MQ==&mid=401741723&idx=1&sn=a58c3652f9373edc095a605b64215006#rd");
 }
Exemple #23
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;
  }
Exemple #24
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView");

    // Inflate layout of the dialog
    View rootView =
        inflater.inflate(
            R.layout.sso_dialog,
            container,
            false); // null parent view because it will go in the dialog layout
    mSsoWebView = (WebView) rootView.findViewById(R.id.sso_webview);

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    if (savedInstanceState == null) {
      Log_OC.d(TAG, "   initWebView start");
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);
      cookieManager.removeAllCookie();
      mSsoWebView.loadUrl(mInitialUrl);

    } else {
      Log_OC.d(TAG, "   restoreWebView start");
      WebBackForwardList history =
          mSsoWebView.restoreState(savedInstanceState.getBundle(KEY_WEBVIEW_STATE));
      if (history == null) {
        Log_OC.e(TAG, "Error restoring WebView state ; back to starting URL");
        mSsoWebView.loadUrl(mInitialUrl);
      }
    }

    WebSettings webSettings = mSsoWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setSavePassword(false);
    webSettings.setUserAgentString(WebdavClient.USER_AGENT);
    webSettings.setSaveFormData(false);

    return rootView;
  }
  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");
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.instagram_demo_login);

    ButterKnife.bind(this);

    String cookieHost = Uri.parse(authInstragramLogin).getHost();
    configureCookies(cookieHost);

    WebViewClient wvClient = new CIAWebViewClient(this);
    webView.setWebViewClient(wvClient);

    final WebSettings settings = webView.getSettings();
    settings.setUserAgentString(BaseClient.USER_AGENT);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
  }
Exemple #27
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.web_layout);
   // ����ַ
   webView = (WebView) findViewById(R.id.web_view);
   webView.loadUrl(getIntent().getStringExtra("url"));
   WebSettings websettings = webView.getSettings();
   websettings.setJavaScriptEnabled(true); // Warning! You can have XSS vulnerabilities!
   websettings.setBuiltInZoomControls(true);
   webView.setWebViewClient(
       new WebViewClient() {
         @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url); // ���ݴ���ȥ�IJ������¼�����ҳ
           return true; // ��ʾ����Ҫ����ϵͳ�������
         }
       });
 }
  @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);
          }
        });
  }
Exemple #29
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();
    }
  }
  @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);
  }