Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package seacoders.abhilash.bogguru;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.os.Bundle;
  5. import android.support.annotation.Nullable;
  6. import android.support.v4.app.Fragment;
  7. import android.support.v4.view.GravityCompat;
  8. import android.support.v4.widget.DrawerLayout;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.webkit.WebSettings;
  13. import android.webkit.WebView;
  14. import android.webkit.WebViewClient;
  15. import android.widget.ProgressBar;
  16. import android.widget.TextView;
  17.  
  18. public class HomeFragment extends Fragment {
  19. private WebView wv;
  20. private TextView txt;
  21. ProgressBar pbar;
  22.  
  23. public static final String TITLE = "Home";
  24.  
  25. public static HomeFragment newInstance() {
  26.  
  27. return new HomeFragment();
  28. }
  29.  
  30. @Nullable
  31. @Override
  32. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
  33. //return inflater.inflate(R.layout.fragment_home, container, false);
  34. View v=inflater.inflate(R.layout.fragment_home, container, false);
  35. wv = (WebView)v.findViewById(R.id.webview);
  36. wv.loadUrl("http://www.google.com");
  37. WebSettings webSettings = wv.getSettings();
  38. webSettings.setJavaScriptEnabled(true);
  39. pbar = (ProgressBar) container.findViewById(R.id.pg1);
  40. txt = (TextView) container.findViewById(R.id.txtload);
  41. wv.setWebViewClient(new MyWebViewClient());
  42. return v;
  43. }
  44.  
  45. public class MyWebViewClient extends WebViewClient {
  46.  
  47. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  48. wv.loadUrl("file:///android_asset/error.html");
  49. }
  50.  
  51. @Override
  52. public void onPageStarted(WebView view, String url, Bitmap favicon) {
  53. super.onPageStarted(view, url, favicon);
  54. System.out.println("loading... please wait");
  55. pbar.setVisibility(View.VISIBLE);
  56. txt.setVisibility(View.VISIBLE);
  57. }
  58.  
  59. @Override
  60. public void onPageFinished(WebView view, String url) {
  61. System.out.println("finished loading");
  62. pbar.setVisibility(View.GONE);
  63. txt.setVisibility(View.GONE);
  64. }
  65. }
  66.  
  67. }
Add Comment
Please, Sign In to add comment