Example usage for android.os AsyncTask THREAD_POOL_EXECUTOR

List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR

Introduction

In this page you can find the example usage for android.os AsyncTask THREAD_POOL_EXECUTOR.

Prototype

Executor THREAD_POOL_EXECUTOR

To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.

Click Source Link

Document

An Executor that can be used to execute tasks in parallel.

Usage

From source file:com.kasungunathilaka.sarigama.util.PlayerQueue.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11
public static <T> void executeAsyncTask(AsyncTask<T, ?, ?> asyncTask, T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    else//  www . j  a  v  a 2 s . c  o m
        asyncTask.execute(params);
}

From source file:com.rastating.droidbeard.net.SickbeardAsyncTask.java

public void start(Params... args) {
    this.start(AsyncTask.THREAD_POOL_EXECUTOR, args);
}

From source file:eu.power_switch.gui.fragment.configure_geofence.ConfigureGeofenceDialogPage1LocationFragment.java

@Nullable
@Override/* ww w .ja  va2 s .  co  m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_geofence_page_1, container, false);

    MapView mapView = (MapView) rootView.findViewById(R.id.mapView);
    mapViewHandler = new MapViewHandler(getContext(), mapView, savedInstanceState);
    mapViewHandler.addOnMapReadyListener(this);
    mapViewHandler.initMapAsync();

    searchAddressProgress = (ProgressBar) rootView.findViewById(R.id.searchAddressProgress);
    searchAddressTextInputLayout = (TextInputLayout) rootView.findViewById(R.id.searchAddressTextInputLayout);
    searchAddressEditText = (EditText) rootView.findViewById(R.id.searchAddressEditText);

    searchAddressButton = (ImageButton) rootView.findViewById(R.id.searchAddressImageButton);
    searchAddressButton.setImageDrawable(IconicsHelper.getSearchIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    searchAddressButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideSoftwareKeyboard(getView());

            searchAddressEditText.setEnabled(false);
            searchAddressProgress.setVisibility(View.VISIBLE);
            new AsyncTask<String, Void, AsyncTaskResult<LatLng>>() {
                @Override
                protected AsyncTaskResult<LatLng> doInBackground(String... params) {
                    try {
                        LatLng location = mapViewHandler.findCoordinates(params[0]);
                        return new AsyncTaskResult<>(location);
                    } catch (Exception e) {
                        return new AsyncTaskResult<>(e);
                    }
                }

                @Override
                protected void onPostExecute(AsyncTaskResult<LatLng> result) {
                    if (result.isSuccess()) {
                        searchAddressTextInputLayout.setError(null);
                        searchAddressTextInputLayout.setErrorEnabled(false);

                        if (geofenceView == null) {
                            geofenceView = mapViewHandler.addGeofence(result.getResult().get(0),
                                    currentGeofenceRadius);
                        } else {
                            geofenceView.setCenter(result.getResult().get(0));
                            geofenceView.setRadius(currentGeofenceRadius);
                        }

                        cameraChangedBySystem = true;
                        mapViewHandler.moveCamera(result.getResult().get(0), 14, true);
                    } else {
                        if (result.getException() instanceof CoordinatesNotFoundException) {
                            searchAddressTextInputLayout.setErrorEnabled(true);
                            searchAddressTextInputLayout.setError(getString(R.string.address_not_found));
                        } else {
                            searchAddressTextInputLayout.setErrorEnabled(true);
                            searchAddressTextInputLayout.setError(getString(R.string.unknown_error));
                        }
                    }

                    searchAddressEditText.setEnabled(true);
                    searchAddressProgress.setVisibility(View.GONE);
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, searchAddressEditText.getText().toString());
        }
    });

    geofenceRadiusEditText = (EditText) rootView.findViewById(R.id.geofenceRadiusEditText);
    geofenceRadiusEditText.setText(String.valueOf((int) currentGeofenceRadius));
    geofenceRadiusEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                int radius = Integer.valueOf(s.toString());

                updateGeofenceRadius(radius);
                if (radius != geofenceRadiusSeekbar.getProgress()) {
                    if (radius <= geofenceRadiusSeekbar.getMax()) {
                        geofenceRadiusSeekbar.setProgress(radius);
                    }
                }

                cameraChangedBySystem = true;
                mapViewHandler.moveCamera(getCurrentLocation(), false);
            }
        }
    });

    geofenceRadiusSeekbar = (SeekBar) rootView.findViewById(R.id.geofenceRadiusSeekbar);
    geofenceRadiusSeekbar.setMax(2000);
    geofenceRadiusSeekbar.setProgress((int) currentGeofenceRadius);
    geofenceRadiusSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateGeofenceRadius(progress);
            if (geofenceRadiusEditText.getText().length() > 0
                    && Integer.valueOf(geofenceRadiusEditText.getText().toString()) != progress) {
                geofenceRadiusEditText.setText(String.valueOf(seekBar.getProgress()));
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            updateGeofenceRadius(seekBar.getProgress());
            if (geofenceRadiusEditText.getText().length() > 0
                    && Integer.valueOf(geofenceRadiusEditText.getText().toString()) != seekBar.getProgress()) {
                geofenceRadiusEditText.setText(String.valueOf(seekBar.getProgress()));
            }
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            updateGeofenceRadius(seekBar.getProgress());
            if (geofenceRadiusEditText.getText().length() > 0
                    && Integer.valueOf(geofenceRadiusEditText.getText().toString()) != seekBar.getProgress()) {
                geofenceRadiusEditText.setText(String.valueOf(seekBar.getProgress()));
            }

            cameraChangedBySystem = true;
            mapViewHandler.moveCamera(getCurrentLocation(), false);
        }
    });

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureGeofenceDialog.GEOFENCE_ID_KEY)) {
        geofenceId = args.getLong(ConfigureGeofenceDialog.GEOFENCE_ID_KEY);
    }

    initializeData();

    return rootView;
}

From source file:com.giovanniterlingen.windesheim.view.Fragments.ChooseScheduleFragment.java

private void alertConnectionProblem() {
    if (!getUserVisibleHint()) {
        return;/*from  w w w  . java  2  s  . c om*/
    }
    ApplicationLoader.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            new AlertDialog.Builder(context).setTitle(getResources().getString(R.string.alert_connection_title))
                    .setMessage(getResources().getString(R.string.alert_connection_description))
                    .setPositiveButton(getResources().getString(R.string.connect),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    if (componentFetcher != null) {
                                        if (componentFetcher.getStatus() == AsyncTask.Status.RUNNING
                                                || componentFetcher.getStatus() == AsyncTask.Status.PENDING) {
                                            componentFetcher.cancel(true);
                                        }
                                    }
                                    (componentFetcher = new ComponentFetcher())
                                            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                    dialog.cancel();
                                }
                            })
                    .setNegativeButton(getResources().getString(R.string.cancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            })
                    .show();
        }
    });
}

