summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2022-05-07 18:05:40 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2022-05-08 08:24:20 +0200
commitbc762b702d9869070b05d63e14a39a758a21ad3e (patch)
treec95a08512e007fec165384569761793ac76efc1a /android
parent9a249103de13f2a00fc17bf138d3e656f9a311b8 (diff)
android: Don't show any color in palette as selected if none matches
In Android Viewer with experimental editing mode enabled, doing the following resulted in black still being marked as the current font color in the "Style" -> "Font Color" UI. 1) create a new Writer doc in the desktop version with one paragraph that has the font color explicitly set to black and one with "Dark Brick 2" 2) open the doc in Android Viewer with experimental mode enabled 3) tap on the first paragraph with font color explicitly set to black 4) open the "Style" -> "Font Color" UI where the color could be changed (layout file: `toolbar_color_picker.xml`) -> black is marked as current font color (OK) 5) tap on the paragraph which has font color "Dark Brick 2" set -> black is still marked as current font color (NOK) This is because the indices of the previously set color would just remain set if the new color was not found in any of the palettes which contain a set of predefined colors. Change that to set the index for the `upperSelectedBox` palette to 0 (i.e. switch to the first palette), and the index of the `selectedBox` (i.e. color within the palette) to the special value of '-1' and don't mark any palette or color as selected in that case. The newly introduced `ColorPickerAdapter#unselectColors` will be used from elsewhere in a follow-up commit, so make it public right away. The two `ImageButton`s right in the "Style" tab in the toolbar (i.e. `font_color_picker_button` and `font_back_color_picker_button` in `toolbar_bottom.xml`) remain unchanged and keep showing the actual color, since those are not restricted to predefined colors in the palettes. For the case where no explicit font color is set (i.e. use of automatic font color, e.g. black if no background is set, but white if the background is set to black), the value '-1' is sent from the C++ side, and no color should be marked as selected in Android Viewer, which also works with this change in place in general. However, the current handling for the "automatic color" case on Android Viewer side looks suspicious in more ways that will be addressed in a follow-up commit. Change-Id: I228d57ace5341bd311761f40c477441d1e511d5d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133989 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
-rw-r--r--android/source/src/java/org/libreoffice/ColorPickerAdapter.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
index bae9c3ed7768..dbbf65cf67b8 100644
--- a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
+++ b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
@@ -40,7 +40,8 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.
public void onBindViewHolder(final ColorPickerViewHolder holder, int position) {
holder.colorBox.setBackgroundColor(colorList[position]);
- if (colorPaletteAdapter.getUpperSelectedBox() == position) {
+ if (colorPaletteAdapter.getUpperSelectedBox() == position
+ && colorPaletteAdapter.getSelectedBox() >= 0) {
holder.colorBox.setImageResource(R.drawable.ic_done_white_12dp);
} else {
holder.colorBox.setImageDrawable(null);
@@ -68,6 +69,15 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.
updateAdapter();
}
+ /**
+ * Switches to first palette, but doesn't mark any color as selected.
+ * Use this if no color in the palette matches the actual one.
+ */
+ public void unselectColors() {
+ colorPaletteAdapter.changePosition(0, -1);
+ updateAdapter();
+ }
+
private void selectSubColor(int position1, int position2) {
colorPaletteAdapter.setPosition(position1, position2);
}
@@ -123,21 +133,22 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.
updateAdapter();
return;
}
- /*
- Find the color if the palette points another color
- */
- if (colorPalette[colorPaletteAdapter.getUpperSelectedBox()][colorPaletteAdapter.getSelectedBox()] != color) {
- for (int i = 0; i < 11; i++) {
- for (int k = 0; k < 8; k++) {
- if (colorPalette[i][k] == color) {
- colorPaletteAdapter.changePosition(i, k);
- updateAdapter();
- return;
- }
+
+ // try to find and highlight the color in the existing palettes
+ for (int i = 0; i < 11; i++) {
+ for (int k = 0; k < 8; k++) {
+ if (colorPalette[i][k] == color) {
+ colorPaletteAdapter.changePosition(i, k);
+ updateAdapter();
+ return;
}
}
}
+
+ // no color in the palettes matched
+ unselectColors();
}
+
private void updateAdapter(){
LOKitShell.getMainHandler().post(new Runnable() {
@Override