Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:resizeableActivity="true"
android:usesCleartextTraffic="false">
<meta-data android:name="android.supports_size_changes" android:value="true"/>
<meta-data android:name="miui.supportAppContinuity" android:value="true"/>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ class MainActivity : FlutterActivity() {
private val mainHandler = Handler(Looper.getMainLooper())
private var ecardWidgets: EcardWidgetBridge? = null
private var ecardFeedback: EcardFeedback? = null
private var screenFormFactor: ScreenFormFactorBridge? = null

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
ecardWidgets = EcardWidgetBridge(this, flutterEngine.dartExecutor.binaryMessenger).also {
it.capture(intent, notifyFlutter = false)
}
ecardFeedback = EcardFeedback(this, flutterEngine.dartExecutor.binaryMessenger)
screenFormFactor = ScreenFormFactorBridge(this, flutterEngine.dartExecutor.binaryMessenger)

MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
Expand Down Expand Up @@ -82,6 +84,8 @@ class MainActivity : FlutterActivity() {
ecardWidgets = null
ecardFeedback?.dispose()
ecardFeedback = null
screenFormFactor?.dispose()
screenFormFactor = null
super.cleanUpFlutterEngine(flutterEngine)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package club.geekpie.techpie

import android.app.Activity
import android.os.Build
import android.view.Display
import android.view.WindowManager
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

/**
* Reports the form factor of the screen this activity is currently on.
*
* Xiaomi exposes no public rear-screen API; the official Flip guidance is to
* detect the device family through `MiuiMultiDisplayTypeInfo` and to react to
* the window size for fold continuity. The rear screen is the secondary
* display, so its id is the only reliable signal that the app is running there.
*/
class ScreenFormFactorBridge(
private val activity: Activity,
messenger: BinaryMessenger,
) : MethodChannel.MethodCallHandler {
private val channel = MethodChannel(messenger, CHANNEL)

init {
channel.setMethodCallHandler(this)
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
"info" -> result.success(info())
else -> result.notImplemented()
}
}

fun dispose() {
channel.setMethodCallHandler(null)
}

private fun info(): Map<String, Any?> {
val display = currentDisplay()
val displayId = display?.displayId ?: Display.DEFAULT_DISPLAY
val metrics = activity.resources.displayMetrics
val bounds = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.windowManager.currentWindowMetrics.bounds
} else {
android.graphics.Rect(0, 0, metrics.widthPixels, metrics.heightPixels)
}
return mapOf(
"isFlipDevice" to miuiFlag("isFlipDevice"),
"isRearDevice" to miuiFlag("isRearDevice"),
"displayId" to displayId,
"windowWidthPx" to bounds.width(),
"windowHeightPx" to bounds.height(),
"density" to metrics.density.toDouble(),
"densityDpi" to metrics.densityDpi,
"isDefaultDisplay" to (displayId == Display.DEFAULT_DISPLAY),
"isInMultiWindowMode" to activity.isInMultiWindowMode,
"model" to Build.MODEL,
"manufacturer" to Build.MANUFACTURER,
"sdkInt" to Build.VERSION.SDK_INT,
)
}

private fun currentDisplay(): Display? =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.display
} else {
@Suppress("DEPRECATION")
activity.windowManager.defaultDisplay
}

/**
* The class is absent on most devices and hidden on some HyperOS builds;
* a failed probe simply means "not this form factor", never a crash.
*/
private fun miuiFlag(method: String): Boolean = try {
val type = Class.forName("miui.util.MiuiMultiDisplayTypeInfo")
type.getMethod(method).invoke(null) as? Boolean ?: false
} catch (_: ReflectiveOperationException) {
false
} catch (_: SecurityException) {
false
} catch (_: LinkageError) {
false
}

private companion object {
const val CHANNEL = "techpie/screen_form_factor"
}
}
7 changes: 7 additions & 0 deletions docs/cover-rear-glance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Cover and rear display glance

On compatible Android displays the app shows a compact course/deadline/online-payment surface. Settings configure sections and offer previews. Display classification excludes unfolded landscape windows. The main navigator stays mounted across fold/unfold, and shortcuts are consumed by the visible surface. Policy acceptance gates personal data on both surfaces; the glance never changes main-display brightness.

The implementation retains upstream iOS tab stacks, online Apple Watch support, dependency pins, release version, signing and update channel. It does not add a display permission on other platforms. Offline payment remains in the full campus-card UI; previews and source checks do not verify camera scanning on every physical rear screen.

Regression coverage includes classification, compact layouts, privacy, foreground/payment lifecycle and shortcut routing. Actual vendor display routing, folding and QR scans still require compatible hardware.
10 changes: 10 additions & 0 deletions lib/features/campus_card/core/config/payment_code_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ final maximizePaymentCodeBrightnessProvider =

