package com.epson.cameracopy.p006ui;

import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.support.p000v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.epson.cameracopy.device.CameraPreviewControl;

import java.util.Collections;
import java.util.List;

/* renamed from: com.epson.cameracopy.ui.PictureResolutionDialogFragment */
public class PictureResolutionDialogFragment extends DialogFragment {
    private static final String KEY_CAMERA_PICTURE_RESOLUTION_MODE = "picture_resolution_mode";
    private static final String KEY_CAMERA_PICTURE_SIZE = "picture_size";
    private static final int MANUAL_SIZE_START_INDEX = 1;
    private List<Point> mSizeList;

    /* renamed from: com.epson.cameracopy.ui.PictureResolutionDialogFragment$OnItemSelectedListener */
    interface OnItemSelectedListener {
        void onItemSelected(boolean z, int i, Point point);
    }

    public static PictureResolutionDialogFragment newInstance(int i, Point point) {
        PictureResolutionDialogFragment pictureResolutionDialogFragment = new PictureResolutionDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_CAMERA_PICTURE_RESOLUTION_MODE, i);
        if (point != null) {
            bundle.putIntArray(KEY_CAMERA_PICTURE_SIZE, new int[]{point.x, point.y});
        }
        pictureResolutionDialogFragment.setArguments(bundle);
        return pictureResolutionDialogFragment;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:2:0x000f, code lost:
        r7 = r7.getIntArray(KEY_CAMERA_PICTURE_SIZE);
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public android.app.Dialog onCreateDialog(android.os.Bundle r7) {
        /*
            r6 = this;
            android.os.Bundle r7 = r6.getArguments()
            java.lang.String r0 = "picture_resolution_mode"
            int r0 = r7.getInt(r0)
            r1 = 0
            r2 = 1
            r3 = 0
            if (r0 != r2) goto L_0x0025
            java.lang.String r4 = "picture_size"
            int[] r7 = r7.getIntArray(r4)
            if (r7 == 0) goto L_0x0025
            int r4 = r7.length
            r5 = 2
            if (r4 < r5) goto L_0x0025
            android.graphics.Point r4 = new android.graphics.Point
            r5 = r7[r1]
            r7 = r7[r2]
            r4.<init>(r5, r7)
            goto L_0x0026
        L_0x0025:
            r4 = r3
        L_0x0026:
            java.util.List r7 = r6.getPictureSizeList()
            r6.mSizeList = r7
            java.util.List<android.graphics.Point> r7 = r6.mSizeList
            java.lang.CharSequence[] r7 = r6.getPictureSizeStrList(r7)
            if (r7 != 0) goto L_0x0035
            return r3
        L_0x0035:
            java.util.List<android.graphics.Point> r2 = r6.mSizeList
            int r0 = r6.getListPoisition(r0, r4, r2)
            com.epson.cameracopy.ui.PictureResolutionDialogFragment$MyAdapter r2 = new com.epson.cameracopy.ui.PictureResolutionDialogFragment$MyAdapter
            android.support.v4.app.FragmentActivity r3 = r6.getActivity()
            r4 = 2131361980(0x7f0a00bc, float:1.8343728E38)
            r2.<init>(r3, r4, r7, r0)
            android.app.AlertDialog$Builder r7 = new android.app.AlertDialog$Builder
            android.support.v4.app.FragmentActivity r3 = r6.getActivity()
            r7.<init>(r3)
            r3 = 2131625007(0x7f0e042f, float:1.887721E38)
            android.app.AlertDialog$Builder r3 = r7.setTitle(r3)
            com.epson.cameracopy.ui.PictureResolutionDialogFragment$1 r4 = new com.epson.cameracopy.ui.PictureResolutionDialogFragment$1
            r4.<init>()
            r3.setSingleChoiceItems(r2, r0, r4)
            android.app.AlertDialog r7 = r7.create()
            r7.setCanceledOnTouchOutside(r1)
            return r7
        */
        throw new UnsupportedOperationException("Method not decompiled: com.epson.cameracopy.p006ui.PictureResolutionDialogFragment.onCreateDialog(android.os.Bundle):android.app.Dialog");
    }

    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
    }

    private List<Point> getPictureSizeList() {
        List<Point> cameraPictureSizes = CameraPreviewControl.getInstance(getActivity()).getCameraPictureSizes();
        if (cameraPictureSizes == null) {
            return null;
        }
        Collections.sort(cameraPictureSizes, new AreaComparator());
        return cameraPictureSizes;
    }

    private int getListPoisition(int i, Point point, List<Point> list) {
        int indexOf;
        if (i != 1 || point == null || (indexOf = this.mSizeList.indexOf(point)) < 0) {
            return 0;
        }
        return indexOf + 1;
    }

    private CharSequence[] getPictureSizeStrList(List<Point> list) {
        String[] strArr = new String[((list != null ? list.size() : 0) + 1)];
        strArr[0] = getActivity().getResources().getString(R.string.picture_size_auto);
        if (list == null) {
            return strArr;
        }
        int i = 1;
        for (Point next : list) {
            strArr[i] = CameraPreviewControl.getPictureSizeString(next.x, next.y);
            i++;
        }
        return strArr;
    }

    /* access modifiers changed from: private */
    public void selectListItem(int i) {
        OnItemSelectedListener onItemSelectedListener = (OnItemSelectedListener) getActivity();
        List<Point> list = this.mSizeList;
        if (list == null) {
            onItemSelectedListener.onItemSelected(false, -1, (Point) null);
        } else if (i == 0) {
            onItemSelectedListener.onItemSelected(true, 0, (Point) null);
        } else {
            try {
                onItemSelectedListener.onItemSelected(true, 1, list.get(i - 1));
            } catch (IndexOutOfBoundsException unused) {
            }
        }
    }

    /* renamed from: com.epson.cameracopy.ui.PictureResolutionDialogFragment$MyAdapter */
    static class MyAdapter extends ArrayAdapter<CharSequence> {
        LayoutInflater mLayoutInflater;
        int mSelectNumber;

        public MyAdapter(Context context, int i, CharSequence[] charSequenceArr, int i2) {
            super(context, i, charSequenceArr);
            this.mLayoutInflater = (LayoutInflater) context.getSystemService("layout_inflater");
            this.mSelectNumber = i2;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                view = this.mLayoutInflater.inflate(R.layout.select_list_row, viewGroup, false);
            }
            ((TextView) view.findViewById(R.id.docsize_name)).setText((CharSequence) getItem(i));
            ImageView imageView = (ImageView) view.findViewById(R.id.current_docsize_image);
            if (i != this.mSelectNumber) {
                imageView.setVisibility(4);
            } else {
                imageView.setVisibility(0);
            }
            return view;
        }
    }
}
