android/source/src/java/org/libreoffice/ColorPickerAdapter.java |    9 --
 android/source/src/java/org/libreoffice/FontController.java     |   45 
++++++----
 2 files changed, 27 insertions(+), 27 deletions(-)

New commits:
commit 5c50d8f7ee351e7605b382ae5b06ccaa8518747f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat May 7 19:23:12 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun May 8 08:25:36 2022 +0200

    android: Handle auto color as such
    
    When no color is explicitly set for the font/background
    (i.e. automatic color is used which would e.g. be black
    for the font if no background color is set or white
    if a black highlight color is set in Writer), the value
    for the color sent in the ".uno:Color" event for the font
    color and similarly for the background/highlight color
    (".uno:BackgroundColor" in Calc, ".uno:CharBackColor"
    in Impress, ".uno:BackColor" in Writer) is -1.
    
    The previous handling of that special value was problematic:
    
    1) Where handled specifically, -1 was interpreted as "black color"
    rather than "auto/no color".
    
    2) The color handled by the above-mentioned UNO events
    does not contain/handle the alpha channel, while Android
    does, so a conversion happens to add/remove the alpha
    layer.
    However, the anonymous `ColorPaletteListener`s that handle font
    and background color updates in their `updateColorPickerPosition`
    methods were not doing a logical or to add an alpha channel to
    the LO-provided color, but *adding* 0xFF000000 instead, which is
    the same for actual colors without an alpha channel set, but
    the actual special value of -1 (0xFFFFFFFF) would then
    be converted to 0xFEFFFFFF and no longer be treated as
    special.
    
    The way of treating -1 as black would also have the
    side effect that an explicit white color (0x00FFFFFF) would
    be converted to 0xFFFFFFFF, which is -1, and
    would therefore be treated as black.
    (So setting font color to white would result in black
    being shown as font color in the font color UI in experimental
    mode instead...)
    
    In order to actually handle auto color as such, handle
    the special value of -1 right in the `updateColorPickerPosition`
    methods: In that case, unselect any explicitly selected color
    (and set color to transparent for the buttons in the "Style"
    tab of the toolbar, `font_color_picker_button`
    and `font_back_color_picker_button` in `toolbar_bottom.xml`).
    Also, do a logical or to add the alpha layer instead
    of adding 0xFF000000.
    
    While at it, unify the code in the two
    `updateColorPickerPosition` methods a bit.
    
    Change-Id: I2e6512f32e671f92c8d31b2780c350dd74fb0747
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133992
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java 
b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
index dbbf65cf67b8..a17dd264fb99 100644
--- a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
+++ b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java
@@ -125,15 +125,6 @@ public class ColorPickerAdapter extends 
RecyclerView.Adapter<ColorPickerAdapter.
     }
 
     public void findSelectedTextColor(int color) {
-        /*
-            Libreoffice recognizes -1 as Black
-         */
-        if (color == -1) {
-            colorPaletteAdapter.changePosition(0, 0);
-            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++) {
diff --git a/android/source/src/java/org/libreoffice/FontController.java 
b/android/source/src/java/org/libreoffice/FontController.java
index ab8ffe307363..2eb6b2f7f658 100644
--- a/android/source/src/java/org/libreoffice/FontController.java
+++ b/android/source/src/java/org/libreoffice/FontController.java
@@ -23,6 +23,9 @@ import java.util.Iterator;
 
 public class FontController implements AdapterView.OnItemSelectedListener {
 
+    /** -1 as value in ".uno:Color" et al. means "automatic color"/no color 
set. */
+    private static final int COLOR_AUTO = -1;
+
     private boolean mFontNameSpinnerSet = false;
     private boolean mFontSizeSpinnerSet = false;
     private final LibreOfficeMainActivity mActivity;
@@ -50,9 +53,17 @@ public class FontController implements 
AdapterView.OnItemSelectedListener {
 
         @Override
         public void updateColorPickerPosition(int color) {
-            if (null == colorPickerAdapter) return;
-            colorPickerAdapter.findSelectedTextColor(color + 0xFF000000);
-            changeFontColorBoxColor(color + 0xFF000000);
+            if (colorPickerAdapter == null) {
+                return;
+            }
+            if (color == COLOR_AUTO) {
+                colorPickerAdapter.unselectColors();
+                changeFontColorBoxColor(Color.TRANSPARENT);
+                return;
+            }
+            final int colorWithAlpha = color | 0xFF000000;
+            colorPickerAdapter.findSelectedTextColor(colorWithAlpha);
+            changeFontColorBoxColor(colorWithAlpha);
         }
     };
 
@@ -64,10 +75,17 @@ public class FontController implements 
AdapterView.OnItemSelectedListener {
 
         @Override
         public void updateColorPickerPosition(int color) {
-            if(backColorPickerAdapter != null)
-            backColorPickerAdapter.findSelectedTextColor(color + 0xFF000000);
-            changeFontBackColorBoxColor(color + 0xFF000000);
-
+            if (backColorPickerAdapter == null) {
+                return;
+            }
+            if (color == COLOR_AUTO) {
+                backColorPickerAdapter.unselectColors();
+                changeFontBackColorBoxColor(Color.TRANSPARENT);
+                return;
+            }
+            final int colorWithAlpha = color | 0xFF000000;
+            backColorPickerAdapter.findSelectedTextColor(colorWithAlpha);
+            changeFontBackColorBoxColor(colorWithAlpha);
         }
     };
 
@@ -77,11 +95,7 @@ public class FontController implements 
AdapterView.OnItemSelectedListener {
         LOKitShell.getMainHandler().post(new Runnable() {
             @Override
             public void run() {
-                if(color == -1){ //Libreoffice recognizes -1 as black
-                    fontColorPickerButton.setBackgroundColor(Color.BLACK);
-                }else{
-                    fontColorPickerButton.setBackgroundColor(color);
-                }
+                fontColorPickerButton.setBackgroundColor(color);
             }
         });
     }
@@ -92,12 +106,7 @@ public class FontController implements 
AdapterView.OnItemSelectedListener {
         LOKitShell.getMainHandler().post(new Runnable() {
             @Override
             public void run() {
-                if(color == -1){ //Libreoffice recognizes -1 as black
-                    fontBackColorPickerButton.setBackgroundColor(Color.BLACK);
-                }else{
-                    fontBackColorPickerButton.setBackgroundColor(color);
-
-                }
+                fontBackColorPickerButton.setBackgroundColor(color);
             }
         });
     }

Reply via email to