Пример #1
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;
  }
Пример #2
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);
  }
Пример #3
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);
  }
Пример #4
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;
            }
          }
        });
  }
  @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());
  }
Пример #6
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);
   }
 }
Пример #7
0
  @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);
  }
Пример #8
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);
  }
 /** * 初始化内容控件 */
 private void initWeb() {
   // TODO Auto-generated method stub
   String release = android.os.Build.VERSION.RELEASE;
   release = release.substring(0, 3);
   if ("4.4".equals(release)) {
     web_content.setWebViewClient(new MyWebViewClient());
   } else {
     web_content.setVisibility(View.VISIBLE);
     WebSettings ws = web_content.getSettings();
     ws.setJavaScriptEnabled(true);
     ws.setAllowFileAccess(true);
     ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
     ws.setDefaultTextEncodingName("utf-8");
     ws.setTextSize(TextSize.NORMAL);
     ws.setAppCacheEnabled(false);
     ws.setDomStorageEnabled(true);
     if (android.os.Build.VERSION.SDK_INT >= 8) {
       ws.setPluginState(PluginState.ON);
     }
     ws.setRenderPriority(RenderPriority.HIGH);
     web_content.setWebViewClient(new WebViewClientDemo());
     web_content.setWebChromeClient(new WebViewChromeClientDemo());
     web_content.loadDataWithBaseURL("", unit.getIntroduce(), "text/html", "utf-8", null);
   }
 }
Пример #10
0
  public synchronized void initPreferences() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    WebSettings webSettings = getSettings();

    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);

    webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true));
    webSettings.setJavaScriptEnabled(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setJavaScriptCanOpenWindowsAutomatically(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true));
    webSettings.setSupportMultipleWindows(
        sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
    webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

    boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
    if (textReflow) {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } catch (Exception e) {
        }
      }
    } else {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    }

    int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
    if (userAgent == 1) {
      webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
    } else if (userAgent == 2) {
      webSettings.setUserAgentString(
          sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal));
    } else {
      webSettings.setUserAgentString(userAgentOriginal);
    }

    int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0"));
    initRendering(mode);

    webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true));
  }
  @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_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // WebView
    mwebView = (WebView) findViewById(R.id.myWebView);
    WebSettings webSettings = mwebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // improve webView performance
    mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mwebView.getSettings().setAppCacheEnabled(true);
    mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setEnableSmoothTransition(true);

    mwebView.loadUrl("http://www.newsweek.com");
    // force links open in webview only
    mwebView.setWebViewClient(new MyWebviewClient());
  }
Пример #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    // -------------------------------TabView
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    // --------------------------------------

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // WebView
    mwebView = (WebView) findViewById(R.id.myWebView);
    WebSettings webSettings = mwebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // improve webView performance
    mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mwebView.getSettings().setAppCacheEnabled(true);
    mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setEnableSmoothTransition(true);

    mwebView.loadUrl("http://www.newsweek.com");
    // force links open in webview only
    mwebView.setWebViewClient(new MyWebviewClient());
  }
Пример #14
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   WebView webView = (WebView) findViewById(R.id.web_view);
   Log.e("TAG", webView.getSettings().getDefaultTextEncodingName());
   WebSettings settings = webView.getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setDefaultTextEncodingName("utf-8");
   settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
   //        webView.loadData(Url.url, "text/html;charset=UTF-8", null);
   String str = "<head><link rel=\"stylesheet\" href=\"wcss.css\" type=\"text/css\" /></head>";
   webView.loadDataWithBaseURL("", Url.url, "text/html;charset=UTF-8", "", "");
 }
Пример #15
0
  @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);
  }
  /** Create and initialize web container. */
  public void init() {
    LOG.d(TAG, "DroidGap.init()");

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

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

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

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

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

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

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

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

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

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

    // Clear cancel flag
    this.cancelLoadUrl = false;
  }
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    dialog = new LoadingDialog(this);
    dialog.show();
    setContentView(R.layout.fragment_user_help);
    webView = (WebView) findViewById(R.id.fragment_user_help_webview);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // webSettings.setBuiltInZoomControls(true);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    webViewUtil = new WebViewUtil();
    new HelpAsyncTask().execute("");
    setEdgeFromLeft();
  }
Пример #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);
  }
  @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);
  }
Пример #20
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_web);
   ButterKnife.bind(this);
   mToolbar.setTitle(mTitle);
   setSupportActionBar(mToolbar);
   ActionBar actionBar = getSupportActionBar();
   if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
   mUrl = getIntent().getStringExtra(EXTRA_URL);
   mTitle = getIntent().getStringExtra(EXTRA_TITLE);
   mWebView = new WebView(getApplicationContext());
   mRelativeLayout.addView(mWebView);
   WebSettings settings = mWebView.getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setLoadWithOverviewMode(true);
   settings.setAppCacheEnabled(true);
   settings.setSupportZoom(true);
   settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
   mWebView.setWebChromeClient(new ChromeClient());
   mWebView.setWebViewClient(new ViewClient());
   mWebView.loadUrl(mUrl);
 }
