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.orbar.pxdemo.ImageView.FivePXImageFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == Activity.RESULT_OK) { //boolean result=data.getBooleanExtra("result", false); if (getActivity() instanceof MainActivity) { ((MainActivity) getActivity()).onSuccessLogin(); }//from w ww .j av a 2 s.c o m if (reason == LOGGING_REASON.FAVORITE) { processFavorite(); } if (reason == LOGGING_REASON.LIKE) { processLike(); } if (reason == LOGGING_REASON.COMMENT) { submitComment(); } // The comment count, Like count, or the Favorite count (and color) will change. mLoadImageDetailsList = new LoadImageDetailsList(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager, mFiveZeroZeroImageBean); mLoadImageDetailsList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } if (resultCode == Activity.RESULT_CANCELED) { // Do Nothing, no need to process whatever triggered the login task } } }
From source file:radu.pidroid.Controller.java
public boolean setupVideoFeed() { String URL = "http://" + serverIP + ":" + (serverPort + 1) + "/?action=stream"; try {//from w ww . ja v a 2 s . c o m videoFeedTask = new VideoFeedTask(); videoFeedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, URL); } catch (Exception exception) { Log.e("setupVideoFeed():", "Could not connect to host!"); return false; } // try-catch return true; }
From source file:in.andres.kandroid.kanboard.KanboardAPI.java
public KanboardAPI(String serverURL, final String username, final String password) throws IOException { Authenticator.setDefault(new Authenticator() { @Override//from ww w. j av a 2 s . com protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); } }); serverURL = serverURL.trim(); String tmpURL = serverURL; if (!serverURL.endsWith("jsonrpc.php")) { if (!serverURL.endsWith("/")) tmpURL += "/"; tmpURL += "jsonrpc.php"; } kanboardURL = new URL(tmpURL); Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol())); // threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256)); threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR; threadPoolExecutor.setCorePoolSize(12); threadPoolExecutor.setMaximumPoolSize(12); }
From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java
private void initCamera() { // Only for the first time if (userMarker != null) { return;// w w w. j ava 2 s . c o m } Location gps = mLocationClient.getLastLocation(); if (gps != null) { cameraUpdate = true; mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), mInitialZoomLevel), new CancelableCallback() { @Override public void onFinish() { cameraUpdate = false; handleBuildingsOnMap(); } @Override public void onCancel() { cameraUpdate = false; handleBuildingsOnMap(); } }); } else { AsyncTask<Void, Integer, Void> task = new AsyncTask<Void, Integer, Void>() { GeoPoint location; @Override protected Void doInBackground(Void... params) { try { location = AndroidUtils.getIPLocation(); } catch (Exception e) { } return null; } @Override protected void onPostExecute(Void result) { if (location != null && userMarker == null) { userData.setLocationIP(location); updateLocation(); cameraUpdate = true; mMap.animateCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(location.dlat, location.dlon), mInitialZoomLevel), new CancelableCallback() { @Override public void onFinish() { cameraUpdate = false; handleBuildingsOnMap(); } @Override public void onCancel() { cameraUpdate = false; handleBuildingsOnMap(); } }); } else { handleBuildingsOnMap(); } } }; int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { task.execute(); } } }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void handleResetSecureSession() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.ConversationActivity_reset_secure_session_question); builder.setIconAttribute(R.attr.dialog_alert_icon); builder.setCancelable(true);/* w w w. ja v a 2 s . c o m*/ builder.setMessage(R.string.ConversationActivity_this_may_help_if_youre_having_encryption_problems); builder.setPositiveButton(R.string.ConversationActivity_reset, (dialog, which) -> { if (isSingleConversation()) { final Context context = getApplicationContext(); OutgoingEndSessionMessage endSessionMessage = new OutgoingEndSessionMessage( new OutgoingTextMessage(getRecipient(), "TERMINATE", 0, -1)); new AsyncTask<OutgoingEndSessionMessage, Void, Long>() { @Override protected Long doInBackground(OutgoingEndSessionMessage... messages) { return MessageSender.send(context, messages[0], threadId, false, null); } @Override protected void onPostExecute(Long result) { sendComplete(result); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, endSessionMessage); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
From source file:com.android.leanlauncher.LauncherTransitionable.java
/** * Add a widget to the workspace./*w w w. j av a 2 s .c o m*/ */ private void completeAddAppWidget(final int appWidgetId, long container, AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { if (appWidgetInfo == null) { appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); } // Calculate the grid spans needed to fit this widget CellLayout layout = mWorkspace.getScreen(); int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); int[] spanXY = getSpanForWidget(this, appWidgetInfo); // Try finding open space on Launcher screen // We have saved the position to which the widget was dragged-- this really only matters // if we are placing widgets on a "spring-loaded" screen int[] cellXY = mTmpAddItemCellCoordinates; int[] touchXY = mPendingAddInfo.dropPos; int[] finalSpan = new int[2]; boolean foundCellSpan = false; if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { cellXY[0] = mPendingAddInfo.cellX; cellXY[1] = mPendingAddInfo.cellY; spanXY[0] = mPendingAddInfo.spanX; spanXY[1] = mPendingAddInfo.spanY; foundCellSpan = true; } else if (touchXY != null) { // when dragging and dropping, just find the closest free spot int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], spanXY[1], cellXY, finalSpan); spanXY[0] = finalSpan[0]; spanXY[1] = finalSpan[1]; foundCellSpan = (result != null); } else { foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); } if (!foundCellSpan) { if (appWidgetId != -1) { // Deleting an app widget ID is a void call but writes to disk before returning // to the caller... new AsyncTask<Void, Void, Void>() { public Void doInBackground(Void... args) { mAppWidgetHost.deleteAppWidgetId(appWidgetId); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); } showOutOfSpaceMessage(); return; } // Build Launcher-specific widget info and save to database LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); launcherInfo.spanX = spanXY[0]; launcherInfo.spanY = spanXY[1]; launcherInfo.minSpanX = mPendingAddInfo.minSpanX; launcherInfo.minSpanY = mPendingAddInfo.minSpanY; launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); LauncherModel.addItemToDatabase(this, launcherInfo, container, cellXY[0], cellXY[1], false); if (!mRestoring) { if (hostView == null) { // Perform actual inflation because we're live launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); } else { // The AppWidgetHostView has already been inflated and instantiated launcherInfo.hostView = hostView; } launcherInfo.hostView.setTag(launcherInfo); launcherInfo.hostView.setVisibility(View.VISIBLE); launcherInfo.notifyWidgetSizeChanged(this); mWorkspace.addInScreen(launcherInfo.hostView, container, cellXY[0], cellXY[1], launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); } resetAddInfo(); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
/** * This loads a path into the MainFragment. * @param path the path to be loaded//from ww w. j a v a 2s . c o m * @param back if we're coming back from any directory and want the scroll to be restored * @param openMode the mode in which the directory should be opened */ public void loadlist(final String path, final boolean back, final OpenMode openMode) { if (mActionMode != null) mActionMode.finish(); mSwipeRefreshLayout.setRefreshing(true); if (loadFilesListTask != null && loadFilesListTask.getStatus() == AsyncTask.Status.RUNNING) { loadFilesListTask.cancel(true); } loadFilesListTask = new LoadFilesListTask(ma.getActivity(), path, ma, openMode, getBoolean(PREFERENCE_SHOW_THUMB), getBoolean(PREFERENCE_SHOW_HIDDENFILES), (data) -> { if (data != null && data.second != null) { boolean isPathLayoutGrid = dataUtils.getListOrGridForPath(path, DataUtils.LIST) == DataUtils.GRID; setListElements(data.second, back, path, data.first, false, isPathLayoutGrid); mSwipeRefreshLayout.setRefreshing(false); } }); loadFilesListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.amaze.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; }/*from ww w .j av a 2 s . c o 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, 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: 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(); 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:eu.faircode.netguard.ActivitySettings.java
private void handleExport(final Intent data) { new AsyncTask<Object, Object, Throwable>() { @Override//from ww w . j a va 2s . c o m protected Throwable doInBackground(Object... objects) { OutputStream out = null; try { Uri target = data.getData(); if (data.hasExtra("org.openintents.extra.DIR_PATH")) target = Uri.parse(target + "/netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); Log.i(TAG, "Writing URI=" + target); out = getContentResolver().openOutputStream(target); xmlExport(out); 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)); } } } @Override protected void onPostExecute(Throwable ex) { if (running) { if (ex == null) Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.android.mail.browse.ConversationCursor.java
/** * When we get a requery from the UI, we'll do it, but also clear the cache. The listener is * notified when the requery is complete * NOTE: This will have to change, of course, when we start using loaders... */// w ww . ja v a 2s. co m public boolean refresh() { if (DEBUG) LogUtils.i(LOG_TAG, "[refresh() this=%s]", this); synchronized (mCacheMapLock) { if (mRefreshTask != null) { if (DEBUG) { LogUtils.i(LOG_TAG, "[refresh() %s returning; already running %d]", mName, mRefreshTask.hashCode()); } return false; } if (mUnderlyingCursor != null) { mUnderlyingCursor.stopCaching(); } mRefreshTask = new RefreshTask(); mRefreshTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } return true; }