diff --git a/.idea/misc.xml b/.idea/misc.xml
index 8f3ac843d..9e9b47c61 100755
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -6,7 +6,8 @@
-
+
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 49561f4a6..69b3f5506 100755
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,7 +36,8 @@
+ android:configChanges="orientation|screenSize|uiMode"
+ android:windowSoftInputMode="adjustResize">
LOG.debug ("Picked color:", color, hexCode));
+
+ final var builder = newMaterialDialogBuilder (mContext);
+ builder.setView (view);
+
+ final var dialog = builder.create ();
+ dialog.getWindow ().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
+ return dialog;
+ }
+
public interface OnClickListener {
void onClick (DialogInterface dialog, int which, String newValue);
}
diff --git a/app/src/main/res/menu/menu_editor_nav.xml b/app/src/main/res/menu/menu_editor_nav.xml
index 8253a2253..2e5e552ba 100755
--- a/app/src/main/res/menu/menu_editor_nav.xml
+++ b/app/src/main/res/menu/menu_editor_nav.xml
@@ -24,8 +24,8 @@
android:title="@string/discussions_on_telegram"/>
+ android:icon="@drawable/ic_github"
+ android:title="@string/title_github"/>
- {
+
+ // If it's not from user, then the values have already been updated
+ if (fromUser) {
+ final var id = slider.getId ();
+ final var intVal = (int) value;
+ if (id == R.id.alpha_slider) {
+ alpha = intVal;
+ } else if (id == R.id.red_slider) {
+ red = intVal;
+ } else if (id == R.id.green_slider){
+ green = intVal;
+ } else if (id == R.id.blue_slider) {
+ blue = intVal;
+ }
+
+ updatePreview ();
+ }
+ };
+
public ColorPickerView (Context context) {
this (context, null);
}
@@ -75,18 +104,124 @@ public class ColorPickerView extends LinearLayout {
init ();
}
+ /**
+ * Set a listener that will be notified when the user picks a color.
+ * @param listener The listener to set.
+ */
+ public void setOnPickListener (OnPickListener listener) {
+ this.mPickListener = listener;
+ }
+
private void init () {
- final var color = this.DEFAULT_COLOR;
+
+ setColor (DEFAULT_COLOR);
+
+ this.binding.alphaSlider.addOnChangeListener (mValueChangeListener);
+ this.binding.redSlider.addOnChangeListener (mValueChangeListener);
+ this.binding.greenSlider.addOnChangeListener (mValueChangeListener);
+ this.binding.blueSlider.addOnChangeListener (mValueChangeListener);
+
+ this.binding.hexField.getEditText ().addTextChangedListener (new ColorTextWatcher ());
+
+ this.binding.pick.setOnClickListener (v -> {
+ if (mPickListener != null) {
+ mPickListener.onPick (getColor (), getHexColor ());
+ }
+ });
+ }
+
+ /**
+ * Get the hex color code of the current color value.
+ * @return The hex color code of the current color value.
+ */
+ @NonNull
+ public String getHexColor () {
+ return Integer.toHexString (getColor ());
+ }
+
+ /**
+ * Set the color value of this picker to the given hex color code.
+ * @param hexCode The hex color code.
+ * @see #setColor(int)
+ */
+ public void setColor (final String hexCode) {
+ setColor (parseColor (hexCode));
+ }
+
+ /**
+ * Set the color value for this color picker.
+ * this will in turn update value of the sliders
+ * and the color preview.
+ * @param color The new color value.
+ */
+ public void setColor (int color) {
this.alpha = alpha (color);
this.red = red (color);
this.green = green(color);
this.blue = blue (color);
-
+
this.binding.alphaSlider.setValue (alpha);
this.binding.redSlider.setValue (red);
this.binding.greenSlider.setValue (green);
this.binding.blueSlider.setValue (blue);
- this.binding.colorPreview.setBackgroundColor (color);
+ updatePreview ();
+ }
+
+ /**
+ * Get the int value of the color from the current
+ * values of alpha, red, green and blue color values.
+ * @return The int color value.
+ */
+ public int getColor () {
+ return argb (alpha, red, green, blue);
+ }
+
+ /**
+ * Call this method to update the preview of the current color.
+ */
+ private void updatePreview () {
+ this.binding.colorPreview.setBackgroundColor (getColor ());
+ }
+
+ /**
+ * A listener that can be used to get notified when the user picks a color.
+ *
+ * @author Akash Yadav
+ */
+ public interface OnPickListener {
+
+ /**
+ * Called when the user picks a color using the 'Pick' button.
+ * @param color The integer value of the color.
+ * @param hexCode The hex color code of the color.
+ */
+ void onPick (int color, String hexCode);
+ }
+
+ /**
+ * A TextWatcher that is used to listen for text updates in the
+ * hex color input field.
+ */
+ private class ColorTextWatcher implements TextWatcher {
+
+ @Override
+ public void beforeTextChanged (CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void afterTextChanged (Editable s) {
+ }
+
+ @Override
+ public void onTextChanged (CharSequence s, int start, int before, int count) {
+ try {
+ final var color = parseColor ("#" + s);
+ setColor (color);
+ } catch (Exception e) {
+ // May happen due to invalid color values
+ // Simply ignore
+ }
+ }
}
}
diff --git a/common/src/main/res/layout/layout_color_picker.xml b/common/src/main/res/layout/layout_color_picker.xml
index af4582cd0..e2d1dc1fc 100644
--- a/common/src/main/res/layout/layout_color_picker.xml
+++ b/common/src/main/res/layout/layout_color_picker.xml
@@ -17,7 +17,8 @@
+ android:layout_height="wrap_content"
+ android:paddingBottom="16dp">
@@ -47,9 +52,13 @@
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="255"
+ android:stepSize="1"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
- android:layout_marginTop="16dp"
+ android:layout_marginTop="8dp"
+ app:thumbColor="@android:color/holo_red_light"
+ app:trackColorActive="@android:color/holo_red_light"
+ app:tickVisible="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/alpha_slider"/>
@@ -60,9 +69,13 @@
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="255"
+ android:stepSize="1"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
- android:layout_marginTop="16dp"
+ android:layout_marginTop="8dp"
+ app:thumbColor="@android:color/holo_green_light"
+ app:trackColorActive="@android:color/holo_green_light"
+ app:tickVisible="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/red_slider"/>
@@ -74,9 +87,13 @@
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="255"
+ android:stepSize="1"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
- android:layout_marginTop="16dp"
+ android:layout_marginTop="8dp"
+ app:thumbColor="@android:color/holo_blue_dark"
+ app:trackColorActive="@android:color/holo_blue_dark"
+ app:tickVisible="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/green_slider"/>
@@ -86,9 +103,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_color_picker_pick"
- android:layout_marginTop="16dp"
+ android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
+ android:textColor="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/blue_slider"/>
@@ -99,17 +117,17 @@
android:hint="@string/msg_hex_color_code"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
- android:layout_marginTop="16dp"
+ android:layout_marginTop="8dp"
android:minWidth="100dp"
app:startIconDrawable="@drawable/ic_hex_icon"
- app:counterMaxLength="8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/pick"
app:layout_constraintTop_toBottomOf="@id/blue_slider">