package com.aigestudio.wheelpicker; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Camera; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Region; import android.graphics.Typeface; import android.os.Build; import android.os.Handler; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.widget.Scroller; import java.util.Arrays; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ public class WheelPicker extends View implements IDebug, IWheelPicker, Runnable { private static final String i0 = WheelPicker.class.getSimpleName(); private static final Handler j0 = new Handler(); private int A; private int B; private int C; private int D; private int E; private int F; private int G; private int H; private int I; private int J; private int K; private int L; private int M; private int N; private int O; private int P; private int Q; private int R; private int S; private int T; private int U; private boolean V; private boolean W; private Paint a; private boolean a0; private Scroller b; private boolean b0; private VelocityTracker c; private boolean c0; private boolean d; private boolean d0; private OnItemSelectedListener e; private boolean e0; private OnWheelChangeListener f; private boolean f0; private Rect g; private String g0; private Rect h; private boolean h0; private Rect i; private Rect j; private Camera k; private Matrix l; private Matrix m; private List n; private String o; private int p; private int q; private int r; private int s; private int t; private int u; private int v; private int x; private int y; private int z; public interface OnItemSelectedListener { void a(WheelPicker wheelPicker, Object obj, int i); } public interface OnWheelChangeListener { void a(int i); void b(int i); void c(int i); } public WheelPicker(Context context) { this(context, null); } private int a(int i, int i2, int i3) { return i == 1073741824 ? i2 : i == Integer.MIN_VALUE ? Math.min(i3, i2) : i3; } private void b() { int i = this.C; if (i == 1) { this.O = this.g.left; } else if (i != 2) { this.O = this.M; } else { this.O = this.g.right; } this.P = (int) (this.N - ((this.a.ascent() + this.a.descent()) / 2.0f)); } private void c() { int i = this.G; int i2 = this.D; int i3 = i * i2; this.I = this.c0 ? Integer.MIN_VALUE : ((-i2) * (this.n.size() - 1)) + i3; if (this.c0) { i3 = Integer.MAX_VALUE; } this.J = i3; } private void d() { if (this.W) { int i = this.y / 2; int i2 = this.N; int i3 = this.E; int i4 = i2 + i3; int i5 = i2 - i3; Rect rect = this.h; Rect rect2 = this.g; rect.set(rect2.left, i4 - i, rect2.right, i4 + i); Rect rect3 = this.i; Rect rect4 = this.g; rect3.set(rect4.left, i5 - i, rect4.right, i5 + i); } } private void e() { this.t = 0; this.s = 0; if (this.V) { this.s = (int) this.a.measureText(String.valueOf(this.n.get(0))); } else if (d(this.R)) { this.s = (int) this.a.measureText(String.valueOf(this.n.get(this.R))); } else if (TextUtils.isEmpty(this.o)) { Iterator it = this.n.iterator(); while (it.hasNext()) { this.s = Math.max(this.s, (int) this.a.measureText(String.valueOf(it.next()))); } } else { this.s = (int) this.a.measureText(this.o); } Paint.FontMetrics fontMetrics = this.a.getFontMetrics(); this.t = (int) (fontMetrics.bottom - fontMetrics.top); } private void f() { int i = this.C; if (i == 1) { this.a.setTextAlign(Paint.Align.LEFT); } else if (i != 2) { this.a.setTextAlign(Paint.Align.CENTER); } else { this.a.setTextAlign(Paint.Align.RIGHT); } } private void j() { int i = this.p; if (i < 2) { throw new ArithmeticException("Wheel's visible item count can not be less than 2!"); } if (i % 2 == 0) { this.p = i + 1; } this.q = this.p + 2; this.r = this.q / 2; } public int getCurrentItemPosition() { return this.H; } public int getCurtainColor() { return this.A; } public List getData() { return this.n; } public int getIndicatorColor() { return this.z; } public int getIndicatorSize() { return this.y; } public int getItemAlign() { return this.C; } public int getItemSpace() { return this.B; } public int getItemTextColor() { return this.u; } public int getItemTextSize() { return this.x; } public String getMaximumWidthText() { return this.o; } public int getMaximumWidthTextPosition() { return this.R; } public int getSelectedItemPosition() { return this.G; } public int getSelectedItemTextColor() { return this.v; } public Typeface getTypeface() { Paint paint = this.a; if (paint != null) { return paint.getTypeface(); } return null; } public int getVisibleItemCount() { return this.p; } @Override // android.view.View protected void onDraw(Canvas canvas) { String valueOf; int i; OnWheelChangeListener onWheelChangeListener = this.f; if (onWheelChangeListener != null) { onWheelChangeListener.a(this.Q); } int i2 = (-this.Q) / this.D; int i3 = this.r; int i4 = i2 - i3; int i5 = this.G + i4; int i6 = -i3; while (i5 < this.G + i4 + this.q) { if (this.c0) { int size = i5 % this.n.size(); if (size < 0) { size += this.n.size(); } valueOf = String.valueOf(this.n.get(size)); } else { valueOf = d(i5) ? String.valueOf(this.n.get(i5)) : ""; } this.a.setColor(this.u); this.a.setStyle(Paint.Style.FILL); int i7 = this.P; int i8 = this.D; int i9 = (i6 * i8) + i7 + (this.Q % i8); if (this.d0) { int abs = i7 - Math.abs(i7 - i9); int i10 = this.g.top; int i11 = this.P; float f = (-(1.0f - (((abs - i10) * 1.0f) / (i11 - i10)))) * 90.0f * (i9 > i11 ? 1 : i9 < i11 ? -1 : 0); if (f < -90.0f) { f = -90.0f; } if (f > 90.0f) { f = 90.0f; } i = c((int) f); int i12 = this.M; int i13 = this.C; if (i13 == 1) { i12 = this.g.left; } else if (i13 == 2) { i12 = this.g.right; } int i14 = this.N - i; this.k.save(); this.k.rotateX(f); this.k.getMatrix(this.l); this.k.restore(); float f2 = -i12; float f3 = -i14; this.l.preTranslate(f2, f3); float f4 = i12; float f5 = i14; this.l.postTranslate(f4, f5); this.k.save(); this.k.translate(0.0f, 0.0f, a(r12)); this.k.getMatrix(this.m); this.k.restore(); this.m.preTranslate(f2, f3); this.m.postTranslate(f4, f5); this.l.postConcat(this.m); } else { i = 0; } if (this.b0) { int i15 = this.P; int abs2 = (int) ((((i15 - Math.abs(i15 - i9)) * 1.0f) / this.P) * 255.0f); if (abs2 < 0) { abs2 = 0; } this.a.setAlpha(abs2); } if (this.d0) { i9 = this.P - i; } if (this.v != -1) { canvas.save(); if (this.d0) { canvas.concat(this.l); } canvas.clipRect(this.j, Region.Op.DIFFERENCE); float f6 = i9; canvas.drawText(valueOf, this.O, f6, this.a); canvas.restore(); this.a.setColor(this.v); canvas.save(); if (this.d0) { canvas.concat(this.l); } canvas.clipRect(this.j); canvas.drawText(valueOf, this.O, f6, this.a); canvas.restore(); } else { canvas.save(); canvas.clipRect(this.g); if (this.d0) { canvas.concat(this.l); } canvas.drawText(valueOf, this.O, i9, this.a); canvas.restore(); } if (this.h0) { canvas.save(); canvas.clipRect(this.g); this.a.setColor(-1166541); int i16 = this.N + (this.D * i6); Rect rect = this.g; float f7 = i16; canvas.drawLine(rect.left, f7, rect.right, f7, this.a); this.a.setColor(-13421586); this.a.setStyle(Paint.Style.STROKE); int i17 = i16 - this.E; Rect rect2 = this.g; canvas.drawRect(rect2.left, i17, rect2.right, i17 + this.D, this.a); canvas.restore(); } i5++; i6++; } if (this.a0) { this.a.setColor(this.A); this.a.setStyle(Paint.Style.FILL); canvas.drawRect(this.j, this.a); } if (this.W) { this.a.setColor(this.z); this.a.setStyle(Paint.Style.FILL); canvas.drawRect(this.h, this.a); canvas.drawRect(this.i, this.a); } if (this.h0) { this.a.setColor(1144254003); this.a.setStyle(Paint.Style.FILL); canvas.drawRect(0.0f, 0.0f, getPaddingLeft(), getHeight(), this.a); canvas.drawRect(0.0f, 0.0f, getWidth(), getPaddingTop(), this.a); canvas.drawRect(getWidth() - getPaddingRight(), 0.0f, getWidth(), getHeight(), this.a); canvas.drawRect(0.0f, getHeight() - getPaddingBottom(), getWidth(), getHeight(), this.a); } } @Override // android.view.View protected void onMeasure(int i, int i2) { int mode = View.MeasureSpec.getMode(i); int mode2 = View.MeasureSpec.getMode(i2); int size = View.MeasureSpec.getSize(i); int size2 = View.MeasureSpec.getSize(i2); int i3 = this.s; int i4 = this.t; int i5 = this.p; int i6 = (i4 * i5) + (this.B * (i5 - 1)); if (this.d0) { i6 = (int) ((i6 * 2) / 3.141592653589793d); } if (this.h0) { Log.i(i0, "Wheel's content size is (" + i3 + ":" + i6 + ")"); } int paddingLeft = i3 + getPaddingLeft() + getPaddingRight(); int paddingTop = i6 + getPaddingTop() + getPaddingBottom(); if (this.h0) { Log.i(i0, "Wheel's size is (" + paddingLeft + ":" + paddingTop + ")"); } setMeasuredDimension(a(mode, size, paddingLeft), a(mode2, size2, paddingTop)); } @Override // android.view.View protected void onSizeChanged(int i, int i2, int i3, int i4) { this.g.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom()); if (this.h0) { Log.i(i0, "Wheel's drawn rect size is (" + this.g.width() + ":" + this.g.height() + ") and location is (" + this.g.left + ":" + this.g.top + ")"); } this.M = this.g.centerX(); this.N = this.g.centerY(); b(); this.F = this.g.height() / 2; this.D = this.g.height() / this.p; this.E = (this.D * 3) / 5; c(); d(); a(); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action == 0) { this.d = true; if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } VelocityTracker velocityTracker = this.c; if (velocityTracker == null) { this.c = VelocityTracker.obtain(); } else { velocityTracker.clear(); } this.c.addMovement(motionEvent); if (!this.b.isFinished()) { this.b.abortAnimation(); this.f0 = true; } int y = (int) motionEvent.getY(); this.S = y; this.T = y; } else if (action == 1) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(false); } if (!this.e0 || this.f0) { this.c.addMovement(motionEvent); if (Build.VERSION.SDK_INT >= 4) { this.c.computeCurrentVelocity(1000, this.L); } else { this.c.computeCurrentVelocity(1000); } this.f0 = false; int yVelocity = (int) this.c.getYVelocity(); if (Math.abs(yVelocity) > this.K) { this.b.fling(0, this.Q, 0, yVelocity, 0, 0, this.I, this.J); Scroller scroller = this.b; scroller.setFinalY(scroller.getFinalY() + b(this.b.getFinalY() % this.D)); } else { Scroller scroller2 = this.b; int i = this.Q; scroller2.startScroll(0, i, 0, b(i % this.D)); } if (!this.c0) { int finalY = this.b.getFinalY(); int i2 = this.J; if (finalY > i2) { this.b.setFinalY(i2); } else { int finalY2 = this.b.getFinalY(); int i3 = this.I; if (finalY2 < i3) { this.b.setFinalY(i3); } } } j0.post(this); VelocityTracker velocityTracker2 = this.c; if (velocityTracker2 != null) { velocityTracker2.recycle(); this.c = null; } } } else if (action != 2) { if (action == 3) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(false); } VelocityTracker velocityTracker3 = this.c; if (velocityTracker3 != null) { velocityTracker3.recycle(); this.c = null; } } } else if (Math.abs(this.T - motionEvent.getY()) < this.U) { this.e0 = true; } else { this.e0 = false; this.c.addMovement(motionEvent); OnWheelChangeListener onWheelChangeListener = this.f; if (onWheelChangeListener != null) { onWheelChangeListener.b(1); } float y2 = motionEvent.getY() - this.S; if (Math.abs(y2) >= 1.0f) { this.Q = (int) (this.Q + y2); this.S = (int) motionEvent.getY(); invalidate(); } } return true; } @Override // java.lang.Runnable public void run() { List list = this.n; if (list == null || list.size() == 0) { return; } if (this.b.isFinished() && !this.f0) { int i = this.D; if (i == 0) { return; } int size = (((-this.Q) / i) + this.G) % this.n.size(); if (size < 0) { size += this.n.size(); } if (this.h0) { Log.i(i0, size + ":" + this.n.get(size) + ":" + this.Q); } this.H = size; OnItemSelectedListener onItemSelectedListener = this.e; if (onItemSelectedListener != null && this.d) { onItemSelectedListener.a(this, this.n.get(size), size); } OnWheelChangeListener onWheelChangeListener = this.f; if (onWheelChangeListener != null && this.d) { onWheelChangeListener.c(size); this.f.b(0); } } if (this.b.computeScrollOffset()) { OnWheelChangeListener onWheelChangeListener2 = this.f; if (onWheelChangeListener2 != null) { onWheelChangeListener2.b(2); } this.Q = this.b.getCurrY(); postInvalidate(); j0.postDelayed(this, 16L); } } public void setAtmospheric(boolean z) { this.b0 = z; invalidate(); } public void setCurtain(boolean z) { this.a0 = z; a(); invalidate(); } public void setCurtainColor(int i) { this.A = i; invalidate(); } public void setCurved(boolean z) { this.d0 = z; requestLayout(); invalidate(); } public void setCyclic(boolean z) { this.c0 = z; c(); invalidate(); } public void setData(List list) { if (list == null) { throw new NullPointerException("WheelPicker's data can not be null!"); } this.n = list; if (this.G > list.size() - 1 || this.H > list.size() - 1) { int size = list.size() - 1; this.H = size; this.G = size; } else { this.G = this.H; } this.Q = 0; e(); c(); requestLayout(); invalidate(); } public void setDebug(boolean z) { this.h0 = z; } public void setIndicator(boolean z) { this.W = z; d(); invalidate(); } public void setIndicatorColor(int i) { this.z = i; invalidate(); } public void setIndicatorSize(int i) { this.y = i; d(); invalidate(); } public void setItemAlign(int i) { this.C = i; f(); b(); invalidate(); } public void setItemSpace(int i) { this.B = i; requestLayout(); invalidate(); } public void setItemTextColor(int i) { this.u = i; invalidate(); } public void setItemTextSize(int i) { this.x = i; this.a.setTextSize(this.x); e(); requestLayout(); invalidate(); } public void setMaximumWidthText(String str) { if (str == null) { throw new NullPointerException("Maximum width text can not be null!"); } this.o = str; e(); requestLayout(); invalidate(); } public void setMaximumWidthTextPosition(int i) { if (d(i)) { this.R = i; e(); requestLayout(); invalidate(); return; } throw new ArrayIndexOutOfBoundsException("Maximum width text Position must in [0, " + this.n.size() + "), but current is " + i); } public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListener) { this.e = onItemSelectedListener; } public void setOnWheelChangeListener(OnWheelChangeListener onWheelChangeListener) { this.f = onWheelChangeListener; } public void setSameWidth(boolean z) { this.V = z; e(); requestLayout(); invalidate(); } public void setSelectedItemPosition(int i) { a(i, true); } public void setSelectedItemTextColor(int i) { this.v = i; a(); invalidate(); } public void setTypeface(Typeface typeface) { Paint paint = this.a; if (paint != null) { paint.setTypeface(typeface); } e(); requestLayout(); invalidate(); } public void setVisibleItemCount(int i) { this.p = i; j(); requestLayout(); } public WheelPicker(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.K = 50; this.L = 8000; this.U = 8; this.W = true; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.WheelPicker); int resourceId = obtainStyledAttributes.getResourceId(R$styleable.WheelPicker_wheel_data, 0); this.n = Arrays.asList(getResources().getStringArray(resourceId == 0 ? R$array.WheelArrayWeek : resourceId)); this.x = obtainStyledAttributes.getDimensionPixelSize(R$styleable.WheelPicker_wheel_item_text_size, getResources().getDimensionPixelSize(R$dimen.wheel_item_text_size)); this.p = obtainStyledAttributes.getInt(R$styleable.WheelPicker_wheel_visible_item_count, 7); this.G = obtainStyledAttributes.getInt(R$styleable.WheelPicker_wheel_selected_item_position, 0); this.V = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_same_width, false); this.R = obtainStyledAttributes.getInt(R$styleable.WheelPicker_wheel_maximum_width_text_position, -1); this.o = obtainStyledAttributes.getString(R$styleable.WheelPicker_wheel_maximum_width_text); this.v = obtainStyledAttributes.getColor(R$styleable.WheelPicker_wheel_selected_item_text_color, -1); this.u = obtainStyledAttributes.getColor(R$styleable.WheelPicker_wheel_item_text_color, -7829368); this.B = obtainStyledAttributes.getDimensionPixelSize(R$styleable.WheelPicker_wheel_item_space, getResources().getDimensionPixelSize(R$dimen.wheel_item_space)); this.c0 = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_cyclic, false); this.W = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_indicator, false); this.z = obtainStyledAttributes.getColor(R$styleable.WheelPicker_wheel_indicator_color, -1166541); this.y = obtainStyledAttributes.getDimensionPixelSize(R$styleable.WheelPicker_wheel_indicator_size, getResources().getDimensionPixelSize(R$dimen.wheel_indicator_size)); this.a0 = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_curtain, false); this.A = obtainStyledAttributes.getColor(R$styleable.WheelPicker_wheel_curtain_color, -1996488705); this.b0 = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_atmospheric, false); this.d0 = obtainStyledAttributes.getBoolean(R$styleable.WheelPicker_wheel_curved, false); this.C = obtainStyledAttributes.getInt(R$styleable.WheelPicker_wheel_item_align, 0); this.g0 = obtainStyledAttributes.getString(R$styleable.WheelPicker_wheel_font_path); obtainStyledAttributes.recycle(); j(); this.a = new Paint(69); this.a.setTextSize(this.x); if (this.g0 != null) { setTypeface(Typeface.createFromAsset(context.getAssets(), this.g0)); } f(); e(); this.b = new Scroller(getContext()); if (Build.VERSION.SDK_INT >= 4) { ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext()); this.K = viewConfiguration.getScaledMinimumFlingVelocity(); this.L = viewConfiguration.getScaledMaximumFlingVelocity(); this.U = viewConfiguration.getScaledTouchSlop(); } this.g = new Rect(); this.h = new Rect(); this.i = new Rect(); this.j = new Rect(); this.k = new Camera(); this.l = new Matrix(); this.m = new Matrix(); } private void a() { if (this.a0 || this.v != -1) { Rect rect = this.j; Rect rect2 = this.g; int i = rect2.left; int i2 = this.N; int i3 = this.E; rect.set(i, i2 - i3, rect2.right, i2 + i3); } } private int a(int i) { return (int) (this.F - (Math.cos(Math.toRadians(i)) * this.F)); } private int c(int i) { return (int) (Math.sin(Math.toRadians(i)) * this.F); } public void a(int i, boolean z) { this.d = false; if (z && this.b.isFinished()) { int size = getData().size(); int i2 = i - this.H; if (i2 == 0) { return; } if (this.c0 && Math.abs(i2) > size / 2) { if (i2 > 0) { size = -size; } i2 += size; } Scroller scroller = this.b; scroller.startScroll(0, scroller.getCurrY(), 0, (-i2) * this.D); j0.post(this); return; } if (!this.b.isFinished()) { this.b.abortAnimation(); } int max = Math.max(Math.min(i, this.n.size() - 1), 0); this.G = max; this.H = max; this.Q = 0; c(); requestLayout(); invalidate(); } private int b(int i) { int i2; if (Math.abs(i) <= this.E) { return -i; } if (this.Q < 0) { i2 = -this.D; } else { i2 = this.D; } return i2 - i; } private boolean d(int i) { return i >= 0 && i < this.n.size(); } }