Search in sources :

Example 1 with SimpleTextWatcher

use of org.thoughtcrime.securesms.contactshare.SimpleTextWatcher in project Signal-Android by WhisperSystems.

the class EditProxyFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    this.proxySwitch = view.findViewById(R.id.edit_proxy_switch);
    this.proxyTitle = view.findViewById(R.id.edit_proxy_address_title);
    this.proxyText = view.findViewById(R.id.edit_proxy_host);
    this.proxyStatus = view.findViewById(R.id.edit_proxy_status);
    this.saveButton = view.findViewById(R.id.edit_proxy_save);
    this.shareButton = view.findViewById(R.id.edit_proxy_share);
    proxyText.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void onTextChanged(String text) {
            onProxyTextChanged(text);
        }
    });
    this.proxyText.setText(Optional.fromNullable(SignalStore.proxy().getProxy()).transform(SignalProxy::getHost).or(""));
    this.proxySwitch.setChecked(SignalStore.proxy().isProxyEnabled());
    initViewModel();
    saveButton.setOnClickListener(v -> onSaveClicked());
    shareButton.setOnClickListener(v -> onShareClicked());
    proxySwitch.setOnCheckedChangeListener((buttonView, isChecked) -> viewModel.onToggleProxy(isChecked));
    LearnMoreTextView description = view.findViewById(R.id.edit_proxy_switch_title_description);
    description.setLearnMoreVisible(true);
    description.setOnLinkClickListener(v -> CommunicationActions.openBrowserLink(requireContext(), "https://support.signal.org/hc/articles/360056052052"));
    requireActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
Also used : SimpleTextWatcher(org.thoughtcrime.securesms.contactshare.SimpleTextWatcher) SignalProxy(org.whispersystems.signalservice.internal.configuration.SignalProxy) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView)

Example 2 with SimpleTextWatcher

use of org.thoughtcrime.securesms.contactshare.SimpleTextWatcher in project Signal-Android by WhisperSystems.

the class SignalPinReminderDialog method show.

public static void show(@NonNull Context context, @NonNull Launcher launcher, @NonNull Callback mainCallback) {
    if (!SignalStore.kbsValues().hasPin()) {
        throw new AssertionError("Must have a PIN!");
    }
    Log.i(TAG, "Showing PIN reminder dialog.");
    AlertDialog dialog = new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.Theme_Signal_AlertDialog_Dark_Cornered_ColoredAccent : R.style.Theme_Signal_AlertDialog_Light_Cornered_ColoredAccent).setView(R.layout.kbs_pin_reminder_view).setCancelable(false).setOnCancelListener(d -> RegistrationLockReminders.scheduleReminder(context, false)).create();
    WindowManager windowManager = ServiceUtil.getWindowManager(context);
    Display display = windowManager.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    dialog.show();
    dialog.getWindow().setLayout((int) (metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);
    EditText pinEditText = (EditText) DialogCompat.requireViewById(dialog, R.id.pin);
    TextView pinStatus = (TextView) DialogCompat.requireViewById(dialog, R.id.pin_status);
    TextView reminder = (TextView) DialogCompat.requireViewById(dialog, R.id.reminder);
    View skip = DialogCompat.requireViewById(dialog, R.id.skip);
    View submit = DialogCompat.requireViewById(dialog, R.id.submit);
    SpannableString reminderText = new SpannableString(context.getString(R.string.KbsReminderDialog__to_help_you_memorize_your_pin));
    SpannableString forgotText = new SpannableString(context.getString(R.string.KbsReminderDialog__forgot_pin));
    ViewUtil.focusAndShowKeyboard(pinEditText);
    ViewCompat.setAutofillHints(pinEditText, HintConstants.AUTOFILL_HINT_PASSWORD);
    switch(SignalStore.pinValues().getKeyboardType()) {
        case NUMERIC:
            pinEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
            break;
        case ALPHA_NUMERIC:
            pinEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            break;
    }
    ClickableSpan clickableSpan = new ClickableSpan() {

        @Override
        public void onClick(@NonNull View widget) {
            dialog.dismiss();
            launcher.launch(CreateKbsPinActivity.getIntentForPinChangeFromForgotPin(context), CreateKbsPinActivity.REQUEST_NEW_PIN);
        }
    };
    forgotText.setSpan(clickableSpan, 0, forgotText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    reminder.setText(new SpannableStringBuilder(reminderText).append(" ").append(forgotText));
    reminder.setMovementMethod(LinkMovementMethod.getInstance());
    PinVerifier.Callback callback = getPinWatcherCallback(context, dialog, pinEditText, pinStatus, mainCallback);
    PinVerifier verifier = new V2PinVerifier();
    skip.setOnClickListener(v -> {
        dialog.dismiss();
        mainCallback.onReminderDismissed(callback.hadWrongGuess());
    });
    submit.setEnabled(false);
    submit.setOnClickListener(v -> {
        Editable pinEditable = pinEditText.getText();
        verifier.verifyPin(pinEditable == null ? null : pinEditable.toString(), callback);
    });
    pinEditText.addTextChangedListener(new SimpleTextWatcher() {

        private final String localHash = Objects.requireNonNull(SignalStore.kbsValues().getLocalPinHash());

        @Override
        public void onTextChanged(String text) {
            if (text.length() >= KbsConstants.MINIMUM_PIN_LENGTH) {
                submit.setEnabled(true);
                if (PinHashing.verifyLocalPinHash(localHash, text)) {
                    dialog.dismiss();
                    mainCallback.onReminderCompleted(text, callback.hadWrongGuess());
                }
            } else {
                submit.setEnabled(false);
            }
        }
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) DialogCompat(androidx.core.app.DialogCompat) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) LinkMovementMethod(android.text.method.LinkMovementMethod) R(org.thoughtcrime.securesms.R) Editable(android.text.Editable) SpannableStringBuilder(android.text.SpannableStringBuilder) Display(android.view.Display) View(android.view.View) HintConstants(androidx.autofill.HintConstants) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) ViewCompat(androidx.core.view.ViewCompat) SpannableString(android.text.SpannableString) SimpleTextWatcher(org.thoughtcrime.securesms.contactshare.SimpleTextWatcher) InputType(android.text.InputType) TextUtils(android.text.TextUtils) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) KbsConstants(org.thoughtcrime.securesms.lock.v2.KbsConstants) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) EditText(android.widget.EditText) EditText(android.widget.EditText) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) DisplayMetrics(android.util.DisplayMetrics) View(android.view.View) TextView(android.widget.TextView) ClickableSpan(android.text.style.ClickableSpan) WindowManager(android.view.WindowManager) SpannableString(android.text.SpannableString) SimpleTextWatcher(org.thoughtcrime.securesms.contactshare.SimpleTextWatcher) NonNull(androidx.annotation.NonNull) Editable(android.text.Editable) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) Display(android.view.Display)

