package com.epson.cameracopy.p006ui;

import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.p000v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import com.epson.cameracopy.device.CameraPreviewControl;
import com.epson.cameracopy.p006ui.PictureResolutionDialogFragment;
import epson.print.ActivityIACommon;

import java.io.File;

/* renamed from: com.epson.cameracopy.ui.CameraPreviewOptionActivity */
public class CameraPreviewOptionActivity extends ActivityIACommon implements PictureResolutionDialogFragment.OnItemSelectedListener {
    private static final int CODE_DIRECTORY_SELECT = 1;
    PlaceholderFragment mFragment;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_camera_preview_option);
        setActionBar((int) R.string.camera_option_title, true);
        if (bundle == null) {
            this.mFragment = new PlaceholderFragment();
            getSupportFragmentManager().beginTransaction().add((int) R.id.container, (Fragment) this.mFragment).commit();
        }
    }

    public void onItemSelected(boolean z, int i, Point point) {
        PlaceholderFragment placeholderFragment;
        if (z && (placeholderFragment = this.mFragment) != null) {
            placeholderFragment.changeSelectedCameraPictureResolution(i, point);
        }
    }

    /* renamed from: com.epson.cameracopy.ui.CameraPreviewOptionActivity$PlaceholderFragment */
    public static class PlaceholderFragment extends Fragment {
        Switch mAutoPhotoToggleButton;
        private int mCameraPictureResolutionMode;
        private Point mCameraPictureSize;
        private CameraPreviewControl mCameraPreviewControl;
        Switch mGuideToggleButton;
        private TextView mPictureResolutionText;
        String mSaveDirectoryName;
        private TextView mSaveDirectoryText;

        public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
            View inflate = layoutInflater.inflate(R.layout.fragment_camera_preview_option, viewGroup, false);
            this.mCameraPreviewControl = CameraPreviewControl.getInstance(getActivity());
            setHasOptionsMenu(true);
            this.mGuideToggleButton = (Switch) inflate.findViewById(R.id.guideToggleButton);
            this.mGuideToggleButton.setChecked(this.mCameraPreviewControl.getGuideMode());
            this.mGuideToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                    PlaceholderFragment.this.changeAutoPhotoToggleButtonStatus(z);
                }
            });
            this.mAutoPhotoToggleButton = (Switch) inflate.findViewById(R.id.autoPictureToggleButton);
            this.mAutoPhotoToggleButton.setChecked(this.mCameraPreviewControl.getAutoPictureMode());
            changeAutoPhotoToggleButtonStatus(this.mGuideToggleButton.isChecked());
            ((LinearLayout) inflate.findViewById(R.id.save_directory_layout)).setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    PlaceholderFragment.this.startSaveDirectoryActivity();
                }
            });
            this.mSaveDirectoryText = (TextView) inflate.findViewById(R.id.saveDirectoryText);
            setSaveDirectoryText(this.mCameraPreviewControl.getSaveDirecotry());
            inflate.findViewById(R.id.picture_resolution_layout).setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    PlaceholderFragment.this.openPictureResolutionDialog();
                }
            });
            this.mPictureResolutionText = (TextView) inflate.findViewById(R.id.pictureResolutionText);
            setCameraPictureResolutionModeFromCameraPreviewControl();
            setPictureResolutionText();
            return inflate;
        }

        public void changeSelectedCameraPictureResolution(int i, Point point) {
            this.mCameraPictureResolutionMode = i;
            if (this.mCameraPictureResolutionMode == 0) {
                this.mCameraPictureSize = null;
            } else {
                this.mCameraPictureSize = point;
            }
            setPictureResolutionText();
        }

        private void setPictureResolutionText() {
            if (this.mCameraPictureResolutionMode == 0) {
                this.mPictureResolutionText.setText(R.string.picture_size_auto);
                return;
            }
            Point point = this.mCameraPictureSize;
            if (point == null || point.x <= 0 || this.mCameraPictureSize.y <= 0) {
                this.mPictureResolutionText.setText("");
                return;
            }
            this.mPictureResolutionText.setText(CameraPreviewControl.getPictureSizeString(this.mCameraPictureSize.x, this.mCameraPictureSize.y));
        }

        private void setCameraPictureResolutionModeFromCameraPreviewControl() {
            this.mCameraPictureResolutionMode = this.mCameraPreviewControl.getPictureResolutionMode();
            this.mCameraPictureSize = null;
            if (this.mCameraPictureResolutionMode == 1) {
                this.mCameraPictureSize = this.mCameraPreviewControl.getPictureSize();
            }
        }

        /* access modifiers changed from: private */
        public void openPictureResolutionDialog() {
            PictureResolutionDialogFragment.newInstance(this.mCameraPictureResolutionMode, this.mCameraPictureSize).show(getActivity().getSupportFragmentManager(), "picture-resolution");
        }

        private void changeValueAndFinish() {
            this.mCameraPreviewControl.setGuideMode(this.mGuideToggleButton.isChecked());
            this.mCameraPreviewControl.setAutoPictureMode(Boolean.valueOf(this.mAutoPhotoToggleButton.isChecked()));
            this.mCameraPreviewControl.setSaveDirecotry(this.mSaveDirectoryName);
            if (this.mCameraPictureResolutionMode == 0) {
                this.mCameraPreviewControl.setPictureResolutionModeAuto();
            } else {
                this.mCameraPreviewControl.setPictureSize(this.mCameraPictureSize);
            }
            getActivity().finish();
        }

        /* access modifiers changed from: private */
        public void changeAutoPhotoToggleButtonStatus(boolean z) {
            if (z && this.mCameraPreviewControl.hasAutoPictureHardware(getActivity())) {
                this.mAutoPhotoToggleButton.setEnabled(true);
                return;
            }
            this.mAutoPhotoToggleButton.setChecked(false);
            this.mAutoPhotoToggleButton.setEnabled(false);
        }

        private void setSaveDirectoryText(String str) {
            this.mSaveDirectoryName = str;
            this.mSaveDirectoryText.setText(new File(this.mSaveDirectoryName).getName());
        }

        public void startSaveDirectoryActivity() {
            startActivityForResult(new Intent(getActivity(), FolderSelectActivity.class), 1);
        }

        public void onActivityResult(int i, int i2, Intent intent) {
            if (i == 1) {
                if (i2 == -1 && intent != null) {
                    String stringExtra = intent.getStringExtra("SELECT_Folder");
                    if (stringExtra != null) {
                        setSaveDirectoryText(stringExtra);
                    }
                } else if (i2 == 1) {
                    SimpleMessageDialogFragment.newInstance(R.string.file_save_error_message).show(getFragmentManager(), "error-dialog");
                }
            }
        }

        public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
            menuInflater.inflate(R.C2138menu.menu_done, menu);
            super.onCreateOptionsMenu(menu, menuInflater);
        }

        public boolean onOptionsItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() != R.id.menuSettingsDone) {
                return super.onOptionsItemSelected(menuItem);
            }
            changeValueAndFinish();
            return true;
        }
    }
}
