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);
}
}
}
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());
}
}
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);
}
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());
}
}
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) {
}
}
Aggregations