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:com.igniva.filemanager.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) { return true; }/* w w w . j av a 2s . co m*/ // Handle action buttons Main ma = null; try { TabFragment tabFragment = getFragment(); if (tabFragment != null) ma = (Main) tabFragment.getTab(); } catch (Exception e) { } switch (item.getItemId()) { case R.id.home: if (ma != null) ma.home(); break; case R.id.history: if (ma != null) utils.showHistoryDialog(ma); break; case R.id.sethome: if (ma == null) return super.onOptionsItemSelected(item); final Main main = ma; if (main.openMode != 0 && main.openMode != 3) { Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show(); break; } final MaterialDialog b = utils.showBasicDialog(mainActivity, BaseActivity.accentSkin, theme1, new String[] { getResources().getString(R.string.questionset), getResources().getString(R.string.setashome), getResources().getString(R.string.yes), getResources().getString(R.string.no), null }); b.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { main.home = main.CURRENT_PATH; updatepaths(main.no); b.dismiss(); } }); b.show(); break; case R.id.item3: finish(); break; case R.id.item10: Fragment fragment = getDFragment(); if (fragment.getClass().getName().contains("AppsList")) utils.showSortDialog((AppsList) fragment); break; case R.id.sortby: if (ma != null) utils.showSortDialog(ma); break; case R.id.dsort: if (ma == null) return super.onOptionsItemSelected(item); String[] sort = getResources().getStringArray(R.array.directorysortmode); MaterialDialog.Builder a = new MaterialDialog.Builder(mainActivity); if (theme == 1) a.theme(Theme.DARK); a.title(R.string.directorysort); int current = Integer.parseInt(Sp.getString("dirontop", "0")); a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { Sp.edit().putString("dirontop", "" + which).commit(); dialog.dismiss(); return true; } }); a.build().show(); break; case R.id.hiddenitems: utils.showHiddenDialog(ma); break; case R.id.view: if (ma.IS_LIST) { if (DataUtils.listfiles.contains(ma.CURRENT_PATH)) { DataUtils.listfiles.remove(ma.CURRENT_PATH); grid.removePath(ma.CURRENT_PATH, DataUtils.LIST); } grid.addPath(null, ma.CURRENT_PATH, DataUtils.GRID, 0); DataUtils.gridfiles.add(ma.CURRENT_PATH); } else { if (DataUtils.gridfiles.contains(ma.CURRENT_PATH)) { DataUtils.gridfiles.remove(ma.CURRENT_PATH); grid.removePath(ma.CURRENT_PATH, DataUtils.GRID); } grid.addPath(null, ma.CURRENT_PATH, DataUtils.LIST, 0); DataUtils.listfiles.add(ma.CURRENT_PATH); } ma.switchView(); break; case R.id.paste: String path = ma.CURRENT_PATH; ArrayList<BaseFile> arrayList = new ArrayList<>(); if (COPY_PATH != null) { arrayList = COPY_PATH; new CopyFileCheck(ma, path, false, mainActivity, BaseActivity.rootMode) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList); } else if (MOVE_PATH != null) { arrayList = MOVE_PATH; new CopyFileCheck(ma, path, true, mainActivity, BaseActivity.rootMode) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList); } COPY_PATH = null; MOVE_PATH = null; invalidatePasteButton(item); break; case R.id.extract: Fragment fragment1 = getSupportFragmentManager().findFragmentById(R.id.content_frame); if (fragment1.getClass().getName().contains("ZipViewer")) mainActivityHelper.extractFile(((ZipViewer) fragment1).f); break; case R.id.search: View searchItem = toolbar.findViewById(R.id.search); searchViewEditText.setText(""); searchItem.getLocationOnScreen(searchCoords); revealSearchView(); break; } return super.onOptionsItemSelected(item); }
From source file:com.filemanager.free.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*www .j a v a 2 s. c om*/ // Handle action buttons Main ma = null; try { TabFragment tabFragment = getFragment(); if (tabFragment != null) ma = (Main) tabFragment.getTab(); } catch (Exception ignored) { } switch (item.getItemId()) { case R.id.home: if (ma != null) ma.home(); break; case R.id.history: if (ma != null) utils.showHistoryDialog(ma); break; case R.id.sethome: if (ma == null) return super.onOptionsItemSelected(item); final Main main = ma; if (main.openMode != 0 && main.openMode != 3) { Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show(); break; } final MaterialDialog b = utils.showBasicDialog(mainActivity, fabskin, theme1, new String[] { getResources().getString(R.string.questionset), getResources().getString(R.string.setashome), getResources().getString(R.string.yes), getResources().getString(R.string.no), null }); b.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { main.home = main.CURRENT_PATH; updatepaths(main.no); b.dismiss(); } }); b.show(); break; case R.id.item3: finish(); break; case R.id.item10: Fragment fragment = getDFragment(); if (fragment.getClass().getName().contains("AppsList")) utils.showSortDialog((AppsList) fragment); break; case R.id.sortby: if (ma != null) utils.showSortDialog(ma); break; case R.id.dsort: if (ma == null) return super.onOptionsItemSelected(item); String[] sort = getResources().getStringArray(R.array.directorysortmode); MaterialDialog.Builder a = new MaterialDialog.Builder(mainActivity); if (theme == 1) a.theme(Theme.DARK); a.title(R.string.directorysort); int current = Integer.parseInt(Sp.getString("dirontop", "0")); a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { Sp.edit().putString("dirontop", "" + which).commit(); dialog.dismiss(); return true; } }); a.build().show(); break; case R.id.hiddenitems: utils.showHiddenDialog(ma); break; case R.id.view: assert ma != null; if (ma.IS_LIST) { if (DataUtils.listfiles.contains(ma.CURRENT_PATH)) { DataUtils.listfiles.remove(ma.CURRENT_PATH); grid.removePath(ma.CURRENT_PATH, DataUtils.LIST); } grid.addPath(null, ma.CURRENT_PATH, DataUtils.GRID, 0); DataUtils.gridfiles.add(ma.CURRENT_PATH); } else { if (DataUtils.gridfiles.contains(ma.CURRENT_PATH)) { DataUtils.gridfiles.remove(ma.CURRENT_PATH); grid.removePath(ma.CURRENT_PATH, DataUtils.GRID); } grid.addPath(null, ma.CURRENT_PATH, DataUtils.LIST, 0); DataUtils.listfiles.add(ma.CURRENT_PATH); } ma.switchView(); break; case R.id.search: //mainActivityHelper.search(); showSearchView(); break; case R.id.paste: String path = ma.CURRENT_PATH; ArrayList<BaseFile> arrayList = new ArrayList<>(); if (COPY_PATH != null) { arrayList = COPY_PATH; new CopyFileCheck(ma, path, false, mainActivity, rootmode) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList); } else if (MOVE_PATH != null) { arrayList = MOVE_PATH; new CopyFileCheck(ma, path, true, mainActivity, rootmode) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList); } COPY_PATH = null; MOVE_PATH = null; invalidatePasteButton(item); break; case R.id.extract: Fragment fragment1 = getSupportFragmentManager().findFragmentById(R.id.content_frame); if (fragment1.getClass().getName().contains("ZipViewer")) mainActivityHelper.extractFile(((ZipViewer) fragment1).f); break; } return super.onOptionsItemSelected(item); }
From source file:nu.yona.app.ui.YonaActivity.java
private void showContactDetails(final Intent data) { final RegisterUser user = new RegisterUser(); new AsyncTask<Void, Void, Object>() { @Override//from ww w . j av a 2 s . c om protected Object doInBackground(Void... params) { try { Uri result = data.getData(); String id = result.getLastPathSegment(); //To get email address of user Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?", new String[] { id }, null); if (cursor.moveToFirst()) { user.setEmailAddress(cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))); } cursor.close(); // To get contact name etc of user String whereName = ContactsContract.Data.MIMETYPE + " = ? AND " + ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ? "; String[] whereNameParams = new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, id }; Cursor nameCur = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME); while (nameCur.moveToNext()) { user.setFirstName(nameCur.getString(nameCur .getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME))); user.setLastName(nameCur.getString(nameCur .getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME))); } nameCur.close(); // To get Mobile number of contact Cursor phoneCur = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?", new String[] { id }, null); List<String> numberList = new ArrayList<String>(); phoneCur.moveToFirst(); do { String number = phoneCur .getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); number = TextUtils.isEmpty(number) ? getString(R.string.blank) : number.replace(getString(R.string.space), getString(R.string.blank)); numberList.add(number); } while (phoneCur.moveToNext()); if (numberList.size() == 1) { user.setMobileNumber(numberList.get(0)); } else { user.setMultipleNumbers(numberList); } phoneCur.close(); } catch (Exception e) { AppUtils.reportException(YonaActivity.class.getSimpleName(), e, Thread.currentThread()); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); showLoadingView(false, null); new Handler().postDelayed(new Runnable() { @Override public void run() { YonaApplication.getEventChangeManager() .notifyChange(EventChangeManager.EVENT_CONTAT_CHOOSED, user); } }, AppConstant.TIMER_DELAY); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SELECT_FILE) { if (resultCode == Activity.RESULT_OK) { Bitmap selectedImage = null; try { selectedImage = decodeUri(data.getData()); selectedImage = imageProcess(selectedImage); if (selectedImage != null) { new ImageString(selectedImage).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); showLog("Bitmap Size " + selectedImage.getHeight() + "*" + selectedImage.getWidth()); userImage.setImageBitmap(selectedImage); }/*w ww . j a v a 2 s.com*/ } catch (FileNotFoundException e) { e.printStackTrace(); } } } else if (requestCode == REQUEST_CAMERA) { if (resultCode == Activity.RESULT_OK) { File file = new File(imageUri); Bitmap selectedImage = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1000, 1000); selectedImage = imageProcess(selectedImage); if (selectedImage != null) { new ImageString(selectedImage).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); showLog("Bitmap Size " + selectedImage.getHeight() + "*" + selectedImage.getWidth()); userImage.setImageBitmap(selectedImage); } } else if (resultCode == Activity.RESULT_CANCELED) { // showLog("Canceled"); File file = new File(imageUri); file.delete(); } } }
From source file:eu.faircode.netguard.ActivitySettings.java
private void handleHosts(final Intent data) { new AsyncTask<Object, Object, Throwable>() { @Override/*from w ww . j a v a 2 s .co m*/ protected Throwable doInBackground(Object... objects) { File hosts = new File(getFilesDir(), "hosts.txt"); FileOutputStream out = null; InputStream in = null; try { Log.i(TAG, "Reading URI=" + data.getData()); ContentResolver resolver = getContentResolver(); String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*"); String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]); AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null); in = descriptor.createInputStream(); out = new FileOutputStream(hosts); 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)); } } } @Override protected void onPostExecute(Throwable ex) { if (running) { if (ex == null) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ActivitySettings.this); String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); prefs.edit().putString("hosts_last_import", last).apply(); if (running) { getPreferenceScreen().findPreference("hosts_import") .setSummary(getString(R.string.msg_import_last, last)); Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("hosts import", ActivitySettings.this, false); } else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:dentex.youtube.downloader.DashboardActivity.java
private void pauseresume(final DashboardListItem currentItem) { final String itemID = currentItem.getId(); long itemIDlong = Long.parseLong(itemID); Utils.logger("d", "pauseresume on id " + itemID, DEBUG_TAG); if (currentItem.getStatus().equals(getString(R.string.json_status_in_progress))) { BugSenseHandler.leaveBreadcrumb("...pausing"); try {/*www. j a va2 s .c o m*/ if (Maps.dtMap.containsKey(itemIDlong)) { DownloadTask dt = Maps.dtMap.get(itemIDlong); dt.cancel(); } else { if (Maps.dtMap.size() > 0) { // cancel (pause) every dt found Utils.logger("w", "pauseresume: id not found into 'dtMap'; canceling all tasks", DEBUG_TAG); for (Iterator<DownloadTask> iterator = Maps.dtMap.values().iterator(); iterator .hasNext();) { DownloadTask dt = (DownloadTask) iterator.next(); dt.cancel(); } } } } catch (NullPointerException e) { Log.e(DEBUG_TAG, "dt.cancel() @ pauseresume: " + e.getMessage()); BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> dt.cancel() @ pauseresume: ", e.getMessage(), e); } YTD.removeIdUpdateNotification(itemIDlong); // update the JSON file entry Json.addEntryToJsonFile(DashboardActivity.this, itemID, currentItem.getType(), currentItem.getYtId(), currentItem.getPos(), YTD.JSON_DATA_STATUS_PAUSED, currentItem.getPath(), currentItem.getFilename(), currentItem.getBasename(), currentItem.getAudioExt(), currentItem.getSize(), false); } if (currentItem.getStatus().equals(getString(R.string.json_status_paused))) { BugSenseHandler.leaveBreadcrumb("...resuming"); String link = YTD.videoinfo.getString(String.valueOf(itemID) + "_link", null); if (link != null) { DownloadTaskListener dtl = new DownloadTaskListener() { @Override public void preDownload(DownloadTask task) { long ID = task.getDownloadId(); Utils.logger("d", "__preDownload on ID: " + ID, DEBUG_TAG); Maps.mNetworkSpeedMap.put(ID, (long) 0); Json.addEntryToJsonFile(sDashboard, String.valueOf(ID), currentItem.getType(), currentItem.getYtId(), currentItem.getPos(), YTD.JSON_DATA_STATUS_IN_PROGRESS, currentItem.getPath(), currentItem.getFilename(), currentItem.getBasename(), currentItem.getAudioExt(), currentItem.getSize(), false); YTD.sequence.add(ID); YTD.NotificationHelper(sDashboard); } @Override public void updateProcess(DownloadTask task) { /*YTD.downloadPercentMap = task.getDownloadPercentMap(); YTD.downloadTotalSizeMap = task.getTotalSizeMap(); YTD.downloadPartialSizeMap = task.getDownloadSizeMap();*/ } @Override public void finishDownload(DownloadTask task) { long ID = task.getDownloadId(); Utils.logger("d", "__finishDownload on ID: " + ID, DEBUG_TAG); Utils.scanMedia(getApplicationContext(), new String[] { currentItem.getPath() + File.separator + currentItem.getFilename() }, new String[] { "video/*" }); long downloadTotalSize = Maps.mTotalSizeMap.get(ID); String size = String.valueOf(Utils.MakeSizeHumanReadable(downloadTotalSize, false)); Json.addEntryToJsonFile(sDashboard, String.valueOf(ID), currentItem.getType(), currentItem.getYtId(), currentItem.getPos(), YTD.JSON_DATA_STATUS_COMPLETED, currentItem.getPath(), currentItem.getFilename(), currentItem.getBasename(), currentItem.getAudioExt(), size, false); if (DashboardActivity.isDashboardRunning) DashboardActivity.refreshlist(sDashboard); YTD.removeIdUpdateNotification(ID); YTD.videoinfo.edit().remove(ID + "_link").apply(); //YTD.videoinfo.edit().remove(ID + "_position").apply(); Maps.removeFromAllMaps(ID); } @Override public void errorDownload(DownloadTask task, Throwable error) { String nameOfVideo = task.getDownloadedFileName(); long ID = task.getDownloadId(); Utils.logger("w", "__errorDownload on ID: " + ID, DEBUG_TAG); if (error != null && error instanceof InvalidYoutubeLinkException) { Toast.makeText(sDashboard, nameOfVideo + ": " + getString(R.string.downloading) + "\n" + getString(R.string.wait), Toast.LENGTH_LONG).show(); Json.addEntryToJsonFile(sDashboard, String.valueOf(ID), YTD.JSON_DATA_TYPE_V, currentItem.getYtId(), currentItem.getPos(), YTD.JSON_DATA_STATUS_PAUSED, currentItem.getPath(), nameOfVideo, currentItem.getBasename(), currentItem.getAudioExt(), currentItem.getSize(), false); reDownload(currentItem, "AUTO"); } else { Toast.makeText(sDashboard, nameOfVideo + ": " + getString(R.string.download_failed), Toast.LENGTH_LONG).show(); Json.addEntryToJsonFile(sDashboard, String.valueOf(ID), YTD.JSON_DATA_TYPE_V, currentItem.getYtId(), currentItem.getPos(), YTD.JSON_DATA_STATUS_PAUSED, currentItem.getPath(), nameOfVideo, currentItem.getBasename(), currentItem.getAudioExt(), currentItem.getSize(), false); if (DashboardActivity.isDashboardRunning) DashboardActivity.refreshlist(sDashboard); YTD.removeIdUpdateNotification(ID); } } }; //TODO try { DownloadTask dt = new DownloadTask(this, itemIDlong, link, currentItem.getFilename(), currentItem.getPath(), dtl, true); Maps.dtMap.put(itemIDlong, dt); dt.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (MalformedURLException e) { Log.e(DEBUG_TAG, "unable to start Download Manager -> " + e.getMessage()); } } else { //notifyOpsNotSupported(); reDownload(currentItem, "AUTO"); } } refreshlist(sDashboard); }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void handleDistributionBroadcastEnabled(MenuItem item) { distributionType = ThreadDatabase.DistributionTypes.BROADCAST; item.setChecked(true);/* ww w.ja va 2 s.c o m*/ if (threadId != -1) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { DatabaseFactory.getThreadDatabase(ConversationActivity.this).setDistributionType(threadId, ThreadDatabase.DistributionTypes.BROADCAST); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public void loadlist(String path, boolean back, OpenMode openMode) { if (mActionMode != null) { mActionMode.finish();//from w ww .ja va 2s . com } /*if(openMode==-1 && android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) bindDrive(path); else */ if (loadList != null) loadList.cancel(true); loadList = new LoadList(ma.getActivity(), utilsProvider, back, ma, openMode); loadList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (path)); }
From source file:org.akop.ararat.view.CrosswordView.java
private void regenerateBitmaps() { synchronized (mRendererLock) { if (mAsyncTask != null) { mAsyncTask.cancel(false);/* w w w.j ava 2 s.c om*/ } // A 1px size line is always present, so it's not enough to just // check for zero if (mPuzzleRect.width() > 1 && mPuzzleRect.height() > 1) { mAsyncTask = new RenderTask(mRenderScale); mAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void handleDistributionConversationEnabled(MenuItem item) { distributionType = ThreadDatabase.DistributionTypes.CONVERSATION; item.setChecked(true);/* www. j a v a2 s .c om*/ if (threadId != -1) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { DatabaseFactory.getThreadDatabase(ConversationActivity.this).setDistributionType(threadId, ThreadDatabase.DistributionTypes.CONVERSATION); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }