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 initializeMmsEnabledCheck() { new AsyncTask<Void, Void, Boolean>() { @Override/* w w w .j a v a 2 s .c o m*/ protected Boolean doInBackground(Void... params) { return Util.isMmsCapable(ConversationActivity.this); } @Override protected void onPostExecute(Boolean isMmsEnabled) { ConversationActivity.this.isMmsEnabled = isMmsEnabled; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.amaze.filemanager.activities.MainActivity.java
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) { new Thread(new Runnable() { @Override// w w w . j a v a 2s . c o m public void run() { mIntentInProgress = false; mGoogleApiKey = true; // !mGoogleApiClient.isConnecting if (mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else mGoogleApiClient.disconnect(); } }).run(); } else if (requestCode == image_selector_request_code) { if (Sp != null && intent != null && intent.getData() != null) { if (Build.VERSION.SDK_INT >= 19) getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit(); setDrawerHeaderBackground(); } } else if (requestCode == 3) { String p = Sp.getString("URI", null); Uri oldUri = null; if (p != null) oldUri = Uri.parse(p); Uri treeUri = null; if (responseCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. treeUri = intent.getData(); // Persist URI - this is required for verification of writability. if (treeUri != null) Sp.edit().putString("URI", treeUri.toString()).commit(); } // If not confirmed SAF, or if still not writable, then revert settings. if (responseCode != Activity.RESULT_OK) { /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder) */ if (treeUri != null) Sp.edit().putString("URI", oldUri.toString()).commit(); return; } // After confirmation, update stored value of folder. // Persist access permissions. final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); getContentResolver().takePersistableUriPermission(treeUri, takeFlags); switch (operation) { case DataUtils.DELETE://deletion new DeleteTask(null, mainActivity).execute((oparrayList)); break; case DataUtils.COPY://copying Intent intent1 = new Intent(con, CopyService.class); intent1.putExtra("FILE_PATHS", (oparrayList)); intent1.putExtra("COPY_DIRECTORY", oppathe); startService(intent1); break; case DataUtils.MOVE://moving new MoveFiles((oparrayList), ((Main) getFragment().getTab()), ((Main) getFragment().getTab()).getActivity(), 0) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path); break; case DataUtils.NEW_FOLDER://mkdir Main ma1 = ((Main) getFragment().getTab()); mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1); break; case DataUtils.RENAME: mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, rootmode); Main ma2 = ((Main) getFragment().getTab()); ma2.updateList(); break; case DataUtils.NEW_FILE: Main ma3 = ((Main) getFragment().getTab()); mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3); break; case DataUtils.EXTRACT: mainActivityHelper.extractFile(new File(oppathe)); break; case DataUtils.COMPRESS: mainActivityHelper.compressFiles(new File(oppathe), oparrayList); } operation = -1; } }
From source file:com.dycody.android.idealnote.DetailFragment.java
/** * Discards changes done to the note and eventually delete new attachments *//*from www .j a v a 2 s . c om*/ @SuppressLint("NewApi") private void discard() { // Checks if some new files have been attached and must be removed if (!noteTmp.getAttachmentsList().equals(note.getAttachmentsList())) { for (Attachment newAttachment : noteTmp.getAttachmentsList()) { if (!note.getAttachmentsList().contains(newAttachment)) { StorageHelper.delete(mainActivity, newAttachment.getUri().getPath()); } } } goBack = true; if (!noteTmp.equals(noteOriginal)) { // Restore original status of the note if (noteOriginal.get_id() == null) { mainActivity.deleteNote(noteTmp); goHome(); } else { SaveNoteTask saveNoteTask = new SaveNoteTask(this, false); if (Build.VERSION.SDK_INT >= 11) { saveNoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, noteOriginal); } else { saveNoteTask.execute(noteOriginal); } } MainActivity.notifyAppWidgets(mainActivity); } else { goHome(); } }
From source file:it.feio.android.omninotes.DetailFragment.java
/** * Save new notes, modify them or archive *//*w w w.j av a2 s . com*/ void saveNote(OnNoteSaved mOnNoteSaved) { // Changed fields noteTmp.setTitle(getNoteTitle()); noteTmp.setContent(getNoteContent()); // Check if some text or attachments of any type have been inserted or // is an empty note if (goBack && TextUtils.isEmpty(noteTmp.getTitle()) && TextUtils.isEmpty(noteTmp.getContent()) && noteTmp.getAttachmentsList().size() == 0) { Log.d(Constants.TAG, "Empty note not saved"); exitMessage = getString(R.string.empty_note_not_saved); exitCroutonStyle = ONStyle.INFO; goHome(); return; } if (saveNotNeeded()) { exitMessage = ""; if (goBack) { goHome(); } return; } noteTmp.setAttachmentsListOld(note.getAttachmentsList()); // Saving changes to the note SaveNoteTask saveNoteTask = new SaveNoteTask(mOnNoteSaved, lastModificationUpdatedNeeded()); saveNoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, noteTmp); }
From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java
private void selectPlaceActivityResult_HELP2(final BuildingModel b, final FloorModel f) { String trackedPositionLat = userData.getSelectedBuilding().getLatitudeString(); String trackedPositionLon = userData.getSelectedBuilding().getLongitudeString(); // first we should disable the tracker if it's working disableAnyplaceTracker();/*from ww w . j a v a 2 s. c o m*/ class Callback implements DownloadRadioMapTaskBuid.DownloadRadioMapListener, PreviousRunningTask { boolean progressBarEnabled = false; boolean disableSuccess = false; @Override public void onSuccess(String result) { if (disableSuccess) { onErrorOrCancel(""); return; } // start the tracker enableAnyplaceTracker(); // Download All Building Floors and Radiomaps if (AnyplaceAPI.PLAY_STORE) { mAnyplaceCache.fetchAllFloorsRadiomapsRun(new BackgroundFetchListener() { @Override public void onSuccess(String result) { hideProgressBar(); if (AnyplaceAPI.DEBUG_MESSAGES) { btnTrackme.setBackgroundColor(Color.YELLOW); } floorSelector.updateFiles(b.buid); floorSelector.Start(b.getLatitudeString(), b.getLongitudeString()); } @Override public void onProgressUpdate(int progress_current, int progress_total) { progressBar.setProgress( (int) ((float) progress_current / progress_total * progressBar.getMax())); } @Override public void onErrorOrCancel(String result, ErrorType error) { // Do not hide progress bar if previous task is running // ErrorType.SINGLE_INSTANCE // Do not hide progress bar because a new task will be created // ErrorType.CANCELLED if (error == ErrorType.EXCEPTION) hideProgressBar(); } @Override public void onPrepareLongExecute() { showProgressBar(); } }, b); } } @Override public void onErrorOrCancel(String result) { if (progressBarEnabled) { hideProgressBar(); } } @Override public void onPrepareLongExecute() { progressBarEnabled = true; showProgressBar(); // Set a smaller percentage than fetchAllFloorsRadiomapsOfBUID progressBar.setProgress((int) (1.0f / (userData.getSelectedBuilding().getFloors().size() * 2) * progressBar.getMax())); } @Override public void disableSuccess() { disableSuccess = true; } } if (downloadRadioMapTaskBuid != null) { ((PreviousRunningTask) downloadRadioMapTaskBuid.getCallbackInterface()).disableSuccess(); } downloadRadioMapTaskBuid = new DownloadRadioMapTaskBuid(new Callback(), this, trackedPositionLat, trackedPositionLon, userData.getSelectedBuildingId(), userData.getSelectedFloorNumber(), false); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { // Execute task parallel with others and multiple instances of // itself downloadRadioMapTaskBuid.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { downloadRadioMapTaskBuid.execute(); } }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private ListenableFuture<Boolean> initializeIdentityRecords() { final SettableFuture<Boolean> future = new SettableFuture<>(); new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() { @Override/*www. java 2s . co m*/ protected @NonNull Pair<IdentityRecordList, String> doInBackground(Recipient... params) { IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this); IdentityRecordList identityRecordList = new IdentityRecordList(); List<Recipient> recipients = new LinkedList<>(); if (params[0].isGroupRecipient()) { recipients.addAll(DatabaseFactory.getGroupDatabase(ConversationActivity.this) .getGroupMembers(params[0].getAddress().toGroupString(), false)); } else { recipients.add(params[0]); } for (Recipient recipient : recipients) { Log.i(TAG, "Loading identity for: " + recipient.getAddress()); identityRecordList.add(identityDatabase.getIdentity(recipient.getAddress())); } String message = null; if (identityRecordList.isUnverified()) { message = IdentityUtil.getUnverifiedBannerDescription(ConversationActivity.this, identityRecordList.getUnverifiedRecipients(ConversationActivity.this)); } return new Pair<>(identityRecordList, message); } @Override protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) { Log.i(TAG, "Got identity records: " + result.first.isUnverified()); identityRecords.replaceWith(result.first); if (result.second != null) { Log.d(TAG, "Replacing banner..."); unverifiedBannerView.get().display(result.second, result.first.getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener()); } else if (unverifiedBannerView.resolved()) { Log.d(TAG, "Clearing banner..."); unverifiedBannerView.get().hide(); } titleView.setVerified(isSecureText && identityRecords.isVerified()); future.set(true); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient); return future; }
From source file:org.ymkm.lib.http.HttpRequester.java
/** * Executes a new asynchronous request to specified URI * /* www . j a v a2 s . c o m*/ * <p> * This method spawns a new thread to perform the request. * </p> * <p> * Given {@link HttpRequestListener} will be used as a callback before the request is executed and will be given * back the server response once the execution completes.<br/> * {@code HttpRequestListener.onSetHttpClient} and {@code HttpRequestListener.onSetHttpParams} will also be called * so that the caller can customize the request before it is executed. * </p> * <p> * In case of a client-side exception during the execution, {@code returnCode} will have a value of 500 and * {@code responseBody} will contain the exception message. If the error occurred while processing the request, The * status code returned by the server will be be returned instead. * </p> * <p> * The third parameter is an Activity that the caller wish to notify as being busy during the request execution.<br/> * {@code Activity.setProgressBarIndeterminateVisibility} will be called before and after the request. * </p> * * @param uri * the uri to request * @param whenLoaded * the callback to use before/after the request * @param activity * the activity to notify when request is busy executing * @return HttpRequesterFuture a future object tied to this request */ @SuppressLint("NewApi") public static HttpRequesterFuture requestAsync(final ExecutableRequest req, final HttpRequestListener whenLoaded, Activity activity) { HttpRequestHolder loadReq = HttpRequestHolder.newInstance(req, whenLoaded); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { // Execution was done in a separate thread for versions > DONUT < HONEYCOMB return new HttpRequesterFuture( (HttpRequesterTask) (new HttpRequesterTask(whenLoaded, null)).execute(loadReq)); } else { // Can be executed in a separate thread return new HttpRequesterFuture((HttpRequesterTask) (new HttpRequesterTask(whenLoaded, null)) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, loadReq)); } }
From source file:com.filemanager.free.activities.MainActivity.java
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) { new Thread(new Runnable() { @Override//from ww w . j a va 2 s . c om public void run() { mIntentInProgress = false; mGoogleApiKey = true; // !mGoogleApiClient.isConnecting if (mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else mGoogleApiClient.disconnect(); } }).run(); } else if (requestCode == image_selector_request_code) { if (Sp != null && intent != null && intent.getData() != null) { if (Build.VERSION.SDK_INT >= 19) { getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { con.getApplicationContext().grantUriPermission(BuildConfig.APPLICATION_ID, intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION); } Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit(); setDrawerHeaderBackground(); } } else if (requestCode == 3) { String p = Sp.getString("URI", null); Uri oldUri = null; if (p != null) oldUri = Uri.parse(p); Uri treeUri = null; if (responseCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. treeUri = intent.getData(); // Persist URI - this is required for verification of writability. if (treeUri != null) { Sp.edit().putString("URI", treeUri.toString()).commit(); } } // If not confirmed SAF, or if still not writable, then revert settings. if (responseCode != Activity.RESULT_OK) { /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false, currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder) */ if (treeUri != null) { Sp.edit().putString("URI", oldUri.toString()).commit(); } return; } // After confirmation, update stored value of folder. // Persist access permissions. int takeFlags = intent.getFlags(); takeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (treeUri != null) { getContentResolver().takePersistableUriPermission(treeUri, takeFlags); } } else { if (treeUri != null) { con.getApplicationContext().grantUriPermission(BuildConfig.APPLICATION_ID, treeUri, takeFlags); } } switch (operation) { case DataUtils.DELETE://deletion new DeleteTask(null, mainActivity).execute((oparrayList)); break; case DataUtils.COPY://copying Intent intent1 = new Intent(con, CopyService.class); intent1.putExtra("FILE_PATHS", (oparrayList)); intent1.putExtra("COPY_DIRECTORY", oppathe); startService(intent1); break; case DataUtils.MOVE://moving new MoveFiles((oparrayList), ((Main) getFragment().getTab()), ((Main) getFragment().getTab()).getActivity(), 0) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path); break; case DataUtils.NEW_FOLDER://mkdir Main ma1 = ((Main) getFragment().getTab()); mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1); break; case DataUtils.RENAME: mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, rootmode); Main ma2 = ((Main) getFragment().getTab()); ma2.updateList(); break; case DataUtils.NEW_FILE: Main ma3 = ((Main) getFragment().getTab()); mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3); break; case DataUtils.EXTRACT: mainActivityHelper.extractFile(new File(oppathe)); break; case DataUtils.COMPRESS: mainActivityHelper.compressFiles(new File(oppathe), oparrayList); } operation = -1; } }
From source file:com.dycody.android.idealnote.DetailFragment.java
/** * Save new notes, modify them or archive *//*from ww w . j a v a 2 s . c o m*/ void saveNote(OnNoteSaved mOnNoteSaved) { // Changed fields noteTmp.setTitle(getNoteTitle()); noteTmp.setContent(getNoteContent()); // Check if some text or attachments of any type have been inserted or // is an empty note if (goBack && TextUtils.isEmpty(noteTmp.getTitle()) && TextUtils.isEmpty(noteTmp.getContent()) && noteTmp.getAttachmentsList().size() == 0) { Log.d(Constants.TAG, "Empty note not saved"); //exitMessage = getString(R.string.empty_note_not_saved); Toast.makeText(getActivity(), R.string.empty_note_not_saved, Toast.LENGTH_SHORT).show(); //exitCroutonStyle = ONStyle.INFO; goHome(); return; } if (saveNotNeeded()) { exitMessage = ""; if (goBack) { goHome(); } return; } noteTmp.setAttachmentsListOld(note.getAttachmentsList()); new SaveNoteTask(mOnNoteSaved, lastModificationUpdatedNeeded()) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, noteTmp); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
public void onSearchCompleted(final String query) { if (!results) { // no results were found LIST_ELEMENTS.clear();//w w w . j av a 2 s .c o m } new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { Collections.sort(LIST_ELEMENTS, new FileListSorter(dsort, sortby, asc)); return null; } @Override public void onPostExecute(Void c) { reloadListElements(true, true, !IS_LIST);// TODO: 7/7/2017 this is really inneffient, use RecycleAdapter's createHeaders() getMainActivity().getAppbar().getBottomBar().setPathText(""); getMainActivity().getAppbar().getBottomBar() .setFullPathText(getString(R.string.searchresults, query)); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }