List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR
Executor THREAD_POOL_EXECUTOR
To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.
Click Source Link
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, final boolean initiatingConversation) throws InvalidMessageException { if (!isDefaultSms && (!isSecureText || forceSms)) { showDefaultSmsPrompt();/*from ww w .java 2 s .com*/ return; } final Context context = getApplicationContext(); final String messageBody = getMessage(); OutgoingTextMessage message; if (isSecureText && !forceSms) { message = new OutgoingEncryptedMessage(recipient, messageBody, expiresIn); ApplicationContext.getInstance(context).getTypingStatusSender().onTypingStopped(threadId); } else { message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId); } Permissions.with(this).request(Manifest.permission.SEND_SMS).ifNecessary(forceSms || !isSecureText) .withPermanentDenialDialog(getString( R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms)) .onAllGranted(() -> { silentlySetComposeText(""); final long id = fragment.stageOutgoingMessage(message); new AsyncTask<OutgoingTextMessage, Void, Long>() { @Override protected Long doInBackground(OutgoingTextMessage... messages) { if (initiatingConversation) { DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true); } return MessageSender.send(context, messages[0], threadId, forceSms, () -> fragment.releaseOutgoingMessage(id)); } @Override protected void onPostExecute(Long result) { sendComplete(result); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message); }).execute(); }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void recordTransportPreference(TransportOption transportOption) { new AsyncTask<Void, Void, Void>() { @Override//from w w w.jav a2 s .c o m protected Void doInBackground(Void... params) { RecipientDatabase recipientDatabase = DatabaseFactory .getRecipientDatabase(ConversationActivity.this); recipientDatabase.setDefaultSubscriptionId(recipient, transportOption.getSimSubscriptionId().or(-1)); if (!recipient.isPushGroupRecipient()) { recipientDatabase.setForceSmsSelection(recipient, recipient.getRegistered() == RegisteredState.REGISTERED && transportOption.isSms()); } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
@Override public void onRecorderFinished() { updateToggleButtonState();//from w w w . ja va 2 s.c o m 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(final @NonNull 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, Collections.emptyList(), Collections.emptyList(), expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() { @Override public void onSuccess(Void nothing) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { BlobProvider.getInstance().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(); } }); }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
@Override public void onRecorderCanceled() { updateToggleButtonState();/*from www. j a v a2s .c om*/ 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) { BlobProvider.getInstance().delete(ConversationActivity.this, result.first); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @Override public void onFailure(ExecutionException e) { } }); }
From source file:com.guardtrax.ui.screens.HomeScreen.java
private void syncDB() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) new SyncDataFromDB().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else/*from www .j a v a 2 s .c om*/ new SyncDataFromDB().execute(); }
From source file:com.guardtrax.ui.screens.HomeScreen.java
private void syncFTP() { //new Download_FTP().execute(); //do not sync if dummy registration is in place if (Utility.deviceRegistered()) { if (ftpDownload == null) { ftpDownload = new Download_FTP(HomeScreen.this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ftpDownload.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else//from w w w .jav a 2 s. c o m ftpDownload.execute(); } } }
From source file:com.guardtrax.ui.screens.HomeScreen.java
private void syncftpUpload() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) new Upload_FTP(HomeScreen.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else//from w w w . java 2 s. c o m new Upload_FTP(HomeScreen.this).execute(); }
From source file:com.guardtrax.ui.screens.HomeScreen.java
private void checkUpdate() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) new checkForUpdates().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else//from w w w . ja va 2s. c om new checkForUpdates().execute(); }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
public void dumpLogsToLocalData() { if (DEBUG_DUMP_LOG) { new AsyncTask<Void, Void, Void>() { public Void doInBackground(Void... args) { boolean success = false; sDateStamp.setTime(sRunStart); String FILENAME = sDateStamp.getMonth() + "-" + sDateStamp.getDay() + "_" + sDateStamp.getHours() + "-" + sDateStamp.getMinutes() + "_" + sDateStamp.getSeconds() + ".txt"; FileOutputStream fos = null; File outFile = null; try { outFile = new File(getFilesDir(), FILENAME); outFile.createNewFile(); fos = new FileOutputStream(outFile); } catch (Exception e) { e.printStackTrace(); }/* w ww .j av a2s . c o m*/ if (fos != null) { PrintWriter writer = new PrintWriter(fos); writer.println(" "); writer.println("Debug logs: "); synchronized (sDumpLogs) { for (int i = 0; i < sDumpLogs.size(); i++) { writer.println(" " + sDumpLogs.get(i)); } } writer.close(); } try { if (fos != null) { fos.close(); success = true; } } catch (IOException e) { e.printStackTrace(); } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); } }
From source file:com.android.mail.ui.AbstractActivityController.java
protected void navigateUpFolderHierarchy() { new AsyncTask<Void, Void, Folder>() { @Override/*from w w w. j a v a 2 s. c om*/ protected Folder doInBackground(final Void... params) { if (mInbox == null) { // We don't have an inbox, but we need it final Cursor cursor = mContext.getContentResolver().query(mAccount.settings.defaultInbox, UIProvider.FOLDERS_PROJECTION, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { mInbox = new Folder(cursor); } } finally { cursor.close(); } } } // Now try to load our parent final Folder folder; if (mFolder != null) { Cursor cursor = null; try { cursor = mContext.getContentResolver().query(mFolder.parent, UIProvider.FOLDERS_PROJECTION, null, null, null); if (cursor == null || !cursor.moveToFirst()) { // We couldn't load the parent, so use the inbox folder = mInbox; } else { folder = new Folder(cursor); } } finally { if (cursor != null) { cursor.close(); } } } else { folder = mInbox; } return folder; } @Override protected void onPostExecute(final Folder result) { onFolderSelected(result); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); }