aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java28
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java62
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/AbstractAlertDialog.java125
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java180
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java71
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java185
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java48
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java47
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java31
10 files changed, 789 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java
new file mode 100644
index 00000000..52891a91
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java
@@ -0,0 +1,28 @@
+package de.thedevstack.conversationsplus.ui;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.ListView;
+
+import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
+import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask;
+import de.thedevstack.android.logcat.ui.LogCatOutputCopyOnClickListener;
+import eu.siacs.conversations.R;
+
+/**
+ * Created by tzur on 07.10.2015.
+ */
+public class LogCatOutputActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_logcatoutput);
+ ListView lv = (ListView)findViewById(R.id.actLogInfoOutput);
+ LogCatArrayAdapter logCatOutputAdapter = new LogCatArrayAdapter(this, R.layout.list_item_logcatoutput);
+ lv.setAdapter(logCatOutputAdapter);
+ new ReadLogCatAsyncTask(logCatOutputAdapter).execute();
+ Button copyButton = (Button) findViewById(R.id.actLogOutputCopyButton);
+ copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter, R.string.cplus_copied_to_clipboard, R.string.cplus_not_copied_to_clipboard_empty));
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java
new file mode 100644
index 00000000..e14d7f6b
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java
@@ -0,0 +1,62 @@
+package de.thedevstack.conversationsplus.ui.adapter;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Presences;
+import eu.siacs.conversations.utils.UIHelper;
+
+/**
+ * Created by tzur on 27.09.2015.
+ */
+public class PresencesArrayAdapter extends ArrayAdapter<Presence> {
+ private final Context context;
+ private final Presence[] values;
+
+ public PresencesArrayAdapter(Context context, Presences presences) {
+ super(context, R.layout.dialog_resources_status);
+ this.context = context;
+ this.values = getPresenceArray(presences);
+ addAll(this.values);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View rowView = inflater.inflate(R.layout.dialog_resources_status, parent, false);
+ TextView textView = (TextView) rowView.findViewById(R.id.dlg_res_stat_resource_name);
+ textView.setText(this.values[position].resource);
+ textView.setTextColor(Color.parseColor(UIHelper.getStatusColor(this.values[position].status)));
+
+ return rowView;
+ }
+
+ private static Presence[] getPresenceArray(Presences presences) {
+ ArrayList<Presence> presenceArrayList = new ArrayList<>();
+ if (null != presences && null != presences.getPresences() && !presences.getPresences().isEmpty()) {
+ for (Map.Entry<String, eu.siacs.conversations.entities.Presence> entry : presences.getPresences().entrySet()) {
+ Presence p = new Presence();
+ p.resource = entry.getKey();
+ p.status = entry.getValue().getStatus();
+ presenceArrayList.add(p);
+ }
+ presenceArrayList.trimToSize();
+ }
+ return presenceArrayList.toArray(new Presence[0]);
+ }
+}
+
+class Presence {
+ String resource;
+ eu.siacs.conversations.entities.Presence.Status status;
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/AbstractAlertDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/AbstractAlertDialog.java
new file mode 100644
index 00000000..2f394fb3
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/AbstractAlertDialog.java
@@ -0,0 +1,125 @@
+package de.thedevstack.conversationsplus.ui.dialogs;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.database.Cursor;
+import android.graphics.drawable.Drawable;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListAdapter;
+
+import eu.siacs.conversations.R;
+
+/**
+ * Created by tzur on 29.09.2015.
+ */
+public class AbstractAlertDialog {
+ protected AlertDialog.Builder builder;
+
+ public AbstractAlertDialog(Context context, String title) {
+ this.builder = new AlertDialog.Builder(context);
+ this.builder.setTitle(title);
+ this.builder.setPositiveButton(R.string.cplus_ok, null);
+ }
+
+ public AbstractAlertDialog(Context context, int titleTextId) {
+ this(context, context.getString(titleTextId));
+ }
+
+ public void show() {
+ this.builder.show();
+ }
+
+ public Context getContext() {
+ return builder.getContext();
+ }
+
+ public AlertDialog.Builder setTitle(int titleId) {
+ return builder.setTitle(titleId);
+ }
+
+ public AlertDialog.Builder setTitle(CharSequence title) {
+ return builder.setTitle(title);
+ }
+
+ public AlertDialog.Builder setIcon(int iconId) {
+ return builder.setIcon(iconId);
+ }
+
+ public AlertDialog.Builder setIcon(Drawable icon) {
+ return builder.setIcon(icon);
+ }
+
+ public AlertDialog.Builder setMessage(CharSequence message) {
+ return builder.setMessage(message);
+ }
+
+ public AlertDialog.Builder setMessage(int messageId) {
+ return builder.setMessage(messageId);
+ }
+
+ public AlertDialog.Builder setIconAttribute(int attrId) {
+ return builder.setIconAttribute(attrId);
+ }
+
+ public AlertDialog.Builder setPositiveButton(int textId, DialogInterface.OnClickListener listener) {
+ return builder.setPositiveButton(textId, listener);
+ }
+
+ public AlertDialog.Builder setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener) {
+ return builder.setPositiveButton(text, listener);
+ }
+
+ public AlertDialog.Builder setNegativeButton(int textId, DialogInterface.OnClickListener listener) {
+ return builder.setNegativeButton(textId, listener);
+ }
+
+ public AlertDialog.Builder setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener) {
+ return builder.setNegativeButton(text, listener);
+ }
+
+ public AlertDialog.Builder setNeutralButton(int textId, DialogInterface.OnClickListener listener) {
+ return builder.setNeutralButton(textId, listener);
+ }
+
+ public AlertDialog.Builder setNeutralButton(CharSequence text, DialogInterface.OnClickListener listener) {
+ return builder.setNeutralButton(text, listener);
+ }
+
+ public AlertDialog.Builder setCancelable(boolean cancelable) {
+ return builder.setCancelable(cancelable);
+ }
+
+ public AlertDialog.Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
+ return builder.setOnCancelListener(onCancelListener);
+ }
+
+ public AlertDialog.Builder setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
+ return builder.setOnDismissListener(onDismissListener);
+ }
+
+ public AlertDialog.Builder setOnKeyListener(DialogInterface.OnKeyListener onKeyListener) {
+ return builder.setOnKeyListener(onKeyListener);
+ }
+
+ public AlertDialog.Builder setAdapter(ListAdapter adapter, DialogInterface.OnClickListener listener) {
+ return builder.setAdapter(adapter, listener);
+ }
+
+ public AlertDialog.Builder setCursor(Cursor cursor, DialogInterface.OnClickListener listener, String labelColumn) {
+ return builder.setCursor(cursor, listener, labelColumn);
+ }
+
+ public AlertDialog.Builder setView(View view) {
+ return builder.setView(view);
+ }
+
+ public AlertDialog.Builder setView(int layoutResId) {
+ return builder.setView(layoutResId);
+ }
+
+ public AlertDialog.Builder setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {
+ return builder.setOnItemSelectedListener(listener);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
new file mode 100644
index 00000000..5cf9dd7d
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
@@ -0,0 +1,180 @@
+package de.thedevstack.conversationsplus.ui.dialogs;
+
+import android.app.Activity;
+import android.text.format.DateFormat;
+import android.view.View;
+import android.widget.TextView;
+
+import java.util.Date;
+
+import de.thedevstack.android.logcat.Logging;
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.utils.UIHelper;
+
+/**
+ * Fills the contents to the message details dialog.
+ * The view definition is done in R.layout.dialog_message_details.
+ */
+public class MessageDetailsDialog extends AbstractAlertDialog {
+
+ /**
+ * Initializes the Message Details Dialog.
+ * @param context the context of this alert dialog (the parent activity).
+ * @param message the message to be displayed
+ */
+ public MessageDetailsDialog(Activity context, Message message) {
+ super(context, R.string.dlg_msg_details_title);
+ this.createView(context, message);
+ }
+
+ /**
+ * Creates the view for the message details alert dialog.
+ * @param context the context of this alert dialog (the parent activity).
+ * @param message the message to be displayed
+ */
+ protected void createView(Activity context, Message message) {
+ int viewId = R.layout.dialog_message_details;
+ View view = context.getLayoutInflater().inflate(viewId, null);
+
+ displayMessageSentTime(view, message);
+ displaySenderAndReceiver(view, message);
+ displayMessageTypeInfo(view, message);
+ displayMessageStatusInfo(view, message);
+ displayFileInfo(view, message);
+
+ this.setView(view);
+ }
+
+ /**
+ * Publishes file information, if message contains an image to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayFileInfo(View view, Message message) {
+ if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
+ Logging.d("messagedetailsfile", "File is stored in path: " + message.getRelativeFilePath());
+ view.findViewById(R.id.dlgMsgDetFileTable).setVisibility(View.VISIBLE);
+ if (null != message.getFileParams()) {
+ Message.FileParams params = message.getFileParams();
+ TextView tvFilesize = (TextView) view.findViewById(R.id.dlgMsgDetFileSize);
+ tvFilesize.setText(UIHelper.getHumanReadableFileSize(params.size));
+ }
+ TextView mimetype = (TextView) view.findViewById(R.id.dlgMsgDetFileMimeType);
+ mimetype.setText(message.getMimeType());
+ }
+ }
+
+ /**
+ * Displays message status info to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageStatusInfo(View view, Message message) {
+ TextView msgStatusTextView = (TextView) view.findViewById(R.id.dlgMsgDetMsgStatus);
+ int msgStatusResId;
+ int msgStatusColorResId = R.color.primaryText;
+ switch (message.getStatus()) {
+ case Message.STATUS_WAITING:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_waiting;
+ break;
+ case Message.STATUS_UNSEND:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_unsend;
+ break;
+ case Message.STATUS_OFFERED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_offered;
+ break;
+ case Message.STATUS_SEND_FAILED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_failed;
+ msgStatusColorResId = R.color.error;
+ break;
+ case Message.STATUS_RECEIVED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_received;
+ break;
+ case Message.STATUS_SEND:
+ case Message.STATUS_SEND_DISPLAYED:
+ case Message.STATUS_SEND_RECEIVED:
+ default:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_sent;
+ }
+ msgStatusTextView.setText(msgStatusResId);
+ msgStatusTextView.setTextColor(getContext().getResources().getColor(msgStatusColorResId));
+ }
+
+ /**
+ * Publishes message type information to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageTypeInfo(View view, Message message) {
+ TextView msgTypeTextView = (TextView) view.findViewById(R.id.dlgMsgDetMsgType);
+ int msgTypeResId;
+ switch (message.getType()) {
+ case Message.TYPE_PRIVATE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_private;
+ break;
+ case Message.TYPE_FILE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_file;
+ break;
+ case Message.TYPE_IMAGE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_image;
+ break;
+ case Message.TYPE_STATUS:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_status;
+ break;
+ case Message.TYPE_TEXT:
+ default:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_text;
+ }
+ msgTypeTextView.setText(msgTypeResId);
+ }
+
+ /**
+ * Publishes information about sending and receiving parties to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displaySenderAndReceiver(View view, Message message) {
+ Conversation conversation = message.getConversation();
+ // Get own resource name -> What about msg written on other client?
+ String me = conversation.getAccount().getJid().getResourcepart();
+ // Get resource name of chat partner, if available
+ String other = (null == message.getCounterpart() || message.getCounterpart().isBareJid()) ? "" : message.getCounterpart().getResourcepart();
+ Logging.d("MesageDialog", "Me: " + me + ", other: " + other);
+ TextView sender = (TextView) view.findViewById(R.id.dlgMsgDetSender);
+ TextView receipient = (TextView) view.findViewById(R.id.dlgMsgDetReceipient);
+
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ // Change label of sending and receiving party to MUC terminology
+ TextView senderLabel = (TextView) view.findViewById(R.id.dlgMsgDetLblSender);
+ senderLabel.setText(R.string.dlg_msg_details_sender_nick);
+ TextView receipientLabel = (TextView) view.findViewById(R.id.dlgMsgDetLblReceipient);
+ receipientLabel.setText(R.string.dlg_msg_details_receipient_nick);
+
+ // Get own nick for MUC
+ me = conversation.getMucOptions().getActualNick();
+ }
+ if (Message.STATUS_RECEIVED == message.getStatus()) {
+ // Sender was chat partner, if the status is for my account received
+ sender.setText(other);
+ // Set receipient to myself in case of normal chat or private message in MUC
+ if (conversation.getMode() == Conversation.MODE_SINGLE || Message.TYPE_PRIVATE == message.getType()) {
+ receipient.setText(me);
+ }
+ } else {
+ sender.setText(me);
+ receipient.setText(other);
+ }
+ }
+
+ /**
+ * Publishes information about message sent time to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageSentTime(View view, Message message) {
+ TextView timeSent = (TextView) view.findViewById(R.id.dlgMsgDetTimeSent);
+ timeSent.setText(DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getTimeSent())));
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
new file mode 100644
index 00000000..c29832a5
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
@@ -0,0 +1,71 @@
+package de.thedevstack.conversationsplus.ui.dialogs;
+
+import android.app.Activity;
+import android.content.DialogInterface;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.TextView;
+
+import de.thedevstack.conversationsplus.enums.UserDecision;
+import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener;
+import eu.siacs.conversations.R;
+
+/**
+ * A dialog to give the user the choice to decide whether to do something or not.
+ * The user also has the choice to save his answer for the future.
+ * A UserDecisionListener is used to provide the functionality to be performed by clicking on yes, or no.
+ */
+public class UserDecisionDialog extends AbstractAlertDialog {
+ protected final UserDecisionListener listener;
+ protected final CheckBox rememberCheckBox;
+
+ public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) {
+ super(context, questionResourceId);
+ this.listener = userDecisionListener;
+
+ int viewId = R.layout.dialog_userdecision;
+ View view = context.getLayoutInflater().inflate(viewId, null);
+
+ this.rememberCheckBox = (CheckBox) view.findViewById(R.id.dlgUserDecRemember);
+
+ this.setPositiveButton(R.string.cplus_yes, new PositiveOnClickListener());
+ this.setNegativeButton(R.string.cplus_no, new NegativeOnClickListener());
+ this.setView(view);
+ }
+
+ public void decide(UserDecision baseDecision) {
+ switch (baseDecision) {
+ case ALWAYS:
+ this.listener.onYes();
+ break;
+ case NEVER:
+ this.listener.onNo();
+ break;
+ case ASK:
+ this.show();
+ break;
+ }
+ }
+
+ class PositiveOnClickListener implements DialogInterface.OnClickListener {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ listener.onYes();
+ if (rememberCheckBox.isChecked()) {
+ listener.onRemember(UserDecision.ALWAYS);
+ }
+ }
+ }
+
+ class NegativeOnClickListener implements DialogInterface.OnClickListener {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ listener.onNo();
+ if (rememberCheckBox.isChecked()) {
+ listener.onRemember(UserDecision.NEVER);
+ }
+ }
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
new file mode 100644
index 00000000..992776e5
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
@@ -0,0 +1,185 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import android.app.PendingIntent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.widget.Toast;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.enums.UserDecision;
+import de.thedevstack.conversationsplus.exceptions.UiException;
+import de.thedevstack.conversationsplus.utils.FileUtils;
+import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.utils.MessageUtil;
+import de.thedevstack.conversationsplus.utils.StreamUtil;
+
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.DownloadableFile;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.persistance.FileBackend;
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.ui.UiCallback;
+import eu.siacs.conversations.ui.XmppActivity;
+
+/**
+ * Created by tzur on 31.10.2015.
+ */
+public class ResizePictureUserDecisionListener implements UserDecisionListener {
+ protected Uri uri;
+ protected final Conversation conversation;
+ protected final UiCallback<Message> callback;
+ protected final XmppConnectionService xmppConnectionService;
+ protected final Toast prepareFileToast;
+ protected final XmppActivity activity;
+
+ public ResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, XmppConnectionService xmppConnectionService) {
+ this.xmppConnectionService = xmppConnectionService;
+ this.conversation = conversation;
+ this.activity = activity;
+ this.prepareFileToast = Toast.makeText(ConversationsPlusApplication.getAppContext(), ConversationsPlusApplication.getInstance().getText(R.string.preparing_image), Toast.LENGTH_LONG);
+ this.callback = new UiCallback<Message>() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Message object) {
+ hidePrepareFileToast();
+ }
+
+ @Override
+ public void success(Message message) {
+ ResizePictureUserDecisionListener.this.xmppConnectionService.sendMessage(message);
+ }
+
+ @Override
+ public void error(int error, Message message) {
+ hidePrepareFileToast();
+ //TODO Find another way to display an error dialog
+ ResizePictureUserDecisionListener.this.activity.displayErrorDialog(error);
+ }
+
+ protected void hidePrepareFileToast() {
+ ResizePictureUserDecisionListener.this.activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ResizePictureUserDecisionListener.this.prepareFileToast.cancel();
+ }
+ });
+ }
+ };
+ }
+
+ public ResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, Uri uri, XmppConnectionService xmppConnectionService) {
+ this(activity, conversation, xmppConnectionService);
+ this.uri = uri;
+ }
+
+ public void setUri(Uri uri) {
+ this.uri = uri;
+ }
+
+ protected void showPrepareFileToast() {
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ prepareFileToast.show();
+ }
+ });
+ }
+
+ @Override
+ public void onYes() {
+ this.showPrepareFileToast();
+ final Message message;
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
+ } else {
+ message = new Message(conversation, "", conversation.getNextEncryption());
+ }
+ message.setCounterpart(conversation.getNextCounterpart());
+ message.setType(Message.TYPE_IMAGE);
+ ConversationsPlusApplication.executeFileAdding(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ Bitmap resizedAndRotatedImage = ImageUtil.resizeAndRotateImage(uri);
+ DownloadableFile file = FileBackend.compressImageAndCopyToPrivateStorage(message, resizedAndRotatedImage);
+ String filePath = file.getAbsolutePath();
+ long imageSize = file.getSize();
+ int imageWidth = resizedAndRotatedImage.getWidth();
+ int imageHeight = resizedAndRotatedImage.getHeight();
+ MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ xmppConnectionService.getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
+ } catch (final UiException e) {
+ Logging.e("pictureresizesending", "Error while sending resized picture. " + e.getMessage());
+ callback.error(e.getResId(), message);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onNo() {
+ this.showPrepareFileToast();
+ final Message message;
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
+ } else {
+ message = new Message(conversation, "", conversation.getNextEncryption());
+ }
+ message.setCounterpart(conversation.getNextCounterpart());
+ message.setType(Message.TYPE_IMAGE);
+ ConversationsPlusApplication.executeFileAdding(new Runnable() {
+ @Override
+ public void run() {
+ InputStream is = null;
+ try {
+ is = StreamUtil.openInputStreamFromContentResolver(uri);
+ long imageSize = is.available();
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeStream(is, null, options);
+ int imageHeight = options.outHeight;
+ int imageWidth = options.outWidth;
+ String filePath = FileUtils.getPath(uri);
+ MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ xmppConnectionService.getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
+ } catch (FileNotFoundException e) {
+ Logging.e("picturesending", "File not found to send not resized. " + e.getMessage());
+ callback.error(R.string.error_file_not_found, message);
+ } catch (IOException e) {
+ Logging.e("picturesending", "Error while sending not resized picture. " + e.getMessage());
+ callback.error(R.string.error_io_exception, message);
+ } finally {
+ if (null != is) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ Logging.w("picturesending", "Error while closing stream for sending not resized picture. " + e.getMessage());
+ }
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onRemember(UserDecision decision) {
+ ConversationsPlusPreferences.applyResizePicture(decision);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java
new file mode 100644
index 00000000..7455cf97
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShareWithResizePictureUserDecisionListener.java
@@ -0,0 +1,48 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import android.net.Uri;
+
+import java.util.List;
+
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.ui.XmppActivity;
+
+/**
+ * Created by tzur on 03.11.2015.
+ */
+public class ShareWithResizePictureUserDecisionListener extends ResizePictureUserDecisionListener {
+ protected final List<Uri> uris;
+
+ public ShareWithResizePictureUserDecisionListener(XmppActivity activity, Conversation conversation, XmppConnectionService xmppConnectionService, List<Uri> uris) {
+ super(activity, conversation, xmppConnectionService);
+ this.uris = uris;
+ }
+
+ @Override
+ public void onYes() {
+ if (null != this.uris && !this.uris.isEmpty()) {
+ for (Uri uri : this.uris) {
+ this.setUri(uri);
+ super.onYes();
+ }
+ }
+ this.finishSharing();
+ }
+
+ @Override
+ public void onNo() {
+ if (null != this.uris && !this.uris.isEmpty()) {
+ for (Uri uri : this.uris) {
+ this.setUri(uri);
+ super.onNo();
+ }
+ }
+ this.finishSharing();
+ }
+
+ protected void finishSharing() {
+ this.activity.switchToConversation(conversation, null, true);
+ this.activity.finish();
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
new file mode 100644
index 00000000..1c16095c
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
@@ -0,0 +1,47 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import android.content.Context;
+import android.view.View;
+
+import de.thedevstack.conversationsplus.ui.adapter.PresencesArrayAdapter;
+import de.thedevstack.conversationsplus.ui.dialogs.AbstractAlertDialog;
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Contact;
+
+/**
+ * This listener shows the dialog with the resources of a contact.
+ * The resources are shown with the color of their current online mode.
+ * This listener implements OnClickListener and OnLongClickListener.
+ */
+public class ShowResourcesListDialogListener extends AbstractAlertDialog implements View.OnClickListener, View.OnLongClickListener {
+ private Contact contact;
+
+ public ShowResourcesListDialogListener(Context context, Contact contact) {
+ super(context, getTitle(context, contact));
+ this.contact = contact;
+ this.init();
+ }
+
+ private static final String getTitle(Context context, Contact contact) {
+ if (null != contact && null != contact.getJid() && null != contact.getJid().toBareJid()) {
+ int presenceCount = null != contact.getPresences() ? contact.getPresences().size() : 0;
+ return context.getString(R.string.dlg_resources_title, contact.getJid().toBareJid().toString(), presenceCount);
+ }
+ return null != contact ? contact.toString() : "";
+ }
+
+ protected void init() {
+ this.builder.setAdapter(new PresencesArrayAdapter(getContext(), this.contact.getPresences()), null);
+ }
+
+ @Override
+ public void onClick(View v) {
+ this.show();
+ }
+
+ @Override
+ public boolean onLongClick(View view) {
+ this.show();
+ return true;
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
new file mode 100644
index 00000000..fbee6290
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
@@ -0,0 +1,12 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+import de.thedevstack.conversationsplus.enums.UserDecision;
+
+/**
+ * Created by tzur on 31.10.2015.
+ */
+public interface UserDecisionListener {
+ void onYes();
+ void onNo();
+ void onRemember(UserDecision decision);
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java
new file mode 100644
index 00000000..5dcfc607
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java
@@ -0,0 +1,31 @@
+package de.thedevstack.conversationsplus.ui.preferences;
+
+import android.content.Context;
+import android.content.Intent;
+import android.preference.Preference;
+import android.util.AttributeSet;
+
+import de.thedevstack.conversationsplus.ui.LogCatOutputActivity;
+
+/**
+ * Created by tzur on 07.10.2015.
+ */
+public class LogInformationPreference extends Preference {
+ public LogInformationPreference(final Context context, final AttributeSet attrs, final int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public LogInformationPreference(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ }
+ public LogInformationPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void onClick() {
+ super.onClick();
+ final Intent intent = new Intent(getContext(), LogCatOutputActivity.class);
+ getContext().startActivity(intent);
+ }
+}