android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java |   17 
++++++----
 1 file changed, 11 insertions(+), 6 deletions(-)

New commits:
commit 7c7e044f3cd6adc8ce639d01dc083827cdd87266
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Nov 27 10:55:51 2023 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Nov 27 14:04:13 2023 +0100

    tdf#158398 android: Center Calc header text
    
    Center the header text in the Calc header cell, to
    make better use of the space. This is in line with
    what the desktop version also does.
    
    Setting the text alignment to `Paint.Align.CENTER`
    is sufficient for centering horizontally.
    There's no equivalent for centering vertically, so
    calculate the position based on the text bounds.
    
    Change-Id: Ia8d5d8434b703cb7daecd34ae70405883f22f0d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159988
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java 
b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
index 1b2db6f65796..eec0b5e4a88d 100644
--- a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
+++ b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
@@ -4,6 +4,7 @@ import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Paint.Style;
+import android.graphics.Rect;
 import android.graphics.RectF;
 import android.text.TextPaint;
 
@@ -11,6 +12,7 @@ public class CalcHeaderCell extends CommonCanvasElement {
     private final TextPaint mTextPaint = new TextPaint();
     private final Paint mBgPaint = new Paint();
     private final RectF mBounds;
+    private final Rect mTextBounds = new Rect();
     private final String mText;
 
     public CalcHeaderCell(float left, float top, float width, float height, 
String text, boolean selected) {
@@ -26,7 +28,10 @@ public class CalcHeaderCell extends CommonCanvasElement {
         mBgPaint.setAlpha(100);  // hard coded for now
         mTextPaint.setColor(Color.GRAY);
         mTextPaint.setTextSize(24f); // hard coded for now
+        mTextPaint.setTextAlign(Paint.Align.CENTER);
         mText = text;
+
+        mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
     }
 
     /**
@@ -49,6 +54,6 @@ public class CalcHeaderCell extends CommonCanvasElement {
     @Override
     public void onDraw(Canvas canvas) {
         canvas.drawRect(mBounds, mBgPaint);
-        canvas.drawText(mText, mBounds.left, mBounds.bottom, mTextPaint);
+        canvas.drawText(mText, mBounds.centerX(), mBounds.centerY() - 
mTextBounds.centerY(), mTextPaint);
     }
 }
commit 808a94d85928545d8c8128f52116509c1ff8c121
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Nov 27 10:49:32 2023 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Nov 27 14:04:04 2023 +0100

    android: Make CalcHeaderCell fields final
    
    Change-Id: I7e14145569428a2803f9376cf719e524aa8963a8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159987
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java 
b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
index c1f8e74e7ba2..1b2db6f65796 100644
--- a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
+++ b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java
@@ -8,10 +8,10 @@ import android.graphics.RectF;
 import android.text.TextPaint;
 
 public class CalcHeaderCell extends CommonCanvasElement {
-    private TextPaint mTextPaint = new TextPaint();
-    private Paint mBgPaint = new Paint();
-    private RectF mBounds;
-    private String mText;
+    private final TextPaint mTextPaint = new TextPaint();
+    private final Paint mBgPaint = new Paint();
+    private final RectF mBounds;
+    private final String mText;
 
     public CalcHeaderCell(float left, float top, float width, float height, 
String text, boolean selected) {
         mBounds = new RectF(left, top, left + width, top + height);
@@ -51,4 +51,4 @@ public class CalcHeaderCell extends CommonCanvasElement {
         canvas.drawRect(mBounds, mBgPaint);
         canvas.drawText(mText, mBounds.left, mBounds.bottom, mTextPaint);
     }
-}
\ No newline at end of file
+}

Reply via email to