Search in sources :

Example 11 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project Conversations by siacs.

the class EditAccountActivity method updateAccountInformation.

private void updateAccountInformation(boolean init) {
    if (init) {
        this.binding.accountJid.getEditableText().clear();
        if (mUsernameMode) {
            this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getEscapedLocal());
        } else {
            this.binding.accountJid.getEditableText().append(this.mAccount.getJid().asBareJid().toEscapedString());
        }
        this.binding.accountPassword.getEditableText().clear();
        this.binding.accountPassword.getEditableText().append(this.mAccount.getPassword());
        this.binding.hostname.setText("");
        this.binding.hostname.getEditableText().append(this.mAccount.getHostname());
        this.binding.port.setText("");
        this.binding.port.getEditableText().append(String.valueOf(this.mAccount.getPort()));
        this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
    }
    if (!mInitMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        this.binding.accountPassword.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
    }
    final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && !mAccount.isOptionSet(Account.OPTION_FIXED_USERNAME) && QuickConversationsService.isConversations();
    this.binding.accountJid.setEnabled(editable);
    this.binding.accountJid.setFocusable(editable);
    this.binding.accountJid.setFocusableInTouchMode(editable);
    this.binding.accountJid.setCursorVisible(editable);
    final String displayName = mAccount.getDisplayName();
    updateDisplayName(displayName);
    final boolean togglePassword = mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
    final boolean editPassword = !mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || (!mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && QuickConversationsService.isConversations()) || mAccount.getLastErrorStatus() == Account.State.UNAUTHORIZED;
    this.binding.accountPasswordLayout.setPasswordVisibilityToggleEnabled(togglePassword);
    this.binding.accountPassword.setFocusable(editPassword);
    this.binding.accountPassword.setFocusableInTouchMode(editPassword);
    this.binding.accountPassword.setCursorVisible(editPassword);
    this.binding.accountPassword.setEnabled(editPassword);
    if (!mInitMode) {
        this.binding.avater.setVisibility(View.VISIBLE);
        AvatarWorkerTask.loadAvatar(mAccount, binding.avater, R.dimen.avatar_on_details_screen_size);
    } else {
        this.binding.avater.setVisibility(View.GONE);
    }
    this.binding.accountRegisterNew.setChecked(this.mAccount.isOptionSet(Account.OPTION_REGISTER));
    if (this.mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) {
        if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.setTitle(R.string.create_account);
            }
        }
        this.binding.accountRegisterNew.setVisibility(View.GONE);
    } else if (this.mAccount.isOptionSet(Account.OPTION_REGISTER) && mForceRegister == null) {
        this.binding.accountRegisterNew.setVisibility(View.VISIBLE);
    } else {
        this.binding.accountRegisterNew.setVisibility(View.GONE);
    }
    if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
        Features features = this.mAccount.getXmppConnection().getFeatures();
        this.binding.stats.setVisibility(View.VISIBLE);
        boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().available(mAccount) && isOptimizingBattery();
        boolean showDataSaverWarning = isAffectedByDataSaver();
        showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
        this.binding.sessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection().getLastSessionEstablished()));
        if (features.rosterVersioning()) {
            this.binding.serverInfoRosterVersion.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoRosterVersion.setText(R.string.server_info_unavailable);
        }
        if (features.carbons()) {
            this.binding.serverInfoCarbons.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoCarbons.setText(R.string.server_info_unavailable);
        }
        if (features.mam()) {
            this.binding.serverInfoMam.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoMam.setText(R.string.server_info_unavailable);
        }
        if (features.csi()) {
            this.binding.serverInfoCsi.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoCsi.setText(R.string.server_info_unavailable);
        }
        if (features.blocking()) {
            this.binding.serverInfoBlocking.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoBlocking.setText(R.string.server_info_unavailable);
        }
        if (features.sm()) {
            this.binding.serverInfoSm.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoSm.setText(R.string.server_info_unavailable);
        }
        if (features.externalServiceDiscovery()) {
            this.binding.serverInfoExternalService.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoExternalService.setText(R.string.server_info_unavailable);
        }
        if (features.pep()) {
            AxolotlService axolotlService = this.mAccount.getAxolotlService();
            if (axolotlService != null && axolotlService.isPepBroken()) {
                this.binding.serverInfoPep.setText(R.string.server_info_broken);
            } else if (features.pepPublishOptions() || features.pepOmemoWhitelisted()) {
                this.binding.serverInfoPep.setText(R.string.server_info_available);
            } else {
                this.binding.serverInfoPep.setText(R.string.server_info_partial);
            }
        } else {
            this.binding.serverInfoPep.setText(R.string.server_info_unavailable);
        }
        if (features.httpUpload(0)) {
            final long maxFileSize = features.getMaxHttpUploadSize();
            if (maxFileSize > 0) {
                this.binding.serverInfoHttpUpload.setText(UIHelper.filesizeToString(maxFileSize));
            } else {
                this.binding.serverInfoHttpUpload.setText(R.string.server_info_available);
            }
        } else {
            this.binding.serverInfoHttpUpload.setText(R.string.server_info_unavailable);
        }
        this.binding.pushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
        if (xmppConnectionService.getPushManagementService().available(mAccount)) {
            this.binding.serverInfoPush.setText(R.string.server_info_available);
        } else {
            this.binding.serverInfoPush.setText(R.string.server_info_unavailable);
        }
        final long pgpKeyId = this.mAccount.getPgpId();
        if (pgpKeyId != 0 && Config.supportOpenPgp()) {
            OnClickListener openPgp = view -> launchOpenKeyChain(pgpKeyId);
            OnClickListener delete = view -> showDeletePgpDialog();
            this.binding.pgpFingerprintBox.setVisibility(View.VISIBLE);
            this.binding.pgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId));
            this.binding.pgpFingerprint.setOnClickListener(openPgp);
            if ("pgp".equals(messageFingerprint)) {
                this.binding.pgpFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
            }
            this.binding.pgpFingerprintDesc.setOnClickListener(openPgp);
            this.binding.actionDeletePgp.setOnClickListener(delete);
        } else {
            this.binding.pgpFingerprintBox.setVisibility(View.GONE);
        }
        final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
        if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
            this.binding.axolotlFingerprintBox.setVisibility(View.VISIBLE);
            if (ownAxolotlFingerprint.equals(messageFingerprint)) {
                this.binding.ownFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
                this.binding.ownFingerprintDesc.setText(R.string.omemo_fingerprint_selected_message);
            } else {
                this.binding.ownFingerprintDesc.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption);
                this.binding.ownFingerprintDesc.setText(R.string.omemo_fingerprint);
            }
            this.binding.axolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
            this.binding.actionCopyAxolotlToClipboard.setVisibility(View.VISIBLE);
            this.binding.actionCopyAxolotlToClipboard.setOnClickListener(v -> copyOmemoFingerprint(ownAxolotlFingerprint));
        } else {
            this.binding.axolotlFingerprintBox.setVisibility(View.GONE);
        }
        boolean hasKeys = false;
        binding.otherDeviceKeys.removeAllViews();
        for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
            if (!session.getTrust().isCompromised()) {
                boolean highlight = session.getFingerprint().equals(messageFingerprint);
                addFingerprintRow(binding.otherDeviceKeys, session, highlight);
                hasKeys = true;
            }
        }
        if (hasKeys && Config.supportOmemo()) {
            // TODO: either the button should be visible if we print an active device or the device list should be fed with reactived devices
            this.binding.otherDeviceKeysCard.setVisibility(View.VISIBLE);
            Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
            if (otherDevices == null || otherDevices.isEmpty()) {
                binding.clearDevices.setVisibility(View.GONE);
            } else {
                binding.clearDevices.setVisibility(View.VISIBLE);
            }
        } else {
            this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
        }
    } else {
        final TextInputLayout errorLayout;
        if (this.mAccount.errorStatus()) {
            if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED || this.mAccount.getStatus() == Account.State.DOWNGRADE_ATTACK) {
                errorLayout = this.binding.accountPasswordLayout;
            } else if (mShowOptions && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND && this.binding.hostname.getText().length() > 0) {
                errorLayout = this.binding.hostnameLayout;
            } else {
                errorLayout = this.binding.accountJidLayout;
            }
            errorLayout.setError(getString(this.mAccount.getStatus().getReadableId()));
            if (init || !accountInfoEdited()) {
                errorLayout.requestFocus();
            }
        } else {
            errorLayout = null;
        }
        removeErrorsOnAllBut(errorLayout);
        this.binding.stats.setVisibility(View.GONE);
        this.binding.otherDeviceKeysCard.setVisibility(View.GONE);
    }
}
Also used : PendingItem(eu.siacs.conversations.ui.util.PendingItem) Arrays(java.util.Arrays) OnCaptchaRequested(eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested) Bundle(android.os.Bundle) KeyChain(android.security.KeyChain) SoftKeyboardUtils(eu.siacs.conversations.ui.util.SoftKeyboardUtils) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) PendingIntent(android.app.PendingIntent) ActionBar(androidx.appcompat.app.ActionBar) MenuDoubleTabUtil(eu.siacs.conversations.ui.util.MenuDoubleTabUtil) CheckBox(android.widget.CheckBox) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Handler(android.os.Handler) SignupUtils(eu.siacs.conversations.utils.SignupUtils) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Resolver(eu.siacs.conversations.utils.Resolver) Log(android.util.Log) AvatarWorkerTask(eu.siacs.conversations.ui.util.AvatarWorkerTask) DataBindingUtil(androidx.databinding.DataBindingUtil) XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) KeyChainAliasCallback(android.security.KeyChainAliasCallback) Set(java.util.Set) XmppAxolotlSession(eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession) List(java.util.List) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) OnUpdateBlocklist(eu.siacs.conversations.xmpp.OnUpdateBlocklist) HttpUrl(okhttp3.HttpUrl) TextWatcher(android.text.TextWatcher) Config(eu.siacs.conversations.Config) AlertDialog(androidx.appcompat.app.AlertDialog) PresenceTemplateAdapter(eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter) Builder(androidx.appcompat.app.AlertDialog.Builder) TextInputLayout(com.google.android.material.textfield.TextInputLayout) DialogPresenceBinding(eu.siacs.conversations.databinding.DialogPresenceBinding) OnKeyStatusUpdated(eu.siacs.conversations.xmpp.OnKeyStatusUpdated) PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate) Features(eu.siacs.conversations.xmpp.XmppConnection.Features) Intent(android.content.Intent) Account(eu.siacs.conversations.entities.Account) Element(eu.siacs.conversations.xml.Element) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ActivityEditAccountBinding(eu.siacs.conversations.databinding.ActivityEditAccountBinding) CryptoHelper(eu.siacs.conversations.utils.CryptoHelper) IntentSender(android.content.IntentSender) Presence(eu.siacs.conversations.entities.Presence) Toast(android.widget.Toast) Menu(android.view.Menu) UIHelper(eu.siacs.conversations.utils.UIHelper) Settings(android.provider.Settings) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Build(android.os.Build) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) R(eu.siacs.conversations.R) QuickConversationsService(eu.siacs.conversations.services.QuickConversationsService) CharMatcher(com.google.common.base.CharMatcher) TextUtils(android.text.TextUtils) Data(eu.siacs.conversations.xmpp.forms.Data) BarcodeProvider(eu.siacs.conversations.services.BarcodeProvider) XmppConnectionService(eu.siacs.conversations.services.XmppConnectionService) TorServiceUtils(eu.siacs.conversations.utils.TorServiceUtils) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) OnAccountUpdate(eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate) Activity(android.app.Activity) XmppUri(eu.siacs.conversations.utils.XmppUri) EditText(android.widget.EditText) Jid(eu.siacs.conversations.xmpp.Jid) OnClickListener(android.view.View.OnClickListener) OpenPgpUtils(org.openintents.openpgp.util.OpenPgpUtils) XmppAxolotlSession(eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) OnClickListener(android.view.View.OnClickListener) Features(eu.siacs.conversations.xmpp.XmppConnection.Features) TextInputLayout(com.google.android.material.textfield.TextInputLayout) ActionBar(androidx.appcompat.app.ActionBar)