From source file:de.enlightened.peris.SocialFragment.java

private void loadStatuses() {
    this.socialLoader = new DownloadStatusesTask();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        this.socialLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {/*from   w  w w . ja  v a2s. c o m*/
        this.socialLoader.execute();
    }

}

From source file:de.enlightened.peris.MessageActivity.java

@SuppressLint("NewApi")
private void deleteMessage() {
    final TaskListener<ApiResult> listener = new TaskListener<ApiResult>() {
        @Override/*from w ww.j  a  va 2 s. c om*/
        public void onPostExecute(final ApiResult result) {
            MessageActivity.this.finish();
        }
    };

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        new DeleteMessageTask(MessageActivity.this.application.getSession().getApi(),
                MessageActivity.this.messageId, MessageActivity.this.folderId, listener)
                        .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        new DeleteMessageTask(MessageActivity.this.application.getSession().getApi(),
                MessageActivity.this.messageId, MessageActivity.this.folderId, listener).execute();
    }
}

From source file:joshuatee.wx.ModelInterfaceActivity.java

@Override
public void onClick(View v2) {
    switch (v2.getId()) {

    case R.id.button_back:
        time_tmp = spinner2.getSelectedItemPosition();
        time_tmp--;/*from  w  ww  .j  av a  2  s .  c o  m*/
        if (time_tmp == -1) {
            time_tmp = list_time.size() - 1;
        }

        spinner2.setSelection(time_tmp);
        new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        break;
    case R.id.button_forward:
        time_tmp = spinner2.getSelectedItemPosition();
        time_tmp++;
        if (time_tmp == list_time.size()) {
            time_tmp = 0;
        }
        spinner2.setSelection(time_tmp);
        new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        break;
    case R.id.button_animate:
        new GetAnimate().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        break;
    case R.id.tv:
        Intent i_rid = new Intent(this, CODSoundingRidSelectActivity.class);
        startActivity(i_rid);
        break;
    case R.id.iv:
        String cod_souding_nws = preferences3.getString("COD_SOUNDING_NWS", "DTX");
        String nws_x = preferences3.getString("NWS_" + cod_souding_nws + "_X", "");
        String nws_y = preferences3.getString("NWS_" + cod_souding_nws + "_Y", "");

        Intent i_iv = new Intent(this, Webscreen.class);
        i_iv.putExtra(Webscreen.URL,
                "http://climate.cod.edu/flanis/model/fsound/index.php?type=" + run.replace("Z", "") + "|"
                        + model + "|US|500|spd|" + time + "|" + nws_x + "," + nws_y + "|false");
        startActivity(i_iv);
        break;

    }
}

