This commit is contained in:
Thibault Deckers 2025-02-14 00:01:46 +01:00
parent 79840b098f
commit 983f50a814
9 changed files with 38 additions and 6 deletions

View file

@ -15,6 +15,7 @@ import android.os.Looper
import android.util.Log
import android.util.SizeF
import android.widget.RemoteViews
import androidx.core.graphics.createBitmap
import androidx.core.net.toUri
import app.loup.streams_channel.StreamsChannel
import deckers.thibault.aves.channel.AvesByteSendingMethodCodec
@ -218,7 +219,7 @@ class HomeWidgetProvider : AppWidgetProvider() {
val heightPx = (sizeDip.height * devicePixelRatio).roundToInt()
try {
val bitmap = Bitmap.createBitmap(widthPx, heightPx, Bitmap.Config.ARGB_8888).also {
val bitmap = createBitmap(widthPx, heightPx, Bitmap.Config.ARGB_8888).also {
bitmaps.add(it)
it.copyPixelsFromBuffer(ByteBuffer.wrap(bytes))
}

View file

@ -6,6 +6,7 @@ import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.RectF
import android.net.Uri
import androidx.core.graphics.createBitmap
import com.caverock.androidsvg.PreserveAspectRatio
import com.caverock.androidsvg.RenderOptions
import com.caverock.androidsvg.SVG
@ -100,7 +101,7 @@ class SvgRegionFetcher internal constructor(
return
}
var bitmap = Bitmap.createBitmap(
var bitmap = createBitmap(
targetBitmapWidth + bleedX * 2,
targetBitmapHeight + bleedY * 2,
Bitmap.Config.ARGB_8888

View file

@ -77,8 +77,12 @@ class ActivityWindowHandler(private val activity: Activity) : WindowHandler(acti
)
}
override fun supportsWideGamut(call: MethodCall, result: MethodChannel.Result) {
result.success(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.resources.configuration.isScreenWideColorGamut)
}
override fun supportsHdr(call: MethodCall, result: MethodChannel.Result) {
result.success(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.getDisplayCompat()?.isHdr ?: false)
result.success(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.resources.configuration.isScreenHdr)
}
override fun setHdrColorMode(call: MethodCall, result: MethodChannel.Result) {

View file

@ -29,6 +29,10 @@ class ServiceWindowHandler(service: Service) : WindowHandler(service) {
result.success(HashMap<String, Any>())
}
override fun supportsWideGamut(call: MethodCall, result: MethodChannel.Result) {
result.success(false)
}
override fun supportsHdr(call: MethodCall, result: MethodChannel.Result) {
result.success(false)
}

View file

@ -18,6 +18,7 @@ abstract class WindowHandler(private val contextWrapper: ContextWrapper) : Metho
"requestOrientation" -> Coresult.safe(call, result, ::requestOrientation)
"isCutoutAware" -> Coresult.safe(call, result, ::isCutoutAware)
"getCutoutInsets" -> Coresult.safe(call, result, ::getCutoutInsets)
"supportsWideGamut" -> Coresult.safe(call, result, ::supportsWideGamut)
"supportsHdr" -> Coresult.safe(call, result, ::supportsHdr)
"setHdrColorMode" -> Coresult.safe(call, result, ::setHdrColorMode)
else -> result.notImplemented()
@ -46,6 +47,8 @@ abstract class WindowHandler(private val contextWrapper: ContextWrapper) : Metho
abstract fun getCutoutInsets(call: MethodCall, result: MethodChannel.Result)
abstract fun supportsWideGamut(call: MethodCall, result: MethodChannel.Result)
abstract fun supportsHdr(call: MethodCall, result: MethodChannel.Result)
abstract fun setHdrColorMode(call: MethodCall, result: MethodChannel.Result)

View file

@ -22,6 +22,7 @@ import deckers.thibault.aves.metadata.SVGParserBufferedInputStream
import deckers.thibault.aves.metadata.SvgHelper.normalizeSize
import deckers.thibault.aves.utils.StorageUtils
import kotlin.math.ceil
import androidx.core.graphics.createBitmap
@GlideModule
class SvgGlideModule : LibraryGlideModule() {
@ -68,7 +69,7 @@ internal class SvgFetcher(val model: SvgImage, val width: Int, val height: Int)
bitmapWidth = width
bitmapHeight = ceil(svgHeight * width / svgWidth).toInt()
}
val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888)
val bitmap = createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
svg.renderToCanvas(canvas)

View file

@ -18,6 +18,8 @@ abstract class WindowService {
Future<EdgeInsets> getCutoutInsets();
Future<bool> supportsWideGamut();
Future<bool> supportsHdr();
Future<void> setHdrColorMode(bool on);
@ -26,7 +28,7 @@ abstract class WindowService {
class PlatformWindowService implements WindowService {
static const _platform = MethodChannel('deckers.thibault/aves/window');
bool? _isCutoutAware, _supportsHdr;
bool? _isCutoutAware, _supportsHdr, _supportsWideGamut;
@override
Future<bool> isActivity() async {
@ -126,6 +128,18 @@ class PlatformWindowService implements WindowService {
return EdgeInsets.zero;
}
@override
Future<bool> supportsWideGamut() async {
if (_supportsWideGamut != null) return SynchronousFuture(_supportsWideGamut!);
try {
final result = await _platform.invokeMethod('supportsWideGamut');
_supportsWideGamut = result as bool?;
} on PlatformException catch (e, stack) {
await reportService.recordError(e, stack);
}
return _supportsWideGamut ?? false;
}
@override
Future<bool> supportsHdr() async {
if (_supportsHdr != null) return SynchronousFuture(_supportsHdr!);

View file

@ -157,6 +157,7 @@ class _BugReportState extends State<BugReport> with FeedbackMixin {
final mediaQuery = MediaQuery.of(context);
final view = View.of(context);
final supportsHdr = await windowService.supportsHdr();
final supportsWideGamut = await windowService.supportsWideGamut();
final connections = await Connectivity().checkConnectivity();
final storageVolumes = await storageService.getStorageVolumes();
final storageGrants = await storageService.getGrantedDirectories();
@ -169,7 +170,7 @@ class _BugReportState extends State<BugReport> with FeedbackMixin {
'Android build: ${androidInfo.display}',
'Device: ${androidInfo.manufacturer} ${androidInfo.model}',
'Display: pixel ratio=${view.devicePixelRatio}, logical=${mediaQuery.size.width}x${mediaQuery.size.height}, physical=${view.physicalSize.width}x${view.physicalSize.height}',
'Support: dynamic colors=${device.isDynamicColorAvailable}, geocoder=${device.hasGeocoder}, HDR=$supportsHdr',
'Support: dynamic colors=${device.isDynamicColorAvailable}, geocoder=${device.hasGeocoder}, HDR=$supportsHdr, wide gamut=$supportsWideGamut',
'Mobile services: ${mobileServices.isServiceAvailable ? 'ready' : 'not available'}',
'Connectivity: ${connections.map((v) => v.name).join(', ')}',
'System locales: ${WidgetsBinding.instance.platformDispatcher.locales.join(', ')}',

View file

@ -27,6 +27,7 @@ class _DebugCapabilitiesSectionState extends State<DebugCapabilitiesSection> wit
windowService.isCutoutAware(),
windowService.isRotationLocked(),
windowService.supportsHdr(),
windowService.supportsWideGamut(),
]);
}
@ -72,6 +73,7 @@ class _DebugCapabilitiesSectionState extends State<DebugCapabilitiesSection> wit
bool isCutoutAware,
bool isRotationLocked,
bool supportsHdr,
bool supportsWideGamut,
] = data;
return Padding(
@ -85,6 +87,7 @@ class _DebugCapabilitiesSectionState extends State<DebugCapabilitiesSection> wit
'isCutoutAware': '$isCutoutAware',
'isRotationLocked': '$isRotationLocked',
'supportsHdr': '$supportsHdr',
'supportsWideGamut': '$supportsWideGamut',
},
),
],