导航菜单

页面标题

页面副标题

Plus 12 v10.13.1.1 - ConvertThemesActivity.java 源代码

正在查看: Plus 12 v10.13.1.1 应用的 ConvertThemesActivity.java JAVA 源代码文件

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


package org.telegram.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.PlusSettings;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.ActionBar.ThemeDescription;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.DocumentSelectActivity;

public class ConvertThemesActivity extends BaseFragment {
    public String PATH_TO_FILE;
    public String PATH_TO_SERVER;
    public Map<String, String> p2tMap;
    public Map<String, String> t2pMap;
    public String tempName;
    public TextView textView;
    public TextView textView2;
    public TextView textView3;

    public View createView(Context context) {
        ((BaseFragment) this).actionBar.setTitle(LocaleController.getString("ConvertThemes", R.string.ConvertThemes));
        ((BaseFragment) this).actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        ((BaseFragment) this).actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
                if (id == -1) {
                    ConvertThemesActivity.this.finishFragment();
                }
            }
        });
        RelativeLayout relativeLayout = new RelativeLayout(context);
        ((BaseFragment) this).fragmentView = relativeLayout;
        relativeLayout.setOnTouchListener(new View.OnTouchListener(this) {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        RelativeLayout relativeLayout2 = (RelativeLayout) ((BaseFragment) this).fragmentView;
        ScrollView scrollView = new ScrollView(context);
        relativeLayout2.addView(scrollView);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
        layoutParams.width = -1;
        layoutParams.height = -2;
        scrollView.setLayoutParams(layoutParams);
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(1);
        linearLayout.setPadding(0, AndroidUtilities.dp(20.0f), 0, AndroidUtilities.dp(20.0f));
        scrollView.addView(linearLayout);
        FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) linearLayout.getLayoutParams();
        layoutParams2.width = -1;
        layoutParams2.height = -2;
        linearLayout.setLayoutParams(layoutParams2);
        TextView textView = new TextView(context);
        this.textView = textView;
        textView.setTextSize(1, 24.0f);
        this.textView.setGravity(1);
        this.textView.setTextColor(Theme.usePlusTheme ? Theme.defColor : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        this.textView.setText(LocaleController.getString("LoadTheme", R.string.LoadTheme));
        linearLayout.addView(this.textView, LayoutHelper.createLinear(-2, -2, 1, 0, 20, 0, 0));
        this.textView.setOnClickListener(new AnonymousClass3());
        TextView textView2 = new TextView(context);
        this.textView2 = textView2;
        textView2.setTextColor(Theme.usePlusTheme ? Theme.prefTitleColor : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        this.textView2.setTextSize(1, 12.0f);
        this.textView2.setSingleLine(false);
        this.textView2.setAutoLinkMask(15);
        this.textView2.setLinksClickable(true);
        linearLayout.addView(this.textView2, LayoutHelper.createLinear(-2, -2, 80, 10, 20, 0, 0));
        TextView textView3 = new TextView(context);
        this.textView3 = textView3;
        textView3.setTextSize(1, 20.0f);
        this.textView3.setGravity(1);
        this.textView3.setVisibility(8);
        this.textView3.setTextColor(Theme.usePlusTheme ? Theme.defColor : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        linearLayout.addView(this.textView3, LayoutHelper.createLinear(-2, -2, 1, 0, 20, 0, 0));
        this.textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Object tag;
                if (ConvertThemesActivity.this.getParentActivity() == null || (tag = v.getTag()) == null) {
                    return;
                }
                File file = new File(tag.toString());
                Theme.ThemeInfo applyThemeFile = Theme.applyThemeFile(file, file.getName().replace(".attheme", ""), null, true);
                if (applyThemeFile != null) {
                    ConvertThemesActivity.this.presentFragment(new ThemePreviewActivity(applyThemeFile));
                }
            }
        });
        this.textView3.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public final boolean onLongClick(View view) {
                boolean lambda$createView$0;
                lambda$createView$0 = ConvertThemesActivity.this.lambda$createView$0(view);
                return lambda$createView$0;
            }
        });
        downloadFileAsync();
        return ((BaseFragment) this).fragmentView;
    }

    public class AnonymousClass3 implements View.OnClickListener {
        public AnonymousClass3() {
        }

        @Override
        public void onClick(View v) {
            if (ConvertThemesActivity.this.getParentActivity() == null) {
                return;
            }
            DocumentSelectActivity documentSelectActivity = new DocumentSelectActivity(false);
            documentSelectActivity.fileFilter = ".attheme";
            documentSelectActivity.arrayFilter = new String[]{".xml"};
            documentSelectActivity.setDelegate(new AnonymousClass1());
            ConvertThemesActivity.this.presentFragment(documentSelectActivity);
        }

        public class AnonymousClass1 implements DocumentSelectActivity.DocumentSelectActivityDelegate {
            @Override
            public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
            }

            @Override
            public void startDocumentSelectActivity() {
            }

            @Override
            public void startMusicSelectActivity(BaseFragment baseFragment) {
                DocumentSelectActivity.DocumentSelectActivityDelegate.CC.$default$startMusicSelectActivity(this, baseFragment);
            }

            public AnonymousClass1() {
            }

            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files, String caption, boolean notify, int scheduleDate) {
                activity.finishFragment();
                ConvertThemesActivity.this.textView2.setText("");
                ConvertThemesActivity.this.textView3.setVisibility(8);
                String str = files.get(0);
                File file = new File(str);
                String str2 = file.getName().split("\\.")[r5.length - 1];
                if (str2.contains("xml")) {
                    ConvertThemesActivity.this.textView2.append("\n");
                    if (ConvertThemesActivity.this.t2pMap != null) {
                        TextView textView = ConvertThemesActivity.this.textView2;
                        StringBuilder sb = new StringBuilder();
                        sb.append("");
                        sb.append(ConvertThemesActivity.this.t2pMap.size() - 1);
                        sb.append(" keys");
                        textView.append(sb.toString());
                    }
                    ConvertThemesActivity.this.textView2.append("\n");
                    AndroidUtilities.runOnUIThread(new RunnableC00171(str, file), 100L);
                    return;
                }
                if (str2.contains("attheme")) {
                    ConvertThemesActivity.this.textView2.append("\n");
                    ConvertThemesActivity.this.textView2.append("NOT SUPPORTED YET");
                }
            }

            public class RunnableC00171 implements Runnable {
                public final File val$themeFile;
                public final String val$xmlFile;

                public RunnableC00171(final String val$xmlFile, final File val$themeFile) {
                    this.val$xmlFile = val$xmlFile;
                    this.val$themeFile = val$themeFile;
                }

                @Override
                public void run() {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            ConvertThemesActivity.this.tempName = "temp_" + System.currentTimeMillis();
                            Activity parentActivity = ConvertThemesActivity.this.getParentActivity();
                            RunnableC00171 runnableC00171 = RunnableC00171.this;
                            if (Utilities.loadPrefFromSD(parentActivity, runnableC00171.val$xmlFile, ConvertThemesActivity.this.tempName, true) == 4) {
                                ConvertThemesActivity.this.textView2.append("\n");
                                ConvertThemesActivity.this.textView2.append("IN: " + RunnableC00171.this.val$themeFile.getAbsolutePath().replace(Environment.getExternalStorageDirectory().toString(), "..."));
                                AndroidUtilities.runOnUIThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences(ConvertThemesActivity.this.tempName, 0);
                                        RunnableC00171 runnableC001712 = RunnableC00171.this;
                                        ConvertThemesActivity.this.saveTheme(runnableC001712.val$xmlFile.replace(".xml", ".attheme"), sharedPreferences);
                                        Utilities.deletePrefFile(ConvertThemesActivity.this.getParentActivity(), ConvertThemesActivity.this.tempName);
                                    }
                                }, 100L);
                            }
                        }
                    }, 100L);
                }
            }
        }
    }

    public boolean lambda$createView$0(View view) {
        String obj;
        Object tag = view.getTag();
        if (tag != null && (obj = tag.toString()) != null && obj.length() > 0 && new File(obj).exists()) {
            Intent intent = new Intent("android.intent.action.SEND");
            intent.setType("*/attheme");
            File file = new File(obj);
            if (Build.VERSION.SDK_INT >= 24) {
                try {
                    intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(getParentActivity(), ApplicationLoader.getApplicationId() + ".provider", file));
                    intent.setFlags(1);
                } catch (Exception unused) {
                    intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(file));
                }
            } else {
                intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(file));
            }
            getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
        }
        return true;
    }

    public final void fileToHashMap(String filePath) {
        BufferedReader bufferedReader;
        this.p2tMap = new HashMap();
        this.t2pMap = new HashMap();
        try {
            bufferedReader = new BufferedReader(new FileReader(filePath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            bufferedReader = null;
        }
        while (true) {
            try {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    String[] split = readLine.split("=", 2);
                    if (split.length >= 2) {
                        String str = split[0];
                        if (!str.startsWith("#")) {
                            String str2 = split[1];
                            this.t2pMap.put(str, str2);
                            this.p2tMap.put(str2, str);
                        }
                    } else {
                        System.out.println("ignoring line: " + readLine);
                    }
                } else {
                    bufferedReader.close();
                    return;
                }
            } catch (IOException e2) {
                e2.printStackTrace();
                return;
            }
        }
    }

    public final void saveTheme(String str, SharedPreferences sharedPreferences) {
        Throwable th;
        FileOutputStream fileOutputStream;
        FileOutputStream fileOutputStream2;
        String str2 = "tmessage";
        int i = sharedPreferences.getInt("themeColor", Theme.defColor);
        int darkColor = AndroidUtilities.setDarkColor(i, 21);
        int darkColor2 = AndroidUtilities.setDarkColor(i, -64);
        Map<String, ?> all = sharedPreferences.getAll();
        Map<String, ?> all2 = sharedPreferences.getAll();
        this.textView2.append("\n");
        this.textView2.append(all.size() + " keys");
        StringBuilder sb = new StringBuilder();
        int i2 = 0;
        for (Map.Entry<String, String> entry : this.t2pMap.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            Object obj = all.get(value);
            if (obj == null) {
                if (value.equals("darkColor")) {
                    obj = Integer.valueOf(darkColor);
                }
                if (value.equals("lightColor")) {
                    obj = Integer.valueOf(darkColor2);
                }
            }
            if (obj != null) {
                sb.append(key);
                sb.append("=");
                sb.append(obj);
                sb.append("\n");
                i2++;
                all2.remove(value);
            }
        }
        for (Map.Entry<String, ?> entry2 : all2.entrySet()) {
            String key2 = entry2.getKey();
            Object value2 = entry2.getValue();
            if (!(value2 instanceof Boolean) && !(value2 instanceof String) && !TextUtils.isEmpty(key2) && !key2.endsWith("GradientColor") && !key2.endsWith("Gradient")) {
                key2.endsWith("Size");
            }
        }
        File file = new File(str);
        this.textView2.append("\n\n");
        this.textView2.append("OUT: " + file.getAbsolutePath().replace(Environment.getExternalStorageDirectory().toString(), ".."));
        ?? r4 = 0;
        r4 = 0;
        try {
            try {
                try {
                    fileOutputStream2 = new FileOutputStream(file);
                } catch (Throwable th2) {
                    th = th2;
                    fileOutputStream = r4;
                }
            } catch (Exception e) {
                e = e;
            }
        } catch (Exception e2) {
            r4 = e2;
            FileLog.e("tmessage", (Throwable) r4);
        }
        try {
            try {
                fileOutputStream2.write(sb.toString().getBytes());
                this.textView2.append("\n");
                this.textView2.append(i2 + " keys");
                File file2 = new File(str.replace(".attheme", "_wallpaper.jpg"));
                if (file2.exists()) {
                    try {
                        Point realScreenSize = AndroidUtilities.getRealScreenSize();
                        Bitmap loadBitmap = ImageLoader.loadBitmap(file2.getAbsolutePath(), (Uri) null, realScreenSize.x, realScreenSize.y, true);
                        if (loadBitmap != null) {
                            fileOutputStream2.write(new byte[]{87, 80, 83, 10});
                            loadBitmap.compress(Bitmap.CompressFormat.JPEG, 87, fileOutputStream2);
                            fileOutputStream2.write(new byte[]{10, 87, 80, 69, 10});
                            this.textView2.append("\n");
                            this.textView2.append("Wallpaper found and added: " + AndroidUtilities.formatFileSize(file2.length()));
                        }
                    } catch (Exception e3) {
                        FileLog.e(e3);
                    }
                }
                this.textView2.append("\n");
                TextView textView = this.textView2;
                String str3 = "Theme size: " + AndroidUtilities.formatFileSize(file.length()) + " bytes";
                textView.append(str3);
                fileOutputStream2.close();
                r4 = str3;
            } catch (Exception e4) {
                e = e4;
                r4 = fileOutputStream2;
                FileLog.e(e);
                if (r4 != 0) {
                    r4.close();
                    r4 = r4;
                }
                this.textView3.setText(file.getName());
                this.textView3.setTag(file.getAbsolutePath());
                str2 = null;
                this.textView3.setVisibility(0);
            }
            this.textView3.setText(file.getName());
            this.textView3.setTag(file.getAbsolutePath());
            str2 = null;
            this.textView3.setVisibility(0);
        } catch (Throwable th3) {
            th = th3;
            fileOutputStream = fileOutputStream2;
            if (fileOutputStream == null) {
                throw th;
            }
            try {
                fileOutputStream.close();
                throw th;
            } catch (Exception e5) {
                FileLog.e(str2, e5);
                throw th;
            }
        }
    }

    public final void downloadFileAsync() {
        StringBuilder sb = new StringBuilder();
        sb.append(Environment.getExternalStorageDirectory());
        sb.append(PlusSettings.usePlusFolder() ? "/Plus" : "/Telegram");
        sb.append("/Themes/t2p");
        this.PATH_TO_FILE = sb.toString();
        this.PATH_TO_SERVER = "https://plusmessenger.org/plus/t2p";
        new DownloadFilesTask().execute(new URL[0]);
    }

    public final String downloadRemoteTextFileContent() {
        URL url;
        try {
            url = new URL(this.PATH_TO_SERVER);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            url = null;
        }
        try {
            URLConnection openConnection = url.openConnection();
            openConnection.connect();
            int contentLength = openConnection.getContentLength();
            File file = new File(this.PATH_TO_FILE);
            if (file.exists() && file.length() == contentLength) {
                fileToHashMap(this.PATH_TO_FILE);
                return null;
            }
            BufferedInputStream bufferedInputStream = new BufferedInputStream(url.openStream(), 8192);
            FileOutputStream fileOutputStream = new FileOutputStream(this.PATH_TO_FILE);
            byte[] bArr = new byte[1024];
            long j = 0;
            while (true) {
                int read = bufferedInputStream.read(bArr);
                if (read != -1) {
                    j += read;
                    fileOutputStream.write(bArr, 0, read);
                } else {
                    String str = "" + j;
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    bufferedInputStream.close();
                    fileToHashMap(this.PATH_TO_FILE);
                    return str;
                }
            }
        } catch (IOException e2) {
            e2.printStackTrace();
            return "";
        }
    }

    public ArrayList<ThemeDescription> getThemeDescriptions() {
        return new ArrayList<>(Arrays.asList(new ThemeDescription(((BaseFragment) this).fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite), new ThemeDescription(((BaseFragment) this).actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault), new ThemeDescription(((BaseFragment) this).actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon), new ThemeDescription(((BaseFragment) this).actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), new ThemeDescription(((BaseFragment) this).actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector), new ThemeDescription(this.textView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText)));
    }

    public class DownloadFilesTask extends AsyncTask<URL, Void, String> {
        public long fs;

        public DownloadFilesTask() {
        }

        @Override
        public String doInBackground(URL... urls) {
            return ConvertThemesActivity.this.downloadRemoteTextFileContent();
        }

        @Override
        public void onPostExecute(String result) {
            ConvertThemesActivity.this.textView2.append("\n");
            this.fs = new File(ConvertThemesActivity.this.PATH_TO_FILE).length();
            if (result == null) {
                ConvertThemesActivity.this.textView2.append("Cache used: " + this.fs + " bytes");
            } else {
                ConvertThemesActivity.this.textView2.append("Old cache found. Updated: " + this.fs + " bytes");
            }
            if (ConvertThemesActivity.this.t2pMap != null) {
                ConvertThemesActivity.this.textView2.append("\n");
                TextView textView = ConvertThemesActivity.this.textView2;
                StringBuilder sb = new StringBuilder();
                sb.append("");
                sb.append(ConvertThemesActivity.this.t2pMap.size() - 1);
                sb.append(" keys");
                textView.append(sb.toString());
            }
        }
    }
}