@@ -13,9 +13,6 @@ class CameraActivity(Activity):
1313 CONFIGFILE = "config.json"
1414 SCANQR_CONFIG = "config_scanqr_mode.json"
1515
16- button_width = 75
17- button_height = 50
18-
1916 STATUS_NO_CAMERA = "No camera found."
2017 STATUS_SEARCHING_QR = "Searching QR codes...\n \n Hold still and try varying scan distance (10-25cm) and make the QR code big (4-12cm). Ensure proper lighting."
2118 STATUS_FOUND_QR = "Found QR, trying to decode... hold still..."
@@ -49,24 +46,20 @@ def onCreate(self):
4946 self .main_screen .set_style_border_width (0 , lv .PART .MAIN )
5047 self .main_screen .set_size (lv .pct (100 ), lv .pct (100 ))
5148 self .main_screen .set_scrollbar_mode (lv .SCROLLBAR_MODE .OFF )
49+
5250 # Initialize LVGL image widget
5351 self .image = lv .image (self .main_screen )
54- self .image .align (lv .ALIGN .LEFT_MID , 0 , 0 )
55- close_button = lv .button (self .main_screen )
56- close_button .set_size (self .button_width , self .button_height )
57- close_button .align (lv .ALIGN .TOP_RIGHT , 0 , 0 )
58- close_label = lv .label (close_button )
52+ self .close_button = lv .button (self .main_screen )
53+ close_label = lv .label (self .close_button )
5954 close_label .set_text (lv .SYMBOL .CLOSE )
6055 close_label .center ()
61- close_button .add_event_cb (lambda e : self .finish (),lv .EVENT .CLICKED ,None )
56+ self . close_button .add_event_cb (lambda e : self .finish (),lv .EVENT .CLICKED ,None )
6257 # Settings button
63- settings_button = lv .button (self .main_screen )
64- settings_button .set_size (self .button_width , self .button_height )
65- settings_button .align_to (close_button , lv .ALIGN .OUT_BOTTOM_MID , 0 , 10 )
66- settings_label = lv .label (settings_button )
58+ self .settings_button = lv .button (self .main_screen )
59+ settings_label = lv .label (self .settings_button )
6760 settings_label .set_text (lv .SYMBOL .SETTINGS )
6861 settings_label .center ()
69- settings_button .add_event_cb (lambda e : self .open_settings (),lv .EVENT .CLICKED ,None )
62+ self . settings_button .add_event_cb (lambda e : self .open_settings (),lv .EVENT .CLICKED ,None )
7063 #self.zoom_button = lv.button(self.main_screen)
7164 #self.zoom_button.set_size(self.button_width, self.button_height)
7265 #self.zoom_button.align(lv.ALIGN.RIGHT_MID, 0, self.button_height + 5)
@@ -75,31 +68,48 @@ def onCreate(self):
7568 #zoom_label.set_text("Z")
7669 #zoom_label.center()
7770 self .qr_button = lv .button (self .main_screen )
78- self .qr_button .set_size (self .button_width , self .button_height )
7971 self .qr_button .add_flag (lv .obj .FLAG .HIDDEN )
80- self .qr_button .align (lv .ALIGN .BOTTOM_RIGHT , 0 , 0 )
8172 self .qr_button .add_event_cb (self .qr_button_click ,lv .EVENT .CLICKED ,None )
8273 self .qr_label = lv .label (self .qr_button )
8374 #self.qr_label.set_text(lv.SYMBOL.EYE_OPEN)
8475 self .qr_label .set_text ("QR" )
8576 self .qr_label .center ()
8677
8778 self .snap_button = lv .button (self .main_screen )
88- self .snap_button .set_size (self .button_width , self .button_width )
89- self .snap_button .align_to (self .qr_button , lv .ALIGN .OUT_TOP_MID , 0 , - 10 )
9079 self .snap_button .add_flag (lv .obj .FLAG .HIDDEN )
9180 self .snap_button .add_event_cb (self .snap_button_click ,lv .EVENT .CLICKED ,None )
92- self .snap_button .set_style_radius (self .button_width , lv .PART .MAIN )
9381 snap_label = lv .label (self .snap_button )
9482 snap_label .set_text (lv .SYMBOL .OK )
9583 snap_label .center ()
9684
85+ self .image .align (lv .ALIGN .TOP_LEFT , 0 , 0 )
86+ if mpos_ui .DisplayMetrics .width () < mpos_ui .DisplayMetrics .height ():
87+ # poster
88+ self .button_width = int ((mpos_ui .DisplayMetrics .width () / 4 ) - 5 )
89+ self .button_height = 50
90+ self .resize_buttons ()
91+ self .snap_button .set_size (self .button_height , self .button_height )
92+ self .close_button .align (lv .ALIGN .BOTTOM_RIGHT , 0 , 0 )
93+ self .settings_button .align_to (self .close_button , lv .ALIGN .OUT_LEFT_MID , - 5 , 0 )
94+ self .qr_button .align (lv .ALIGN .BOTTOM_LEFT , 0 , 0 )
95+ self .snap_button .align_to (self .qr_button , lv .ALIGN .OUT_RIGHT_MID , 5 , - 2 ) # needs -2 to avoid being too low
96+ else :
97+ # landscape
98+ self .button_width = 75
99+ self .button_height = int ((mpos_ui .DisplayMetrics .height () / 4 ) - 10 )
100+ self .resize_buttons ()
101+ self .snap_button .set_size (self .button_height , self .button_height )
102+ self .close_button .align (lv .ALIGN .TOP_RIGHT , 0 , 0 )
103+ self .settings_button .align_to (self .close_button , lv .ALIGN .OUT_BOTTOM_MID , 0 , 10 )
104+ self .qr_button .align (lv .ALIGN .BOTTOM_RIGHT , 0 , 0 )
105+ self .snap_button .align_to (self .qr_button , lv .ALIGN .OUT_TOP_MID , 0 , - 10 )
106+
97107 self .status_label_cont = lv .obj (self .main_screen )
98108 width = mpos_ui .DisplayMetrics .pct_of_width (70 )
99- height = mpos_ui .DisplayMetrics .pct_of_width (60 )
109+ height = mpos_ui .DisplayMetrics .pct_of_height (60 )
100110 self .status_label_cont .set_size (width ,height )
101- center_w = round ((mpos_ui .DisplayMetrics .pct_of_width ( 100 ) - self .button_width - 5 - width )/ 2 )
102- center_h = round ((mpos_ui .DisplayMetrics .pct_of_height ( 100 ) - height )/ 2 )
111+ center_w = round ((mpos_ui .DisplayMetrics .width ( ) - self .button_width - 5 - width )/ 2 )
112+ center_h = round ((mpos_ui .DisplayMetrics .height ( ) - height )/ 2 )
103113 self .status_label_cont .set_pos (center_w ,center_h )
104114 self .status_label_cont .set_style_bg_color (lv .color_white (), lv .PART .MAIN )
105115 self .status_label_cont .set_style_bg_opa (66 , lv .PART .MAIN )
@@ -130,6 +140,12 @@ def onPause(self, screen):
130140 self .stop_cam ()
131141 print ("camera app cleanup done." )
132142
143+ def resize_buttons (self ):
144+ self .close_button .set_size (self .button_width , self .button_height )
145+ self .settings_button .set_size (self .button_width , self .button_height )
146+ self .qr_button .set_size (self .button_width , self .button_height )
147+ self .snap_button .set_style_radius (self .button_width , lv .PART .MAIN )
148+
133149 def start_cam (self ):
134150 # Init camera:
135151 self .cam = CameraManager .get_cameras ()[0 ].init (self .width , self .height , self .colormode )
@@ -194,9 +210,10 @@ def update_preview_image(self):
194210 'data' : None # Will be updated per frame
195211 })
196212 self .image .set_src (self .image_dsc )
197- disp = lv .display_get_default ()
198- target_h = disp .get_vertical_resolution ()
199- #target_w = disp.get_horizontal_resolution() - self.button_width - 5 # leave 5px for border
213+ if mpos_ui .DisplayMetrics .width () < mpos_ui .DisplayMetrics .height ():
214+ target_h = mpos_ui .DisplayMetrics .width ()
215+ else :
216+ target_h = mpos_ui .DisplayMetrics .height ()
200217 target_w = target_h # square
201218 print (f"scaling to size: { target_w } x{ target_h } " )
202219 scale_factor_w = round (target_w * 256 / self .width )
0 commit comments