Search in sources :

Example 6 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by signalapp.

the class ConversationActivity method sendMediaMessage.

private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, final long expiresIn, final int subscriptionId, final boolean initiating) {
    OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(recipient, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType);
    final SettableFuture<Void> future = new SettableFuture<>();
    final Context context = getApplicationContext();
    final OutgoingMediaMessage outgoingMessage;
    if (isSecureText && !forceSms) {
        outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessageCandidate);
    } else {
        outgoingMessage = outgoingMessageCandidate;
    }
    Permissions.with(this).request(Manifest.permission.SEND_SMS, Manifest.permission.READ_SMS).ifNecessary(!isSecureText || forceSms).withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms)).onAllGranted(() -> {
        attachmentManager.clear(glideRequests, false);
        composeText.setText("");
        final long id = fragment.stageOutgoingMessage(outgoingMessage);
        new AsyncTask<Void, Void, Long>() {

            @Override
            protected Long doInBackground(Void... param) {
                if (initiating) {
                    DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true);
                }
                return MessageSender.send(context, outgoingMessage, threadId, forceSms, () -> fragment.releaseOutgoingMessage(id));
            }

            @Override
            protected void onPostExecute(Long result) {
                sendComplete(result);
                future.set(null);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }).onAnyDenied(() -> future.set(null)).execute();
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage)

Example 7 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by signalapp.

the class ConversationActivity method initializeIdentityRecords.

private ListenableFuture<Boolean> initializeIdentityRecords() {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() {

        @Override
        @NonNull
        protected Pair<IdentityRecordList, String> doInBackground(Recipient... params) {
            IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this);
            IdentityRecordList identityRecordList = new IdentityRecordList();
            List<Recipient> recipients = new LinkedList<>();
            if (params[0].isGroupRecipient()) {
                recipients.addAll(DatabaseFactory.getGroupDatabase(ConversationActivity.this).getGroupMembers(params[0].getAddress().toGroupString(), false));
            } else {
                recipients.add(params[0]);
            }
            for (Recipient recipient : recipients) {
                Log.w(TAG, "Loading identity for: " + recipient.getAddress());
                identityRecordList.add(identityDatabase.getIdentity(recipient.getAddress()));
            }
            String message = null;
            if (identityRecordList.isUnverified()) {
                message = IdentityUtil.getUnverifiedBannerDescription(ConversationActivity.this, identityRecordList.getUnverifiedRecipients(ConversationActivity.this));
            }
            return new Pair<>(identityRecordList, message);
        }

        @Override
        protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
            Log.w(TAG, "Got identity records: " + result.first.isUnverified());
            identityRecords.replaceWith(result.first);
            if (result.second != null) {
                Log.w(TAG, "Replacing banner...");
                unverifiedBannerView.get().display(result.second, result.first.getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener());
            } else if (unverifiedBannerView.resolved()) {
                Log.w(TAG, "Clearing banner...");
                unverifiedBannerView.get().hide();
            }
            titleView.setVerified(isSecureText && identityRecords.isVerified());
            future.set(true);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) NonNull(android.support.annotation.NonNull) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(android.util.Pair)

Example 8 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by signalapp.

the class AudioRecorder method stopRecording.

@NonNull
public ListenableFuture<Pair<Uri, Long>> stopRecording() {
    Log.w(TAG, "stopRecording()");
    final SettableFuture<Pair<Uri, Long>> future = new SettableFuture<>();
    executor.execute(() -> {
        if (audioCodec == null) {
            sendToFuture(future, new IOException("MediaRecorder was never initialized successfully!"));
            return;
        }
        audioCodec.stop();
        try {
            long size = MediaUtil.getMediaSize(context, captureUri);
            sendToFuture(future, new Pair<>(captureUri, size));
        } catch (IOException ioe) {
            Log.w(TAG, ioe);
            sendToFuture(future, ioe);
        }
        audioCodec = null;
        captureUri = null;
    });
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IOException(java.io.IOException) Pair(android.util.Pair) NonNull(android.support.annotation.NonNull)

Example 9 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by signalapp.

the class ViewUtil method animateOut.

public static ListenableFuture<Boolean> animateOut(@NonNull final View view, @NonNull final Animation animation, final int visibility) {
    final SettableFuture future = new SettableFuture();
    if (view.getVisibility() == visibility) {
        future.set(true);
    } else {
        view.clearAnimation();
        animation.reset();
        animation.setStartTime(0);
        animation.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                view.setVisibility(visibility);
                future.set(true);
            }
        });
        view.startAnimation(animation);
    }
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Animation(android.view.animation.Animation) AlphaAnimation(android.view.animation.AlphaAnimation)

Example 10 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by signalapp.

the class PeerConnectionWrapper method setLocalDescription.

public void setLocalDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setLocalDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            throw new AssertionError();
        }

        @Override
        public void onCreateFailure(String error) {
            throw new AssertionError();
        }

        @Override
        public void onSetSuccess() {
            future.set(true);
        }

        @Override
        public void onSetFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }
    }, sdp);
    try {
        future.get();
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Aggregations

SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)37 Context (android.content.Context)9 Animation (android.view.animation.Animation)8 ExecutionException (java.util.concurrent.ExecutionException)8 SdpObserver (org.webrtc.SdpObserver)8 SessionDescription (org.webrtc.SessionDescription)8 ScaleAnimation (android.view.animation.ScaleAnimation)6 TranslateAnimation (android.view.animation.TranslateAnimation)6 Bitmap (android.graphics.Bitmap)4 NonNull (android.support.annotation.NonNull)4 OvershootInterpolator (android.view.animation.OvershootInterpolator)4 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 DraftDatabase (org.thoughtcrime.securesms.database.DraftDatabase)4 Drafts (org.thoughtcrime.securesms.database.DraftDatabase.Drafts)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 SuppressLint (android.annotation.SuppressLint)3 SpannableString (android.text.SpannableString)3 List (java.util.List)3 VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)3