Search in sources :

Example 6 with StringRes

use of androidx.annotation.StringRes in project Conversations by siacs.

the class ChooseContactActivity method getTitleFromIntent.

@StringRes
public int getTitleFromIntent() {
    final Intent intent = getIntent();
    boolean multiple = intent != null && intent.getBooleanExtra(EXTRA_SELECT_MULTIPLE, false);
    @StringRes int fallback = multiple ? R.string.title_activity_choose_contacts : R.string.title_activity_choose_contact;
    return intent != null ? intent.getIntExtra(EXTRA_TITLE_RES_ID, fallback) : fallback;
}
Also used : StringRes(androidx.annotation.StringRes) Intent(android.content.Intent) StringRes(androidx.annotation.StringRes)

Example 7 with StringRes

use of androidx.annotation.StringRes in project Conversations by siacs.

the class PgpEngine method encrypt.

public void encrypt(final Message message, final UiCallback<Message> callback) {
    Intent params = new Intent();
    params.setAction(OpenPgpApi.ACTION_ENCRYPT);
    final Conversation conversation = (Conversation) message.getConversation();
    if (conversation.getMode() == Conversation.MODE_SINGLE) {
        long[] keys = { conversation.getContact().getPgpKeyId(), conversation.getAccount().getPgpId() };
        params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
    } else {
        params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, conversation.getMucOptions().getPgpKeyIds());
    }
    if (!message.needsUploading()) {
        params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
        String body;
        if (message.hasFileOnRemoteHost()) {
            body = message.getFileParams().url;
        } else {
            body = message.getBody();
        }
        InputStream is = new ByteArrayInputStream(body.getBytes());
        final OutputStream os = new ByteArrayOutputStream();
        api.executeApiAsync(params, is, os, result -> {
            switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
                case OpenPgpApi.RESULT_CODE_SUCCESS:
                    try {
                        os.flush();
                        final ArrayList<String> encryptedMessageBody = new ArrayList<>();
                        final String[] lines = os.toString().split("\n");
                        for (int i = 2; i < lines.length - 1; ++i) {
                            if (!lines[i].contains("Version")) {
                                encryptedMessageBody.add(lines[i].trim());
                            }
                        }
                        message.setEncryptedBody(Joiner.on('\n').join(encryptedMessageBody));
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                        mXmppConnectionService.sendMessage(message);
                        callback.success(message);
                    } catch (IOException e) {
                        callback.error(R.string.openpgp_error, message);
                    }
                    break;
                case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                    callback.userInputRequired(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
                    break;
                case OpenPgpApi.RESULT_CODE_ERROR:
                    OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
                    String errorMessage = error != null ? error.getMessage() : null;
                    @StringRes final int res;
                    if (errorMessage != null && errorMessage.startsWith("Bad key for encryption")) {
                        res = R.string.bad_key_for_encryption;
                    } else {
                        res = R.string.openpgp_error;
                    }
                    logError(conversation.getAccount(), error);
                    callback.error(res, message);
                    break;
            }
        });
    } else {
        try {
            DownloadableFile inputFile = this.mXmppConnectionService.getFileBackend().getFile(message, true);
            DownloadableFile outputFile = this.mXmppConnectionService.getFileBackend().getFile(message, false);
            outputFile.getParentFile().mkdirs();
            outputFile.createNewFile();
            final InputStream is = new FileInputStream(inputFile);
            final OutputStream os = new FileOutputStream(outputFile);
            api.executeApiAsync(params, is, os, result -> {
                switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
                    case OpenPgpApi.RESULT_CODE_SUCCESS:
                        try {
                            os.flush();
                        } catch (IOException ignored) {
                        // ignored
                        }
                        FileBackend.close(os);
                        mXmppConnectionService.sendMessage(message);
                        callback.success(message);
                        break;
                    case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                        callback.userInputRequired(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
                        break;
                    case OpenPgpApi.RESULT_CODE_ERROR:
                        logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
                        callback.error(R.string.openpgp_error, message);
                        break;
                }
            });
        } catch (final IOException e) {
            callback.error(R.string.openpgp_error, message);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StringRes(androidx.annotation.StringRes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Conversation(eu.siacs.conversations.entities.Conversation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) OpenPgpError(org.openintents.openpgp.OpenPgpError) DownloadableFile(eu.siacs.conversations.entities.DownloadableFile)

Example 8 with StringRes

use of androidx.annotation.StringRes 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

StringRes (androidx.annotation.StringRes)8 SuppressLint (android.annotation.SuppressLint)4 Intent (android.content.Intent)3 Conversation (eu.siacs.conversations.entities.Conversation)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Manifest (android.Manifest)1 TargetApi (android.annotation.TargetApi)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 ComponentName (android.content.ComponentName)1 ContextWrapper (android.content.ContextWrapper)1 DialogInterface (android.content.DialogInterface)1 SendIntentException (android.content.IntentSender.SendIntentException)1 ServiceConnection (android.content.ServiceConnection)1 SharedPreferences (android.content.SharedPreferences)1