Example 12 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project zype-android by zype.

the class LoginActivity method resetPassword.

private void resetPassword() {
    hideKeyboard();
    TextInputLayout layoutEmailReset = findViewById(R.id.layoutEmailReset);
    String email = layoutEmailReset.getEditText().getText().toString();
    if (TextUtils.isEmpty(email)) {
        layoutEmailReset.setError(getString(R.string.error_field_required));
        return;
    } else if (!isEmailValid(email)) {
        layoutEmailReset.setError(getString(R.string.error_invalid_email));
        return;
    }
    showProgress(true);
    ConsumerForgotPasswordParamsBuilder builder = new ConsumerForgotPasswordParamsBuilder();
    builder.addEmail(email);
    getApi().executeRequest(WebApiManager.Request.CONSUMER_FORGOT_PASSWORD, builder.build());
}
Also used : ConsumerForgotPasswordParamsBuilder(com.zype.android.webapi.builder.ConsumerForgotPasswordParamsBuilder) SpannableString(android.text.SpannableString) TextInputLayout(com.google.android.material.textfield.TextInputLayout)

Example 13 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project OneSignal-Android-SDK by OneSignal.

the class Dialog method createUpdateAlertDialog.

/**
 * Create an AlertDialog for when the user updates a single value field
 * Click OK to verify and update the field being updated
 */
