Update git submodules
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / PageNumberRect.java
blob62de88ea5441c2c9f1d6673e30249eb9a2101fac
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8 package org.libreoffice.canvas;
10 import android.graphics.Canvas;
11 import android.graphics.Color;
12 import android.graphics.Paint;
13 import android.graphics.Rect;
14 import android.text.TextPaint;
17 * A canvas element on DocumentOverlayView. Shows a rectangle with current page
18 * number and total page number inside of it.
20 public class PageNumberRect extends CommonCanvasElement {
21 private String mPageNumberString;
22 private TextPaint mPageNumberRectPaint = new TextPaint();
23 private Paint mBgPaint = new Paint();
24 private Rect mTextBounds = new Rect();
25 private float mBgMargin = 5f;
27 public PageNumberRect() {
28 mBgPaint.setColor(Color.BLACK);
29 mBgPaint.setAlpha(100);
30 mPageNumberRectPaint.setColor(Color.WHITE);
33 /**
34 * Implement hit test here
36 * @param x - x coordinate of the
37 * @param y - y coordinate of the
39 @Override
40 public boolean onHitTest(float x, float y) {
41 return false;
44 /**
45 * Called inside draw if the element is visible. Override this method to
46 * draw the element on the canvas.
48 * @param canvas - the canvas
50 @Override
51 public void onDraw(Canvas canvas) {
52 canvas.drawRect(canvas.getWidth()*0.1f - mBgMargin,
53 canvas.getHeight()*0.1f - mTextBounds.height() - mBgMargin,
54 mTextBounds.width() + canvas.getWidth()*0.1f + mBgMargin,
55 canvas.getHeight()*0.1f + mBgMargin,
56 mBgPaint);
57 canvas.drawText(mPageNumberString, canvas.getWidth()*0.1f, canvas.getHeight()*0.1f, mPageNumberRectPaint);
60 public void setPageNumberString (String pageNumberString) {
61 mPageNumberString = pageNumberString;
62 mPageNumberRectPaint.getTextBounds(mPageNumberString, 0, mPageNumberString.length(), mTextBounds);