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:it.feio.android.omninotes.utils.GeocodeHelper.java

public static void getCoordinatesFromAddress(Context mContext, String address,
        final OnGeoUtilResultListener listener) {
    class CoordinatesResolverTask extends AsyncTask<String, Void, double[]> {
        private Context mContext;

        public CoordinatesResolverTask(Context context) {
            this.mContext = context;
        }// w  ww.  java  2s  .c o m

        @Override
        protected double[] doInBackground(String... params) {
            double[] coords;
            try {
                coords = GeocodeHelper.getCoordinatesFromAddress(mContext, params[0]);
            } catch (IOException ex) {
                coords = null;
            }
            return coords;
        }

        @Override
        protected void onPostExecute(double[] coords) {
            super.onPostExecute(coords);
            listener.onCoordinatesResolved(coords);
        }
    }

    CoordinatesResolverTask task = new CoordinatesResolverTask(mContext);
    if (Build.VERSION.SDK_INT >= 11) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, address);
    } else {
        task.execute(address);
    }
}

From source file:com.prey.activities.InitActivity.java

public void onboardingInit() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        new OnboardingInitTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    else/*from w  w  w.j a  v  a  2 s  .  co  m*/
        new OnboardingInitTask().execute();
}

From source file:com.tlongdev.bktf.presenter.fragment.RecentsPresenter.java

public void loadCurrencyPrices() {
    LoadCurrencyPricesInteractor interactor = new LoadCurrencyPricesInteractor(mApplication, this);
    interactor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:app.com.timbuktu.fragment.ColorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_collectionview, container, false);
    Bundle bdl = getArguments();//from  w w w . j  a  va2s  .  co m

    mFragmentLayout = (FrameLayout) v.findViewById(R.id.fragment_layout);

    LayerDrawable bgDrawable = (LayerDrawable) mFragmentLayout.getBackground();
    GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(bdl.getInt(EXTRA_COLOR));

    TextView tv = (TextView) v.findViewById(R.id.header);
    Collection collection = bdl.getParcelable(EXTRA_COLLECTION);
    tv.setText("Position - " + bdl.getInt(EXTRA_POS));

    if (collection != null) {
        tv.setText("Position - " + bdl.getInt(EXTRA_POS) + " # of Pics :" + collection.size());

        ImageView imgView = (ImageView) v.findViewById(R.id.collage);
        mTask = new CollageWorkerTask(imgView, collection);
        mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    return v;
}

From source file:ch.carteggio.ui.ConversationIconLoader.java

/**
 * Load a conversation picture and display it using the supplied {@link ImageView} instance.
 *
 * <p>//from w ww.  j a  va2s.  c  om
 * If a picture is found in the cache, it is displayed in the {@code ImageView}
 * immediately. Otherwise a {@link ConversationPictureRetrievalTask} is started to try to load the
 * conversation picture in a background thread. Depending on the result the contact picture, the group
 * picture or a fallback picture is then stored in the bitmap cache.
 * </p>
 *
 * @param conversationId
 *         The id of the conversation for which we need to find the image.
 * @param image
 *         The {@code ImageView} instance to receive the picture.
 *
 * @see #mBitmapCache
 * @see #calculateFallbackBitmap(Address)
 */
public void loadConversationPicture(long conversationId, ImageView image) {
    Bitmap bitmap = getBitmapFromCache(conversationId);
    if (bitmap != null) {
        // The picture was found in the bitmap cache
        image.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(conversationId, image)) {
        ConversationPictureRetrievalTask task = new ConversationPictureRetrievalTask(image, conversationId);
        AsyncDrawable asyncDrawable = new AsyncDrawable(mResources,
                calculateFallbackBitmap(new String[] { "none" }), task);
        image.setImageDrawable(asyncDrawable);
        try {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } catch (RejectedExecutionException e) {
            // We flooded the thread pool queue... use a fallback picture
            image.setImageBitmap(calculateFallbackBitmap(new String[] { "none" }));
        }
    }
}

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

/**
 * Sets the state of a single LED//from  w  w w. j  av  a 2  s  . c om
 * @param device The target weave device
 * @param ledIndex The index of the LED to adjust
 * @param lightState Whether the LED should be "on" or not.
 */