final class MaximizePaymentCodeBrightnessController
extends AsyncNotifier<bool> {
MaximizePaymentCodeBrightnessController() : _fixed = null;

/// A controller that ignores the stored preference, for surfaces that must
/// never touch the main display's brightness.
MaximizePaymentCodeBrightnessController.fixed(bool value) : _fixed = value;

static const _key = 'geekpay.maximize_payment_code_brightness';

final bool? _fixed;

@override
Future<bool> build() async {
final fixed = _fixed;
if (fixed != null) return fixed;
final preferences = await SharedPreferences.getInstance();
return preferences.getBool(_key) ?? false;
}
Expand Down
174 changes: 174 additions & 0 deletions lib/features/campus_card/presentation/widgets/payment_code_qr.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../theme/tokens.dart';

/// The campus payment QR, shared by the full pass and the glance surface.
///
/// [qrKey] defaults to the key the full pass has always exposed; the glance
/// passes its own key so a test can tell the two surfaces apart.
final class PaymentCodeQr extends StatefulWidget {
const PaymentCodeQr({
super.key,
required this.payload,
required this.binaryPayload,
required this.size,
required this.onTap,
this.qrKey = const Key('payment-code-qr'),
});

final String payload;
final bool binaryPayload;
final double size;
final VoidCallback onTap;
final Key qrKey;

@override
State<PaymentCodeQr> createState() => _PaymentCodeQrState();
}

class _PaymentCodeQrState extends State<PaymentCodeQr> {
late Widget _image;

@override
void initState() {
super.initState();
_image = _createImage();
}

@override
void didUpdateWidget(PaymentCodeQr oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.payload != widget.payload ||
oldWidget.binaryPayload != widget.binaryPayload) {
_image = _createImage();
}
}

Widget _createImage() => widget.binaryPayload
? QrImageView.withQr(
qr: QrCode.fromUint8List(
data: Uint8List.fromList(latin1.encode(widget.payload)),
errorCorrectLevel: QrErrorCorrectLevel.L,
),
padding: EdgeInsets.zero,
eyeStyle: const QrEyeStyle(
eyeShape: QrEyeShape.square,
color: GpTokens.campusRed,
),
dataModuleStyle: const QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square,
color: GpTokens.campusRed,
),
backgroundColor: GpTokens.cardCanvas,
)
: QrImageView(
data: widget.payload,
version: QrVersions.auto,
padding: EdgeInsets.zero,
eyeStyle: const QrEyeStyle(
eyeShape: QrEyeShape.square,
color: GpTokens.campusRed,
),
dataModuleStyle: const QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square,
color: GpTokens.campusRed,
),
backgroundColor: GpTokens.cardCanvas,
);

@override
Widget build(BuildContext context) {
return Semantics(
button: true,
label: '轻触二维码刷新',
child: GestureDetector(
onTap: widget.onTap,
child: Container(
key: widget.qrKey,
width: widget.size,
height: widget.size,
color: GpTokens.cardCanvas,
padding: EdgeInsets.all(widget.size * 0.035),
child: _image,
),
),
);
}
}

/// Thirty-second countdown shown under an online code.
final class PaymentCodeCountdown extends StatefulWidget {
const PaymentCodeCountdown({
super.key,
required this.generation,
required this.active,
required this.style,
this.seconds = 30,
});

final int generation;
final bool active;
final TextStyle style;
final int seconds;

@override
State<PaymentCodeCountdown> createState() => _PaymentCodeCountdownState();
}

class _PaymentCodeCountdownState extends State<PaymentCodeCountdown> {
Timer? _timer;
late int _remaining;

@override
void initState() {
super.initState();
_remaining = widget.seconds;
_startTimer();
}

@override
void didUpdateWidget(PaymentCodeCountdown oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.generation != widget.generation ||
oldWidget.seconds != widget.seconds) {
_remaining = widget.seconds;
_startTimer();
} else if (oldWidget.active != widget.active) {
_startTimer();
}
}

void _startTimer() {
_timer?.cancel();
if (!widget.active || _remaining <= 1) return;
final initial = _remaining;
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
final next = (initial - timer.tick).clamp(1, widget.seconds);
setState(() => _remaining = next);
if (_remaining == 1) timer.cancel();
});
}

@override
void dispose() {
_timer?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) => SizedBox(
width: double.infinity,
child: RepaintBoundary(
child: Text(
'$_remaining秒后刷新',
textAlign: TextAlign.center,
style: widget.style,
),
),
);
}
Loading
Loading