Skip to content

Commit caa02b6

Browse files
committed
Add a popup dialog to help enabling developer options, add a final view to confirm success and close the app window
1 parent 163bac3 commit caa02b6

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed
105 KB
Loading

openandroidinstaller/openandroidinstaller.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Main app code for openAndroidInstaller."""
22

33

4+
from ctypes import alignment
45
import webbrowser
56
from functools import partial
67
from os import path
@@ -13,7 +14,8 @@
1314
from flet import (AppBar, Banner, Checkbox, Column, Container, Divider,
1415
ElevatedButton, FilePicker, FilePickerResultEvent, Icon,
1516
Image, Page, ProgressBar, ProgressRing, Row, Text,
16-
TextButton, TextField, UserControl, VerticalDivider, colors,
17+
TextButton, TextField, UserControl, VerticalDivider, colors, FilledButton,
18+
AlertDialog,
1719
icons)
1820
from installer_config import InstallerConfig, Step
1921
from widgets import call_button, confirm_button, get_title
@@ -27,7 +29,7 @@ def __init__(self, image: str = "placeholder.png"):
2729
super().__init__()
2830
self.right_view = Column(expand=True)
2931
self.left_view = Column(
30-
width=400, controls=[Image(src=IMAGE_PATH + "/" + image)], expand=True
32+
width=480, controls=[Image(src=IMAGE_PATH + "/" + image)], expand=True, horizontal_alignment="center",
3133
)
3234
# main view row
3335
self.view = Row(
@@ -37,10 +39,11 @@ def __init__(self, image: str = "placeholder.png"):
3739

3840

3941
class WelcomeView(BaseView):
40-
def __init__(self, on_confirm: Callable, load_config: Callable):
42+
def __init__(self, on_confirm: Callable, load_config: Callable, page: Page):
4143
super().__init__(image="connect-to-usb.png")
4244
self.on_confirm = on_confirm
4345
self.load_config = load_config
46+
self.page = page
4447

4548
def build(self):
4649
self.continue_button = ElevatedButton(
@@ -57,6 +60,15 @@ def build(self):
5760
disabled=True,
5861
label_position="left",
5962
)
63+
self.dlg_help_developer_options = AlertDialog(
64+
modal=True,
65+
title=Text("How to enable developer options and OEM unlocking"),
66+
content=Text("To do this, tap seven times on the build number in the System-Menu in Settings. Then in developer options, toggle OEM unlocking and USB-Debugging."),
67+
actions=[
68+
TextButton("Close", on_click=self.close_developer_options_dlg),
69+
],
70+
actions_alignment="end",
71+
)
6072
self.right_view.controls.extend(
6173
[
6274
get_title("Welcome to the OpenAndroidInstaller!"),
@@ -69,8 +81,9 @@ def build(self):
6981
),
7082
Divider(),
7183
Text(
72-
"Enable USB debugging on your device by enabling developer options. To do this, tap seven times on the build number in the System-Menu in Settings. Then in developer options, toggle OEM unlocking and USB-Debugging."
84+
"Enable USB debugging and OEM unlocking on your device by enabling developer options."
7385
),
86+
Row([FilledButton("How do I enable developer mode?", on_click=self.open_developer_options_dlg, expand=True, tooltip="Get help to enable developer options and OEM unlocking.")]),
7487
Divider(),
7588
Text(
7689
"Now connect your device to this computer via USB, then press 'Search device'."
@@ -89,6 +102,7 @@ def build(self):
89102
on_click=self.search_devices,
90103
icon=icons.PHONE_ANDROID,
91104
expand=True,
105+
tooltip="Search for a connected device."
92106
),
93107
self.continue_button,
94108
],
@@ -98,6 +112,18 @@ def build(self):
98112
)
99113
return self.view
100114

115+
def open_developer_options_dlg(self, e):
116+
"""Open the dialog for help to developer mode."""
117+
self.page.dialog = self.dlg_help_developer_options
118+
self.dlg_help_developer_options.open = True
119+
self.page.update()
120+
121+
122+
def close_developer_options_dlg(self, e):
123+
"""Close the dialog for help to developer mode."""
124+
self.dlg_help_developer_options.open = False
125+
self.page.update()
126+
101127
def search_devices(self, e):
102128
try:
103129
# read device properties
@@ -209,14 +235,25 @@ def enable_button_if_ready(self, e):
209235
else:
210236
self.confirm_button.disabled = True
211237

238+
class SuccessView(BaseView):
239+
def __init__(self, page: Page):
240+
super().__init__(image="success.png")
241+
242+
def build(self, ):
243+
self.right_view.controls = [
244+
get_title("Installation completed successfully!"),
245+
Row([ElevatedButton("Finish and close", expand=True, on_click=lambda _: self.page.window_close())])
246+
]
247+
return self.view
248+
212249

213250
class MainView(UserControl):
214-
def __init__(self):
251+
def __init__(self, page: Page):
215252
super().__init__()
216253
self.config = None
217254
# initialize the progress bar indicator
218255
self.progress_bar = ProgressBar(
219-
width=400, color="#00d886", bgcolor="#eeeeee", bar_height=16
256+
width=480, color="#00d886", bgcolor="#eeeeee", bar_height=16
220257
)
221258
self.progress_bar.value = 0
222259
# create the main columns
@@ -241,6 +278,7 @@ def __init__(self):
241278
welcome = WelcomeView(
242279
on_confirm=self.confirm,
243280
load_config=self.load_config,
281+
page=self.page
244282
)
245283
select_files = SelectFilesView(
246284
on_confirm=self.confirm,
@@ -252,6 +290,8 @@ def __init__(self):
252290
)
253291
# ordered to allow for pop
254292
self.default_views = [select_files, welcome]
293+
# create the final success view
294+
self.final_view = SuccessView(page)
255295
# keep track of the number of steps
256296
self.num_steps = len(self.default_views)
257297

@@ -272,7 +312,7 @@ def confirm(self, e):
272312
# if there are default views left, display them first
273313
if self.default_views:
274314
self.view.controls.append(self.default_views.pop())
275-
else:
315+
elif self.config.steps:
276316
self.view.controls.append(
277317
StepView(
278318
step=self.config.steps.pop(0),
@@ -283,6 +323,9 @@ def confirm(self, e):
283323
recovery_path=self.recovery_path,
284324
)
285325
)
326+
else:
327+
# display the final view
328+
self.view.controls.append(self.final_view)
286329
self.view.update()
287330

288331
def load_config(self, path: str):
@@ -388,8 +431,8 @@ def call_to_phone(self, e, command: str):
388431
def main(page: Page):
389432
# Configure the application base page
390433
page.title = "OpenAndroidInstaller"
391-
page.window_width = 960
392-
page.window_height = 640
434+
page.window_width = 1080
435+
page.window_height = 720
393436
page.window_top = 100
394437
page.window_left = 720
395438
page.scroll = "adaptive"
@@ -437,12 +480,13 @@ def close_banner(e):
437480
TextButton("I understand", on_click=close_banner),
438481
],
439482
)
440-
page.banner.open = True
483+
# TODO: disable the banner for now
484+
#page.banner.open = True
441485

442486
page.update()
443487

444488
# create application instance
445-
app = MainView()
489+
app = MainView(page)
446490

447491
# add application's root control to the page
448492
page.add(app)

0 commit comments

Comments
 (0)