summaryrefslogtreecommitdiff
path: root/android/source/src/java/org/libreoffice/MockTileProvider.java
blob: 19f7b48713b3d8ca84f51ffd44221a56fc1f3217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.libreoffice;

import android.graphics.Bitmap;
import android.graphics.PointF;
import android.view.KeyEvent;

import org.mozilla.gecko.gfx.BufferedCairoImage;
import org.mozilla.gecko.gfx.CairoImage;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.IntSize;

public class MockTileProvider implements TileProvider {
    private static final int TILE_SIZE = 256;
    private final GeckoLayerClient mLayerClient;
    private final String inputFile;

    public MockTileProvider(GeckoLayerClient layerClient, String input) {
        mLayerClient = layerClient;
        this.inputFile = input;

        for (int i = 0; i < 5; i++) {
            String partName = "Part " + i;
            final DocumentPartView partView = new DocumentPartView(i, partName);
            LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
                @Override
                public void run() {
                    LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdapter().add(partView);
                }
            });
        }
        LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
            @Override
            public void run() {
                LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdapter().notifyDataSetChanged();
            }
        });
    }

    @Override
    public int getPageWidth() {
        return 549;
    }

    @Override
    public int getPageHeight() {
        return 630 * 5;
    }

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public CairoImage createTile(float x, float y, IntSize tileSize, float zoom) {
        int tiles = (int) (getPageWidth() / TILE_SIZE) + 1;
        int tileNumber = (int) ((y / TILE_SIZE) * tiles + (x / TILE_SIZE));
        tileNumber %= 9;
        tileNumber += 1; // 0 to 1 based numbering

        String imageName = "d" + tileNumber;
        Bitmap bitmap = mLayerClient.getView().getDrawable(imageName);

        return new BufferedCairoImage(bitmap);
    }

    @Override
    public void rerenderTile(CairoImage image, float x, float y, IntSize tileSize, float zoom) {
    }

    @Override
    public Bitmap thumbnail(int size) {
        return mLayerClient.getView().getDrawable("dummy_page");
    }

    @Override
    public void close() {
    }

    @Override
    public boolean isTextDocument() {
        return true;
    }

    @Override
    public boolean isSpreadsheet() {
        return false;
    }

    @Override
    public void sendKeyEvent(KeyEvent keyEvent) {
    }

    @Override
    public void mouseButtonDown(PointF documentCoordinate, int numberOfClicks) {
    }

    @Override
    public void mouseButtonUp(PointF documentCoordinate, int numberOfClicks) {
    }

    @Override
    public void postUnoCommand(String command) {
    }

    @Override
    public void setTextSelectionStart(PointF documentCoordinate) {
    }

    @Override
    public void setTextSelectionEnd(PointF documentCoordinate) {
    }

    @Override
    public void setTextSelectionReset(PointF documentCoordinate) {
    }

    @Override
    public void setGraphicSelectionStart(PointF documentCoordinate) {
    }

    @Override
    public void setGraphicSelectionEnd(PointF documentCoordinate) {
    }

    @Override
    public void changePart(int partIndex) {
    }

    @Override
    public int getCurrentPartNumber() {
        return 0;
    }

    @Override
    public int getPartsCount() {
        return 0;
    }

    @Override
    public void onSwipeLeft() {
    }

    @Override
    public void onSwipeRight() {
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */