Search in sources :

Example 56 with AsyncTask

use of android.os.AsyncTask in project android_packages_apps_Dialer by LineageOS.

the class ClearFrequentsDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity().getApplicationContext();
    final ContentResolver resolver = getActivity().getContentResolver();
    final OnClickListener okListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (!PermissionsUtil.hasContactsReadPermissions(context)) {
                return;
            }
            final ProgressDialog progressDialog = ProgressDialog.show(getContext(), getString(R.string.clearFrequentsProgress_title), null, true, true);
            final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    resolver.delete(ContactsContract.DataUsageFeedback.DELETE_USAGE_URI, null, null);
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    progressDialog.dismiss();
                }
            };
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    };
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.clearFrequentsConfirmation_title).setMessage(R.string.clearFrequentsConfirmation).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, okListener).setCancelable(true).create();
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) AsyncTask(android.os.AsyncTask) OnClickListener(android.content.DialogInterface.OnClickListener) ProgressDialog(android.app.ProgressDialog) ContentResolver(android.content.ContentResolver)

Example 57 with AsyncTask

use of android.os.AsyncTask in project xDrip by NightscoutFoundation.

the class ShareRest method getSessionId.

private String getSessionId() {
    AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() {

        @Override
        protected String doInBackground(String... params) {
            try {
                Boolean isActive = null;
                if (params[0] != null)
                    isActive = dexcomShareApi.checkSessionActive(params[0]).execute().body();
                if (isActive == null || !isActive) {
                    return updateAuthenticationParams();
                } else
                    return params[0];
            } catch (IOException e) {
                return null;
            } catch (RuntimeException e) {
                UserError.Log.wtf(TAG, "Painful exception processing response in updateAuthenticationParams " + e);
                return null;
            }
        }

        private String updateAuthenticationParams() throws IOException {
            sessionId = dexcomShareApi.getSessionId(new ShareAuthenticationBody(password, username).toMap()).execute().body();
            dexcomShareApi.authenticatePublisherAccount(sessionId, serialNumber, new ShareAuthenticationBody(password, username).toMap()).execute().body();
            dexcomShareApi.StartRemoteMonitoringSession(sessionId, serialNumber).execute();
            String assignment = dexcomShareApi.checkMonitorAssignment(sessionId, serialNumber).execute().body();
            if ((assignment != null) && (!assignment.equals("AssignedToYou"))) {
                dexcomShareApi.updateMonitorAssignment(sessionId, serialNumber).execute();
            }
            return sessionId;
        }
    };
    if (sessionId == null || sessionId.equals(""))
        try {
            sessionId = task.executeOnExecutor(xdrip.executor, sessionId).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    return sessionId;
}
Also used : ShareAuthenticationBody(com.eveningoutpost.dexdrip.ShareModels.Models.ShareAuthenticationBody) AsyncTask(android.os.AsyncTask) IOException(java.io.IOException)

Example 58 with AsyncTask

use of android.os.AsyncTask 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 59 with AsyncTask

use of android.os.AsyncTask in project Signal-Android by signalapp.

the class ConversationActivity method handleUnblock.

private void handleUnblock() {
    // noinspection CodeBlock2Expr
    new AlertDialog.Builder(this).setTitle(R.string.ConversationActivity_unblock_this_contact_question).setMessage(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact).setNegativeButton(android.R.string.cancel, null).setPositiveButton(R.string.ConversationActivity_unblock, (dialog, which) -> {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setBlocked(recipient, false);
                ApplicationContext.getInstance(ConversationActivity.this).getJobManager().add(new MultiDeviceBlockedUpdateJob(ConversationActivity.this));
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) UntrustedSendDialog(org.thoughtcrime.securesms.components.identity.UntrustedSendDialog) SendButton(org.thoughtcrime.securesms.components.SendButton) Uri(android.net.Uri) ColorDrawable(android.graphics.drawable.ColorDrawable) Dialogs(org.thoughtcrime.securesms.util.Dialogs) SecureRandom(java.security.SecureRandom) Manifest(android.Manifest) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) TargetApi(android.annotation.TargetApi) Log(android.util.Log) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) DrawerState(org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState) IntentFilter(android.content.IntentFilter) AnimatingToggle(org.thoughtcrime.securesms.components.AnimatingToggle) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GroupUtil(org.thoughtcrime.securesms.util.GroupUtil) MultiDeviceBlockedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob) TextWatcher(android.text.TextWatcher) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) Types(org.thoughtcrime.securesms.database.MmsSmsColumns.Types) Util(org.thoughtcrime.securesms.util.Util) AttachmentTypeSelector(org.thoughtcrime.securesms.components.AttachmentTypeSelector) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) WebRtcCallService(org.thoughtcrime.securesms.service.WebRtcCallService) NonNull(android.support.annotation.NonNull) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) Editable(android.text.Editable) AttachmentDrawerListener(org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) AudioRecorder(org.thoughtcrime.securesms.audio.AudioRecorder) ReminderView(org.thoughtcrime.securesms.components.reminder.ReminderView) KeyCachingService(org.thoughtcrime.securesms.service.KeyCachingService) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) QuickAttachmentDrawer(org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer) MenuInflater(android.view.MenuInflater) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) Toast(android.widget.Toast) Menu(android.view.Menu) InputAwareLayout(org.thoughtcrime.securesms.components.InputAwareLayout) UnverifiedBannerView(org.thoughtcrime.securesms.components.identity.UnverifiedBannerView) Type(org.thoughtcrime.securesms.TransportOption.Type) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) AudioSlidePlayer(org.thoughtcrime.securesms.audio.AudioSlidePlayer) Permissions(org.thoughtcrime.securesms.permissions.Permissions) TextUtils(android.text.TextUtils) IOException(java.io.IOException) InviteReminder(org.thoughtcrime.securesms.components.reminder.InviteReminder) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) AlertDialog(android.support.v7.app.AlertDialog) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor) Configuration(android.content.res.Configuration) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts) Telephony(android.provider.Telephony) WindowCompat(android.support.v4.view.WindowCompat) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) UnverifiedSendDialog(org.thoughtcrime.securesms.components.identity.UnverifiedSendDialog) MessageNotifier(org.thoughtcrime.securesms.notifications.MessageNotifier) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) DatabaseFactory(org.thoughtcrime.securesms.database.DatabaseFactory) WindowManager(android.view.WindowManager) Address(org.thoughtcrime.securesms.database.Address) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Browser(android.provider.Browser) AttachmentManager(org.thoughtcrime.securesms.mms.AttachmentManager) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) ContactsContract(android.provider.ContactsContract) OnFocusChangeListener(android.view.View.OnFocusChangeListener) SecurityEvent(org.thoughtcrime.securesms.crypto.SecurityEvent) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) View(android.view.View) Button(android.widget.Button) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ExpiredBuildReminder(org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder) AsyncTask(android.os.AsyncTask) MenuItemCompat(android.support.v4.view.MenuItemCompat) InputPanel(org.thoughtcrime.securesms.components.InputPanel) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) CharacterState(org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) PorterDuff(android.graphics.PorterDuff) ThreadMode(org.greenrobot.eventbus.ThreadMode) BroadcastReceiver(android.content.BroadcastReceiver) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) ScribbleActivity(org.thoughtcrime.securesms.scribbles.ScribbleActivity) ByteString(com.google.protobuf.ByteString) MediaType(org.thoughtcrime.securesms.mms.AttachmentManager.MediaType) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) MarkReadReceiver(org.thoughtcrime.securesms.notifications.MarkReadReceiver) DirectoryHelper(org.thoughtcrime.securesms.util.DirectoryHelper) ActivityNotFoundException(android.content.ActivityNotFoundException) SignalPlace(org.thoughtcrime.securesms.components.location.SignalPlace) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) SESSION_LOCK(org.whispersystems.libsignal.SessionCipher.SESSION_LOCK) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) Nullable(android.support.annotation.Nullable) EditorInfo(android.view.inputmethod.EditorInfo) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) KeyEvent(android.view.KeyEvent) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord) DynamicLanguage(org.thoughtcrime.securesms.util.DynamicLanguage) Pair(android.util.Pair) EmojiDrawer(org.thoughtcrime.securesms.components.emoji.EmojiDrawer) Intent(android.content.Intent) MaterialColor(org.thoughtcrime.securesms.color.MaterialColor) ExpirationUtil(org.thoughtcrime.securesms.util.ExpirationUtil) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) OnKeyboardShownListener(org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener) SuppressLint(android.annotation.SuppressLint) PlacePicker(com.google.android.gms.location.places.ui.PlacePicker) EventBus(org.greenrobot.eventbus.EventBus) Build(android.os.Build) GroupShareProfileView(org.thoughtcrime.securesms.profiles.GroupShareProfileView) LinkedList(java.util.LinkedList) ActionBar(android.support.v7.app.ActionBar) SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) HidingLinearLayout(org.thoughtcrime.securesms.components.HidingLinearLayout) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) Stub(org.thoughtcrime.securesms.util.views.Stub) Color(android.graphics.Color) OnKeyListener(android.view.View.OnKeyListener) ComposeText(org.thoughtcrime.securesms.components.ComposeText) PersistentBlobProvider(org.thoughtcrime.securesms.providers.PersistentBlobProvider) Subscribe(org.greenrobot.eventbus.Subscribe) RecipientModifiedListener(org.thoughtcrime.securesms.recipients.RecipientModifiedListener) ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Mode(android.graphics.PorterDuff.Mode) Vibrator(android.os.Vibrator) ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) OnClickListener(android.view.View.OnClickListener) UnauthorizedReminder(org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder) AsyncTask(android.os.AsyncTask) MultiDeviceBlockedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob)

