This commit is contained in:
iNPUTmice 2014-11-06 17:25:14 +01:00
parent dace729c5b
commit e42b6d715b
1 changed files with 26 additions and 24 deletions

View File

@ -10,10 +10,6 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.net.Uri; import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.MediaStore; import android.provider.MediaStore;
@ -55,20 +51,21 @@ public class ConversationActivity extends XmppActivity implements
public static final int REQUEST_SEND_MESSAGE = 0x0201; public static final int REQUEST_SEND_MESSAGE = 0x0201;
public static final int REQUEST_DECRYPT_PGP = 0x0202; public static final int REQUEST_DECRYPT_PGP = 0x0202;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0203; private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0203;
private static final int REQUEST_IMAGE_CAPTURE = 0x0204; private static final int REQUEST_IMAGE_CAPTURE = 0x0204;
private static final int REQUEST_RECORD_AUDIO = 0x0205; private static final int REQUEST_RECORD_AUDIO = 0x0205;
private static final int REQUEST_SEND_PGP_IMAGE = 0x0206; private static final int REQUEST_SEND_PGP_IMAGE = 0x0206;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303; private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation"; 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_PANEL_OPEN = "state_panel_open";
private static final String STATE_PENDING_URI = "state_pending_uri";
private String mOpenConverstaion = null; private String mOpenConverstaion = null;
private boolean mPanelOpen = true; private boolean mPanelOpen = true;
private Uri mPendingImageUri = null;
private View mContentView; private View mContentView;
@ -81,7 +78,6 @@ public class ConversationActivity extends XmppActivity implements
private Toast prepareImageToast; private Toast prepareImageToast;
private Uri pendingImageUri = null;
public List<Conversation> getConversationList() { public List<Conversation> getConversationList() {
return this.conversationList; return this.conversationList;
@ -148,11 +144,14 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mOpenConverstaion = savedInstanceState.getString( mOpenConverstaion = savedInstanceState.getString(
STATE_OPEN_CONVERSATION, null); STATE_OPEN_CONVERSATION, null);
mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true); mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true);
String pending = savedInstanceState.getString(STATE_PENDING_URI, null);
if (pending != null) {
mPendingImageUri = Uri.parse(pending);
}
} }
setContentView(R.layout.fragment_conversations_overview); setContentView(R.layout.fragment_conversations_overview);
@ -301,12 +300,12 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onPresenceSelected() { public void onPresenceSelected() {
if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) { if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
pendingImageUri = xmppConnectionService.getFileBackend() mPendingImageUri = xmppConnectionService.getFileBackend()
.getTakePhotoUri(); .getTakePhotoUri();
Intent takePictureIntent = new Intent( Intent takePictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE); MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
pendingImageUri); mPendingImageUri);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE); REQUEST_IMAGE_CAPTURE);
@ -680,6 +679,9 @@ public class ConversationActivity extends XmppActivity implements
} }
savedInstanceState.putBoolean(STATE_PANEL_OPEN, savedInstanceState.putBoolean(STATE_PANEL_OPEN,
isConversationsOverviewVisable()); isConversationsOverviewVisable());
if (this.mPendingImageUri != null) {
savedInstanceState.putString(STATE_PENDING_URI, this.mPendingImageUri.toString());
}
super.onSaveInstanceState(savedInstanceState); super.onSaveInstanceState(savedInstanceState);
} }
@ -712,16 +714,16 @@ public class ConversationActivity extends XmppActivity implements
if (selectedFragment != null) { if (selectedFragment != null) {
selectedFragment.onBackendConnected(); selectedFragment.onBackendConnected();
} else { } else {
pendingImageUri = null; mPendingImageUri = null;
setSelectedConversation(conversationList.get(0)); setSelectedConversation(conversationList.get(0));
swapConversationFragment(); swapConversationFragment();
} }
} }
if (pendingImageUri != null) { if (mPendingImageUri != null) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),
pendingImageUri); mPendingImageUri);
pendingImageUri = null; mPendingImageUri = null;
} }
ExceptionHelper.checkForCrash(this, this.xmppConnectionService); ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
} }
@ -761,11 +763,11 @@ public class ConversationActivity extends XmppActivity implements
selectedFragment.updateMessages(); selectedFragment.updateMessages();
} }
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
pendingImageUri = data.getData(); mPendingImageUri = data.getData();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),
pendingImageUri); mPendingImageUri);
pendingImageUri = null; mPendingImageUri = null;
} }
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) { } else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
@ -778,15 +780,15 @@ public class ConversationActivity extends XmppActivity implements
getSelectedConversation()); getSelectedConversation());
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) { } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
// encryptTextMessage(); // encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE) { } else if (requestCode == REQUEST_IMAGE_CAPTURE && mPendingImageUri != null) {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),
pendingImageUri); mPendingImageUri);
pendingImageUri = null; mPendingImageUri = null;
} }
Intent intent = new Intent( Intent intent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(pendingImageUri); intent.setData(mPendingImageUri);
sendBroadcast(intent); sendBroadcast(intent);
} else if (requestCode == REQUEST_RECORD_AUDIO) { } else if (requestCode == REQUEST_RECORD_AUDIO) {
attachAudioToConversation(getSelectedConversation(), attachAudioToConversation(getSelectedConversation(),
@ -794,7 +796,7 @@ public class ConversationActivity extends XmppActivity implements
} }
} else { } else {
if (requestCode == REQUEST_IMAGE_CAPTURE) { if (requestCode == REQUEST_IMAGE_CAPTURE) {
pendingImageUri = null; mPendingImageUri = null;
} }
} }
} }