OSDN Git Service

ANRdaemon: move trace result from /sdcard to /data am: d93aa41807
[android-x86/system-extras.git] / slideshow / slideshow.cpp
index 25a2206..15824f8 100644 (file)
 #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)
 
@@ -38,7 +39,7 @@ static int input_cb(int fd, unsigned int epevents, void *data)
         return -1;
     }
 
-    if (ev.type == EV_KEY) {
+    if (ev.type == EV_KEY && ev.value == 1) {
         *key_code = ev.code;
     }
 
@@ -54,7 +55,7 @@ static void clear()
 
 static void draw(const char *resname)
 {
-    gr_surface surface;
+    GRSurface* surface;
     int w, h, x, y;
 
     if (res_create_display_surface(resname, &surface) < 0) {
@@ -85,16 +86,16 @@ int main(int argc, char **argv)
     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;
@@ -118,21 +119,28 @@ int main(int argc, char **argv)
     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 {
@@ -140,7 +148,7 @@ int main(int argc, char **argv)
                 ev_dispatch();
             }
 
-            if (time(NULL) - start >= LAST_TIMEOUT_S) {
+            if (android::uptimeMillis() - start >= LAST_TIMEOUT_MS) {
                 break;
             }
         } while (key_code != KEY_POWER);