|
1 | 1 | import lvgl as lv |
2 | | -from mpos.apps import Activity, Intent |
3 | | -from mpos.activity_navigator import ActivityNavigator |
4 | | - |
5 | | -from mpos.ui.keyboard import MposKeyboard |
| 2 | +from mpos.apps import Intent |
| 3 | +from mpos.ui import SettingsActivity as SettingsActivityFramework |
6 | 4 | from mpos import PackageManager, SettingActivity |
7 | 5 | import mpos.config |
8 | 6 | import mpos.ui |
|
12 | 10 | from check_imu_calibration import CheckIMUCalibrationActivity |
13 | 11 |
|
14 | 12 | # Used to list and edit all settings: |
15 | | -class SettingsActivity(Activity): |
| 13 | +class SettingsActivity(SettingsActivityFramework): |
16 | 14 | def __init__(self): |
17 | 15 | super().__init__() |
18 | 16 | self.prefs = None |
@@ -60,79 +58,9 @@ def __init__(self): |
60 | 58 | ] |
61 | 59 |
|
62 | 60 | def onCreate(self): |
63 | | - screen = lv.obj() |
64 | | - print("creating SettingsActivity ui...") |
65 | | - screen.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0) |
66 | | - screen.set_flex_flow(lv.FLEX_FLOW.COLUMN) |
67 | | - screen.set_style_border_width(0, 0) |
68 | | - self.setContentView(screen) |
69 | | - |
70 | | - def onResume(self, screen): |
71 | | - # reload settings because the SettingsActivity might have changed them - could be optimized to only load if it did: |
72 | | - self.prefs = mpos.config.SharedPreferences("com.micropythonos.settings") |
73 | | - |
74 | | - # Create settings entries |
75 | | - screen.clean() |
76 | | - # Get the group for focusable objects |
77 | | - focusgroup = lv.group_get_default() |
78 | | - if not focusgroup: |
79 | | - print("WARNING: could not get default focusgroup") |
80 | | - |
81 | | - for setting in self.settings: |
82 | | - #print(f"setting {setting.get('title')} has changed_callback {setting.get('changed_callback')}") |
83 | | - # Container for each setting |
84 | | - setting_cont = lv.obj(screen) |
85 | | - setting_cont.set_width(lv.pct(100)) |
86 | | - setting_cont.set_height(lv.SIZE_CONTENT) |
87 | | - setting_cont.set_style_border_width(1, 0) |
88 | | - #setting_cont.set_style_border_side(lv.BORDER_SIDE.BOTTOM, 0) |
89 | | - setting_cont.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0) |
90 | | - setting_cont.add_flag(lv.obj.FLAG.CLICKABLE) |
91 | | - setting["cont"] = setting_cont # Store container reference for visibility control |
92 | | - |
93 | | - # Title label (bold, larger) |
94 | | - title = lv.label(setting_cont) |
95 | | - title.set_text(setting["title"]) |
96 | | - title.set_style_text_font(lv.font_montserrat_16, 0) |
97 | | - title.set_pos(0, 0) |
98 | | - |
99 | | - # Value label (smaller, below title) |
100 | | - value = lv.label(setting_cont) |
101 | | - value.set_text(self.prefs.get_string(setting["key"], "(not set)" if not setting.get("dont_persist") else "(not persisted)")) |
102 | | - value.set_style_text_font(lv.font_montserrat_12, 0) |
103 | | - value.set_style_text_color(lv.color_hex(0x666666), 0) |
104 | | - value.set_pos(0, 20) |
105 | | - setting["value_label"] = value # Store reference for updating |
106 | | - setting_cont.add_event_cb(lambda e, s=setting: self.startSettingActivity(s), lv.EVENT.CLICKED, None) |
107 | | - setting_cont.add_event_cb(lambda e, container=setting_cont: self.focus_container(container),lv.EVENT.FOCUSED,None) |
108 | | - setting_cont.add_event_cb(lambda e, container=setting_cont: self.defocus_container(container),lv.EVENT.DEFOCUSED,None) |
109 | | - if focusgroup: |
110 | | - focusgroup.add_obj(setting_cont) |
111 | | - |
112 | | - def startSettingActivity(self, setting): |
113 | | - ui_type = setting.get("ui") |
114 | | - |
115 | | - activity_class = SettingActivity |
116 | | - if ui_type == "activity": |
117 | | - activity_class = setting.get("activity_class") |
118 | | - if not activity_class: |
119 | | - print("ERROR: Setting is defined as 'activity' ui without 'activity_class', aborting...") |
120 | | - |
121 | | - intent = Intent(activity_class=activity_class) |
122 | | - intent.putExtra("setting", setting) |
123 | | - intent.putExtra("prefs", self.prefs) |
124 | | - self.startActivity(intent) |
125 | | - |
126 | | - def focus_container(self, container): |
127 | | - print(f"container {container} focused, setting border...") |
128 | | - container.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN) |
129 | | - container.set_style_border_width(1, lv.PART.MAIN) |
130 | | - container.scroll_to_view(True) # scroll to bring it into view |
131 | | - |
132 | | - def defocus_container(self, container): |
133 | | - print(f"container {container} defocused, unsetting border...") |
134 | | - container.set_style_border_width(0, lv.PART.MAIN) |
135 | | - |
| 61 | + if not self.prefs: |
| 62 | + self.prefs = mpos.config.SharedPreferences("com.micropythonos.settings") |
| 63 | + super().onCreate() |
136 | 64 |
|
137 | 65 | # Change handlers: |
138 | 66 | def reset_into_bootloader(self, new_value): |
|
0 commit comments