#400 accessibility: apply bold font system setting
This commit is contained in:
parent
eaa335919d
commit
126059ee48
4 changed files with 73 additions and 24 deletions
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## <a id="unreleased"></a>[Unreleased]
|
## <a id="unreleased"></a>[Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Accessibility: apply bold font system setting
|
||||||
|
|
||||||
## <a id="v1.7.4"></a>[v1.7.4] - 2022-11-11
|
## <a id="v1.7.4"></a>[v1.7.4] - 2022-11-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -3,6 +3,7 @@ package deckers.thibault.aves.channel.calls
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -19,6 +20,7 @@ class AccessibilityHandler(private val contextWrapper: ContextWrapper) : MethodC
|
||||||
"areAnimationsRemoved" -> safe(call, result, ::areAnimationsRemoved)
|
"areAnimationsRemoved" -> safe(call, result, ::areAnimationsRemoved)
|
||||||
"hasRecommendedTimeouts" -> safe(call, result, ::hasRecommendedTimeouts)
|
"hasRecommendedTimeouts" -> safe(call, result, ::hasRecommendedTimeouts)
|
||||||
"getRecommendedTimeoutMillis" -> safe(call, result, ::getRecommendedTimeoutMillis)
|
"getRecommendedTimeoutMillis" -> safe(call, result, ::getRecommendedTimeoutMillis)
|
||||||
|
"shouldUseBoldFont" -> safe(call, result, ::shouldUseBoldFont)
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +78,28 @@ class AccessibilityHandler(private val contextWrapper: ContextWrapper) : MethodC
|
||||||
result.success(millis)
|
result.success(millis)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flutter v3.4 already checks the system `Configuration.fontWeightAdjustment` to update `MediaQuery`
|
||||||
|
// but we need to also check the non-standard Samsung field `bf` representing the bold font toggle
|
||||||
|
private fun shouldUseBoldFont(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
|
||||||
|
var shouldBold = false
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
val config = contextWrapper.resources.configuration
|
||||||
|
val fontWeightAdjustment = config.fontWeightAdjustment
|
||||||
|
shouldBold = if (fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED && fontWeightAdjustment != 0) {
|
||||||
|
fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT
|
||||||
|
} else {
|
||||||
|
// fallback to Samsung non-standard field
|
||||||
|
Regex(" bf=([01]) ").find(config.toString())?.groups?.get(1)?.value == "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.success(shouldBold)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val LOG_TAG = LogUtils.createTag<AccessibilityHandler>()
|
private val LOG_TAG = LogUtils.createTag<AccessibilityHandler>()
|
||||||
const val CHANNEL = "deckers.thibault/aves/accessibility"
|
const val CHANNEL = "deckers.thibault/aves/accessibility"
|
||||||
|
|
||||||
|
// match Flutter way: https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/view/AccessibilityBridge.java#L125
|
||||||
|
const val BOLD_TEXT_WEIGHT_ADJUSTMENT = 300
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,16 @@ import 'package:flutter/services.dart';
|
||||||
class AccessibilityService {
|
class AccessibilityService {
|
||||||
static const _platform = MethodChannel('deckers.thibault/aves/accessibility');
|
static const _platform = MethodChannel('deckers.thibault/aves/accessibility');
|
||||||
|
|
||||||
|
static Future<bool> shouldUseBoldFont() async {
|
||||||
|
try {
|
||||||
|
final result = await _platform.invokeMethod('shouldUseBoldFont');
|
||||||
|
if (result != null) return result as bool;
|
||||||
|
} on PlatformException catch (e, stack) {
|
||||||
|
await reportService.recordError(e, stack);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool> areAnimationsRemoved() async {
|
static Future<bool> areAnimationsRemoved() async {
|
||||||
try {
|
try {
|
||||||
final result = await _platform.invokeMethod('areAnimationsRemoved');
|
final result = await _platform.invokeMethod('areAnimationsRemoved');
|
||||||
|
|
|
@ -108,6 +108,7 @@ class AvesApp extends StatefulWidget {
|
||||||
class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
final ValueNotifier<AppMode> appModeNotifier = ValueNotifier(AppMode.main);
|
final ValueNotifier<AppMode> appModeNotifier = ValueNotifier(AppMode.main);
|
||||||
late final Future<void> _appSetup;
|
late final Future<void> _appSetup;
|
||||||
|
late final Future<bool> _shouldUseBoldFontLoader;
|
||||||
late final Future<CorePalette?> _dynamicColorPaletteLoader;
|
late final Future<CorePalette?> _dynamicColorPaletteLoader;
|
||||||
final CollectionSource _mediaStoreSource = MediaStoreSource();
|
final CollectionSource _mediaStoreSource = MediaStoreSource();
|
||||||
final Debouncer _mediaStoreChangeDebouncer = Debouncer(delay: Durations.mediaContentChangeDebounceDelay);
|
final Debouncer _mediaStoreChangeDebouncer = Debouncer(delay: Durations.mediaContentChangeDebounceDelay);
|
||||||
|
@ -129,6 +130,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
_appSetup = _setup();
|
_appSetup = _setup();
|
||||||
// remember screen size to use it later, when `context` and `window` are no longer reliable
|
// remember screen size to use it later, when `context` and `window` are no longer reliable
|
||||||
_screenSize = _getScreenSize();
|
_screenSize = _getScreenSize();
|
||||||
|
_shouldUseBoldFontLoader = AccessibilityService.shouldUseBoldFont();
|
||||||
_dynamicColorPaletteLoader = DynamicColorPlugin.getCorePalette();
|
_dynamicColorPaletteLoader = DynamicColorPlugin.getCorePalette();
|
||||||
_mediaStoreChangeChannel.receiveBroadcastStream().listen((event) => _onMediaStoreChange(event as String?));
|
_mediaStoreChangeChannel.receiveBroadcastStream().listen((event) => _onMediaStoreChange(event as String?));
|
||||||
_newIntentChannel.receiveBroadcastStream().listen((event) => _onNewIntent(event as Map?));
|
_newIntentChannel.receiveBroadcastStream().listen((event) => _onNewIntent(event as Map?));
|
||||||
|
@ -205,32 +207,43 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
lightAccent = Color(tonalPalette?.get(60) ?? defaultAccent.value);
|
lightAccent = Color(tonalPalette?.get(60) ?? defaultAccent.value);
|
||||||
darkAccent = Color(tonalPalette?.get(70) ?? defaultAccent.value);
|
darkAccent = Color(tonalPalette?.get(70) ?? defaultAccent.value);
|
||||||
}
|
}
|
||||||
return MaterialApp(
|
return FutureBuilder<bool>(
|
||||||
navigatorKey: AvesApp.navigatorKey,
|
future: _shouldUseBoldFontLoader,
|
||||||
home: home,
|
builder: (context, snapshot) {
|
||||||
navigatorObservers: _navigatorObservers,
|
// Flutter v3.4 already checks the system `Configuration.fontWeightAdjustment` to update `MediaQuery`
|
||||||
builder: (context, child) {
|
// but we need to also check the non-standard Samsung field `bf` representing the bold font toggle
|
||||||
if (initialized) {
|
final shouldUseBoldFont = snapshot.data ?? false;
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => AvesApp.setSystemUIStyle(context));
|
return MaterialApp(
|
||||||
}
|
navigatorKey: AvesApp.navigatorKey,
|
||||||
return AvesColorsProvider(
|
home: home,
|
||||||
child: Theme(
|
navigatorObservers: _navigatorObservers,
|
||||||
data: Theme.of(context).copyWith(
|
builder: (context, child) {
|
||||||
pageTransitionsTheme: pageTransitionsTheme,
|
if (initialized) {
|
||||||
),
|
WidgetsBinding.instance.addPostFrameCallback((_) => AvesApp.setSystemUIStyle(context));
|
||||||
child: child!,
|
}
|
||||||
),
|
return MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(boldText: shouldUseBoldFont),
|
||||||
|
child: AvesColorsProvider(
|
||||||
|
child: Theme(
|
||||||
|
data: Theme.of(context).copyWith(
|
||||||
|
pageTransitionsTheme: pageTransitionsTheme,
|
||||||
|
),
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onGenerateTitle: (context) => context.l10n.appName,
|
||||||
|
theme: Themes.lightTheme(lightAccent, initialized),
|
||||||
|
darkTheme: themeBrightness == AvesThemeBrightness.black ? Themes.blackTheme(darkAccent, initialized) : Themes.darkTheme(darkAccent, initialized),
|
||||||
|
themeMode: themeBrightness.appThemeMode,
|
||||||
|
locale: settingsLocale,
|
||||||
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
|
supportedLocales: AvesApp.supportedLocales,
|
||||||
|
// TODO TLAD remove custom scroll behavior when this is fixed: https://github.com/flutter/flutter/issues/82906
|
||||||
|
scrollBehavior: StretchMaterialScrollBehavior(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onGenerateTitle: (context) => context.l10n.appName,
|
|
||||||
theme: Themes.lightTheme(lightAccent, initialized),
|
|
||||||
darkTheme: themeBrightness == AvesThemeBrightness.black ? Themes.blackTheme(darkAccent, initialized) : Themes.darkTheme(darkAccent, initialized),
|
|
||||||
themeMode: themeBrightness.appThemeMode,
|
|
||||||
locale: settingsLocale,
|
|
||||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
||||||
supportedLocales: AvesApp.supportedLocales,
|
|
||||||
// TODO TLAD remove custom scroll behavior when this is fixed: https://github.com/flutter/flutter/issues/82906
|
|
||||||
scrollBehavior: StretchMaterialScrollBehavior(),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue