Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ConnectivityManager connec =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connec != null && (connec.getNetworkInfo(1).isAvailable() == true)
        || (connec.getNetworkInfo(0).isAvailable() == true)) {
      this.setTitle("New Friend..");

      Parse.initialize(
          this,
          "PV07xPdLpxzJKBKUS2UP6iJ0W9GbEHvmfPMMQovz",
          "OPxrcJKt4Pe26WHvCAeuI86hnGzXjOlO1NmyfJyP");

      WebView myWebView = (WebView) findViewById(R.id.webView1);
      myWebView.loadUrl("http://www.markevansjr.com/AndroidApp/index.html");

      WebSettings webSettings = myWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");

      myWebView.setWebViewClient(new WebViewClient());
    } else {
      Toast toast = Toast.makeText(this, "NO CONNECTION", Toast.LENGTH_SHORT);
      toast.show();
    }
  }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gives_detail);
    iv = (ImageView) findViewById(R.id.iv);
    tv = (TextView) findViewById(R.id.tv);
    wv = (WebView) findViewById(R.id.wv);
    Intent intent = getIntent();
    gives = intent.getParcelableExtra("gives");
    String imgUrl = gives.getGImgUrl();
    ImageLoaderUtil.display(imgUrl, iv);
    tv.setText(gives.getGDescription());

    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    wv.setWebChromeClient(new WebChromeClient());
    wv.setWebViewClient(new WebViewClient());
    String url =
        "http://m.amap.com/?q="
            + gives.getGLatitude()
            + ","
            + gives.getGLongitude()
            + "&name="
            + gives.getGLocation()
            + "&view=detail"
            + "&key=5c8577b8ad3565cc7ea726272888efca";
    wv.loadUrl(url);
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Window win = this.getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

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

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

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

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

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

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

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

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

    MainWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              QuotaUpdater quotaUpdater) {
            Log.i(TAG, "estimatedSize=" + estimatedSize);
            quotaUpdater.updateQuota(estimatedSize * 2);
          }
        });
    MainWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView webView, String url) {
            // String lang = getLangCode(getLocale());
            // MainWebView.loadUrl("javascript:setLanguage('"+lang+"');");
          }
        });
  }
  /** Called to instantiate the view. Creates and returns the WebView. */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mWebView != null) {
      mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    View myFragmentView = inflater.inflate(R.layout.news_feed_fragment, container, false);
    progress = ProgressDialog.show(getActivity(), "Loading", "Please wait...", true);

    mWebView.setWebViewClient(
        new InnerWebViewClient() {
          public void onPageFinished(WebView view, String url) {
            if (progress != null) {
              progress.dismiss();
            }
            super.onPageFinished(view, url);
          }
        }); // forces it to open in app
    mWebView.loadUrl(mUrl);
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);

    return mWebView;
  }
  @SuppressLint("SetJavaScriptEnabled")
  private void initWebView() {
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDefaultTextEncodingName("utf-8");
    mWebView.setWebViewClient(
        new WebViewClient() {
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            AppLog.e(T.EDITOR, description);
          }
        });
    mWebView.setWebChromeClient(
        new WebChromeClient() {
          public boolean onConsoleMessage(ConsoleMessage cm) {
            AppLog.e(
                T.EDITOR,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }

          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            AppLog.e(T.EDITOR, message);
            return true;
          }

          @Override
          public void onConsoleMessage(String message, int lineNumber, String sourceId) {
            AppLog.e(T.EDITOR, message + " -- from line " + lineNumber + " of " + sourceId);
          }
        });
    String htmlEditor = getHtmlEditor();
    mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", "");
  }
 private dd(Context context, ab abVar, boolean z, boolean z2, l lVar, db dbVar) {
   super(context);
   this.mg = new Object();
   this.pZ = context;
   this.mF = abVar;
   this.qb = z;
   this.nP = lVar;
   this.mG = dbVar;
   setBackgroundColor(0);
   WebSettings settings = getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setSavePassword(false);
   settings.setSupportMultipleWindows(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   cv.a(context, dbVar.pU, settings);
   if (VERSION.SDK_INT >= 17) {
     cx.a(getContext(), settings);
   } else if (VERSION.SDK_INT >= 11) {
     cw.a(getContext(), settings);
   }
   setDownloadListener(this);
   if (VERSION.SDK_INT >= 11) {
     this.pY = new dg(this, z2);
   } else {
     this.pY = new de(this, z2);
   }
   setWebViewClient(this.pY);
   if (VERSION.SDK_INT >= 14) {
     setWebChromeClient(new dh(this));
   } else if (VERSION.SDK_INT >= 11) {
     setWebChromeClient(new df(this));
   }
   bf();
 }
Пример #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lesson);

    wv = (WebView) findViewById(R.id.wv_lesson);
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);

    pref = getSharedPreferences("user", Context.MODE_PRIVATE);

    new Thread() {
      public void run() {
        String s = null;
        try {
          s =
              MyUtils.postHtml(
                  "http://awaydian.top/app/index.php?m=njust&a=lesson",
                  "id="
                      + pref.getString("jwc_id", null)
                      + "&psw="
                      + pref.getString("jwc_psw", null),
                  null);

        } catch (Exception e) {
          s = "网络出现问题";
          e.printStackTrace();
        }
        Message msg = new Message();
        msg.obj = s;
        handler.sendMessage(msg);
      }
    }.start();
  }
