Improve color selector, selection is still a little bit weird, however, much better.

This commit is contained in:
B. Petersen
2017-04-10 22:51:10 +02:00
parent f03a3a9b50
commit a61e73b91b
13 changed files with 32 additions and 47 deletions
@@ -26,38 +26,34 @@ package com.b44t.ui.Cells;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.R;
import com.b44t.ui.Components.LayoutHelper;
import static com.b44t.messenger.AndroidUtilities.dp;
public class TextColorCell extends FrameLayout {
private TextView textView;
private boolean needDivider;
private int currentColor;
private Paint dividerpaint;
private Paint circlepaint;
private Drawable colorDrawable;
private static Paint paint;
public TextColorCell(Context context) {
super(context);
if (paint == null) {
paint = new Paint();
paint.setColor(0xffd9d9d9);
paint.setStrokeWidth(1);
}
dividerpaint = new Paint();
dividerpaint.setColor(0xffd9d9d9);
dividerpaint.setStrokeWidth(1);
dividerpaint.setAntiAlias(true);
colorDrawable = getResources().getDrawable(R.drawable.switch_to_on2);
circlepaint = new Paint();
circlepaint.setAntiAlias(true);
textView = new TextView(context);
textView.setTextColor(0xff212121);
@@ -71,33 +67,27 @@ public class TextColorCell extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(dp(48) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
}
public void setTextAndColor(String text, int color, boolean divider) {
textView.setText(text);
needDivider = divider;
currentColor = color;
colorDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
setWillNotDraw(!needDivider && currentColor == 0);
circlepaint.setColor(color);
setWillNotDraw(false);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(getPaddingLeft(), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, paint);
}
if (currentColor != 0 && colorDrawable != null) {
int x;
int y = (getMeasuredHeight() - colorDrawable.getMinimumHeight()) / 2;
if (!LocaleController.isRTL) {
x = getMeasuredWidth() - colorDrawable.getIntrinsicWidth() - AndroidUtilities.dp(14.5f);
} else {
x = AndroidUtilities.dp(14.5f);
}
colorDrawable.setBounds(x, y, x + colorDrawable.getIntrinsicWidth(), y + colorDrawable.getIntrinsicHeight());
colorDrawable.draw(canvas);
canvas.drawLine(getPaddingLeft(), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, dividerpaint);
}
final int RADIUS = dp(8);
int x = getWidth()-getPaddingRight()-dp(17)-RADIUS;
int y = getHeight()/2;
canvas.drawCircle(x+dp(1), y+dp(1), RADIUS, dividerpaint);
canvas.drawCircle(x, y, RADIUS, circlepaint);
}
}
@@ -36,7 +36,7 @@ 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 String STATE_SHOW_OLD_COLOR = "showColor";
private static final int[] COLORS = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00, 0xFFFFFFFF, 0xFFFFFF00, 0xFFFF0000 };
@@ -56,7 +56,7 @@ public class ColorPickerView extends View {
private RectF mCenterRectangle = new RectF();
private boolean mUserIsMovingPointer = false;
private int mCenterOldColor;
private boolean mShowCenterOldColor;
private final boolean mShowCenterOldColor = false;
private int mCenterNewColor;
private float mTranslationOffset;
private float mSlopX;
@@ -145,7 +145,7 @@ public class ColorPickerView extends View {
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
//mShowCenterOldColor = true;
}
@Override
@@ -344,14 +344,14 @@ public class ColorPickerView extends View {
return mCenterOldColor;
}
public void setShowOldCenterColor(boolean show) {
/*public void setShowOldCenterColor(boolean show) {
mShowCenterOldColor = show;
invalidate();
}
public boolean getShowOldCenterColor() {
return mShowCenterOldColor;
}
}*/
@Override
protected Parcelable onSaveInstanceState() {
@@ -361,7 +361,7 @@ public class ColorPickerView extends View {
state.putParcelable(STATE_PARENT, superState);
state.putFloat(STATE_ANGLE, mAngle);
state.putInt(STATE_OLD_COLOR, mCenterOldColor);
state.putBoolean(STATE_SHOW_OLD_COLOR, mShowCenterOldColor);
//state.putBoolean(STATE_SHOW_OLD_COLOR, mShowCenterOldColor);
return state;
}
@@ -375,7 +375,7 @@ public class ColorPickerView extends View {
mAngle = savedState.getFloat(STATE_ANGLE);
setOldCenterColor(savedState.getInt(STATE_OLD_COLOR));
mShowCenterOldColor = savedState.getBoolean(STATE_SHOW_OLD_COLOR);
//mShowCenterOldColor = savedState.getBoolean(STATE_SHOW_OLD_COLOR);
int currentColor = calculateColor(mAngle);
mPointerColor.setColor(currentColor);
setNewCenterColor(currentColor);
@@ -259,12 +259,12 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.contains("color_" + dialog_id)) {
colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
colorPickerView.setColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
} else {
if ((int) dialog_id < 0) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
colorPickerView.setColor(preferences.getInt("GroupLed", 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
colorPickerView.setColor(preferences.getInt("MessagesLed", 0xff00ff00));
}
}
@@ -285,9 +285,9 @@ public class SettingsNotificationsActivity extends BaseFragment implements Notif
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
colorPickerView.setColor(preferences.getInt("MessagesLed", 0xff00ff00));
} else if (i == groupLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
colorPickerView.setColor(preferences.getInt("GroupLed", 0xff00ff00));
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/switch_to_on2" />
<item android:drawable="@drawable/switch_to_on1" />
</selector>