Skip to content

Commit ba0b2bd

Browse files
Nice keyboard animations
1 parent 7a35d2f commit ba0b2bd

3 files changed

Lines changed: 29 additions & 26 deletions

File tree

internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import _thread
66

77
from mpos.apps import Activity, Intent
8+
import mpos.ui.anim
89
import mpos.ui
910
import mpos.config
1011

@@ -219,11 +220,12 @@ class PasswordPage(Activity):
219220
connect_button=None
220221
cancel_button=None
221222

223+
animator = mpos.ui.anim.WidgetAnimator()
224+
222225
def onCreate(self):
223226
self.selected_ssid = self.getIntent().extras.get("selected_ssid")
224227
print("PasswordPage: Creating new password page")
225228
password_page=lv.obj()
226-
password_page.set_size(lv.pct(100),lv.pct(100))
227229
print(f"show_password_page: Creating label for SSID: {self.selected_ssid}")
228230
label=lv.label(password_page)
229231
label.set_text(f"Password for {self.selected_ssid}")
@@ -234,18 +236,6 @@ def onCreate(self):
234236
self.password_ta.set_one_line(True)
235237
self.password_ta.align_to(label, lv.ALIGN.OUT_BOTTOM_MID, 5, 0)
236238
self.password_ta.add_event_cb(self.password_ta_cb,lv.EVENT.CLICKED,None)
237-
pwd = self.findSavedPassword(self.selected_ssid)
238-
if pwd:
239-
self.password_ta.set_text(pwd)
240-
self.password_ta.set_placeholder_text("Password")
241-
print("PasswordPage: Creating keyboard (hidden by default)")
242-
self.keyboard=lv.keyboard(password_page)
243-
self.keyboard.set_size(lv.pct(100),0)
244-
self.keyboard.align(lv.ALIGN.BOTTOM_LEFT,0,0)
245-
self.keyboard.set_textarea(self.password_ta)
246-
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.READY,None)
247-
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.CANCEL,None)
248-
self.keyboard.add_event_cb(self.keyboard_value_changed_cb,lv.EVENT.VALUE_CHANGED,None)
249239
print("PasswordPage: Creating Connect button")
250240
self.connect_button=lv.button(password_page)
251241
self.connect_button.set_size(100,40)
@@ -262,13 +252,24 @@ def onCreate(self):
262252
label=lv.label(self.cancel_button)
263253
label.set_text("Close")
264254
label.center()
255+
pwd = self.findSavedPassword(self.selected_ssid)
256+
if pwd:
257+
self.password_ta.set_text(pwd)
258+
self.password_ta.set_placeholder_text("Password")
259+
print("PasswordPage: Creating keyboard (hidden by default)")
260+
self.keyboard=lv.keyboard(password_page)
261+
self.keyboard.align(lv.ALIGN.BOTTOM_MID,0,0)
262+
self.keyboard.set_textarea(self.password_ta)
263+
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.READY,None)
264+
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.CANCEL,None)
265+
self.keyboard.add_event_cb(self.keyboard_value_changed_cb,lv.EVENT.VALUE_CHANGED,None)
266+
self.hide_keyboard()
265267
print("PasswordPage: Loading password page")
266268
self.setContentView(password_page)
267269

268270
def hide_keyboard(self):
269271
print("keyboard_cb: READY or CANCEL or RETURN clicked, hiding keyboard")
270-
self.keyboard.set_height(0)
271-
self.keyboard.remove_state(lv.STATE.DISABLED)
272+
self.animator.hide_widget(self.keyboard, anim_type="fade", duration=500, delay=0)
272273
print("keyboard_cb: Showing Connect and Cancel buttons")
273274
self.connect_button.remove_flag(lv.obj.FLAG.HIDDEN)
274275
self.cancel_button.remove_flag(lv.obj.FLAG.HIDDEN)
@@ -295,8 +296,7 @@ def password_ta_cb(self, event):
295296
self.connect_button.add_flag(lv.obj.FLAG.HIDDEN)
296297
self.cancel_button.add_flag(lv.obj.FLAG.HIDDEN)
297298
print("password_ta_cb: Showing keyboard")
298-
self.keyboard.set_height(160)
299-
self.keyboard.add_flag(lv.obj.FLAG.CLICKABLE) # seems needed after showing/hiding the keyboard a few times
299+
self.animator.show_widget(self.keyboard, anim_type="fade", duration=500, delay=0) # slide_up causes it to be placed way too low...
300300

