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.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java
private void filterByTopicTitle(String topicTitle) { topicTitleFilter = topicTitle;//from w w w . ja v a 2 s .co m new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... arg) { Cursor cursor = getCursor(); return cursor; } @Override protected void onPostExecute(Cursor cursor) { ((CursorAdapter) gridView.getAdapter()).changeCursor(cursor); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.bt.heliniumstudentapp.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainContext = MainActivity.mainContext; pendingRestart = false;/*from w w w . j av a 2 s. c om*/ setContentView(R.layout.activity_settings); toolbarTB = (Toolbar) findViewById(R.id.tb_toolbar_as); toolbarTB.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); setToolbar(); addPreferencesFromResource(R.layout.preferencescreen_settings); getListView().setBackgroundColor(Color.TRANSPARENT); getListView().setCacheColorHint(Color.TRANSPARENT); getListView().setBackgroundColor(ContextCompat.getColor(this, MainActivity.themeColor)); setTheme(MainActivity.themeSettings); MainActivity.setStatusBar(this); setTitles(); findPreference("pref_general_class").setSummary( Arrays.asList(getResources().getStringArray(R.array.general_class_array)).get(Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(this).getString("pref_general_class", "0")))); findPreference("pref_general_language") .setSummary(Arrays.asList(getResources().getStringArray(R.array.general_language_array)) .get(Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_general_language", "0")))); findPreference("pref_customization_theme") .setSummary(Arrays.asList(getResources().getStringArray(R.array.customization_theme_array)) .get(Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_theme", "0")))); findPreference("pref_customization_color_primary") .setSummary(Arrays.asList(getResources().getStringArray(R.array.customization_color_primary_array)) .get(Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_primary", "4")))); findPreference("pref_customization_color_accent") .setSummary(Arrays.asList(getResources().getStringArray(R.array.customization_color_accent_array)) .get(Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_accent", "14")))); try { final String date = PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_schedule_version_0", ""); if (date.equals("")) findPreference("pref_schedule_version_0").setSummary(getString(R.string.database_no)); else findPreference("pref_schedule_version_0") .setSummary(DateFormat.getDateFormat(getApplicationContext()).format( HeliniumStudentApp.df_save().parse(date)) + date.substring(date.indexOf(' '))); } catch (ParseException ignored) { } try { final String date = PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_schedule_version_1", ""); if (date.equals("")) findPreference("pref_schedule_version_1").setSummary(getString(R.string.database_no)); else findPreference("pref_schedule_version_1") .setSummary(DateFormat.getDateFormat(getApplicationContext()).format( HeliniumStudentApp.df_save().parse(date)) + date.substring(date.indexOf(' '))); } catch (ParseException ignored) { } try { final String date = PreferenceManager.getDefaultSharedPreferences(this).getString("pref_grades_version", ""); if (date.equals("")) findPreference("pref_grades_version").setSummary(getString(R.string.database_no)); else findPreference("pref_grades_version").setSummary(DateFormat.getDateFormat(getApplicationContext()) .format(HeliniumStudentApp.df_save().parse(date)) + date.substring(date.indexOf(' '))); } catch (ParseException ignored) { } findPreference("pref_grades_term").setSummary(Arrays .asList(getResources().getStringArray(R.array.grades_term_array)) .get(Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(this).getString("pref_grades_term", "1")) - 1)); try { findPreference("pref_updates_check").setSummary(getString(R.string.updates_check_summary) + ' ' + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); } catch (PackageManager.NameNotFoundException ignored) { } findPreference("pref_general_class") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { preference.setSummary( Arrays.asList(getResources().getStringArray(R.array.general_class_array)) .get(Integer.parseInt(newValue.toString()))); GradesFragment.gradesHtml = null; pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_general_language") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { preference.setSummary( Arrays.asList(getResources().getStringArray(R.array.general_language_array)) .get(Integer.parseInt(newValue.toString()))); pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_customization_theme") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { preference.setSummary( Arrays.asList(getResources().getStringArray(R.array.customization_theme_array)) .get(Integer.parseInt(newValue.toString()))); //MainActivity.setColors(Integer.parseInt(newValue.toString()), HeliniumStudentApp.ACTION_NULL, HeliniumStudentApp.ACTION_NULL); //setTheme(MainActivity.themeSettings); GradesFragment.gradesHtml = null; pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_customization_color_primary") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { preference.setSummary(Arrays .asList(getResources() .getStringArray(R.array.customization_color_primary_array)) .get(Integer.parseInt(newValue.toString()))); MainActivity.setColors(HeliniumStudentApp.ACTION_NULL, Integer.parseInt(newValue.toString()), HeliniumStudentApp.ACTION_NULL); setToolbar(); GradesFragment.gradesHtml = null; pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_customization_color_accent") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { preference.setSummary(Arrays .asList(getResources().getStringArray(R.array.customization_color_accent_array)) .get(Integer.parseInt(newValue.toString()))); MainActivity.setColors(HeliniumStudentApp.ACTION_NULL, HeliniumStudentApp.ACTION_NULL, Integer.parseInt(newValue.toString())); setTitles(); GradesFragment.gradesHtml = null; pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_customization_compact") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { GradesFragment.gradesHtml = null; pendingRestart = true; return true; } }); findPreference("pref_schedule_next_week") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { findPreference("pref_schedule_version_1").setSummary(getString(R.string.database_no)); PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this).edit() .putString("html_schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this).edit() .putString("pref_schedule_version_1", null).apply(); return true; } }); findPreference("pref_grades_term") .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!((ListPreference) preference).getValue().equals(newValue)) { findPreference("pref_grades_version").setSummary(getString(R.string.database_no)); preference.setSummary( Arrays.asList(getResources().getStringArray(R.array.grades_term_array)) .get(Integer.parseInt(newValue.toString()) - 1)); PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this).edit() .putString("html_grades", null).apply(); PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this).edit() .putString("pref_grades_version", null).apply(); GradesFragment.gradesHtml = null; pendingRestart = true; return true; } else { return false; } } }); findPreference("pref_updates_check") .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (MainActivity.isOnline()) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) new UpdateClass(SettingsActivity.this, true).execute(); else new UpdateClass(SettingsActivity.this, true) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { Toast.makeText(SettingsActivity.this, getString(R.string.error_conn_no), Toast.LENGTH_SHORT).show(); } return true; } }); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
private static void showMedia(final String localId, final Context ctx, final ProgressDialog dialog) { new AsyncTask<Void, Void, Boolean>() { private boolean noMedia = false; @Override/*from w w w . j a v a 2s.c om*/ protected Boolean doInBackground(Void... params) { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); Intent mediaPlayer = new Intent(Intent.ACTION_VIEW); if (file1.exists()) { mediaPlayer.setDataAndType(Uri.fromFile(file1), "image/*"); } else if (file2.exists()) { mediaPlayer.setDataAndType(Uri.fromFile(file2), "video/*"); } else { noMedia = true; return false; } ctx.startActivity(mediaPlayer); return true; } @Override protected void onPostExecute(Boolean result) { if (dialog != null) { dialog.dismiss(); } if (noMedia) { Toast.makeText(ctx.getApplicationContext(), ctx.getApplicationContext().getText(R.string.no_media), Toast.LENGTH_SHORT).show(); noMedia = false; } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.microsoft.services.msa.AuthorizationRequest.java
/** * Called when the response uri contains an authorization code. * * This method launches an async AccessTokenRequest and dismisses the dialog window. * * See <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-4.1.2">Section * 4.1.2</a> of the OAuth 2.0 spec for more information. * * @param code is the authorization code from the uri *///from ww w . j a va2 s . c o m private void onAuthorizationResponse(String code) { if (TextUtils.isEmpty(code)) throw new AssertionError(); // Since we DO have an authorization code, launch an AccessTokenRequest. // We do this asynchronously to prevent the HTTP IO from occupying the // UI/main thread (which we are on right now). AccessTokenRequest request = new AccessTokenRequest(this.client, this.clientId, code, mOAuthConfig); TokenRequestAsync requestAsync = new TokenRequestAsync(request); // We want to know when this request finishes, because we need to notify our // observers. requestAsync.addObserver(this); requestAsync.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:joshuatee.wx.StormReportsActivity.java
private void updateDisplay() { if (cMonth != pMonth || cYear != pYear || cDay != pDay) { UpdateIowaMesoData();/*from w ww.ja v a 2 s. c om*/ no = date + "_rpts"; img_url = "http://www.spc.noaa.gov/climo/reports/" + no + ".gif"; text_url = "http://www.spc.noaa.gov/climo/reports/" + no + ".csv"; first_run = true; filter = "All"; new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); cYear = pYear; cMonth = pMonth; cDay = pDay; } }
From source file:gr.ioanpier.auth.users.memorypaintings.MainActivityFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Language Locale String languageToLoad = getActivity().getIntent().getStringExtra(LANGUAGE); // your language if (languageToLoad != null) { Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;/*from w w w . j av a 2 s. c om*/ getActivity().getResources().updateConfiguration(config, getActivity().getResources().getDisplayMetrics()); } View rootView = inflater.inflate(R.layout.fragment_main, container, false); //Calculate the level and the number of cards. level = getActivity().getIntent().getIntExtra(LEVEL_TAG, 0); if (level >= layoutsPerLevel.length) level = layoutsPerLevel.length - 1; numberOfCards = cardsPerLevel[level]; numberOfBitmapWorkerTasks = numberOfCards / 2; instantiateLoadingBar(); if (!isExternalStorageReadable()) { Log.e(LOG, "External storage wasn't readable"); storedDrawables = null; } else { File[] imageFiles = getFilesFromDirectory(WelcomeScreen.IMAGES_PATH, ".jpg", ".png"); if (imageFiles.length > 0) { String descriptionsFolder = "Descriptions"; Locale locale = getActivity().getResources().getConfiguration().locale; if (locale.getDisplayLanguage().equals(Locale.ENGLISH.getDisplayLanguage())) descriptionsFolder = descriptionsFolder.concat("_en"); else descriptionsFolder = descriptionsFolder.concat("_pl"); File[] descFiles = getFilesFromDirectory(WelcomeScreen.DESCRIPTIONS_PATH, ".txt"); //getDrawables storedDrawables = getDrawables(imageFiles, descFiles); } else { Log.e(LOG, "No files found in external storage"); storedDrawables = null; } } pairs = new int[numberOfCards]; for (int i = 0; i < numberOfCards; i++) { pairs[i] = -1; } cards = new ImageViewCard[numberOfCards]; //This is where the layout magic happens. LinearLayout linearLayout; int index; for (int i = 0; i < layoutsPerLevel[level]; i++) { //The layout consists of multiple vertical LinearLayout[s] positioned horizontally next to each other. linearLayout = new LinearLayout(getActivity()); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f)); linearLayout.setOrientation(LinearLayout.VERTICAL); for (int j = 0; j < numberOfCards / layoutsPerLevel[level]; j++) { //Each LinearLayout has a number of ImageViewCard[s], each positioned evenly in inside the layout. The number depends on the level. //ImageViewCard is an extension of the ViewFlipper class with a built in flipCard method for flipping between 2 images and which also includes animation. ImageViewCard card = new ImageViewCard(getActivity()); card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f)); ((LinearLayout.LayoutParams) card.getLayoutParams()).setMargins(16, 16, 16, 16); //SquareImageView is an extension of the ImageView class that ensures that the image is square. //Two are needed, one for the back of the image and one for the front. SquareImageView image1 = new SquareImageView(getActivity()); image1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); SquareImageView image2 = new SquareImageView(getActivity()); image2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); //Add the SquareImageView[s] to the ImageViewCard and subsequently that to the LinearLayout. card.addView(image1); card.addView(image2); index = i * numberOfCards / layoutsPerLevel[level] + j; linearLayout.addView(card); cardsIndex.put(card.hashCode(), index); //Set the back of the image. ((ImageView) card.getChildAt(0)) .setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.black)); //Save the ImageViewCard for later use. cards[index] = card; } //Add the LinearLayout to the rootView. ((LinearLayout) rootView.findViewById(R.id.parent)).addView(linearLayout); } //Assign a listener for every ImageViewCard. View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { if (!stillAnimating && numberOfBitmapWorkerTasks == 0) { int cardID = cardsIndex.get(view.hashCode()); stillAnimating = true; synchronized (gameLogicLock) { if (numberOfCardsFound < numberOfCards) onCardFlipped(cardID); else onCardClicked(cardID); } //Add a delay before the listener can be activated again. new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { try { Thread.sleep(250); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(Void n) { stillAnimating = false; } }.execute(); } else if (numberOfBitmapWorkerTasks > 0) { Toast.makeText(getActivity(), getString(R.string.loading_bar_message), Toast.LENGTH_SHORT) .show(); } } }; for (int i = 0; i < numberOfCards; i++) { cards[i].setOnClickListener(onClickListener); } //Initialize found = new boolean[numberOfCards]; for (int i = 0; i < numberOfCards; i++) found[i] = false; //Initialize int[] chosenDrawables = new int[numberOfCards / 2]; cardDrawablePairs = new int[numberOfCards]; //Initialize. Holds the index of every ImageViewCard in cards. Will later be used for the pairs. ArrayList<Integer> availablePairs = new ArrayList<>(); for (int i = 0; i < numberOfCards; i++) availablePairs.add(i); Collections.shuffle(availablePairs); Random r = new Random(); int pair1, pair2; BitmapWorkerTask bitmapWorkerTask; for (int i = 0; i < numberOfCards / 2; i++) { //Choose at random one of the available images. Make sure it's unique. int range; if (storedDrawables == null) range = colors.length; else range = storedDrawables.length; boolean unique = false; while (!unique) { unique = true; //If there are a lot of images, this should be changed (there will never be a lot) chosenDrawables[i] = r.nextInt(range); for (int j = 0; j < i; j++) { if (chosenDrawables[i] == chosenDrawables[j]) unique = false; } } //availablePairs have already been shuffled, so just remove the first 2. pair1 = availablePairs.remove(0); pair2 = availablePairs.remove(0); cardDrawablePairs[pair1] = chosenDrawables[i]; cardDrawablePairs[pair2] = chosenDrawables[i]; //Assign the front of the ImageViewCard to the randomly chosen Drawable. ImageView imageView1, imageView2; String absolutePath; if (storedDrawables == null) { (cards[pair1].getChildAt(1)) .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]])); (cards[pair2].getChildAt(1)) .setBackgroundColor(ContextCompat.getColor(getActivity(), colors[chosenDrawables[i]])); } else { DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut wm.getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels / (layoutsPerLevel[level]); int screenHeight = displayMetrics.heightPixels / (cardsPerLevel[level] / layoutsPerLevel[level]); absolutePath = storedDrawables[chosenDrawables[i]].absolute_path_image; imageView1 = ((ImageView) cards[pair1].getChildAt(1)); imageView2 = ((ImageView) cards[pair2].getChildAt(1)); bitmapWorkerTask = new BitmapWorkerTask(screenWidth, screenHeight, imageView1, imageView2); bitmapWorkerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, absolutePath); } //Save the pairs. pairs[pair1] = pair2; pairs[pair2] = pair1; } if (storedDrawables == null) { numberOfBitmapWorkerTasks = 0; } return rootView; }
From source file:joshuatee.wx.NEXRADAttributesActivity.java
public void LocationAdd(int id) { new SaveLocFromCounty().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id); }
From source file:joshuatee.wx.ModelInterfaceActivity.java
private void selectItem(int position) { mDrawerList.setItemChecked(position, false); mDrawerLayout.closeDrawer(mDrawerList); if (model.equals("GFS")) { param = UtilityModelInterface.model_gfs_params[position]; } else if (model.equals("RAP")) { param = UtilityModelInterface.model_rap_params[position]; } else if (model.equals("NAM")) { param = UtilityModelInterface.model_nam_params[position]; } else if (model.equals("ECMWF")) { param = UtilityModelInterface.model_ecmwf_params[position]; } else if (model.equals("UKMET")) { //param = UtilityModelInterface.model_ukmet_params[position]; } else if (model.equals("HRRR")) { param = UtilityModelInterface.model_hrrr_params[position]; } else if (model.equals("NAM4KM")) { param = UtilityModelInterface.model_nam4km_params[position]; } else if (model.equals("SREF")) { param = UtilityModelInterface.model_sref_params[position]; }//ww w.j a va 2s.c om editor.putString("MODEL_PARAM_LAST_USED", param); editor.commit(); new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java
private void setupListNavigation() { if (displayOptionsAdapter == null) { displayOptionsAdapter = getDisplayOptionsAdapter(null); displayOptionsAdapter.changeCursor(null); getActionBar().setListNavigationCallbacks(displayOptionsAdapter, navListener); }//from w w w. ja v a2s . com new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... arg0) { return getDisplayOptionsCursor(dataService.getHelper()); } @Override protected void onPostExecute(Cursor cursor) { displayOptionsAdapter.changeCursor(cursor); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.chromium.chrome.browser.download.DownloadManagerService.java
/** * Schedule an update if there is no update scheduled. *//*from w w w. ja v a 2s.c o m*/ private void scheduleUpdateIfNeeded() { if (mIsUIUpdateScheduled.compareAndSet(false, true)) { Runnable updateTask = new Runnable() { @Override public void run() { new AsyncTask<Void, Void, Void>() { @Override public Void doInBackground(Void... params) { updateAllNotifications(); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); mIsUIUpdateScheduled.set(false); } }; mHandler.postDelayed(updateTask, mUpdateDelayInMillis); } }