2018-04-27 00:03:54 +00:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.app.Activity;
|
2018-10-11 23:45:22 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2018-04-27 00:03:54 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
2018-08-06 18:42:22 +00:00
|
|
|
import android.support.v4.app.TaskStackBuilder;
|
2018-04-27 00:03:54 +00:00
|
|
|
import android.text.TextUtils;
|
2018-10-11 23:45:22 +00:00
|
|
|
import android.widget.Toast;
|
2018-04-27 00:03:54 +00:00
|
|
|
|
2019-02-01 03:28:40 +00:00
|
|
|
import org.thoughtcrime.securesms.conversation.ConversationActivity;
|
2018-04-27 00:03:54 +00:00
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
import org.thoughtcrime.securesms.WebRtcCallActivity;
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
|
|
|
|
|
|
|
public class CommunicationActions {
|
|
|
|
|
|
|
|
public static void startVoiceCall(@NonNull Activity activity, @NonNull Recipient recipient) {
|
|
|
|
Permissions.with(activity)
|
|
|
|
.request(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
|
|
|
|
.ifNecessary()
|
|
|
|
.withRationaleDialog(activity.getString(R.string.ConversationActivity_to_call_s_signal_needs_access_to_your_microphone_and_camera, recipient.toShortString()),
|
|
|
|
R.drawable.ic_mic_white_48dp,
|
|
|
|
R.drawable.ic_videocam_white_48dp)
|
|
|
|
.withPermanentDenialDialog(activity.getString(R.string.ConversationActivity_signal_needs_the_microphone_and_camera_permissions_in_order_to_call_s, recipient.toShortString()))
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
Intent intent = new Intent(activity, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, recipient.getAddress());
|
|
|
|
activity.startService(intent);
|
|
|
|
|
|
|
|
Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);
|
|
|
|
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
activity.startActivity(activityIntent);
|
|
|
|
})
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:42:22 +00:00
|
|
|
public static void startConversation(@NonNull Context context, @NonNull Recipient recipient, @Nullable String text) {
|
|
|
|
startConversation(context, recipient, text, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void startConversation(@NonNull Context context,
|
|
|
|
@NonNull Recipient recipient,
|
|
|
|
@Nullable String text,
|
|
|
|
@Nullable TaskStackBuilder backStack)
|
2018-04-27 00:03:54 +00:00
|
|
|
{
|
|
|
|
new AsyncTask<Void, Void, Long>() {
|
|
|
|
@Override
|
|
|
|
protected Long doInBackground(Void... voids) {
|
|
|
|
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Long threadId) {
|
|
|
|
Intent intent = new Intent(context, ConversationActivity.class);
|
|
|
|
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.getAddress());
|
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
|
|
intent.putExtra(ConversationActivity.TIMING_EXTRA, System.currentTimeMillis());
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(text)) {
|
|
|
|
intent.putExtra(ConversationActivity.TEXT_EXTRA, text);
|
|
|
|
}
|
|
|
|
|
2018-08-06 18:42:22 +00:00
|
|
|
if (backStack != null) {
|
|
|
|
backStack.addNextIntent(intent);
|
|
|
|
backStack.startActivities();
|
|
|
|
} else {
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2018-04-27 00:03:54 +00:00
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void composeSmsThroughDefaultApp(@NonNull Context context, @NonNull Address address, @Nullable String text) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + address.serialize()));
|
|
|
|
if (text != null) {
|
|
|
|
intent.putExtra("sms_body", text);
|
|
|
|
}
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2018-10-11 23:45:22 +00:00
|
|
|
|
|
|
|
public static void openBrowserLink(@NonNull Context context, @NonNull String link) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
|
|
|
|
context.startActivity(intent);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(context, R.string.CommunicationActions_no_browser_found, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
2018-04-27 00:03:54 +00:00
|
|
|
}
|