Nice keyboard animations

This commit is contained in:
Thomas Farstrike
2025-06-06 12:43:01 +02:00
parent 7a35d2f805
commit ba0b2bd6e2
3 changed files with 29 additions and 26 deletions
@@ -5,6 +5,7 @@ import lvgl as lv
import _thread
from mpos.apps import Activity, Intent
import mpos.ui.anim
import mpos.ui
import mpos.config
@@ -219,11 +220,12 @@ class PasswordPage(Activity):
connect_button=None
cancel_button=None
animator = mpos.ui.anim.WidgetAnimator()
def onCreate(self):
self.selected_ssid = self.getIntent().extras.get("selected_ssid")
print("PasswordPage: Creating new password page")
password_page=lv.obj()
password_page.set_size(lv.pct(100),lv.pct(100))
print(f"show_password_page: Creating label for SSID: {self.selected_ssid}")
label=lv.label(password_page)
label.set_text(f"Password for {self.selected_ssid}")
@@ -234,18 +236,6 @@ class PasswordPage(Activity):
self.password_ta.set_one_line(True)
self.password_ta.align_to(label, lv.ALIGN.OUT_BOTTOM_MID, 5, 0)
self.password_ta.add_event_cb(self.password_ta_cb,lv.EVENT.CLICKED,None)
pwd = self.findSavedPassword(self.selected_ssid)
if pwd:
self.password_ta.set_text(pwd)
self.password_ta.set_placeholder_text("Password")
print("PasswordPage: Creating keyboard (hidden by default)")
self.keyboard=lv.keyboard(password_page)
self.keyboard.set_size(lv.pct(100),0)
self.keyboard.align(lv.ALIGN.BOTTOM_LEFT,0,0)
self.keyboard.set_textarea(self.password_ta)
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.READY,None)
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.CANCEL,None)
self.keyboard.add_event_cb(self.keyboard_value_changed_cb,lv.EVENT.VALUE_CHANGED,None)
print("PasswordPage: Creating Connect button")
self.connect_button=lv.button(password_page)
self.connect_button.set_size(100,40)
@@ -262,13 +252,24 @@ class PasswordPage(Activity):
label=lv.label(self.cancel_button)
label.set_text("Close")
label.center()
pwd = self.findSavedPassword(self.selected_ssid)
if pwd:
self.password_ta.set_text(pwd)
self.password_ta.set_placeholder_text("Password")
print("PasswordPage: Creating keyboard (hidden by default)")
self.keyboard=lv.keyboard(password_page)
self.keyboard.align(lv.ALIGN.BOTTOM_MID,0,0)
self.keyboard.set_textarea(self.password_ta)
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.READY,None)
self.keyboard.add_event_cb(self.keyboard_cb,lv.EVENT.CANCEL,None)
self.keyboard.add_event_cb(self.keyboard_value_changed_cb,lv.EVENT.VALUE_CHANGED,None)
self.hide_keyboard()
print("PasswordPage: Loading password page")
self.setContentView(password_page)
def hide_keyboard(self):
print("keyboard_cb: READY or CANCEL or RETURN clicked, hiding keyboard")
self.keyboard.set_height(0)
self.keyboard.remove_state(lv.STATE.DISABLED)
self.animator.hide_widget(self.keyboard, anim_type="fade", duration=500, delay=0)
print("keyboard_cb: Showing Connect and Cancel buttons")
self.connect_button.remove_flag(lv.obj.FLAG.HIDDEN)
self.cancel_button.remove_flag(lv.obj.FLAG.HIDDEN)
@@ -295,8 +296,7 @@ class PasswordPage(Activity):
self.connect_button.add_flag(lv.obj.FLAG.HIDDEN)
self.cancel_button.add_flag(lv.obj.FLAG.HIDDEN)
print("password_ta_cb: Showing keyboard")
self.keyboard.set_height(160)
self.keyboard.add_flag(lv.obj.FLAG.CLICKABLE) # seems needed after showing/hiding the keyboard a few times
self.animator.show_widget(self.keyboard, anim_type="fade", duration=500, delay=0) # slide_up causes it to be placed way too low...
def connect_cb(self, event):
+1 -1
View File
@@ -149,7 +149,7 @@ def create_notification_bar():
notification_bar.set_size(lv.pct(100), NOTIFICATION_BAR_HEIGHT)
notification_bar.set_pos(0, show_bar_animation_start_value)
notification_bar.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
notification_bar.set_scroll_dir(lv.DIR.VER)
notification_bar.set_scroll_dir(lv.DIR.NONE)
notification_bar.set_style_border_width(0, 0)
notification_bar.set_style_radius(0, 0)
# Time label
+11 -8
View File
@@ -19,10 +19,10 @@ class WidgetAnimator:
anim.set_values(0, 255)
anim.set_time(duration)
anim.set_delay(delay)
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opacity(value, 0))
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0))
anim.set_path_cb(lv.anim_t.path_ease_in_out)
# Ensure opacity is reset after animation
anim.set_completed_cb(lambda *args: widget.set_style_opacity(255, 0))
anim.set_completed_cb(lambda *args: widget.set_style_opa(255, 0))
elif anim_type == "slide_down":
print("doing slide_down")
# Create slide-down animation (y from -height to original y)
@@ -40,6 +40,7 @@ class WidgetAnimator:
anim.set_completed_cb(lambda *args: widget.set_y(original_y))
elif anim_type == "slide_up":
# Create slide-up animation (y from +height to original y)
# Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
original_y = widget.get_y()
height = widget.get_height()
anim = lv.anim_t()
@@ -67,12 +68,13 @@ class WidgetAnimator:
anim.set_values(255, 0)
anim.set_time(duration)
anim.set_delay(delay)
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opacity(value, 0))
anim.set_custom_exec_cb(lambda anim, value: widget.set_style_opa(value, 0))
anim.set_path_cb(lv.anim_t.path_ease_in_out)
# Set HIDDEN flag after animation
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
elif anim_type == "slide_down":
# Create slide-down animation (y from original y to +height)
# Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
original_y = widget.get_y()
height = widget.get_height()
anim = lv.anim_t()
@@ -84,7 +86,7 @@ class WidgetAnimator:
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
anim.set_path_cb(lv.anim_t.path_ease_in_out)
# Set HIDDEN flag after animation
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
elif anim_type == "slide_up":
print("hide with slide_up")
# Create slide-up animation (y from original y to -height)
@@ -99,16 +101,17 @@ class WidgetAnimator:
anim.set_custom_exec_cb(lambda anim, value: widget.set_y(value))
anim.set_path_cb(lv.anim_t.path_ease_in_out)
# Set HIDDEN flag after animation
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget, original_y))
anim.set_completed_cb(lambda *args: self.hide_complete_cb(widget))
# Store and start animation
self.animations[widget] = anim
anim.start()
def hide_complete_cb(self, widget, original_y):
def hide_complete_cb(self, widget):
#print("hide_complete_cb")
widget.add_flag(lv.obj.FLAG.HIDDEN)
widget.set_y(original_y)
#if original_y:
# widget.set_y(original_y) # in case it shifted slightly due to rounding etc
def stop_animation(self, widget):