diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-07 21:25:14 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-08 08:27:05 +0200 |
commit | e1381521c593620511113e70ebe1b0c52a1f0378 (patch) | |
tree | a4869daeb24ea629d4abda651ddd2bd77d2127c3 | |
parent | 5c50d8f7ee351e7605b382ae5b06ccaa8518747f (diff) |
android: Allow setting auto font/bg color
Add a button in the color palette UI
(that can be found in the bottom toolbar
under "Styles" -> "Font Color"/"Highlight Color"
when experimental editing mode is enabled) which
allows setting auto color for the font
or the highlighting/background.
This allows to unset any explicitly set color and
use the automatic color.
This is equivalent to the "Automatic"/"No fill color"
items in the font color and character highlighting
color popups in the desktop version.
Add a `boolean keepAlpha` param to
`sendFont{,Back}ColorChange` to be able
to distinguish between "auto color" and white
when -1/0xFFFFFFFF is passed as color.
See also previous commit
Change-Id I2e6512f32e671f92c8d31b2780c350dd74fb0747,
"android: Handle auto color as such", for some more
context.
Change-Id: I05182a2adbc00e64b1925ff52861a51ba8dcc21f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133996
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | android/source/res/drawable/ic_auto_color.xml | 10 | ||||
-rw-r--r-- | android/source/res/layout/toolbar_color_picker.xml | 32 | ||||
-rw-r--r-- | android/source/res/values-de/strings.xml | 1 | ||||
-rw-r--r-- | android/source/res/values/strings.xml | 1 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/FontController.java | 21 |
5 files changed, 52 insertions, 13 deletions
diff --git a/android/source/res/drawable/ic_auto_color.xml b/android/source/res/drawable/ic_auto_color.xml new file mode 100644 index 000000000000..3c68b556ee70 --- /dev/null +++ b/android/source/res/drawable/ic_auto_color.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M18,14c0,-4 -6,-10.8 -6,-10.8s-1.33,1.51 -2.73,3.52l8.59,8.59c0.09,-0.42 0.14,-0.86 0.14,-1.31zM17.12,17.12L12.5,12.5 5.27,5.27 4,6.55l3.32,3.32C6.55,11.32 6,12.79 6,14c0,3.31 2.69,6 6,6 1.52,0 2.9,-0.57 3.96,-1.5l2.63,2.63 1.27,-1.27 -2.74,-2.74z"/> +</vector> diff --git a/android/source/res/layout/toolbar_color_picker.xml b/android/source/res/layout/toolbar_color_picker.xml index e80f25bf46f6..6a8f81b2a842 100644 --- a/android/source/res/layout/toolbar_color_picker.xml +++ b/android/source/res/layout/toolbar_color_picker.xml @@ -21,13 +21,31 @@ android:layout_height="wrap_content" android:padding="10dp" android:orientation="vertical"> - <ImageButton - android:id="@+id/button_go_back_color_picker" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - app:srcCompat="@drawable/ic_arrow_back_black_24dp" - android:background="@drawable/image_button_background" - android:layout_marginBottom="10dp"/> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal"> + + <ImageButton + android:id="@+id/button_go_back_color_picker" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="10dp" + android:background="@drawable/image_button_background" + app:srcCompat="@drawable/ic_arrow_back_black_24dp" /> + + <Button + android:id="@+id/button_auto_color" + android:layout_alignParentRight="true" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="10dp" + android:background="@drawable/image_button_background" + android:text="@string/automatic" + app:drawableLeftCompat="@drawable/ic_auto_color" /> + + </RelativeLayout> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" diff --git a/android/source/res/values-de/strings.xml b/android/source/res/values-de/strings.xml index e1a87da475bf..41e8f6e2c7b1 100644 --- a/android/source/res/values-de/strings.xml +++ b/android/source/res/values-de/strings.xml @@ -168,4 +168,5 @@ <string name="highlight_color">Hervorhebungs-Farbe</string> <string name="font_color">Schriftfarbe</string> <string name="action_rename_slide">Folie umbenennen</string> + <string name="automatic">Automatisch</string> </resources> diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 49eea9f3014c..207be1c2c150 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -168,4 +168,5 @@ <string name="highlight_color">Highlight Color</string> <string name="font_color">Font Color</string> <string name="action_rename_slide">Rename Slide</string> + <string name="automatic">Automatic</string> </resources> diff --git a/android/source/src/java/org/libreoffice/FontController.java b/android/source/src/java/org/libreoffice/FontController.java index 2eb6b2f7f658..e0161076a5a1 100644 --- a/android/source/src/java/org/libreoffice/FontController.java +++ b/android/source/src/java/org/libreoffice/FontController.java @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -48,7 +49,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { final ColorPaletteListener colorPaletteListener = new ColorPaletteListener() { @Override public void applyColor(int color) { - sendFontColorChange(color); + sendFontColorChange(color, false); } @Override @@ -70,7 +71,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { final ColorPaletteListener backColorPaletteListener = new ColorPaletteListener() { @Override public void applyColor(int color) { - sendFontBackColorChange(color); + sendFontBackColorChange(color, false); } @Override @@ -141,12 +142,12 @@ public class FontController implements AdapterView.OnItemSelectedListener { } } - private void sendFontColorChange(int color){ + private void sendFontColorChange(int color, boolean keepAlpha){ try { JSONObject json = new JSONObject(); JSONObject valueJson = new JSONObject(); valueJson.put("type", "long"); - valueJson.put("value", 0x00FFFFFF & color); + valueJson.put("value", keepAlpha ? color : 0x00FFFFFF & color); json.put("Color", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Color", json.toString())); @@ -161,12 +162,12 @@ public class FontController implements AdapterView.OnItemSelectedListener { * 0x00FFFFFF & color operation removes the alpha which is FF, * if we don't remove it, the color value becomes negative which is not recognized by LOK */ - private void sendFontBackColorChange(int color){ + private void sendFontBackColorChange(int color, boolean keepAlpha) { try { JSONObject json = new JSONObject(); JSONObject valueJson = new JSONObject(); valueJson.put("type", "long"); - valueJson.put("value", 0x00FFFFFF & color); + valueJson.put("value", keepAlpha ? color : 0x00FFFFFF & color); if(mActivity.getTileProvider().isSpreadsheet()){ json.put("BackgroundColor", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:BackgroundColor", json.toString())); @@ -315,6 +316,10 @@ public class FontController implements AdapterView.OnItemSelectedListener { fontColorPicker.setOnClickListener(clickListener); fontColorPickerButton.setOnClickListener(clickListener); + final Button autoColorButton = colorPickerLayout.findViewById(R.id.button_auto_color); + autoColorButton.setOnClickListener(view -> { + sendFontColorChange(COLOR_AUTO, true); + }); } private void setupBackColorPicker(){ @@ -374,6 +379,10 @@ public class FontController implements AdapterView.OnItemSelectedListener { fontColorPicker.setOnClickListener(clickListener); fontColorPickerButton.setOnClickListener(clickListener); + final Button autoColorButton = backColorPickerLayout.findViewById(R.id.button_auto_color); + autoColorButton.setOnClickListener(view -> { + sendFontBackColorChange(COLOR_AUTO, true); + }); } public void selectFont(final String fontName) { |