@blotch/angular-lynx-native 22.3.0 → 22.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -15
- package/dist/android/project.d.ts +90 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +369 -5
- package/dist/eject.d.ts +15 -1
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +13 -2
- package/dist/features.d.ts +70 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +115 -0
- package/dist/generate.d.ts +17 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +12 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +8 -2
- package/dist/ios/frameworks.d.ts +6 -5
- package/dist/ios/frameworks.d.ts.map +1 -1
- package/dist/ios/frameworks.js +46 -15
- package/dist/ios/project.d.ts +173 -11
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +767 -33
- package/dist/options.d.ts +143 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +127 -0
- package/dist/permissions.d.ts +18 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +63 -3
- package/package.json +1 -1
- package/templates/android/README.md +37 -2
- package/templates/android/angular-lynx.properties +2 -0
- package/templates/android/app/build.gradle.kts +70 -1
- package/templates/android/app/src/main/AndroidManifest.xml +24 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +376 -6
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +6 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
- package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
- package/templates/android/app/src/main/res/values/share_target.xml +11 -0
- package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
- package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
- package/templates/android/build.gradle.kts +1 -1
- package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
- package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
- package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
- package/templates/ios/App/AngularLynxVideo.h +37 -0
- package/templates/ios/App/AngularLynxVideo.m +435 -0
- package/templates/ios/App/AngularLynxWebGL.h +69 -7
- package/templates/ios/App/AngularLynxWebGL.m +538 -29
- package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
- package/templates/ios/App/AppDelegate.swift +34 -2
- package/templates/ios/App/AppleSignInButton.swift +106 -0
- package/templates/ios/App/AppleSignInModule.swift +222 -0
- package/templates/ios/App/BarcodeScannerModule.swift +284 -0
- package/templates/ios/App/BiometricsModule.swift +256 -0
- package/templates/ios/App/BluetoothModule.swift +1086 -0
- package/templates/ios/App/CalendarModule.swift +158 -0
- package/templates/ios/App/FilePickerModule.swift +240 -0
- package/templates/ios/App/HapticsModule.swift +90 -0
- package/templates/ios/App/Info.plist +2 -0
- package/templates/ios/App/LynxViewController.swift +210 -6
- package/templates/ios/App/MotionModule.swift +430 -0
- package/templates/ios/App/NfcModule.swift +346 -0
- package/templates/ios/App/PhotoLibraryModule.swift +169 -0
- package/templates/ios/App/ShareTargetModule.swift +150 -0
- package/templates/ios/App/ShellModule.swift +17 -0
- package/templates/ios/App/StoreReviewModule.swift +61 -0
- package/templates/ios/App/TrackingModule.swift +121 -0
- package/templates/ios/App/WifiModule.swift +237 -0
- package/templates/ios/App/XElementRegistry.swift +13 -3
- package/templates/ios/ShareExtension/Info.plist +42 -0
- package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
|
@@ -15,7 +15,7 @@ import android.provider.Settings
|
|
|
15
15
|
import android.util.Log
|
|
16
16
|
import android.view.accessibility.AccessibilityManager
|
|
17
17
|
import android.widget.FrameLayout
|
|
18
|
-
import androidx.activity.
|
|
18
|
+
import androidx.activity.BackEventCompat
|
|
19
19
|
import androidx.activity.OnBackPressedCallback
|
|
20
20
|
import androidx.activity.result.PickVisualMediaRequest
|
|
21
21
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
@@ -26,7 +26,10 @@ import androidx.core.os.ConfigurationCompat
|
|
|
26
26
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
|
27
27
|
import androidx.core.view.ViewCompat
|
|
28
28
|
import androidx.core.view.WindowInsetsCompat
|
|
29
|
+
import androidx.fragment.app.FragmentActivity
|
|
30
|
+
import com.lynx.jsbridge.LynxModule
|
|
29
31
|
import com.lynx.react.bridge.JavaOnlyArray
|
|
32
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
30
33
|
import com.lynx.tasm.LynxBooleanOption
|
|
31
34
|
import com.lynx.tasm.LynxError
|
|
32
35
|
import com.lynx.tasm.LynxView
|
|
@@ -38,8 +41,12 @@ import com.lynx.xelement.XElementBehaviors
|
|
|
38
41
|
/**
|
|
39
42
|
* The whole app: one full-screen LynxView running the Angular app. Angular
|
|
40
43
|
* Router navigates inside it, so there is no native navigation stack.
|
|
44
|
+
*
|
|
45
|
+
* A FragmentActivity, which is a ComponentActivity, because AndroidX's
|
|
46
|
+
* BiometricPrompt (BiometricsModule) shows as a fragment over one. AppCompat,
|
|
47
|
+
* which XElement needs, brings the fragment library to every app anyway.
|
|
41
48
|
*/
|
|
42
|
-
class MainActivity :
|
|
49
|
+
class MainActivity : FragmentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
43
50
|
private lateinit var lynxView: LynxView
|
|
44
51
|
|
|
45
52
|
// Whether the page draws under the system bars and the cutout:
|
|
@@ -47,11 +54,41 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
47
54
|
// resource.
|
|
48
55
|
private val edgeToEdge by lazy { resources.getBoolean(R.bool.edge_to_edge) }
|
|
49
56
|
|
|
57
|
+
// Whether the app's text follows the system's font size, and the largest
|
|
58
|
+
// scale it takes (0 for no cap): angular.json's textScaling, which
|
|
59
|
+
// app/build.gradle.kts writes as resources.
|
|
60
|
+
private val textScaling by lazy { resources.getBoolean(R.bool.text_scaling) }
|
|
61
|
+
private val maxTextScale by lazy {
|
|
62
|
+
resources.getString(R.string.max_text_scale).toFloatOrNull() ?: 0f
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The font scale the LynxView was built with, which Lynx gives each engine
|
|
66
|
+
// it sets up (see onLoadSuccess below).
|
|
67
|
+
private var builtFontScale = 1f
|
|
68
|
+
|
|
50
69
|
// The safe-area insets, and whether the screen has a cutout, as the
|
|
51
70
|
// window last reported them. Sent in the global props.
|
|
52
71
|
private var safeArea = Insets.NONE
|
|
53
72
|
private var hasCutout = false
|
|
54
73
|
|
|
74
|
+
// Where the app is, for LynxAppState, sent in the global props and again
|
|
75
|
+
// as the activity's lifecycle moves: "active" from onResume, "inactive"
|
|
76
|
+
// from onPause and onStart, and "background" from onStop. It starts
|
|
77
|
+
// "inactive": the first props go out from onCreate, on the way onto the
|
|
78
|
+
// screen. From Android 10, both apps in split screen stay resumed, so
|
|
79
|
+
// onPause doesn't run when the other one takes the focus: a resumed
|
|
80
|
+
// activity is "inactive" too while it isn't the top resumed one
|
|
81
|
+
// (onTopResumedActivityChanged, which older Androids never call).
|
|
82
|
+
private var appState = "inactive"
|
|
83
|
+
private var resumed = false
|
|
84
|
+
|
|
85
|
+
// Whether this is the top resumed activity. Android 10 and later call
|
|
86
|
+
// onTopResumedActivityChanged(true) after onResume once it is, but never
|
|
87
|
+
// say false first, so it starts false there: an activity started without
|
|
88
|
+
// the focus in split screen stays "inactive". Older Androids never call
|
|
89
|
+
// it, so a resumed activity is the one with the focus.
|
|
90
|
+
private var topResumed = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
|
|
91
|
+
|
|
55
92
|
// Sends the accessibility settings again when the user changes one while
|
|
56
93
|
// the app is open: Remove animations (the animator duration scale), the
|
|
57
94
|
// contrast level (Android 14) and high contrast text (Android 16). The
|
|
@@ -71,12 +108,52 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
71
108
|
|
|
72
109
|
// Disabled until the Angular app enables it (see ShellModule), so by
|
|
73
110
|
// default back leaves the app like any other root screen.
|
|
111
|
+
//
|
|
112
|
+
// While it's enabled, Android's predictive back gesture reaches the app
|
|
113
|
+
// as it goes, not only once it's done: a stack in the app moves its top
|
|
114
|
+
// page with the finger, as Android's own screens do, and brings it back
|
|
115
|
+
// if the gesture is canceled. Android sends these only for the gesture,
|
|
116
|
+
// on Android 14 and later; a press of the 3-button bar's back, or of a
|
|
117
|
+
// key, calls handleOnBackPressed() alone.
|
|
74
118
|
private val backHandler = object : OnBackPressedCallback(false) {
|
|
119
|
+
override fun handleOnBackStarted(backEvent: BackEventCompat) {
|
|
120
|
+
sendBackGesture("started", backEvent)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
override fun handleOnBackProgressed(backEvent: BackEventCompat) {
|
|
124
|
+
sendBackGesture("progressed", backEvent)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override fun handleOnBackCancelled() {
|
|
128
|
+
sendBackGesture("canceled", null)
|
|
129
|
+
}
|
|
130
|
+
|
|
75
131
|
override fun handleOnBackPressed() {
|
|
76
132
|
lynxView.sendGlobalEvent(ShellModule.BACK_EVENT, JavaOnlyArray())
|
|
77
133
|
}
|
|
78
134
|
}
|
|
79
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Sends a step of the back gesture as an `angularLynxBackGesture` global
|
|
138
|
+
* event: its phase, how far it's gone (0 to 1, eased by Android as its
|
|
139
|
+
* own screens use it) and the edge it came from.
|
|
140
|
+
*/
|
|
141
|
+
private fun sendBackGesture(phase: String, backEvent: BackEventCompat?) {
|
|
142
|
+
val event = JavaOnlyMap()
|
|
143
|
+
event.putString("phase", phase)
|
|
144
|
+
if (backEvent != null) {
|
|
145
|
+
event.putDouble("progress", backEvent.progress.toDouble())
|
|
146
|
+
event.putString(
|
|
147
|
+
"edge",
|
|
148
|
+
if (backEvent.swipeEdge == BackEventCompat.EDGE_RIGHT) "right" else "left",
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
lynxView.sendGlobalEvent(
|
|
152
|
+
ShellModule.BACK_GESTURE_EVENT,
|
|
153
|
+
JavaOnlyArray().apply { pushMap(event) },
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
80
157
|
// The open sign-in (see WebAuthModule): the scheme its page returns to,
|
|
81
158
|
// who to tell, and whether the app has gone behind the Custom Tab yet.
|
|
82
159
|
private class WebAuthSession(val scheme: String, val done: (WebAuthModule.Result) -> Unit) {
|
|
@@ -108,6 +185,83 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
108
185
|
}
|
|
109
186
|
}
|
|
110
187
|
|
|
188
|
+
// Android's permission prompt, which the modules that need a runtime
|
|
189
|
+
// permission show through PermissionHost (PermissionRequests.kt), and who
|
|
190
|
+
// to tell what the person chose. Registered as the activity is created,
|
|
191
|
+
// as the Photo Picker's launcher is, and for the same reason.
|
|
192
|
+
private var permissionsAnswered: ((Map<String, Boolean>) -> Unit)? = null
|
|
193
|
+
private val permissionPrompt =
|
|
194
|
+
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { results ->
|
|
195
|
+
val done = permissionsAnswered ?: return@registerForActivityResult
|
|
196
|
+
permissionsAnswered = null
|
|
197
|
+
done(results)
|
|
198
|
+
}
|
|
199
|
+
private val permissionHost = object : PermissionHost {
|
|
200
|
+
override fun requestPermissions(names: Array<String>, done: (Map<String, Boolean>) -> Unit): Boolean {
|
|
201
|
+
if (permissionsAnswered != null) return false
|
|
202
|
+
permissionsAnswered = done
|
|
203
|
+
permissionPrompt.launch(names)
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The document picker and save screen behind LynxFilePicker (see
|
|
209
|
+
// FilePickerModule), and who to tell what came back. Registered as the
|
|
210
|
+
// activity is created, as the Photo Picker is above. Only an app with
|
|
211
|
+
// angular.json's filePicker keeps these lines (@blotch/angular-lynx-native's
|
|
212
|
+
// android/project.ts).
|
|
213
|
+
// angular-lynx:file-picker
|
|
214
|
+
private var documentDone: ((Int, Intent?) -> Unit)? = null
|
|
215
|
+
private val documentLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
216
|
+
val done = documentDone ?: return@registerForActivityResult
|
|
217
|
+
documentDone = null
|
|
218
|
+
done(result.resultCode, result.data)
|
|
219
|
+
}
|
|
220
|
+
private val filePickerHost = object : FilePickerModule.Host {
|
|
221
|
+
override fun startDocumentActivity(intent: Intent, done: (Int, Intent?) -> Unit): Boolean {
|
|
222
|
+
if (documentDone != null) return false
|
|
223
|
+
documentDone = done
|
|
224
|
+
try {
|
|
225
|
+
documentLauncher.launch(intent)
|
|
226
|
+
} catch (error: ActivityNotFoundException) {
|
|
227
|
+
documentDone = null
|
|
228
|
+
throw error
|
|
229
|
+
}
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// /angular-lynx:file-picker
|
|
234
|
+
|
|
235
|
+
// angular-lynx:calendar
|
|
236
|
+
// The calendar app's editor (see CalendarModule), and who to tell how it
|
|
237
|
+
// closed. Registered as the activity is created, as the image picker's
|
|
238
|
+
// launcher is. Only an app whose angular.json sets calendar keeps these
|
|
239
|
+
// lines and the module (@blotch/angular-lynx-native's android/project.ts).
|
|
240
|
+
private var calendarEditorClosed: ((Int) -> Unit)? = null
|
|
241
|
+
private val calendarEditor = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
242
|
+
val done = calendarEditorClosed ?: return@registerForActivityResult
|
|
243
|
+
calendarEditorClosed = null
|
|
244
|
+
done(result.resultCode)
|
|
245
|
+
}
|
|
246
|
+
private val calendarHost = object : CalendarModule.Host {
|
|
247
|
+
override fun openCalendarEditor(intent: Intent, done: (Int) -> Unit): Boolean {
|
|
248
|
+
if (calendarEditorClosed != null) return false
|
|
249
|
+
// Throws ActivityNotFoundException before anything is kept, so a
|
|
250
|
+
// phone without a calendar app can try again.
|
|
251
|
+
calendarEditor.launch(intent)
|
|
252
|
+
calendarEditorClosed = done
|
|
253
|
+
return true
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// /angular-lynx:calendar
|
|
257
|
+
|
|
258
|
+
// angular-lynx:share-target
|
|
259
|
+
// Tells the runtime's LynxShareTarget a share is waiting (see onCreate).
|
|
260
|
+
private val shareArrived: () -> Unit = {
|
|
261
|
+
lynxView.sendGlobalEvent(ShareTargetModule.EVENT, JavaOnlyArray())
|
|
262
|
+
}
|
|
263
|
+
// /angular-lynx:share-target
|
|
264
|
+
|
|
111
265
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
112
266
|
// The splash screen (themes.xml's Theme.AngularLynxShell.Starting),
|
|
113
267
|
// before anything else: it switches the activity to the app's own
|
|
@@ -142,7 +296,18 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
142
296
|
intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY == 0
|
|
143
297
|
) {
|
|
144
298
|
ShortcutsModule.run(intent)
|
|
299
|
+
// angular-lynx:share-target
|
|
300
|
+
// A share that started the app, from another app's share sheet,
|
|
301
|
+
// waits for the runtime's LynxShareTarget to take it.
|
|
302
|
+
ShareTargetModule.receive(this, intent)
|
|
303
|
+
// /angular-lynx:share-target
|
|
145
304
|
}
|
|
305
|
+
// angular-lynx:share-target
|
|
306
|
+
// Reading a share's files takes a moment, and Android may recreate
|
|
307
|
+
// the activity meanwhile, so the event goes through whichever
|
|
308
|
+
// activity is current once they're read (ShareTargetModule.arrived).
|
|
309
|
+
ShareTargetModule.arrived = shareArrived
|
|
310
|
+
// /angular-lynx:share-target
|
|
146
311
|
// A link that started the app, which the router starts at. Unlike a
|
|
147
312
|
// shortcut it's read again when Android recreates the activity: the
|
|
148
313
|
// app starts again then, and a link tapped after Android ended the
|
|
@@ -158,6 +323,7 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
158
323
|
// The bundle in the app's assets, or in the debug build `ng serve
|
|
159
324
|
// --platform android` runs, the dev server's (DevServer.kt).
|
|
160
325
|
val bundleUrl = DevServer.bundleUrl(this) ?: BundleAssets.MAIN_BUNDLE
|
|
326
|
+
builtFontScale = textScale(resources.configuration)
|
|
161
327
|
lynxView = LynxViewBuilder().apply {
|
|
162
328
|
// Lynx's engine thread, which runs the main thread's JavaScript
|
|
163
329
|
// (the whole Angular app), layout and Lynx's animator, gets a
|
|
@@ -171,6 +337,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
171
337
|
// on every <list>, which this strategy requires. The iOS shell
|
|
172
338
|
// does the same.
|
|
173
339
|
setThreadStrategyForRendering(ThreadStrategyForRendering.MOST_ON_TASM)
|
|
340
|
+
// The user's font size (see textScale()). The build tells Lynx to
|
|
341
|
+
// scale only `sp` lengths by it, which the page's root font size
|
|
342
|
+
// is written in, so every rem grows with it and a px size doesn't.
|
|
343
|
+
setFontScale(builtFontScale)
|
|
174
344
|
setTemplateProvider(AssetTemplateProvider(this@MainActivity))
|
|
175
345
|
setTemplateResourceFetcher(AssetTemplateResourceFetcher(this@MainActivity))
|
|
176
346
|
setMediaResourceFetcher(AssetMediaResourceFetcher())
|
|
@@ -182,23 +352,126 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
182
352
|
registerModule(SecureStorageModule.NAME, SecureStorageModule::class.java, null)
|
|
183
353
|
// LynxClipboard's text (ClipboardModule.kt).
|
|
184
354
|
registerModule(ClipboardModule.NAME, ClipboardModule::class.java, null)
|
|
355
|
+
// LynxHaptics' taps (HapticsModule.kt), which play on this
|
|
356
|
+
// activity's window.
|
|
357
|
+
registerModule(HapticsModule.NAME, HapticsModule::class.java, this@MainActivity)
|
|
185
358
|
// Links out of the app (LinkingModule.kt), which it opens from this
|
|
186
359
|
// activity.
|
|
187
360
|
registerModule(LinkingModule.NAME, LinkingModule::class.java, this@MainActivity)
|
|
188
361
|
// The photo picker behind LynxImagePicker (ImagePickerModule.kt), which
|
|
189
362
|
// this activity launches.
|
|
190
363
|
registerModule(ImagePickerModule.NAME, ImagePickerModule::class.java, imagePickerHost)
|
|
364
|
+
// The document picker behind LynxFilePicker (FilePickerModule.kt),
|
|
365
|
+
// which this activity launches. Only an app with filePicker keeps
|
|
366
|
+
// these lines and the module.
|
|
367
|
+
// angular-lynx:file-picker
|
|
368
|
+
registerModule(FilePickerModule.NAME, FilePickerModule::class.java, filePickerHost)
|
|
369
|
+
// /angular-lynx:file-picker
|
|
191
370
|
// The share sheet behind LynxShare (ShareModule.kt), which it opens
|
|
192
371
|
// from this activity.
|
|
193
372
|
registerModule(ShareModule.NAME, ShareModule::class.java, this@MainActivity)
|
|
373
|
+
// Biometrics behind LynxBiometrics and LynxSecureStorage's
|
|
374
|
+
// requireBiometrics (BiometricsModule.kt), whose prompt shows over
|
|
375
|
+
// this activity. Only an app with permissions.biometrics keeps
|
|
376
|
+
// these lines and the module (@blotch/angular-lynx-native's
|
|
377
|
+
// android/project.ts).
|
|
378
|
+
// angular-lynx:biometrics
|
|
379
|
+
registerModule(BiometricsModule.NAME, BiometricsModule::class.java, this@MainActivity)
|
|
380
|
+
// /angular-lynx:biometrics
|
|
381
|
+
// Saving to the photo library behind LynxPhotoLibrary
|
|
382
|
+
// (PhotoLibraryModule.kt). Only an app with permissions.savePhotos
|
|
383
|
+
// keeps these lines and the module (@blotch/angular-lynx-native's
|
|
384
|
+
// android/project.ts).
|
|
385
|
+
// angular-lynx:photo-library
|
|
386
|
+
registerModule(PhotoLibraryModule.NAME, PhotoLibraryModule::class.java, null)
|
|
387
|
+
// /angular-lynx:photo-library
|
|
388
|
+
// The code scanner behind LynxBarcodeScanner
|
|
389
|
+
// (BarcodeScannerModule.kt), which opens over this activity. Only
|
|
390
|
+
// an app whose angular.json sets permissions.camera has it: the
|
|
391
|
+
// generator deletes the file, and the Play services library it
|
|
392
|
+
// needs, from every other app (as the iOS shell leaves its module
|
|
393
|
+
// out, since App Store Connect flags an app whose code uses the
|
|
394
|
+
// camera without saying why). So it's looked up by name, which
|
|
395
|
+
// compiles either way, and nothing else may name the class.
|
|
396
|
+
// Lynx's own R8 rules keep every LynxModule's name, so a release
|
|
397
|
+
// build finds it too.
|
|
398
|
+
optionalModule(BARCODE_SCANNER_MODULE_CLASS)?.let {
|
|
399
|
+
registerModule(BARCODE_SCANNER_MODULE, it, this@MainActivity)
|
|
400
|
+
}
|
|
401
|
+
// Google Play's rating prompt behind LynxStoreReview
|
|
402
|
+
// (StoreReviewModule.kt), which it shows over this activity. An
|
|
403
|
+
// app whose angular.json doesn't set storeReview is built without
|
|
404
|
+
// the module, these lines and Play's review library
|
|
405
|
+
// (@blotch/angular-lynx-native's android/project.ts).
|
|
406
|
+
// angular-lynx:store-review
|
|
407
|
+
registerModule(StoreReviewModule.NAME, StoreReviewModule::class.java, this@MainActivity)
|
|
408
|
+
// /angular-lynx:store-review
|
|
409
|
+
// angular-lynx:calendar
|
|
410
|
+
// The calendar app's editor behind LynxCalendar (CalendarModule.kt),
|
|
411
|
+
// which this activity opens. An app whose angular.json doesn't set
|
|
412
|
+
// calendar is built without the module and these lines.
|
|
413
|
+
registerModule(CalendarModule.NAME, CalendarModule::class.java, calendarHost)
|
|
414
|
+
// /angular-lynx:calendar
|
|
415
|
+
// angular-lynx:tracking
|
|
416
|
+
// The advertising ID's opt-out behind LynxTracking
|
|
417
|
+
// (TrackingModule.kt). An app whose angular.json doesn't set
|
|
418
|
+
// permissions.tracking is built without the module, these lines
|
|
419
|
+
// and Play's advertising ID library.
|
|
420
|
+
registerModule(TrackingModule.NAME, TrackingModule::class.java, null)
|
|
421
|
+
// /angular-lynx:tracking
|
|
422
|
+
// angular-lynx:nfc
|
|
423
|
+
// NFC reader mode behind LynxNfc (NfcModule.kt), in this activity.
|
|
424
|
+
// An app whose angular.json doesn't set permissions.nfc is built
|
|
425
|
+
// without the module and these lines.
|
|
426
|
+
registerModule(NfcModule.NAME, NfcModule::class.java, this@MainActivity)
|
|
427
|
+
// /angular-lynx:nfc
|
|
428
|
+
// angular-lynx:wifi
|
|
429
|
+
// The Wi-Fi network reads and joins behind LynxWifi
|
|
430
|
+
// (WifiModule.kt), which asks for the location a read needs
|
|
431
|
+
// through this activity's prompt. An app whose angular.json
|
|
432
|
+
// doesn't set wifi is built without the module and these lines.
|
|
433
|
+
registerModule(WifiModule.NAME, WifiModule::class.java, permissionHost)
|
|
434
|
+
// /angular-lynx:wifi
|
|
435
|
+
// The motion sensors, the compass and shakes behind LynxMotion
|
|
436
|
+
// (MotionModule.kt), which stop while this activity is paused. An
|
|
437
|
+
// app whose angular.json doesn't set motion is built without the
|
|
438
|
+
// module and these lines (@blotch/angular-lynx-native's
|
|
439
|
+
// android/project.ts).
|
|
440
|
+
// angular-lynx:motion
|
|
441
|
+
registerModule(MotionModule.NAME, MotionModule::class.java, this@MainActivity)
|
|
442
|
+
// /angular-lynx:motion
|
|
194
443
|
// The shortcuts the person runs from the app icon's menu, which
|
|
195
444
|
// LynxShortcuts takes (ShortcutsModule.kt).
|
|
196
445
|
registerModule(ShortcutsModule.NAME, ShortcutsModule::class.java, null)
|
|
446
|
+
// angular-lynx:share-target
|
|
447
|
+
// What other apps share to this one, which LynxShareTarget takes
|
|
448
|
+
// (ShareTargetModule.kt). An app whose angular.json has no
|
|
449
|
+
// shareTarget is built without the module, its intent filters and
|
|
450
|
+
// these lines.
|
|
451
|
+
registerModule(ShareTargetModule.NAME, ShareTargetModule::class.java, null)
|
|
452
|
+
// /angular-lynx:share-target
|
|
453
|
+
// Bluetooth LE behind LynxBluetooth (BluetoothModule.kt), which
|
|
454
|
+
// asks for its permissions through this activity. Only an app
|
|
455
|
+
// whose angular.json sets permissions.bluetooth has it: the
|
|
456
|
+
// generator deletes the file from every other app, which then
|
|
457
|
+
// ships no Bluetooth code and its manifest declares no Bluetooth
|
|
458
|
+
// permission (the iOS shell does the same, since App Store Connect
|
|
459
|
+
// flags an app whose code uses CoreBluetooth without saying why).
|
|
460
|
+
// So it's looked up by name, which compiles either way, and
|
|
461
|
+
// nothing else may name the class. Lynx's own R8 rules keep every
|
|
462
|
+
// LynxModule's name, so a release build finds it too.
|
|
463
|
+
optionalModule(BLUETOOTH_MODULE_CLASS)?.let {
|
|
464
|
+
registerModule(BLUETOOTH_MODULE, it, permissionHost)
|
|
465
|
+
}
|
|
197
466
|
// <canvas>'s WebGL (WebGLModule.kt), which the runtime calls from
|
|
198
467
|
// the main thread, where Angular runs: main-thread modules let
|
|
199
468
|
// it get its answers synchronously, with lynx.module(name). Lynx
|
|
200
|
-
// calls them on its engine thread, not the UI thread.
|
|
469
|
+
// calls them on its engine thread, not the UI thread. An app
|
|
470
|
+
// that never draws on a canvas is built without the canvas code
|
|
471
|
+
// and these lines (@blotch/angular-lynx-native's features.ts).
|
|
472
|
+
// angular-lynx:canvas
|
|
201
473
|
registerModule(WebGLModule.NAME, WebGLModule::class.java, null)
|
|
474
|
+
// /angular-lynx:canvas
|
|
202
475
|
// Bundled files for the main thread's fetch and Image (AssetsModule.kt).
|
|
203
476
|
registerModule(AssetsModule.NAME, AssetsModule::class.java, null)
|
|
204
477
|
setEnableMTSModule(true)
|
|
@@ -209,8 +482,13 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
209
482
|
// In an edge-to-edge app an <overlay>'s window fills the screen as
|
|
210
483
|
// the page does, under the navigation bar too (EdgeToEdgeOverlay.kt).
|
|
211
484
|
if (edgeToEdge) addBehavior(EdgeToEdgeOverlay.behavior())
|
|
485
|
+
// angular-lynx:canvas
|
|
212
486
|
// The shell's own <canvas> (CanvasUI.kt): Lynx has none.
|
|
213
487
|
addBehavior(CanvasUI.behavior())
|
|
488
|
+
// XElement's <video>, with frames a canvas can read (VideoUI.kt).
|
|
489
|
+
// Without the canvas, XElementBehaviors' own <video> plays.
|
|
490
|
+
addBehavior(VideoUI.behavior())
|
|
491
|
+
// /angular-lynx:canvas
|
|
214
492
|
// Live reload, in the debug build: it renders the bundle again
|
|
215
493
|
// after every edit.
|
|
216
494
|
DevServer.register(this) { lynxView.renderTemplateUrl(bundleUrl, "") }
|
|
@@ -232,6 +510,16 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
232
510
|
override fun onReceivedError(error: LynxError?) {
|
|
233
511
|
Log.e(TAG, "Lynx error: ${error?.msg}")
|
|
234
512
|
}
|
|
513
|
+
|
|
514
|
+
// A load sets up a new engine, as the debug build's reload does,
|
|
515
|
+
// and Lynx gives it the font scale the LynxView was built with:
|
|
516
|
+
// updateFontScale doesn't change that. So a size chosen since then
|
|
517
|
+
// would be lost on reload while textScale kept it; give the new
|
|
518
|
+
// page the current scale.
|
|
519
|
+
override fun onLoadSuccess() {
|
|
520
|
+
val scale = textScale(resources.configuration)
|
|
521
|
+
if (scale != builtFontScale) lynxView.updateFontScale(scale)
|
|
522
|
+
}
|
|
235
523
|
})
|
|
236
524
|
|
|
237
525
|
// Draw the page under the status bar, the navigation bar and the
|
|
@@ -341,6 +629,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
341
629
|
lynxView.sendGlobalEvent(ShortcutsModule.EVENT, JavaOnlyArray())
|
|
342
630
|
return
|
|
343
631
|
}
|
|
632
|
+
// angular-lynx:share-target
|
|
633
|
+
// A share from another app's share sheet while the app is open.
|
|
634
|
+
if (ShareTargetModule.receive(this, intent)) return
|
|
635
|
+
// /angular-lynx:share-target
|
|
344
636
|
if (intent.action != Intent.ACTION_VIEW) return
|
|
345
637
|
val url = intent.data ?: return
|
|
346
638
|
// The sign-in page's redirect to the callback scheme: the deep link
|
|
@@ -364,12 +656,27 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
364
656
|
// language change still restarts the activity, which sends the new
|
|
365
657
|
// appLocale: Angular reads LOCALE_ID only once. A new wallpaper arrives
|
|
366
658
|
// here too, without a restart, and globalProps() reads its colors again.
|
|
659
|
+
//
|
|
660
|
+
// A new font size arrives here too (the manifest lists fontScale), and the
|
|
661
|
+
// page's root font size, with every rem, takes the new scale at once.
|
|
367
662
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
368
663
|
super.onConfigurationChanged(newConfig)
|
|
369
664
|
updateWindowAppearance()
|
|
665
|
+
lynxView.updateFontScale(textScale(newConfig))
|
|
370
666
|
lynxView.updateGlobalProps(globalProps(newConfig))
|
|
371
667
|
}
|
|
372
668
|
|
|
669
|
+
// How much larger than the default the user's font size is (Settings >
|
|
670
|
+
// Display > Font size): 1 at the default, up to 2 on Android 14 and
|
|
671
|
+
// later. Capped at angular.json's textScaling.max, and 1 with
|
|
672
|
+
// "textScaling": false. Android 14 scales large sp text less than small
|
|
673
|
+
// (nonlinear font scaling); Lynx applies the one factor to everything.
|
|
674
|
+
private fun textScale(config: Configuration): Float {
|
|
675
|
+
if (!textScaling) return 1f
|
|
676
|
+
val scale = config.fontScale.takeIf { it > 0f } ?: 1f
|
|
677
|
+
return if (maxTextScale > 0f) minOf(scale, maxTextScale) else scale
|
|
678
|
+
}
|
|
679
|
+
|
|
373
680
|
// Kept through a dark mode switch, the window keeps the theme it started
|
|
374
681
|
// with: its background, which shows behind the system bars, and the
|
|
375
682
|
// bars' icons, which enableEdgeToEdge() picked for the old mode. Both are
|
|
@@ -386,9 +693,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
386
693
|
/**
|
|
387
694
|
* The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
|
|
388
695
|
* (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
|
|
389
|
-
* build option's Intl.DateTimeFormat), the accessibility settings
|
|
390
|
-
* (LynxAccessibilitySettings), `
|
|
391
|
-
* `
|
|
696
|
+
* build option's Intl.DateTimeFormat), the accessibility settings and
|
|
697
|
+
* text scale (LynxAccessibilitySettings), `appState` (LynxAppState),
|
|
698
|
+
* `osVersion` (LynxSystemInfo) and `initialURL` (LynxLinking and the
|
|
699
|
+
* router), plus the
|
|
392
700
|
* safe-area insets in dp and `edgeToEdge`, which env(safe-area-inset-*)
|
|
393
701
|
* reads. The iOS shell sends the same keys, and Lynx Explorer sends theme
|
|
394
702
|
* and isNotchScreen too. Android 12 and later also send the wallpaper's
|
|
@@ -415,6 +723,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
415
723
|
// Lynx has no API for these. Android has no Reduce Transparency.
|
|
416
724
|
"reduceMotion" to reduceMotion(),
|
|
417
725
|
"increaseContrast" to increaseContrast(),
|
|
726
|
+
// The font size, as the LynxView's font scale has it
|
|
727
|
+
// (LynxAccessibilitySettings.textScale).
|
|
728
|
+
"textScale" to textScale(config),
|
|
729
|
+
"appState" to appState,
|
|
418
730
|
)
|
|
419
731
|
// The user's language as a BCP 47 tag, such as "fr-FR".
|
|
420
732
|
ConfigurationCompat.getLocales(config)[0]?.let { props["appLocale"] = it.toLanguageTag() }
|
|
@@ -443,11 +755,27 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
443
755
|
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA &&
|
|
444
756
|
getSystemService(AccessibilityManager::class.java).isHighContrastTextEnabled)
|
|
445
757
|
|
|
758
|
+
// Tells the app where it is now (LynxAppState). Lynx itself tells the
|
|
759
|
+
// app's code nothing when it leaves the screen or comes back.
|
|
760
|
+
private fun sendAppState(state: String) {
|
|
761
|
+
if (appState == state) return
|
|
762
|
+
appState = state
|
|
763
|
+
sendGlobalProps()
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
override fun onStart() {
|
|
767
|
+
super.onStart()
|
|
768
|
+
sendAppState("inactive")
|
|
769
|
+
}
|
|
770
|
+
|
|
446
771
|
// Lynx pauses timers and animations in the background and fires the
|
|
447
772
|
// page's visibility events from these.
|
|
448
773
|
override fun onResume() {
|
|
449
774
|
super.onResume()
|
|
450
775
|
lynxView.onEnterForeground()
|
|
776
|
+
resumed = true
|
|
777
|
+
// After the timers resume, so what the app starts on its return runs.
|
|
778
|
+
sendAppState(if (topResumed) "active" else "inactive")
|
|
451
779
|
// Back from a Custom Tab without its redirect: the person closed it.
|
|
452
780
|
// Android says nothing else when a Custom Tab closes.
|
|
453
781
|
webAuthSession?.takeIf { it.opened }?.let {
|
|
@@ -456,13 +784,35 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
456
784
|
}
|
|
457
785
|
}
|
|
458
786
|
|
|
787
|
+
// Android 10 and later: whether this is the resumed activity that has the
|
|
788
|
+
// focus, which changes without a pause in split screen. Called after
|
|
789
|
+
// onResume and before onPause, so it only moves a resumed activity
|
|
790
|
+
// between "active" and "inactive".
|
|
791
|
+
override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
|
|
792
|
+
super.onTopResumedActivityChanged(isTopResumedActivity)
|
|
793
|
+
topResumed = isTopResumedActivity
|
|
794
|
+
if (resumed) sendAppState(if (isTopResumedActivity) "active" else "inactive")
|
|
795
|
+
}
|
|
796
|
+
|
|
459
797
|
override fun onPause() {
|
|
798
|
+
resumed = false
|
|
799
|
+
// Before Lynx pauses the timers, so the app hears it on its way out.
|
|
800
|
+
sendAppState("inactive")
|
|
460
801
|
lynxView.onEnterBackground()
|
|
461
802
|
webAuthSession?.opened = true
|
|
462
803
|
super.onPause()
|
|
463
804
|
}
|
|
464
805
|
|
|
806
|
+
override fun onStop() {
|
|
807
|
+
sendAppState("background")
|
|
808
|
+
super.onStop()
|
|
809
|
+
}
|
|
810
|
+
|
|
465
811
|
override fun onDestroy() {
|
|
812
|
+
// angular-lynx:share-target
|
|
813
|
+
// Only this activity's own: a recreated one has set its own already.
|
|
814
|
+
if (ShareTargetModule.arrived === shareArrived) ShareTargetModule.arrived = null
|
|
815
|
+
// /angular-lynx:share-target
|
|
466
816
|
contentResolver.unregisterContentObserver(animationScaleObserver)
|
|
467
817
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
468
818
|
(contrastListener as UiModeManager.ContrastChangeListener?)?.let {
|
|
@@ -482,6 +832,26 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
482
832
|
private companion object {
|
|
483
833
|
const val TAG = "AngularLynxShell"
|
|
484
834
|
|
|
835
|
+
// BarcodeScannerModule and BluetoothModule, and their NAMEs, which
|
|
836
|
+
// this file can't refer to (see onCreate). The classes are in the
|
|
837
|
+
// shell's own package, which is fixed whatever the app's
|
|
838
|
+
// applicationId.
|
|
839
|
+
const val BARCODE_SCANNER_MODULE_CLASS = "dev.angularlynx.shell.BarcodeScannerModule"
|
|
840
|
+
const val BARCODE_SCANNER_MODULE = "AngularLynxBarcodeScanner"
|
|
841
|
+
const val BLUETOOTH_MODULE_CLASS = "dev.angularlynx.shell.BluetoothModule"
|
|
842
|
+
const val BLUETOOTH_MODULE = "AngularLynxBluetooth"
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* The module class named [className], or null when the generator
|
|
846
|
+
* left it out of this app.
|
|
847
|
+
*/
|
|
848
|
+
fun optionalModule(className: String): Class<out LynxModule>? =
|
|
849
|
+
try {
|
|
850
|
+
Class.forName(className).asSubclass(LynxModule::class.java)
|
|
851
|
+
} catch (_: ClassNotFoundException) {
|
|
852
|
+
null
|
|
853
|
+
}
|
|
854
|
+
|
|
485
855
|
// The longest the splash screen waits for the app (see onCreate),
|
|
486
856
|
// and its fade, as long as the iOS shell's.
|
|
487
857
|
const val SPLASH_TIMEOUT_MS = 5_000L
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import com.lynx.react.bridge.JavaOnlyArray
|
|
4
|
+
import com.lynx.react.bridge.ReadableArray
|
|
5
|
+
import java.nio.ByteBuffer
|
|
6
|
+
import java.nio.ByteOrder
|
|
7
|
+
|
|
8
|
+
// How bytes cross a module call, both ways: the WebGL module's buffers and
|
|
9
|
+
// images, and the files AssetsModule reads. Here, not in WebGLModule.kt, as
|
|
10
|
+
// an app that never draws on a canvas is built without that file
|
|
11
|
+
// (@blotch/angular-lynx-native's features.ts) and still has AssetsModule.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The bytes the runtime sends as 32-bit words, with the byte count last (see
|
|
15
|
+
* toWords in webgl-bridge.ts). Android runs little-endian, so the words land
|
|
16
|
+
* in memory as the bytes were.
|
|
17
|
+
*/
|
|
18
|
+
internal fun bytesFromWords(words: ReadableArray): ByteBuffer {
|
|
19
|
+
val count = words.size()
|
|
20
|
+
if (count == 0) return ByteBuffer.allocateDirect(0)
|
|
21
|
+
val byteLength = words.getDouble(count - 1).toLong().toInt()
|
|
22
|
+
val buffer = ByteBuffer.allocateDirect((count - 1) * 4).order(ByteOrder.LITTLE_ENDIAN)
|
|
23
|
+
for (i in 0 until count - 1) buffer.putInt(words.getDouble(i).toLong().toInt())
|
|
24
|
+
buffer.rewind()
|
|
25
|
+
buffer.limit(minOf(byteLength, (count - 1) * 4))
|
|
26
|
+
return buffer
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Bytes as words for the trip back, the byte count last. */
|
|
30
|
+
internal fun wordsFromBytes(bytes: ByteBuffer, length: Int): JavaOnlyArray {
|
|
31
|
+
val words = JavaOnlyArray()
|
|
32
|
+
val source = bytes.duplicate().order(ByteOrder.LITTLE_ENDIAN)
|
|
33
|
+
source.rewind()
|
|
34
|
+
val wordCount = (length + 3) / 4
|
|
35
|
+
for (i in 0 until wordCount) {
|
|
36
|
+
var word = 0L
|
|
37
|
+
for (b in 0 until 4) {
|
|
38
|
+
val index = i * 4 + b
|
|
39
|
+
if (index < length) word = word or ((source.get(index).toLong() and 0xff) shl (8 * b))
|
|
40
|
+
}
|
|
41
|
+
words.pushDouble(word.toDouble())
|
|
42
|
+
}
|
|
43
|
+
words.pushInt(length)
|
|
44
|
+
return words
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
internal fun flipRows(pixels: ByteBuffer, stride: Int, height: Int) {
|
|
48
|
+
val top = ByteArray(stride)
|
|
49
|
+
val bottom = ByteArray(stride)
|
|
50
|
+
for (row in 0 until height / 2) {
|
|
51
|
+
val other = height - 1 - row
|
|
52
|
+
pixels.position(row * stride); pixels.get(top)
|
|
53
|
+
pixels.position(other * stride); pixels.get(bottom)
|
|
54
|
+
pixels.position(row * stride); pixels.put(bottom)
|
|
55
|
+
pixels.position(other * stride); pixels.put(top)
|
|
56
|
+
}
|
|
57
|
+
pixels.rewind()
|
|
58
|
+
}
|