导航菜单

页面标题

页面副标题

Zepto v25.1.4 - MapplsStylesHelper.java 源代码

正在查看: Zepto v25.1.4 应用的 MapplsStylesHelper.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mappls.sdk.maps;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.media.a;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
import com.google.gson.Gson;
import com.mappls.android.lms.MapplsLMSManager;
import com.mappls.sdk.maps.AutoValue_MapplsGetStyle;
import com.mappls.sdk.maps.style.IStyleListener;
import com.mappls.sdk.maps.style.model.MapplsStyle;
import com.mappls.sdk.maps.utils.BitmapUtils;
import com.mappls.sdk.services.utils.MapplsUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

@Keep
public class MapplsStylesHelper {
    private static final String STYLE_ERROR_CODE = "Something went wrong - 101";
    private String baseUrl;
    private MapplsStyle defaultStyle;
    private String logoBaseUrl;
    private final Context mContext;
    private final PreferenceHelper preferenceHelper;
    private final List<MapplsStyle> styleList = new ArrayList();
    private final HashMap<String, StyleData> styleHashMap = new HashMap<>();
    private final HashMap<String, Bitmap> logoHashMap = new HashMap<>();
    private final HashMap<String, LogoData> logoDataHashMap = new HashMap<>();

    public MapplsStylesHelper(Context context) {
        this.mContext = context;
        this.preferenceHelper = new PreferenceHelper(context);
    }

    private void downloadImage(String str, final LogoData logoData, final LogoImageLoadCallback logoImageLoadCallback) {
        File file = new File(this.mContext.getFilesDir(), logoData.getLogoId());
        file.mkdir();
        final File file2 = new File(file, logoData.getModified() + ".jpg");
        if (file2.exists()) {
            Bitmap decodeFile = BitmapFactory.decodeFile(file2.getAbsolutePath());
            this.logoHashMap.put(logoData.getLogoId(), decodeFile);
            if (logoImageLoadCallback != null) {
                logoImageLoadCallback.a(decodeFile);
                return;
            }
            return;
        }
        for (File file3 : file.listFiles()) {
            if (file3 != null) {
                file3.delete();
            }
        }
        StringBuilder t = a.t(str);
        t.append(logoData.getLogoUrl());
        getBitmap(t.toString(), new OnImageAdded() {
            @Override
            public final void a(Bitmap bitmap) {
                MapplsStylesHelper mapplsStylesHelper = MapplsStylesHelper.this;
                mapplsStylesHelper.logoHashMap.put(logoData.getLogoId(), bitmap);
                mapplsStylesHelper.saveImageToFile(bitmap, file2.getAbsolutePath());
                LogoImageLoadCallback logoImageLoadCallback2 = logoImageLoadCallback;
                if (logoImageLoadCallback2 != null) {
                    logoImageLoadCallback2.a(bitmap);
                }
            }
        });
    }

    private String getBaseUrl() {
        return this.baseUrl;
    }

    private void getBitmap(final String str, final OnImageAdded onImageAdded) {
        Executors.newSingleThreadExecutor().execute(new Runnable() {
            @Override
            public final void run() {
                URL url;
                Bitmap bitmap = null;
                try {
                    url = new URL(str);
                } catch (MalformedURLException e2) {
                    e2.printStackTrace();
                    url = null;
                }
                try {
                    bitmap = BitmapFactory.decodeStream(((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection())).getInputStream());
                } catch (IOException e3) {
                    e3.printStackTrace();
                }
                onImageAdded.a(bitmap);
            }
        });
    }

    private void getLogos(String str, List<LogoData> list) {
        if (list == null) {
            return;
        }
        for (LogoData logoData : list) {
            this.logoDataHashMap.put(logoData.getLogoId(), logoData);
            downloadImage(str, logoData, null);
        }
    }

    public void initStyles(GetStylesResponse getStylesResponse) {
        this.baseUrl = getStylesResponse.getBaseUrl();
        this.logoBaseUrl = getStylesResponse.getBaseUrlLogo();
        this.styleList.clear();
        for (StyleData styleData : getStylesResponse.getData()) {
            String name = styleData.getName();
            String displayName = styleData.getDisplayName();
            String description = styleData.getDescription();
            String str = this.baseUrl + styleData.getImageUrl();
            styleData.isDefault();
            MapplsStyle mapplsStyle = new MapplsStyle();
            mapplsStyle.a = description;
            mapplsStyle.b = displayName;
            mapplsStyle.c = str;
            mapplsStyle.f1784d = name;
            this.styleList.add(mapplsStyle);
            this.styleHashMap.put(styleData.getName(), styleData);
            if (styleData.isDefault().intValue() == 1) {
                this.defaultStyle = mapplsStyle;
            }
        }
        getLogos(getStylesResponse.getBaseUrlLogo(), getStylesResponse.getLogoData());
    }

