public static final int STYPE_CVE = 27; public static final int T2_ANTISUB_PATROL = 26; public static final int T2_AUTOGYRO = 25; public static final int T2_DEPTH_CHARGE = 15; // 폭뢰 public static final int T2_GUN_LARGE = 3; public static final int T2_GUN_LARGE_II = 38; public static final int T2_GUN_MEDIUM = 2; public static final int T2_GUN_SMALL = 1; public static final int T2_RADAR_LARGE = 13; public static final int T2_RADAR_SMALL = 12; public static final int T2_RADER_LARGE_II = 93; public static final int T2_SONAR = 14; public static final int T2_SONAR_LARGE = 40; public static final int T2_SUB_GUN = 4; public static boolean checkUserShipDataLoaded() {
    return userShipData != null && userShipData.size() > 0;
} public static JsonObject getKcShipDataById(int id, String list) {
    if (kcGameData == null) return null;
    JsonObject temp = new JsonObject();
    if (kcShipData.containsKey(id)) {
        if (list.equals("all")) {
            return kcShipData.get(id);
        } else {
            String[] requestList = list.split(",");
            for (int i = 0; i < requestList.length; i++) {
                String orig_api_item = requestList[i];
                String api_item = orig_api_item;
                if (!api_item.startsWith("api_")) {
                    api_item = "api_" + api_item;
                }
                temp.add(orig_api_item, kcShipData.get(id).get(api_item));
            }
            return temp;
        }
    } else {
        Log.e("KCA", String.valueOf(id) + " not in list");
        return null;
    }
} public static String getShipTypeAbbr(int idx) {
    if (kcStypeData != null && idx < kcStypeData.size()) {
        return kcStypeData.get(idx).getAsString();
    } else {
        return "";
    }
} public static JsonObject getUserItemStatusById(int id, String list, String kclist) {
    if (helper == null || kcGameData == null) return null;
    String data = helper.getItemValue(id);
    if (data != null) {
        JsonObject userData = new JsonParser().parse(data).getAsJsonObject();
        int kc_item_id = userData.get("api_slotitem_id").getAsInt();
        JsonObject kcData = getKcItemStatusById(kc_item_id, kclist);

        if (list.equals("all")) {
            for (Map.Entry<String, JsonElement> k : userData.entrySet()) {
                kcData.add(k.getKey(), userData.get(k.getKey()));
            }
        } else {
            String[] requestList = list.split(",");
            for (int i = 0; i < requestList.length; i++) {
                String orig_api_item = requestList[i];
                String api_item = orig_api_item;
                if (!api_item.startsWith("api_")) {
                    api_item = "api_" + api_item;
                }
                if (userData.has(api_item)) {
                    kcData.add(orig_api_item, userData.get(api_item));
                }
            }
        }
        kcData.remove("");
        return kcData;
    } else {
        return null;
    }
} public static JsonObject getUserShipDataById(int id, String list) {
    JsonObject target_data = null;
    JsonObject return_data = new JsonObject();
    if (userShipData != null) {
        if (userShipData.containsKey(id)) {
            target_data = userShipData.get(id);
        }
    } else if (helper.getShipCount() > 0) {
        JsonArray data = helper.getJsonArrayValue(DB_KEY_SHIPIFNO);
        for (int i = 0; i < data.size(); i++) {
            JsonObject item = data.get(i).getAsJsonObject();
            int aid = item.get("api_id").getAsInt();
            if (aid == id) {
                target_data = item;
                break;
            }
        }
    }

    if (target_data != null) {
        if (list.equals("all")) {
            return target_data;
        } else {
            String[] requestList = list.split(",");
            for (String orig_api_item: requestList) {
                String api_item = orig_api_item;
                if (!api_item.startsWith("api_")) {
                    api_item = "api_" + api_item;
                }
                if (target_data.has(api_item)) {
                    return_data.add(orig_api_item, target_data.get(api_item));
                }
            }
        }
    }
    return return_data;
} public static final String DB_KEY_DECKPORT = "key_deckport"; public static final int KCANOTIFY_DB_VERSION = 5; public static final String PREF_KCA_LANGUAGE = "kca_language"; public static String getExpeditionHeader(int mission_no) {
    String mission_no_head = "";
    String mission_no_value = getExpeditionStr(mission_no);
    if (mission_no_value.matches("[A-Z][0-9]+")) {
        mission_no_head = "[".concat(mission_no_value).concat("] ");
    } else {
        mission_no_head = KcaUtils.format("[%02d] ", mission_no);
    }
    return mission_no_head;
} public static int getId(String resourceName, Class<?> c) {
    try {
        Field idField = c.getDeclaredField(resourceName);
        return idField.getInt(idField);
    } catch (Exception e) {
        throw new RuntimeException("No resource ID found for: "
                + resourceName + " / " + c, e);
    }
} public static String getStringFromException(Exception ex) {
    StringWriter errors = new StringWriter();
    ex.printStackTrace(new PrintWriter(errors));
    return errors.toString().replaceAll("\n", " / ").replaceAll("\t", "");
} public static String getTimeStr(int left_time, boolean is_min) {
    int sec, min, hour;
    sec = left_time;
    min = sec / 60;
    hour = min / 60;
    sec = sec % 60;
    min = min % 60;
    if (is_min) return KcaUtils.format("%02d:%02d", hour * 60 + min, sec);
    else return KcaUtils.format("%02d:%02d:%02d", hour, min, sec);
} public static int getWindowLayoutType() {
    int windowLayoutType = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        windowLayoutType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        windowLayoutType = WindowManager.LayoutParams.TYPE_PHONE;
    }
    return windowLayoutType;
} public static String joinStr(List<String> list, String delim) {
    String resultStr = "";
    if (list.size() > 0) {
        int i;
        for (i = 0; i < list.size() - 1; i++) {
            resultStr = resultStr.concat(list.get(i));
            resultStr = resultStr.concat(delim);
        }
        resultStr = resultStr.concat(list.get(i));
    }
    return resultStr;
}
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.antest1.kcanotify.KcaApiData.STYPE_CVE;
import static com.antest1.kcanotify.KcaApiData.T2_ANTISUB_PATROL;
import static com.antest1.kcanotify.KcaApiData.T2_AUTOGYRO;
import static com.antest1.kcanotify.KcaApiData.T2_DEPTH_CHARGE;
import static com.antest1.kcanotify.KcaApiData.T2_GUN_LARGE;
import static com.antest1.kcanotify.KcaApiData.T2_GUN_LARGE_II;
import static com.antest1.kcanotify.KcaApiData.T2_GUN_MEDIUM;
import static com.antest1.kcanotify.KcaApiData.T2_GUN_SMALL;
import static com.antest1.kcanotify.KcaApiData.T2_RADAR_LARGE;
import static com.antest1.kcanotify.KcaApiData.T2_RADAR_SMALL;
import static com.antest1.kcanotify.KcaApiData.T2_RADER_LARGE_II;
import static com.antest1.kcanotify.KcaApiData.T2_SONAR;
import static com.antest1.kcanotify.KcaApiData.T2_SONAR_LARGE;
import static com.antest1.kcanotify.KcaApiData.T2_SUB_GUN;
import static com.antest1.kcanotify.KcaApiData.checkUserShipDataLoaded;
import static com.antest1.kcanotify.KcaApiData.getKcShipDataById;
import static com.antest1.kcanotify.KcaApiData.getShipTypeAbbr;
import static com.antest1.kcanotify.KcaApiData.getUserItemStatusById;
import static com.antest1.kcanotify.KcaApiData.getUserShipDataById;
import static com.antest1.kcanotify.KcaConstants.DB_KEY_DECKPORT;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION;
import static com.antest1.kcanotify.KcaConstants.PREF_KCA_LANGUAGE;
import static com.antest1.kcanotify.KcaExpedition2.getExpeditionHeader;
import static com.antest1.kcanotify.KcaUtils.getId;
import static com.antest1.kcanotify.KcaUtils.getStringFromException;
import static com.antest1.kcanotify.KcaUtils.getTimeStr;
import static com.antest1.kcanotify.KcaUtils.getWindowLayoutType;
import static com.antest1.kcanotify.KcaUtils.joinStr;
                mView.findViewById(view_id).setBackgroundColor(
                        ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
            } else {
                mView.findViewById(view_id).setBackgroundColor(
                        ContextCompat.getColor(getApplicationContext(), R.color.colorFleetInfoBtn));
            }
        }

        for (int i = 1; i < 4; i++) {
            int view_id = getId("fleet_".concat(String.valueOf(i + 1)), R.id.class);
            if (idx == i) {
                mView.findViewById(view_id).setBackgroundColor(
                        ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
            } else {
                mView.findViewById(view_id).setBackgroundColor(
                        ContextCompat.getColor(getApplicationContext(), R.color.colorFleetInfoBtn));
            }
        }
    }

    public IBinder onBind(Intent paramIntent) {
        return null;
    }

    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();
        }
    }

    @Override
    public void onDestroy() {
        active = false;
        if (mView != null) {
            if (mView.getParent() != null) mManager.removeViewImmediate(mView);
        }
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null && intent.getAction() != null) {
            if (intent.getAction().startsWith(SHOW_EXCHECKVIEW_ACTION)) {
                deckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                if (deckdata != null && deckdata.size() >= 2) {
                    int selected_new = Integer.parseInt(intent.getAction().split("/")[1]);
                    if (selected_new < 1) selected_new = 1;
                    else if (selected_new > 3) selected_new = 2;
                    if (selected_new < deckdata.size()) {
                        selected = selected_new;
                    }
                    clearItemViewLayout();
                    int setViewResult = setView();
                    if (setViewResult == 0) {
                        if (mView.getParent() != null) {
                            mManager.removeViewImmediate(mView);
                        }
                        mManager.addView(mView, mParams);
                    }
                    Log.e("KCA", "show_excheckview_action " + String.valueOf(setViewResult));
                    mView.findViewById(R.id.excheckview_head).setOnClickListener(mViewClickListener);
                    mView.findViewById(R.id.excheck_detail_reward).setOnClickListener(mViewClickListener);
                    for (int i = 1; i < 4; i++) {
                        mView.findViewById(getId("fleet_".concat(String.valueOf(i + 1)), R.id.class)).setOnClickListener(mViewClickListener);
                    }
                    for (int i = 1; i <= 7; i++) {
                        mView.findViewById(getId("expd_world_".concat(String.valueOf(i)), R.id.class)).setOnClickListener(mViewClickListener);
                    }
                    for (int i = 0; i < 15; i++) {
                        mView.findViewById(KcaUtils.getId("expd_btn_".concat(String.valueOf(i)), R.id.class)).setOnClickListener(mViewClickListener);
                    }
                    mView.setVisibility(View.VISIBLE);
                } else {
                    stopSelf();
                }
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    private JsonObject checkFleetCondition(String data) {
        boolean total_pass = false;
        String cve_key = String.valueOf(STYPE_CVE);