From source file:com.securecomcode.voice.ui.ContactsListActivity.java

private void displayContacts() {
    this.showSectionHeaders = !isFavoritesFragment();
    if (!loadContacts) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            new FetchContacts().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {//from   ww w. j a va 2 s  .c o  m
            new FetchContacts().execute();
        }
        loadContacts = true;
    }
    getListView().setDivider(null);
}

From source file:com.google.samples.apps.ledtoggler.LedSwitchesFragment.java

/**
 * Queries the device for its current state, and extracts the data related to the current state
 * of all LEDs on the device.  The "post execute" step populates the UI with the correct number
 * of Led switches, each initialized to the correct state. E.g if the board has 3 LEDs in
 * positions "on, off, on", the UI will have 3 switches set to "on, off, on".
 *//*w  ww .j  av  a2 s  .  co m*/
public void updateLightStates() {
    // Network call, punt off the main thread.
    new AsyncTask<Void, Void, Response<DeviceState>>() {

        @Override
        protected Response<DeviceState> doInBackground(Void... params) {
            return Weave.COMMAND_API.getState(mApiClient, mDevice.getId());
        }

        @Override
        protected void onPostExecute(Response<DeviceState> result) {
            super.onPostExecute(result);
            if (result != null) {
                if (!result.isSuccess() || result.getError() != null) {
                    Log.e(TAG, "Failure querying for state. " + result.getError());
                    Snackbar.make(LedSwitchesFragment.this.getView(), R.string.error_querying_state,
                            Snackbar.LENGTH_LONG).show();
                } else {

                    Map<String, Object> state = (Map<String, Object>) result.getSuccess()
                            .getStateValue("_ledflasher");
                    if (state == null) {
                        Log.i(TAG, "Command definition Doesn't contain led flasher. " + "States are "
                                + result.getSuccess().getStateNames().toString());
                        Snackbar.make(LedSwitchesFragment.this.getView(), R.string.error_unexpected_states,
                                Snackbar.LENGTH_LONG).show();
                    } else {
                        // Convert list of boolean states to Led Objects, use them
                        // to populate a collection of UI switches for the user.
                        ArrayList<Boolean> ledStates = (ArrayList<Boolean>) state.get("_leds");
                        mAdapter.clear();

                        if (ledStates == null) {
                            Log.i(TAG, "LEDs could not be found.");
                            Snackbar.make(LedSwitchesFragment.this.getView(), R.string.error_unexpected_states,
                                    Snackbar.LENGTH_LONG).show();
                        } else {
                            Log.i(TAG, "Success querying device for LEDs! Populating now.");
                            for (Boolean ledState : ledStates) {
                                mAdapter.add(new Led(ledState));
                            }
                        }
                    }
                }
            }
        }

    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:joshuatee.wx.USWarningsWithRadarActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    editor = preferences.edit();//from  www  .  j  av a2s .  c om
    theme_blue_current = preferences.getString("THEME_BLUE", "");
    if (theme_blue_current.contains("white")) {
        highlight_color = Color.BLUE;
        background_color = Color.BLACK;
        highlight_color_str = "blue";
        background_color_str = "black";

    }
    setTheme(Utility.Theme(theme_blue_current));
    setContentView(R.layout.activity_uswarnings_with_radar_v3);

    Resources res = getResources();
    padding = (int) res.getDimension(R.dimen.padding);
    padding_vertical = (int) res.getDimension(R.dimen.padding_vertical);
    text_size = res.getDimension(R.dimen.listitem_text);

    newline = System.getProperty("line.separator");
    space = Pattern.compile(" ");
    semicolon = Pattern.compile(";");

    turl = getIntent().getStringArrayExtra(URL);
    turl_local[0] = turl[0];
    turl_local[1] = turl[1];
    original_filter = turl[0];

    alert_cod_radar_current = preferences.getString("ALERT_COD_RADAR", "");
    debug_status_current = preferences.getString("DEBUG_STATUS", "");

    dynamicview = (LinearLayout) findViewById(R.id.ll);
    lprams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, filter_array));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.drawer, R.string.drawer_open,
            R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

}