导航菜单

页面标题

页面副标题

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

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

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


package org.thoughtcrime.securesms;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import java.io.File;
import java.io.IOException;
import java.security.SecureRandom;
import org.thoughtcrime.securesms.components.AvatarSelector;
import org.thoughtcrime.securesms.components.InputAwareLayout;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
import org.thoughtcrime.securesms.mms.AttachmentManager;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.ViewUtil;

public class CreateProfileActivity extends BaseActionBarActivity {
    public static final String FROM_WELCOME = "from_welcome";
    private static final int REQUEST_CODE_AVATAR = 1;
    private static final String TAG = "CreateProfileActivity";
    private AttachmentManager attachmentManager;
    private ImageView avatar;
    private Bitmap avatarBmp;
    private boolean avatarChanged;
    private InputAwareLayout container;
    private boolean fromWelcome;
    private boolean imageLoaded;
    private EditText name;
    private EditText statusView;

    static void lambda$onCreate$0() {
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.fromWelcome = getIntent().getBooleanExtra("from_welcome", false);
        setContentView(R.layout.profile_create_activity);
        getSupportActionBar().setTitle(R.string.pref_profile_info_headline);
        getSupportActionBar().setDisplayHomeAsUpEnabled(!this.fromWelcome);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        this.attachmentManager = new AttachmentManager(this, new AttachmentManager.AttachmentListener() {
            @Override
            public final void onAttachmentChanged() {
                CreateProfileActivity.lambda$onCreate$0();
            }
        });
        this.avatarChanged = false;
        initializeResources();
        initializeProfileName();
        initializeProfileAvatar();
        initializeStatusText();
    }

