mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 13:26:43 +02:00
Move to fonts plugin
This commit is contained in:
@ -1,44 +0,0 @@
|
|||||||
package dev.imranr.obtainium
|
|
||||||
|
|
||||||
import android.util.Xml
|
|
||||||
import org.xmlpull.v1.XmlPullParser
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileInputStream
|
|
||||||
|
|
||||||
class DefaultSystemFont {
|
|
||||||
fun get(): String {
|
|
||||||
return try {
|
|
||||||
val file = File("/system/etc/fonts.xml")
|
|
||||||
val fileStream = FileInputStream(file)
|
|
||||||
parseFontsFileStream(fileStream)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.message ?: "Unknown fonts.xml parsing exception"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseFontsFileStream(fileStream: FileInputStream): String {
|
|
||||||
fileStream.use { stream ->
|
|
||||||
val parser = Xml.newPullParser()
|
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
|
|
||||||
parser.setInput(stream, null)
|
|
||||||
parser.nextTag()
|
|
||||||
return parseFonts(parser)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseFonts(parser: XmlPullParser): String {
|
|
||||||
while (!((parser.next() == XmlPullParser.END_TAG) && (parser.name == "family"))) {
|
|
||||||
if ((parser.eventType == XmlPullParser.START_TAG) && (parser.name == "font")
|
|
||||||
&& (parser.getAttributeValue(null, "style") == "normal")
|
|
||||||
&& (parser.getAttributeValue(null, "weight") == "400")) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parser.next()
|
|
||||||
val fontFile = parser.text.trim()
|
|
||||||
if (fontFile == "") {
|
|
||||||
throw NoSuchFieldException("The font filename couldn't be found in fonts.xml")
|
|
||||||
}
|
|
||||||
return "/system/fonts/$fontFile"
|
|
||||||
}
|
|
||||||
}
|
|
@ -140,10 +140,7 @@ class MainActivity: FlutterActivity() {
|
|||||||
flutterEngine.dartExecutor.binaryMessenger, "native")
|
flutterEngine.dartExecutor.binaryMessenger, "native")
|
||||||
nativeChannel!!.setMethodCallHandler {
|
nativeChannel!!.setMethodCallHandler {
|
||||||
call, result ->
|
call, result ->
|
||||||
if (call.method == "getSystemFont") {
|
if (call.method == "checkPermissionShizuku") {
|
||||||
val res = DefaultSystemFont().get()
|
|
||||||
result.success(res)
|
|
||||||
} else if (call.method == "checkPermissionShizuku") {
|
|
||||||
shizukuCheckPermission(result)
|
shizukuCheckPermission(result)
|
||||||
} else if (call.method == "installWithShizuku") {
|
} else if (call.method == "installWithShizuku") {
|
||||||
val apkFileUri: String = call.argument("apkFileUri")!!
|
val apkFileUri: String = call.argument("apkFileUri")!!
|
||||||
|
@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:obtainium/pages/home.dart';
|
import 'package:obtainium/pages/home.dart';
|
||||||
import 'package:obtainium/providers/apps_provider.dart';
|
import 'package:obtainium/providers/apps_provider.dart';
|
||||||
import 'package:obtainium/providers/logs_provider.dart';
|
import 'package:obtainium/providers/logs_provider.dart';
|
||||||
|
import 'package:obtainium/providers/native_provider.dart';
|
||||||
import 'package:obtainium/providers/notifications_provider.dart';
|
import 'package:obtainium/providers/notifications_provider.dart';
|
||||||
import 'package:obtainium/providers/settings_provider.dart';
|
import 'package:obtainium/providers/settings_provider.dart';
|
||||||
import 'package:obtainium/providers/source_provider.dart';
|
import 'package:obtainium/providers/source_provider.dart';
|
||||||
@ -231,6 +232,8 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
.harmonized();
|
.harmonized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settingsProvider.useSystemFont) NativeFeatures.loadSystemFont();
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Obtainium',
|
title: 'Obtainium',
|
||||||
localizationsDelegates: context.localizationDelegates,
|
localizationsDelegates: context.localizationDelegates,
|
||||||
|
@ -469,17 +469,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
onChanged: (useSystemFont) {
|
onChanged: (useSystemFont) {
|
||||||
if (useSystemFont) {
|
if (useSystemFont) {
|
||||||
NativeFeatures.loadSystemFont()
|
NativeFeatures.loadSystemFont()
|
||||||
.then((fontLoadRes) {
|
.then((val) {
|
||||||
if (fontLoadRes == 'ok') {
|
settingsProvider.useSystemFont = true;
|
||||||
settingsProvider.useSystemFont =
|
|
||||||
true;
|
|
||||||
} else {
|
|
||||||
showError(
|
|
||||||
ObtainiumError(tr(
|
|
||||||
'systemFontError',
|
|
||||||
args: [fontLoadRes])),
|
|
||||||
context);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
settingsProvider.useSystemFont = false;
|
settingsProvider.useSystemFont = false;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:android_system_font/android_system_font.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class NativeFeatures {
|
class NativeFeatures {
|
||||||
@ -9,8 +10,7 @@ class NativeFeatures {
|
|||||||
static int _resPermShizuku = -2; // not set
|
static int _resPermShizuku = -2; // not set
|
||||||
|
|
||||||
static Future<ByteData> _readFileBytes(String path) async {
|
static Future<ByteData> _readFileBytes(String path) async {
|
||||||
var file = File(path);
|
var bytes = await File(path).readAsBytes();
|
||||||
var bytes = await file.readAsBytes();
|
|
||||||
return ByteData.view(bytes.buffer);
|
return ByteData.view(bytes.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,15 +34,13 @@ class NativeFeatures {
|
|||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> loadSystemFont() async {
|
static Future loadSystemFont() async {
|
||||||
if (_systemFontLoaded) { return "ok"; }
|
if (_systemFontLoaded) return;
|
||||||
var getFontRes = await _channel.invokeMethod('getSystemFont');
|
|
||||||
if (getFontRes[0] != '/') { return getFontRes; } // Error
|
|
||||||
var fontLoader = FontLoader('SystemFont');
|
var fontLoader = FontLoader('SystemFont');
|
||||||
fontLoader.addFont(_readFileBytes(getFontRes));
|
var fontFilePath = await AndroidSystemFont().getFilePath();
|
||||||
await fontLoader.load();
|
fontLoader.addFont(_readFileBytes(fontFilePath!));
|
||||||
|
fontLoader.load();
|
||||||
_systemFontLoaded = true;
|
_systemFontLoaded = true;
|
||||||
return "ok";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<int> checkPermissionShizuku() async {
|
static Future<int> checkPermissionShizuku() async {
|
||||||
|
@ -26,6 +26,15 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.1"
|
version: "0.7.1"
|
||||||
|
android_system_font:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "."
|
||||||
|
ref: master
|
||||||
|
resolved-ref: "355f897e92a58a803f91d9270d389d9ec40ba550"
|
||||||
|
url: "https://github.com/re7gog/android_system_font"
|
||||||
|
source: git
|
||||||
|
version: "1.0.0"
|
||||||
animations:
|
animations:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -68,6 +68,10 @@ dependencies:
|
|||||||
crypto: ^3.0.3
|
crypto: ^3.0.3
|
||||||
app_links: ^4.0.0
|
app_links: ^4.0.0
|
||||||
background_fetch: ^1.2.1
|
background_fetch: ^1.2.1
|
||||||
|
android_system_font:
|
||||||
|
git:
|
||||||
|
url: https://github.com/re7gog/android_system_font
|
||||||
|
ref: master
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user