public static final String SHOW_AKASHIVIEW_ACTION = "show_akashiview"; public static String getItemTranslation(String jp_name) {
    String name = jp_name;
    if (currentLocaleCode.equals("jp")) {
        return jp_name;
    } else if (kcItemTranslationData.has(name)) {
        name = kcItemTranslationData.get(name).getAsString();
    }
    return name;
} public static JsonObject getKcItemStatusById(int id, String list) {
    if (kcGameData == null) return null;
    JsonObject temp = new JsonObject();
    if (kcItemData.containsKey(id)) {
        if (list.equals("all")) {
            return kcItemData.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, kcItemData.get(id).get(api_item));
            }
            return temp.getAsJsonObject();
        }
    } else {
        return null;
    }

} 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 boolean isGameDataLoaded() {
    return kcGameData != null;
} public static boolean isItemAircraft(int id) {
    int result = Arrays.binarySearch(T2LIST_AIRCRAFTS, id);
    return result > -1;
} public static void loadTranslationData(Context context) {
    loadTranslationData(context, false);
} public static final String DB_KEY_DECKPORT = "key_deckport"; public static final String DB_KEY_USEITEMS = "key_useitems"; public static final String ERROR_TYPE_FLEETVIEW = "F"; public static final int KCANOTIFY_DB_VERSION = 5; public static final String PREF_FIX_VIEW_LOC = "fix_view_loc"; public static final String PREF_FV_MENU_ORDER = "fleetview_menu_order"; public static final String PREF_KCA_SEEK_CN = "kca_seek_cn"; public static final String PREF_VIEW_YLOC = "view_yloc"; public static final int SEEK_PURE = 0; public static final String SHOW_QUESTVIEW_ACTION_NEW = "show_questview_new"; public final static String CLOSE_FLEETVIEW = "CloseFleetView"; public final static String FV_BTN_PRESS = "FvBtnPress"; public final static String OPEN_FLEETVIEW = "OpenFleetView"; public static Boolean getBooleanPreferences(Context ctx, String key) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    return pref.getBoolean(key, false);
} public static Context getContextWithLocale(Context ac, Context bc) {
    Locale locale;
    String[] pref_locale = getStringPreferences(ac, PREF_KCA_LANGUAGE).split("-");
    if (pref_locale[0].toLowerCase().equals("default") || pref_locale.length < 2) {
        locale = Locale.getDefault();
    } else {
        locale = new Locale(pref_locale[0], pref_locale[1]);
    }
    Configuration configuration = new Configuration(ac.getResources().getConfiguration());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
        return bc.createConfigurationContext(configuration);
    } else {
        configuration.locale = locale;
        DisplayMetrics metrics = new DisplayMetrics();
        bc.getResources().updateConfiguration(configuration, bc.getResources().getDisplayMetrics());
        return bc;
    }
} 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 getStringPreferences(Context ctx, String key) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    try {
        return String.valueOf(pref.getInt(key, 0));
    } catch (Exception e) {
        // Nothing to do
    }
    return pref.getString(key, "");
} 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;
} public static void sendUserAnalytics(Context context, String event, JsonObject value) {
    Bundle params = new Bundle();
    FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);
    if (value != null) {
        for (String key: value.keySet()) {
            params.putString(key, value.get(key).getAsString());
        }
    }
    mFirebaseAnalytics.logEvent(event, params);
} public static void setPreferences(Context ctx, String key, Object value) {
    SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = pref.edit();
    if (value instanceof String) {
        editor.putString(key, (String) value);
    } else if (value instanceof Boolean) {
        editor.putBoolean(key, (Boolean) value);
    } else if (value instanceof Integer) {
        editor.putString(key, String.valueOf(value));
    } else {
        editor.putString(key, value.toString());
    }
    editor.commit();
}
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.Settings;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.google.common.io.ByteStreams;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static com.antest1.kcanotify.KcaAkashiViewService.SHOW_AKASHIVIEW_ACTION;
import static com.antest1.kcanotify.KcaApiData.getItemTranslation;
import static com.antest1.kcanotify.KcaApiData.getKcItemStatusById;
import static com.antest1.kcanotify.KcaApiData.getUserItemStatusById;
import static com.antest1.kcanotify.KcaApiData.isGameDataLoaded;
import static com.antest1.kcanotify.KcaApiData.isItemAircraft;
import static com.antest1.kcanotify.KcaApiData.loadTranslationData;
import static com.antest1.kcanotify.KcaConstants.DB_KEY_DECKPORT;
import static com.antest1.kcanotify.KcaConstants.DB_KEY_USEITEMS;
import static com.antest1.kcanotify.KcaConstants.ERROR_TYPE_FLEETVIEW;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION;
import static com.antest1.kcanotify.KcaConstants.PREF_FIX_VIEW_LOC;
import static com.antest1.kcanotify.KcaConstants.PREF_FV_MENU_ORDER;
import static com.antest1.kcanotify.KcaConstants.PREF_KCA_SEEK_CN;
import static com.antest1.kcanotify.KcaConstants.PREF_VIEW_YLOC;
import static com.antest1.kcanotify.KcaConstants.SEEK_PURE;
import static com.antest1.kcanotify.KcaQuestViewService.SHOW_QUESTVIEW_ACTION_NEW;
import static com.antest1.kcanotify.KcaUseStatConstant.CLOSE_FLEETVIEW;
import static com.antest1.kcanotify.KcaUseStatConstant.FV_BTN_PRESS;
import static com.antest1.kcanotify.KcaUseStatConstant.OPEN_FLEETVIEW;
import static com.antest1.kcanotify.KcaUtils.getBooleanPreferences;
import static com.antest1.kcanotify.KcaUtils.getContextWithLocale;
import static com.antest1.kcanotify.KcaUtils.getId;
import static com.antest1.kcanotify.KcaUtils.getStringFromException;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.getWindowLayoutType;
import static com.antest1.kcanotify.KcaUtils.joinStr;
import static com.antest1.kcanotify.KcaUtils.sendUserAnalytics;
import static com.antest1.kcanotify.KcaUtils.setPreferences;
import static org.apache.commons.lang3.StringUtils.split;
        }
        if (itemView != null) {
            if (itemView.getParent() != null) mManager.removeViewImmediate(itemView);
        }
        super.onDestroy();
    }

    private void setFleetMenu() {
        LinearLayout fleetMenuArea = mView.findViewById(R.id.viewbutton_area);
        List<TextView> menuBtnList = new ArrayList<>();
        for (int i = 0; i < fleetview_menu_keys.length; i++) {
            String key = fleetview_menu_keys[i];
            TextView tv = mView.findViewById(KcaUtils.getId(KcaUtils.format("viewbutton_%s", key), R.id.class));
            tv.setText(getStringWithLocale(KcaUtils.getId(KcaUtils.format("viewmenu_%s", key), R.string.class)));
            tv.setOnTouchListener(mViewTouchListener);
            menuBtnList.add(tv);
            ((ViewGroup) tv.getParent()).removeView(tv);
        }

        String order_data = getStringPreferences(getApplicationContext(), PREF_FV_MENU_ORDER);
        if (order_data.length() > 0) {
            JsonArray order = new JsonParser().parse(order_data).getAsJsonArray();
            for (int i = 0; i < order.size(); i++) {
                fleetMenuArea.addView(menuBtnList.get(order.get(i).getAsInt()));
            }
        } else {
            for (TextView tv: menuBtnList) {
                fleetMenuArea.addView(tv);
            }
        }
    }

    private void initView() {
        mView = mInflater.inflate(R.layout.view_fleet_list, null);
        mView.setVisibility(GONE);
        KcaUtils.resizeFullWidthView(getApplicationContext(), mView);
        mView.findViewById(R.id.fleetview_shiparea).setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.fleetview_tool).setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.fleetview_head).setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.fleetview_cn_change).setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.fleetview_fleetswitch).setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.fleetview_hqinfo).setOnTouchListener(mViewTouchListener);

        for (int i = 0; i < 5; i++) {
            mView.findViewById(getId("fleet_".concat(String.valueOf(i + 1)), R.id.class)).setOnTouchListener(mViewTouchListener);
        }
        for (int i = 0; i < 12; i++) {
//            mView.findViewById(getId("fleetview_item_".concat(String.valueOf(i + 1)), R.id.class)).setOnTouchListener(mViewTouchListener);
            getFleetViewItem(i).setOnTouchListener(mViewTouchListener);
        }

        setFleetMenu();
        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
        mParams.gravity = KcaUtils.getGravity(view_status);
        setPreferences(getApplicationContext(), PREF_VIEW_YLOC, view_status);

        fleetInfoLine = mView.findViewById(R.id.fleetview_infoline);

        fleetInfoLine.setOnTouchListener(mViewTouchListener);

        fleetInfoTitle = mView.findViewById(R.id.fleetview_title);
        fleetHqInfoView = mView.findViewById(R.id.fleetview_hqinfo);
        fleetCnChangeBtn = mView.findViewById(R.id.fleetview_cn_change);
        fleetAkashiTimerBtn = mView.findViewById(R.id.fleetview_akashi_timer);
        fleetSwitchBtn = mView.findViewById(R.id.fleetview_fleetswitch);
        fleetSwitchBtn.setVisibility(View.GONE);
        fleetShipArea = mView.findViewById(R.id.fleetview_shiparea);
        fleetMenu = mView.findViewById(R.id.fleetview_menu);
        fleetMenuArrowUp = mView.findViewById(R.id.fleetview_menu_up);
        fleetMenuArrowDown = mView.findViewById(R.id.fleetview_menu_down);
        fleetMenu.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                ViewTreeObserver observer = fleetMenu.getViewTreeObserver();
                observer.addOnScrollChangedListener(fleetMenuScrollChangeListener);
                return false;
            }
        });
    }

    final ViewTreeObserver.OnScrollChangedListener fleetMenuScrollChangeListener = new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (fleetMenu != null && fleetMenuArrowUp != null && fleetMenuArrowDown != null) {
                if (fleetMenu.getScrollY() < fleetview_menu_margin) {
                    fleetMenuArrowUp.setVisibility(View.GONE);
                    fleetMenuArrowDown.setAlpha(0.9f);
                } else if (fleetMenu.getChildAt(0).getBottom() - (fleetMenu.getHeight() + fleetMenu.getScrollY()) < fleetview_menu_margin) {
                    fleetMenuArrowDown.setVisibility(View.GONE);
                    fleetMenuArrowUp.setAlpha(0.9f);
                } else {
                    fleetMenuArrowUp.setVisibility(View.VISIBLE);
                    fleetMenuArrowDown.setVisibility(View.VISIBLE);
                    fleetMenuArrowUp.setAlpha(0.6f);
                    fleetMenuArrowDown.setAlpha(0.6f);
                }
            }
        }
    };

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null && intent.getAction() != null) {
            if (intent.getAction().equals(SHOW_FLEETVIEW_ACTION)) {
                if (mView != null && mView.getVisibility() != View.VISIBLE) {
                    if (seekcn_internal == -1) seekcn_internal = getSeekCn();
                    fleetCnChangeBtn.setText(getSeekType());
                    int setViewResult = setView();
                    if (setViewResult == 0) {
                        mView.setVisibility(View.VISIBLE);
                        if (mView.getParent() != null) {
                            mManager.removeViewImmediate(mView);
                        }
                        mManager.addView(mView, mParams);
                    }
                    sendUserAnalytics(getApplicationContext(), OPEN_FLEETVIEW, null);