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.siacs.conversations.ui.ServiceBrowserFragment.java
protected void startDiscovery() { mSubscription = mRxDnssd.browse(mReqType, mDomain).compose(mRxDnssd.resolve()) .compose(mRxDnssd.queryRecords()).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<BonjourService>() { @Override/* ww w . ja va 2 s . c o m*/ public void call(BonjourService bonjourService) { int itemsCount = mAdapter.getItemCount(); if (!bonjourService.isLost()) { // query "/spreedbox-notify/api/v1/static/scripts/spreedbox-notify.js" String url = ""; if (bonjourService.getInet4Address() != null) { url = "https://" + bonjourService.getInet4Address().getHostAddress() + "/spreedbox-notify/api/v1/static/scripts/spreedbox-notify.js"; } else { url = "https://" + bonjourService.getInet6Address().getHostAddress() + "/spreedbox-notify/api/v1/static/scripts/spreedbox-notify.js"; } CheckSpreedbox checkSpreedbox = new CheckSpreedbox(); checkSpreedbox.bonjourService = bonjourService; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { checkSpreedbox.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url); } else { checkSpreedbox.execute(url); } } catch (RejectedExecutionException e) { e.printStackTrace(); } } else { mAdapter.remove(bonjourService); } ServiceBrowserFragment.this.showList(itemsCount); mAdapter.notifyDataSetChanged(); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Log.e("DNSSD", "Error: ", throwable); ServiceBrowserFragment.this.showError(throwable); } }); }
From source file:net.sourceforge.servestream.fragment.BrowseFragment.java
@SuppressLint("NewApi") private void browseTo(UriBean uri) { showDialog(LOADING_DIALOG);// w ww . j a v a 2 s .co m DetermineActionTask determineActionTask = new DetermineActionTask(getActivity(), uri, this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { determineActionTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { determineActionTask.execute(); } }
From source file:com.prey.activities.CheckPasswordActivity.java
protected void bindPasswordControls() { Button checkPasswordOkButton = (Button) findViewById(R.id.password_btn_login); final EditText pass1 = ((EditText) findViewById(R.id.password_pass_txt)); checkPasswordOkButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final String passwordtyped = pass1.getText().toString(); final Context ctx = getApplicationContext(); if (passwordtyped.equals("")) Toast.makeText(ctx, R.string.preferences_password_length_error, Toast.LENGTH_LONG).show(); else { if (passwordtyped.length() < 6 || passwordtyped.length() > 32) { Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range, 6, 32), Toast.LENGTH_LONG).show(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) new CheckPassword().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, passwordtyped); else new CheckPassword().execute(passwordtyped); }/*from w ww . ja v a2s . co m*/ } } }); //Hack to fix hint's typeface: http://stackoverflow.com/questions/3406534/password-hint-font-in-android EditText password = (EditText) findViewById(R.id.password_pass_txt); password.setTypeface(Typeface.DEFAULT); password.setTransformationMethod(new PasswordTransformationMethod()); }
From source file:org.dbhatt.d_deleted_contact.MainActivity.java
private void restore_all_contacts() { if (deleted_contact.isEmpty()) Toast.makeText(getApplicationContext(), R.string.no_data_found, Toast.LENGTH_SHORT).show(); else/* www . j ava 2 s . c o m*/ new AlertDialog.Builder(this).setTitle(R.string.restore).setMessage(R.string.all_contact) .setPositiveButton(R.string.restore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new Restore_All_contact().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }).create().show(); }
From source file:com.jainbooks.activitys.DashboardActivity.java
public static void registorOrAuthenticate(Activity mActivity, String argJSONString, TAListener listener, String url) {// w w w . j av a2 s . c o m new TAPOSTWebServiceAsyncTask(mActivity, null, listener, WebServiceConstants.BASE_URL + url, argJSONString) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); }
From source file:net.sourceforge.servestream.fragment.BrowseFragment.java
@SuppressLint("NewApi") private void refreshList() { if (mDirectory == null) { return;/* w w w .j av a 2 s . c o m*/ } showDialog(LOADING_DIALOG); mWebpageParserTask = new WebpageParserTask(mHandler, mDirectory[mStepsBack]); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mWebpageParserTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { mWebpageParserTask.execute(); } }
From source file:joshuatee.wx.LocationFragment.java
@Override public void onClick(View v2) { switch (v2.getId()) { case R.id.forecast_generic_status: refresh_dynamic_content();// w ww. j a v a2s .c o m break; case R.id.current_generic: intent = new Intent(getActivity(), SPCSoundingsActivity.class); intent.putExtra(SPCSoundingsActivity.URL, new String[] { preferences.getString("NWS" + loc_num, ""), "" }); startActivity(intent); break; case R.id.forecast_generic: if (seven_day_ext_shown) { button_for.setText(seven_day_sum); seven_day_ext_shown = false; tv_sunrise.setText(""); tv_sunrise.setVisibility(View.GONE); } else { tv_sunrise.setVisibility(View.VISIBLE); if (Utility.US(x)) { new GetSunrise().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } button_for.setText(seven_day_ext); seven_day_ext_shown = true; } break; case R.id.hazards_generic: if (hazards_shown) { tv_hazard.setTextColor(highlight_color); tv_hazard.setText(Html.fromHtml(hazards_sum)); hazards_shown = false; } else { GetHazards(); hazards_shown = true; } break; } }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
@SuppressWarnings("ConstantConditions") @Override//ww w .j av a2s. c om public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) { mainContext = (AppCompatActivity) getActivity(); scheduleLayout = inflater.inflate(R.layout.fragment_schedule, viewGroup, false); MainActivity.setToolbarTitle(mainContext, getResources().getString(R.string.schedule), null); weekDaysLV = (ListView) scheduleLayout.findViewById(R.id.lv_weekDays_fs); final boolean restart = PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("forced_restart", false); if (restart) PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putBoolean("forced_restart", false) .apply(); if (restart) { //TODO Database check? MainActivity.setStatusBar(mainContext); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (MainActivity.isOnline()) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } else if (scheduleJson == null) { final boolean online = MainActivity.isOnline(); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); if (online && PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_updates_auto_update", true)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) new UpdateClass(mainContext, false).execute(); else new UpdateClass(mainContext, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } if (online && (PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_schedule_init", true) || PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null) == null)) { getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { MainActivity.setStatusBar(mainContext); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (online) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } } ((SwipeRefreshLayout) scheduleLayout).setColorSchemeResources(MainActivity.accentSecondaryColor, MainActivity.accentPrimaryColor, MainActivity.primaryColor); ((SwipeRefreshLayout) scheduleLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); MainActivity.prevIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus--; getSchedule(HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (scheduleFocus > currentWeek + 1) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.historyIV.setOnClickListener(new OnClickListener() { //FIXME Huge mess private int year; private int monthOfYear; private int dayOfMonth; @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { MainActivity.setUI(HeliniumStudentApp.VIEW_SCHEDULE, HeliniumStudentApp.ACTION_ONLINE); final AlertDialog.Builder weekpickerDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); final View view = View.inflate(mainContext, R.layout.dialog_schedule, null); weekpickerDialogBuilder.setView(view); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.np_weekpicker_dw); year = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR); monthOfYear = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.MONTH); dayOfMonth = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.DAY_OF_MONTH); weekpickerDialogBuilder.setTitle(getString(R.string.go_to)); weekpickerDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final GregorianCalendar date = new GregorianCalendar( HeliniumStudentApp.LOCALE); final GregorianCalendar today = new GregorianCalendar( HeliniumStudentApp.LOCALE); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, monthOfYear); date.set(Calendar.DAY_OF_MONTH, dayOfMonth); date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); today.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); scheduleFocus = (today.get(Calendar.WEEK_OF_YEAR)) - ((int) ((today.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)) - (date.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)))); getSchedule(HeliniumStudentApp.DIREC_OTHER, HeliniumStudentApp.ACTION_REFRESH_IN); } }); weekpickerDialogBuilder.setNegativeButton(getString(android.R.string.cancel), null); final AlertDialog weekPickerDialog = weekpickerDialogBuilder.create(); final GregorianCalendar minDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); minDate.set(Calendar.YEAR, 2000); minDate.set(Calendar.WEEK_OF_YEAR, 1); final GregorianCalendar maxDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); maxDate.set(Calendar.YEAR, 2038); maxDate.set(Calendar.WEEK_OF_YEAR, 1); datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() { final GregorianCalendar newDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); @Override public void onDateChanged(DatePicker view, int dialogYear, int dialogMonthOfYear, int dialogDayOfMonth) { newDate.set(year, monthOfYear, dayOfMonth); year = dialogYear; monthOfYear = dialogMonthOfYear; dayOfMonth = dialogDayOfMonth; if (minDate != null && minDate.after(newDate)) view.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH), this); else if (maxDate != null && maxDate.before(newDate)) view.init(maxDate.get(Calendar.YEAR), maxDate.get(Calendar.MONTH), maxDate.get(Calendar.DAY_OF_MONTH), this); else view.init(year, monthOfYear, dayOfMonth, this); } }); weekPickerDialog.setCanceledOnTouchOutside(true); weekPickerDialog.show(); weekPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); weekPickerDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); } else { scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.nextIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus++; getSchedule(HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) != null && scheduleFocus >= currentWeek) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); return scheduleLayout; }
From source file:de.enlightened.peris.PerisMain.java
/** * Called when the activity is first created. *//*from w ww .j ava2 s . com*/ @SuppressLint("NewApi") @Override public final void onCreate(final Bundle savedInstanceState) { this.application = (PerisApp) getApplication(); this.application.setActive(true); this.backStackId = this.application.getBackStackId(); this.ah = this.application.getAnalyticsHelper(); if (this.application.getSession().getServer().serverIcon == null) { final int optimalIconSize = (int) this.getResources().getDimension(android.R.dimen.app_icon_size); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { new CheckForumIconTask(this.application.getSession(), optimalIconSize) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { new CheckForumIconTask(this.application.getSession(), optimalIconSize).execute(); } } this.serverAddress = this.application.getSession().getServer().serverAddress; final SharedPreferences appPreferences = getSharedPreferences("prefs", 0); this.sidebarOption = appPreferences.getBoolean("show_sidebar", true); this.screenTitle = getString(R.string.app_name); if (getString(R.string.server_location).contentEquals("0")) { this.storagePrefix = this.serverAddress + "_"; this.screenSubtitle = this.serverAddress; } else { this.screenSubtitle = this.screenTitle; } this.serverUserid = this.application.getSession().getServer().serverUserId; final String tagline = this.application.getSession().getServer().serverTagline; final SharedPreferences.Editor editor = appPreferences.edit(); if (tagline.contentEquals("null") || tagline.contentEquals("0")) { final String deviceName = android.os.Build.MODEL; final String appName = getString(R.string.app_name); final String appVersion = getString(R.string.app_version); String appColor = getString(R.string.default_color); if (this.application.getSession().getServer().serverColor.contains("#")) { appColor = this.application.getSession().getServer().serverColor; } final String standardTagline = "[color=" + appColor + "][b]Sent from my " + deviceName + " using " + appName + " v" + appVersion + ".[/b][/color]"; this.application.getSession().getServer().serverTagline = standardTagline; this.application.getSession().updateServer(); } editor.putInt(this.storagePrefix + "just_logged_in", 0); editor.commit(); if (this.serverUserid != null) { final Toast toast = Toast.makeText(PerisMain.this, "TIP: Tap on the key icon to log in to your forum account.", Toast.LENGTH_LONG); toast.show(); } final Intent intent = getIntent(); final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { this.handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { this.handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { this.handleSendMultipleImages(intent); // Handle multiple images being sent } } /*else { // Handle other intents, such as being started from the home screen }*/ this.background = this.application.getSession().getServer().serverColor; ThemeSetter.setTheme(this, this.background); super.onCreate(savedInstanceState); ThemeSetter.setActionBar(this, this.background); this.actionBar = getActionBar(); this.actionBar.setDisplayHomeAsUpEnabled(true); this.actionBar.setHomeButtonEnabled(true); this.actionBar.setTitle(this.screenTitle); this.actionBar.setSubtitle(this.screenSubtitle); //Send app analytics data this.ah.trackScreen(getClass().getSimpleName(), false); this.ah.trackEvent("server connection", "connected", "connected", false); //Send tracking data for parsed analytics from peris.json this.serverAddress = this.application.getSession().getServer().analyticsId; if (this.serverAddress != null) { this.ah.trackCustomScreen(this.serverAddress, "Peris Forum Reader v" + getString(R.string.app_version) + " for Android"); } setContentView(R.layout.main_swipe); this.mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); this.flSecondary = (FrameLayout) findViewById(R.id.main_page_frame_right); this.seperator = findViewById(R.id.main_page_seperator); //Setup forum background final String forumWallpaper = this.application.getSession().getServer().serverWallpaper; final String forumBackground = this.application.getSession().getServer().serverBackground; if (forumBackground != null && forumBackground.contains("#") && forumBackground.length() == 7) { this.mDrawerLayout.setBackgroundColor(Color.parseColor(forumBackground)); } else { this.mDrawerLayout.setBackgroundColor(Color.parseColor(getString(R.string.default_background))); } if (forumWallpaper != null && forumWallpaper.contains("http")) { final ImageView mainSwipeImageBackground = (ImageView) findViewById(R.id.main_swipe_image_background); final String imageUrl = forumWallpaper; ImageLoader.getInstance().displayImage(imageUrl, mainSwipeImageBackground); } else { findViewById(R.id.main_swipe_image_background).setVisibility(View.GONE); } this.setupSlidingDrawer(); if (this.application.getStackManager().getBackStackSize(this.backStackId) == 0) { final Bundle bundle = this.initializeNewSession(appPreferences); this.loadCategory(bundle, "NEW_SESSION", false); //application.stackManager.addToBackstack(backStackId, BackStackManager.BackStackItem.BACKSTACK_TYPE_FORUM,bundle); } else { this.recoverBackstack(); } final Bundle parms = getIntent().getExtras(); if (parms != null) { if (parms.containsKey("stealing")) { final Boolean stealing = parms.getBoolean("stealing"); if (stealing) { final String stealingLocation = parms.getString("stealing_location", "0"); final String stealingType = parms.getString("stealing_type", "0"); final boolean locationNumeric = isNumeric(stealingLocation); if (stealingType.contentEquals("forum") && locationNumeric && !stealingLocation.contentEquals("0")) { this.loadTopicItem(Category.builder().id(stealingLocation).name("External Link").build()); } if (stealingType.contentEquals("topic") && locationNumeric && !stealingLocation.contentEquals("0")) { this.loadTopicItem(Topic.builder().id(stealingLocation).title("External Link").build()); } } } } //Juice up gesture listener this.enableGestures(); }
From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java
@Override protected void onStart() { super.onStart(); gridView = (GridView) findViewById(R.id.grid); gridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); gridView.setMultiChoiceModeListener(multiChoiceModeListener); gridView.setOnItemClickListener(itemClickListener); View emptyView = getLayoutInflater().inflate(R.layout.listview_empty, null, false); ((TextView) emptyView.findViewById(R.id.text_list_empty)).setText(R.string.msg_no_downloaded_videos); ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(emptyView, p);//ww w. j a v a2 s .com gridView.setEmptyView(emptyView); requestDataService(new ObjectCallback<KADataService>() { @Override public void call(final KADataService dataService) { ManageDownloadsActivity.this.dataService = dataService; CursorAdapter adapter = new Adapter(ManageDownloadsActivity.this, null, 0, dataService.getThumbnailManager()); gridView.setAdapter(adapter); new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... arg) { return getCursor(); } @Override protected void onPostExecute(Cursor cursor) { ((CursorAdapter) gridView.getAdapter()).changeCursor(cursor); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); final ActionBar ab = getActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ab.setTitle(""); setupListNavigation(); // The receiver performs actions that require a dataService, so register it here. IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_LIBRARY_UPDATE); filter.addAction(ACTION_BADGE_EARNED); filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED); filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE); filter.addAction(ACTION_TOAST); broadcastManager.registerReceiver(receiver, filter); } }); }