aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java112
1 files changed, 48 insertions, 64 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 306f61eb..5cfc1116 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -9,6 +9,7 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
+import android.media.MediaActionSound;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
@@ -52,19 +53,14 @@ public class ConversationActivity extends XmppActivity
public static final String CONVERSATION = "conversationUuid";
public static final String TEXT = "text";
public static final String NICK = "nick";
- public static final String PRESENCE = "eu.siacs.conversations.presence";
public static final int REQUEST_SEND_MESSAGE = 0x0201;
public static final int REQUEST_DECRYPT_PGP = 0x0202;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
- private static final int REQUEST_ATTACH_IMAGE_DIALOG = 0x0203;
- private static final int REQUEST_IMAGE_CAPTURE = 0x0204;
- private static final int REQUEST_RECORD_AUDIO = 0x0205;
- private static final int REQUEST_SEND_PGP_IMAGE = 0x0206;
- private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0208;
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
private static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
+ private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open";
private static final String STATE_PENDING_URI = "state_pending_uri";
@@ -100,10 +96,6 @@ public class ConversationActivity extends XmppActivity
this.mSelectedConversation = conversation;
}
- public ListView getConversationListView() {
- return this.listView;
- }
-
public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
@@ -346,33 +338,37 @@ public class ConversationActivity extends XmppActivity
@Override
public void onPresenceSelected() {
- if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
- mPendingImageUri = xmppConnectionService.getFileBackend()
- .getTakePhotoUri();
- Intent takePictureIntent = new Intent(
- MediaStore.ACTION_IMAGE_CAPTURE);
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
- mPendingImageUri);
- if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
- startActivityForResult(takePictureIntent,
- REQUEST_IMAGE_CAPTURE);
+ Intent intent = new Intent();
+ boolean chooser = false;
+ switch (attachmentChoice) {
+ case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ intent.setType("image/*");
+ chooser = true;
+ break;
+ case ATTACHMENT_CHOICE_TAKE_PHOTO:
+ mPendingImageUri = xmppConnectionService.getFileBackend().getTakePhotoUri();
+ intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
+ intent.putExtra(MediaStore.EXTRA_OUTPUT,mPendingImageUri);
+ break;
+ case ATTACHMENT_CHOICE_CHOOSE_FILE:
+ chooser = true;
+ intent.setType("*/*");
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ break;
+ case ATTACHMENT_CHOICE_RECORD_VOICE:
+ intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
+ break;
+ }
+ if (intent.resolveActivity(getPackageManager()) != null) {
+ if (chooser) {
+ startActivityForResult(
+ Intent.createChooser(intent,getString(R.string.perform_action_with)),
+ attachmentChoice);
+ } else {
+ startActivityForResult(intent, attachmentChoice);
}
- } else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
- Intent attachFileIntent = new Intent();
- attachFileIntent.setType("image/*");
- attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
- Intent chooser = Intent.createChooser(attachFileIntent,
- getString(R.string.attach_file));
- startActivityForResult(chooser, REQUEST_ATTACH_IMAGE_DIALOG);
- } else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_FILE) {
- Intent attachFileIntent = new Intent();
- //attachFileIntent.setType("file/*");
- attachFileIntent.setType("*/*");
- attachFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
- attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
- Intent chooser = Intent.createChooser(attachFileIntent,
- getString(R.string.attach_file));
- startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
}
}
});
@@ -541,8 +537,10 @@ public class ConversationActivity extends XmppActivity
}
PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
attachFilePopup.inflate(R.menu.attachment_choices);
- attachFilePopup
- .setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
+ attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
+ }
+ attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
@@ -553,9 +551,12 @@ public class ConversationActivity extends XmppActivity
case R.id.attach_take_picture:
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
break;
- case R.id.attach_record_voice:
+ case R.id.attach_choose_file:
attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
break;
+ case R.id.attach_record_voice:
+ attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
+ break;
}
return false;
}
@@ -864,44 +865,29 @@ public class ConversationActivity extends XmppActivity
if (requestCode == REQUEST_DECRYPT_PGP) {
mConversationFragment.hideSnackbar();
mConversationFragment.updateMessages();
- } else if (requestCode == REQUEST_ATTACH_IMAGE_DIALOG) {
+ } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
mPendingImageUri = data.getData();
if (xmppConnectionServiceBound) {
- attachImageToConversation(getSelectedConversation(),
- mPendingImageUri);
+ attachImageToConversation(getSelectedConversation(),mPendingImageUri);
mPendingImageUri = null;
}
- } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
+ } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) {
mPendingFileUri = data.getData();
if (xmppConnectionServiceBound) {
- attachFileToConversation(getSelectedConversation(),
- mPendingFileUri);
+ attachFileToConversation(getSelectedConversation(),mPendingFileUri);
mPendingFileUri = null;
}
- } else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
-
- } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
- attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
- } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
- attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
- } else if (requestCode == REQUEST_ANNOUNCE_PGP) {
- announcePgp(getSelectedConversation().getAccount(),
- getSelectedConversation());
- } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
- // encryptTextMessage();
- } else if (requestCode == REQUEST_IMAGE_CAPTURE && mPendingImageUri != null) {
+ } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO && mPendingImageUri != null) {
if (xmppConnectionServiceBound) {
- attachImageToConversation(getSelectedConversation(),
- mPendingImageUri);
+ attachImageToConversation(getSelectedConversation(),mPendingImageUri);
mPendingImageUri = null;
}
- Intent intent = new Intent(
- Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(mPendingImageUri);
sendBroadcast(intent);
}
} else {
- if (requestCode == REQUEST_IMAGE_CAPTURE) {
+ if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
mPendingImageUri = null;
}
}
@@ -941,8 +927,6 @@ public class ConversationActivity extends XmppActivity
public void userInputRequried(PendingIntent pi,
Message object) {
hidePrepareFileToast();
- ConversationActivity.this.runIntent(pi,
- ConversationActivity.REQUEST_SEND_PGP_IMAGE);
}
@Override