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.ConversationItem.java
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//from w w w . j a v a 2 s .co m 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); } }
From source file:at.flack.MainActivity.java
public void updateSMSContacts() { new UpdateSMSContacts().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
private static void getSchedule(final int direction, final int transition) { MainActivity.setUI(HeliniumStudentApp.VIEW_SCHEDULE, transition); try {/* www .j a v a 2s . c o m*/ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) new GetScheduleData().execute( HeliniumStudentApp.URL_SCHEDULE + String.valueOf( HeliniumStudentApp.df_homework().parse(getDateFormatted() + " GMT").getTime()), scheduleFocus, direction, transition + 1, true); else new GetScheduleData().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, HeliniumStudentApp.URL_SCHEDULE + String.valueOf( HeliniumStudentApp.df_homework().parse(getDateFormatted() + " GMT").getTime()), scheduleFocus, direction, transition + 1, true); } catch (ParseException ignored) { } }
From source file:org.exobel.routerkeygen.ui.Preferences.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void checkCurrentDictionary() throws FileNotFoundException { final String myDicFile = PreferenceManager.getDefaultSharedPreferences(getBaseContext()) .getString(dicLocalPref, null); if (myDicFile == null) { removeDialog(DIALOG_ASK_DOWNLOAD); startService(new Intent(getApplicationContext(), DictionaryDownloadService.class) .putExtra(DictionaryDownloadService.URL_DOWNLOAD, PUB_DOWNLOAD)); } else {/*from w ww .j av a2 s .com*/ AsyncTask<Void, Void, Integer> task = new AsyncTask<Void, Void, Integer>() { private final static int TOO_ADVANCED = 1; private final static int OK = 0; private final static int DOWNLOAD_NEEDED = -1; private final static int ERROR_NETWORK = -2; private final static int ERROR = -3; protected void onPreExecute() { removeDialog(DIALOG_ASK_DOWNLOAD); showDialog(DIALOG_WAIT); } protected Integer doInBackground(Void... params) { // Comparing this version with the online // version try { HttpURLConnection con = (HttpURLConnection) new URL(PUB_DIC_CFV).openConnection(); DataInputStream dis = new DataInputStream(con.getInputStream()); byte[] cfvTable = new byte[18]; boolean readCorrectly = InputStreamUtils.readFromInput(cfvTable, cfvTable.length, dis); dis.close(); con.disconnect(); if (!readCorrectly) { return ERROR; } InputStream is = new FileInputStream(myDicFile); byte[] dicVersion = new byte[2]; // Check our version readCorrectly = InputStreamUtils.readFromInput(dicVersion, dicVersion.length, is); is.close(); if (!readCorrectly) { return ERROR; } int thisVersion, onlineVersion; thisVersion = dicVersion[0] << 8 | dicVersion[1]; onlineVersion = cfvTable[0] << 8 | cfvTable[1]; if (thisVersion == onlineVersion) { // It is the latest version, but is // it not corrupt? byte[] dicHash = new byte[16]; System.arraycopy(cfvTable, 2, dicHash, 0, dicHash.length); if (HashUtils.checkDicMD5(new File(myDicFile).getPath(), dicHash)) { // All is well return OK; } } if (onlineVersion > thisVersion && onlineVersion > MAX_DIC_VERSION) { // Online version is too advanced return TOO_ADVANCED; } return DOWNLOAD_NEEDED; } catch (FileNotFoundException e) { return DOWNLOAD_NEEDED; } catch (UnknownHostException e) { return ERROR_NETWORK; } catch (Exception e) { return ERROR; } } protected void onPostExecute(Integer result) { removeDialog(DIALOG_WAIT); if (isFinishing()) return; if (result == null) { showDialog(DIALOG_ERROR); return; } switch (result) { case ERROR: showDialog(DIALOG_ERROR); break; case ERROR_NETWORK: Toast.makeText(Preferences.this, R.string.msg_errthomson3g, Toast.LENGTH_SHORT).show(); break; case DOWNLOAD_NEEDED: startService(new Intent(getApplicationContext(), DictionaryDownloadService.class) .putExtra(DictionaryDownloadService.URL_DOWNLOAD, PUB_DOWNLOAD)); break; case OK: Toast.makeText(getBaseContext(), getResources().getString(R.string.msg_dic_updated), Toast.LENGTH_SHORT).show(); break; case TOO_ADVANCED: showDialog(DIALOG_ERROR_TOO_ADVANCED); break; } } }; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { task.execute(); } else { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }
From source file:at.vcity.androidimsocket.services.IMService.java
public void messageReceived(MessageInfo msg)//String userId, String message) { if (msg != null) { Intent i = new Intent(TAKE_MESSAGE); localstoragehandler.insert(msg); i.putExtra(MessageInfo.MESSAGE, msg); sendBroadcast(i);/*from www .j a v a2 s . c om*/ FriendInfo activeFriend = FriendController.getActiveFriend(); if (activeFriend == null)//|| activeFriend.userId.equals(msg.fromUserId) == false) {{ new AsyncTask<MessageInfo, Void, MessageInfo>() { @Override protected MessageInfo doInBackground(MessageInfo... m) { while (!FriendController.isFriendListReady()) { try { Thread.sleep(1000); } catch (InterruptedException e) { } } return m[0]; } @Override protected void onPostExecute(MessageInfo msg) { //super.onPostExecute(aVoid); showNotification(msg);//msg.fromUserId, message, msg.type); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, msg); } Log.i("TAKE_MESSAGE broadcast sent by im service", ""); }
From source file:eu.power_switch.gui.dialog.AddActionDialog.java
private void updatePositiveButton() { new AsyncTask<Void, Void, Boolean>() { @Override/*from ww w .j a v a2 s . c om*/ protected Boolean doInBackground(Void... params) { return checkValidity(); } @Override protected void onPostExecute(Boolean bool) { setPositiveButtonVisibility(bool); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.cw.litenote.main.MainAct.java
void createDefaultContent_byDownload() { /**//from w ww . jav a 2 s . c o m * LiteNote_default_content.xml * Unit: folder */ // LiteNote_default_content.xml String srcUrl = "https://drive.google.com/uc?authuser=0&id=1qAfMUJ9DMsciVkb7hEQAwLrmcyfN95sF&export=download"; Async_default_byDownload async = new Async_default_byDownload(mAct, srcUrl); async.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "Downloading file ..."); /// // download txt file from Web site // Thread thread = new Thread(new Runnable() // { // @Override // public void run() // { // try { // //cf https://www.sample-videos.com/download-sample-text-file.php // URL url = new URL("https://www.sample-videos.com/text/Sample-text-file-10kb.txt"); // // //create https connection // HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); // urlConnection.setRequestMethod("GET"); // urlConnection.setDoOutput(true); // // //connect // urlConnection.connect(); // // //output path // String dirString = Environment.getExternalStorageDirectory().toString() + // "/" + // Util.getStorageDirName(MainAct.mAct); // // File storageRoot = new File(dirString); // File file = new File(storageRoot, "default_content_by_download.xml"); // // FileOutputStream fileOutput = null; // fileOutput = new FileOutputStream(file); // // // input path // InputStream inputStream = null; // inputStream = urlConnection.getInputStream(); // // int totalSize = urlConnection.getContentLength(); // int downloadedSize = 0; // // //create buffer // byte[] buffer = new byte[1024]; // int bufferLength = 0; // bufferLength = inputStream.read(buffer); // // while ( bufferLength > 0 ) // { // // write // try { // fileOutput.write(buffer, 0, bufferLength); // } catch (IOException e) { // e.printStackTrace(); // } // // downloadedSize += bufferLength; // // // progress // int progress=(int)(downloadedSize*100/totalSize); // // try { // bufferLength = inputStream.read(buffer); // } catch (IOException e) { // e.printStackTrace(); // } // } // // //close // fileOutput.close(); // // while(!file.exists() || (file.length() == 0) ) // { // System.out.println("MainAct / _onRequestPermissionsResult / downloading ! Waiting..."); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // }); // thread.start(); /// }
From source file:gov.cdc.epiinfo.RecordList.java
private void createRecord() { waitDialog = ProgressDialog.show(this, getString(R.string.loading_form), getString(R.string.please_wait), true);//from w w w . ja v a 2s. c o m SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); boolean useInterviewMode = sharedPref.getBoolean("interview", false) || formMetadata.IsInterviewForm; Intent i; if (useInterviewMode) { i = new Intent(this, Interviewer.class); } else { i = new Intent(this, RecordEditor.class); } new PreCompiledLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, i); }
From source file:eu.faircode.netguard.ActivityLog.java
private void handleExportPCAP(final Intent data) { new AsyncTask<Object, Object, Throwable>() { @Override//from w w w . jav a 2s . c om protected Throwable doInBackground(Object... objects) { OutputStream out = null; FileInputStream in = null; try { // Stop capture ServiceSinkhole.setPcap(false, ActivityLog.this); Uri target = data.getData(); if (data.hasExtra("org.openintents.extra.DIR_PATH")) target = Uri.parse(target + "/netguard.pcap"); Log.i(TAG, "Export PCAP URI=" + target); out = getContentResolver().openOutputStream(target); File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); in = new FileInputStream(pcap); int len; long total = 0; byte[] buf = new byte[4096]; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); total += len; } Log.i(TAG, "Copied bytes=" + total); return null; } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return ex; } finally { if (out != null) try { out.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } if (in != null) try { in.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } // Resume capture SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityLog.this); if (prefs.getBoolean("pcap", false)) ServiceSinkhole.setPcap(true, ActivityLog.this); } } @Override protected void onPostExecute(Throwable ex) { if (ex == null) Toast.makeText(ActivityLog.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); else Toast.makeText(ActivityLog.this, ex.toString(), Toast.LENGTH_LONG).show(); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.thoughtcrime.securesms.conversation.ConversationFragment.java
private void handleResendMessage(final MessageRecord message) { final Context context = getActivity().getApplicationContext(); new AsyncTask<MessageRecord, Void, Void>() { @Override/*from ww w . j av a 2s. c o m*/ protected Void doInBackground(MessageRecord... messageRecords) { MessageSender.resend(context, messageRecords[0]); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message); }