2019-06-11 09:13:04 +02:00
|
|
|
package tw.nekomimi.nekogram;
|
|
|
|
|
2021-11-18 13:59:08 +01:00
|
|
|
import android.Manifest;
|
2019-06-11 09:13:04 +02:00
|
|
|
import android.app.Activity;
|
2019-07-29 17:22:59 +02:00
|
|
|
import android.content.Intent;
|
2019-06-11 09:13:04 +02:00
|
|
|
import android.content.SharedPreferences;
|
2020-07-19 09:44:11 +02:00
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2021-04-11 02:53:15 +02:00
|
|
|
import android.content.res.Configuration;
|
2021-01-08 10:09:16 +01:00
|
|
|
import android.graphics.Typeface;
|
2021-11-18 13:59:08 +01:00
|
|
|
import android.os.Build;
|
2019-06-11 09:13:04 +02:00
|
|
|
|
2021-04-11 02:53:15 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-06-11 09:13:04 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2021-04-19 14:25:33 +02:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2021-01-08 10:09:16 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2020-06-25 17:25:17 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2020-02-25 10:04:26 +01:00
|
|
|
import org.telegram.messenger.NotificationsService;
|
2020-06-25 17:25:17 +02:00
|
|
|
import org.telegram.messenger.R;
|
2021-04-11 02:53:15 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2020-06-25 17:25:17 +02:00
|
|
|
|
2021-01-08 10:09:16 +01:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.FileReader;
|
2021-01-11 12:22:07 +01:00
|
|
|
import java.util.Locale;
|
2021-01-08 10:09:16 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2019-06-11 09:13:04 +02:00
|
|
|
|
2021-01-11 12:22:07 +01:00
|
|
|
import cn.hutool.core.util.StrUtil;
|
2021-10-30 08:05:57 +02:00
|
|
|
import tw.nekomimi.nkmr.NekomuraConfig;
|
2021-01-11 12:22:07 +01:00
|
|
|
|
2019-06-11 09:13:04 +02:00
|
|
|
public class NekoConfig {
|
|
|
|
|
2020-04-26 08:50:44 +02:00
|
|
|
public static final int TITLE_TYPE_TEXT = 0;
|
|
|
|
public static final int TITLE_TYPE_ICON = 1;
|
|
|
|
public static final int TITLE_TYPE_MIX = 2;
|
|
|
|
|
2021-11-18 13:59:08 +01:00
|
|
|
public static boolean forceSystemPicker = false; // SDK23+ and no storage permission
|
|
|
|
|
2020-07-19 09:44:11 +02:00
|
|
|
public static String getOpenPGPAppName() {
|
|
|
|
|
2021-10-30 08:05:57 +02:00
|
|
|
if (StrUtil.isNotBlank(NekomuraConfig.openPGPApp.String())) {
|
2020-07-19 09:44:11 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
PackageManager manager = ApplicationLoader.applicationContext.getPackageManager();
|
2021-10-30 08:05:57 +02:00
|
|
|
ApplicationInfo info = manager.getApplicationInfo(NekomuraConfig.openPGPApp.String(), PackageManager.GET_META_DATA);
|
2020-07-19 09:44:11 +02:00
|
|
|
return (String) manager.getApplicationLabel(info);
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
2021-10-30 08:05:57 +02:00
|
|
|
NekomuraConfig.openPGPApp.setConfigString("");
|
2020-07-19 09:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-03 07:43:35 +01:00
|
|
|
return LocaleController.getString("None", R.string.None);
|
2020-07-19 09:44:11 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:25:17 +02:00
|
|
|
public static String formatLang(String name) {
|
|
|
|
|
2021-11-01 12:39:27 +01:00
|
|
|
if (name == null || name.isEmpty()) {
|
2020-06-25 17:25:17 +02:00
|
|
|
|
|
|
|
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);
|
2019-06-11 09:13:04 +02:00
|
|
|
|
|
|
|
}
|
2020-06-25 17:25:17 +02:00
|
|
|
|
2019-06-11 09:13:04 +02:00
|
|
|
}
|
2020-06-25 17:25:17 +02:00
|
|
|
|
2019-06-11 09:13:04 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 17:25:17 +02:00
|
|
|
static {
|
2021-11-18 13:59:08 +01:00
|
|
|
checkForceSystemPicker();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkForceSystemPicker() {
|
|
|
|
// TODO show alert?
|
|
|
|
// TODO not working: send photo (upstream bug)
|
|
|
|
if (Build.VERSION.SDK_INT >= 23 && ApplicationLoader.applicationContext.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
forceSystemPicker = true;
|
|
|
|
BuildVars.NO_SCOPED_STORAGE = false;
|
|
|
|
}
|
2019-06-11 09:13:04 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 15:30:57 +02:00
|
|
|
|
2021-01-08 10:09:16 +01:00
|
|
|
private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf";
|
|
|
|
|
2021-10-30 08:05:57 +02:00
|
|
|
public static boolean loadSystemEmojiFailed = false;
|
|
|
|
private static Typeface systemEmojiTypeface;
|
|
|
|
|
2021-01-08 10:09:16 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-11 02:53:15 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:25:17 +02:00
|
|
|
}
|