private void startWebView(String url) {
    webView.setWebViewClient(
        new WebViewClient() {
          ProgressDialog progressDialog;

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

          public void onLoadResource(WebView view, String url) {
            if (progressDialog == null) {
              // in standard case YourActivity.this
              progressDialog = new ProgressDialog(MainActivity.this);
              progressDialog.setMessage("Loading...");
              progressDialog.show();
            }
          }

          public void onPageFinished(WebView view, String url) {
            try {
              if (progressDialog.isShowing()) {
                view.clearCache(true);
                progressDialog.dismiss();
                progressDialog = null;
              }
            } catch (Exception exception) {
              exception.printStackTrace();
            }
          }
        });

    /*
    String sayfa = "<html><body><h1>your own html</h1></body></html>";
    webView.loadData(sayfa, "text/html", null);
    */

    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);

    webView.loadUrl(url);
  }
예제 #2
0
  protected void initWebViewSettings(WebView w) {
    w.setScrollbarFadingEnabled(true);
    w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    w.setMapTrackballToArrowKeys(false); // use trackball directly
    // Enable the built-in zoom
    w.getSettings().setBuiltInZoomControls(true);
    /// M: Add to disable overscroll mode
    w.setOverScrollMode(View.OVER_SCROLL_NEVER);
    final PackageManager pm = mContext.getPackageManager();
    boolean supportsMultiTouch =
        pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)
            || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT);
    w.getSettings().setDisplayZoomControls(!supportsMultiTouch);

    // Add this WebView to the settings observer list and update the
    // settings
    final BrowserSettings s = BrowserSettings.getInstance();
    s.startManagingSettings(w.getSettings());
  }
예제 #3
0
  public static void initWebView(Context context, WebView mWebView) {
    if (mWebView != null) {
      mWebView.setDrawingCacheBackgroundColor(0x00000000);
      mWebView.setFocusableInTouchMode(true);
      mWebView.setFocusable(true);
      mWebView.setAnimationCacheEnabled(false);
      mWebView.setDrawingCacheEnabled(true);
      mWebView.setBackgroundColor(context.getResources().getColor(android.R.color.white));
      mWebView.getRootView().setBackgroundDrawable(null);
      mWebView.setWillNotCacheDrawing(false);
      mWebView.setAlwaysDrawnWithCacheEnabled(true);
      mWebView.setScrollbarFadingEnabled(true);
      mWebView.setHorizontalScrollBarEnabled(false);
      mWebView.setVerticalScrollBarEnabled(true);
      mWebView.setSaveEnabled(true);
      mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

      initializeSettings(mWebView.getSettings(), context);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Initialize the WebView
    webView.getSettings().setSupportZoom(true);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.setWebViewClient(new WebViewClient());

    Intent i = getIntent();
    HqEntity hqEntity = (HqEntity) i.getSerializableExtra(Constants.HQ_KEY);
    allowCacheAccess(hqEntity.isCacheEnabled());

    // Load the URLs inside the WebView, not in the external web browser
    webView.loadUrl(hqEntity.getUrl());
  }
  @Override
  protected void onStart() {
    super.onStart();

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

    mObserver = new HtmlEventObserver();

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

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

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

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

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

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

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

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

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

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

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

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

    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);

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

    mWebView.loadUrl("javascript:" + jsonSrc);
    mWebView.loadUrl("javascript:" + androidJsSrc);
    mWebView.loadUrl("javascript:" + mAPIWrapperSource);
    Log.d(
        config.getLOG_TAG(),
        "Launch Webview: "
            + "file://"
            + this.getFilesDir().getAbsolutePath()
            + "/"
            + config.getMAIN_SCRIPT_NAME());
    mWebView.loadUrl(
        "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME());
  }
예제 #6
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_whats_trending, container, false);
    // View footerView =
    // ((LayoutInflater)this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
    // this.getListView().addFooterView(footerView);
    progressBarT4 = (ProgressBar) rootView.findViewById(R.id.progressBar1web);
    load = (TextView) rootView.findViewById(R.id.loadin);
    browser = (WebView) rootView.findViewById(R.id.webView1);
    refreshweb = (Button) rootView.findViewById(R.id.buttonrefresh);
    anim = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.animation);
    // load.startAnimation(anim);
    // getActivity().anim.setAnimationListener(this);
    browser.setWebViewClient(new MyBrowser());

    // TODO Auto-generated method stub
    browser.getSettings().setLoadsImagesAutomatically(true);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.getSettings().setSupportZoom(false);
    // browser.getSettings().setBuiltInZoomControls(true);
    browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    browser.setScrollbarFadingEnabled(true);
    browser.getSettings().setLoadsImagesAutomatically(true);

    if (!haveNetworkConnection()) { // load.setTextColor(getResources().getColor(R.color.yellow));
      load.setBackgroundColor(getResources().getColor(R.color.red));
      load.setText("No Internet Connection");

      progressBarT4.setVisibility(View.GONE);
      refreshweb.setVisibility(View.VISIBLE);
      refreshweb.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              // TODO Auto-generated method stub
              Intent i = new Intent(getActivity(), MainActivity.class);

              getActivity().finish();
              startActivity(i);
            }
          });
      Toast.makeText(getActivity(), "No Internet Cannection", Toast.LENGTH_SHORT).show();

    } else {

      browser.setWebChromeClient(
          new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
              progressBarT4.setVisibility(View.VISIBLE);

              progressBarT4.setProgress(progress);

              if (progress == 100) {
                load.setVisibility(View.GONE);
                //		    	            	/load.clearAnimation();
                progressBarT4.setVisibility(
                    View.GONE); // Make the bar disappear after URL is loaded
              }
            }
          });
      load.setVisibility(View.VISIBLE);
      progressBarT4.setVisibility(View.VISIBLE);

      if (webViewBundle == null) {
        browser.loadUrl("http://192.168.43.207/SEtest-Mobile/about.html");
      } else {
        browser.restoreState(webViewBundle);
      }

      /*dialog = ProgressDialog.show(getActivity(), "",
                 "Please Wait",true);
      dialog.setCancelable(true);
      dialog.setCanceledOnTouchOutside(true);*/

    }

    return rootView;
  }