Пример #8
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"); // 转义符
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String targetURL = "https://m.facebook.com/";

    if (getIntent().getExtras() != null) {
      String url = getIntent().getExtras().getString("url", "");
      if (!"".equals(url)) {
        targetURL = url;
      }
    }

    WakeupManager.updateNotificationSystem(this);

    webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient());
    webview.loadData("<h1>" + getString(R.string.request_pending) + "</h1>", "text/html", "UTF-8");
    webview.setWebViewClient(new WebViewClient());
    WebSettings webSettings = webview.getSettings();
    webSettings.setBlockNetworkImage(false);
    webSettings.setUserAgentString(getString(R.string.app_name));
    webview.loadUrl(targetURL);
    setContentView(webview);
  }
  private void loadAndPlayVideo() {
    if (popUpViewVideo == null) {
      popUpViewVideo = layoutInflater.inflate(R.layout.fragment_video, null);
      webView = (WebView) popUpViewVideo.findViewById(R.id.webview2);
      WebSettings webSettings = webView.getSettings();
      webSettings.setPluginState(WebSettings.PluginState.ON);
      webSettings.setJavaScriptEnabled(true);
      String html = getHTML(getVideoURL());

      webView.loadData(html, "text/html", "utf-8");
      webView.setWebViewClient(
          new WebViewClient() {

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

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

      videoPopup = popupWindow(popUpViewVideo, true);
    }
    mDrawerLayout.closeDrawer(mDrawerList);
  }
Пример #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // 保持屏幕亮
    //		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //				WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    webview = (WebView) super.findViewById(R.id.webView);
    progress = (ProgressBar) super.findViewById(R.id.progress);
    // progress.setVisibility(View.GONE);
    webview.setWebChromeClient(new WebChromeClientImpl(handler));
    webview.setWebViewClient(wc);
    // webview.setInitialScale(25);
    ws = webview.getSettings();
    ws.setJavaScriptCanOpenWindowsAutomatically(true);
    ws.setJavaScriptEnabled(true);
    ws.setPluginState(PluginState.ON);
    ws.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    Log.i("---", "加载");
    // ws.setSupportZoom(true);
    // ws.setBuiltInZoomControls(true);//设置支持缩放
    // ws.setUseWideViewPort(true);
    webview.loadUrl("http://aaaadc.com");
    // webview.loadUrl("http://www.oceanthree.hk/apps_shop/app_index.php");

  }
 /** * 初始化内容控件 */
 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);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // ------------------to be removed after connecting the activities

    Intent myIntent1 = new Intent(this, UserData.class);
    this.startActivity(myIntent1);

    // -------------

    final WebView myWebView = (WebView) findViewById(R.id.webView1);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.setWebChromeClient(new WebChromeClient());

    final EditText url = (EditText) findViewById(R.id.editText1);

    final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            myWebView.loadUrl(" file:///android_asset/index.html");
          }
        });
  }