public void createUpdateAlertDialog(final String content, final ProfileUtil.FieldType field, final UpdateAlertDialogCallback callback) {
    View updateAlertDialogView = layoutInflater.inflate(R.layout.update_alert_dialog_layout, null, false);
    final TextInputLayout updateAlertDialogTextInputLayout = updateAlertDialogView.findViewById(R.id.update_alert_dialog_text_input_layout);
    final EditText updateAlertDialogEditText = updateAlertDialogView.findViewById(R.id.update_alert_dialog_edit_text);
    final ProgressBar updateAlertDialogProgressBar = updateAlertDialogView.findViewById(R.id.update_alert_dialog_progress_bar);
    String hintTitle = "New " + field.getTitle();
    updateAlertDialogTextInputLayout.setHint(hintTitle);
    updateAlertDialogEditText.setText(content);
    font.applyFont(updateAlertDialogTextInputLayout, font.saralaBold);
    font.applyFont(updateAlertDialogEditText, font.saralaBold);
    final CustomAlertDialogBuilder updateAlertDialog = new CustomAlertDialogBuilder(context, updateAlertDialogView);
    updateAlertDialog.setView(updateAlertDialogView);
    updateAlertDialog.setIsCancelable(true);
    updateAlertDialog.setCanceledOnTouchOutside(false);
    updateAlertDialog.setPositiveButton(Text.BUTTON_UPDATE, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, int which) {
            toggleUpdateAlertDialogAttributes(true);
            final String newContent = updateAlertDialogEditText.getText().toString().trim();
            if (newContent.equals(content)) {
                InterfaceUtil.hideKeyboardFrom(context, updateAlertDialogEditText);
                toggleUpdateAlertDialogAttributes(false);
                dialog.dismiss();
            } else if (ProfileUtil.isContentValid(field, updateAlertDialogTextInputLayout)) {
                InterfaceUtil.hideKeyboardFrom(context, updateAlertDialogEditText);
                switch(field) {
                    case APP_ID:
                        updateAppId(dialog, newContent);
                        break;
                    case EMAIL:
                        updateEmail(dialog, newContent);
                        break;
                    case SMS:
                        updateSMsNumber(dialog, newContent);
                        break;
                    case EXTERNAL_USER_ID:
                        updateExternalUserId(dialog, newContent);
                        break;
                }
            } else {
                toggleUpdateAlertDialogAttributes(false);
            }
        }

        private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) {
            int progressVisibility = disableAttributes ? View.VISIBLE : View.GONE;
            updateAlertDialogProgressBar.setVisibility(progressVisibility);
            int buttonVisibility = disableAttributes ? View.GONE : View.VISIBLE;
            updateAlertDialog.getPositiveButtonElement().setVisibility(buttonVisibility);
            updateAlertDialog.getNegativeButtonElement().setVisibility(buttonVisibility);
            updateAlertDialog.getPositiveButtonElement().setEnabled(!disableAttributes);
            updateAlertDialog.getNegativeButtonElement().setEnabled(!disableAttributes);
            updateAlertDialog.setIsCancelable(!disableAttributes);
        }

        /**
         * Handles changing the app id for the SDK by reinitializing and caching
         */
        private void updateAppId(DialogInterface dialog, String appId) {
            OneSignal.setAppId(appId);
            SharedPreferenceUtil.cacheOneSignalAppId(context, appId);
            toggleUpdateAlertDialogAttributes(false);
            dialog.dismiss();
            callback.onSuccess(appId);
        }

        /**
         * Updates the email attached to the device and caches
         */
        private void updateEmail(final DialogInterface dialog, final String email) {
            currentUser.setEmail(email, new EmailUpdateCallback() {

                @Override
                public void onSuccess() {
                    SharedPreferenceUtil.cacheUserEmail(context, email);
                    Log.d(Tag.DEBUG, Text.EMAIL_SET_SUCCESSFULLY);
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            toggleUpdateAlertDialogAttributes(false);
                            dialog.dismiss();
                            callback.onSuccess(email);
                        }
                    });
                }

                @Override
                public void onFailure() {
                    Log.d(Tag.ERROR, Text.EMAIL_SET_FAILURE);
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            toggleUpdateAlertDialogAttributes(false);
                            dialog.dismiss();
                            callback.onFailure();
                        }
                    });
                }
            });
        }

        /**
         * Updates the SMS number attached to the device and caches
         */
        private void updateSMsNumber(final DialogInterface dialog, final String smsNumber) {
            currentUser.setSMSNumber(smsNumber, new SMSUpdateCallback() {

                @Override
                public void onSuccess() {
                    SharedPreferenceUtil.cacheUserSMSNumber(context, smsNumber);
                    Log.d(Tag.DEBUG, Text.SMS_SET_SUCCESSFULLY);
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            toggleUpdateAlertDialogAttributes(false);
                            dialog.dismiss();
                            callback.onSuccess(smsNumber);
                        }
                    });
                }

                @Override
                public void onFailure() {
                    Log.d(Tag.ERROR, Text.SMS_SET_FAILURE);
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            toggleUpdateAlertDialogAttributes(false);
                            dialog.dismiss();
                            callback.onFailure();
                        }
                    });
                }
            });
        }

        /**
         * Set external id attached to the user/email of the device
         */
        private void updateExternalUserId(final DialogInterface dialog, final String externalUserId) {
            OneSignal.setExternalUserId(externalUserId, new OneSignal.OSExternalUserIdUpdateCompletionHandler() {

                @Override
                public void onSuccess(JSONObject results) {
                    // Default success to false until we know push came back successful
                    boolean successful = false;
                    // Check push exists with success status and success status is true
                    if (isExternalUserIdPushSuccessful(results)) {
                        OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Push channel external user id set successfully");
                        SharedPreferenceUtil.cacheUserExternalUserId(context, externalUserId);
                        successful = true;
                    }
                    // Check email exists with success status and success status is true
                    if (isExternalUserIdEmailSuccessful(results)) {
                        OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Email channel external user id set successfully");
                    }
                    // We could eventually check email also but not important for now
                    if (successful)
                        callback.onSuccess(externalUserId);
                    else
                        callback.onFailure();
                    toggleUpdateAlertDialogAttributes(false);
                    dialog.dismiss();
                }

                @Override
                public void onFailure(OneSignal.ExternalIdError error) {
                    OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "External user id set failed with error: " + error);
                    callback.onFailure();
                    dialog.dismiss();
                }

                /**
                 * Parse the results of the external user id completion callback and make sure push.success = true
                 */
                private boolean isExternalUserIdPushSuccessful(JSONObject status) {
                    boolean successful = false;
                    try {
                        if (!status.has("push"))
                            return false;
                        JSONObject pushStatus = status.getJSONObject("push");
                        if (!pushStatus.has("success"))
                            return false;
                        successful = pushStatus.getBoolean("success");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    return successful;
                }

                /**
                 * Parse the results of the external user id completion callback and make sure email.success = true
                 */
                private boolean isExternalUserIdEmailSuccessful(JSONObject status) {
                    boolean successful = false;
                    try {
                        if (!status.has("email"))
                            return false;
                        JSONObject emailStatus = status.getJSONObject("email");
                        if (!emailStatus.has("success"))
                            return false;
                        successful = emailStatus.getBoolean("success");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    return successful;
                }
            });
        }
    }).setNegativeButton(Text.BUTTON_CANCEL, null);
    updateAlertDialog.show();
    updateAlertDialogEditText.requestFocus();
}
Also used : EditText(android.widget.EditText) OneSignal(com.onesignal.OneSignal) DialogInterface(android.content.DialogInterface) EmailUpdateCallback(com.onesignal.sdktest.callback.EmailUpdateCallback) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) SMSUpdateCallback(com.onesignal.sdktest.callback.SMSUpdateCallback) JSONObject(org.json.JSONObject) CustomAlertDialogBuilder(com.onesignal.sdktest.ui.CustomAlertDialogBuilder) TextInputLayout(com.google.android.material.textfield.TextInputLayout) ProgressBar(android.widget.ProgressBar)

