Search in sources :

Example 1 with DialogQuickeditBinding

use of eu.siacs.conversations.databinding.DialogQuickeditBinding in project Conversations by siacs.

the class XmppActivity method quickEdit.

@SuppressLint("InflateParams")
private void quickEdit(final String previousValue, final OnValueEdited callback, @StringRes final int hint, boolean password, boolean permitEmpty) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_quickedit, null, false);
    if (password) {
        binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    builder.setPositiveButton(R.string.accept, null);
    if (hint != 0) {
        binding.inputLayout.setHint(getString(hint));
    }
    binding.inputEditText.requestFocus();
    if (previousValue != null) {
        binding.inputEditText.getText().append(previousValue);
    }
    builder.setView(binding.getRoot());
    builder.setNegativeButton(R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText));
    dialog.show();
    View.OnClickListener clickListener = v -> {
        String value = binding.inputEditText.getText().toString();
        if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
            String error = callback.onValueEdited(value);
            if (error != null) {
                binding.inputLayout.setError(error);
                return;
            }
        }
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    };
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    }));
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnDismissListener(dialog1 -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) SoftKeyboardUtils(eu.siacs.conversations.ui.util.SoftKeyboardUtils) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) IBinder(android.os.IBinder) BoolRes(androidx.annotation.BoolRes) Manifest(android.Manifest) PowerManager(android.os.PowerManager) AvatarService(eu.siacs.conversations.services.AvatarService) MenuDoubleTabUtil(eu.siacs.conversations.ui.util.MenuDoubleTabUtil) ThemeHelper(eu.siacs.conversations.utils.ThemeHelper) Handler(android.os.Handler) ClipboardManager(android.content.ClipboardManager) ServiceConnection(android.content.ServiceConnection) View(android.view.View) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) PresenceSelector(eu.siacs.conversations.ui.util.PresenceSelector) TargetApi(android.annotation.TargetApi) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) ConnectivityManager(android.net.ConnectivityManager) AsyncTask(android.os.AsyncTask) Contact(eu.siacs.conversations.entities.Contact) SettingsUtils(eu.siacs.conversations.ui.util.SettingsUtils) InputType(android.text.InputType) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DisplayMetrics(android.util.DisplayMetrics) StringRes(androidx.annotation.StringRes) List(java.util.List) Message(eu.siacs.conversations.entities.Message) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) EmojiService(eu.siacs.conversations.ui.service.EmojiService) OnUpdateBlocklist(eu.siacs.conversations.xmpp.OnUpdateBlocklist) XmppConnectionBinder(eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder) Context(android.content.Context) Config(eu.siacs.conversations.Config) AlertDialog(androidx.appcompat.app.AlertDialog) Builder(androidx.appcompat.app.AlertDialog.Builder) OnKeyStatusUpdated(eu.siacs.conversations.xmpp.OnKeyStatusUpdated) Intent(android.content.Intent) SystemClock(android.os.SystemClock) Account(eu.siacs.conversations.entities.Account) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Conversation(eu.siacs.conversations.entities.Conversation) AccountUtils(eu.siacs.conversations.utils.AccountUtils) ClipData(android.content.ClipData) Strings(com.google.common.base.Strings) SuppressLint(android.annotation.SuppressLint) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Toast(android.widget.Toast) Menu(android.view.Menu) DialogQuickeditBinding(eu.siacs.conversations.databinding.DialogQuickeditBinding) ContextWrapper(android.content.ContextWrapper) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ExceptionHelper(eu.siacs.conversations.utils.ExceptionHelper) DialogInterface(android.content.DialogInterface) PgpEngine(eu.siacs.conversations.crypto.PgpEngine) R(eu.siacs.conversations.R) QuickConversationsService(eu.siacs.conversations.services.QuickConversationsService) Presences(eu.siacs.conversations.entities.Presences) ComponentName(android.content.ComponentName) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) Point(android.graphics.Point) IOException(java.io.IOException) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) BarcodeProvider(eu.siacs.conversations.services.BarcodeProvider) XmppConnectionService(eu.siacs.conversations.services.XmppConnectionService) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) Jid(eu.siacs.conversations.xmpp.Jid) Resources(android.content.res.Resources) Builder(androidx.appcompat.app.AlertDialog.Builder) Builder(androidx.appcompat.app.AlertDialog.Builder) DialogQuickeditBinding(eu.siacs.conversations.databinding.DialogQuickeditBinding) ImageView(android.widget.ImageView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Aggregations

Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 PendingIntent (android.app.PendingIntent)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 ContextWrapper (android.content.ContextWrapper)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SendIntentException (android.content.IntentSender.SendIntentException)1 ServiceConnection (android.content.ServiceConnection)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 Bitmap (android.graphics.Bitmap)1