aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-05 21:06:10 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-06 15:28:19 +0200
commit9fc7a1b980863955a139193ded0fef5edfbad296 (patch)
tree0784b7afce2872633acd7890c1d4f97f189e7741 /src/eu
parent77491039097734ce746b5b46791464bd236d4703 (diff)
added button to open images
Diffstat (limited to 'src/eu')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java76
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java10
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java20
-rw-r--r--src/eu/siacs/conversations/utils/PhoneHelper.java23
4 files changed, 117 insertions, 12 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
new file mode 100644
index 00000000..05c50530
--- /dev/null
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -0,0 +1,76 @@
+package eu.siacs.conversations.persistance;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.math.BigInteger;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.util.Log;
+
+import eu.siacs.conversations.entities.Conversation;
+
+
+public class FileBackend {
+
+ private static int IMAGE_SIZE = 1920;
+
+ private Context context;
+
+ public FileBackend(Context context) {
+ this.context = context;
+ }
+
+
+ public File copyImageToPrivateStorage(Conversation conversation, Uri image) {
+ try {
+ InputStream is = context.getContentResolver().openInputStream(image);
+ String prefix = context.getFilesDir().getAbsolutePath();
+ String path = prefix+"/"+conversation.getAccount().getJid()+"/"+conversation.getContactJid();
+ String filename =new BigInteger(""+System.currentTimeMillis()).toString(32) + ".webp";
+ File file = new File(path+"/"+filename);
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+ OutputStream os = new FileOutputStream(file);
+ Bitmap originalBitmap = BitmapFactory.decodeStream(is);
+ is.close();
+ int w = originalBitmap.getWidth();
+ int h = originalBitmap.getHeight();
+ boolean success;
+ if (Math.max(w, h) > IMAGE_SIZE) {
+ int scalledW;
+ int scalledH;
+ if (w<=h) {
+ scalledW = (int) (w / ((double) h/IMAGE_SIZE));
+ scalledH = IMAGE_SIZE;
+ } else {
+ scalledW = IMAGE_SIZE;
+ scalledH = (int) (h / ((double) w/IMAGE_SIZE));
+ }
+ Bitmap scalledBitmap = Bitmap.createScaledBitmap(originalBitmap, scalledW,scalledH, true);
+ success = scalledBitmap.compress(Bitmap.CompressFormat.WEBP, 75, os);
+ } else {
+ success = originalBitmap.compress(Bitmap.CompressFormat.WEBP, 75, os);
+ }
+ if (!success) {
+ Log.d("xmppService","couldnt compress");
+ }
+ os.close();
+ return file;
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+}
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 9dbce675..76e7d728 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -27,6 +27,7 @@ import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.persistance.DatabaseBackend;
+import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.persistance.OnPhoneContactsMerged;
import eu.siacs.conversations.ui.OnAccountListChangedListener;
import eu.siacs.conversations.ui.OnConversationListChangedListener;
@@ -73,6 +74,7 @@ public class XmppConnectionService extends Service {
protected static final String LOGTAG = "xmppService";
public DatabaseBackend databaseBackend;
+ private FileBackend fileBackend;
public long startDate;
@@ -381,6 +383,11 @@ public class XmppConnectionService extends Service {
}
+ public FileBackend getFileBackend() {
+ return this.fileBackend;
+ }
+
+
protected Conversation findMuc(String name, Account account) {
for (Conversation conversation : this.conversations) {
if (conversation.getContactJid().split("/")[0].equals(name)
@@ -522,7 +529,8 @@ public class XmppConnectionService extends Service {
@Override
public void onCreate() {
ExceptionHelper.init(getApplicationContext());
- databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
+ this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
+ this.fileBackend = new FileBackend(getApplicationContext());
this.accounts = databaseBackend.getAccounts();
this.getConversations();
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 41ee6336..82b33499 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1,5 +1,8 @@
package eu.siacs.conversations.ui;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -8,8 +11,11 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.ExceptionHelper;
+import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper;
+import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.AlertDialog;
@@ -18,6 +24,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.widget.SlidingPaneLayout;
@@ -46,6 +53,7 @@ public class ConversationActivity extends XmppActivity {
public static final int REQUEST_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783;
+ private static final int ATTACH_FILE = 0x48502;
protected SlidingPaneLayout spl;
@@ -272,6 +280,13 @@ public class ConversationActivity extends XmppActivity {
case android.R.id.home:
spl.openPane();
break;
+ case R.id.action_attach_file:
+ Intent attachFileIntent = new Intent();
+ attachFileIntent.setType("image/*");
+ attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
+ startActivityForResult(Intent.createChooser(attachFileIntent,
+ "Attach File"), ATTACH_FILE);
+ break;
case R.id.action_add:
startActivity(new Intent(this, ContactsActivity.class));
break;
@@ -478,6 +493,11 @@ public class ConversationActivity extends XmppActivity {
if (selectedFragment!=null) {
selectedFragment.hidePgpPassphraseBox();
}
+ } else if (requestCode == ATTACH_FILE) {
+ FileBackend backend = xmppConnectionService.getFileBackend();
+ File file = backend.copyImageToPrivateStorage(getSelectedConversation(), data.getData());
+ Log.d(LOGTAG,"new file"+file.getAbsolutePath());
+
}
}
}
diff --git a/src/eu/siacs/conversations/utils/PhoneHelper.java b/src/eu/siacs/conversations/utils/PhoneHelper.java
index 5c652afe..dd3e0e19 100644
--- a/src/eu/siacs/conversations/utils/PhoneHelper.java
+++ b/src/eu/siacs/conversations/utils/PhoneHelper.java
@@ -13,18 +13,19 @@ import android.os.Bundle;
import android.os.Looper;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Profile;
+import android.provider.MediaStore;
public class PhoneHelper {
-
- public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
- if (Looper.myLooper()==null) {
+
+ public static void loadPhoneContacts(Context context,
+ final OnPhoneContactsLoadedListener listener) {
+ if (Looper.myLooper() == null) {
Looper.prepare();
}
final Looper mLooper = Looper.myLooper();
final Hashtable<String, Bundle> phoneContacts = new Hashtable<String, Bundle>();
-
- final String[] PROJECTION = new String[] {
- ContactsContract.Data._ID,
+
+ final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.PHOTO_THUMBNAIL_URI,
ContactsContract.Data.LOOKUP_KEY,
@@ -35,7 +36,7 @@ public class PhoneHelper {
+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
+ "\")";
-
+
CursorLoader mCursorLoader = new CursorLoader(context,
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
null);
@@ -55,14 +56,14 @@ public class PhoneHelper {
"photouri",
cursor.getString(cursor
.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI)));
- contact.putString("lookup",cursor.getString(cursor
+ contact.putString("lookup", cursor.getString(cursor
.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
phoneContacts.put(
cursor.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
contact);
}
- if (listener!=null) {
+ if (listener != null) {
listener.onPhoneContactsLoaded(phoneContacts);
}
mLooper.quit();
@@ -77,12 +78,12 @@ public class PhoneHelper {
Cursor mProfileCursor = activity.getContentResolver().query(
Profile.CONTENT_URI, mProjection, null, null, null);
- if (mProfileCursor.getCount()==0) {
+ if (mProfileCursor.getCount() == 0) {
return null;
} else {
mProfileCursor.moveToFirst();
String uri = mProfileCursor.getString(1);
- if (uri==null) {
+ if (uri == null) {
return null;
} else {
return Uri.parse(uri);