Пример #14
0
  @SuppressWarnings("deprecation")
  @SuppressLint("SetJavaScriptEnabled")
  public static void loadUrlAdaptiveScreen(
      Context mContext, WebView webview, String url, boolean javaScriptEnabled) {
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(javaScriptEnabled);
    // 自适应屏幕
    // 第一种:
    // WebSetting settings = webView.getSettings();
    // settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    // 把所有内容放在webview等宽的一列中。(可能会出现页面中链接失效)
    // 第二种:
    // settings.setUseWideViewPort(true);
    // settings.setLoadWithOverviewMode(true);
    // 第三种:
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity <= 120) {
      webSettings.setDefaultZoom(ZoomDensity.CLOSE);
    } else if (mDensity > 120 && mDensity < 240) {
      webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity >= 240) {
      webSettings.setDefaultZoom(ZoomDensity.FAR);
    }

    webview.setWebViewClient(new WebViewClient());
    webview.loadUrl(url);
  }
Пример #15
0
  private void setData() {
    webView.setVisibility(View.VISIBLE);
    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultFontSize(16);
    webView.requestFocusFromTouch(); // 支持获取手势焦点
    webView.setWebViewClient(
        new WebViewClient() { // 打开网页时不调用系统浏览器, 而是在本WebView中显示
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
          }
        });

    webView.loadDataWithBaseURL(null, CONTENT, "text/html", "UTF-8", null);
    dialog.cancel();
  }
Пример #16
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);
  }
  @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("查看图片");
    }
  }
Пример #18
0
  @Override
  public void initComponents() {
    wvUrl = (WebView) innerView.findViewById(R.id.wvUrl);
    WebSettings ws = wvUrl.getSettings();
    ws.setAllowFileAccess(true);
    ws.setAppCacheEnabled(true);
    ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    ws.setBuiltInZoomControls(false);
    ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    ws.setDisplayZoomControls(false);
    ws.setJavaScriptEnabled(true);
    ws.setSupportZoom(false);
    ws.setDefaultTextEncodingName("GBK");

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

                  @Override
                  public void run() {
                    view.loadUrl(url);
                  }
                });
            return false;
          }
        });
    wvUrl.setWebChromeClient(new WebChromeClient());
  }
Пример #19
0
 private void setupWebview() {
   webview = (WebView) findViewById(R.id.main_webview);
   WebSettings webSettings = webview.getSettings();
   webSettings.setJavaScriptEnabled(true);
   webview.addJavascriptInterface(this, "hostapp");
   webview.loadUrl(getResources().getString(R.string.app_url));
 }
Пример #20
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);
  }
Пример #21
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("file:///android_asset/example.html");
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webView.getSettings().setDomStorageEnabled(true);

    webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    webView.getSettings().setAppCachePath(appCachePath);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);

    webView.setWebChromeClient(
        new WebChromeClient() {

          @Override
          public void onConsoleMessage(String message, int lineNumber, String sourceID) {
            super.onConsoleMessage(message, lineNumber, sourceID);
            Log.d("MyApplication", message + " -- From line " + lineNumber + " of " + sourceID);
          }
        });
  }
Пример #22
0
  @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();
          }
        });
  }
