package epson.print.imgsel;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import com.epson.cameracopy.p006ui.ImagePreviewActivity;
import epson.common.ScalableImageView;
import epson.print.R;

public class ImageViewSingleFragment extends ImageViewBaseFragment implements View.OnClickListener {
    public static ImageViewSingleFragment newInstance(String str, int i) {
        ImageViewSingleFragment imageViewSingleFragment = new ImageViewSingleFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ImagePreviewActivity.PARAM_PICTURE_FILENAME, str);
        bundle.putInt(ImageViewPagerActivity.PARAMS_MESSAGE_TYPE, i);
        imageViewSingleFragment.setArguments(bundle);
        return imageViewSingleFragment;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (getArguments() != null) {
            this.mFileName = getArguments().getString(ImagePreviewActivity.PARAM_PICTURE_FILENAME);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        int i = 0;
        View inflate = layoutInflater.inflate(R.layout.fragment_image_view_single, viewGroup, false);
        this.mImageView = (ScalableImageView) inflate.findViewById(R.id.imageView);
        this.mProgressBar = (ProgressBar) inflate.findViewById(R.id.imageLoadProgressBar);
        Button button = (Button) inflate.findViewById(R.id.selectButton);
        button.setOnClickListener(this);
        Bundle arguments = getArguments();
        if (arguments != null) {
            i = arguments.getInt(ImageViewPagerActivity.PARAMS_MESSAGE_TYPE, 0);
        }
        if (i == 1) {
            button.setText(R.string.imgsel_view_pager_toggle_photo_copy);
        }
        super.onCreateView(layoutInflater, viewGroup, bundle);
        return inflate;
    }

    public void onClick(View view) {
        selectImageOnSingleFileMode();
    }

    private void selectImageOnSingleFileMode() {
        ImageSelector selector = this.mListener.getSelector();
        selector.clear();
        if (selector.add(this.mFileName)) {
            onSingleModeItemSelected();
        }
    }

    private void onSingleModeItemSelected() {
        if (this.mListener != null) {
            this.mListener.onSingleModeItemSelected();
        }
    }
}
