GuideWebviewFragment.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.epson.mobilephone.common.guide;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import android.support.p000v4.app.Fragment;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.webkit.WebView;
  9. import android.widget.FrameLayout;
  10. import com.epson.guidelib.C0907R;
  11. public class GuideWebviewFragment extends Fragment {
  12. private static final String ARG_PARAM1 = "html_file_path";
  13. MyClickListener mClickListerner;
  14. private String mHtmlPath;
  15. private WebView mWebView;
  16. private FrameLayout mWebViewFrame;
  17. public interface MyClickListener {
  18. void onClickClose();
  19. }
  20. public static GuideWebviewFragment newInstance(String str) {
  21. GuideWebviewFragment guideWebviewFragment = new GuideWebviewFragment();
  22. Bundle bundle = new Bundle();
  23. bundle.putString(ARG_PARAM1, str);
  24. guideWebviewFragment.setArguments(bundle);
  25. return guideWebviewFragment;
  26. }
  27. public void onCreate(Bundle bundle) {
  28. super.onCreate(bundle);
  29. if (getArguments() != null) {
  30. mHtmlPath = getArguments().getString(ARG_PARAM1);
  31. }
  32. }
  33. public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
  34. View inflate = layoutInflater.inflate(C0907R.layout.fragment_guide_webview, viewGroup, false);
  35. mWebView = (WebView) inflate.findViewById(C0907R.C0909id.guideWebview);
  36. mWebViewFrame = (FrameLayout) inflate.findViewById(C0907R.C0909id.guideWebViewFrame);
  37. ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mWebView.getLayoutParams();
  38. ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) mWebViewFrame.getLayoutParams();
  39. mWebView.getSettings().setBuiltInZoomControls(false);
  40. mWebView.getSettings().setLoadWithOverviewMode(true);
  41. mWebView.getSettings().setUseWideViewPort(true);
  42. mWebView.setInitialScale(1);
  43. mWebView.loadUrl(mHtmlPath);
  44. int webViewDP = Utils.getWebViewDP(getActivity(), getContext());
  45. marginLayoutParams.height = (int) Utils.dptopx(webViewDP, getContext());
  46. marginLayoutParams.width = (int) Utils.dptopx(webViewDP, getContext());
  47. marginLayoutParams2.height = (int) Utils.dptopx(Utils.LAYOUT_MEARGIN + webViewDP, getContext());
  48. marginLayoutParams2.width = (int) Utils.dptopx(webViewDP + Utils.LAYOUT_MEARGIN, getContext());
  49. mWebView.setLayoutParams(marginLayoutParams);
  50. mWebViewFrame.setLayoutParams(marginLayoutParams2);
  51. inflate.findViewById(C0907R.C0909id.closeImage).setOnClickListener(new View.OnClickListener() {
  52. public void onClick(View view) {
  53. if (GuideWebviewFragment.mClickListerner != null) {
  54. GuideWebviewFragment.mClickListerner.onClickClose();
  55. }
  56. }
  57. });
  58. return inflate;
  59. }
  60. public void onPause() {
  61. super.onPause();
  62. mWebView.onPause();
  63. }
  64. public void onResume() {
  65. mWebView.onResume();
  66. super.onResume();
  67. }
  68. public void onDestroy() {
  69. WebView webView = mWebView;
  70. if (webView != null) {
  71. webView.destroy();
  72. }
  73. mWebView = null;
  74. super.onDestroy();
  75. }
  76. public void onAttach(Context context) {
  77. super.onAttach(context);
  78. try {
  79. mClickListerner = (MyClickListener) context;
  80. } catch (ClassCastException unused) {
  81. throw new ClassCastException(getActivity().toString() + "must implement OnArticleSelectedListener.");
  82. }
  83. }
  84. public void onDetach() {
  85. super.onDetach();
  86. mClickListerner = null;
  87. }
  88. }