Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package seacoders.abhilash.bogguru;
- import android.graphics.Bitmap;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.support.v4.view.GravityCompat;
- import android.support.v4.widget.DrawerLayout;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- public class HomeFragment extends Fragment {
- private WebView wv;
- private TextView txt;
- ProgressBar pbar;
- public static final String TITLE = "Home";
- public static HomeFragment newInstance() {
- return new HomeFragment();
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
- //return inflater.inflate(R.layout.fragment_home, container, false);
- View v=inflater.inflate(R.layout.fragment_home, container, false);
- wv = (WebView)v.findViewById(R.id.webview);
- wv.loadUrl("http://www.google.com");
- WebSettings webSettings = wv.getSettings();
- webSettings.setJavaScriptEnabled(true);
- pbar = (ProgressBar) container.findViewById(R.id.pg1);
- txt = (TextView) container.findViewById(R.id.txtload);
- wv.setWebViewClient(new MyWebViewClient());
- return v;
- }
- public class MyWebViewClient extends WebViewClient {
- public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
- wv.loadUrl("file:///android_asset/error.html");
- }
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- super.onPageStarted(view, url, favicon);
- System.out.println("loading... please wait");
- pbar.setVisibility(View.VISIBLE);
- txt.setVisibility(View.VISIBLE);
- }
- @Override
- public void onPageFinished(WebView view, String url) {
- System.out.println("finished loading");
- pbar.setVisibility(View.GONE);
- txt.setVisibility(View.GONE);
- }
- }
- }
Add Comment
Please, Sign In to add comment