301301

302302
def connect_cb(self, event):

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def create_notification_bar():
149149
notification_bar.set_size(lv.pct(100), NOTIFICATION_BAR_HEIGHT)
150150
notification_bar.set_pos(0, show_bar_animation_start_value)
151151
notification_bar.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
152-
notification_bar.set_scroll_dir(lv.DIR.VER)
152+
notification_bar.set_scroll_dir(lv.DIR.NONE)
153153
notification_bar.set_style_border_width(0, 0)
154154
notification_bar.set_style_radius(0, 0)
155155
# Time label

internal_filesystem/lib/mpos/ui/anim.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def show_widget(self, widget, anim_type="fade", duration=500, delay=0):
1919
anim.set_values(0, 255)
2020
anim.set_time(duration)
2121
anim.set_delay(delay)
22-
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opacity(value, 0))
22+
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0))
2323
anim.set_path_cb(lv.anim_t.path_ease_in_out)
2424
# Ensure opacity is reset after animation
25-
anim.set_completed_cb(lambda *args: widget.set_style_opacity(255, 0))
25+
anim.set_completed_cb(lambda *args: widget.set_style_opa(255, 0))
2626
elif anim_type == "slide_down":
2727
print("doing slide_down")
2828
# Create slide-down animation (y from -height to original y)
@@ -40,6 +40,7 @@ def show_widget(self, widget, anim_type="fade", duration=500, delay=0):
4040
anim.set_completed_cb(lambda *args: widget.set_y(original_y))
4141
elif anim_type == "slide_up":
4242
# Create slide-up animation (y from +height to original y)
43+
# Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
4344
original_y = widget.get_y()
4445
height = widget.get_height()
4546
anim = lv.anim_t()
@@ -67,12 +68,13 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
6768
anim.set_values(255, 0)
6869
anim.set_time(duration)
6970
anim.set_delay(delay)
70-
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opacity(value, 0))
71+
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0))
7172
anim.set_path_cb(lv.anim_t.path_ease_in_out)
7273
# Set HIDDEN flag after animation
73-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
74+
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
7475
elif anim_type == "slide_down":
7576
# Create slide-down animation (y from original y to +height)
77+
# Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
7678
original_y = widget.get_y()
7779
height = widget.get_height()
7880
anim = lv.anim_t()
@@ -84,7 +86,7 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
8486
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
8587
anim.set_path_cb(lv.anim_t.path_ease_in_out)
8688
# Set HIDDEN flag after animation
87-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
89+
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
8890
elif anim_type == "slide_up":
8991
print("hide with slide_up")
9092
# Create slide-up animation (y from original y to -height)
@@ -99,16 +101,17 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
99101
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
100102
anim.set_path_cb(lv.anim_t.path_ease_in_out)
101103
# Set HIDDEN flag after animation
102-
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
104+
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
103105

104106
# Store and start animation
105107
self.animations[widget] = anim
106108
anim.start()
107109

108-
def hide_complete_cb(self, widget, original_y):
110+
def hide_complete_cb(self, widget):
109111
#print("hide_complete_cb")
110112
widget.add_flag(lv.obj.FLAG.HIDDEN)
111-
widget.set_y(original_y)
113+
#if original_y:
114+
# widget.set_y(original_y) # in case it shifted slightly due to rounding etc
112115

113116

114117
def stop_animation(self, widget):

0 commit comments

Comments
 (0)