Search in sources :

Example 56 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method attachFile.

public void attachFile(final int attachmentChoice) {
    if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) {
        if (!hasStorageAndCameraPermission(attachmentChoice)) {
            return;
        }
    } else if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
        if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(attachmentChoice)) {
            return;
        }
    }
    if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
        if (!activity.hasMicPermission(attachmentChoice)) {
            return;
        }
    }
    if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
        if (!activity.hasLocationPermission(attachmentChoice)) {
            return;
        }
    }
    try {
        activity.getPreferences().edit().putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString()).apply();
    } catch (IllegalArgumentException e) {
    // just do not save
    }
    final int encryption = conversation.getNextEncryption();
    final int mode = conversation.getMode();
    if (encryption == Message.ENCRYPTION_PGP) {
        if (activity.hasPgp()) {
            if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
                activity.xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback<Contact>() {

                    @Override
                    public void userInputRequried(PendingIntent pi, Contact contact) {
                        startPendingIntent(pi, attachmentChoice);
                    }

                    @Override
                    public void success(Contact contact) {
                        selectPresenceToAttachFile(attachmentChoice);
                    }

                    @Override
                    public void error(int error, Contact contact) {
                        activity.replaceToast(getString(error));
                    }
                });
            } else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
                if (!conversation.getMucOptions().everybodyHasKeys()) {
                    getActivity().runOnUiThread(() -> {
                        Toast warning = Toast.makeText(activity, R.string.missing_public_keys, Toast.LENGTH_LONG);
                        warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        warning.show();
                    });
                }
                selectPresenceToAttachFile(attachmentChoice);
            } else {
                final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
                if (fragment != null) {
                    fragment.showNoPGPKeyDialog(false, (dialog, which) -> {
                        conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                        activity.xmppConnectionService.updateConversation(conversation);
                        selectPresenceToAttachFile(attachmentChoice);
                    });
                }
            }
        } else {
            activity.showInstallPgpDialog();
        }
    } else {
        if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
            selectPresenceToAttachFile(attachmentChoice);
        }
    }
}
Also used : Arrays(java.util.Arrays) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection) Bundle(android.os.Bundle) MessageUtils(de.pixart.messenger.utils.MessageUtils) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Uri(android.net.Uri) ImageView(android.widget.ImageView) EXTRA_ACCOUNT(de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT) Account(de.pixart.messenger.entities.Account) Manifest(android.Manifest) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) PopupMenu(android.widget.PopupMenu) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) Log(android.util.Log) Set(java.util.Set) SendButtonTool(de.pixart.messenger.ui.util.SendButtonTool) Contact(de.pixart.messenger.entities.Contact) Transferable(de.pixart.messenger.entities.Transferable) EditMessage(de.pixart.messenger.ui.widget.EditMessage) TextWatcher(android.text.TextWatcher) UIHelper(de.pixart.messenger.utils.UIHelper) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) SimpleDateFormat(java.text.SimpleDateFormat) BitmapFactory(android.graphics.BitmapFactory) SystemClock(android.os.SystemClock) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) SessionStatus(net.java.otr4j.session.SessionStatus) ArrayList(java.util.ArrayList) Conversation(de.pixart.messenger.entities.Conversation) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ENCRYPTION_EXCEPTIONS(de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS) Fragment(android.app.Fragment) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) IOException(java.io.IOException) ScrollState(de.pixart.messenger.ui.util.ScrollState) File(java.io.File) IdRes(android.support.annotation.IdRes) Gravity(android.view.Gravity) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DataBindingUtil(android.databinding.DataBindingUtil) SendButtonAction(de.pixart.messenger.ui.util.SendButtonAction) ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) PendingIntent(android.app.PendingIntent) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Jid(de.pixart.messenger.xmpp.jid.Jid) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) AdapterView(android.widget.AdapterView) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) Presence(de.pixart.messenger.entities.Presence) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) MessageAdapter(de.pixart.messenger.ui.adapter.MessageAdapter) ExifInterface(android.support.media.ExifInterface) FragmentConversationBinding(de.pixart.messenger.databinding.FragmentConversationBinding) UUID(java.util.UUID) ViewGroup(android.view.ViewGroup) OnScrollListener(android.widget.AbsListView.OnScrollListener) ConversationMenuConfigurator(de.pixart.messenger.ui.util.ConversationMenuConfigurator) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) FileUtils(de.pixart.messenger.utils.FileUtils) ListView(android.widget.ListView) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) XmppConnection(de.pixart.messenger.xmpp.XmppConnection) EditorInfo(android.view.inputmethod.EditorInfo) Blockable(de.pixart.messenger.entities.Blockable) Context(android.content.Context) ContextMenu(android.view.ContextMenu) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) MessageArchiveService(de.pixart.messenger.services.MessageArchiveService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) FileBackend(de.pixart.messenger.persistance.FileBackend) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) MotionEvent(android.view.MotionEvent) R(de.pixart.messenger.R) AttachmentTool(de.pixart.messenger.ui.util.AttachmentTool) Build(android.os.Build) Config(de.pixart.messenger.Config) NickValidityChecker(de.pixart.messenger.utils.NickValidityChecker) DialogInterface(android.content.DialogInterface) Message(de.pixart.messenger.entities.Message) MucOptions(de.pixart.messenger.entities.MucOptions) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) StylingHelper(de.pixart.messenger.utils.StylingHelper) InputConnectionCompat(android.support.v13.view.inputmethod.InputConnectionCompat) PendingItem(de.pixart.messenger.ui.util.PendingItem) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) Collections(java.util.Collections) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) OnClickListener(android.view.View.OnClickListener) REQUEST_INVITE_TO_CONVERSATION(de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION) Toast(android.widget.Toast) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Example 57 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method attachImageToConversation.

