@oxy.so/bloom-lens 0.0.0-stage → 1.0.0
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/LICENSE +673 -0
- package/NOTICE +26 -0
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/assets/fonts/Inter-OFL.txt +93 -0
- package/android/src/main/assets/fonts/Inter-Regular.ttf +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/220 +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidModule.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidView.kt +548 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassBackdrop.kt +215 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassLens.kt +103 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeGeometry.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeIcons.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeMaterial.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeHost.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeModule.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeView.kt +609 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/StaticGlassCache.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceIcons.kt +114 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesHost.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesModule.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesView.kt +527 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassIcons.kt +68 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassMenuContent.kt +349 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassRow.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassFieldTexture.kt +102 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassGaussianField.kt +161 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassShapes.kt +37 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedField.kt +119 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedUnion.kt +81 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassGroup.kt +225 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassJelly.kt +118 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphFrame.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphTuning.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMotion.kt +475 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassSpring.kt +78 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassDevGuard.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassFeedback.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuOverlay.kt +433 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuSession.kt +750 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassScrub.kt +41 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassSubmenuLayer.kt +290 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassAbsorbRecord.kt +9 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMemberRecord.kt +14 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuConfigRecord.kt +24 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuItemRecord.kt +23 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassShrinkRecord.kt +10 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassTriggerConfigRecord.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRecipe.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRenderer.kt +361 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassShaders.kt +318 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassStill.kt +115 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassSurfaceState.kt +38 -0
- package/expo-module.config.json +10 -0
- package/package.json +29 -4
- package/patches/bloom.patch +1908 -0
- package/patches/menu/bloom.patch +148 -0
- package/src/base.tsx +208 -0
- package/src/chrome/compositor-geometry.ts +163 -0
- package/src/chrome/glass-header.tsx +155 -0
- package/src/chrome/glass-search-fab.tsx +113 -0
- package/src/chrome/glass-size-class.tsx +150 -0
- package/src/chrome/glass-toolbar.tsx +45 -0
- package/src/chrome/interface.ts +17 -0
- package/src/chrome/ios-tab-bar.tsx +49 -0
- package/src/chrome/surface-layer.ts +91 -0
- package/src/chrome/surface-nodes.tsx +54 -0
- package/src/index.ts +19 -0
- package/src/menu/components/menu/index.ts +22 -0
- package/src/menu/components/menu/menu.tsx +97 -0
- package/src/menu/components/menu-action-row/index.ts +1 -0
- package/src/menu/components/menu-action-row/menu-action-row.tsx +12 -0
- package/src/menu/components/menu-content/index.ts +2 -0
- package/src/menu/components/menu-content/menu-content.tsx +11 -0
- package/src/menu/components/menu-item/index.ts +13 -0
- package/src/menu/components/menu-item/menu-item-icon.tsx +10 -0
- package/src/menu/components/menu-item/menu-item-subtitle.tsx +14 -0
- package/src/menu/components/menu-item/menu-item-title.tsx +11 -0
- package/src/menu/components/menu-item/menu-item.tsx +11 -0
- package/src/menu/components/menu-label/index.ts +3 -0
- package/src/menu/components/menu-label/menu-label.tsx +11 -0
- package/src/menu/components/menu-separator/index.ts +3 -0
- package/src/menu/components/menu-separator/menu-separator.tsx +7 -0
- package/src/menu/components/menu-submenu/index.ts +1 -0
- package/src/menu/components/menu-submenu/menu-submenu.tsx +12 -0
- package/src/menu/components/menu-trigger/index.ts +3 -0
- package/src/menu/components/menu-trigger/interface.ts +41 -0
- package/src/menu/components/menu-trigger/menu-trigger.android.tsx +97 -0
- package/src/menu/components/menu-trigger/menu-trigger.tsx +15 -0
- package/src/menu/components/menu-trigger/native-menu.android.ts +9 -0
- package/src/menu/components/menu-trigger-button/index.ts +3 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.android.tsx +38 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.tsx +17 -0
- package/src/menu/constants/interface.ts +6 -0
- package/src/menu/constants/menu.const.ts +11 -0
- package/src/menu/context/interface.ts +63 -0
- package/src/menu/context/menu.context.ts +7 -0
- package/src/menu/index.ts +53 -0
- package/src/menu/interface.ts +229 -0
- package/src/menu/utils/create-compound-component.util.ts +18 -0
- package/src/menu/utils/find-menu-content.util.ts +17 -0
- package/src/menu/utils/flatten-elements.util.ts +18 -0
- package/src/menu/utils/parse-menu-content.util.ts +98 -0
- package/src/menu/utils/parse-menu-item.util.ts +56 -0
- package/src/menu/utils/register-component.util.ts +13 -0
- package/src/menu/utils/to-native-item.util.ts +24 -0
- package/src/rows.tsx +61 -0
- package/README.md +0 -3
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.chrome
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import android.graphics.Paint
|
|
7
|
+
import android.graphics.Rect
|
|
8
|
+
import android.graphics.RectF
|
|
9
|
+
import android.graphics.RenderNode
|
|
10
|
+
import android.graphics.Typeface
|
|
11
|
+
import android.os.Build
|
|
12
|
+
import android.util.Log
|
|
13
|
+
import android.util.TypedValue
|
|
14
|
+
import android.widget.EditText
|
|
15
|
+
import android.widget.FrameLayout
|
|
16
|
+
import android.view.Choreographer
|
|
17
|
+
|
|
18
|
+
import android.view.MotionEvent
|
|
19
|
+
import android.view.View
|
|
20
|
+
import android.view.ViewGroup
|
|
21
|
+
import android.view.ViewConfiguration
|
|
22
|
+
import android.view.inputmethod.EditorInfo
|
|
23
|
+
import android.view.inputmethod.InputMethodManager
|
|
24
|
+
import so.oxy.bloom.glassmenu.motion.GlassSpring
|
|
25
|
+
import so.oxy.bloom.glassmenu.backdrop.GlassBackdrop
|
|
26
|
+
import so.oxy.bloom.glassmenu.motion.GlassJelly
|
|
27
|
+
import so.oxy.bloom.glassmenu.motion.GlassMotion
|
|
28
|
+
import so.oxy.bloom.glassmenu.motion.GlassSpringSpec
|
|
29
|
+
import so.oxy.bloom.glassmenu.overlay.GlassFeedback
|
|
30
|
+
import so.oxy.bloom.glassmenu.overlay.GlassScrub
|
|
31
|
+
import so.oxy.bloom.glassmenu.render.GlassRenderer
|
|
32
|
+
import so.oxy.bloom.glassmenu.render.GlassSurfaceState
|
|
33
|
+
import kotlin.math.abs
|
|
34
|
+
import kotlin.math.max
|
|
35
|
+
import kotlin.math.min
|
|
36
|
+
|
|
37
|
+
// Native iOS-style chrome: tab bar capsule with a sliding pill, search circle that morphs into a field, and a
|
|
38
|
+
// create circle. Mirrors ios-tab-bar-view.web.tsx: same geometry (ChromeGeometry), same springs, same fills.
|
|
39
|
+
// The chrome drawn as a window overlay (a direct child of the window root, like the menu overlay): the page is never an
|
|
40
|
+
// ancestor of the glass, so the backdrop cannot contain the surface that samples it. The Expo host (GlassChromeHost)
|
|
41
|
+
// forwards props and events.
|
|
42
|
+
class GlassChromeView(context: Context) : FrameLayout(context) {
|
|
43
|
+
// Events to the host: "onTabSelect", "onSearchChange", "onCreate".
|
|
44
|
+
var emit: (String, Map<String, Any?>) -> Unit = { _, _ -> }
|
|
45
|
+
|
|
46
|
+
private val density = resources.displayMetrics.density
|
|
47
|
+
private val slop = ViewConfiguration.get(context).scaledTouchSlop
|
|
48
|
+
|
|
49
|
+
var labels: List<String> = emptyList()
|
|
50
|
+
set(value) {
|
|
51
|
+
field = value
|
|
52
|
+
invalidate()
|
|
53
|
+
}
|
|
54
|
+
var icons: List<String> = emptyList()
|
|
55
|
+
set(value) {
|
|
56
|
+
field = value
|
|
57
|
+
invalidate()
|
|
58
|
+
}
|
|
59
|
+
var selectedIndex: Int = 0
|
|
60
|
+
set(value) {
|
|
61
|
+
field = value
|
|
62
|
+
pillSpring.target(value.toFloat(), PILL_SPEC)
|
|
63
|
+
kick()
|
|
64
|
+
}
|
|
65
|
+
// dp, same meaning as bottomInset in the web bar.
|
|
66
|
+
var bottomInset: Float = 0f
|
|
67
|
+
set(value) {
|
|
68
|
+
field = value
|
|
69
|
+
invalidate()
|
|
70
|
+
}
|
|
71
|
+
var searchPlaceholder: String = "Search"
|
|
72
|
+
set(value) {
|
|
73
|
+
field = value
|
|
74
|
+
input.hint = value
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private val searchSpring = GlassSpring(0.002f, 0.02f)
|
|
78
|
+
// One jelly per pressable control, as the menu has one for its trigger.
|
|
79
|
+
private val searchJelly = GlassJelly()
|
|
80
|
+
private val fabJelly = GlassJelly()
|
|
81
|
+
private val pillJelly = GlassJelly()
|
|
82
|
+
// The shared scrub controller of each pressable control (the same one the menu uses for its rows).
|
|
83
|
+
private val searchScrub = GlassScrub(searchJelly)
|
|
84
|
+
private val fabScrub = GlassScrub(fabJelly)
|
|
85
|
+
private val pillScrub = GlassScrub(pillJelly)
|
|
86
|
+
private var pressedScrub: GlassScrub? = null
|
|
87
|
+
private val pillSpring = GlassSpring(0.002f, 0.02f)
|
|
88
|
+
private var searchOpen = false
|
|
89
|
+
private var running = false
|
|
90
|
+
private var lastNanos = -1L
|
|
91
|
+
private val frameCallback = Choreographer.FrameCallback { nanos -> onFrame(nanos) }
|
|
92
|
+
|
|
93
|
+
// One renderer per glass surface, as in the menu (a renderer records its own RenderNodes).
|
|
94
|
+
private val barRenderer = GlassRenderer(density, density * FIELD_STEP)
|
|
95
|
+
private val fabRenderer = GlassRenderer(density, density * FIELD_STEP)
|
|
96
|
+
// The selection pill: refraction on (the menu's resting-trigger material). Its own renderer.
|
|
97
|
+
private val pillRenderer = GlassRenderer(density, density * FIELD_STEP)
|
|
98
|
+
// The rasterized static glass (hardware buffer), see StaticGlassCache.
|
|
99
|
+
private val staticGlass = StaticGlassCache()
|
|
100
|
+
// The window backdrop: the page behind the chrome, shared with the menus (GlassBackdrop, recorded in preDraw).
|
|
101
|
+
private var backdropProvider: GlassBackdrop? = null
|
|
102
|
+
private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
103
|
+
private val iconPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
104
|
+
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
105
|
+
typeface = Typeface.create(Typeface.DEFAULT, 700, false)
|
|
106
|
+
textAlign = Paint.Align.CENTER
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private val input = EditText(context).apply {
|
|
110
|
+
background = null
|
|
111
|
+
setPadding(0, 0, 0, 0)
|
|
112
|
+
setSingleLine(true)
|
|
113
|
+
imeOptions = EditorInfo.IME_ACTION_SEARCH
|
|
114
|
+
setTextColor(Color.WHITE)
|
|
115
|
+
setHintTextColor(ACCENT_INACTIVE)
|
|
116
|
+
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17f)
|
|
117
|
+
gravity = android.view.Gravity.CENTER_VERTICAL or android.view.Gravity.START
|
|
118
|
+
alpha = 0f
|
|
119
|
+
visibility = View.INVISIBLE
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
init {
|
|
123
|
+
setWillNotDraw(false)
|
|
124
|
+
addView(input)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// The field is placed by placeInput(); FrameLayout's own layout pass must not move it.
|
|
128
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {}
|
|
129
|
+
|
|
130
|
+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
131
|
+
super.onSizeChanged(w, h, oldw, oldh)
|
|
132
|
+
if (oldw == 0) pillSpring.reset(selectedIndex.toFloat())
|
|
133
|
+
invalidate()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override fun onAttachedToWindow() {
|
|
137
|
+
super.onAttachedToWindow()
|
|
138
|
+
val root = rootView as? ViewGroup ?: return
|
|
139
|
+
backdropProvider = GlassBackdrop.forRoot(root).also { it.register(this) { android.graphics.Color.BLACK } }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
override fun onDetachedFromWindow() {
|
|
143
|
+
backdropProvider?.unregister(this)
|
|
144
|
+
backdropProvider = null
|
|
145
|
+
Choreographer.getInstance().removeFrameCallback(frameCallback)
|
|
146
|
+
running = false
|
|
147
|
+
lastNanos = -1L
|
|
148
|
+
barRenderer.release()
|
|
149
|
+
fabRenderer.release()
|
|
150
|
+
staticGlass.release()
|
|
151
|
+
super.onDetachedFromWindow()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private fun kick() {
|
|
155
|
+
if (running) return
|
|
156
|
+
running = true
|
|
157
|
+
lastNanos = -1L
|
|
158
|
+
Choreographer.getInstance().postFrameCallback(frameCallback)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// One display frame: advance both springs with the real frame time (capped like the web loop), then redraw.
|
|
162
|
+
private fun onFrame(nanos: Long) {
|
|
163
|
+
val seconds = if (lastNanos < 0L) 1f / 60f else min((nanos - lastNanos) / 1_000_000_000f, 1f / 30f)
|
|
164
|
+
lastNanos = nanos
|
|
165
|
+
searchSpring.advance(seconds)
|
|
166
|
+
pillSpring.advance(seconds)
|
|
167
|
+
searchJelly.advance(seconds)
|
|
168
|
+
fabJelly.advance(seconds)
|
|
169
|
+
pillJelly.advance(seconds)
|
|
170
|
+
invalidate()
|
|
171
|
+
if (searchSpring.isSettled && pillSpring.isSettled && searchJelly.isSettled && fabJelly.isSettled && pillJelly.isSettled) {
|
|
172
|
+
searchSpring.finish()
|
|
173
|
+
pillSpring.finish()
|
|
174
|
+
invalidate()
|
|
175
|
+
running = false
|
|
176
|
+
lastNanos = -1L
|
|
177
|
+
} else {
|
|
178
|
+
Choreographer.getInstance().postFrameCallback(frameCallback)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// A surface inside the page must not draw while the backdrop is recorded (it would record itself).
|
|
183
|
+
override fun dispatchDraw(canvas: Canvas) {
|
|
184
|
+
super.dispatchDraw(canvas)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
override fun onDraw(canvas: Canvas) {
|
|
188
|
+
if (width <= 0 || height <= 0) return
|
|
189
|
+
val w = width / density
|
|
190
|
+
val h = height / density
|
|
191
|
+
val progress = clamp01(searchSpring.value)
|
|
192
|
+
val shapes = ChromeGeometry.tabBarShapes(w, h, bottomInset, progress).map { shape ->
|
|
193
|
+
when (shape.id) {
|
|
194
|
+
"search" -> deform(shape, searchJelly)
|
|
195
|
+
"fab" -> deform(shape, fabJelly)
|
|
196
|
+
else -> shape
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Glass surfaces are drawn in pixels (GlassRenderer works in px, like the menu).
|
|
200
|
+
drawGlassSurfaces(canvas, shapes, w, h)
|
|
201
|
+
canvas.save()
|
|
202
|
+
canvas.scale(density, density)
|
|
203
|
+
drawContent(canvas, w, h, shapes, progress)
|
|
204
|
+
canvas.restore()
|
|
205
|
+
// The selection pill is drawn last: above the labels and icons, refracting them as it passes over.
|
|
206
|
+
drawPillGlass(canvas, w, h, progress)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Press deformation of one control: the menu's GlassJelly.deformControl on the control's rectangle (dp).
|
|
210
|
+
// At rest the jelly is idle and the rectangle is unchanged.
|
|
211
|
+
private fun deform(shape: ChromeShape, jelly: GlassJelly): ChromeShape {
|
|
212
|
+
val rect = RectF(shape.x0, shape.y0, shape.x1, shape.y1)
|
|
213
|
+
jelly.deformControl(rect, 1f, 1f)
|
|
214
|
+
return ChromeShape(shape.id, shape.group, rect.left, rect.top, rect.right, rect.bottom, min(rect.width(), rect.height()) / 2f)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// The bar (capsule + search circle fused) and the create circle: the menu's material through ChromeMaterial.
|
|
218
|
+
private fun drawGlassSurfaces(canvas: Canvas, shapes: List<ChromeShape>, w: Float, h: Float) {
|
|
219
|
+
val provider = backdropProvider ?: return
|
|
220
|
+
val root = rootView as? ViewGroup ?: return
|
|
221
|
+
// Glass states are in window px (the backdrop is in window coordinates): translate the canvas to the window.
|
|
222
|
+
val rootLocation = IntArray(2)
|
|
223
|
+
val chromeLocation = IntArray(2)
|
|
224
|
+
root.getLocationInWindow(rootLocation)
|
|
225
|
+
getLocationInWindow(chromeLocation)
|
|
226
|
+
val ox = (chromeLocation[0] - rootLocation[0]).toFloat()
|
|
227
|
+
val oy = (chromeLocation[1] - rootLocation[1]).toFloat()
|
|
228
|
+
val rest = ChromeGeometry.tabBarShapes(w, h, bottomInset, 0f)
|
|
229
|
+
val limits = Rect(0, 0, root.width, root.height)
|
|
230
|
+
val d = density
|
|
231
|
+
val progress = clamp01(searchSpring.value)
|
|
232
|
+
val tabs = shapes.first { it.id == "tabs" }
|
|
233
|
+
val search = shapes.first { it.id == "search" }
|
|
234
|
+
val fab = shapes.first { it.id == "fab" }
|
|
235
|
+
canvas.save()
|
|
236
|
+
canvas.translate(-ox, -oy)
|
|
237
|
+
// The static glass (bar container and create circle) comes from a hardware texture while the pill is dragged; the
|
|
238
|
+
// texture covers the strip from the top of the static glass down, and is rendered again only when its key changes.
|
|
239
|
+
val stripTopDp = max(0f, min(rest.first { it.id == "tabs" }.y0, rest.first { it.id == "fab" }.y0) - ChromeGeometry.LAYER_PAD)
|
|
240
|
+
// Whole device pixels: a fractional offset makes drawBitmap resample the texture, which blurs the rim and the shadow edges.
|
|
241
|
+
val stripPx = Math.round(stripTopDp * d).toFloat()
|
|
242
|
+
val stripWidthPx = Math.round(w * d)
|
|
243
|
+
val stripHeightPx = Math.round(h * d) - stripPx.toInt()
|
|
244
|
+
val cacheKey = "$stripWidthPx,$stripHeightPx,${Math.round(progress * 1000)},${provider.version},$bottomInset,${labels.size},$ox,$oy"
|
|
245
|
+
if (staticGlass.isSupported && staticGlass.key != cacheKey) {
|
|
246
|
+
staticGlass.render(cacheKey, stripWidthPx, stripHeightPx) { cacheCanvas ->
|
|
247
|
+
cacheCanvas.save()
|
|
248
|
+
cacheCanvas.translate(-ox, -(oy + stripPx))
|
|
249
|
+
drawStaticGlass(cacheCanvas, provider, limits, ox, oy, tabs, search, fab, rest)
|
|
250
|
+
cacheCanvas.restore()
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
val cached = if (staticGlass.isSupported) staticGlass.bitmap else null
|
|
254
|
+
if (cached != null && staticGlass.key == cacheKey) {
|
|
255
|
+
canvas.drawBitmap(cached, 0f, stripPx, null)
|
|
256
|
+
} else {
|
|
257
|
+
drawStaticGlass(canvas, provider, limits, ox, oy, tabs, search, fab, rest)
|
|
258
|
+
}
|
|
259
|
+
canvas.restore()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// The static glass: the bar container and the create circle, at the shapes of the current search progress.
|
|
263
|
+
private fun drawStaticGlass(
|
|
264
|
+
canvas: Canvas,
|
|
265
|
+
provider: GlassBackdrop,
|
|
266
|
+
limits: Rect,
|
|
267
|
+
ox: Float,
|
|
268
|
+
oy: Float,
|
|
269
|
+
tabs: ChromeShape,
|
|
270
|
+
search: ChromeShape,
|
|
271
|
+
fab: ChromeShape,
|
|
272
|
+
rest: List<ChromeShape>,
|
|
273
|
+
) {
|
|
274
|
+
val barState = glassState(tabs, search, ChromeGeometry.layerFor("bar", rest), ox, oy)
|
|
275
|
+
barRenderer.prepare(barState)
|
|
276
|
+
barRenderer.drawGlass(canvas, provider, barState, limits)
|
|
277
|
+
// The create circle shrinks to nothing as the search opens: skip it when it has no area left.
|
|
278
|
+
if (fab.x1 - fab.x0 >= 1f) {
|
|
279
|
+
val fabState = glassState(fab, null, ChromeGeometry.layerFor("fab", rest), ox, oy)
|
|
280
|
+
fabRenderer.prepare(fabState)
|
|
281
|
+
fabRenderer.drawGlass(canvas, provider, fabState, limits)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// The pill's backdrop: the page (provider node) plus the tab items, recorded into its own node. The pill is not
|
|
286
|
+
// recorded into it, and the page node contains neither the chrome nor the pill, so there is no recursion.
|
|
287
|
+
private val pillBackdrop = RenderNode("ChromePillBackdrop")
|
|
288
|
+
|
|
289
|
+
private fun drawPillGlass(canvas: Canvas, w: Float, h: Float, progress: Float) {
|
|
290
|
+
if (labels.isEmpty()) return
|
|
291
|
+
val provider = backdropProvider ?: return
|
|
292
|
+
val root = rootView as? ViewGroup ?: return
|
|
293
|
+
val rootLocation = IntArray(2)
|
|
294
|
+
val chromeLocation = IntArray(2)
|
|
295
|
+
root.getLocationInWindow(rootLocation)
|
|
296
|
+
getLocationInWindow(chromeLocation)
|
|
297
|
+
val ox = (chromeLocation[0] - rootLocation[0]).toFloat()
|
|
298
|
+
val oy = (chromeLocation[1] - rootLocation[1]).toFloat()
|
|
299
|
+
val limits = Rect(0, 0, root.width, root.height)
|
|
300
|
+
val shapes = ChromeGeometry.tabBarShapes(w, h, bottomInset, progress)
|
|
301
|
+
val d = density
|
|
302
|
+
pillBackdrop.setPosition(0, 0, root.width, root.height)
|
|
303
|
+
val rec = pillBackdrop.beginRecording(root.width, root.height)
|
|
304
|
+
rec.drawRenderNode(provider.node)
|
|
305
|
+
rec.save()
|
|
306
|
+
rec.translate(ox, oy)
|
|
307
|
+
rec.scale(d, d)
|
|
308
|
+
drawTabItems(rec, w, h, shapes, progress)
|
|
309
|
+
rec.restore()
|
|
310
|
+
pillBackdrop.endRecording()
|
|
311
|
+
val pill = pillRectDp(w, h, progress)
|
|
312
|
+
val pillState = pillGlassState(pill, ox, oy)
|
|
313
|
+
pillRenderer.prepare(pillState)
|
|
314
|
+
canvas.save()
|
|
315
|
+
canvas.translate(-ox, -oy)
|
|
316
|
+
pillRenderer.drawGlass(canvas, pillBackdrop, pillState, limits)
|
|
317
|
+
canvas.restore()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// The pill rectangle in dp: at the pill's spring position, deformed by its jelly like the menu's trigger.
|
|
321
|
+
private fun pillRectDp(w: Float, h: Float, progress: Float): RectF {
|
|
322
|
+
val tabs = ChromeGeometry.tabBarShapes(w, h, bottomInset, progress).first { it.id == "tabs" }
|
|
323
|
+
val itemW = ChromeGeometry.itemWidth(w, labels.size)
|
|
324
|
+
val left = tabs.x0 + ChromeGeometry.PILL_INSET + pillSpring.value * itemW
|
|
325
|
+
val rect = RectF(left, tabs.y0 + ChromeGeometry.PILL_INSET, left + itemW, tabs.y0 + ChromeGeometry.TAB_HEIGHT - ChromeGeometry.PILL_INSET)
|
|
326
|
+
pillJelly.deformControl(rect, 1f, 1f)
|
|
327
|
+
return rect
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private fun pillGlassState(pill: RectF, ox: Float, oy: Float): GlassSurfaceState {
|
|
331
|
+
val d = density
|
|
332
|
+
val state = GlassSurfaceState()
|
|
333
|
+
ChromeMaterial.applyPill(state, pillJelly, pill, ox, oy, d)
|
|
334
|
+
val radius = min(pill.width(), pill.height()) / 2f * d
|
|
335
|
+
state.incoming.set(pill.left * d + ox, pill.top * d + oy, pill.right * d + ox, pill.bottom * d + oy)
|
|
336
|
+
state.radiusX = radius
|
|
337
|
+
state.radiusY = radius
|
|
338
|
+
// Capture: the pill plus a margin for the blur reach, as the menu's resting anchor does.
|
|
339
|
+
state.captureBounds.set(state.incoming)
|
|
340
|
+
state.captureBounds.inset(-PILL_CAPTURE_MARGIN * d, -PILL_CAPTURE_MARGIN * d)
|
|
341
|
+
return state
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// State of one chrome surface in px. `source` is the second shape of a fused pair (smoothing = blend).
|
|
345
|
+
private fun glassState(incoming: ChromeShape, source: ChromeShape?, capture: ChromeLayer, ox: Float, oy: Float): GlassSurfaceState {
|
|
346
|
+
val d = density
|
|
347
|
+
val state = GlassSurfaceState()
|
|
348
|
+
ChromeMaterial.apply(state)
|
|
349
|
+
state.incoming.set(incoming.x0 * d + ox, incoming.y0 * d + oy, incoming.x1 * d + ox, incoming.y1 * d + oy)
|
|
350
|
+
state.radiusX = incoming.radius * d
|
|
351
|
+
state.radiusY = incoming.radius * d
|
|
352
|
+
state.hasSource = source != null
|
|
353
|
+
if (source != null) {
|
|
354
|
+
state.source.set(source.x0 * d + ox, source.y0 * d + oy, source.x1 * d + ox, source.y1 * d + oy)
|
|
355
|
+
state.sourceRadius = source.radius * d
|
|
356
|
+
// Fusion follows the gap between the two shapes: 0 at rest (separate, no field union), full blend when the gap is closed.
|
|
357
|
+
val gap = source.x0 - incoming.x1
|
|
358
|
+
state.smoothing = ChromeGeometry.SMOOTH_BLEND * d * (1f - gap / ChromeGeometry.REST_GAP).coerceIn(0f, 1f)
|
|
359
|
+
}
|
|
360
|
+
state.captureBounds.set(capture.x * d + ox, capture.y * d + oy, (capture.x + capture.width) * d + ox, (capture.y + capture.height) * d + oy)
|
|
361
|
+
return state
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Tab items: icon 22 dp, label 11 dp below (same layout as the web items). Drawn in dp.
|
|
365
|
+
private fun drawTabItems(canvas: Canvas, w: Float, h: Float, shapes: List<ChromeShape>, progress: Float) {
|
|
366
|
+
val tabs = shapes.first { it.id == "tabs" }
|
|
367
|
+
val itemW = if (labels.isNotEmpty()) ChromeGeometry.itemWidth(w, labels.size) else 0f
|
|
368
|
+
val centerY = tabs.y0 + ChromeGeometry.TAB_HEIGHT / 2f
|
|
369
|
+
val itemsOpacity = clamp01(1f - progress * 1.5f)
|
|
370
|
+
labels.forEachIndexed { i, label ->
|
|
371
|
+
val cx = tabs.x0 + ChromeGeometry.PILL_INSET + i * itemW + itemW / 2f
|
|
372
|
+
// The label takes the active colour as the pill covers it: the colour follows the pill's continuous position.
|
|
373
|
+
val color = lerpColor(TAB_INACTIVE, ACCENT, clamp01(1f - abs(pillSpring.value - i)))
|
|
374
|
+
val iconName = icons.getOrNull(i) ?: ""
|
|
375
|
+
ChromeIcons.draw(canvas, iconPaint, iconName, cx, centerY - 7.5f, 22f, color, itemsOpacity)
|
|
376
|
+
textPaint.color = ChromeIcons.withAlpha(color, itemsOpacity)
|
|
377
|
+
textPaint.textSize = 11f
|
|
378
|
+
canvas.drawText(label, cx, centerY + 15.5f, textPaint)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private fun drawContent(canvas: Canvas, w: Float, h: Float, shapes: List<ChromeShape>, progress: Float) {
|
|
383
|
+
|
|
384
|
+
val tabs = shapes.first { it.id == "tabs" }
|
|
385
|
+
val search = shapes.first { it.id == "search" }
|
|
386
|
+
val fab = shapes.first { it.id == "fab" }
|
|
387
|
+
val itemCount = labels.size
|
|
388
|
+
val itemW = if (itemCount > 0) ChromeGeometry.itemWidth(w, itemCount) else 0f
|
|
389
|
+
val centerY = tabs.y0 + ChromeGeometry.TAB_HEIGHT / 2f
|
|
390
|
+
val itemsOpacity = clamp01(1f - progress * 1.5f)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
drawTabItems(canvas, w, h, shapes, progress)
|
|
394
|
+
|
|
395
|
+
// Search circle: lupa fades out as the close icon fades in.
|
|
396
|
+
val searchCx = (search.x0 + search.x1) / 2f
|
|
397
|
+
val searchCy = (search.y0 + search.y1) / 2f
|
|
398
|
+
val closeOpacity = clamp01((progress - 0.5f) * 2f)
|
|
399
|
+
ChromeIcons.draw(canvas, iconPaint, "search", searchCx, searchCy, 26f, Color.WHITE, 1f - closeOpacity)
|
|
400
|
+
ChromeIcons.draw(canvas, iconPaint, "close", searchCx, searchCy, 24f, Color.WHITE, closeOpacity)
|
|
401
|
+
|
|
402
|
+
// Create circle: the shape shrinks with progress, the plus fades out.
|
|
403
|
+
val fabCx = (fab.x0 + fab.x1) / 2f
|
|
404
|
+
val fabCy = (fab.y0 + fab.y1) / 2f
|
|
405
|
+
ChromeIcons.draw(canvas, iconPaint, "add", fabCx, fabCy, 30f, Color.WHITE, clamp01(1f - progress * 2f))
|
|
406
|
+
|
|
407
|
+
// Field: search glyph and the text input, both inside the capsule.
|
|
408
|
+
val fieldOpacity = clamp01((progress - 0.4f) / 0.6f)
|
|
409
|
+
val fieldLeft = tabs.x0 + ChromeGeometry.FIELD_SIDE + ChromeGeometry.FIELD_ICON + ChromeGeometry.FIELD_GAP
|
|
410
|
+
val fieldRight = tabs.x1 - ChromeGeometry.FIELD_SIDE
|
|
411
|
+
ChromeIcons.draw(canvas, iconPaint, "search", tabs.x0 + ChromeGeometry.FIELD_SIDE + ChromeGeometry.FIELD_ICON / 2f, centerY, ChromeGeometry.FIELD_ICON, ACCENT_INACTIVE, fieldOpacity)
|
|
412
|
+
// One text line, centred on the bar, so the hint and the typed text sit on the same axis as the glyph.
|
|
413
|
+
placeInput(fieldLeft, centerY - FIELD_LINE / 2f, fieldRight, centerY + FIELD_LINE / 2f, fieldOpacity)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// The text input follows the field geometry; it is hidden when the field is closed.
|
|
417
|
+
private fun placeInput(left: Float, top: Float, right: Float, bottom: Float, opacity: Float) {
|
|
418
|
+
input.layout(
|
|
419
|
+
(left * density).toInt(),
|
|
420
|
+
(top * density).toInt(),
|
|
421
|
+
(right * density).toInt(),
|
|
422
|
+
(bottom * density).toInt(),
|
|
423
|
+
)
|
|
424
|
+
input.alpha = opacity
|
|
425
|
+
input.visibility = if (opacity > 0f) View.VISIBLE else View.INVISIBLE
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private enum class Target { TAB, SEARCH, FAB }
|
|
429
|
+
|
|
430
|
+
private var pressedTarget: Target? = null
|
|
431
|
+
private var pressedIndex = -1
|
|
432
|
+
private var dragging = false
|
|
433
|
+
private var pressedOnPill = false
|
|
434
|
+
private var downX = 0f
|
|
435
|
+
private var downY = 0f
|
|
436
|
+
|
|
437
|
+
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
438
|
+
when (event.actionMasked) {
|
|
439
|
+
MotionEvent.ACTION_DOWN -> {
|
|
440
|
+
val hit = hitTest(event.x / density, event.y / density) ?: return false
|
|
441
|
+
pressedTarget = hit.first
|
|
442
|
+
pressedIndex = hit.second
|
|
443
|
+
dragging = false
|
|
444
|
+
downX = event.x
|
|
445
|
+
downY = event.y
|
|
446
|
+
pressedScrub = when (hit.first) {
|
|
447
|
+
Target.SEARCH -> searchScrub
|
|
448
|
+
Target.FAB -> fabScrub
|
|
449
|
+
Target.TAB -> pillScrub
|
|
450
|
+
}
|
|
451
|
+
pressedScrub?.press(event.x / density, event.y / density, if (hit.first == Target.TAB) hit.second else GlassScrub.NONE)
|
|
452
|
+
// Only a press on the pill can drag it; a press on another tab is a tap.
|
|
453
|
+
pressedOnPill = hit.first == Target.TAB && pressOnPill(event.x / density, event.y / density)
|
|
454
|
+
kick()
|
|
455
|
+
return true
|
|
456
|
+
}
|
|
457
|
+
MotionEvent.ACTION_MOVE -> {
|
|
458
|
+
if (pressedTarget == null) return true
|
|
459
|
+
val dx = event.x - downX
|
|
460
|
+
val dy = event.y - downY
|
|
461
|
+
// A horizontal move from a tab drags the pill; any other move beyond the slop cancels the press.
|
|
462
|
+
// Like the menu's scrub: no start threshold. A press on the pill is dragged by the first move.
|
|
463
|
+
if (!dragging && pressedOnPill) dragging = true
|
|
464
|
+
if (dragging) {
|
|
465
|
+
dragPill(event.x / density, event.y / density)
|
|
466
|
+
} else if (abs(dx) > slop || abs(dy) > slop) {
|
|
467
|
+
pressedTarget = null
|
|
468
|
+
releasePress()
|
|
469
|
+
}
|
|
470
|
+
return true
|
|
471
|
+
}
|
|
472
|
+
MotionEvent.ACTION_UP -> {
|
|
473
|
+
val target = pressedTarget
|
|
474
|
+
val wasDragging = dragging
|
|
475
|
+
pressedTarget = null
|
|
476
|
+
dragging = false
|
|
477
|
+
releasePress()
|
|
478
|
+
if (wasDragging) settlePill() else if (target != null) activate(target, pressedIndex)
|
|
479
|
+
return true
|
|
480
|
+
}
|
|
481
|
+
MotionEvent.ACTION_CANCEL -> {
|
|
482
|
+
val wasDragging = dragging
|
|
483
|
+
pressedTarget = null
|
|
484
|
+
dragging = false
|
|
485
|
+
releasePress()
|
|
486
|
+
if (wasDragging) selectedIndex = selectedIndex
|
|
487
|
+
return true
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return false
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// True when (x, y) in dp is on the pill at its current position.
|
|
494
|
+
private fun pressOnPill(x: Float, y: Float): Boolean {
|
|
495
|
+
if (labels.isEmpty()) return false
|
|
496
|
+
val w = width / density
|
|
497
|
+
val h = height / density
|
|
498
|
+
val tabs = ChromeGeometry.tabBarShapes(w, h, bottomInset, clamp01(searchSpring.value)).first { it.id == "tabs" }
|
|
499
|
+
val itemW = ChromeGeometry.itemWidth(w, labels.size)
|
|
500
|
+
val left = tabs.x0 + ChromeGeometry.PILL_INSET + pillSpring.value * itemW
|
|
501
|
+
return x >= left && x <= left + itemW && y >= tabs.y0 && y <= tabs.y1
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// The pill follows the finger in X, clamped to the first and last tab. The jelly deforms it while it moves.
|
|
505
|
+
private fun dragPill(x: Float, y: Float) {
|
|
506
|
+
if (labels.isEmpty()) return
|
|
507
|
+
val w = width / density
|
|
508
|
+
val h = height / density
|
|
509
|
+
val tabs = ChromeGeometry.tabBarShapes(w, h, bottomInset, clamp01(searchSpring.value)).first { it.id == "tabs" }
|
|
510
|
+
val itemW = ChromeGeometry.itemWidth(w, labels.size)
|
|
511
|
+
val index = (x - tabs.x0 - ChromeGeometry.PILL_INSET - itemW / 2f) / itemW
|
|
512
|
+
val clamped = index.coerceIn(0f, (labels.size - 1).toFloat())
|
|
513
|
+
pillSpring.reset(clamped)
|
|
514
|
+
// The menu's highlight tick: a tab change under the finger (the nearest tab changed).
|
|
515
|
+
val nearest = Math.round(clamped)
|
|
516
|
+
val previous = pillScrub.current
|
|
517
|
+
if (pillScrub.drag(x, y, nearest) && previous != GlassScrub.NONE) GlassFeedback.tick(this)
|
|
518
|
+
kick()
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Release after a drag: the pill settles on the nearest tab with the menu's spring (CollapseSpring, via selectedIndex),
|
|
522
|
+
// and that tab's action fires.
|
|
523
|
+
private fun settlePill() {
|
|
524
|
+
if (labels.isEmpty()) return
|
|
525
|
+
val nearest = Math.round(pillSpring.value).coerceIn(0, labels.size - 1)
|
|
526
|
+
selectedIndex = nearest
|
|
527
|
+
emit("onTabSelect", mapOf("index" to nearest))
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Hit areas in dp, from the current geometry. Tabs are not hit while the search is open (their items are hidden).
|
|
531
|
+
private fun hitTest(x: Float, y: Float): Pair<Target, Int>? {
|
|
532
|
+
val w = width / density
|
|
533
|
+
val h = height / density
|
|
534
|
+
val progress = clamp01(searchSpring.value)
|
|
535
|
+
val shapes = ChromeGeometry.tabBarShapes(w, h, bottomInset, progress)
|
|
536
|
+
val tabs = shapes.first { it.id == "tabs" }
|
|
537
|
+
val search = shapes.first { it.id == "search" }
|
|
538
|
+
val fab = shapes.first { it.id == "fab" }
|
|
539
|
+
if (inside(x, y, search)) return Pair(Target.SEARCH, -1)
|
|
540
|
+
if (inside(x, y, fab)) return Pair(Target.FAB, -1)
|
|
541
|
+
if (progress < 0.5f && labels.isNotEmpty() && inside(x, y, tabs)) {
|
|
542
|
+
val itemW = ChromeGeometry.itemWidth(w, labels.size)
|
|
543
|
+
val index = ((x - tabs.x0 - ChromeGeometry.PILL_INSET) / itemW).toInt()
|
|
544
|
+
if (index in labels.indices) return Pair(Target.TAB, index)
|
|
545
|
+
}
|
|
546
|
+
return null
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
private fun inside(x: Float, y: Float, s: ChromeShape): Boolean = x >= s.x0 && x <= s.x1 && y >= s.y0 && y <= s.y1
|
|
550
|
+
|
|
551
|
+
private fun activate(target: Target, index: Int) {
|
|
552
|
+
when (target) {
|
|
553
|
+
Target.TAB -> {
|
|
554
|
+
selectedIndex = index
|
|
555
|
+
emit("onTabSelect", mapOf("index" to index))
|
|
556
|
+
}
|
|
557
|
+
Target.SEARCH -> toggleSearch()
|
|
558
|
+
Target.FAB -> emit("onCreate", emptyMap())
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
private fun toggleSearch() {
|
|
563
|
+
searchOpen = !searchOpen
|
|
564
|
+
searchSpring.target(if (searchOpen) 1f else 0f, SEARCH_SPEC)
|
|
565
|
+
if (searchOpen) {
|
|
566
|
+
input.requestFocus()
|
|
567
|
+
context.getSystemService(InputMethodManager::class.java)?.showSoftInput(input, 0)
|
|
568
|
+
} else {
|
|
569
|
+
input.clearFocus()
|
|
570
|
+
context.getSystemService(InputMethodManager::class.java)?.hideSoftInputFromWindow(windowToken, 0)
|
|
571
|
+
}
|
|
572
|
+
kick()
|
|
573
|
+
emit("onSearchChange", mapOf("open" to searchOpen))
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
private fun releasePress() {
|
|
577
|
+
pressedScrub?.release()
|
|
578
|
+
pressedScrub = null
|
|
579
|
+
kick()
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
private fun clamp01(value: Float): Float = value.coerceIn(0f, 1f)
|
|
583
|
+
|
|
584
|
+
// Linear interpolation of two colours, channel by channel (no animation of its own: t comes from the pill).
|
|
585
|
+
private fun lerpColor(from: Int, to: Int, t: Float): Int {
|
|
586
|
+
fun channel(a: Int, b: Int): Int = Math.round(a + (b - a) * t)
|
|
587
|
+
return Color.argb(
|
|
588
|
+
channel(Color.alpha(from), Color.alpha(to)),
|
|
589
|
+
channel(Color.red(from), Color.red(to)),
|
|
590
|
+
channel(Color.green(from), Color.green(to)),
|
|
591
|
+
channel(Color.blue(from), Color.blue(to)),
|
|
592
|
+
)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
companion object {
|
|
596
|
+
private const val TAG = "GlassChrome"
|
|
597
|
+
// Same value as the menu's GlassMenuAndroidView.FieldStep (its companion is private).
|
|
598
|
+
private const val FIELD_STEP = 4f
|
|
599
|
+
private const val PILL_CAPTURE_MARGIN = 12f
|
|
600
|
+
private const val FIELD_LINE = 28f
|
|
601
|
+
// The menu's own specs (one motion core): EjectSpring starts the morph, CollapseSpring moves the pill.
|
|
602
|
+
private val SEARCH_SPEC = GlassMotion.EjectSpring
|
|
603
|
+
private val PILL_SPEC = GlassMotion.CollapseSpring
|
|
604
|
+
private val ACCENT = 0xFF0A84FF.toInt()
|
|
605
|
+
private val ACCENT_INACTIVE = 0xFFA1A1A6.toInt()
|
|
606
|
+
// Inactive tab labels and icons: white, as in Apple's tab bar. The search field keeps ACCENT_INACTIVE.
|
|
607
|
+
private val TAB_INACTIVE = 0xFFFFFFFF.toInt()
|
|
608
|
+
}
|
|
609
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.chrome
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.ColorSpace
|
|
6
|
+
import android.graphics.PixelFormat
|
|
7
|
+
import android.graphics.PorterDuff
|
|
8
|
+
import android.hardware.HardwareBuffer
|
|
9
|
+
import android.media.ImageReader
|
|
10
|
+
import android.os.Build
|
|
11
|
+
|
|
12
|
+
// A rasterized copy of the static glass of the chrome (the bar container and the create circle), in a hardware buffer.
|
|
13
|
+
// While the pill is dragged the static glass is drawn from this texture instead of being recorded every frame: the
|
|
14
|
+
// glass keeps its material (the texture is the output of the same GlassRenderer draw), and only the pill is live.
|
|
15
|
+
// It is rendered again only when its key changes (size, backdrop version, search progress, inset): never per frame.
|
|
16
|
+
internal class StaticGlassCache {
|
|
17
|
+
private var reader: ImageReader? = null
|
|
18
|
+
private var image: android.media.Image? = null
|
|
19
|
+
private var textureBitmap: Bitmap? = null
|
|
20
|
+
val bitmap: Bitmap? get() = textureBitmap
|
|
21
|
+
private var width = 0
|
|
22
|
+
private var height = 0
|
|
23
|
+
var key: String? = null
|
|
24
|
+
private set
|
|
25
|
+
|
|
26
|
+
val isSupported: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
|
27
|
+
|
|
28
|
+
// Renders [draw] into a hardware buffer of width x height px. Returns the wrapped bitmap, or null if unsupported.
|
|
29
|
+
fun render(newKey: String, w: Int, h: Int, draw: (Canvas) -> Unit): Bitmap? {
|
|
30
|
+
if (!isSupported || w <= 0 || h <= 0) return null
|
|
31
|
+
if (w != width || h != height || reader == null) {
|
|
32
|
+
release()
|
|
33
|
+
reader = ImageReader.newInstance(
|
|
34
|
+
w, h, PixelFormat.RGBA_8888, 2,
|
|
35
|
+
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE or HardwareBuffer.USAGE_GPU_COLOR_OUTPUT,
|
|
36
|
+
)
|
|
37
|
+
width = w
|
|
38
|
+
height = h
|
|
39
|
+
}
|
|
40
|
+
val surface = reader?.surface ?: return null
|
|
41
|
+
val canvas = surface.lockHardwareCanvas() ?: return null
|
|
42
|
+
try {
|
|
43
|
+
canvas.drawColor(0, PorterDuff.Mode.CLEAR)
|
|
44
|
+
draw(canvas)
|
|
45
|
+
} finally {
|
|
46
|
+
surface.unlockCanvasAndPost(canvas)
|
|
47
|
+
}
|
|
48
|
+
val next = reader?.acquireLatestImage() ?: return bitmap
|
|
49
|
+
val buffer = next.hardwareBuffer
|
|
50
|
+
if (buffer == null) {
|
|
51
|
+
next.close()
|
|
52
|
+
return textureBitmap
|
|
53
|
+
}
|
|
54
|
+
val wrapped = Bitmap.wrapHardwareBuffer(buffer, ColorSpace.get(ColorSpace.Named.SRGB))
|
|
55
|
+
buffer.close()
|
|
56
|
+
image?.close()
|
|
57
|
+
image = next
|
|
58
|
+
textureBitmap = wrapped
|
|
59
|
+
key = newKey
|
|
60
|
+
return wrapped
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fun release() {
|
|
64
|
+
textureBitmap = null
|
|
65
|
+
image?.close()
|
|
66
|
+
image = null
|
|
67
|
+
reader?.close()
|
|
68
|
+
reader = null
|
|
69
|
+
width = 0
|
|
70
|
+
height = 0
|
|
71
|
+
key = null
|
|
72
|
+
}
|
|
73
|
+
}
|