Пример #23
0
  private void init() {
    webView = (WebView) findViewById(R.id.webView);
    // WebView加载的是本地资源
    //        webView.loadUrl("file:///android_asset/example.html");
    // WebView加载的是Web资源
    webView.loadUrl("http://www.baidu.com");
    webView.loadUrl(url);
    // 覆盖WebView默认通过第三方或者是系统浏览器打开网页的行为,使得网页可以在VebView中打开
    webView.setWebViewClient(
        new WebViewClient() {
          // 返回值为true的时候,控制网页在WebView中打开,当WebView为false的时候,调用第三方或者是系统的浏览器打开
          // WebViewClient帮助WebView处理一些页面控制和请求通知
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    // 启用JavaScript
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

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

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

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

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

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

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

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

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

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

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

    //        }

    return rootView;
  }
Пример #25
0
 @SuppressLint("SetJavaScriptEnabled")
 public static void loadUrl(
     Context mContext, WebView webview, String url, boolean javaScriptEnabled) {
   WebSettings webSettings = webview.getSettings();
   webSettings.setJavaScriptEnabled(javaScriptEnabled);
   webview.setWebViewClient(new WebViewClient());
   webview.loadUrl(url);
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mWebView != null) {
      mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    mIsWebViewAvailable = true;

    webView = getWebView();
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
          }

          @Override
          public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            Log.d("EnterActivityData", "Url: " + url);

            return super.shouldInterceptRequest(view, url);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            parent.hideProgressBar();
          }
        });
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebChromeClient(
        new WebChromeClient() {
          public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d(
                "EnterActivityData",
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        });

    if (savedInstanceState == null) {
      Bundle args = new Bundle();
      args.putString(ARG_ACTIVITY_ID, activityId);
      getLoaderManager().initLoader(ACTIVITY_LOADER_ID, args, this);
      getLoaderManager().initLoader(SITES_LOADER_ID, null, this);
    } else {
      activityId = savedInstanceState.getString(ARG_ACTIVITY_ID);
      activity = savedInstanceState.getString("activity");
      sites = savedInstanceState.getString("sites");
      activityUrl = savedInstanceState.getString("activityUrl");
      siteToSave = savedInstanceState.getParcelable("newSite");
      themes = savedInstanceState.getString("themes");

      tryLoadPage();
    }
    return mWebView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_webview);

    mWebView = (WebView) findViewById(R.id.webview);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);

    mWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (URLUtil.isNetworkUrl(url)) {
              if (mLoadingProgressBar != null) {
                mLoadingProgressBar.setVisibility(View.VISIBLE);
                mLoadingProgressBar.startAnimation(
                    AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_in));
              }
              view.loadUrl(url);
            } else {
              // Otherwise allow the OS to handle things like tel, mailto, etc.
              Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
              startActivity(intent);
            }
            return true;
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            if (mLoadingProgressBar != null) {
              mLoadingProgressBar.setVisibility(View.GONE);
              mLoadingProgressBar.startAnimation(
                  AnimationUtils.loadAnimation(WebViewActivity.this, R.anim.abc_fade_out));
            }
          }
        });

    Intent intent = getIntent();
    if (intent != null) {
      String url = intent.getStringExtra(DATA_URL);
      if (URLUtil.isNetworkUrl(url)) {
        mWebView.loadUrl(url);
      }

      String title = intent.getStringExtra(DATA_TITLE);
      if (!TextUtils.isEmpty(title)) {
        setTitle(title);
      }
    }

    mLoadingProgressBar = getToolbar().findViewById(R.id.toolbar_progress_bar);
    mLoadingProgressBar.setVisibility(View.VISIBLE);
  }
  @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");
  }
 private void createWebView() {
   mWebView = new WebView(this);
   mWebView.setInitialScale(300);
   mWebView.measure(800, 1280);
   mWebView.layout(0, 0, 800, 1280);
   WebSettings webSettings = mWebView.getSettings();
   webSettings.setJavaScriptEnabled(false);
   mWebView.setBackgroundColor(0xff202020);
 }
Пример #30
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(final Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_reader);

    final int apiVersion = android.os.Build.VERSION.SDK_INT;
    if (apiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      getActionBar().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
      getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.WHITE));
    }

    syndicationName = getIntent().getStringExtra("syndicationName");

    if (TextUtils.isEmpty(syndicationName)) {
      getActionBar().setTitle(Html.fromHtml("<b><u>" + getTitle().toString() + "</u><b>"));
    } else {
      getActionBar().setTitle(Html.fromHtml("<b><u>" + syndicationName + "</u><b>"));
    }

    publicationTitle = getIntent().getStringExtra("title");
    if (!TextUtils.isEmpty(publicationTitle)) {
      final TextView tv = (TextView) findViewById(R.id.reader_title);
      tv.setTypeface(TypeFaceSingleton.getInstance(this).getUserTypeFace(), Typeface.BOLD);

      tv.setText(publicationTitle);
      getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    }

    getActionBar().setBackgroundDrawable(new ColorDrawable(0xeeeeee));
    getActionBar().setStackedBackgroundDrawable(new ColorDrawable(0xeeeeee));

    final String text = getIntent().getStringExtra("read");
    link = getIntent().getStringExtra("link");
    isFavorite = getIntent().getBooleanExtra("isFavorite", false);
    publicationId = getIntent().getIntExtra("publicationId", -1);
    syndicationId = getIntent().getIntExtra("syndicationId", -1);

    final WebView webView = (WebView) findViewById(R.id.reader);
    final WebSettings settings = webView.getSettings();
    settings.setAllowFileAccess(true);
    settings.setDefaultTextEncodingName("utf-8");

    // For enable video
    webView.setWebChromeClient(new WebChromeClient());

    settings.setJavaScriptEnabled(true);

    settings.setDefaultFontSize(
        TypeFaceSingleton.getInstance(getApplicationContext()).getUserFontSize());

    webView.loadDataWithBaseURL(null, getHtmlData(text), "text/html", "utf-8", null);

    publicationRepository = new PublicationRepository(this);
  }