private void attachImageToConversation(Conversation conversation, Uri uri, boolean sendAsIs) {
    if (conversation == null) {
        return;
    }
    if (sendAsIs) {
        sendImage(conversation, uri);
        return;
    }
    final Conversation conversation_preview = conversation;
    final Uri uri_preview = uri;
    Bitmap bitmap = BitmapFactory.decodeFile(FileUtils.getPath(activity, uri));
    File file = null;
    ExifInterface exif = null;
    int orientation = 0;
    try {
        file = new File(FileUtils.getPath(activity, uri));
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (file != null) {
        try {
            exif = new ExifInterface(file.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
        orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    }
    Log.d(Config.LOGTAG, "EXIF: " + orientation);
    Bitmap rotated_image = null;
    Log.d(Config.LOGTAG, "Rotate image");
    rotated_image = FileBackend.rotateBitmap(file, bitmap, orientation);
    if (rotated_image != null) {
        int scaleSize = 600;
        int originalWidth = rotated_image.getWidth();
        int originalHeight = rotated_image.getHeight();
        int newWidth = -1;
        int newHeight = -1;
        float multFactor;
        if (originalHeight > originalWidth) {
            newHeight = scaleSize;
            multFactor = (float) originalWidth / (float) originalHeight;
            newWidth = (int) (newHeight * multFactor);
        } else if (originalWidth > originalHeight) {
            newWidth = scaleSize;
            multFactor = (float) originalHeight / (float) originalWidth;
            newHeight = (int) (newWidth * multFactor);
        } else if (originalHeight == originalWidth) {
            newHeight = scaleSize;
            newWidth = scaleSize;
        }
        Log.d(Config.LOGTAG, "Scaling preview image from " + originalHeight + "px x " + originalWidth + "px to " + newHeight + "px x " + newWidth + "px");
        Bitmap preview = Bitmap.createScaledBitmap(rotated_image, newWidth, newHeight, false);
        ImageView ImagePreview = new ImageView(activity);
        LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        ImagePreview.setLayoutParams(vp);
        ImagePreview.setMaxWidth(newWidth);
        ImagePreview.setMaxHeight(newHeight);
        // ImagePreview.setScaleType(ImageView.ScaleType.FIT_XY);
        // ImagePreview.setAdjustViewBounds(true);
        ImagePreview.setPadding(5, 5, 5, 5);
        ImagePreview.setImageBitmap(preview);
        getActivity().runOnUiThread(() -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setView(ImagePreview);
            builder.setTitle(R.string.send_image);
            builder.setPositiveButton(R.string.ok, (dialog, which) -> sendImage(conversation_preview, uri_preview));
            builder.setOnCancelListener(dialog -> mPendingImageUris.clear());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                builder.setOnDismissListener(dialog -> mPendingImageUris.clear());
            }
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        });
    } else {
        getActivity().runOnUiThread(() -> Toast.makeText(getActivity(), getText(R.string.error_file_not_found), Toast.LENGTH_LONG).show());
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ExifInterface(android.support.media.ExifInterface) Conversation(de.pixart.messenger.entities.Conversation) IOException(java.io.IOException) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) SendIntentException(android.content.IntentSender.SendIntentException) ActivityNotFoundException(android.content.ActivityNotFoundException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) File(java.io.File) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) LinearLayout(android.widget.LinearLayout)

Example 58 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class OtrService method injectMessage.

@Override
public void injectMessage(SessionID session, String body) throws OtrException {
    MessagePacket packet = new MessagePacket();
    packet.setFrom(account.getJid());
    if (session.getUserID().isEmpty()) {
        packet.setAttribute("to", session.getAccountID());
    } else {
        packet.setAttribute("to", session.getAccountID() + "/" + session.getUserID());
    }
    packet.setBody(body);
    MessageGenerator.addMessageHints(packet);
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
            if (mXmppConnectionService.sendChatStates()) {
                packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
            }
        }
    } catch (final InvalidJidException ignored) {
    }
    packet.setType(MessagePacket.TYPE_CHAT);
    packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
    account.getXmppConnection().sendMessagePacket(packet);
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Example 59 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class OtrService method askForSecret.

