Search in sources :

Example 1 with SettableFuture

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

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)

Example 2 with SettableFuture

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

the class SignalMapView method display.

public ListenableFuture<Bitmap> display(final SignalPlace place) {
    final SettableFuture<Bitmap> future = new SettableFuture<>();
    this.mapView.onCreate(null);
    this.mapView.onResume();
    this.mapView.setVisibility(View.VISIBLE);
    this.imageView.setVisibility(View.GONE);
    this.mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(final GoogleMap googleMap) {
            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
            googleMap.addMarker(new MarkerOptions().position(place.getLatLong()));
            googleMap.setBuildingsEnabled(true);
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            googleMap.getUiSettings().setAllGesturesEnabled(false);
            googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {

                @Override
                public void onMapLoaded() {
                    googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {

                        @Override
                        public void onSnapshotReady(Bitmap bitmap) {
                            future.set(bitmap);
                            imageView.setImageBitmap(bitmap);
                            imageView.setVisibility(View.VISIBLE);
                            mapView.setVisibility(View.GONE);
                            mapView.onPause();
                            mapView.onDestroy();
                        }
                    });
                }
            });
        }
    });
    this.textView.setText(place.getDescription());
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback)

Example 3 with SettableFuture

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

the class VerificationPinKeyboard method displayFailure.

public ListenableFuture<Boolean> displayFailure() {
    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.failureView.getBackground().setColorFilter(getResources().getColor(R.color.red_500), PorterDuff.Mode.SRC_IN);
    this.failureView.setVisibility(View.VISIBLE);
    TranslateAnimation shake = new TranslateAnimation(0, 30, 0, 0);
    shake.setDuration(50);
    shake.setRepeatCount(7);
    shake.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) {
        }
    });
    this.failureView.startAnimation(shake);
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) TranslateAnimation(android.view.animation.TranslateAnimation) ScaleAnimation(android.view.animation.ScaleAnimation) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation)

Example 4 with SettableFuture

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

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

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

the class ScribbleView method getRenderedImage.

@SuppressLint("StaticFieldLeak")
@NonNull
public ListenableFuture<Bitmap> getRenderedImage(@NonNull GlideRequests glideRequests) {
    final SettableFuture<Bitmap> future = new SettableFuture<>();
    final Context context = getContext();
    final boolean isLowMemory = Util.isLowMemory(context);
    if (imageUri == 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 glideRequests.asBitmap().load(new DecryptableUri(imageUri)).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);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    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) SuppressLint(android.annotation.SuppressLint)

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