mirror of https://github.com/NekoX-Dev/NekoX.git
137 lines
4.7 KiB
Java
137 lines
4.7 KiB
Java
package tw.nekomimi.nekogram;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.res.Configuration;
|
|
import android.graphics.Typeface;
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
import org.telegram.messenger.BuildVars;
|
|
import org.telegram.messenger.FileLog;
|
|
import org.telegram.messenger.LocaleController;
|
|
import org.telegram.messenger.NotificationCenter;
|
|
import org.telegram.messenger.NotificationsService;
|
|
import org.telegram.messenger.R;
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.util.Locale;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import tw.nekomimi.nkmr.NekomuraConfig;
|
|
|
|
public class NekoConfig {
|
|
|
|
public static final int TITLE_TYPE_TEXT = 0;
|
|
public static final int TITLE_TYPE_ICON = 1;
|
|
public static final int TITLE_TYPE_MIX = 2;
|
|
|
|
public static String getOpenPGPAppName() {
|
|
|
|
if (StrUtil.isNotBlank(NekomuraConfig.openPGPApp.String())) {
|
|
|
|
try {
|
|
PackageManager manager = ApplicationLoader.applicationContext.getPackageManager();
|
|
ApplicationInfo info = manager.getApplicationInfo(NekomuraConfig.openPGPApp.String(), PackageManager.GET_META_DATA);
|
|
return (String) manager.getApplicationLabel(info);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
NekomuraConfig.openPGPApp.setConfigString("");
|
|
}
|
|
|
|
}
|
|
|
|
return LocaleController.getString("None", R.string.None);
|
|
|
|
}
|
|
|
|
public static String formatLang(String name) {
|
|
|
|
if (name == null) {
|
|
|
|
return LocaleController.getString("Default", R.string.Default);
|
|
|
|
} else {
|
|
|
|
if (name.contains("-")) {
|
|
|
|
return new Locale(StrUtil.subBefore(name, "-", false), StrUtil.subAfter(name, "-", false)).getDisplayName(LocaleController.getInstance().currentLocale);
|
|
|
|
} else {
|
|
|
|
return new Locale(name).getDisplayName(LocaleController.getInstance().currentLocale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static {
|
|
}
|
|
|
|
|
|
private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf";
|
|
|
|
public static boolean loadSystemEmojiFailed = false;
|
|
private static Typeface systemEmojiTypeface;
|
|
|
|
public static Typeface getSystemEmojiTypeface() {
|
|
if (!loadSystemEmojiFailed && systemEmojiTypeface == null) {
|
|
try {
|
|
Pattern p = Pattern.compile(">(.*emoji.*)</font>", Pattern.CASE_INSENSITIVE);
|
|
BufferedReader br = new BufferedReader(new FileReader("/system/etc/fonts.xml"));
|
|
String line;
|
|
while ((line = br.readLine()) != null) {
|
|
Matcher m = p.matcher(line);
|
|
if (m.find()) {
|
|
systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + m.group(1));
|
|
FileLog.d("emoji font file fonts.xml = " + m.group(1));
|
|
break;
|
|
}
|
|
}
|
|
br.close();
|
|
} catch (Exception e) {
|
|
FileLog.e(e);
|
|
}
|
|
if (systemEmojiTypeface == null) {
|
|
try {
|
|
systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + EMOJI_FONT_AOSP);
|
|
FileLog.d("emoji font file = " + EMOJI_FONT_AOSP);
|
|
} catch (Exception e) {
|
|
FileLog.e(e);
|
|
loadSystemEmojiFailed = true;
|
|
}
|
|
}
|
|
}
|
|
return systemEmojiTypeface;
|
|
}
|
|
|
|
public static int getNotificationColor() {
|
|
int color = 0;
|
|
Configuration configuration = ApplicationLoader.applicationContext.getResources().getConfiguration();
|
|
boolean isDark = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
|
if (isDark) {
|
|
color = 0xffffffff;
|
|
} else {
|
|
if (Theme.getActiveTheme().hasAccentColors()) {
|
|
color = Theme.getActiveTheme().getAccentColor(Theme.getActiveTheme().currentAccentId);
|
|
}
|
|
if (Theme.getActiveTheme().isDark() || color == 0) {
|
|
color = Theme.getColor(Theme.key_actionBarDefault);
|
|
}
|
|
// too bright
|
|
if (AndroidUtilities.computePerceivedBrightness(color) >= 0.721f) {
|
|
color = Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader) | 0xff000000;
|
|
}
|
|
}
|
|
return color;
|
|
}
|
|
|
|
} |