package epson.print.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.util.AttributeSet;
import android.widget.TextView;
import java.util.Locale;
import org.apache.commons.lang.ClassUtils;

public class JWrapTextView extends TextView {
    public JWrapTextView(Context context) {
        super(context, (AttributeSet) null);
    }

    public JWrapTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public JWrapTextView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    protected void onDraw(Canvas canvas) {
        if (Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPAN.getLanguage()) || Locale.getDefault().getLanguage().equalsIgnoreCase(Locale.JAPANESE.getLanguage())) {
            setText(Hyphenation.japaneseHyphenation(getText().toString(), this));
        }
        super.onDraw(canvas);
    }

    static class Hyphenation {
        private static final char[] HYP_JPN_BACK = {'(', 65288, '[', 65371, 12296, 12298, 12300, 12302, 12304, 12317, 8216, 8220, 8810};
        private static final char[] HYP_JPN_FRONT = {')', 65289, ']', 65373, 12297, 12299, 12301, 12303, 12305, 12319, 8217, 8221, 8811, 12540, 12449, 12451, 12453, 12455, 12457, 12483, 12515, 12517, 12519, 12526, 12533, 12534, 12353, 12355, 12357, 12359, 12361, 12387, 12419, 12421, 12423, 8722, '-', 12316, '?', 65311, '!', 65281, 65381, 12539, 8229, 8230, ':', ';', 65306, 65307};
        private static final char[] HYP_JPN_FRONT_PUNCTUATION = {12290, ClassUtils.PACKAGE_SEPARATOR_CHAR, 12289, ','};
        private static final char NEWLINE_CHARA = '\n';
        private static boolean isPunctuationToEnd = false;

        Hyphenation() {
        }

        public static void setIsPunctuationToEnd(boolean z) {
            isPunctuationToEnd = z;
        }

        public static CharSequence japaneseHyphenation(String str, TextView textView) {
            return japaneseHyphenation(str, textView, (textView.getWidth() - textView.getCompoundPaddingLeft()) - textView.getCompoundPaddingRight());
        }

        /* JADX WARNING: Removed duplicated region for block: B:50:0x00b0  */
        /* JADX WARNING: Removed duplicated region for block: B:51:0x00b8  */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public static java.lang.CharSequence japaneseHyphenation(java.lang.String r13, android.widget.TextView r14, int r15) {
            /*
                android.text.TextPaint r14 = r14.getPaint()
                android.text.SpannableStringBuilder r0 = new android.text.SpannableStringBuilder
                r0.<init>()
                r1 = 0
                r2 = 0
                r3 = 0
            L_0x000c:
                int r4 = r13.length()
                if (r2 >= r4) goto L_0x00bd
                int r4 = r2 + 1
                java.lang.String r5 = r13.substring(r3, r4)
                char r6 = r13.charAt(r2)
                r7 = 10
                r8 = 1
                if (r6 != r7) goto L_0x0030
                java.lang.String r3 = r13.substring(r3, r2)
                r0.append(r3)
                java.lang.String r3 = "\n"
                r0.append(r3)
                r3 = r4
                goto L_0x00ba
            L_0x0030:
                float r4 = android.text.Layout.getDesiredWidth(r5, r14)
                float r5 = (float) r15
                int r4 = (r4 > r5 ? 1 : (r4 == r5 ? 0 : -1))
                if (r4 <= 0) goto L_0x00ba
                r4 = 0
            L_0x003a:
                char[] r5 = HYP_JPN_FRONT
                int r9 = r5.length
                if (r4 >= r9) goto L_0x004b
                char r5 = r5[r4]
                if (r6 != r5) goto L_0x0048
                int r2 = r2 + -1
                r4 = r2
                r2 = 1
                goto L_0x004d
            L_0x0048:
                int r4 = r4 + 1
                goto L_0x003a
            L_0x004b:
                r4 = r2
                r2 = 0
            L_0x004d:
                boolean r5 = isPunctuationToEnd
                if (r5 != 0) goto L_0x0064
                if (r2 != 0) goto L_0x0064
                r5 = 0
            L_0x0054:
                char[] r9 = HYP_JPN_FRONT_PUNCTUATION
                int r10 = r9.length
                if (r5 >= r10) goto L_0x0064
                char r9 = r9[r5]
                if (r6 != r9) goto L_0x0061
                int r4 = r4 + -1
                r2 = 1
                goto L_0x0064
            L_0x0061:
                int r5 = r5 + 1
                goto L_0x0054
            L_0x0064:
                if (r2 != 0) goto L_0x007f
                if (r4 <= 0) goto L_0x007f
                int r5 = r4 + -1
                char r5 = r13.charAt(r5)
                r9 = 0
            L_0x006f:
                char[] r10 = HYP_JPN_BACK
                int r11 = r10.length
                if (r9 >= r11) goto L_0x007f
                char r10 = r10[r9]
                if (r5 != r10) goto L_0x007c
                int r4 = r4 + -1
                r2 = 1
                goto L_0x007f
            L_0x007c:
                int r9 = r9 + 1
                goto L_0x006f
            L_0x007f:
                boolean r5 = isPunctuationToEnd
                if (r5 == 0) goto L_0x0094
                if (r2 != 0) goto L_0x0094
                r2 = 0
            L_0x0086:
                char[] r5 = HYP_JPN_FRONT_PUNCTUATION
                int r9 = r5.length
                if (r2 >= r9) goto L_0x0094
                char r5 = r5[r2]
                if (r6 != r5) goto L_0x0091
                r2 = 1
                goto L_0x0095
            L_0x0091:
                int r2 = r2 + 1
                goto L_0x0086
            L_0x0094:
                r2 = 0
            L_0x0095:
                int r5 = r4 + r2
                java.lang.String r3 = r13.substring(r3, r5)
                r0.append(r3)
                java.lang.String r3 = "\n"
                r0.append(r3)
                int r2 = r2 + r4
                int r3 = r13.length()
                if (r2 >= r3) goto L_0x00b8
                char r3 = r13.charAt(r2)
                if (r3 != r7) goto L_0x00b8
                int r3 = r4 + 1
                int r2 = r2 + 1
                r12 = r3
                r3 = r2
                r2 = r12
                goto L_0x00ba
            L_0x00b8:
                r3 = r2
                r2 = r4
            L_0x00ba:
                int r2 = r2 + r8
                goto L_0x000c
            L_0x00bd:
                java.lang.String r14 = r13.substring(r3)
                int r14 = r14.length()
                if (r14 <= 0) goto L_0x00ce
                java.lang.String r13 = r13.substring(r3)
                r0.append(r13)
            L_0x00ce:
                return r0
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.print.widgets.JWrapTextView.Hyphenation.japaneseHyphenation(java.lang.String, android.widget.TextView, int):java.lang.CharSequence");
        }

        public static CharSequence japaneseHyphenationInCharacters(String str, TextView textView, int i) {
            return japaneseHyphenation(str, textView, ((int) Layout.getDesiredWidth("あ", textView.getPaint())) * i);
        }
    }
}
