| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.Intent; |
| 5 | import android.content.SharedPreferences; |
| 6 | import android.content.pm.ApplicationInfo; |
| 7 | import android.content.pm.PackageManager; |
| 8 | import android.content.res.Configuration; |
| 9 | import android.graphics.Typeface; |
| 10 | |
| 11 | import org.telegram.messenger.AndroidUtilities; |
| 12 | import org.telegram.messenger.ApplicationLoader; |
| 13 | import org.telegram.messenger.BuildVars; |
| 14 | import org.telegram.messenger.FileLog; |
| 15 | import org.telegram.messenger.LocaleController; |
| 16 | import org.telegram.messenger.NotificationCenter; |
| 17 | import org.telegram.messenger.NotificationsService; |
| 18 | import org.telegram.messenger.R; |
| 19 | import org.telegram.ui.ActionBar.Theme; |
| 20 | |
| 21 | import java.io.BufferedReader; |
| 22 | import java.io.FileReader; |
| 23 | import java.util.Locale; |
| 24 | import java.util.regex.Matcher; |
| 25 | import java.util.regex.Pattern; |
| 26 | |
| 27 | import cn.hutool.core.util.StrUtil; |
| 28 | import tw.nekomimi.nkmr.NekomuraConfig; |
| 29 | |
| 30 | public class NekoConfig { |
| 31 | |
| 32 | public static final int TITLE_TYPE_TEXT = 0; |
| 33 | public static final int TITLE_TYPE_ICON = 1; |
| 34 | public static final int TITLE_TYPE_MIX = 2; |
| 35 | |
| 36 | public static String getOpenPGPAppName() { |
| 37 | |
| 38 | if (StrUtil.isNotBlank(NekomuraConfig.openPGPApp.String())) { |
| 39 | |
| 40 | try { |
| 41 | PackageManager manager = ApplicationLoader.applicationContext.getPackageManager(); |
| 42 | ApplicationInfo info = manager.getApplicationInfo(NekomuraConfig.openPGPApp.String(), PackageManager.GET_META_DATA); |
| 43 | return (String) manager.getApplicationLabel(info); |
| 44 | } catch (PackageManager.NameNotFoundException e) { |
| 45 | NekomuraConfig.openPGPApp.setConfigString(""); |
| 46 | } |
| 47 | |
| 48 | } |
| 49 | |
| 50 | return LocaleController.getString("None", R.string.None); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | public static String formatLang(String name) { |
| 55 | |
| 56 | if (name == null) { |
| 57 | |
| 58 | return LocaleController.getString("Default", R.string.Default); |
| 59 | |
| 60 | } else { |
| 61 | |
| 62 | if (name.contains("-")) { |
| 63 | |
| 64 | return new Locale(StrUtil.subBefore(name, "-", false), StrUtil.subAfter(name, "-", false)).getDisplayName(LocaleController.getInstance().currentLocale); |
| 65 | |
| 66 | } else { |
| 67 | |
| 68 | return new Locale(name).getDisplayName(LocaleController.getInstance().currentLocale); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | static { |
| 77 | } |
| 78 | |
| 79 | |
| 80 | private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; |
| 81 | |
| 82 | public static boolean loadSystemEmojiFailed = false; |
| 83 | private static Typeface systemEmojiTypeface; |
| 84 | |
| 85 | public static Typeface getSystemEmojiTypeface() { |
| 86 | if (!loadSystemEmojiFailed && systemEmojiTypeface == null) { |
| 87 | try { |
| 88 | Pattern p = Pattern.compile(">(.*emoji.*)</font>", Pattern.CASE_INSENSITIVE); |
| 89 | BufferedReader br = new BufferedReader(new FileReader("/system/etc/fonts.xml")); |
| 90 | String line; |
| 91 | while ((line = br.readLine()) != null) { |
| 92 | Matcher m = p.matcher(line); |
| 93 | if (m.find()) { |
| 94 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + m.group(1)); |
| 95 | FileLog.d("emoji font file fonts.xml = " + m.group(1)); |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | br.close(); |
| 100 | } catch (Exception e) { |
| 101 | FileLog.e(e); |
| 102 | } |
| 103 | if (systemEmojiTypeface == null) { |
| 104 | try { |
| 105 | systemEmojiTypeface = Typeface.createFromFile("/system/fonts/" + EMOJI_FONT_AOSP); |
| 106 | FileLog.d("emoji font file = " + EMOJI_FONT_AOSP); |
| 107 | } catch (Exception e) { |
| 108 | FileLog.e(e); |
| 109 | loadSystemEmojiFailed = true; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | return systemEmojiTypeface; |
| 114 | } |
| 115 | |
| 116 | public static int getNotificationColor() { |
| 117 | int color = 0; |
| 118 | Configuration configuration = ApplicationLoader.applicationContext.getResources().getConfiguration(); |
| 119 | boolean isDark = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; |
| 120 | if (isDark) { |
| 121 | color = 0xffffffff; |
| 122 | } else { |
| 123 | if (Theme.getActiveTheme().hasAccentColors()) { |
| 124 | color = Theme.getActiveTheme().getAccentColor(Theme.getActiveTheme().currentAccentId); |
| 125 | } |
| 126 | if (Theme.getActiveTheme().isDark() || color == 0) { |
| 127 | color = Theme.getColor(Theme.key_actionBarDefault); |
| 128 | } |
| 129 | // too bright |
| 130 | if (AndroidUtilities.computePerceivedBrightness(color) >= 0.721f) { |
| 131 | color = Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader) | 0xff000000; |
| 132 | } |
| 133 | } |
| 134 | return color; |
| 135 | } |
| 136 | |
| 137 | } |