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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations