Search in sources :

Example 1 with ListenableFuture

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

the class ConversationActivity method onRecorderCanceled.

@Override
public void onRecorderCanceled() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(50);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(final Pair<Uri, Long> result) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first);
                    return null;
                }
            }.execute();
        }

        @Override
        public void onFailure(ExecutionException e) {
        }
    });
}
Also used : AsyncTask(android.os.AsyncTask) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Uri(android.net.Uri) Pair(android.util.Pair)

Example 2 with ListenableFuture

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

the class ScribbleActivity method onSave.

@Override
public void onSave() {
    ListenableFuture<Bitmap> future = scribbleView.getRenderedImage(glideRequests);
    future.addListener(new ListenableFuture.Listener<Bitmap>() {

        @Override
        public void onSuccess(Bitmap result) {
            PersistentBlobProvider provider = PersistentBlobProvider.getInstance(ScribbleActivity.this);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            result.compress(Bitmap.CompressFormat.JPEG, 80, baos);
            byte[] data = baos.toByteArray();
            baos = null;
            result = null;
            Uri uri = provider.create(ScribbleActivity.this, data, MediaUtil.IMAGE_JPEG, null);
            Intent intent = new Intent();
            intent.setData(uri);
            setResult(RESULT_OK, intent);
            finish();
        }

        @Override
        public void onFailure(ExecutionException e) {
            Log.w(TAG, e);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PersistentBlobProvider(org.thoughtcrime.securesms.providers.PersistentBlobProvider) ExecutionException(java.util.concurrent.ExecutionException) Uri(android.net.Uri)

Example 3 with ListenableFuture

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

the class ConversationActivity method onRecorderCanceled.

@Override
public void onRecorderCanceled() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    vibrator.vibrate(50);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(final Pair<Uri, Long> result) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }

        @Override
        public void onFailure(ExecutionException e) {
        }
    });
}
Also used : AsyncTask(android.os.AsyncTask) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Uri(android.net.Uri) Pair(android.util.Pair)

Example 4 with ListenableFuture

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

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    vibrator.vibrate(20);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(@NonNull final Pair<Uri, Long> result) {
            boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
            int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
            long expiresIn = recipient.getExpireMessages() * 1000L;
            boolean initiating = threadId == -1;
            AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true);
            SlideDeck slideDeck = new SlideDeck();
            slideDeck.addSlide(audioSlide);
            sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() {

                @Override
                public void onSuccess(Void nothing) {
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
                            return null;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Uri(android.net.Uri) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair)

Example 5 with ListenableFuture

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

the class ScribbleActivity method onSave.

@Override
public void onSave() {
    ListenableFuture<Bitmap> future = scribbleView.getRenderedImage();
    future.addListener(new ListenableFuture.Listener<Bitmap>() {

        @Override
        public void onSuccess(Bitmap result) {
            PersistentBlobProvider provider = PersistentBlobProvider.getInstance(ScribbleActivity.this);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            result.compress(Bitmap.CompressFormat.JPEG, 80, baos);
            byte[] data = baos.toByteArray();
            baos = null;
            result = null;
            Uri uri = provider.create(masterSecret, data, ContentType.IMAGE_JPEG);
            Intent intent = new Intent();
            intent.setData(uri);
            setResult(RESULT_OK, intent);
            finish();
        }

        @Override
        public void onFailure(ExecutionException e) {
            Log.w(TAG, e);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PersistentBlobProvider(org.thoughtcrime.securesms.providers.PersistentBlobProvider) ExecutionException(java.util.concurrent.ExecutionException) Uri(android.net.Uri)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)7 ListenableFuture (org.thoughtcrime.securesms.util.concurrent.ListenableFuture)7 Uri (android.net.Uri)6 Vibrator (android.os.Vibrator)5 Pair (android.util.Pair)4 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2 AsyncTask (android.os.AsyncTask)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)2 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)2 PersistentBlobProvider (org.thoughtcrime.securesms.providers.PersistentBlobProvider)2 AssertedSuccessListener (org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener)2 VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1