LibreOffice Module android (master) 1
PageNumberRect.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
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 */
8package org.libreoffice.canvas;
9
10import android.graphics.Canvas;
11import android.graphics.Color;
12import android.graphics.Paint;
13import android.graphics.Rect;
14import android.text.TextPaint;
15
16/*
17 * A canvas element on DocumentOverlayView. Shows a rectangle with current page
18 * number and total page number inside of it.
19 */
20public class PageNumberRect extends CommonCanvasElement {
22 private TextPaint mPageNumberRectPaint = new TextPaint();
23 private Paint mBgPaint = new Paint();
24 private Rect mTextBounds = new Rect();
25 private float mBgMargin = 5f;
26
27 public PageNumberRect() {
28 mBgPaint.setColor(Color.BLACK);
29 mBgPaint.setAlpha(100);
30 mPageNumberRectPaint.setColor(Color.WHITE);
31 }
32
39 @Override
40 public boolean onHitTest(float x, float y) {
41 return false;
42 }
43
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);
58 }
59
60 public void setPageNumberString (String pageNumberString) {
61 mPageNumberString = pageNumberString;
63 }
64}
Common implementation to canvas elements.
boolean onHitTest(float x, float y)
Implement hit test here.
void setPageNumberString(String pageNumberString)
void onDraw(Canvas canvas)
Called inside draw if the element is visible.