public void setDeviceLightState(final WeaveDevice device, final int ledIndex, final boolean lightState) {
    // Listview is 0-based, Led index in the brillo app is 1-based.
    final int normalizedLedIndex = ledIndex + 1;

    // Network call, punt off the main thread.
    new AsyncTask<Void, Void, Response<CommandResult>>() {

        @Override
        protected Response<CommandResult> doInBackground(Void... params) {
            Command command = getSetLightStateCommand(normalizedLedIndex, lightState);

            return Weave.COMMAND_API.execute(mApiClient, device.getId(), command);
        }

        @Override
        protected void onPostExecute(Response<CommandResult> result) {
            super.onPostExecute(result);
            if (result != null) {
                if (!result.isSuccess() || result.getError() != null) {
                    Log.e(TAG, "Failure setting light state: " + result.getError());
                    Snackbar.make(LedSwitchesFragment.this.getView(), R.string.error_setting_state,
                            Snackbar.LENGTH_LONG).show();
                } else {
                    Log.i(TAG, "Success setting light state!");
                }
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:sintef.android.gravity.AlarmService.java

public synchronized void onEvent(EventTypes type) {
    switch (type) {
    case FALL_DETECTED:
        if (!mTimerState.equals(TimerState.PENDING))
            return;
        EventBus.getDefault().post(EventTypes.START_ALARM);

        mTimerState = TimerState.RUNNING;

        Intent start_app_intent = new Intent(this, MainActivity.class);
        start_app_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        start_app_intent.putExtra(ALARM_STARTED, true);
        startActivity(start_app_intent);

        PendingIntent start_app_pending_intent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);

        mNotificationBuilder.setContentTitle(getString(R.string.phone_notification_waiting));
        // mNotificationBuilder.addAction(android.R.drawable.presence_busy, "Cancel", stopIntent);
        mNotificationBuilder.setContentIntent(start_app_pending_intent);
        mNotificationManager.notify(R.string.app_name, mNotificationBuilder.build());

        mAlarmTask = getAlarmTask();//from  w  w w  . jav a  2  s .  com
        mAlarmTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        break;
    case ALARM_STOPPED:
    case STOP_ALARM:
        if (mAlarmTask != null) {
            mAlarmTask.cancel(true);
        }
        break;

    }
}

From source file:fm.krui.kruifm.KRUIScheduleActivity.java

/**
 * Downloads JSON-based show data from KRUI's servers, caches it, and parses it into Show objects to be displayed.
 * Filenames of each cache file are stored as member constants
 * Categories are represented as integers which determine event coloring for all shows pulled from this text file.
 *                 1 - Regular Rotation/*from   w  w w  .  ja va  2  s. c om*/
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Special Programming
 */
private void downloadShowData() {

    // Download all 5 text files, each one stores data from one category of show.
    String[] urls = { ROOT_URL + MAIN_SCHEDULE_RR_URL, ROOT_URL + MAIN_SCHEDULE_MS_URL,
            ROOT_URL + MAIN_SCHEDULE_S_URL, ROOT_URL + MAIN_SCHEDULE_NT_URL, ROOT_URL + MAIN_SCHEDULE_SP_URL };

    // Store each text file onto internal storage to avoid having to download information every time this activity is called.
    String[] filenames = { MAIN_SCHEDULE_RR_FILENAME, MAIN_SCHEDULE_MS_FILENAME, MAIN_SCHEDULE_S_FILENAME,
            MAIN_SCHEDULE_NT_FILENAME, MAIN_SCHEDULE_SP_FILENAME };

    // Execute process
    Log.v(TAG, "About to launch TextFetcher to grab JSON files");
    try {
        TextFetcher tf = new TextFetcher(this, urls, filenames, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            tf.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        } else {
            tf.execute((Void[]) null);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:eu.musesproject.client.connectionmanager.ConnectionManager.java

/**
 * Starts to poll with the server either in sleep/active mode
 * @return void/*  ww  w. j a v  a 2  s  .  c o m*/
 */

public void poll() {
    //Log.d(APP_TAG, "Polling !!");
    if (NetworkChecker.isInternetConnected) {
        if (PhoneModeReceiver.SLEEP_MODE_ACTIVE) {
            HttpClientAsyncThread httpClientAsyncThread = new HttpClientAsyncThread();
            httpClientAsyncThread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, POLL, URL,
                    Integer.toString(AlarmReceiver.DEFAULT_SLEEP_POLL_INTERVAL), "");
        } else {
            HttpClientAsyncThread httpClientAsyncThread = new HttpClientAsyncThread();
            httpClientAsyncThread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, POLL, URL,
                    Integer.toString(AlarmReceiver.DEFAULT_POLL_INTERVAL), "");
        }
    }
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarSplashActivity.java

private void checkRszIo() {
    mCheckRszIo = new AsyncTask<Void, Void, Boolean>() {

        final String rszio = "https://rsz.io/";

        @Override/*from  w w  w. ja va2s .  c  om*/
        protected Boolean doInBackground(Void... voids) {
            while ((!isCancelled())) {
                try {
                    Thread.sleep(1);
                    URL url = new URL(rszio);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setReadTimeout(6000);
                    connection.setConnectTimeout(6000);
                    int code = connection.getResponseCode();
                    return code == 200;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            CandyBarMainActivity.sRszIoAvailable = aBoolean;
            LogUtil.e("rsz.io availability: " + CandyBarMainActivity.sRszIoAvailable);
            mCheckRszIo = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}