@Override
public void askForSecret(SessionID id, InstanceTag instanceTag, String question) {
    try {
        final Jid jid = Jid.fromSessionID(id);
        Conversation conversation = this.mXmppConnectionService.find(this.account, jid);
        if (conversation != null) {
            conversation.smp().hint = question;
            conversation.smp().status = Conversation.Smp.STATUS_CONTACT_REQUESTED;
            mXmppConnectionService.updateConversationUi();
        }
    } catch (InvalidJidException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": smp in invalid session " + id.toString());
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Example 60 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class OtrService method setSmpStatus.

private void setSmpStatus(SessionID id, int status) {
    try {
        final Jid jid = Jid.fromSessionID(id);
        Conversation conversation = this.mXmppConnectionService.find(this.account, jid);
        if (conversation != null) {
            conversation.smp().status = status;
            mXmppConnectionService.updateConversationUi();
        }
    } catch (final InvalidJidException ignored) {
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Aggregations

Conversation (de.pixart.messenger.entities.Conversation)69 Jid (de.pixart.messenger.xmpp.jid.Jid)20 Account (de.pixart.messenger.entities.Account)18 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)16 Message (de.pixart.messenger.entities.Message)15 Contact (de.pixart.messenger.entities.Contact)11 MucOptions (de.pixart.messenger.entities.MucOptions)9 Intent (android.content.Intent)7 SuppressLint (android.annotation.SuppressLint)6 Uri (android.net.Uri)6 SpannableString (android.text.SpannableString)6 View (android.view.View)6 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)6 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)6 Element (de.pixart.messenger.xml.Element)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)6 IOException (java.io.IOException)6 Fragment (android.app.Fragment)5 SharedPreferences (android.content.SharedPreferences)5 Bitmap (android.graphics.Bitmap)5