From 9e7ae8a62652258f3ecbf147b578b73286f6d4d8 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 9 Apr 2015 13:40:31 -0700 Subject: Move default implementations into Device. The current abstract class was a nice idea but has led to a lot of copy & paste in practice. Right now, no one we know of has any extra menu items, so let's make the default menu available to everyone. (If we assume that someone somewhere really does need custom device-specific menu options, a better API would let them add to our menu rather than replacing it.) Change-Id: I59f6a92f3ecd830c2ce78ce9da19eaaf472c5dfa --- device.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 device.cpp (limited to 'device.cpp') diff --git a/device.cpp b/device.cpp new file mode 100644 index 000000000..20a763f2b --- /dev/null +++ b/device.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device.h" + +// TODO: this is a lie for, say, fugu. +static const char* HEADERS[] = { + "Volume up/down to move highlight.", + "Power button to select.", + "", + NULL +}; + +static const char* ITEMS[] = { + "Reboot system now", + "Reboot to bootloader", + "Apply update from ADB", + "Apply update from SD card", + "Wipe data/factory reset", + "Wipe cache partition", + "View recovery logs", + "Power off", + NULL +}; + +const char* const* Device::GetMenuHeaders() { return HEADERS; } +const char* const* Device::GetMenuItems() { return ITEMS; } + +Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { + switch (menu_position) { + case 0: return REBOOT; + case 1: return REBOOT_BOOTLOADER; + case 2: return APPLY_ADB_SIDELOAD; + case 3: return APPLY_EXT; + case 4: return WIPE_DATA; + case 5: return WIPE_CACHE; + case 6: return READ_RECOVERY_LASTLOG; + case 7: return SHUTDOWN; + default: return NO_ACTION; + } +} -- cgit v1.2.3 From ec28340cf3af1029a00db1c83d78d14e8798e245 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 10 Apr 2015 10:01:53 -0700 Subject: Move "Mount /system" to the main menu. Everyone's adding secret key combinations for this anyway, and it's very useful when debugging. Change-Id: Iad549452b872a7af963dd649f283ebcd3ea24234 --- device.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'device.cpp') diff --git a/device.cpp b/device.cpp index 20a763f2b..af92b15bd 100644 --- a/device.cpp +++ b/device.cpp @@ -31,6 +31,7 @@ static const char* ITEMS[] = { "Apply update from SD card", "Wipe data/factory reset", "Wipe cache partition", + "Mount /system", "View recovery logs", "Power off", NULL @@ -44,11 +45,12 @@ Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { case 0: return REBOOT; case 1: return REBOOT_BOOTLOADER; case 2: return APPLY_ADB_SIDELOAD; - case 3: return APPLY_EXT; + case 3: return APPLY_SDCARD; case 4: return WIPE_DATA; case 5: return WIPE_CACHE; - case 6: return READ_RECOVERY_LASTLOG; - case 7: return SHUTDOWN; + case 6: return MOUNT_SYSTEM; + case 7: return VIEW_RECOVERY_LOGS; + case 8: return SHUTDOWN; default: return NO_ACTION; } } -- cgit v1.2.3 From 4af215b2c35b41e983753256ad6dbebbf879c982 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 10 Apr 2015 15:00:34 -0700 Subject: Auto-detect whether to use the long-press UI. Change-Id: Ie77a5584e301467c6a5e164d2c62d6f036b2c0c0 --- device.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'device.cpp') diff --git a/device.cpp b/device.cpp index af92b15bd..024fc3465 100644 --- a/device.cpp +++ b/device.cpp @@ -16,15 +16,21 @@ #include "device.h" -// TODO: this is a lie for, say, fugu. -static const char* HEADERS[] = { - "Volume up/down to move highlight.", - "Power button to select.", +static const char* REGULAR_HEADERS[] = { + "Volume up/down move highlight.", + "Power button activates.", "", NULL }; -static const char* ITEMS[] = { +static const char* LONG_PRESS_HEADERS[] = { + "Any button cycles highlight.", + "Long-press activates.", + "", + NULL +}; + +static const char* MENU_ITEMS[] = { "Reboot system now", "Reboot to bootloader", "Apply update from ADB", @@ -37,8 +43,13 @@ static const char* ITEMS[] = { NULL }; -const char* const* Device::GetMenuHeaders() { return HEADERS; } -const char* const* Device::GetMenuItems() { return ITEMS; } +const char* const* Device::GetMenuHeaders() { + return ui_->HasThreeButtons() ? REGULAR_HEADERS : LONG_PRESS_HEADERS; +} + +const char* const* Device::GetMenuItems() { + return MENU_ITEMS; +} Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { switch (menu_position) { @@ -54,3 +65,28 @@ Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { default: return NO_ACTION; } } + +int Device::HandleMenuKey(int key, int visible) { + if (!visible) { + return kNoAction; + } + + switch (key) { + case KEY_DOWN: + case KEY_VOLUMEDOWN: + return kHighlightDown; + + case KEY_UP: + case KEY_VOLUMEUP: + return kHighlightUp; + + case KEY_ENTER: + case KEY_POWER: + return kInvokeItem; + + default: + // If you have all of the above buttons, any other buttons + // are ignored. Otherwise, any button cycles the highlight. + return ui_->HasThreeButtons() ? kNoAction : kHighlightDown; + } +} -- cgit v1.2.3 From 8fd86d77f1a2f15c6fa95bc390bcbe646374873a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 13 Apr 2015 14:36:02 -0700 Subject: Move the menu header out of the menu. This makes it easier for us to deal with arbitrary information at the top, and means that headers added by specific commands don't overwrite the default ones. Add the fingerprint back, but broken up so it fits even on sprout's display. Change-Id: Id71da79ab1aa455a611d72756a3100a97ceb4c1c --- device.cpp | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'device.cpp') diff --git a/device.cpp b/device.cpp index 024fc3465..fd1a9875b 100644 --- a/device.cpp +++ b/device.cpp @@ -16,20 +16,6 @@ #include "device.h" -static const char* REGULAR_HEADERS[] = { - "Volume up/down move highlight.", - "Power button activates.", - "", - NULL -}; - -static const char* LONG_PRESS_HEADERS[] = { - "Any button cycles highlight.", - "Long-press activates.", - "", - NULL -}; - static const char* MENU_ITEMS[] = { "Reboot system now", "Reboot to bootloader", @@ -43,10 +29,6 @@ static const char* MENU_ITEMS[] = { NULL }; -const char* const* Device::GetMenuHeaders() { - return ui_->HasThreeButtons() ? REGULAR_HEADERS : LONG_PRESS_HEADERS; -} - const char* const* Device::GetMenuItems() { return MENU_ITEMS; } -- cgit v1.2.3