use of com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE in project kcanotify by antest1.
the class KcaService method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.e("KCA", "lang: " + newConfig.getLocales().get(0).getLanguage() + " " + newConfig.getLocales().get(0).getCountry());
KcaApplication.defaultLocale = newConfig.getLocales().get(0);
} else {
Log.e("KCA", "lang: " + newConfig.locale.getLanguage() + " " + newConfig.locale.getCountry());
KcaApplication.defaultLocale = newConfig.locale;
}
if (getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE).startsWith("default")) {
LocaleUtils.setLocale(Locale.getDefault());
} else {
String[] pref = getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE).split("-");
LocaleUtils.setLocale(new Locale(pref[0], pref[1]));
}
contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());
loadTranslationData(getApplicationContext());
showDataLoadErrorToast(getApplicationContext(), getBaseContext(), getStringWithLocale(R.string.download_check_error));
super.onConfigurationChanged(newConfig);
}
use of com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE in project kcanotify by antest1.
the class FleetInfoActivity method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.e("KCA", "lang: " + newConfig.getLocales().get(0).getLanguage() + " " + newConfig.getLocales().get(0).getCountry());
KcaApplication.defaultLocale = newConfig.getLocales().get(0);
} else {
Log.e("KCA", "lang: " + newConfig.locale.getLanguage() + " " + newConfig.locale.getCountry());
KcaApplication.defaultLocale = newConfig.locale;
}
if (getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE).startsWith("default")) {
LocaleUtils.setLocale(Locale.getDefault());
} else {
String[] pref = getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE).split("-");
LocaleUtils.setLocale(new Locale(pref[0], pref[1]));
}
super.onConfigurationChanged(newConfig);
is_portrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT;
if (is_portrait) {
fleetlist_ships.setNumColumns(1);
} else {
fleetlist_ships.setNumColumns(2);
}
fleetlist_ships.invalidateViews();
}
use of com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE in project kcanotify by antest1.
the class KcaAlarmService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
createAlarmChannel();
Log.e("KCA", "KcaAlarmService Called: " + String.valueOf(startId));
if (intent != null && intent.getAction() != null) {
String action = intent.getAction();
Log.e("KCA-N", "Action: ".concat(action));
Log.e("KCA-N", "B> " + alarm_set.toString());
if (action.startsWith(REFRESH_CHANNEL)) {
String uri = intent.getStringExtra("uri");
Log.e("KCA-A", REFRESH_CHANNEL + " recv: " + uri);
createAlarmChannel(uri);
} else if (action.startsWith(ACTION_PREFIX)) {
if (action.startsWith(CLICK_ACTION)) {
Intent kcintent = getKcIntent(getApplicationContext());
if (kcintent != null) {
kcintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pintent = PendingIntent.getActivity(getApplicationContext(), 0, kcintent, 0);
try {
pintent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
}
if (action.startsWith(UPDATE_ACTION)) {
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
String[] action_list = action.split("_");
if (action_list.length == 3) {
int nid = Integer.parseInt(action_list[2]);
alarm_set.remove(nid);
notificationManager.cancel(nid);
}
}
Log.e("KCA-N", "A> " + alarm_set.toString());
} else if (intent != null && intent.getStringExtra("data") != null) {
JsonObject data = new JsonParser().parse(intent.getStringExtra("data")).getAsJsonObject();
int type = data.get("type").getAsInt();
if (type == TYPE_UPDATE) {
int utype = data.get("utype").getAsInt();
String version = data.get("version").getAsString();
int nid = getNotificationId(NOTI_UPDATE, utype);
notificationManager.notify(nid, createUpdateNotification(utype, version, nid));
alarm_set.add(nid);
} else if (getBooleanPreferences(getApplication(), PREF_KCA_NOTI_NOTIFYATSVCOFF) || KcaService.getServiceStatus()) {
loadTranslationData(getApplicationContext());
if (intent.getStringExtra("data") != null) {
String locale = LocaleUtils.getResourceLocaleCode(getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE));
if (type == TYPE_EXPEDITION) {
int idx = data.get("idx").getAsInt();
KcaExpedition2.clearMissionData(idx);
if (isExpAlarmEnabled()) {
if (!isExpeditionDataLoaded())
loadSimpleExpeditionInfoFromStorage(getApplicationContext());
int mission_no = data.get("mission_no").getAsInt();
String mission_name = KcaApiData.getExpeditionName(mission_no, locale);
String kantai_name = data.get("kantai_name").getAsString();
boolean cancelFlag = data.get("cancel_flag").getAsBoolean();
boolean caFlag = data.get("ca_flag").getAsBoolean();
// if (caFlag) idx = idx | EXP_CANCEL_FLAG;
int nid = getNotificationId(NOTI_EXP, idx);
notificationManager.notify(nid, createExpeditionNotification(mission_no, mission_name, kantai_name, cancelFlag, caFlag, nid));
alarm_set.add(nid);
}
} else if (type == TYPE_DOCKING) {
int dockId = data.get("dock_id").getAsInt();
KcaDocking.setCompleteTime(dockId, -1);
KcaDocking.setShipId(dockId, 0);
if (isDockAlarmEnabled()) {
int shipId = data.get("ship_id").getAsInt();
String shipName = "";
if (shipId != -1) {
JsonObject kcShipData = KcaApiData.getKcShipDataById(shipId, "name");
if (kcShipData != null) {
shipName = getShipTranslation(kcShipData.get("name").getAsString(), false);
}
}
int nid = getNotificationId(NOTI_DOCK, dockId);
notificationManager.notify(nid, createDockingNotification(dockId, shipName, nid));
alarm_set.add(nid);
}
} else if (type == TYPE_MORALE) {
int idx = data.get("idx").getAsInt();
if (isMoraleAlarmEnabled()) {
int nid = getNotificationId(NOTI_MORALE, idx);
String kantai_name = data.get("kantai_name").getAsString();
notificationManager.notify(nid, createMoraleNotification(idx, kantai_name, nid));
alarm_set.add(nid);
}
} else if (type == TYPE_AKASHI) {
if (isAkashiAlarmEnabled()) {
int nid = getNotificationId(NOTI_AKASHI, 0);
if (KcaAkashiRepairInfo.getAkashiInFlasship()) {
notificationManager.notify(nid, createAkashiRepairNotification(nid));
alarm_set.add(nid);
}
}
}
}
}
}
Log.e("KCA", "Noti Count: " + String.valueOf(alarm_set.size()));
if (sHandler != null) {
bundle = new Bundle();
bundle.putString("url", KCA_API_PREF_NOTICOUNT_CHANGED);
bundle.putString("data", "");
sMsg = sHandler.obtainMessage();
sMsg.setData(bundle);
sHandler.sendMessage(sMsg);
}
return super.onStartCommand(intent, flags, startId);
}
use of com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE in project kcanotify by antest1.
the class KcaExpeditionCheckViewService method onCreate.
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
stopSelf();
}
try {
active = true;
locale = LocaleUtils.getResourceLocaleCode(KcaUtils.getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE));
ship_data = new ArrayList<>();
checkdata = new HashMap<>();
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
contextWithLocale = KcaUtils.getContextWithLocale(getApplicationContext(), getBaseContext());
mInflater = LayoutInflater.from(contextWithLocale);
mView = mInflater.inflate(R.layout.view_excheck_list, null);
KcaUtils.resizeFullWidthView(getApplicationContext(), mView);
mView.setVisibility(View.GONE);
itemView = mView.findViewById(R.id.view_excheck_detail);
mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.CENTER;
mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mManager.addView(mView, mParams);
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
displayWidth = size.x;
} catch (Exception e) {
e.printStackTrace();
active = false;
error_flag = true;
stopSelf();
}
}
use of com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE in project kcanotify by antest1.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vpn_main);
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
assetManager = getAssets();
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.app_name);
prefs.edit().putBoolean(PREF_SVC_ENABLED, KcaService.getServiceStatus()).apply();
prefs.edit().putBoolean(PREF_VPN_ENABLED, KcaVpnService.checkOn()).apply();
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
downloader = KcaUtils.getInfoDownloader(getApplicationContext());
int sniffer_mode = Integer.parseInt(getStringPreferences(getApplicationContext(), PREF_SNIFFER_MODE));
vpnbtn = findViewById(R.id.vpnbtn);
vpnbtn.setTextOff(getStringWithLocale(R.string.ma_vpn_toggleoff));
vpnbtn.setTextOn(getStringWithLocale(R.string.ma_vpn_toggleon));
vpnbtn.setText("PASSIVE");
vpnbtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
JsonObject statProperties = new JsonObject();
try {
final Intent prepare = VpnService.prepare(MainActivity.this);
if (prepare == null) {
// Log.i(TAG, "Prepare done");
onActivityResult(REQUEST_VPN, RESULT_OK, null);
} else {
startActivityForResult(prepare, REQUEST_VPN);
}
statProperties.addProperty("is_success", true);
} catch (Throwable ex) {
// Prepare failed
statProperties.addProperty("is_success", false);
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
sendUserAnalytics(getApplicationContext(), START_SNIFFER, statProperties);
} else {
KcaVpnService.stop(VPN_STOP_REASON, MainActivity.this);
prefs.edit().putBoolean(PREF_VPN_ENABLED, false).apply();
sendUserAnalytics(getApplicationContext(), END_SNIFFER, null);
}
}
});
if (sniffer_mode == SNIFFER_ACTIVE) {
vpnbtn.setEnabled(true);
} else {
vpnbtn.setEnabled(false);
}
Intent serviceIntent = new Intent(MainActivity.this, KcaService.class);
svcbtn = findViewById(R.id.svcbtn);
svcbtn.setTextOff(getStringWithLocale(R.string.ma_svc_toggleoff));
svcbtn.setTextOn(getStringWithLocale(R.string.ma_svc_toggleon));
svcbtn.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (!prefs.getBoolean(PREF_SVC_ENABLED, false)) {
sendUserAnalytics(getApplicationContext(), START_SERVICE, null);
loadTranslationData(getApplicationContext());
serviceIntent.setAction(KcaService.KCASERVICE_START);
if (Build.VERSION.SDK_INT >= 26) {
startForegroundService(serviceIntent);
} else {
startService(serviceIntent);
}
}
} else {
serviceIntent.setAction(KcaService.KCASERVICE_STOP);
startService(serviceIntent);
sendUserAnalytics(getApplicationContext(), END_SERVICE, null);
prefs.edit().putBoolean(PREF_SVC_ENABLED, false).apply();
}
});
kcbtn = findViewById(R.id.kcbtn);
kcbtn.setOnClickListener(v -> {
String kcApp = getStringPreferences(getApplicationContext(), PREF_KC_PACKAGE);
Intent kcIntent = getKcIntent(getApplicationContext());
boolean is_kca_installed = false;
if (!BuildConfig.DEBUG)
is_kca_installed = (kcIntent != null);
JsonObject statProperties = new JsonObject();
statProperties.addProperty("browser", kcApp);
statProperties.addProperty("sniffer", sniffer_mode);
statProperties.addProperty("enabled", is_kca_installed ? 1 : 0);
sendUserAnalytics(getApplicationContext(), RUN_KANCOLLE, statProperties);
if (is_kca_installed) {
kcIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(kcIntent);
finish();
} else {
if (kcApp.equals(KC_PACKAGE_NAME)) {
Toast.makeText(getApplicationContext(), getString(R.string.ma_toast_kancolle_not_installed), Toast.LENGTH_LONG).show();
} else if (kcApp.equals(GOTO_PACKAGE_NAME)) {
Toast.makeText(getApplicationContext(), getString(R.string.ma_toast_gotobrowser_not_installed), Toast.LENGTH_LONG).show();
}
}
});
kctoolbtn = findViewById(R.id.kcatoolbtn);
kctoolbtn.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, ToolsActivity.class);
startActivity(intent);
});
kctoolbtn.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white), PorterDuff.Mode.SRC_ATOP);
kcafairybtn = findViewById(R.id.kcafairybtn);
boolean is_random_fairy = getBooleanPreferences(getApplicationContext(), PREF_FAIRY_RANDOM);
if (is_random_fairy) {
kcafairybtn.setImageResource(R.mipmap.ic_help);
} else {
String fairyIdValue = getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON);
String fairyPath = "noti_icon_".concat(fairyIdValue);
KcaUtils.setFairyImageFromStorage(getApplicationContext(), fairyPath, kcafairybtn, 24);
}
kcafairybtn.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white), PorterDuff.Mode.SRC_ATOP);
kcafairybtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
} else if (KcaService.getServiceStatus() && sHandler != null) {
Bundle bundle = new Bundle();
bundle.putString("url", KCA_API_FAIRY_RETURN);
bundle.putString("data", "");
Message sMsg = sHandler.obtainMessage();
sMsg.setData(bundle);
sHandler.sendMessage(sMsg);
}
}
});
textWarn = findViewById(R.id.textMainWarn);
textWarn.setVisibility(View.GONE);
String main_html = "";
try {
String locale = getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE);
InputStream ais = assetManager.open("main-".concat(getResourceLocaleCode(locale)).concat(".html"));
byte[] bytes = ByteStreams.toByteArray(ais);
main_html = new String(bytes);
} catch (IOException e) {
main_html = "Error loading html file.";
}
textMainUpdate = findViewById(R.id.textMainUpdate);
textMainUpdate.setOnClickListener(v -> {
startActivity(new Intent(this, UpdateCheckActivity.class));
});
textDescription = findViewById(R.id.textDescription);
Spanned fromHtml = HtmlCompat.fromHtml(getApplicationContext(), main_html, 0);
textDescription.setMovementMethod(LinkMovementMethod.getInstance());
textDescription.setText(fromHtml);
// Linkify.addLinks(textDescription, Linkify.WEB_URLS);
backPressCloseHandler = new BackPressCloseHandler(this);
textMaintenance = findViewById(R.id.textMaintenance);
String maintenanceInfo = dbHelper.getValue(DB_KEY_KCMAINTNC);
if (maintenanceInfo != null && maintenanceInfo.trim().length() > 0) {
try {
JsonArray maintenance_data = (new JsonParser().parse(maintenanceInfo)).getAsJsonArray();
String mt_start = maintenance_data.get(0).getAsString();
String mt_end = maintenance_data.get(1).getAsString();
if (!mt_start.equals("")) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
Date start_date = df.parse(mt_start);
Date end_date = df.parse(mt_end);
SimpleDateFormat out_df = df;
if (Build.VERSION.SDK_INT >= 18) {
out_df = new SimpleDateFormat(DateFormat.getBestDateTimePattern(Locale.getDefault(), "EEE, dd MMM yyyy HH:mm Z"), Locale.getDefault());
}
boolean is_passed = end_date.getTime() < System.currentTimeMillis();
boolean before_maintenance = System.currentTimeMillis() < start_date.getTime();
if (before_maintenance) {
textMaintenance.setText(KcaUtils.format(getStringWithLocale(R.string.ma_nextmaintenance), out_df.format(start_date)));
} else if (!is_passed) {
textMaintenance.setText(KcaUtils.format(getStringWithLocale(R.string.ma_endmaintenance), out_df.format(end_date)));
}
textMaintenance.setVisibility(View.VISIBLE);
} else {
textMaintenance.setVisibility(View.GONE);
}
} catch (ParseException | IllegalStateException e) {
textMaintenance.setText(getStringFromException(e));
textMaintenance.setVisibility(View.VISIBLE);
}
} else {
textMaintenance.setVisibility(View.GONE);
}
String locale = getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE);
ImageView specialImage = findViewById(R.id.special_image);
specialImage.setImageResource(R.mipmap.special_image);
specialImage.setVisibility(View.GONE);
specialImage.setOnClickListener(v -> v.setVisibility(View.GONE));
textSpecial = findViewById(R.id.textSpecial);
textSpecial.setText(getStringWithLocale(R.string.special_message));
textSpecial.setOnClickListener(v -> {
specialImage.setImageResource(R.mipmap.special_image);
specialImage.setVisibility(View.VISIBLE);
sendUserAnalytics(getApplicationContext(), OPEN_PIC, null);
});
textSpecial2 = findViewById(R.id.textSpecial2);
textSpecial2.setText(getStringWithLocale(R.string.notification_message));
textSpecial2.setOnClickListener(v -> {
String locale1 = getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE);
String locale_code = getResourceLocaleCode(locale1);
String url = KcaUtils.format("http://luckyjervis.com/noti.html", locale_code);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setShowTitle(true);
intentBuilder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
intentBuilder.enableUrlBarHiding();
final CustomTabsIntent customTabsIntent = intentBuilder.build();
final List<ResolveInfo> customTabsApps = getPackageManager().queryIntentActivities(customTabsIntent.intent, 0);
if (customTabsApps.size() > 0) {
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));
} else {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
}
});
}
Aggregations