Example 14 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project OneSignal-Android-SDK by OneSignal.

the class Dialog method createAddPairAlertDialog.

/**
 * Create an AlertDialog for when the user updates a single value field
 * Click OK to verify and update the field being updated
 */
public void createAddPairAlertDialog(String content, final ProfileUtil.FieldType field, final AddPairAlertDialogCallback callback) {
    final View addPairAlertDialogView = layoutInflater.inflate(R.layout.add_pair_alert_dialog_layout, null, false);
    final TextView addPairAlertDialogTitleTextView = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_title_text_view);
    final TextInputLayout addPairAlertDialogKeyTextInputLayout = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_key_text_input_layout);
    final EditText addPairAlertDialogKeyEditText = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_key_edit_text);
    final TextInputLayout addPairAlertDialogValueTextInputLayout = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_value_text_input_layout);
    final EditText addPairAlertDialogValueEditText = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_value_edit_text);
    final ProgressBar addPairAlertDialogProgressBar = addPairAlertDialogView.findViewById(R.id.add_pair_alert_dialog_progress_bar);
    addPairAlertDialogKeyTextInputLayout.setHint("Key");
    addPairAlertDialogValueTextInputLayout.setHint("Value");
    addPairAlertDialogTitleTextView.setText(content);
    font.applyFont(addPairAlertDialogTitleTextView, font.saralaBold);
    font.applyFont(addPairAlertDialogKeyTextInputLayout, font.saralaBold);
    font.applyFont(addPairAlertDialogKeyEditText, font.saralaBold);
    font.applyFont(addPairAlertDialogValueTextInputLayout, font.saralaBold);
    font.applyFont(addPairAlertDialogValueEditText, font.saralaBold);
    final CustomAlertDialogBuilder addPairAlertDialog = new CustomAlertDialogBuilder(context, addPairAlertDialogView);
    addPairAlertDialog.setView(addPairAlertDialogView);
    addPairAlertDialog.setIsCancelable(true);
    addPairAlertDialog.setCanceledOnTouchOutside(false);
    addPairAlertDialog.setPositiveButton(Text.BUTTON_ADD, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, int which) {
            toggleUpdateAlertDialogAttributes(true);
            final String pairKey = addPairAlertDialogKeyEditText.getText().toString().trim();
            final String pairStringValue = addPairAlertDialogValueEditText.getText().toString().trim();
            Object pairValue = pairStringValue;
            if (Util.isBoolean(pairStringValue)) {
                pairValue = Boolean.parseBoolean(pairStringValue.toLowerCase());
            } else if (Util.isNumeric(pairStringValue)) {
                pairValue = Double.parseDouble(pairStringValue);
            }
            if (ProfileUtil.isContentValid(field, addPairAlertDialogKeyTextInputLayout)) {
                InterfaceUtil.hideKeyboardFrom(context, addPairAlertDialogView);
                switch(field) {
                    case TAG:
                        OneSignal.sendTag(pairKey, pairStringValue);
                        break;
                    case TRIGGER:
                        OneSignal.addTrigger(pairKey, pairValue);
                        break;
                }
                dialog.dismiss();
                callback.onSuccess(new Pair<>(pairKey, pairValue));
            } else {
                toggleUpdateAlertDialogAttributes(false);
            }
        }

        private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) {
            int progressVisibility = disableAttributes ? View.VISIBLE : View.GONE;
            addPairAlertDialogProgressBar.setVisibility(progressVisibility);
            int buttonVisibility = disableAttributes ? View.GONE : View.VISIBLE;
            addPairAlertDialog.getPositiveButtonElement().setVisibility(buttonVisibility);
            addPairAlertDialog.getNegativeButtonElement().setVisibility(buttonVisibility);
            addPairAlertDialog.getPositiveButtonElement().setEnabled(!disableAttributes);
            addPairAlertDialog.getNegativeButtonElement().setEnabled(!disableAttributes);
            addPairAlertDialog.setIsCancelable(!disableAttributes);
        }
    }).setNegativeButton(Text.BUTTON_CANCEL, null);
    addPairAlertDialog.show();
    addPairAlertDialogKeyEditText.requestFocus();
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) CustomAlertDialogBuilder(com.onesignal.sdktest.ui.CustomAlertDialogBuilder) JSONObject(org.json.JSONObject) TextInputLayout(com.google.android.material.textfield.TextInputLayout) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar)

