正在查看: Delta Chat v1.58.3 应用的 InstantOnboardingActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Delta Chat v1.58.3 应用的 InstantOnboardingActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
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.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
import com.b44t.messenger.DcLot;
import com.b44t.messenger.rpc.RpcException;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import java.io.File;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Objects;
import org.thoughtcrime.securesms.components.AvatarSelector;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcEventCenter;
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.proxy.ProxySettingsActivity;
import org.thoughtcrime.securesms.qr.RegistrationQrActivity;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.views.ProgressDialog;
public class InstantOnboardingActivity extends BaseActionBarActivity implements DcEventCenter.DcEventDelegate {
private static final String DCACCOUNT = "dcaccount";
private static final String DCLOGIN = "dclogin";
private static final String DEFAULT_CHATMAIL_HOST = "nine.testrun.org";
public static final String FROM_WELCOME = "from_welcome";
private static final String INSTANCES_URL = "https://delta.chat/chatmail";
public static final String QR_ACCOUNT_EXTRA = "qr_account_extra";
private static final int REQUEST_CODE_AVATAR = 1;
private static final String TAG = "InstantOnboardingActivity";
private AttachmentManager attachmentManager;
private ImageView avatar;
private Bitmap avatarBmp;
private boolean avatarChanged;
private DcContext dcContext;
private boolean imageLoaded;
private boolean isDcLogin;
private EditText name;
private TextView privacyPolicyBtn;
private ProgressDialog progressDialog;
private String providerHost;
private String providerQrData;
private Button signUpBtn;
static void lambda$onCreate$0() {
}
@Override
public boolean runOnMain() {
return DcEventCenter.DcEventDelegate.CC.$default$runOnMain(this);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.instant_onboarding_activity);
((ActionBar) Objects.requireNonNull(getSupportActionBar())).setTitle(R.string.onboarding_create_instant_account);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
boolean booleanExtra = getIntent().getBooleanExtra("from_welcome", false);
if (DcHelper.getContext(this).isConfigured() == 1) {
AccountManager.getInstance().beginAccountCreation(this);
}
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(!booleanExtra) {
public void handleOnBackPressed() {
AccountManager accountManager = AccountManager.getInstance();
if (accountManager.canRollbackAccountCreation(InstantOnboardingActivity.this)) {
accountManager.rollbackAccountCreation(InstantOnboardingActivity.this);
} else {
InstantOnboardingActivity.this.finish();
}
}
});
this.isDcLogin = false;
this.providerHost = DEFAULT_CHATMAIL_HOST;
this.providerQrData = "dcaccount:https://" + this.providerHost + "/new";
this.attachmentManager = new AttachmentManager(this, new AttachmentManager.AttachmentListener() {
@Override
public final void onAttachmentChanged() {
InstantOnboardingActivity.lambda$onCreate$0();
}
});
this.avatarChanged = false;
registerForEvents();
initializeResources();
initializeProfile();
handleIntent();
updateProvider();
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleIntent();
}
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
getMenuInflater().inflate(R.menu.instant_onboarding_menu, menu);
MenuItem findItem = menu.findItem(R.id.menu_proxy_settings);
if (TextUtils.isEmpty(DcHelper.get(this, DcHelper.CONFIG_PROXY_URL))) {
findItem.setShowAsAction(0);
} else {
findItem.setIcon(DcHelper.getInt(this, DcHelper.CONFIG_PROXY_ENABLED) == 1 ? R.drawable.ic_proxy_enabled_24 : R.drawable.ic_proxy_disabled_24);
findItem.setShowAsAction(2);
}
return super.onPrepareOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
super.onOptionsItemSelected(menuItem);
int itemId = menuItem.getItemId();
if (itemId == 16908332) {
getOnBackPressedDispatcher().onBackPressed();
return true;
}
if (itemId == R.id.menu_proxy_settings) {
startActivity(new Intent((Context) this, (Class<?>) ProxySettingsActivity.class));
return true;
}
if (itemId != R.id.menu_view_log) {
return false;
}
startActivity(new Intent((Context) this, (Class<?>) LogViewActivity.class));
return true;
}
public void onActivityResult(int i, int i2, Intent intent) {
IntentResult parseActivityResult;
super.onActivityResult(i, i2, intent);
if (i2 != -1) {
return;
}
if (i == 1) {
onFileSelected(intent != null ? intent.getData() : null);
return;
}
if (i == 31424) {
setAvatarView(intent.getData());
return;
}
if (i != 49374) {
return;
}
String stringExtra = intent.getStringExtra(RegistrationQrActivity.QRDATA_EXTRA);
if (stringExtra == null && (parseActivityResult = IntentIntegrator.parseActivityResult(i, i2, intent)) != null && parseActivityResult.getFormatName() != null) {
stringExtra = parseActivityResult.getContents();
}
if (stringExtra != null) {
setProviderFromQr(stringExtra);
}
}
private void setProviderFromQr(String str) {
DcLot checkQr = this.dcContext.checkQr(str);
boolean z = checkQr.getState() == 520;
if (z || checkQr.getState() == 250) {
this.isDcLogin = z;
this.providerHost = checkQr.getText1();
this.providerQrData = str;
updateProvider();
return;
}
new AlertDialog.Builder(this).setMessage(R.string.qraccount_qr_code_cannot_be_used).setPositiveButton(R.string.ok, (DialogInterface.OnClickListener) null).show();
}
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
Permissions.onRequestPermissionsResult((Activity) this, i, strArr, iArr);
}
public void onStart() {
super.onStart();
String stringExtra = getIntent().getStringExtra(QR_ACCOUNT_EXTRA);
if (stringExtra != null) {
getIntent().removeExtra(QR_ACCOUNT_EXTRA);
setProviderFromQr(stringExtra);
}
}
protected void onPause() {
super.onPause();
if (DcHelper.getContext(this).isConfigured() == 0) {
String obj = this.name.getText().toString();
if (TextUtils.isEmpty(obj)) {
obj = null;
}
DcHelper.set(this, DcHelper.CONFIG_DISPLAY_NAME, obj);
if (this.avatarChanged) {
try {
AvatarHelper.setSelfAvatar(this, this.avatarBmp);
Prefs.setProfileAvatarId(this, new SecureRandom().nextInt());
this.avatarChanged = false;
} catch (IOException e) {
Log.e(TAG, "Failed to save avatar", e);
}
}
}
}
@Override
public void onResume() {
super.onResume();
invalidateOptionsMenu();
}
public void onDestroy() {
super.onDestroy();
DcHelper.getEventCenter(this).removeObservers(this);
}
private void handleIntent() {
Uri data;
if (getIntent() == null || !"android.intent.action.VIEW".equals(getIntent().getAction()) || (data = getIntent().getData()) == null) {
return;
}
if (data.getScheme().equalsIgnoreCase(DCACCOUNT) || data.getScheme().equalsIgnoreCase(DCLOGIN)) {
setProviderFromQr(data.toString());
}
}
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 CustomTarget<Bitmap>() {
public void onLoadCleared(Drawable drawable) {
}
public void onResourceReady(Object obj, Transition transition) {
onResourceReady((Bitmap) obj, (Transition<? super Bitmap>) transition);
}
public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
InstantOnboardingActivity.this.avatarChanged = true;
InstantOnboardingActivity.this.imageLoaded = true;
InstantOnboardingActivity.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() {
this.avatar = (ImageView) findViewById(R.id.avatar);
this.name = (EditText) findViewById(R.id.name_text);
this.privacyPolicyBtn = (TextView) findViewById(R.id.privacy_policy_button);
this.signUpBtn = (Button) findViewById(R.id.signup_button);
this.privacyPolicyBtn.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1240x73a40d74(view);
}
});
this.signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1241x8dbf8c13(view);
}
});
((Button) findViewById(R.id.other_options_button)).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1242xa7db0ab2(view);
}
});
}
void m1240x73a40d74(View view) {
if (this.isDcLogin) {
return;
}
IntentUtils.showInBrowser(this, "https://" + this.providerHost + "/privacy.html");
}
void m1241x8dbf8c13(View view) {
createProfile();
}
void m1242xa7db0ab2(View view) {
showOtherOptionsDialog();
}
private void showOtherOptionsDialog() {
View inflate = View.inflate(this, R.layout.signup_options_view, null);
final AlertDialog create = new AlertDialog.Builder(this).setView(inflate).setTitle(R.string.instant_onboarding_show_more_instances).setNegativeButton(R.string.cancel, (DialogInterface.OnClickListener) null).create();
inflate.findViewById(R.id.use_other_server).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1243xe2ea7ab9(create, view);
}
});
inflate.findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1244xfd05f958(create, view);
}
});
inflate.findViewById(R.id.scan_qr_button).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
InstantOnboardingActivity.this.m1245x172177f7(create, view);
}
});
create.show();
}
void m1243xe2ea7ab9(AlertDialog alertDialog, View view) {
IntentUtils.showInBrowser(this, INSTANCES_URL);
alertDialog.dismiss();
}
void m1244xfd05f958(AlertDialog alertDialog, View view) {
startRegistrationActivity();
alertDialog.dismiss();
}
void m1245x172177f7(AlertDialog alertDialog, View view) {
new IntentIntegrator(this).setCaptureActivity(RegistrationQrActivity.class).initiateScan();
alertDialog.dismiss();
}
private void startRegistrationActivity() {
startActivity(new Intent((Context) this, (Class<?>) RegistrationActivity.class));
}
private void updateProvider() {
if (this.isDcLogin) {
this.signUpBtn.setText(R.string.login_title);
this.privacyPolicyBtn.setTextColor(getResources().getColor(R.color.gray50));
this.privacyPolicyBtn.setText(getString(R.string.qrlogin_ask_login, new Object[]{this.providerHost}));
} else {
this.signUpBtn.setText(R.string.instant_onboarding_create);
this.privacyPolicyBtn.setTextColor(getResources().getColor(R.color.delta_accent));
if (DEFAULT_CHATMAIL_HOST.equals(this.providerHost)) {
this.privacyPolicyBtn.setText(getString(R.string.instant_onboarding_agree_default2, new Object[]{this.providerHost}));
} else {
this.privacyPolicyBtn.setText(getString(R.string.instant_onboarding_agree_instance, new Object[]{this.providerHost}));
}
}
}
private void initializeProfile() {
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) {
InstantOnboardingActivity.this.m1239x47bcdc6a(view);
}
});
this.name.setText(DcHelper.get(this, DcHelper.CONFIG_DISPLAY_NAME));
}
void m1239x47bcdc6a(View view) {
new AvatarSelector(this, LoaderManager.getInstance(this), new AvatarSelectedListener(), this.imageLoaded).show(this, this.avatar);
}
private void registerForEvents() {
this.dcContext = DcHelper.getContext(this);
DcHelper.getEventCenter(this).addObserver(2041, this);
}
@Override
public void handleEvent(DcEvent dcEvent) {
if (dcEvent.getId() == 2041) {
progressUpdate(dcEvent.getData1Int());
}
}
private void progressUpdate(int i) {
int i2 = i / 10;
ProgressDialog progressDialog = this.progressDialog;
if (progressDialog != null) {
progressDialog.setMessage(getResources().getString(R.string.one_moment) + String.format(" %d%%", Integer.valueOf(i2)));
}
}
private void progressError(String str) {
ProgressDialog progressDialog = this.progressDialog;
if (progressDialog != null) {
try {
progressDialog.dismiss();
} catch (IllegalArgumentException e) {
Log.w(TAG, e);
}
}
WelcomeActivity.maybeShowConfigurationError(this, str);
}
private void progressSuccess() {
DcHelper.getEventCenter(this).endCaptureNextError();
ProgressDialog progressDialog = this.progressDialog;
if (progressDialog != null) {
progressDialog.dismiss();
}
Intent intent = new Intent(getApplicationContext(), (Class<?>) ConversationListActivity.class);
intent.putExtra("from_welcome", true);
startActivity(intent);
finishAffinity();
}
private void createProfile() {
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(InstantOnboardingActivity.this, DcHelper.CONFIG_DISPLAY_NAME, obj);
if (InstantOnboardingActivity.this.avatarChanged) {
try {
?? r3 = InstantOnboardingActivity.this;
AvatarHelper.setSelfAvatar(r3, ((InstantOnboardingActivity) r3).avatarBmp);
Prefs.setProfileAvatarId(InstantOnboardingActivity.this, new SecureRandom().nextInt());
} catch (IOException e) {
Log.w(InstantOnboardingActivity.TAG, e);
return false;
}
}
return true;
}
@Override
public void onPostExecute(Boolean bool) {
super.onPostExecute((AnonymousClass3) bool);
if (bool.booleanValue()) {
InstantOnboardingActivity.this.attachmentManager.cleanup();
InstantOnboardingActivity instantOnboardingActivity = InstantOnboardingActivity.this;
instantOnboardingActivity.startQrAccountCreation(instantOnboardingActivity.providerQrData);
return;
}
Toast.makeText((Context) InstantOnboardingActivity.this, R.string.error, 1).show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
}
public void startQrAccountCreation(final String str) {
ProgressDialog progressDialog = this.progressDialog;
if (progressDialog != null) {
progressDialog.dismiss();
this.progressDialog = null;
}
ProgressDialog progressDialog2 = new ProgressDialog(this);
this.progressDialog = progressDialog2;
progressDialog2.setMessage(getResources().getString(R.string.one_moment));
this.progressDialog.setCanceledOnTouchOutside(false);
this.progressDialog.setCancelable(false);
this.progressDialog.setButton(-2, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public final void onClick(DialogInterface dialogInterface, int i) {
InstantOnboardingActivity.this.m1247x7c221b1f(dialogInterface, i);
}
});
this.progressDialog.show();
DcHelper.getEventCenter(this).captureNextError();
new Thread(new Runnable() {
@Override
public final void run() {
InstantOnboardingActivity.this.m1246xafa3389c(str);
}
}).start();
}
void m1247x7c221b1f(DialogInterface dialogInterface, int i) {
this.dcContext.stopOngoingProcess();
}
void m1246xafa3389c(String str) {
try {
DcHelper.getRpc(this).addTransportFromQr(this.dcContext.getAccountId(), str);
progressSuccess();
} catch (RpcException e) {
Util.runOnMain(new Runnable() {
@Override
public final void run() {
InstantOnboardingActivity.this.m1248x963d99be(e);
}
});
}
}
void m1248x963d99be(RpcException rpcException) {
progressError(rpcException.getMessage());
}
private class AvatarSelectedListener implements AvatarSelector.AttachmentClickedListener {
private AvatarSelectedListener() {
}
@Override
public void onClick(int i) {
if (i == 1) {
AttachmentManager.selectImage(InstantOnboardingActivity.this, 1);
return;
}
if (i == 5) {
InstantOnboardingActivity.this.attachmentManager.capturePhoto(InstantOnboardingActivity.this, 1);
return;
}
if (i != 8) {
return;
}
InstantOnboardingActivity.this.avatarBmp = null;
InstantOnboardingActivity.this.imageLoaded = false;
InstantOnboardingActivity.this.avatarChanged = true;
ImageView imageView = InstantOnboardingActivity.this.avatar;
ResourceContactPhoto resourceContactPhoto = new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp);
?? r1 = InstantOnboardingActivity.this;
imageView.setImageDrawable(resourceContactPhoto.asDrawable(r1, r1.getResources().getColor(R.color.grey_400)));
}
@Override
public void onQuickAttachment(Uri uri) {
InstantOnboardingActivity.this.onFileSelected(uri);
}
}
}