1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 // Allow use of stuff in <time.h>
24 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
25
26 // Disable printf override in common/forbidden.h to avoid
27 // clashes with log.h from the Android SDK.
28 // That header file uses
29 // __attribute__ ((format(printf, 3, 4)))
30 // which gets messed up by our override mechanism; this could
31 // be avoided by either changing the Android SDK to use the equally
32 // legal and valid
33 // __attribute__ ((format(printf, 3, 4)))
34 // or by refining our printf override to use a varadic macro
35 // (which then wouldn't be portable, though).
36 // Anyway, for now we just disable the printf override globally
37 // for the Android port
38 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
39
40 #include "backends/platform/android/android.h"
41 #include "backends/platform/android/jni-android.h"
42
43 #include "gui/ThemeEval.h"
44 #include "gui/widget.h"
45
46 #include "common/translation.h"
47
48 class AndroidOptionsWidget final : public GUI::OptionsContainerWidget {
49 public:
50 explicit AndroidOptionsWidget(GuiObject *boss, const Common::String &name, const Common::String &domain);
51 ~AndroidOptionsWidget() override;
52
53 // OptionsContainerWidget API
54 void load() override;
55 bool save() override;
56 bool hasKeys() override;
57 void setEnabled(bool e) override;
58
59 private:
60 // OptionsContainerWidget API
61 void defineLayout(GUI::ThemeEval &layouts, const Common::String &layoutName, const Common::String &overlayedLayout) const override;
62
63 GUI::CheckboxWidget *_onscreenCheckbox;
64 GUI::CheckboxWidget *_touchpadCheckbox;
65 GUI::CheckboxWidget *_onscreenSAFRevokeCheckbox;
66
67 bool _enabled;
68 };
69
AndroidOptionsWidget(GuiObject * boss,const Common::String & name,const Common::String & domain)70 AndroidOptionsWidget::AndroidOptionsWidget(GuiObject *boss, const Common::String &name, const Common::String &domain) :
71 OptionsContainerWidget(boss, name, "AndroidOptionsDialog", false, domain), _enabled(true) {
72 _onscreenCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "AndroidOptionsDialog.OnScreenControl", _("Show On-screen control"));
73 _touchpadCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "AndroidOptionsDialog.TouchpadMode", _("Touchpad mouse mode"));
74 if (domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
75 // Only show this checkbox in Options (via Options... in the launcher), and not at game domain level (via Edit Game...)
76 // I18N: Show a button to revoke Storage Access Framework permissions for Android
77 _onscreenSAFRevokeCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "AndroidOptionsDialog.SAFRevokePermsControl", _("Show SAF revoke permissions overlay button"));
78 }
79 }
80
~AndroidOptionsWidget()81 AndroidOptionsWidget::~AndroidOptionsWidget() {
82 }
83
defineLayout(GUI::ThemeEval & layouts,const Common::String & layoutName,const Common::String & overlayedLayout) const84 void AndroidOptionsWidget::defineLayout(GUI::ThemeEval &layouts, const Common::String &layoutName, const Common::String &overlayedLayout) const {
85 layouts.addDialog(layoutName, overlayedLayout)
86 .addLayout(GUI::ThemeLayout::kLayoutVertical)
87 .addPadding(0, 0, 0, 0)
88 .addWidget("OnScreenControl", "Checkbox")
89 .addWidget("TouchpadMode", "Checkbox");
90 if (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
91 layouts.addWidget("SAFRevokePermsControl", "Checkbox");
92 }
93 layouts.closeLayout()
94 .closeDialog();
95 }
96
load()97 void AndroidOptionsWidget::load() {
98 _onscreenCheckbox->setState(ConfMan.getBool("onscreen_control", _domain));
99 _touchpadCheckbox->setState(ConfMan.getBool("touchpad_mouse_mode", _domain));
100 if (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
101 _onscreenSAFRevokeCheckbox->setState(ConfMan.getBool("onscreen_saf_revoke_btn", _domain));
102 }
103 }
104
save()105 bool AndroidOptionsWidget::save() {
106 if (_enabled) {
107 ConfMan.setBool("onscreen_control", _onscreenCheckbox->getState(), _domain);
108 ConfMan.setBool("touchpad_mouse_mode", _touchpadCheckbox->getState(), _domain);
109 if (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
110 ConfMan.setBool("onscreen_saf_revoke_btn", _onscreenSAFRevokeCheckbox->getState(), _domain);
111 }
112 } else {
113 ConfMan.removeKey("onscreen_control", _domain);
114 ConfMan.removeKey("touchpad_mouse_mode", _domain);
115 if (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
116 ConfMan.removeKey("onscreen_saf_revoke_btn", _domain);
117 }
118 }
119
120 return true;
121 }
122
hasKeys()123 bool AndroidOptionsWidget::hasKeys() {
124 return ConfMan.hasKey("onscreen_control", _domain) ||
125 ConfMan.hasKey("touchpad_mouse_mode", _domain) ||
126 (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("onscreen_saf_revoke_btn", _domain));
127 }
128
setEnabled(bool e)129 void AndroidOptionsWidget::setEnabled(bool e) {
130 _enabled = e;
131
132 _onscreenCheckbox->setEnabled(e);
133 _touchpadCheckbox->setEnabled(e);
134 if (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain)) {
135 _onscreenSAFRevokeCheckbox->setEnabled(e);
136 }
137 }
138
139
buildBackendOptionsWidget(GUI::GuiObject * boss,const Common::String & name,const Common::String & target) const140 GUI::OptionsContainerWidget *OSystem_Android::buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const {
141 return new AndroidOptionsWidget(boss, name, target);
142 }
143
registerDefaultSettings(const Common::String & target) const144 void OSystem_Android::registerDefaultSettings(const Common::String &target) const {
145 ConfMan.registerDefault("onscreen_control", true);
146 ConfMan.registerDefault("touchpad_mouse_mode", true);
147 ConfMan.registerDefault("onscreen_saf_revoke_btn", false);
148 }
149
applyBackendSettings()150 void OSystem_Android::applyBackendSettings() {
151 JNI::showKeyboardControl(ConfMan.getBool("onscreen_control"));
152 JNI::showSAFRevokePermsControl(ConfMan.getBool("onscreen_saf_revoke_btn"));
153 _touchpad_mode = ConfMan.getBool("touchpad_mouse_mode");
154 }
155