use of com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION in project kcanotify by antest1.
the class InitStartActivity method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_init_download);
Log.e("KCA-DA", "created");
sendUserAnalytics(getApplicationContext(), START_APP, null);
Intent mainIntent = getIntent();
reset_flag = mainIntent.getBooleanExtra(ACTION_RESET, false);
is_destroyed = false;
PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false);
setDefaultPreferences();
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
downloader = KcaUtils.getInfoDownloader(getApplicationContext());
KcaApiData.setDBHelper(dbHelper);
appname = findViewById(R.id.app_title);
appname.setText(getStringWithLocale(R.string.app_name));
appversion = findViewById(R.id.app_version);
appversion.setText(getString(R.string.app_version));
appmessage = findViewById(R.id.app_message);
appmessage.setText("");
appfront = findViewById(R.id.app_icon);
int img_id = (int) (Math.random() * 4);
appfront.setImageResource(R.mipmap.main_image);
int fairy_id = Integer.parseInt(getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON));
if (!FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) {
setPreferences(getApplicationContext(), PREF_FAIRY_ICON, 0);
}
// Initialize resources
setPreferences(getApplicationContext(), PREF_DATALOAD_ERROR_FLAG, false);
loadDefaultAsset();
validated_flag = KcaUtils.validateResourceFiles(getApplicationContext(), dbHelper);
setPreferences(getApplicationContext(), PREF_DATALOAD_ERROR_FLAG, false);
findViewById(R.id.init_layout).setOnClickListener(v -> {
if (validated_flag && !reset_flag) {
startMainActivity(false);
is_skipped = true;
}
});
new Thread(() -> {
runOnUiThread(() -> appmessage.setText("Loading Translation Data..."));
loadTranslationData(getApplicationContext());
runOnUiThread(() -> appmessage.setText("Loading KanColle Game Data..."));
int setDefaultGameDataResult = KcaUtils.setDefaultGameData(getApplicationContext(), dbHelper);
if (setDefaultGameDataResult != 1) {
runOnUiThread(() -> Toast.makeText(getApplicationContext(), "error loading game data", Toast.LENGTH_LONG).show());
}
runOnUiThread(() -> appmessage.setText("Checking External Filter..."));
boolean allow_ext = KcaUtils.getBooleanPreferences(getApplicationContext(), PREF_ALLOW_EXTFILTER);
List<String> result = KcaVpnData.setExternalFilter(allow_ext);
boolean is_default_written = KcaUtils.getStringPreferences(getApplicationContext(), PREF_DEFAULT_APIVER).equals(BuildConfig.VERSION_NAME);
if (!is_default_written) {
runOnUiThread(() -> appmessage.setText("Writing Default Data..."));
String internal_kca_version = getString(R.string.default_gamedata_version);
try {
InputStream api_ais = getAssets().open("api_start2");
byte[] bytes = gzipdecompress(ByteStreams.toByteArray(api_ais));
String asset_start2_data = new String(bytes);
dbHelper.putValue(DB_KEY_STARTDATA, asset_start2_data);
KcaUtils.setPreferences(getApplicationContext(), PREF_DEFAULT_APIVER, BuildConfig.VERSION_NAME);
KcaUtils.setPreferences(getApplicationContext(), PREF_KCA_VERSION, internal_kca_version);
KcaUtils.setPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION, internal_kca_version);
} catch (IOException e) {
e.printStackTrace();
}
}
// main update check
if (!KcaUtils.checkOnline(getApplicationContext()) || !getBooleanPreferences(getApplicationContext(), PREF_CHECK_UPDATE_START)) {
startMainActivity(true);
} else {
if (is_skipped)
return;
runOnUiThread(() -> appmessage.setText("Checking Updates..."));
String currentVersion = BuildConfig.VERSION_NAME;
final Call<String> rv_data = downloader.getRecentVersion();
String response = getResultFromCall(rv_data);
new_resversion = -1;
fairy_flag = 0;
JsonObject response_data = new JsonObject();
try {
if (response != null) {
response_data = new JsonParser().parse(response).getAsJsonObject();
}
} catch (Exception e) {
dbHelper.recordErrorLog(ERROR_TYPE_MAIN, "version_check", "", "", getStringFromException(e));
}
Log.e("KCA", response_data.toString());
if (response_data.has("kc_maintenance")) {
dbHelper.putValue(DB_KEY_KCMAINTNC, response_data.get("kc_maintenance").toString());
}
if (response_data.has("version")) {
String recentVersion = response_data.get("version").getAsString();
if (!compareVersion(currentVersion, recentVersion)) {
// True if latest
JsonObject data = response_data;
if (!is_skipped) {
runOnUiThread(() -> {
AlertDialog.Builder alertDialog = getUpdateAlertDialog(recentVersion, data);
AlertDialog alert = alertDialog.create();
alert.setIcon(R.mipmap.ic_launcher);
alert.setTitle(getStringWithLocale(R.string.sa_checkupdate_dialogtitle));
if (!InitStartActivity.this.isFinishing()) {
alert.show();
}
});
}
} else {
dataCheck(response_data);
}
}
}
}).start();
}
use of com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION in project kcanotify by antest1.
the class KcaQuestViewService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
stopSelf();
} else {
try {
active = true;
helper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
questTracker = new KcaQuestTracker(getApplicationContext(), null, KCANOTIFY_QTDB_VERSION);
contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());
broadcaster = LocalBroadcastManager.getInstance(this);
// mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mInflater = LayoutInflater.from(contextWithLocale);
mView = mInflater.inflate(R.layout.view_quest_list_v2, null);
KcaUtils.resizeFullWidthView(getApplicationContext(), mView);
mView.setVisibility(View.GONE);
questView = mView.findViewById(R.id.questview);
questView.findViewById(R.id.quest_head).setOnTouchListener(mViewTouchListener);
questDescPopupView = mView.findViewById(R.id.quest_desc_popup);
questDescPopupView.setVisibility(View.GONE);
questDescPopupView.findViewById(R.id.view_qd_head).setOnTouchListener(popupViewTouchListener);
adapter = new KcaQuestListAdpater(KcaQuestViewService.this, questTracker);
questList = mView.findViewById(R.id.quest_list);
questList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
TextView page_title = questView.findViewById(R.id.quest_page);
page_title.setText(getStringWithLocale(R.string.questview_page).replace("%d/%d", "???"));
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
isamenuvisible = false;
questView.findViewById(R.id.quest_amenu).setVisibility(View.GONE);
questMenuButton = questView.findViewById(R.id.quest_amenu_btn);
questMenuButton.setOnTouchListener(mViewTouchListener);
questMenuButton.setImageResource(R.mipmap.ic_arrow_up);
questView.findViewById(R.id.quest_page_top).setOnTouchListener(mViewTouchListener);
questView.findViewById(R.id.quest_page_bottom).setOnTouchListener(mViewTouchListener);
for (int i = 0; i < pageIndexList.length; i++) {
TextView view = questView.findViewById(pageIndexList[i]);
view.setText(String.valueOf(i + 1));
view.setOnTouchListener(mViewTouchListener);
}
for (int i = 1; i <= 5; i++) {
TextView view = questView.findViewById(getId(KcaUtils.format("quest_class_%d", i), R.id.class));
view.setText(getStringWithLocale(getId(KcaUtils.format("quest_class_%d", i), R.string.class)));
view.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorFleetInfoBtn));
view.setOnTouchListener(mViewTouchListener);
}
mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.CENTER;
mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
displayWidth = size.x;
} catch (Exception e) {
active = false;
error_flag = true;
sendReport(e, 1);
stopSelf();
}
}
}
use of com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION 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.KCANOTIFY_DB_VERSION in project kcanotify by antest1.
the class KcaInspectorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspector);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getResources().getString(R.string.action_inspector));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
listViewItemList = new ArrayList<>();
adapter = new KcaInspectViewAdpater();
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
questTracker = new KcaQuestTracker(getApplicationContext(), null, KCANOTIFY_QTDB_VERSION);
packetLogger = new KcaPacketLogger(getApplicationContext(), null, KCANOTIFY_PACKETLOG_VERSION);
for (String db_key : DB_KEY_ARRAY) {
String db_value = dbHelper.getValue(db_key);
if (db_value == null)
db_value = "<null>";
else if (db_value.length() > 100) {
db_value = db_value.substring(0, 100).concat(KcaUtils.format("... (%d)", db_value.length()));
}
listViewItemList.add(new AbstractMap.SimpleEntry<>(DB_PREFIX.concat(db_key), db_value));
}
String questlist_data = dbHelper.getQuestListData();
String questlist_view = questlist_data.replace("\n", ", ");
if (questlist_view.length() > 100) {
questlist_view = questlist_view.substring(0, 100).concat(KcaUtils.format("... (%d)", questlist_data.length()));
}
listViewItemList.add(new AbstractMap.SimpleEntry<>(DQ_PREFIX.concat("quest_data"), questlist_view));
String questtrack_data = questTracker.getQuestTrackerDump();
listViewItemList.add(new AbstractMap.SimpleEntry<>(QT_PREFIX.concat("tracked_data"), questtrack_data));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
listViewItemList.add(new AbstractMap.SimpleEntry<>(SPREF_PREFIX.concat(PREF_VPN_ENABLED), String.valueOf(prefs.getBoolean(PREF_VPN_ENABLED, false))));
listViewItemList.add(new AbstractMap.SimpleEntry<>(SPREF_PREFIX.concat(PREF_SVC_ENABLED), String.valueOf(prefs.getBoolean(PREF_SVC_ENABLED, false))));
for (String pref_key : PREFS_LIST) {
String pref_value = "";
try {
if (PREFS_BOOLEAN_LIST.contains(pref_key)) {
pref_value = String.valueOf(getBooleanPreferences(getApplicationContext(), pref_key));
} else {
pref_value = getStringPreferences(getApplicationContext(), pref_key);
}
} catch (Exception e) {
dbHelper.recordErrorLog(ERROR_TYPE_SETTING, "pref", "", "", getStringFromException(e));
}
listViewItemList.add(new AbstractMap.SimpleEntry<>(PREF_PREFIX.concat(pref_key), pref_value));
}
adapter.setListViewItemList(listViewItemList);
listview = findViewById(R.id.inspector_listview);
listview.setAdapter(adapter);
packetlogEnable = findViewById(R.id.packetlog_enable);
packetlogEnable.setChecked(getBooleanPreferences(getApplicationContext(), PREF_PACKET_LOG));
packetlogEnable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
KcaUtils.setPreferences(getApplicationContext(), PREF_PACKET_LOG, isChecked);
}
});
packletlogClear = findViewById(R.id.packetlog_clear);
packletlogClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
packetLogger.clear();
}
});
packetlogDump = findViewById(R.id.packetlog_dump);
packetlogDump.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean result = packetLogger.dump(getApplicationContext());
Toast.makeText(getApplicationContext(), String.valueOf(result), Toast.LENGTH_LONG).show();
}
});
}
use of com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION in project kcanotify by antest1.
the class KcaDockingPopupService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
// Can not draw overlays: pass
stopSelf();
} else {
clickcount = 0;
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = mInflater.inflate(R.layout.view_docking_info, null);
mView.setOnTouchListener(mViewTouchListener);
((TextView) mView.findViewById(R.id.view_dock_title)).setText(getStringWithLocale(R.string.viewmenu_docking_title));
((TextView) mView.findViewById(R.id.view_dock_list_btn)).setText(getStringWithLocale(R.string.viewmenu_docking_list));
mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
popupWidth = mView.getMeasuredWidth();
popupHeight = mView.getMeasuredHeight();
// Button (Fairy) Settings
mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.TOP | Gravity.START;
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));
mParams.x = (screenWidth - popupWidth) / 2;
mParams.y = (screenHeight - popupHeight) / 2;
mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mManager.addView(mView, mParams);
api_ndock = dbHelper.getJsonArrayValue(DB_KEY_NDOCKDATA);
dockingTimer = new Runnable() {
@Override
public void run() {
Log.e("KCA-DKS", "dockingTimer");
try {
updatePopup();
} catch (Exception e) {
Log.e("KCA-DKS", getStringFromException(e));
}
}
};
dockingTimeScheduler = Executors.newSingleThreadScheduledExecutor();
dockingTimeScheduler.scheduleAtFixedRate(dockingTimer, 0, 1, TimeUnit.SECONDS);
adapter = new KcaDockingPopupListAdapter();
JsonArray damage_info = new JsonArray();
JsonArray ship_info = dbHelper.getJsonArrayValue(DB_KEY_SHIPIFNO);
if (ship_info != null) {
JsonObject indock_list = new JsonObject();
if (api_ndock != null) {
for (int i = 0; i < api_ndock.size(); i++) {
JsonObject item = api_ndock.get(i).getAsJsonObject();
if (item.get("api_state").getAsInt() != -1) {
int ship_id = item.get("api_ship_id").getAsInt();
if (ship_id > 0)
indock_list.addProperty(item.get("api_ship_id").getAsString(), true);
}
}
}
for (int i = 0; i < ship_info.size(); i++) {
JsonObject item = ship_info.get(i).getAsJsonObject();
int max_hp = item.get("api_maxhp").getAsInt();
int now_hp = item.get("api_nowhp").getAsInt();
int ship_id = item.get("api_ship_id").getAsInt();
int hp_loss = max_hp - now_hp;
if (hp_loss > 0) {
JsonObject kcdata = KcaApiData.getKcShipDataById(ship_id, "name,stype");
if (kcdata != null && kcdata.has("stype")) {
String id = item.get("api_id").getAsString();
int level = item.get("api_lv").getAsInt();
JsonObject repair_item = new JsonObject();
String name = getShipTranslation(kcdata.get("name").getAsString(), false);
String name_level = KcaUtils.format("%s (Lv %d)", name, level);
int stype = kcdata.get("stype").getAsInt();
int repair_time = KcaDocking.getDockingTime(hp_loss, level, stype);
repair_item.addProperty("name", name_level);
repair_item.addProperty("time_raw", repair_time);
repair_item.addProperty("time", KcaUtils.getTimeStr(repair_time));
repair_item.addProperty("state", getState(now_hp, max_hp));
repair_item.addProperty("dock", indock_list.has(id));
damage_info.add(repair_item);
}
}
}
Type listType = new TypeToken<List<JsonObject>>() {
}.getType();
final List<JsonObject> shipItemList = new Gson().fromJson(damage_info, listType);
StatComparator cmp = new StatComparator();
Collections.sort(shipItemList, cmp);
adapter.setItemList(shipItemList);
timerView = mView.findViewById(R.id.view_dock_timer);
timerView.setVisibility(View.VISIBLE);
dockListView = mView.findViewById(R.id.view_dock_list);
dockListView.setAdapter(adapter);
dockListView.setVisibility(View.GONE);
TextView dockListViewButton = mView.findViewById(R.id.view_dock_list_btn);
dockListViewButton.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
dockListViewButton.setOnClickListener(v -> {
if (dockListView.getVisibility() == View.GONE) {
dockListViewButton.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
dockListView.setVisibility(View.VISIBLE);
timerView.setVisibility(View.GONE);
} else {
dockListViewButton.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.grey));
dockListView.setVisibility(View.GONE);
timerView.setVisibility(View.VISIBLE);
}
});
}
}
}
Aggregations