导航菜单

页面标题

页面副标题

Delta Chat v1.58.3 - ChatBackgroundActivity.java 源代码

正在查看: Delta Chat v1.58.3 应用的 ChatBackgroundActivity.java JAVA 源代码文件

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


package org.thoughtcrime.securesms.preferences;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.concurrent.ExecutionException;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.AttachmentManager;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.preferences.ChatBackgroundActivity;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.ServiceUtil;

public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity {
    private int accountId;
    Button defaultButton;
    Button galleryButton;
    Boolean imageUpdate = false;
    Uri imageUri;
    ImageView preview;
    String tempDestinationPath;

    @Override
    protected void onCreate(Bundle bundle, boolean z) {
        setContentView(R.layout.activity_select_chat_background);
        this.defaultButton = (Button) findViewById(R.id.set_default_button);
        this.galleryButton = (Button) findViewById(R.id.from_gallery_button);
        this.preview = (ImageView) findViewById(R.id.preview);
        this.accountId = DcHelper.getContext(getApplicationContext()).getAccountId();
        this.defaultButton.setOnClickListener(new DefaultClickListener());
        this.galleryButton.setOnClickListener(new GalleryClickListener());
        String backgroundImagePath = Prefs.getBackgroundImagePath(this, this.accountId);
        if (backgroundImagePath.isEmpty()) {
            setDefaultLayoutBackgroundImage();
        } else {
            setLayoutBackgroundImage(backgroundImagePath);
        }
        ActionBar supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.setTitle(R.string.pref_background);
            supportActionBar.setDisplayHomeAsUpEnabled(true);
            supportActionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        }
    }

    public boolean onPrepareOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menu.clear();
        menuInflater.inflate(R.menu.chat_background, menu);
        super.onPrepareOptionsMenu(menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId != R.id.apply_background) {
            if (itemId == 16908332) {
                finish();
                return true;
            }
            return super.onOptionsItemSelected(menuItem);
        }
        final Context applicationContext = getApplicationContext();
        if (this.imageUpdate.booleanValue()) {
            if (this.imageUri != null) {
                new Thread() {
                    @Override
                    public void run() {
                        String str = applicationContext.getFilesDir().getAbsolutePath() + "/background." + ChatBackgroundActivity.this.accountId;
                        Prefs.setBackgroundImagePath(applicationContext, ChatBackgroundActivity.this.accountId, str);
                        ChatBackgroundActivity.this.scaleAndSaveImage(applicationContext, str);
                    }
                }.start();
            } else {
                Prefs.setBackgroundImagePath(applicationContext, this.accountId, "");
            }
        }
        finish();
        return true;
    }

    public void scaleAndSaveImage(Context context, String str) {
        try {
            Display defaultDisplay = ServiceUtil.getWindowManager(context).getDefaultDisplay();
            Point point = new Point();
            defaultDisplay.getSize(point);
            int max = Math.max(point.x, point.y);
            ((Bitmap) GlideApp.with(context).asBitmap().m1456load(this.imageUri).fitCenter().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit(max, max).get()).compress(Bitmap.CompressFormat.JPEG, 85, new FileOutputStream(str));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Prefs.setBackgroundImagePath(context, this.accountId, "");
            showBackgroundSaveError();
        } catch (InterruptedException e2) {
            e = e2;
            e.printStackTrace();
            Prefs.setBackgroundImagePath(context, this.accountId, "");
            showBackgroundSaveError();
        } catch (ExecutionException e3) {
            e = e3;
            e.printStackTrace();
            Prefs.setBackgroundImagePath(context, this.accountId, "");
            showBackgroundSaveError();
        }
    }

    public void setLayoutBackgroundImage(String str) {
        this.preview.setImageDrawable(Drawable.createFromPath(str));
    }

    public void setDefaultLayoutBackgroundImage() {
        if (DynamicTheme.isDarkTheme(this)) {
            this.preview.setImageDrawable(getResources().getDrawable(R.drawable.background_hd_dark));
        } else {
            this.preview.setImageDrawable(getResources().getDrawable(R.drawable.background_hd));
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        Context applicationContext = getApplicationContext();
        if (intent == null || applicationContext == null || i2 != -1 || i != 11) {
            return;
        }
        Uri data = intent.getData();
        this.imageUri = data;
        if (data != null) {
            new AnonymousClass2(applicationContext).start();
        }
        this.imageUpdate = true;
    }

    class AnonymousClass2 extends Thread {
        final Context val$context;

        AnonymousClass2(Context context) {
            this.val$context = context;
        }

        @Override
        public void run() {
            ChatBackgroundActivity.this.tempDestinationPath = this.val$context.getFilesDir().getAbsolutePath() + "/background-temp";
            ChatBackgroundActivity chatBackgroundActivity = ChatBackgroundActivity.this;
            chatBackgroundActivity.scaleAndSaveImage(this.val$context, chatBackgroundActivity.tempDestinationPath);
            ChatBackgroundActivity.this.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    ChatBackgroundActivity.AnonymousClass2.this.m1552x88a0f7e4();
                }
            });
        }

        void m1552x88a0f7e4() {
            ChatBackgroundActivity chatBackgroundActivity = ChatBackgroundActivity.this;
            chatBackgroundActivity.setLayoutBackgroundImage(chatBackgroundActivity.tempDestinationPath);
        }
    }

    private void showBackgroundSaveError() {
        Toast.makeText((Context) this, R.string.error, 1).show();
    }

    private class DefaultClickListener implements View.OnClickListener {
        private DefaultClickListener() {
        }

        @Override
        public void onClick(View view) {
            ChatBackgroundActivity.this.imageUri = null;
            ChatBackgroundActivity.this.tempDestinationPath = "";
            ChatBackgroundActivity.this.setDefaultLayoutBackgroundImage();
            ChatBackgroundActivity.this.imageUpdate = true;
        }
    }

    private class GalleryClickListener implements View.OnClickListener {
        private GalleryClickListener() {
        }

        @Override
        public void onClick(View view) {
            AttachmentManager.selectImage(ChatBackgroundActivity.this, 11);
        }
    }
}