summaryrefslogtreecommitdiff
path: root/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
blob: 2135dbfe9686fb4da7a2d07f1f3a0fec7b3463cb (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* -*- 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.impressremote.communication;

import org.libreoffice.impressremote.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.SparseArray;

public class SlideShow {

    private SparseArray<byte[]> mPreviewImages = new SparseArray<byte[]>();
    private SparseArray<String> mNotes = new SparseArray<String>();

    private int mSize = 0;
    private int mCurrentSlide = 0;
    private Context mContext;

    protected SlideShow(Context aContext) {
        mContext = aContext;
    }

    protected void setLength(int aSize) {
        mSize = aSize;
    }

    public int getSize() {
        return mSize;
    }

    public int getCurrentSlide() {
        return mCurrentSlide;
    }

    protected void setCurrentSlide(int aSlide) {
        mCurrentSlide = aSlide;
    }

    protected void putImage(int aSlide, byte[] aImage) {
        mPreviewImages.put(aSlide, aImage);
    }

    public Bitmap getImage(int aSlide) {
        byte[] aImage = mPreviewImages.get(aSlide);
        if (aImage == null) {
            return BitmapFactory.decodeResource(mContext.getResources(),
                            R.drawable.image_loading);
        }
        Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
        if (aBitmap == null) {
            return BitmapFactory.decodeResource(mContext.getResources(),
                            R.drawable.image_loading);
        }
        return aBitmap;
    }

    protected void putNotes(int aSlide, String aNotes) {
        mNotes.put(aSlide, aNotes);
    }

    public String getNotes(int aSlide) {
        String aNote = mNotes.get(aSlide);
        if (aNote != null) {
            return aNote;
        } else {
            return "";
        }
    }

    // ---------------------------------------------------- TIMER --------------
    private Timer mTimer = new Timer();

    public Timer getTimer() {
        return mTimer;
    }

    public class Timer {
        /**
         * This stores the starting time of the timer if running.
         *
         * If paused this stores how long the timer was previously running.
         */
        private long aTime = 0;

        private long mCountdownTime = 0;

        private boolean mIsRunning = false;

        private boolean mIsCountdown = false;

        /**
         * Set whether this timer should be a normal or a countdown timer.
         * @param aIsCountdown
         *     Whether this should be a countdown timer.
         */
        public void setCountdown(boolean aIsCountdown) {
            mIsCountdown = aIsCountdown;
            if (mIsRunning) {
                mIsRunning = false;
                aTime = 0;
            }
        }

        /**
         * Set the countdown time. Can be set, and isn't lost, whatever mode
         * the timer is running in.
         * @param aCountdownTime
         *      The countdown time.
         */
        public void setCountdownTime(long aCountdownTime) {
            mCountdownTime = aCountdownTime;
        }

        public long getCountdownTime() {
            return mCountdownTime;
        }

        public boolean isCountdown() {
            return mIsCountdown;
        }

        public boolean isRunning() {
            return mIsRunning;
        }

        /**
         * Reset the timer, and stop it it was running.
         */
        public void reset() {
            mIsRunning = false;
            aTime = 0;
        }

        public void startTimer() {
            if (mIsRunning)
                return;

            aTime = System.currentTimeMillis() - aTime;
            mIsRunning = true;
        }

        public void stopTimer() {
            if (!mIsRunning)
                return;

            aTime = System.currentTimeMillis() - aTime;
            mIsRunning = false;
        }

        /**
         * Get either how long this timer has been running, or how long the
         * timer still has left to run.
         * @return
         */
        public long getTimeMillis() {
            long aTimeRunning;
            // Determine how long we've been going.
            if (mIsRunning) {
                aTimeRunning = System.currentTimeMillis() - aTime;
            } else {
                aTimeRunning = aTime;
            }
            // And give the time going, or time left
            if (!mIsCountdown) {
                return aTimeRunning;
            } else {
                long aRet = mCountdownTime - aTimeRunning;
                if (aRet < 0) { // We have completed!
                    mIsRunning = false;
                    aRet = 0;
                }
                return aRet;
            }

        }
    }
}

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