Example 60 with AsyncTask

use of android.os.AsyncTask in project Signal-Android by signalapp.

the class ConversationItem method setExpiration.

@SuppressLint("StaticFieldLeak")
private void setExpiration(final MessageRecord messageRecord) {
    if (messageRecord.getExpiresIn() > 0) {
        this.expirationTimer.setVisibility(View.VISIBLE);
        this.expirationTimer.setPercentage(0);
        if (messageRecord.getExpireStarted() > 0) {
            this.expirationTimer.setExpirationTime(messageRecord.getExpireStarted(), messageRecord.getExpiresIn());
            this.expirationTimer.startAnimation();
        } else if (!messageRecord.isOutgoing() && !messageRecord.isMediaPending()) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
                    long id = messageRecord.getId();
                    boolean mms = messageRecord.isMms();
                    if (mms)
                        DatabaseFactory.getMmsDatabase(context).markExpireStarted(id);
                    else
                        DatabaseFactory.getSmsDatabase(context).markExpireStarted(id);
                    expirationManager.scheduleDeletion(id, mms, messageRecord.getExpiresIn());
                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else {
        this.expirationTimer.setVisibility(View.GONE);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

AsyncTask (android.os.AsyncTask)394 IOException (java.io.IOException)188 InputStream (java.io.InputStream)159 URL (java.net.URL)159 HttpURLConnection (java.net.HttpURLConnection)158 ExecutionException (java.util.concurrent.ExecutionException)158 Gson (com.google.gson.Gson)155 Message (com.remswork.project.alice.model.support.Message)153 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)102 ArrayList (java.util.ArrayList)93 View (android.view.View)54 Intent (android.content.Intent)52 TextView (android.widget.TextView)52 JSONException (org.json.JSONException)51 JSONArray (org.json.JSONArray)50 DialogInterface (android.content.DialogInterface)40 OutputStream (java.io.OutputStream)37 BufferedWriter (java.io.BufferedWriter)35 OutputStreamWriter (java.io.OutputStreamWriter)35 ImageView (android.widget.ImageView)33