    public void saveImageToFile(Bitmap bitmap, String str) {
        FileOutputStream fileOutputStream;
        ?? r0 = 0;
        FileOutputStream fileOutputStream2 = null;
        r0 = 0;
        try {
            try {
                try {
                    fileOutputStream = new FileOutputStream(str);
                } catch (Throwable th) {
                    th = th;
                }
            } catch (Exception e2) {
                e = e2;
            }
        } catch (Exception e3) {
            e3.printStackTrace();
            r0 = r0;
        }
        try {
            bitmap.setHasAlpha(true);
            r0 = 100;
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
            fileOutputStream.close();
        } catch (Exception e4) {
            e = e4;
            fileOutputStream2 = fileOutputStream;
            e.printStackTrace();
            r0 = fileOutputStream2;
            if (fileOutputStream2 != null) {
                fileOutputStream2.close();
                r0 = fileOutputStream2;
            }
        } catch (Throwable th2) {
            th = th2;
            r0 = fileOutputStream;
            if (r0 != 0) {
                try {
                    r0.close();
                } catch (Exception e5) {
                    e5.printStackTrace();
                }
            }
            throw th;
        }
    }

    public synchronized void getBitmapLogo(String str, @NonNull LogoImageLoadCallback logoImageLoadCallback) {
        try {
            StyleData styleData = this.styleHashMap.get(str);
            if (styleData == null || styleData.getLogoIdIndia() == null) {
                logoImageLoadCallback.a(BitmapUtils.a(ContextCompat.d(Mappls.getApplicationContext(), R.drawable.mappls_maps_logo_icon)));
            } else if (this.logoHashMap.containsKey(styleData.getLogoIdIndia())) {
                logoImageLoadCallback.a(this.logoHashMap.get(styleData.getLogoIdIndia()));
            } else if (this.logoDataHashMap.containsKey(styleData.getLogoIdIndia())) {
                downloadImage(this.logoBaseUrl, this.logoDataHashMap.get(styleData.getLogoIdIndia()), logoImageLoadCallback);
            } else {
                logoImageLoadCallback.D();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public MapplsStyle getDefaultStyle() {
        return this.defaultStyle;
    }

    public synchronized void getGlobalBitmapLogo(String str, @NonNull LogoImageLoadCallback logoImageLoadCallback) {
        try {
            StyleData styleData = this.styleHashMap.get(str);
            if (styleData == null || styleData.getGlobalLogoId() == null) {
                logoImageLoadCallback.a(BitmapUtils.a(ContextCompat.d(Mappls.getApplicationContext(), R.drawable.mappls_maps_logo_icon)));
            } else if (this.logoHashMap.containsKey(styleData.getGlobalLogoId())) {
                logoImageLoadCallback.a(this.logoHashMap.get(styleData.getGlobalLogoId()));
            } else if (this.logoDataHashMap.containsKey(styleData.getGlobalLogoId())) {
                downloadImage(this.logoBaseUrl, this.logoDataHashMap.get(styleData.getGlobalLogoId()), logoImageLoadCallback);
            } else {
                logoImageLoadCallback.D();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public MapplsStyle getLastSelectedStyle() {
        return getStyle(this.preferenceHelper.a.getSharedPreferences("com.mappls.sdk.maps_mappls_style", 0).getString("com.mappls.sdk.maps.key_last_selected_style", null));
    }

    public MapplsStyle getStyle(String str) {
        MapplsStyle mapplsStyle = null;
        if (str != null) {
            for (MapplsStyle mapplsStyle2 : this.styleList) {
                if (mapplsStyle2.f1784d.equalsIgnoreCase(str)) {
                    mapplsStyle = mapplsStyle2;
                }
            }
        }
        return mapplsStyle;
    }

    public List<MapplsStyle> getStyleList() {
        return this.styleList;
    }

    public String getStyleUrl(MapplsStyle mapplsStyle) {
        if (!this.styleHashMap.containsKey(mapplsStyle.f1784d)) {
            return null;
        }
        StyleData styleData = this.styleHashMap.get(mapplsStyle.f1784d);
        if (styleData.getStyleUrl().startsWith("https://") || styleData.getStyleUrl().startsWith("http://")) {
            return styleData.getStyleUrl();
        }
        return this.baseUrl + styleData.getStyleUrl();
    }

    public void initialiseStyles(final IStyleListener iStyleListener) {
        if (this.baseUrl != null && this.styleList != null && this.defaultStyle != null) {
            if (iStyleListener != null) {
                iStyleListener.onSuccess();
                return;
            }
            return;
        }
        AutoValue_MapplsGetStyle.Builder builder = new AutoValue_MapplsGetStyle.Builder();
        builder.a = "https://apis.mappls.com/advancedmaps/vapi/";
        String str = "drawable-" + MapplsUtils.getDensityName();
        if (str == null) {
            throw new NullPointerException("Null logoResolution");
        }
        builder.b = str;
        builder.a().enqueueCall(new Callback<GetStylesResponse>() {
            @Override
            public final void a(Call call, Throwable th) {
                th.printStackTrace();
                MapplsStylesHelper mapplsStylesHelper = MapplsStylesHelper.this;
                GetStylesResponse a = mapplsStylesHelper.preferenceHelper.a();
                IStyleListener iStyleListener2 = iStyleListener;
                if (a != null) {
                    mapplsStylesHelper.initStyles(mapplsStylesHelper.preferenceHelper.a());
                    if (iStyleListener2 != null) {
                        iStyleListener2.onSuccess();
                    }
                } else if (iStyleListener2 != null) {
                    iStyleListener2.a(5, MapplsStylesHelper.STYLE_ERROR_CODE);
                }
                if (MapplsLMSManager.isInitialised()) {
                    try {
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("error_code", 5);
                        jSONObject.put("error_message", th.getMessage());
                        jSONObject.put("is_load_from_cache", mapplsStylesHelper.preferenceHelper.a() != null);
                        MapplsLMSManager.getInstance().add("style-api-error", "mappls-map", "8.2.6", jSONObject);
                    } catch (JSONException unused) {
                    }
                }
            }

            @Override
            public final void b(Call call, Response response) {
                int i2 = response.a.f6663d;
                IStyleListener iStyleListener2 = iStyleListener;
                if (i2 == 200) {
                    GetStylesResponse getStylesResponse = (GetStylesResponse) response.b;
                    MapplsStylesHelper mapplsStylesHelper = MapplsStylesHelper.this;
                    PreferenceHelper preferenceHelper = mapplsStylesHelper.preferenceHelper;
                    if (getStylesResponse == null) {
                        preferenceHelper.getClass();
                    } else {
                        SharedPreferences.Editor edit = preferenceHelper.a.getSharedPreferences("com.mappls.sdk.maps_mappls_style", 0).edit();
                        edit.putString("com.mappls.sdk.maps.key_mappls_style_list", new Gson().j(getStylesResponse));
                        edit.apply();
                    }
                    mapplsStylesHelper.initStyles(getStylesResponse);
                    if (MapplsLMSManager.isInitialised()) {
                        try {
                            JSONObject jSONObject = new JSONObject();
                            if (mapplsStylesHelper.defaultStyle != null) {
                                jSONObject.put("default_style", mapplsStylesHelper.defaultStyle.f1784d);
                            }
                            if (mapplsStylesHelper.getLastSelectedStyle() != null) {
                                jSONObject.put("last_selected_style", mapplsStylesHelper.getLastSelectedStyle().f1784d);
                            }
                            MapplsLMSManager.getInstance().add("style-api-success", "mappls-map", "8.2.6", jSONObject);
                        } catch (JSONException unused) {
                        }
                    }
                    if (iStyleListener2 != null) {
                        iStyleListener2.onSuccess();
                        return;
                    }
                    return;
                }
                okhttp3.Response response2 = response.a;
                if (i2 == 7 || i2 == 8 || i2 == 9 || i2 == 101 || i2 == 102 || i2 == 103) {
                    if (MapplsLMSManager.isInitialised()) {
                        try {
                            JSONObject jSONObject2 = new JSONObject();
                            jSONObject2.put("error_code", response2.f6663d);
                            jSONObject2.put("error_message", response2.c);
                            MapplsLMSManager.getInstance().add("style-api-error", "mappls-map", "8.2.6", jSONObject2);
                        } catch (JSONException unused2) {
                        }
                    }
                    if (iStyleListener2 != null) {
                        iStyleListener2.a(response2.f6663d, response2.c);
                        return;
                    }
                    return;
                }
                if (MapplsLMSManager.isInitialised()) {
                    try {
                        JSONObject jSONObject3 = new JSONObject();
                        jSONObject3.put("error_code", response2.f6663d);
                        jSONObject3.put("error_message", response2.c);
                        MapplsLMSManager.getInstance().add("style-api-error", "mappls-map", "8.2.6", jSONObject3);
                    } catch (JSONException unused3) {
                    }
                }
                if (iStyleListener2 != null) {
                    iStyleListener2.a(response2.f6663d, MapplsStylesHelper.STYLE_ERROR_CODE);
                }
            }
        });
    }

    public void setSelectedStyle(String str) {
        PreferenceHelper preferenceHelper = this.preferenceHelper;
        if (str == null) {
            preferenceHelper.getClass();
            return;
        }
        SharedPreferences.Editor edit = preferenceHelper.a.getSharedPreferences("com.mappls.sdk.maps_mappls_style", 0).edit();
        edit.putString("com.mappls.sdk.maps.key_last_selected_style", str);
        edit.apply();
    }
}