-
Notifications
You must be signed in to change notification settings - Fork 1
/
OctoTouchController.b4a
745 lines (633 loc) · 26.8 KB
/
OctoTouchController.b4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
Build1=Default,sadLogic.OctoTouchController
Build2=FOSS,sadLogic.OctoTouchController.foss,FOSS
File1=bed.png
File10=dlgLogging.json
File11=dlgonoff.json
File12=dlgPower.json
File13=dlgprintersetup.json
File14=dlgSimpleApiOnOff.json
File15=dlgThemeSelect.bal
File16=dlgViewText.bal
File17=hotend.png
File18=hotend_header.png
File19=LICENSE.txt
File2=bed_header.png
File20=MainPage2.bal
File21=mainstatcard.bal
File22=mb_info.png
File23=mb_question.png
File24=mb_stop.png
File25=menucard2.bal
File26=menufiles.png
File27=menumovement.png
File28=menuprint.png
File29=no_thumbnail.jpg
File3=dlgAbout.bal
File30=pageFiles.bal
File31=pageMenu2.bal
File32=pageMovement.bal
File33=pagePrinting.bal
File34=splash.png
File35=splashklipper.png
File36=view_z_movement.bal
File37=viewAppUpdate.bal
File38=viewFilamentCtrl.bal
File39=viewfiles.bal
File4=dlgbedlevel.json
File40=viewMovementMM.bal
File41=viewMsgBox.bal
File42=viewMsgBox2.bal
File43=viewOctoSetup.bal
File44=viewPsuCtrl.bal
File45=viewPsuSetup.bal
File46=viewPsuSetupSonOff.bal
File47=viewRoundSlider.bal
File48=viewSlidingWindow.bal
File49=wizbedlevel.json
File5=dlgBLCRtouch.bal
File50=wizFilamentCtrl.bal
File51=wizManualBedLevel.bal
File52=wizManualMeshBedLevel.bal
File6=dlgbltouch.json
File7=dlgFilamentCtrl.json
File8=dlggcodebuilder.json
File9=dlggeneral.json
FileGroup1=MISC
FileGroup10=JSON_CONFIGS
FileGroup11=JSON_CONFIGS
FileGroup12=JSON_CONFIGS
FileGroup13=JSON_CONFIGS
FileGroup14=JSON_CONFIGS
FileGroup15=DIALOG_CUSTOM_VIEWS
FileGroup16=DIALOG_CUSTOM_VIEWS
FileGroup17=MISC
FileGroup18=Default Group
FileGroup19=Default Group
FileGroup2=Default Group
FileGroup20=B4XPages
FileGroup21=Sub Cards
FileGroup22=MISC
FileGroup23=MISC
FileGroup24=MISC
FileGroup25=Sub Cards
FileGroup26=MAIN_MENU
FileGroup27=MAIN_MENU
FileGroup28=MAIN_MENU
FileGroup29=MISC
FileGroup3=DIALOG_CUSTOM_VIEWS
FileGroup30=VIEWS_PAGES
FileGroup31=VIEWS_PAGES
FileGroup32=VIEWS_PAGES
FileGroup33=VIEWS_PAGES
FileGroup34=MISC
FileGroup35=MISC
FileGroup36=DIALOG_CUSTOM_VIEWS
FileGroup37=DIALOG_CUSTOM_VIEWS
FileGroup38=DIALOG_CUSTOM_VIEWS
FileGroup39=VIEWS
FileGroup4=JSON_CONFIGS
FileGroup40=DIALOG_CUSTOM_VIEWS
FileGroup41=DIALOG_CUSTOM_VIEWS
FileGroup42=DIALOG_CUSTOM_VIEWS
FileGroup43=DIALOG_CUSTOM_VIEWS
FileGroup44=DIALOG_CUSTOM_VIEWS
FileGroup45=DIALOG_CUSTOM_VIEWS
FileGroup46=DIALOG_CUSTOM_VIEWS
FileGroup47=DIALOG_CUSTOM_VIEWS
FileGroup48=VIEWS
FileGroup49=JSON_CONFIGS
FileGroup5=DIALOG_CUSTOM_VIEWS
FileGroup50=DIALOG_CUSTOM_VIEWS
FileGroup51=DIALOG_CUSTOM_VIEWS
FileGroup52=DIALOG_CUSTOM_VIEWS
FileGroup6=JSON_CONFIGS
FileGroup7=JSON_CONFIGS
FileGroup8=JSON_CONFIGS
FileGroup9=JSON_CONFIGS
Group=MAIN
Library1=accessibility
Library10=designerutils
Library11=fileprovider
Library12=javaobject
Library13=json
Library14=keyvaluestore
Library15=okhttp
Library16=okhttputils2
Library17=oslibrary
Library18=phone
Library19=reflection
Library2=audio
Library20=runtimepermissions
Library21=viewsex
Library22=websocket
Library23=xui
Library24=xui views
Library3=b4xcollections
Library4=b4xpages
Library5=b4xpreferencesdialog
Library6=bctoast
Library7=byteconverter
Library8=core
Library9=dateutils
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~~\n~'--- https://www.b4x.com/android/forum/threads/android-jar-targetsdkversion-minsdkversion.87610/~\n~'--- Non-ssl (non-https) communication is not permitted by default. It can be enabled in B4A v9+ by adding this line to the manifest editor:~\n~CreateResourceFromFile(Macro, Core.NetworkClearText)~\n~~\n~'--- Take over power functions~\n~AddPermission(android.permission.WAKE_LOCK)~\n~AddPermission(android.permission.WRITE_SETTINGS)~\n~~\n~AddPermission(android.permission.INTERNET)~\n~~\n~'--- app update crap~\n~AddManifestText(<uses-permission~\n~ android:name="android.permission.WRITE_EXTERNAL_STORAGE"~\n~ android:maxSdkVersion="18" />~\n~)~\n~~\n~AddApplicationText(~\n~ <provider~\n~ android:name="android.support.v4.content.FileProvider"~\n~ android:authorities="$PACKAGE$.provider"~\n~ android:exported="false"~\n~ android:grantUriPermissions="true">~\n~ <meta-data~\n~ android:name="android.support.FILE_PROVIDER_PATHS"~\n~ android:resource="@xml/provider_paths"/>~\n~ </provider>~\n~)~\n~CreateResource(xml, provider_paths,~\n~ <files-path name="name" path="shared" />~\n~)~\n~AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)~\n~~\n~#if NOT (FOSS)~\n~'************ Google Play Services Base ************ '--- Android 4.x SSL stuff~\n~'--- search for 'ProviderInstall'~\n~AddApplicationText(~\n~ <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"~\n~ android:theme="@android:style/Theme.Translucent.NoTitleBar"~\n~ android:exported="false"/>~\n~ <meta-data~\n~ android:name="com.google.android.gms.version"~\n~ android:value="@integer/google_play_services_version" />~\n~)~\n~'************ Google Play Services Base (end) ************ '--- Android 4.x SSL stuff~\n~#end if~\n~~\n~AddManifestText(<uses-permission~\n~ android:name="android.permission.WRITE_EXTERNAL_STORAGE"~\n~ android:maxSdkVersion="18" />~\n~)~\n~~\n~~\n~~\n~~\n~'===============================================================================~\n~~\n~''''https://www.b4x.com/android/forum/threads/android-jar-targetsdkversion-minsdkversion.87610/~\n~''''Non-ssl (non-https) communication is not permitted by default. It can be enabled in B4A v9+ by adding this line to the manifest editor:~\n~'''CreateResourceFromFile(Macro, Core.NetworkClearText)~\n~'''~\n~'''AddManifestText(~\n~'''~\n~''' <Activity android:launchMode="singleInstance" />~\n~''' <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="18"/>~\n~''' ~\n~''' <supports-screens android:largeScreens="true" ~\n~''' android:xlargeScreens="true"~\n~''' android:normalScreens="false" ~\n~''' android:smallScreens="false" ~\n~''' android:requiresSmallestWidthDp="800"~\n~''' android:anyDensity="true"/>~\n~'''~\n~''' ~\n~''' <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>~\n~''' <uses-permission android:name="android.permission.GET_ACCOUNTS" />~\n~''' ~\n~''')~\n~'''~\n~'''SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)~\n~'''~\n~'''SetApplicationAttribute(android:hardwareAccelerated, "true")~\n~'''SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")~\n~'''SetApplicationAttribute(android:icon, "@drawable/icon")~\n~'''SetApplicationAttribute(android:label, "$LABEL$")~\n~'''~\n~'''AddPermission(android.permission.REBOOT)~\n~'''AddPermission(android.permission.WAKE_LOCK)~\n~'''AddPermission(android.permission.ACCESS_NETWORK_STATE)~\n~'''~\n~'''#if not (KE)~\n~'''AddPermission(android.permission.MEDIA_UNMOUNTED)~\n~'''AddPermission(android.permission.MEDIA_MOUNTED)~\n~'''~\n~'''AddReceiverText(svrMediaHelper,~\n~'''<intent-filter>~\n~''' <action android:name="android.intent.action.MEDIA_MOUNTED" />~\n~''' <data android:scheme="file"/>~\n~'''</intent-filter>)~\n~'''~\n~'''AddReceiverText(svrMediaHelper,~\n~'''<intent-filter>~\n~''' <action android:name="android.intent.action.MEDIA_UNMOUNTED" />~\n~''' <data android:scheme="file"/>~\n~'''</intent-filter>)~\n~'''#end if~\n~'''~\n~'''#if not (KE)~\n~'''AddReceiverText(eu.dgconsulting.appupdating.newinst2,~\n~''' <intent-filter>~\n~''' <action android:name="android.intent.action.PACKAGE_REPLACED" />~\n~''' <data android:scheme="package" />~\n~''' </intent-filter>)~\n~''' #end if~\n~~\n~
Module1=|relative|src\miscClasses\AppUpdate
Module10=|relative|src\dialogs\dlgAbout
Module11=|relative|src\dialogs\dlgAndroidPowerOptions
Module12=|relative|src\dialogs\dlgAppUpdate
Module13=|relative|src\dialogs\dlgBedLevelManualWiz
Module14=|relative|src\dialogs\dlgBedLevelMeshWiz2
Module15=|relative|src\dialogs\dlgBedLevelSetup
Module16=|relative|src\dialogs\dlgBLTouchActions
Module17=|relative|src\dialogs\dlgBLTouchSetup
Module18=|relative|src\dialogs\dlgBrightness
Module19=|relative|src\dialogs\dlgFilamentCtrl
Module2=|relative|src\custom_controls\AutoTextSizeLabel
Module20=|relative|src\dialogs\dlgFilamentSetup
Module21=|relative|src\dialogs\dlgGCodeCustSetup
Module22=|relative|src\dialogs\dlgGeneralOptions
Module23=|relative|src\dialogs\dlgIpOnOffSetup
Module24=|relative|src\dialogs\dlgKlipperSysCmds
Module25=|relative|src\dialogs\dlgListbox
Module26=|relative|src\dialogs\dlgMsgBox
Module27=|relative|src\dialogs\dlgMsgBox2
Module28=|relative|src\dialogs\dlgNumericInput
Module29=|relative|src\dialogs\dlgOctoPsuCtrl
Module3=|relative|src\miscClasses\B4XEval
Module30=|relative|src\dialogs\dlgOctoPsuSetup
Module31=|relative|src\dialogs\dlgOctoSetup
Module32=|relative|src\dialogs\dlgOctoSysCmds
Module33=|relative|src\dialogs\dlgOnOffCtrl
Module34=|relative|src\dialogs\dlgThemeSelect
Module35=|relative|src\dialogs\dlgViewText
Module36=|relative|src\miscClasses\DSE_Layout
Module37=|relative|src\helperClasses\fileHelpers
Module38=|relative|src\generic\fnc
Module39=|relative|src\generic\gblConst
Module4=|relative|src\B4XPages\B4XMainPage
Module40=|relative|src\helperClasses\guiHelpers
Module41=|relative|src\miscClasses\guiMsgs
Module42=|relative|src\miscClasses\HeaterRoutines
Module43=|relative|src\miscClasses\HttpDownloadStr
Module44=|relative|src\octoPrint\HttpOctoRestAPI
Module45=|relative|src\miscClasses\InMemDB
Module46=|relative|src\octoPrint\JSONparsors\JsonParserFiles
Module47=|relative|src\octoPrint\JSONparsors\JsonParserMasterPrinterSettings
Module48=|relative|src\octoPrint\JSONparsors\JsonParsorConnectionStatus
Module49=|relative|src\octoPrint\JSONparsors\JsonParsorMain
Module5=|relative|src\miscClasses\CallSubUtils
Module50=|relative|src\octoPrint\JSONparsors\JsonParsorOctoVersion
Module51=|relative|src\octoPrint\JSONparsors\JsonParsorPlugins
Module52=|relative|src\custom_controls\lmB4XImageViewX
Module53=|relative|src\generic\logMe
Module54=|relative|src\main\MasterController
Module55=|relative|src\helperClasses\objHelpers
Module56=|relative|src\octoPrint\oc
Module57=|relative|src\octoPrint\OctoKlippyMisc
Module58=|relative|src\octoPrint\OctoSysCmds
Module59=|relative|src\octoPrint\OctoWebSocket
Module6=|relative|src\octoPrint\CheckOctoConnection
Module60=|relative|src\generic\OptionsCfgSeed
Module61=|relative|src\pageViews\pageFiles
Module62=|relative|src\pageViews\pageMenu
Module63=|relative|src\pageViews\pageMovement
Module64=|relative|src\pageViews\pagePrinting
Module65=|relative|src\helperClasses\powerHelpers
Module66=|relative|src\octoPrint\RequestApiKey
Module67=|relative|src\b4xCustomizedClasses\sadAS_FloatingPanel
Module68=|relative|src\b4xCustomizedClasses\sadB4XColorTemplate
Module69=|relative|src\b4xExtensionClasses\sadB4XDialogHelper
Module7=|relative|src\custom_controls\CircularProgressBar
Module70=|relative|src\b4xCustomizedClasses\sadB4XDrawerAdvanced
Module71=|relative|src\b4xExtensionClasses\sadB4XDrawerAdvancedHelper
Module72=|relative|src\b4xCustomizedClasses\sadB4XInputTemplate
Module73=|relative|src\b4xCustomizedClasses\sadClvSelections
Module74=|relative|src\b4xCustomizedClasses\sadPreferencesDialog
Module75=|relative|src\b4xExtensionClasses\sadPreferencesDialogHelper
Module76=|relative|src\custom_controls\sadRoundSlider
Module77=|relative|src\miscClasses\SoundsBeeps
Module78=|relative|src\miscClasses\Stack
Module79=|relative|src\main\startAtBoot
Module8=|relative|src\generic\clrTheme
Module80=|relative|src\main\Starter
Module81=|relative|src\helperClasses\strHelpers
Module82=|relative|src\miscClasses\SysInfo
Module83=|relative|src\octoPrint\WebSocketParse
Module84=|relative|src\miscClasses\WildCardFilesList
Module9=|relative|src\generic\config
NumberOfFiles=52
NumberOfLibraries=24
NumberOfModules=84
Version=12.5
@EndOfDesignText@
#Region Project Attributes
#ApplicationLabel: OctoTC
#VersionCode: 53
#VersionName: 2.0.2
#SignKeyFile: ..\keystore\release.keystore
#SignKeyPassword: !!OctoTC!!
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: false
#End Region
#if not (FOSS)
'--- support for websocket and older android versions
#AdditionalJar: com.google.android.gms:play-services-base
#End If
#region BUILD ACTIONS
'1 - Before the compiler cleans the objects folder (it happens after the code Is parsed).
'2 - Before R.java File Is generated.
'3 - Before the package Is signed (the APK File at this point Is: bin\temp.ap_).
'4 - Before the APK Is installed.
'5 - After the APK Is installed.
'--- these will be usefull when moonraker-klipper support is re-added in
#CustomBuildAction:1, %WINDIR%\system32\cmd.exe, /c copy "..\icons\octo\octo-icon.png" "..\build-icon.png" /y
#CustomBuildAction:1, %WINDIR%\system32\cmd.exe, /c copy "..\icons\octo\octo-icon.png" "res\drawable\icon.png" /y
#end region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: False
'#DebuggerForceFullDeployment: true
'#DebuggerForceStandardAssets: true
#BridgeLogger: True
'-----------------------------------
#End Region
'#AdditionalJar: com.android.support:support-compat
'open project objects folder: ide://run?File=%WINDIR%\explorer.exe&Args=%PROJECT%
'Ctrl + click to export as zip: ide://run?=&File=%B4X%\Zipper.jar&Args=Project.zip
Sub Process_Globals
Public ActionBarHomeClicked As Boolean
'--- was in starter serves
Public tmrTimerCallSub As CallSubUtils
Public kvs As KeyValueStore
Public db As InMemDB
Public Provider As FileProvider
Public isAppClosing As Boolean = False
'--- timers need to be in 'Process_Globals'
Private tmrMain As Timer
'Private tmrFilesCheckChange As Timer
Private tmrScreen As Timer
End Sub
Sub Globals
'Public DEBUG_TEST_INSTALL As Boolean = True ---> See gblConst
Private Const mModule As String = "Main"
Private ph As Phone
Private xui As XUI
'Private FirstRun As Boolean
End Sub
'===================================================================================
Sub Activity_Create(FirstTime As Boolean) 'ignore
If FirstTime Then
'FirstRun = FirstTime '--- am I using this?
Log("Activity_Create - FirstTime = True")
SetUserOrientPref
tmrTimerCallSub.Initialize
kvs.Initialize(xui.DefaultFolder, "kvs.db3")
InitApp
#if debug
tmrTimerCallSub.CallSubDelayedPlus(Me,"tmrSplash_Tick",1000) '--- just a splash screen
#else
tmrTimerCallSub.CallSubDelayedPlus(Me,"tmrSplash_Tick",3500) '--- just a splash screen
#End If
'FirstRun = False
Else
Log("Activity_Create - FirstTime = False")
End If
If tmrScreen.IsInitialized = False Then
tmrScreen.Initialize("tmrScreenPower",15000) '--- init, will be reset later
End If
If tmrMain.IsInitialized = False Then
tmrMain.Initialize("tmrMain",2100) '--- main loop
End If
SetupFullScrn
Dim pm As B4XPagesManager
pm.Initialize(Activity)
End Sub
'===================================================================================
#Region "SCREEN_STUFF"
Private Sub SetupFullScrn
'https://www.b4x.com/android/forum/threads/immersive-mode-hide-the-navigation-bar.90882/
Dim lv As LayoutValues
If ph.SdkVersion >= 28 Then
'--- cutout mode... ????
Dim ctxt As JavaObject
ctxt.InitializeContext
ctxt.RunMethodJO("getWindow", Null).RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode", 1)
End If
If ph.SdkVersion >= 19 Then
Activity_WindowFocusChanged(True)
lv = GetRealSize
Dim jo As JavaObject = Activity
jo.RunMethod("setBottom", Array(lv.Height))
jo.RunMethod("setRight", Array(lv.Width))
Activity.Height = lv.Height
Activity.Width = lv.Width
Else
'--- size *WITH* taskbar
lv = GetDeviceLayoutValues
End If
guiHelpers.gScreenSizeAprox = lv.ApproximateScreenSize
guiHelpers.gIsLandScape = Not (lv.Height > lv.Width)
guiHelpers.gWidth = lv.Width
guiHelpers.gHeight = lv.Height
Dim ac As Accessibility : guiHelpers.gFscale = ac.GetUserFontScale
'SetUserOrientPref
End Sub
Private Sub SetUserOrientPref
If File.Exists(xui.DefaultFolder,gblConst.GENERAL_OPTIONS_FILE) = False Then
OrientPrefAuto
Return
End If
Dim Data As Map = File.ReadMap(xui.DefaultFolder,gblConst.GENERAL_OPTIONS_FILE)
Dim pref As String = Data.GetDefault("ort","Auto").As(String).ToUpperCase
'--- lock orientation
Select Case True
Case pref.StartsWith("PO")
ph.SetScreenOrientation(7)
Case pref.StartsWith("LA")
ph.SetScreenOrientation(6)
Case Else
OrientPrefAuto
End Select
End Sub
Private Sub OrientPrefAuto
If Activity.width < Activity.Height Then
ph.SetScreenOrientation(7)
Else
ph.SetScreenOrientation(6)
End If
End Sub
Private Sub GetRealSize() As LayoutValues
Dim lv As LayoutValues
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim WindowManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window"))
Dim display As JavaObject = WindowManager.RunMethod("getDefaultDisplay", Null)
Dim point As JavaObject
point.InitializeNewInstance("android.graphics.Point", Null)
display.RunMethod("getRealSize", Array(point))
lv.Width = point.GetField("x")
lv.Height = point.GetField("y")
lv.Scale = 100dip / 100
Return lv
End Sub
#end region
#region "TIMERS"
Private Sub tmrMain_Tick
'--- master loop timer
CallSub(B4XPages.MainPage.oMasterController,"tmrMain_Tick")
End Sub
'Private Sub tmrFilesCheckChange_Tick
' '--- when files page is in focus, check files
' 'CallSub(B4XPages.MainPage.oMasterController,"tmrFilesCheckChange_Tick")
'End Sub
Private Sub tmrSplash_Tick
CallSubDelayed(B4XPages.MainPage,"HideSplash_StartUp")
End Sub
Public Sub tmrScreenPower_Tick
Set_ScreenTmr
Dim InSub As String = "tmrScreenPower_Tick"
If config.logPOWER_EVENTS Or config.logTIMER_EVENTS Then
logMe.LogIt2("tmrScreenPower_Tick fired: " & tmrScreen.Interval,mModule,InSub)
End If
If oc.isPrinting Then
If config.logPOWER_EVENTS Then
logMe.LogIt2("We are printing",mModule,InSub)
End If
Set_ScreenTmr
Return
End If
tmrScreen.Enabled = False
fnc.BlankScreen
End Sub
'--- timer control subs --- --- timer control subs ---
'--- timer control subs --- --- timer control subs ---
Public Sub Set_ScreenTmr()
If config.logTIMER_EVENTS Then logMe.LogIt("Set_ScreenTmr",mModule)
Dim inSub As String = "Set_ScreenTmr"
tmrScreen.Enabled = False
If config.AndroidTakeOverSleepFLAG = False Then
If config.logPOWER_EVENTS Then logMe.LogIt("Power control is off",mModule)
Return
End If
'--- any screen time flags set?
If (config.AndroidNotPrintingScrnOffFLAG Or config.AndroidPrintingScrnOffFLAG) Then
If oc.isPrinting And config.AndroidPrintingScrnOffFLAG Then
If config.logPOWER_EVENTS Then
logMe.LogIt2("AndroidPrintingScrnOffFLAG = True: Min: " & config.AndroidPrintingMinTill,mModule,inSub)
End If
tmrScreen.Interval = config.AndroidPrintingMinTill * 1000 * 60 '--- we are printing
Else
If config.logPOWER_EVENTS Then
logMe.LogIt2("AndroidNotPrintingScrnOffFLAG = True: Min: " & config.AndroidNotPrintingMinTill,mModule,inSub)
End If
tmrScreen.Interval = config.AndroidNotPrintingMinTill * 1000 * 60
End If
tmrScreen.Enabled = True
End If
Dim_ActionBar(gblConst.ACTIONBAR_OFF) '--- turn off if it is on
End Sub
Public Sub TurnOnOff_ScreenTmr(EnableDisable As Boolean)
If config.logTIMER_EVENTS Then logMe.LogIt("screen tmr on: " & EnableDisable,mModule)
tmrScreen.Enabled = EnableDisable
End Sub
Public Sub TurnOnOff_MainTmr(EnableDisable As Boolean)
If config.logTIMER_EVENTS Then logMe.LogIt("main tmr on: " & EnableDisable,mModule)
tmrMain.Enabled = EnableDisable
End Sub
'Public Sub TurnOnOff_FilesCheckChangeTmr(EnableDisable As Boolean)
' If config.logFILE_EVENTS Or config.logTIMER_EVENTS Then logMe.LogIt("file tmr on: " & EnableDisable,mModule)
' tmrFilesCheckChange.Enabled = EnableDisable
'End Sub
#end region
'===================================================================================
'==================================================================================
Sub Activity_WindowFocusChanged(HasFocus As Boolean)
If ph.SdkVersion < gblConst.API_ANDROID_4_4 Then Return
'--- restore imersive mode
If HasFocus Then
Try
Dim jo As JavaObject = Activity
Sleep(300)
jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
Catch
Log("error")
'Log(LastException) 'This can cause another error
End Try 'ignore
End If
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
If config.IsInit Then
'--- config power options if flag is set
fnc.ProcessPowerFlags
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
Log("UserClosed:" & UserClosed)
If UserClosed Then ExitApplication
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Region
'==================================================================================
'==================================================================================
'--- 1 = off, 0 = on
Public Sub Dim_ActionBar(On_off As Int)
'--- Android 4 thing, you can dim the action bar
'--- Android 4.4 has Imersive mode so we skip it
Try
If ph.SdkVersion >= gblConst.API_ANDROID_4_0 And ph.SdkVersion < gblConst.API_ANDROID_4_4 Then
Dim r As Reflector
r.Target = Activity
r.RunMethod2("setSystemUiVisibility", On_off, "java.lang.int") '1 = SYSTEM_UI_FLAG_LOW_PROFILE
Else
If On_off = gblConst.ACTIONBAR_OFF Then
Activity_WindowFocusChanged(True)
End If
End If
Catch
'Log("DimBottomButtons - " & LastException)
End Try 'ignore
End Sub
Public Sub Dim_ActionBar_Off
Dim_ActionBar(gblConst.ACTIONBAR_OFF)
End Sub
'Public Sub Restart_App
' ' TODO, errors out, needs work
' guiHelpers.Show_toast("Re-Starting Application...",2000)
' Activity.Finish
' Sleep(2200)
' Dim r, r2 As Reflector
' r.Target = r.GetActivity
' r.Target = r.RunMethod("getApplicationContext")
' r2.Target = r.RunMethod("getPackageManager")
' Dim I As Intent = r2.RunMethod2("getLaunchIntentForPackage", r.RunMethod("getPackageName"), "java.lang.String" )
' r.Target = I
' r.RunMethod2("addFlags", 67108864, "java.lang.int")
' StartActivity(I)
'End Sub
#region "IN APP UPDATE - NON MARKET"
'https://www.b4x.com/android/forum/threads/version-safe-apk-installation.87667/
Public Sub CheckInstallationRequirements As ResumableSub
If File.ExternalWritable = False Then
MsgboxAsync("Storage card not available. Make sure that your device is not connected in USB storage mode.", "")
Return False
Else If ph.SdkVersion >= 26 And CanRequestPackageInstalls = False Then
MsgboxAsync("Please allow me to install applications.", "")
Wait For Msgbox_Result(Result As Int)
Dim in As Intent
in.Initialize("android.settings.MANAGE_UNKNOWN_APP_SOURCES", "package:" & Application.PackageName)
StartActivity(in)
Wait For Activity_Resume '<-- wait for Activity_Resume
Return CanRequestPackageInstalls
Else If CheckNonMarketAppsEnabled = False Then
MsgboxAsync("Please enable installation of non-market applications." & CRLF & "Under Settings - Security - Unknown sources" _
& CRLF & "Or Settings - Applications - Unknown sources", "")
Return False
Else
Return True
End If
End Sub
Private Sub CanRequestPackageInstalls As Boolean
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Return PackageManager.RunMethod("canRequestPackageInstalls", Null)
End Sub
Private Sub CheckNonMarketAppsEnabled As Boolean
If ph.SdkVersion >= 26 Then Return True
If ph.SdkVersion < 17 Or ph.SdkVersion >= 21 Then
Return ph.GetSettings("install_non_market_apps") = "1"
Else
Dim context As JavaObject
context.InitializeContext
Dim resolver As JavaObject = context.RunMethod("getContentResolver", Null)
Dim global As JavaObject
global.InitializeStatic("android.provider.Settings.Global")
Return global.RunMethod("getString", Array(resolver, "install_non_market_apps")) = "1"
End If
End Sub
Private Sub SendInstallIntent(path As String) 'ignore
Dim i As Intent, fullpath As String
If ph.SdkVersion >= 24 Then
fullpath = Provider.GetFileUri(fileHelpers.GetFilenameFromPath(gblConst.APK_NAME))
i.Initialize("android.intent.action.INSTALL_PACKAGE", fullpath)
i.Flags = Bit.Or(i.Flags, 1) '--- FLAG_GRANT_READ_URI_PERMISSION
Else
fullpath = "file://" & File.Combine(path, fileHelpers.GetFilenameFromPath(gblConst.APK_NAME))
i.Initialize(i.ACTION_VIEW, fullpath)
i.SetType("application/vnd.android.package-archive")
End If
logMe.LogIt("App update fullpath: " & fullpath, mModule)
StartActivity(i)
End Sub
Public Sub Start_ApkInstall(args() As String)
Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
If Result Then
SendInstallIntent(args(0))
End If
End Sub
#end region
'--- from starter serves
#region STARTUP_INIT
Private Sub InitApp
Provider.Initialize
If kvs.ContainsKey("install_date") = False Then
kvs.Put("install_date",DateTime.Now)
kvs.Put("version_code",Application.VersionCode)
End If
db.Initialize
Dim oo1 As dlgAppUpdate : oo1.Initialize(Null)
oo1.CleanUpApkDownload
If Application.VersionCode <> kvs.Get("version_code").As(Int) Then
Dim oo As AppUpdate : oo.Initialize : oo.RunPrgUpdate
End If
'File.WriteString(xui.DefaultFolder,"autostart.bin","boot")
'fileHelpers.SafeKill("autostart.bin")
End Sub
Public Sub Clean_OldLogs
logMe.DeleteOldFiles("*.log")
'---check every X hours for old logs / crash files
Dim hrs As Int = 12
tmrTimerCallSub.CallSubDelayedPlus(Me,"Clean_OldLogs",60000 * 60 * hrs)
End Sub
Public Sub Clean_OldCrash
logMe.DeleteOldFiles("*.crash")
'---check every X hours for old logs / crash files
Dim hrs As Int = 12
tmrTimerCallSub.CallSubDelayedPlus(Me,"Clean_OldCrash",60000 * 60 * hrs)
End Sub
Public Sub InitLog_Cleanup
'--- in about 15 minutes check for old logs, crash files (3 days old) and delete them
tmrTimerCallSub.CallSubDelayedPlus(Me,"Clean_OldLogs",60000 * 13)
tmrTimerCallSub.CallSubDelayedPlus(Me,"Clean_OldCrash",60000 * 17)
End Sub
#end region
Public Sub SetObj_Null(obj As Object)
obj = Null
End Sub
Public Sub Show_Unhandled_Error (Error As Exception, StackTrace As String) As Boolean
MsgboxAsync(StackTrace, Error)
Return False
End Sub