From 03fd6c56fe57dcd7cc4a7f7166a00ece42491558 Mon Sep 17 00:00:00 2001 From: Vojtech Bocek Date: Thu, 13 Mar 2014 18:46:34 +0100 Subject: Implement "take a screenshot" feature * Like in android - press power+volume down, screenshots are saved in /sdcard/Pictures/Screenshots (if /sdcard is mounted) or /tmp Change-Id: Iaefa15b11a1d5fdfac57d77388db1621f378a8d4 Signed-off-by: Vojtech Bocek --- gui/action.cpp | 49 ++++++++++++++++++ gui/devices/1024x600/res/ui.xml | 10 ++++ gui/devices/1024x768/res/ui.xml | 10 ++++ gui/devices/1080x1920/res/ui.xml | 5 ++ gui/devices/1200x1920/res/ui.xml | 5 ++ gui/devices/1280x800/res/ui.xml | 10 ++++ gui/devices/1920x1200/res/ui.xml | 10 ++++ gui/devices/240x240/res/ui.xml | 5 ++ gui/devices/2560x1600/res/ui.xml | 10 ++++ gui/devices/320x480/res/ui.xml | 5 ++ gui/devices/480x800/res/ui.xml | 5 ++ gui/devices/480x854/res/ui.xml | 5 ++ gui/devices/540x960/res/ui.xml | 5 ++ gui/devices/720x1280/res/ui.xml | 5 ++ gui/devices/800x1280/res/ui.xml | 5 ++ gui/devices/800x480/res/ui.xml | 10 ++++ minuitwrp/Android.mk | 2 +- minuitwrp/graphics.c | 4 +- minuitwrp/graphics_utils.c | 106 +++++++++++++++++++++++++++++++++++++++ minuitwrp/minui.h | 2 + twrp-functions.cpp | 18 +++++++ twrp-functions.hpp | 1 + 22 files changed, 284 insertions(+), 3 deletions(-) mode change 100755 => 100644 gui/devices/1024x600/res/ui.xml mode change 100755 => 100644 gui/devices/800x1280/res/ui.xml mode change 100755 => 100644 gui/devices/800x480/res/ui.xml create mode 100644 minuitwrp/graphics_utils.c diff --git a/gui/action.cpp b/gui/action.cpp index 3c5584d4a..b77e7e751 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -775,6 +776,54 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } + if (function == "screenshot") + { + time_t tm; + char path[256]; + int path_len; + uid_t uid = -1; + gid_t gid = -1; + + struct passwd *pwd = getpwnam("media_rw"); + if(pwd) { + uid = pwd->pw_uid; + gid = pwd->pw_gid; + } + + const std::string storage = DataManager::GetCurrentStoragePath(); + if(PartitionManager.Is_Mounted_By_Path(storage)) { + snprintf(path, sizeof(path), "%s/Pictures/Screenshots/", storage.c_str()); + } else { + strcpy(path, "/tmp/"); + } + + if(!TWFunc::Create_Dir_Recursive(path, 0666, uid, gid)) + return 0; + + tm = time(NULL); + path_len = strlen(path); + + // Screenshot_2014-01-01-18-21-38.png + strftime(path+path_len, sizeof(path)-path_len, "Screenshot_%Y-%m-%d-%H-%M-%S.png", localtime(&tm)); + + int res = gr_save_screenshot(path); + if(res == 0) { + chmod(path, 0666); + chown(path, uid, gid); + + gui_print("Screenshot was saved to %s\n", path); + + // blink to notify that the screenshow was taken + gr_color(255, 255, 255, 255); + gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + gr_flip(); + gui_forceRender(); + } else { + LOGERR("Failed to take a screenshot!\n"); + } + return 0; + } + if (isThreaded) { if (function == "fileexists") diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml old mode 100755 new mode 100644 index 4795ce0ed..5c9c63b68 --- a/gui/devices/1024x600/res/ui.xml +++ b/gui/devices/1024x600/res/ui.xml @@ -277,6 +277,11 @@ lock + + + + +