Cherish: ColorPicker: make it more user friendly

* Show RGB value instead of ARGB because most average users dont even know about alpha in hex color values
* Make edit text limited to 7 characters and one line
* Remove enter image button

Signed-off-by: 00day0 <therandomuser11@gmail.com>
Signed-off-by: NurKeinNeid <mralexman3000@gmail.com>
This commit is contained in:
00day0
2019-12-11 00:02:58 +01:00
committed by unknown
parent ba9e20e869
commit e0dc6f4d7a
5 changed files with 50 additions and 64 deletions

View File

@@ -1,33 +0,0 @@
<!-- Copyright (C) 2014-2016 The Dirty Unicorns Project
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32.000000dp"
android:height="32.000000dp"
android:viewportWidth="96.000000"
android:viewportHeight="96.000000"
android:tint="?android:attr/colorAccent">
<group
android:translateY="96.000000"
android:scaleX="0.100000"
android:scaleY="-0.100000">
<path
android:fillColor="#FFFFFFFF"
android:strokeWidth="1"
android:pathData="M567 562 l-187 -187 -98 98 -98 97 -42 -43 -42 -43 139 -138 138 -138 232 227 c127
125 231 230 230 234 0 3 -20 23 -43 43 l-42 37 -187 -187z" />
</group>
</vector>

View File

@@ -57,16 +57,11 @@
android:id="@+id/hex" android:id="@+id/hex"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:maxLength="7"
android:hint="@string/hex_hint" /> android:hint="@string/hex_hint" />
<ImageButton
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="@android:color/transparent"
android:gravity="center"
android:src="@drawable/ic_action_set" />
</LinearLayout> </LinearLayout>
<TextView <TextView

View File

@@ -43,17 +43,11 @@
android:id="@+id/hex" android:id="@+id/hex"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:maxLength="7"
android:hint="@string/hex_hint" /> android:hint="@string/hex_hint" />
<ImageButton
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="@android:color/transparent"
android:gravity="center"
android:src="@drawable/ic_action_set" />
</LinearLayout> </LinearLayout>
<net.margaritov.preference.colorpicker.ColorPickerView <net.margaritov.preference.colorpicker.ColorPickerView

View File

@@ -26,12 +26,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.widget.EditText; import android.widget.EditText;
import android.view.KeyEvent;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.android.settings.R; import com.android.settings.R;
public class ColorPickerDialog extends AlertDialog implements ColorPickerView.OnColorChangedListener, View.OnClickListener { public class ColorPickerDialog extends AlertDialog implements ColorPickerView.OnColorChangedListener, View.OnClickListener, View.OnKeyListener {
private ColorPickerView mColorPicker; private ColorPickerView mColorPicker;
private ColorPickerPanelView mOldColor; private ColorPickerPanelView mOldColor;
@@ -58,6 +59,15 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
} }
} }
private void setColorFromHex() {
String text = mHex.getText().toString();
try {
int newColor = ColorPickerPreference.convertToColorInt(text);
mColorPicker.setColor(newColor, true);
} catch (Exception ignored) {
}
}
private void setUp(int color) { private void setUp(int color) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
@@ -71,7 +81,6 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
mNewColor = layout.findViewById(R.id.new_color_panel); mNewColor = layout.findViewById(R.id.new_color_panel);
mHex = layout.findViewById(R.id.hex); mHex = layout.findViewById(R.id.hex);
ImageButton mSetButton = layout.findViewById(R.id.enter);
((LinearLayout) mOldColor.getParent()).setPadding(Math.round(mColorPicker.getDrawingOffset()), ((LinearLayout) mOldColor.getParent()).setPadding(Math.round(mColorPicker.getDrawingOffset()),
0, Math.round(mColorPicker.getDrawingOffset()), 0); 0, Math.round(mColorPicker.getDrawingOffset()), 0);
@@ -83,17 +92,8 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
mColorPicker.setColor(color, true); mColorPicker.setColor(color, true);
if (mHex != null) { if (mHex != null) {
mHex.setText(ColorPickerPreference.convertToARGB(color)); mHex.setText(ColorPickerPreference.convertToRGB(color));
} mHex.setOnKeyListener(this);
if (mSetButton != null) {
mSetButton.setOnClickListener(v -> {
String text = mHex.getText().toString();
try {
int newColor = ColorPickerPreference.convertToColorInt(text);
mColorPicker.setColor(newColor, true);
} catch (Exception ignored) {
}
});
} }
setView(layout); setView(layout);
@@ -105,7 +105,7 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
mNewColor.setColor(color); mNewColor.setColor(color);
try { try {
if (mHex != null) { if (mHex != null) {
mHex.setText(ColorPickerPreference.convertToARGB(color)); mHex.setText(ColorPickerPreference.convertToRGB(color));
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} }
@@ -128,6 +128,16 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
return mColorPicker.getColor(); return mColorPicker.getColor();
} }
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
setColorFromHex();
return true;
}
return false;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (v.getId() == R.id.new_color_panel) { if (v.getId() == R.id.new_color_panel) {

View File

@@ -302,6 +302,26 @@ public class ColorPickerPreference extends Preference implements
return "#" + alpha + red + green + blue; return "#" + alpha + red + green + blue;
} }
public static String convertToRGB(int color) {
String red = Integer.toHexString(Color.red(color));
String green = Integer.toHexString(Color.green(color));
String blue = Integer.toHexString(Color.blue(color));
if (red.length() == 1) {
red = "0" + red;
}
if (green.length() == 1) {
green = "0" + green;
}
if (blue.length() == 1) {
blue = "0" + blue;
}
return "#" + red + green + blue;
}
/** /**
* For custom purposes. Not used by ColorPickerPreferrence * For custom purposes. Not used by ColorPickerPreferrence
* *