Example 15 with TextInputLayout

use of com.google.android.material.textfield.TextInputLayout in project FirebaseUI-Android by firebase.

the class RegisterEmailFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    mNextButton = view.findViewById(R.id.button_create);
    mProgressBar = view.findViewById(R.id.top_progress_bar);
    mEmailEditText = view.findViewById(R.id.email);
    mNameEditText = view.findViewById(R.id.name);
    mPasswordEditText = view.findViewById(R.id.password);
    mEmailInput = view.findViewById(R.id.email_layout);
    mPasswordInput = view.findViewById(R.id.password_layout);
    TextInputLayout nameInput = view.findViewById(R.id.name_layout);
    // Get configuration
    AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdpsOrThrow(getFlowParams().providers, EmailAuthProvider.PROVIDER_ID);
    boolean requireName = emailConfig.getParams().getBoolean(ExtraConstants.REQUIRE_NAME, true);
    mPasswordFieldValidator = new PasswordFieldValidator(mPasswordInput, getResources().getInteger(R.integer.fui_min_password_length));
    mNameValidator = requireName ? new RequiredFieldValidator(nameInput, getResources().getString(R.string.fui_missing_first_and_last_name)) : new NoOpValidator(nameInput);
    mEmailFieldValidator = new EmailFieldValidator(mEmailInput);
    ImeHelper.setImeOnDoneListener(mPasswordEditText, this);
    mEmailEditText.setOnFocusChangeListener(this);
    mNameEditText.setOnFocusChangeListener(this);
    mPasswordEditText.setOnFocusChangeListener(this);
    mNextButton.setOnClickListener(this);
    // Only show the name field if required
    nameInput.setVisibility(requireName ? View.VISIBLE : View.GONE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && getFlowParams().enableCredentials) {
        mEmailEditText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
    }
    TextView footerText = view.findViewById(R.id.email_footer_tos_and_pp_text);
    PrivacyDisclosureUtils.setupTermsOfServiceFooter(requireContext(), getFlowParams(), footerText);
    // WARNING: Nothing below this line will be executed on rotation
    if (savedInstanceState != null) {
        return;
    }
    // If email is passed in, fill in the field and move down to the name field.
    String email = mUser.getEmail();
    if (!TextUtils.isEmpty(email)) {
        mEmailEditText.setText(email);
    }
    // If name is passed in, fill in the field and move down to the password field.
    String name = mUser.getName();
    if (!TextUtils.isEmpty(name)) {
        mNameEditText.setText(name);
    }
    // See http://stackoverflow.com/questions/11082341/android-requestfocus-ineffective#comment51774752_11082523
    if (!requireName || !TextUtils.isEmpty(mNameEditText.getText())) {
        safeRequestFocus(mPasswordEditText);
    } else if (!TextUtils.isEmpty(mEmailEditText.getText())) {
        safeRequestFocus(mNameEditText);
    } else {
        safeRequestFocus(mEmailEditText);
    }
}
Also used : NoOpValidator(com.firebase.ui.auth.util.ui.fieldvalidators.NoOpValidator) EmailFieldValidator(com.firebase.ui.auth.util.ui.fieldvalidators.EmailFieldValidator) TextView(android.widget.TextView) TextInputLayout(com.google.android.material.textfield.TextInputLayout) PasswordFieldValidator(com.firebase.ui.auth.util.ui.fieldvalidators.PasswordFieldValidator) RequiredFieldValidator(com.firebase.ui.auth.util.ui.fieldvalidators.RequiredFieldValidator) AuthUI(com.firebase.ui.auth.AuthUI)

Aggregations

TextInputLayout (com.google.android.material.textfield.TextInputLayout)21 TextView (android.widget.TextView)13 View (android.view.View)12 EditText (android.widget.EditText)10 Bundle (android.os.Bundle)5 ImageView (android.widget.ImageView)5 NonNull (androidx.annotation.NonNull)5 DialogInterface (android.content.DialogInterface)4 Nullable (androidx.annotation.Nullable)4 AlertDialog (androidx.appcompat.app.AlertDialog)4 Toolbar (androidx.appcompat.widget.Toolbar)4 Fragment (androidx.fragment.app.Fragment)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 Navigation (androidx.navigation.Navigation)4 R (org.thoughtcrime.securesms.R)4 AfterTextChanged (org.thoughtcrime.securesms.util.text.AfterTextChanged)4 Activity (android.app.Activity)3 Drawable (android.graphics.drawable.Drawable)3 TextUtils (android.text.TextUtils)3 Button (android.widget.Button)3