Search in sources :

Example 26 with SettableFuture

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

the class PeerConnectionWrapper method createOffer.

public SessionDescription createOffer(MediaConstraints mediaConstraints) throws PeerConnectionException {
    final SettableFuture<SessionDescription> future = new SettableFuture<>();
    peerConnection.createOffer(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            future.set(sdp);
        }

        @Override
        public void onCreateFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }

        @Override
        public void onSetSuccess() {
            throw new AssertionError();
        }

        @Override
        public void onSetFailure(String error) {
            throw new AssertionError();
        }
    }, mediaConstraints);
    try {
        return correctSessionDescription(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)

Example 27 with SettableFuture

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

the class VerificationPinKeyboard method displaySuccess.

public ListenableFuture<Boolean> displaySuccess() {
    SettableFuture<Boolean> result = new SettableFuture<>();
    this.keyboardView.setVisibility(View.INVISIBLE);
    this.progressBar.setVisibility(View.GONE);
    this.failureView.setVisibility(View.GONE);
    this.lockedView.setVisibility(View.GONE);
    this.successView.getBackground().setColorFilter(getResources().getColor(R.color.green_500), PorterDuff.Mode.SRC_IN);
    ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
    scaleAnimation.setInterpolator(new OvershootInterpolator());
    scaleAnimation.setDuration(800);
    scaleAnimation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            result.set(true);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    ViewUtil.animateIn(this.successView, scaleAnimation);
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) OvershootInterpolator(android.view.animation.OvershootInterpolator) ScaleAnimation(android.view.animation.ScaleAnimation) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) ScaleAnimation(android.view.animation.ScaleAnimation)

Example 28 with SettableFuture

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

the class ConversationActivity method saveDraft.

protected ListenableFuture<Long> saveDraft() {
    final SettableFuture<Long> future = new SettableFuture<>();
    if (this.recipient == null) {
        future.set(threadId);
        return future;
    }
    final Drafts drafts = getDraftsForCurrentState();
    final long thisThreadId = this.threadId;
    final int thisDistributionType = this.distributionType;
    new AsyncTask<Long, Void, Long>() {

        @Override
        protected Long doInBackground(Long... params) {
            ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
            DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
            long threadId = params[0];
            if (drafts.size() > 0) {
                if (threadId == -1)
                    threadId = threadDatabase.getThreadIdFor(getRecipient(), thisDistributionType);
                draftDatabase.insertDrafts(threadId, drafts);
                threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), drafts.getUriSnippet(), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
            } else if (threadId > 0) {
                threadDatabase.update(threadId, false);
            }
            return threadId;
        }

        @Override
        protected void onPostExecute(Long result) {
            future.set(result);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, thisThreadId);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SuppressLint(android.annotation.SuppressLint) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 29 with SettableFuture

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

the class AudioRecorder method stopRecording.

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

Example 30 with SettableFuture

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

the class ConversationParentFragment method initializeSecurity.

private ListenableFuture<Boolean> initializeSecurity(final boolean currentSecureText, final boolean currentIsDefaultSms) {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    final Context context = requireContext().getApplicationContext();
    handleSecurityChange(currentSecureText || isPushGroupConversation(), currentIsDefaultSms);
    new AsyncTask<Recipient, Void, boolean[]>() {

        @Override
        protected boolean[] doInBackground(Recipient... params) {
            Recipient recipient = params[0].resolve();
            Log.i(TAG, "Resolving registered state...");
            RegisteredState registeredState;
            if (recipient.isPushGroup()) {
                Log.i(TAG, "Push group recipient...");
                registeredState = RegisteredState.REGISTERED;
            } else {
                Log.i(TAG, "Checking through resolved recipient");
                registeredState = recipient.resolve().getRegistered();
            }
            Log.i(TAG, "Resolved registered state: " + registeredState);
            boolean signalEnabled = Recipient.self().isRegistered();
            if (registeredState == RegisteredState.UNKNOWN) {
                try {
                    Log.i(TAG, "Refreshing directory for user: " + recipient.getId().serialize());
                    registeredState = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
                } catch (IOException e) {
                    Log.w(TAG, e);
                }
            }
            Log.i(TAG, "Returning registered state...");
            return new boolean[] { registeredState == RegisteredState.REGISTERED && signalEnabled, Util.isDefaultSmsProvider(context) };
        }

        @Override
        protected void onPostExecute(boolean[] result) {
            if (result[0] != currentSecureText || result[1] != currentIsDefaultSms) {
                Log.i(TAG, "onPostExecute() handleSecurityChange: " + result[0] + " , " + result[1]);
                handleSecurityChange(result[0], result[1]);
            }
            future.set(true);
            onSecurityUpdated();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient.get());
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

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