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 com.epson.guidelib.C0907R;

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) {
            this.mHtmlPath = getArguments().getString(ARG_PARAM1);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(C0907R.layout.fragment_guide_webview, viewGroup, false);
        this.mWebView = (WebView) inflate.findViewById(C0907R.C0909id.guideWebview);
        this.mWebViewFrame = (FrameLayout) inflate.findViewById(C0907R.C0909id.guideWebViewFrame);
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.mWebView.getLayoutParams();
        ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) this.mWebViewFrame.getLayoutParams();
        this.mWebView.getSettings().setBuiltInZoomControls(false);
        this.mWebView.getSettings().setLoadWithOverviewMode(true);
        this.mWebView.getSettings().setUseWideViewPort(true);
        this.mWebView.setInitialScale(1);
        this.mWebView.loadUrl(this.mHtmlPath);
        int webViewDP = Utils.getWebViewDP(getActivity(), getContext());
        marginLayoutParams.height = (int) Utils.dptopx(webViewDP, getContext());
        marginLayoutParams.width = (int) Utils.dptopx(webViewDP, getContext());
        marginLayoutParams2.height = (int) Utils.dptopx(Utils.LAYOUT_MEARGIN + webViewDP, getContext());
        marginLayoutParams2.width = (int) Utils.dptopx(webViewDP + Utils.LAYOUT_MEARGIN, getContext());
        this.mWebView.setLayoutParams(marginLayoutParams);
        this.mWebViewFrame.setLayoutParams(marginLayoutParams2);
        inflate.findViewById(C0907R.C0909id.closeImage).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (GuideWebviewFragment.this.mClickListerner != null) {
                    GuideWebviewFragment.this.mClickListerner.onClickClose();
                }
            }
        });
        return inflate;
    }

    public void onPause() {
        super.onPause();
        this.mWebView.onPause();
    }

    public void onResume() {
        this.mWebView.onResume();
        super.onResume();
    }

    public void onDestroy() {
        WebView webView = this.mWebView;
        if (webView != null) {
            webView.destroy();
        }
        this.mWebView = null;
        super.onDestroy();
    }

    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            this.mClickListerner = (MyClickListener) context;
        } catch (ClassCastException unused) {
            throw new ClassCastException(getActivity().toString() + "must implement OnArticleSelectedListener.");
        }
    }

    public void onDetach() {
        super.onDetach();
        this.mClickListerner = null;
    }
}