Example 3 with SimpleTextWatcher

use of org.thoughtcrime.securesms.contactshare.SimpleTextWatcher in project Signal-Android by WhisperSystems.

the class UsernameEditFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    usernameInput = view.findViewById(R.id.username_text);
    usernameSubtext = view.findViewById(R.id.username_subtext);
    submitButton = view.findViewById(R.id.username_submit_button);
    deleteButton = view.findViewById(R.id.username_delete_button);
    view.<Toolbar>findViewById(R.id.toolbar).setNavigationOnClickListener(v -> Navigation.findNavController(view).popBackStack());
    viewModel = ViewModelProviders.of(this, new UsernameEditViewModel.Factory()).get(UsernameEditViewModel.class);
    viewModel.getUiState().observe(getViewLifecycleOwner(), this::onUiStateChanged);
    viewModel.getEvents().observe(getViewLifecycleOwner(), this::onEvent);
    submitButton.setOnClickListener(v -> viewModel.onUsernameSubmitted(usernameInput.getText().toString()));
    deleteButton.setOnClickListener(v -> viewModel.onUsernameDeleted());
    usernameInput.setText(Recipient.self().getUsername().orNull());
    usernameInput.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void onTextChanged(String text) {
            viewModel.onUsernameUpdated(text);
        }
    });
    usernameInput.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            viewModel.onUsernameSubmitted(usernameInput.getText().toString());
            return true;
        }
        return false;
    });
}
Also used : SimpleTextWatcher(org.thoughtcrime.securesms.contactshare.SimpleTextWatcher)

Aggregations

SimpleTextWatcher (org.thoughtcrime.securesms.contactshare.SimpleTextWatcher)3 Context (android.content.Context)1 Intent (android.content.Intent)1 Editable (android.text.Editable)1 InputType (android.text.InputType)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Spanned (android.text.Spanned)1 TextUtils (android.text.TextUtils)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 ClickableSpan (android.text.style.ClickableSpan)1 DisplayMetrics (android.util.DisplayMetrics)1 Display (android.view.Display)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 WindowManager (android.view.WindowManager)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1