Пример #21
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    if (fullescreen) {
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }

    // This builds the view. We could probably get away with NOT having a
    // LinearLayout, but I like having a bucket!
    // Display display = getWindowManager().getDefaultDisplay();
    // int width = display.getWidth();
    // int height = display.getHeight();

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

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

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

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

    WebViewReflect.checkCompatibility();

    /*
     * This changes the setWebChromeClient to log alerts to LogCat!
     * Important for Javascript Debugging
     */
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ECLAIR) {
      appView.setWebChromeClient(new AppWebChromeClient());
    }
    appView.setWebViewClient(new AppWebViewClient());

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

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

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

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

    /* Bind the appView object to the gap class methods */
    buildWebView(appView);

    root.addView(appView);
    setContentView(root);

    // If url was passed in to intent, then init webview, which will load
    // the url
    Bundle bundle = this.getIntent().getExtras();
    if (bundle != null) {
      String path = bundle.getString("path");
      if (path != null) {
        this.initPath = path;
      }
      String surl = bundle.getString("serverUrl");
      if (surl != null && surl.length() > 0) {
        bindServerUrl(surl);
      }
    }
    // Setup the hardware volume controls to handle volume control
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
Пример #22
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_details);

    Intent i = getIntent();
    String style = i.getStringExtra("style");

    // 设定状态栏的颜色,当版本大于4.4时起作用
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      SystemBarTintManager tintManager = new SystemBarTintManager(this);
      tintManager.setStatusBarTintEnabled(true);
      // 此处可以重新指定状态栏颜色
      if (style != null) {
        tintManager.setStatusBarTintColor(Color.parseColor(style));
      } else {
        tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);
      }
    }

    url = i.getStringExtra("url");

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitleTextColor(Color.WHITE);
    String title = i.getStringExtra("title");
    if (title != null) {
      mToolbar.setTitle(title);
    } else {
      mToolbar.setTitle("正在加载...");
    }

    if (style != null) {
      mToolbar.setBackgroundColor(Color.parseColor(style));
    }

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

    final ProgressBar pbBar = (ProgressBar) findViewById(R.id.pbWebView);

    wvNews = (WebView) findViewById(R.id.webViewNews);
    WebSettings settings = wvNews.getSettings();
    // 适应屏幕
    settings.setUseWideViewPort(true);
    //        settings.setSupportZoom(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    //      settings.setLoadWithOverviewMode(true);
    //      settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    wvNews.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
              pbBar.setVisibility(View.INVISIBLE);
              LinearLayout.LayoutParams linearParams =
                  (LinearLayout.LayoutParams) pbBar.getLayoutParams(); // 取控件pbBar当前的布局参数
              linearParams.height = 0; // 当控件的高强制设成0象素
              pbBar.setLayoutParams(linearParams);
            } else {
              if (View.INVISIBLE == pbBar.getVisibility()) {
                pbBar.setVisibility(View.VISIBLE);
              }
              pbBar.setProgress(newProgress);
            }
            super.onProgressChanged(view, newProgress);
          }

          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            getSupportActionBar().setTitle(title);
          }
        });

    // wvNews.loadDataWithBaseURL("about:blank", newsHtml.toString(), "text/html", "utf-8", null);
    wvNews.loadUrl(url);
    // wvNews.loadDataWithBaseURL("about:blank", i.getStringExtra("context"), "text/html", "utf-8",
    // null);//读取intent传过来的本地网页数据

  }
Пример #23
0
  @SuppressLint("SetJavaScriptEnabled")
  @SuppressWarnings("deprecation")
  private void initWebViewSettings() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    // TODO: The Activity is the one that should call requestFocus().
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    // Enable JavaScript
    final WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

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

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

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

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

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

    settings.setGeolocationDatabasePath(databasePath);

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

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

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

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

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
      this.receiver =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              settings.getUserAgentString();
            }
          };
      getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
  }
Пример #24
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    // This builds the view.  We could probably get away with NOT having a LinearLayout, but I like
    // having a bucket!

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

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

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

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

    WebViewReflect.checkCompatibility();

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

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

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

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

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

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

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

    root.addView(appView);

    setContentView(root);
  }
Пример #25
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

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

    // Navbar setup

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

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

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

              doNav();

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

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

    urlField.setText(lastUrl);

    // Navbar animation settings

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

          @Override
          public void onAnimationRepeat(Animation animation) {}

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

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

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

    // WebView setup

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

    WebSettings webSettings = webView.getSettings();

    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(
        new WebViewClient() {

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

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

            Log.d("pageFinished", url);

            view.setInitialScale(70);

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

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

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

            if (newScale > 0.7) {

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

            }
          }
        });

    webView.setInitialScale(70);

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

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

    webSettings.setSupportZoom(true);

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

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

    webView.requestFocus();
  }