#include <time.h>
#include <linux/input.h>
#include <cutils/klog.h>
+#include <utils/SystemClock.h>
#include "minui/minui.h"
#define NEXT_TIMEOUT_MS 5000
-#define LAST_TIMEOUT_S 30
+#define LAST_TIMEOUT_MS 30000
#define LOGE(x...) do { KLOG_ERROR("slideshow", x); } while (0)
return -1;
}
- if (ev.type == EV_KEY) {
+ if (ev.type == EV_KEY && ev.value == 1) {
*key_code = ev.code;
}
static void draw(const char *resname)
{
- gr_surface surface;
+ GRSurface* surface;
int w, h, x, y;
if (res_create_display_surface(resname, &surface) < 0) {
int input = false;
int opt;
long int timeout = NEXT_TIMEOUT_MS;
- time_t start;
+ int64_t start;
- while ((opt = getopt(argc, argv, "t")) != -1) {
+ while ((opt = getopt(argc, argv, "t:")) != -1) {
switch (opt) {
case 't':
timeout = strtol(optarg, NULL, 0);
if (timeout < 0 || timeout >= LONG_MAX) {
timeout = NEXT_TIMEOUT_MS;
- LOGE("invalid timeout %s, defaulting to %u\n", optarg,
+ LOGE("invalid timeout %s, defaulting to %ld\n", optarg,
timeout);
}
break;
while (optind < argc - 1) {
draw(argv[optind++]);
- if (ev_wait(timeout) == 0) {
- ev_dispatch();
+ start = android::uptimeMillis();
+ long int timeout_remaining = timeout;
+ do {
+ if (ev_wait(timeout_remaining) == 0) {
+ ev_dispatch();
- if (key_code != -1) {
- input = true;
+ if (key_code != -1) {
+ input = true;
+ break;
+ }
}
- }
+ timeout_remaining -= android::uptimeMillis() - start;
+ } while (timeout_remaining > 0);
};
/* if there was user input while showing the images, display the last
- * image and wait until the power button is pressed or LAST_TIMEOUT_S
+ * image and wait until the power button is pressed or LAST_TIMEOUT_MS
* has elapsed */
if (input) {
- start = time(NULL);
+ start = android::uptimeMillis();
+
draw(argv[optind]);
do {
ev_dispatch();
}
- if (time(NULL) - start >= LAST_TIMEOUT_S) {
+ if (android::uptimeMillis() - start >= LAST_TIMEOUT_MS) {
break;
}
} while (key_code != KEY_POWER);