2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2014 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2014-12-15 20:25:55 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2014-12-15 20:25:55 +00:00
|
|
|
import android.webkit.MimeTypeMap;
|
2014-02-28 06:44:02 +00:00
|
|
|
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2014-02-28 06:44:02 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2014-12-15 20:25:55 +00:00
|
|
|
|
|
|
|
import ws.com.google.android.mms.ContentType;
|
2014-02-28 06:44:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An activity to quickly share content with contacts
|
|
|
|
*
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
2014-06-29 03:40:57 +00:00
|
|
|
public class ShareActivity extends PassphraseRequiredActionBarActivity
|
2014-02-28 06:44:02 +00:00
|
|
|
implements ShareFragment.ConversationSelectedListener
|
2014-12-15 20:25:55 +00:00
|
|
|
{
|
2014-02-28 06:44:02 +00:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme ();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
@Override
|
2014-12-15 20:25:55 +00:00
|
|
|
protected void onPreCreate() {
|
2014-02-28 06:44:02 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
2014-02-28 06:44:02 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
|
2014-02-28 06:44:02 +00:00
|
|
|
setContentView(R.layout.share_activity);
|
2014-12-15 20:25:55 +00:00
|
|
|
initFragment(R.id.drawer_layout, new ShareFragment(), masterSecret);
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
setIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
2014-04-09 20:26:06 +00:00
|
|
|
getSupportActionBar().setTitle(R.string.ShareActivity_share_with);
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
if (!isFinishing()) finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2014-06-29 03:40:57 +00:00
|
|
|
MenuInflater inflater = this.getMenuInflater();
|
2014-02-28 06:44:02 +00:00
|
|
|
menu.clear();
|
|
|
|
|
|
|
|
inflater.inflate(R.menu.share, menu);
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_new_message: handleNewConversation(); return true;
|
|
|
|
case android.R.id.home: finish(); return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleNewConversation() {
|
|
|
|
Intent intent = getBaseShareIntent(NewConversationActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateConversation(long threadId, Recipients recipients, int distributionType) {
|
|
|
|
createConversation(threadId, recipients, distributionType);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createConversation(long threadId, Recipients recipients, int distributionType) {
|
|
|
|
final Intent intent = getBaseShareIntent(ConversationActivity.class);
|
2014-12-18 02:14:19 +00:00
|
|
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
2014-02-28 06:44:02 +00:00
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
private Intent getBaseShareIntent(final Class<?> target) {
|
|
|
|
final Intent intent = new Intent(this, target);
|
|
|
|
final String textExtra = getIntent().getStringExtra(ConversationActivity.DRAFT_TEXT_EXTRA);
|
|
|
|
final Uri streamExtra = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
final String type = streamExtra != null ? getMimeType(streamExtra) : getIntent().getType();
|
|
|
|
|
|
|
|
if (ContentType.isImageType(type)) {
|
|
|
|
intent.putExtra(ConversationActivity.DRAFT_IMAGE_EXTRA, streamExtra);
|
|
|
|
} else if (ContentType.isAudioType(type)) {
|
|
|
|
intent.putExtra(ConversationActivity.DRAFT_AUDIO_EXTRA, streamExtra);
|
|
|
|
} else if (ContentType.isVideoType(type)) {
|
|
|
|
intent.putExtra(ConversationActivity.DRAFT_VIDEO_EXTRA, streamExtra);
|
|
|
|
}
|
|
|
|
intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, textExtra);
|
2014-02-28 06:44:02 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
return intent;
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
private String getMimeType(Uri uri) {
|
|
|
|
String type = getContentResolver().getType(uri);
|
2014-02-28 06:44:02 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
if (type == null) {
|
|
|
|
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
|
|
|
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|