package com.ubt.jimu.user.view.picker; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import android.os.Build; import android.os.Handler; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import com.ubt.jimu.R; import java.util.List; import java.util.Timer; /* loaded from: classes2.dex */ public class LoopView extends View { int A; int B; int C; int D; int E; int F; int G; int H; float I; float J; float K; private float L; private float M; Timer a; int b; Handler c; LoopListener d; private GestureDetector e; private int f; private GestureDetector.SimpleOnGestureListener g; Context h; Paint i; Paint j; Paint k; Paint l; Paint m; List n; int o; int p; int q; int r; int s; int t; int u; float v; boolean x; int y; int z; public LoopView(Context context) { super(context); a(context); } private void a(Context context) { this.o = 0; this.r = 2002349952; this.s = 861499264; this.t = -10915968; this.u = -7166026; this.v = 2.0f; this.x = true; this.B = -1; this.C = 7; this.I = 0.0f; this.J = 0.0f; this.K = 0.0f; this.b = 0; this.g = new LoopViewGestureListener(this); this.c = new MessageHandler(this); this.h = context; setTextSize(17.0f); } static int b(LoopView loopView) { return loopView.getCurrentItem(); } private void c() { if (this.n == null) { return; } this.i = new Paint(); this.i.setColor(this.r); this.i.setAntiAlias(true); this.i.setTypeface(Typeface.MONOSPACE); this.i.setTextSize(this.o); this.j = new Paint(); this.j.setColor(this.t); this.j.setAntiAlias(true); this.j.setTextScaleX(1.05f); this.j.setTypeface(Typeface.MONOSPACE); this.j.setFakeBoldText(true); this.j.setTextSize(this.o); this.k = new Paint(); this.k.setColor(this.u); this.k.setAntiAlias(true); this.k.setTypeface(Typeface.MONOSPACE); this.k.setTextSize(this.o); this.l = new Paint(); this.l.setColor(this.s); this.l.setAntiAlias(true); this.l.setTypeface(Typeface.MONOSPACE); this.l.setTextSize(this.o); this.m = new Paint(); this.m.setColor(this.t); this.m.setAntiAlias(true); this.m.setTextScaleX(1.05f); this.m.setTypeface(Typeface.MONOSPACE); this.m.setTextSize(this.o); if (Build.VERSION.SDK_INT >= 11) { setLayerType(1, null); } this.e = new GestureDetector(this.h, this.g); this.e.setIsLongpressEnabled(false); d(); int i = this.q; float f = this.v; this.E = (int) (i * f * (this.C - 1)); int i2 = this.E; this.D = (int) ((i2 * 2) / 3.141592653589793d); this.F = (int) (i2 / 3.141592653589793d); this.G = this.p + this.o; int i3 = this.D; this.y = (int) ((i3 - (i * f)) / 2.0f); this.z = (int) ((i3 + (f * i)) / 2.0f); if (this.B == -1) { if (this.x) { this.B = (this.n.size() + 1) / 2; } else { this.B = 0; } } this.A = this.B; } private void d() { Rect rect = new Rect(); String str = (String) this.n.get(0); this.j.getTextBounds(str, 0, str.length(), rect); int width = (int) (rect.width() * 2.8f); if (width > this.p) { this.p = width; } int height = rect.height(); if (height > this.q) { this.q = height; } } private void e() { int i = (int) (this.b % (this.v * this.q)); Timer timer = new Timer(); this.a = timer; timer.schedule(new MTimer(this, i, timer), 0L, 10L); } public final int getCurrentItem() { int i = this.A; if (i <= 0) { return 0; } return i; } public final String getCurrentItemValue() { return String.valueOf(this.n.get(getCurrentItem())).trim(); } public final int getItemCount() { List list = this.n; if (list == null) { return 0; } return list.size(); } @Override // android.view.View protected void onDraw(Canvas canvas) { Canvas canvas2 = canvas; List list = this.n; if (list == null) { super.onDraw(canvas); return; } String[] strArr = new String[this.C]; this.H = (int) (this.b / (this.v * this.q)); this.A = this.B + (this.H % list.size()); if (this.x) { if (this.A < 0) { this.A = this.n.size() + this.A; } if (this.A > this.n.size() - 1) { this.A -= this.n.size(); } } else { if (this.A < 0) { this.A = 0; } if (this.A > this.n.size() - 1) { this.A = this.n.size() - 1; } } int i = (int) (this.b % (this.v * this.q)); for (int i2 = 0; i2 < this.C; i2++) { int i3 = this.A - (3 - i2); if (this.x) { if (i3 < 0) { i3 += this.n.size(); } if (i3 > this.n.size() - 1) { i3 -= this.n.size(); } strArr[i2] = (String) this.n.get(i3); } else if (i3 < 0) { strArr[i2] = ""; } else if (i3 > this.n.size() - 1) { strArr[i2] = ""; } else { strArr[i2] = (String) this.n.get(i3); } } int i4 = this.G; int i5 = (i4 - this.p) / 2; int i6 = this.y; canvas.drawLine(0.0f, i6, i4, i6, this.k); int i7 = this.z; canvas.drawLine(0.0f, i7, this.G, i7, this.k); for (int i8 = 0; i8 < this.C; i8++) { canvas.save(); double d = ((((this.q * i8) * this.v) - i) * 3.141592653589793d) / this.E; float f = (float) (90.0d - ((d / 3.141592653589793d) * 180.0d)); if (f >= 90.0f || f <= -90.0f) { canvas.restore(); } else { int cos = (int) ((this.F - (Math.cos(d) * this.F)) - ((Math.sin(d) * this.q) / 2.0d)); canvas2 = canvas; canvas2.translate(0.0f, cos); canvas2.scale(1.0f, (float) Math.sin(d)); String str = strArr[i8]; float f2 = this.o; this.i.setTextSize(f2); this.j.setTextSize(f2); int left = (int) (this.y + (getLeft() * 0.5d)); Rect rect = new Rect(); this.j.getTextBounds(str, 0, str.length(), rect); int width = rect.width(); int width2 = getWidth() - (left * 2); if (width > 0) { left = (int) (left + ((width2 - width) * 0.5d)); } int i9 = this.y; if (cos > i9 || this.q + cos < i9) { int i10 = this.z; if (cos > i10 || this.q + cos < i10) { if (cos >= this.y) { int i11 = this.q; if (cos + i11 <= this.z) { canvas2.clipRect(0, 0, this.G, (int) (i11 * this.v)); canvas2.drawText(strArr[i8], left, this.q, this.j); this.f = this.n.indexOf(strArr[i8]); if (i8 == 3 && this.f == 0) { this.j.getTextBounds(strArr[i8], 0, strArr[i8].length(), new Rect()); this.L = left + r2.width() + 25.0f; this.M = this.q; } } } canvas2.clipRect(0, 0, this.G, (int) (this.q * this.v)); if (i8 == 1 || i8 == 5) { canvas2.drawText(strArr[i8], left, this.q, this.l); } else { canvas2.drawText(strArr[i8], left, this.q, this.i); } canvas.restore(); } else { canvas.save(); canvas2.clipRect(0, 0, this.G, this.z - cos); float f3 = left; canvas2.drawText(strArr[i8], f3, this.q, this.j); canvas.restore(); canvas.save(); canvas2.clipRect(0, this.z - cos, this.G, (int) (this.q * this.v)); canvas2.drawText(strArr[i8], f3, this.q, this.i); canvas.restore(); } } else { canvas.save(); canvas2.clipRect(0, 0, this.G, this.y - cos); float f4 = left; canvas2.drawText(strArr[i8], f4, this.q, this.i); canvas.restore(); canvas.save(); canvas2.clipRect(0, this.y - cos, this.G, (int) (this.q * this.v)); canvas2.drawText(strArr[i8], f4, this.q, this.j); canvas.restore(); } canvas.restore(); } } if (this.L != 0.0f && this.M != 0.0f) { canvas2.drawText(this.h.getResources().getString(R.string.year_old), this.L, ((this.y + this.z) / 2) + (this.M / 2.0f), this.m); } super.onDraw(canvas); } @Override // android.view.View protected void onMeasure(int i, int i2) { c(); setMeasuredDimension(this.G, this.D); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action == 0) { this.I = motionEvent.getRawY(); } else { if (action != 2) { if (!this.e.onTouchEvent(motionEvent) && motionEvent.getAction() == 1) { e(); } return true; } this.J = motionEvent.getRawY(); float f = this.I; float f2 = this.J; this.K = f - f2; this.I = f2; this.b = (int) (this.b + this.K); if (!this.x) { int i = this.b; int i2 = this.B; float f3 = this.v; int i3 = this.q; if (i <= ((int) ((-i2) * i3 * f3))) { this.b = (int) ((-i2) * f3 * i3); } } } if (this.b < ((int) (((this.n.size() - 1) - this.B) * this.v * this.q))) { invalidate(); } else { this.b = (int) (((this.n.size() - 1) - this.B) * this.v * this.q); invalidate(); } if (!this.e.onTouchEvent(motionEvent) && motionEvent.getAction() == 1) { e(); } return true; } public final void setArrayList(List list) { this.n = list; c(); invalidate(); } public final void setCurrentItem(int i) { this.B = i; this.b = 0; e(); invalidate(); } public final void setCyclic(boolean z) { this.x = z; } public final void setListener(LoopListener loopListener) { this.d = loopListener; } public final void setTextSize(float f) { if (f > 0.0f) { this.o = (int) (this.h.getResources().getDisplayMetrics().density * f); } } public final void b() { this.x = false; } public LoopView(Context context, AttributeSet attributeSet) { super(context, attributeSet); a(context); } public LoopView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); a(context); } static void a(LoopView loopView) { loopView.e(); } protected final void a(float f) { Timer timer = new Timer(); this.a = timer; timer.schedule(new LoopTimerTask(this, f, timer), 0L, 20L); } protected final void a() { if (this.d != null) { new Handler().postDelayed(new LoopRunnable(this), 200L); } } }