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:eu.power_switch.widget.activity.ConfigureReceiverWidgetActivity.java
private void updateUI() { new AsyncTask<Void, Void, List<Apartment>>() { @Override/*from w w w.java 2 s.c o m*/ protected List<Apartment> doInBackground(Void... params) { try { return DatabaseHandler.getAllApartments(); } catch (Exception e) { return new ArrayList<>(); } } @Override protected void onPostExecute(List<Apartment> result) { apartmentList.clear(); apartmentList.addAll(result); for (Apartment apartment : apartmentList) { apartmentNameList.add(apartment.getName()); } spinnerApartment.setSelection(0); adapterApartments.notifyDataSetChanged(); updateRoomList(); // Abort if no rooms are defined in main app if (receiverNameList.isEmpty()) { Toast.makeText(getApplicationContext(), getString(R.string.please_define_receiver_in_main_app), Toast.LENGTH_LONG).show(); finish(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:androidx.mediarouter.app.MediaRouteButton.java
public MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr) { super(MediaRouterThemeHelper.createThemedButtonContext(context), attrs, defStyleAttr); context = getContext();/*from w ww . ja v a 2 s . c o m*/ mRouter = MediaRouter.getInstance(context); mCallback = new MediaRouterCallback(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MediaRouteButton, defStyleAttr, 0); mButtonTint = a.getColorStateList(R.styleable.MediaRouteButton_mediaRouteButtonTint); mMinWidth = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minWidth, 0); mMinHeight = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minHeight, 0); int remoteIndicatorResId = a.getResourceId(R.styleable.MediaRouteButton_externalRouteEnabledDrawable, 0); a.recycle(); if (remoteIndicatorResId != 0) { Drawable.ConstantState remoteIndicatorState = sRemoteIndicatorCache.get(remoteIndicatorResId); if (remoteIndicatorState != null) { setRemoteIndicatorDrawable(remoteIndicatorState.newDrawable()); } else { mRemoteIndicatorLoader = new RemoteIndicatorLoader(remoteIndicatorResId); mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } updateContentDescription(); setClickable(true); }
From source file:com.dm.wallpaper.board.fragments.CategoryWallpapersFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ViewHelper.setupToolbar(mToolbar);// w ww.ja va2s .com int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon); mToolbar.setTitle(""); mToolbar.setNavigationIcon( DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_back, color)); ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar); mCategory.setText(mCategoryName); String count = mCategoryCount + " " + getActivity().getResources().getString(R.string.navigation_view_wallpapers); mCount.setText(count); mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), getActivity().getResources().getInteger(R.integer.wallpapers_column_count))); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setHasFixedSize(true); if (WallpaperBoardApplication.getConfig() .getWallpapersGrid() == WallpaperBoardConfiguration.GridStyle.FLAT) { int padding = getActivity().getResources().getDimensionPixelSize(R.dimen.card_margin); mRecyclerView.setPadding(padding, padding, 0, 0); } resetViewBottomPadding(mRecyclerView, true); initAppBar(); color = ColorHelper.getAttributeColor(getActivity(), android.R.attr.textColorPrimary); Drawable drawable = DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color); mSearchResult.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); mAsyncTask = new WallpapersLoader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.giovanniterlingen.windesheim.view.Fragments.ContentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.downloadPending); NotificationCenter.getInstance().addObserver(this, NotificationCenter.downloadUpdated); NotificationCenter.getInstance().addObserver(this, NotificationCenter.downloadFinished); final ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_contents, container, false); recyclerView = viewGroup.findViewById(R.id.contents_recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false); final ProgressBar progressBar = viewGroup.findViewById(R.id.progress_bar); progressBar.setVisibility(View.VISIBLE); Bundle bundle = this.getArguments(); ActionBar toolbar = ((NatschoolActivity) getActivity()).getSupportActionBar(); if (toolbar != null) { String studyRouteName;//from ww w. j a v a2s. c o m if (bundle != null && (studyRouteName = bundle.getString(STUDYROUTE_NAME)) != null && studyRouteName.length() != 0) { toolbar.setTitle(bundle.getString(STUDYROUTE_NAME)); } else { toolbar.setTitle(getResources().getString(R.string.courses)); } toolbar.setDisplayHomeAsUpEnabled(false); toolbar.setDisplayHomeAsUpEnabled(true); } new NatSchoolController((bundle == null ? -1 : (studyRouteId = bundle.getInt(STUDYROUTE_ID))), (bundle == null ? -1 : bundle.getInt(PARENT_ID, -1)), getActivity()) { @Override public void onFinished(final List<NatschoolContent> courses) { progressBar.setVisibility(View.GONE); TextView emptyTextView = viewGroup.findViewById(R.id.empty_textview); if (courses.isEmpty()) { emptyTextView.setVisibility(View.VISIBLE); } else { emptyTextView.setVisibility(View.GONE); } adapter = new NatschoolContentAdapter(getActivity(), courses) { @Override protected void onContentClick(NatschoolContent content, int position) { if (content.url == null || content.url.length() == 0) { Bundle bundle = new Bundle(); if (content.id == -1) { bundle.putInt(STUDYROUTE_ID, content.studyRouteItemId); } else { bundle.putInt(STUDYROUTE_ID, studyRouteId); bundle.putInt(PARENT_ID, content.id); } bundle.putString(STUDYROUTE_NAME, content.name); ContentsFragment contentsFragment = new ContentsFragment(); contentsFragment.setArguments(bundle); getActivity().getSupportFragmentManager().beginTransaction() .replace(R.id.contents_fragment, contentsFragment, "").addToBackStack("") .commit(); } else { if (content.type == 1 || content.type == 3 || content.type == 11) { createWebView(content.url); } else if (content.type == 10) { if (!content.downloading) { new DownloadController(getActivity(), content.url, studyRouteId, content.id, position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } } } }; recyclerView.setAdapter(adapter); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return viewGroup; }
From source file:eu.musesproject.client.connectionmanager.ConnectionManager.java
/** * Sends ack to the server to tell that data has been received on the client * @return void/*from www . ja v a 2 s . c om*/ */ public void ack() { Log.d(TAG, "Sending ack.."); if (NetworkChecker.isInternetConnected) { if (PhoneModeReceiver.SLEEP_MODE_ACTIVE) { // FIXME HttpClientAsyncThread httpClientAsyncThread = new HttpClientAsyncThread(); httpClientAsyncThread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ACK, URL, Integer.toString(AlarmReceiver.DEFAULT_SLEEP_POLL_INTERVAL), ""); } else { HttpClientAsyncThread httpClientAsyncThread = new HttpClientAsyncThread(); httpClientAsyncThread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ACK, URL, Integer.toString(AlarmReceiver.DEFAULT_POLL_INTERVAL), ""); } } }
From source file:com.rks.musicx.ui.fragments.TagEditorFragment.java
private void function() { song = new Song(); toolbar.setTitle("Tag Editor"); toolbar.setTitleTextColor(Color.WHITE); String title = Extras.getInstance().getTitle(); String album = Extras.getInstance().getAlbum(); String artist = Extras.getInstance().getArtist(); String year = Extras.getInstance().getYear(); int no = Extras.getInstance().getNo(); long id = Extras.getInstance().getAlbumID(); String path = Extras.getInstance().getPath(); long songid = Extras.getInstance().getId(); song.setTitle(title);//from ww w . ja v a2 s. co m song.setArtist(artist); song.setAlbum(album); song.setTrackNumber(no); song.setmSongPath(path); song.setId(songid); song.setAlbumId(id); song.setYear(year); song.setLyrics(LyricsHelper.getInbuiltLyrics(path)); mTitleEditText.setText(song.getTitle()); mArtistEditText.setText(song.getArtist()); mAlbumEditText.setText(song.getAlbum()); mTrackEditText.setText(String.valueOf(song.getTrackNumber())); mYearEditText.setText(song.getYear()); mLyricsEditText.setText(song.getLyrics()); saveTags.setImageBitmap(Helper.textAsBitmap("Save", 40, Color.WHITE)); ArtworkUtils.ArtworkLoader(getContext(), 300, 600, album, id, new palette() { @Override public void palettework(Palette palette) { final int[] colors = Helper.getAvailableColor(getContext(), palette); if (getActivity() == null || getActivity().getWindow() == null) { return; } Helper.setColor(getActivity(), colors[0], toolbar); } }, new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { albumArtwork.setImageBitmap(bitmap); } @Override public void bitmapfailed(Bitmap bitmap) { albumArtwork.setImageBitmap(bitmap); } }); int colorAccent = Config.accentColor(getContext(), Helper.getATEKey(getContext())); if (getActivity() == null || getActivity().getWindow() == null) { return; } Helper.setColor(getActivity(), colorAccent, toolbar); saveTags.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new saveData(getContext(), song).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); albumArtwork.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { pickNupdateArtwork(); } }); /** * Show Case */ ShowcaseConfig config = new ShowcaseConfig(); MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(getActivity(), "1600"); sequence.setConfig(config); sequence.addSequenceItem(albumArtwork, "Tap to change Artwork", "GOT IT"); sequence.start(); sequence.setOnItemDismissedListener(new MaterialShowcaseSequence.OnSequenceItemDismissedListener() { @Override public void onDismiss(MaterialShowcaseView materialShowcaseView, int i) { materialShowcaseView.hide(); } }); Helper.rotateFab(saveTags); }
From source file:org.anoopam.main.anoopamvideo.VideoListActivity.java
private void getVideoListFromCache() { SmartUtils.showProgressDialog(this, "Loading...", true); AsyncTask<Void, Void, ArrayList<ContentValues>> task = new AsyncTask<Void, Void, ArrayList<ContentValues>>() { @Override/* www .jav a 2 s. com*/ protected ArrayList<ContentValues> doInBackground(Void... params) { try { videoList = smartCaching.getDataFromCache("videos", "SELECT * FROM videos WHERE catID='" + videoDetails.getAsString("catID") + "' ORDER BY videoTitle ASC"); } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(ArrayList<ContentValues> result) { super.onPostExecute(result); SmartUtils.hideProgressDialog(); if (videoList != null && videoList.size() > 0) { if (mAdapter == null) { mAdapter = new VideoListAdapter(); mRecyclerView.setAdapter(mAdapter); } else { mAdapter.notifyDataSetChanged(); } } } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { task.execute(); } }
From source file:org.anoopam.main.anoopamvideo.VideoCatListActivity.java
private void getVideoCategories() { AsyncTask<Void, Void, ArrayList<ContentValues>> task = new AsyncTask<Void, Void, ArrayList<ContentValues>>() { @Override/*from w w w. j av a 2 s . c o m*/ protected ArrayList<ContentValues> doInBackground(Void... params) { try { return videoCat = smartCaching.getDataFromCache("videocategories", "SELECT * FROM videocategories WHERE mainCatID='1' ORDER BY catName ASC"); } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(ArrayList<ContentValues> result) { super.onPostExecute(result); SmartUtils.hideProgressDialog(); if (videoCat == null || videoCat.size() <= 0) { AMServiceRequest.getInstance().startFetchingAnoopamAudioFromServer(); } else { if (mAdapter == null) { mAdapter = new AudioCatAdapter(); mRecyclerView.setAdapter(mAdapter); } else { mAdapter.notifyDataSetChanged(); } } } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { task.execute(); } }
From source file:com.dm.material.dashboard.candybar.fragments.FAQsFragment.java
private void getFAQs() { mGetFAQs = new AsyncTask<Void, Void, Boolean>() { List<FAQs> faqs;/*from ww w. j a v a 2 s . co m*/ String[] questions; String[] answers; @Override protected void onPreExecute() { super.onPreExecute(); faqs = new ArrayList<>(); questions = getActivity().getResources().getStringArray(R.array.questions); answers = getActivity().getResources().getStringArray(R.array.answers); } @Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try { Thread.sleep(1); for (int i = 0; i < questions.length; i++) { if (i < answers.length) { FAQs faq = new FAQs(questions[i], answers[i]); faqs.add(faq); } } return true; } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; } @Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); if (aBoolean) { setHasOptionsMenu(true); mAdapter = new FAQsAdapter(faqs); mRecyclerView.setAdapter(mAdapter); } mGetFAQs = null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:connection.OptimusHTTP.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void ParallelAsyncTask(HttpReq req, HttpReqPkg p, ResponseListener listener) { req.setOnResultsListener(listener);//w ww .j av a2s.c om if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { req.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, p); } else { req.execute(p); } }