123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.epson.mobilephone.common.guide;
- import android.content.Context;
- import android.os.Bundle;
- import android.support.p000v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.webkit.WebView;
- import android.widget.FrameLayout;
- import androidx.fragment.app.Fragment;
- import com.epson.guidelib.R;
- public class GuideWebviewFragment extends Fragment {
- private static final String ARG_PARAM1 = "html_file_path";
- MyClickListener mClickListerner;
- private String mHtmlPath;
- private WebView mWebView;
- private FrameLayout mWebViewFrame;
- public interface MyClickListener {
- void onClickClose();
- }
- public static GuideWebviewFragment newInstance(String str) {
- GuideWebviewFragment guideWebviewFragment = new GuideWebviewFragment();
- Bundle bundle = new Bundle();
- bundle.putString(ARG_PARAM1, str);
- guideWebviewFragment.setArguments(bundle);
- return guideWebviewFragment;
- }
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
- if (getArguments() != null) {
- mHtmlPath = getArguments().getString(ARG_PARAM1);
- }
- }
- public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
- View inflate = layoutInflater.inflate(R.layout.fragment_guide_webview, viewGroup, false);
- mWebView = (WebView) inflate.findViewById(R.id.guideWebview);
- mWebViewFrame = (FrameLayout) inflate.findViewById(R.id.guideWebViewFrame);
- ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mWebView.getLayoutParams();
- ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) mWebViewFrame.getLayoutParams();
- mWebView.getSettings().setBuiltInZoomControls(false);
- mWebView.getSettings().setLoadWithOverviewMode(true);
- mWebView.getSettings().setUseWideViewPort(true);
- mWebView.setInitialScale(1);
- mWebView.loadUrl(mHtmlPath);
- int webViewDP = Utils.getWebViewDP(getActivity(), getContext());
- marginLayoutParams.height = Utils.dptopx(webViewDP, getContext());
- marginLayoutParams.width = Utils.dptopx(webViewDP, getContext());
- marginLayoutParams2.height = Utils.dptopx(Utils.LAYOUT_MEARGIN + webViewDP, getContext());
- marginLayoutParams2.width = Utils.dptopx(webViewDP + Utils.LAYOUT_MEARGIN, getContext());
- mWebView.setLayoutParams(marginLayoutParams);
- mWebViewFrame.setLayoutParams(marginLayoutParams2);
- inflate.findViewById(R.id.closeImage).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- if (GuideWebviewFragment.mClickListerner != null) {
- GuideWebviewFragment.mClickListerner.onClickClose();
- }
- }
- });
- return inflate;
- }
- public void onPause() {
- super.onPause();
- mWebView.onPause();
- }
- public void onResume() {
- mWebView.onResume();
- super.onResume();
- }
- public void onDestroy() {
- WebView webView = mWebView;
- if (webView != null) {
- webView.destroy();
- }
- mWebView = null;
- super.onDestroy();
- }
- public void onAttach(Context context) {
- super.onAttach(context);
- try {
- mClickListerner = (MyClickListener) context;
- } catch (ClassCastException unused) {
- throw new ClassCastException(getActivity().toString() + "must implement OnArticleSelectedListener.");
- }
- }
- public void onDetach() {
- super.onDetach();
- mClickListerner = null;
- }
- }
|