    public boolean onPrepareOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.preferences_create_profile_menu, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        super.onOptionsItemSelected(menuItem);
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            onBackPressed();
            return true;
        }
        if (itemId != R.id.menu_create_profile) {
            return false;
        }
        updateProfile();
        return false;
    }

    public void onBackPressed() {
        if (this.container.isInputOpen()) {
            this.container.hideCurrentInput(this.name);
        } else if (this.fromWelcome) {
            updateProfile();
        } else {
            super.onBackPressed();
        }
    }

    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        Permissions.onRequestPermissionsResult((Activity) this, i, strArr, iArr);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != -1) {
            return;
        }
        if (i == 1) {
            onFileSelected(intent != null ? intent.getData() : null);
        } else {
            if (i != 31424) {
                return;
            }
            setAvatarView(intent.getData());
        }
    }

    private void setAvatarView(Uri uri) {
        ProfileMediaConstraints profileMediaConstraints = new ProfileMediaConstraints();
        GlideApp.with((FragmentActivity) this).asBitmap().m1456load(uri).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(profileMediaConstraints.getImageMaxWidth(this), profileMediaConstraints.getImageMaxHeight(this)).into(new SimpleTarget<Bitmap>() {
            public void onResourceReady(Object obj, Transition transition) {
                onResourceReady((Bitmap) obj, (Transition<? super Bitmap>) transition);
            }

            public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                CreateProfileActivity.this.avatarChanged = true;
                CreateProfileActivity.this.imageLoaded = true;
                CreateProfileActivity.this.avatarBmp = bitmap;
            }
        });
        GlideApp.with((FragmentActivity) this).m1513load(uri).circleCrop().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(this.avatar);
    }

    public void onFileSelected(Uri uri) {
        if (uri == null) {
            uri = this.attachmentManager.getImageCaptureUri();
        }
        AvatarHelper.cropAvatar(this, uri);
    }

    private void initializeResources() {
        TextView textView = (TextView) ViewUtil.findById((Activity) this, R.id.login_success_text);
        this.avatar = (ImageView) ViewUtil.findById((Activity) this, R.id.avatar);
        this.name = (EditText) ViewUtil.findById((Activity) this, R.id.name_text);
        this.container = (InputAwareLayout) ViewUtil.findById((Activity) this, R.id.container);
        this.statusView = (EditText) ViewUtil.findById((Activity) this, R.id.status_text);
        if (this.fromWelcome) {
            DcHelper.get(this, DcHelper.CONFIG_ADDRESS);
            textView.setText(R.string.set_name_and_avatar_explain);
            ViewUtil.findById((Activity) this, R.id.status_text_layout).setVisibility(8);
            ViewUtil.findById((Activity) this, R.id.information_label).setVisibility(8);
            return;
        }
        textView.setVisibility(8);
    }

    private void initializeProfileName() {
        String str = DcHelper.get(this, DcHelper.CONFIG_DISPLAY_NAME);
        if (TextUtils.isEmpty(str)) {
            return;
        }
        this.name.setText(str);
        this.name.setSelection(str.length(), str.length());
    }

    private void initializeProfileAvatar() {
        File selfAvatarFile = AvatarHelper.getSelfAvatarFile(this);
        if (selfAvatarFile.exists() && selfAvatarFile.length() > 0) {
            this.imageLoaded = true;
            GlideApp.with((FragmentActivity) this).m1514load(selfAvatarFile).circleCrop().into(this.avatar);
        } else {
            this.imageLoaded = false;
            this.avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(this, getResources().getColor(R.color.grey_400)));
        }
        this.avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CreateProfileActivity.this.m1234x838fd748(view);
            }
        });
    }

    void m1234x838fd748(View view) {
        new AvatarSelector(this, LoaderManager.getInstance(this), new AvatarSelectedListener(), this.imageLoaded).show(this, this.avatar);
    }

    private void initializeStatusText() {
        this.statusView.setText(DcHelper.get(this, DcHelper.CONFIG_SELF_STATUS));
    }

    private void updateProfile() {
        if (TextUtils.isEmpty(this.name.getText())) {
            Toast.makeText((Context) this, R.string.please_enter_name, 1).show();
        } else {
            final String obj = this.name.getText().toString();
            new AsyncTask<Void, Void, Boolean>() {
                @Override
                public Boolean doInBackground(Void... voidArr) {
                    DcHelper.set(CreateProfileActivity.this, DcHelper.CONFIG_DISPLAY_NAME, obj);
                    CreateProfileActivity.this.setStatusText();
                    if (CreateProfileActivity.this.avatarChanged) {
                        try {
                            ?? r3 = CreateProfileActivity.this;
                            AvatarHelper.setSelfAvatar(r3, ((CreateProfileActivity) r3).avatarBmp);
                            Prefs.setProfileAvatarId(CreateProfileActivity.this, new SecureRandom().nextInt());
                        } catch (IOException e) {
                            Log.w(CreateProfileActivity.TAG, e);
                            return false;
                        }
                    }
                    return true;
                }

                @Override
                public void onPostExecute(Boolean bool) {
                    super.onPostExecute((AnonymousClass2) bool);
                    if (bool.booleanValue()) {
                        CreateProfileActivity.this.attachmentManager.cleanup();
                        if (CreateProfileActivity.this.fromWelcome) {
                            Intent intent = new Intent(CreateProfileActivity.this.getApplicationContext(), (Class<?>) ConversationListActivity.class);
                            intent.putExtra("from_welcome", true);
                            CreateProfileActivity.this.startActivity(intent);
                        }
                        CreateProfileActivity.this.finish();
                        return;
                    }
                    Toast.makeText((Context) CreateProfileActivity.this, R.string.error, 1).show();
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        }
    }

    public void setStatusText() {
        DcHelper.set(this, DcHelper.CONFIG_SELF_STATUS, this.statusView.getText().toString().trim());
    }

    private class AvatarSelectedListener implements AvatarSelector.AttachmentClickedListener {
        private AvatarSelectedListener() {
        }

        @Override
        public void onClick(int i) {
            if (i == 1) {
                AttachmentManager.selectImage(CreateProfileActivity.this, 1);
                return;
            }
            if (i == 5) {
                CreateProfileActivity.this.attachmentManager.capturePhoto(CreateProfileActivity.this, 1);
                return;
            }
            if (i != 8) {
                return;
            }
            CreateProfileActivity.this.avatarBmp = null;
            CreateProfileActivity.this.imageLoaded = false;
            CreateProfileActivity.this.avatarChanged = true;
            ImageView imageView = CreateProfileActivity.this.avatar;
            ResourceContactPhoto resourceContactPhoto = new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp);
            ?? r1 = CreateProfileActivity.this;
            imageView.setImageDrawable(resourceContactPhoto.asDrawable(r1, r1.getResources().getColor(R.color.grey_400)));
        }

        @Override
        public void onQuickAttachment(Uri uri) {
            CreateProfileActivity.this.onFileSelected(uri);
        }
    }
}