mirror of https://github.com/NekoX-Dev/NekoX
Browse Source
https://github.com/DrKLO/Telegram/pull/200 https://github.com/DrKLO/Telegram/issues/455pull/1/head
31 changed files with 1144 additions and 180 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,383 @@ |
|||
/* |
|||
* Copyright 2012 Lars Werkman |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.telegram.ui.Views; |
|||
|
|||
import android.content.Context; |
|||
import android.graphics.Canvas; |
|||
import android.graphics.Color; |
|||
import android.graphics.Paint; |
|||
import android.graphics.RectF; |
|||
import android.graphics.Shader; |
|||
import android.graphics.SweepGradient; |
|||
import android.os.Bundle; |
|||
import android.os.Parcelable; |
|||
import android.util.AttributeSet; |
|||
import android.view.MotionEvent; |
|||
import android.view.View; |
|||
|
|||
import org.telegram.messenger.Utilities; |
|||
|
|||
public class ColorPickerView extends View { |
|||
|
|||
private static final String STATE_PARENT = "parent"; |
|||
private static final String STATE_ANGLE = "angle"; |
|||
private static final String STATE_OLD_COLOR = "color"; |
|||
private static final String STATE_SHOW_OLD_COLOR = "showColor"; |
|||
|
|||
private static final int[] COLORS = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00, 0xFFFFFF00, 0xFFFF0000 }; |
|||
|
|||
private Paint mColorWheelPaint; |
|||
private Paint mPointerHaloPaint; |
|||
private Paint mPointerColor; |
|||
private int mColorWheelThickness; |
|||
private int mColorWheelRadius; |
|||
private int mPreferredColorWheelRadius; |
|||
private int mColorCenterRadius; |
|||
private int mPreferredColorCenterRadius; |
|||
private int mColorCenterHaloRadius; |
|||
private int mPreferredColorCenterHaloRadius; |
|||
private int mColorPointerRadius; |
|||
private int mColorPointerHaloRadius; |
|||
private RectF mColorWheelRectangle = new RectF(); |
|||
private RectF mCenterRectangle = new RectF(); |
|||
private boolean mUserIsMovingPointer = false; |
|||
private int mCenterOldColor; |
|||
private boolean mShowCenterOldColor; |
|||
private int mCenterNewColor; |
|||
private float mTranslationOffset; |
|||
private float mSlopX; |
|||
private float mSlopY; |
|||
private float mAngle; |
|||
private Paint mCenterOldPaint; |
|||
private Paint mCenterNewPaint; |
|||
private Paint mCenterHaloPaint; |
|||
private float[] mHSV = new float[3]; |
|||
|
|||
private OnColorChangedListener onColorChangedListener; |
|||
private OnColorSelectedListener onColorSelectedListener; |
|||
|
|||
private int oldChangedListenerColor; |
|||
private int oldSelectedListenerColor; |
|||
|
|||
public ColorPickerView(Context context) { |
|||
super(context); |
|||
init(null, 0); |
|||
} |
|||
|
|||
public ColorPickerView(Context context, AttributeSet attrs) { |
|||
super(context, attrs); |
|||
init(attrs, 0); |
|||
} |
|||
|
|||
public ColorPickerView(Context context, AttributeSet attrs, int defStyle) { |
|||
super(context, attrs, defStyle); |
|||
init(attrs, defStyle); |
|||
} |
|||
|
|||
public interface OnColorChangedListener { |
|||
public void onColorChanged(int color); |
|||
} |
|||
|
|||
public interface OnColorSelectedListener { |
|||
public void onColorSelected(int color); |
|||
} |
|||
|
|||
public void setOnColorChangedListener(OnColorChangedListener listener) { |
|||
this.onColorChangedListener = listener; |
|||
} |
|||
|
|||
public void setOnColorSelectedListener(OnColorSelectedListener listener) { |
|||
this.onColorSelectedListener = listener; |
|||
} |
|||
|
|||
private void init(AttributeSet attrs, int defStyle) { |
|||
mColorWheelThickness = Utilities.dp(8); |
|||
mColorWheelRadius = Utilities.dp(124); |
|||
mPreferredColorWheelRadius = mColorWheelRadius; |
|||
mColorCenterRadius = Utilities.dp(54); |
|||
mPreferredColorCenterRadius = mColorCenterRadius; |
|||
mColorCenterHaloRadius = Utilities.dp(60); |
|||
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius; |
|||
mColorPointerRadius = Utilities.dp(14); |
|||
mColorPointerHaloRadius = Utilities.dp(18); |
|||
|
|||
mAngle = (float) (-Math.PI / 2); |
|||
|
|||
Shader s = new SweepGradient(0, 0, COLORS, null); |
|||
|
|||
mColorWheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mColorWheelPaint.setShader(s); |
|||
mColorWheelPaint.setStyle(Paint.Style.STROKE); |
|||
mColorWheelPaint.setStrokeWidth(mColorWheelThickness); |
|||
|
|||
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mPointerHaloPaint.setColor(Color.BLACK); |
|||
mPointerHaloPaint.setAlpha(0x50); |
|||
|
|||
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mPointerColor.setColor(calculateColor(mAngle)); |
|||
|
|||
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mCenterNewPaint.setColor(calculateColor(mAngle)); |
|||
mCenterNewPaint.setStyle(Paint.Style.FILL); |
|||
|
|||
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mCenterOldPaint.setColor(calculateColor(mAngle)); |
|||
mCenterOldPaint.setStyle(Paint.Style.FILL); |
|||
|
|||
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mCenterHaloPaint.setColor(Color.BLACK); |
|||
mCenterHaloPaint.setAlpha(0x00); |
|||
|
|||
mCenterNewColor = calculateColor(mAngle); |
|||
mCenterOldColor = calculateColor(mAngle); |
|||
mShowCenterOldColor = true; |
|||
} |
|||
|
|||
@Override |
|||
protected void onDraw(Canvas canvas) { |
|||
canvas.translate(mTranslationOffset, mTranslationOffset); |
|||
canvas.drawOval(mColorWheelRectangle, mColorWheelPaint); |
|||
|
|||
float[] pointerPosition = calculatePointerPosition(mAngle); |
|||
|
|||
canvas.drawCircle(pointerPosition[0], pointerPosition[1], mColorPointerHaloRadius, mPointerHaloPaint); |
|||
canvas.drawCircle(pointerPosition[0], pointerPosition[1], mColorPointerRadius, mPointerColor); |
|||
canvas.drawCircle(0, 0, mColorCenterHaloRadius, mCenterHaloPaint); |
|||
|
|||
if (mShowCenterOldColor) { |
|||
canvas.drawArc(mCenterRectangle, 90, 180, true, mCenterOldPaint); |
|||
canvas.drawArc(mCenterRectangle, 270, 180, true, mCenterNewPaint); |
|||
} else { |
|||
canvas.drawArc(mCenterRectangle, 0, 360, true, mCenterNewPaint); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|||
final int intrinsicSize = 2 * (mPreferredColorWheelRadius + mColorPointerHaloRadius); |
|||
|
|||
int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
|||
int widthSize = MeasureSpec.getSize(widthMeasureSpec); |
|||
int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
|||
int heightSize = MeasureSpec.getSize(heightMeasureSpec); |
|||
|
|||
int width; |
|||
int height; |
|||
|
|||
if (widthMode == MeasureSpec.EXACTLY) { |
|||
width = widthSize; |
|||
} else if (widthMode == MeasureSpec.AT_MOST) { |
|||
width = Math.min(intrinsicSize, widthSize); |
|||
} else { |
|||
width = intrinsicSize; |
|||
} |
|||
|
|||
if (heightMode == MeasureSpec.EXACTLY) { |
|||
height = heightSize; |
|||
} else if (heightMode == MeasureSpec.AT_MOST) { |
|||
height = Math.min(intrinsicSize, heightSize); |
|||
} else { |
|||
height = intrinsicSize; |
|||
} |
|||
|
|||
int min = Math.min(width, height); |
|||
setMeasuredDimension(min, min); |
|||
mTranslationOffset = min * 0.5f; |
|||
|
|||
mColorWheelRadius = min / 2 - mColorWheelThickness - mColorPointerHaloRadius; |
|||
mColorWheelRectangle.set(-mColorWheelRadius, -mColorWheelRadius, mColorWheelRadius, mColorWheelRadius); |
|||
|
|||
mColorCenterRadius = (int) ((float) mPreferredColorCenterRadius * ((float) mColorWheelRadius / (float) mPreferredColorWheelRadius)); |
|||
mColorCenterHaloRadius = (int) ((float) mPreferredColorCenterHaloRadius * ((float) mColorWheelRadius / (float) mPreferredColorWheelRadius)); |
|||
mCenterRectangle.set(-mColorCenterRadius, -mColorCenterRadius, mColorCenterRadius, mColorCenterRadius); |
|||
} |
|||
|
|||
private int ave(int s, int d, float p) { |
|||
return s + java.lang.Math.round(p * (d - s)); |
|||
} |
|||
|
|||
private int calculateColor(float angle) { |
|||
float unit = (float) (angle / (2 * Math.PI)); |
|||
if (unit < 0) { |