Search in sources :

Example 16 with SettableFuture

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

the class VerificationPinKeyboard method displayLocked.

public ListenableFuture<Boolean> displayLocked() {
    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.lockedView.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.lockedView, 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 17 with SettableFuture

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

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 18 with SettableFuture

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

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 19 with SettableFuture

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

the class ScribbleView method getRenderedImage.

@NonNull
public ListenableFuture<Bitmap> getRenderedImage() {
    final SettableFuture<Bitmap> future = new SettableFuture<>();
    final Context context = getContext();
    final boolean isLowMemory = Util.isLowMemory(context);
    if (imageUri == null || masterSecret == null) {
        future.set(null);
        return future;
    }
    new AsyncTask<Void, Void, Bitmap>() {

        @Override
        @Nullable
        protected Bitmap doInBackground(Void... params) {
            try {
                int width = Target.SIZE_ORIGINAL;
                int height = Target.SIZE_ORIGINAL;
                if (isLowMemory) {
                    width = 768;
                    height = 768;
                }
                return Glide.with(context).load(new DecryptableUri(masterSecret, imageUri)).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(width, height).get();
            } catch (InterruptedException | ExecutionException e) {
                Log.w(TAG, e);
                return null;
            }
        }

        @Override
        protected void onPostExecute(@Nullable Bitmap bitmap) {
            if (bitmap == null) {
                future.set(null);
                return;
            }
            Canvas canvas = new Canvas(bitmap);
            motionView.render(canvas);
            canvasView.render(canvas);
            future.set(bitmap);
        }
    }.execute();
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) Nullable(android.support.annotation.Nullable) NonNull(android.support.annotation.NonNull)

Example 20 with SettableFuture

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

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)

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