Example usage for android.os AsyncTask SERIAL_EXECUTOR

List of usage examples for android.os AsyncTask SERIAL_EXECUTOR

Introduction

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

Prototype

Executor SERIAL_EXECUTOR

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

Click Source Link

Document

An Executor that executes tasks one at a time in serial order.

Usage

From source file:com.orbar.pxdemo.MainActivity.java

@Override
public void onSuccessLogin() {

    mMyAccountViewFlipper.setDisplayedChild(1);

    mFiveZeroZeroUsersAPIBuilder = new FiveZeroZeroUsersAPIBuilder();

    mLoadMyAccount = new LoadMyAccount();
    mLoadMyAccount.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, mFiveZeroZeroUsersAPIBuilder);
}

From source file:eu.power_switch.gui.dialog.AddActionDialog.java

private void updateRoomList() {
    setPositiveButtonVisibility(false);//from   w  ww . j  a  v a 2 s  .  co m

    progressRoom.setVisibility(View.VISIBLE);
    spinner_room.setVisibility(View.GONE);

    progressReceiver.setVisibility(View.VISIBLE);
    spinner_receiver.setVisibility(View.GONE);

    progressButton.setVisibility(View.VISIBLE);
    spinner_button.setVisibility(View.GONE);

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                roomNames.clear();

                for (Room room : currentApartment.getRooms()) {
                    roomNames.add(room.getName());
                }
            } catch (Exception e) {
            }

            Collections.sort(roomNames, compareToIgnoreCase);

            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            progressRoom.setVisibility(View.GONE);
            spinner_room.setVisibility(View.VISIBLE);

            spinner_room.setSelection(0);

            roomSpinnerArrayAdapter.notifyDataSetChanged();

            updateReceiverList();
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

From source file:eu.power_switch.gui.dialog.AddActionDialog.java

private void updateReceiverList() {
    setPositiveButtonVisibility(false);//from ww w.  ja v a  2s .  c o m

    progressReceiver.setVisibility(View.VISIBLE);
    spinner_receiver.setVisibility(View.GONE);

    progressButton.setVisibility(View.VISIBLE);
    spinner_button.setVisibility(View.GONE);

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            receiverNames.clear();

            try {
                Room selectedRoom = getSelectedRoom();
                if (selectedRoom != null) {
                    for (Receiver receiver : selectedRoom.getReceivers()) {
                        receiverNames.add(receiver.getName());
                    }
                }
            } catch (NoSuchElementException e) {

            } catch (Exception e) {
            }

            Collections.sort(receiverNames, compareToIgnoreCase);

            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            progressReceiver.setVisibility(View.GONE);
            spinner_receiver.setVisibility(View.VISIBLE);

            spinner_receiver.setSelection(0);
            receiverSpinnerArrayAdapter.notifyDataSetChanged();

            updateButtonList();
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java

/**
 * Merge the tabs of the other Chrome instance into this instance by reading its tab metadata
 * file and tab state files./*  w w  w.  jav a 2 s . com*/
 *
 * This method should be called after a change in activity state indicates that a merge is
 * necessary. #loadState() will take care of merging states on application cold start if needed.
 *
 * If there is currently a merge or load in progress then this method will return early.
 */
public void mergeState() {
    if (mLoadInProgress || mPersistencePolicy.isMergeInProgress() || !mTabsToRestore.isEmpty()) {
        Log.e(TAG, "Tab load still in progress when merge was attempted.");
        return;
    }

    // Initialize variables.
    mCancelNormalTabLoads = false;
    mCancelIncognitoTabLoads = false;
    mNormalTabsRestored = new SparseIntArray();
    mIncognitoTabsRestored = new SparseIntArray();

    try {
        long time = SystemClock.uptimeMillis();
        // Read the tab state metadata file.
        DataInputStream stream = startFetchTabListTask(AsyncTask.SERIAL_EXECUTOR,
                mPersistencePolicy.getStateToBeMergedFileName()).get();

        // Return early if the stream is null, which indicates there isn't a second instance
        // to merge.
        if (stream == null)
            return;
        logExecutionTime("MergeStateInternalFetchTime", time);
        mPersistencePolicy.setMergeInProgress(true);
        readSavedStateFile(stream, createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(), true),
                null, true);
        logExecutionTime("MergeStateInternalTime", time);
    } catch (Exception e) {
        // Catch generic exception to prevent a corrupted state from crashing app.
        Log.d(TAG, "meregeState exception: " + e.toString(), e);
    }

    // Restore the tabs from the second activity asynchronously.
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            mMergeTabCount = mTabsToRestore.size();
            mRestoreMergedTabsStartTime = SystemClock.uptimeMillis();
            restoreTabs(false);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:eu.power_switch.gui.dialog.AddActionDialog.java

private void updateButtonList() {
    setPositiveButtonVisibility(false);/*  www .j  a  v a2s .c o m*/

    progressButton.setVisibility(View.VISIBLE);
    spinner_button.setVisibility(View.GONE);

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            buttonNames.clear();

            if (Action.ACTION_TYPE_RECEIVER.equals(currentActionType)) {
                updateReceiverButtonList();
            } else if (Action.ACTION_TYPE_ROOM.equals(currentActionType)) {
                updateRoomButtonsList();
            }

            Collections.sort(buttonNames, compareToIgnoreCase);

            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            progressButton.setVisibility(View.GONE);
            spinner_button.setVisibility(View.VISIBLE);

            spinner_button.setSelection(0);

            buttonSpinnerArrayAdapter.notifyDataSetChanged();

            updatePositiveButton();
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * Executes the {@link android.os.AsyncTask} on the {@link android.os.AsyncTask#SERIAL_EXECUTOR},
 * e.g. one after another.//from ww  w  .ja  va 2 s.c o  m
 *
 * <p> This is useful for executing non-blocking operations (e.g. NO network activity, etc.).
 */
@SafeVarargs
public static <T> AsyncTask executeInOrder(AsyncTask<T, ?, ?> task, T... args) {
    return task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, args);
}

From source file:org.brandroid.openmanager.util.EventHandler.java

private static Executor getExecutor() {
    if (ENABLE_MULTITHREADS)
        return AsyncTask.THREAD_POOL_EXECUTOR;
    else//from w w w .j av a2  s  .  c o  m
        return AsyncTask.SERIAL_EXECUTOR;
}

From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java

/**
 * Deletes all files in the tab state directory.  This will delete all files and not just those
 * owned by this TabPersistentStore./*from   www.  j a  va 2  s.c  o m*/
 */
public void clearState() {
    mPersistencePolicy.cancelCleanupInProgress();

    AsyncTask.SERIAL_EXECUTOR.execute(new Runnable() {
        @Override
        public void run() {
            File[] baseStateFiles = getOrCreateBaseStateDirectory().listFiles();
            if (baseStateFiles == null)
                return;
            for (File baseStateFile : baseStateFiles) {
                // In legacy scenarios (prior to migration, state files could reside in the
                // root state directory.  So, handle deleting direct child files as well as
                // those that reside in sub directories.
                if (!baseStateFile.isDirectory()) {
                    if (!baseStateFile.delete()) {
                        Log.e(TAG, "Failed to delete file: " + baseStateFile);
                    }
                } else {
                    File[] files = baseStateFile.listFiles();
                    if (files == null)
                        continue;
                    for (File file : files) {
                        if (!file.delete())
                            Log.e(TAG, "Failed to delete file: " + file);
                    }
                }
            }
        }
    });

    onStateLoaded();
}

From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java

private void previewCapturedImage() {
    try {//from   w  ww. j a  va 2s .com
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ChnagedUri);
        if (bitmap != null) {
            ExifInterface ei = null;
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    InputStream in = getContentResolver().openInputStream(ChnagedUri);
                    ei = new ExifInterface(in);
                } else {
                    ei = new ExifInterface(ChnagedUri.getPath());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (ei != null) {
                int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_UNDEFINED);
                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = rotateImage(bitmap, 270);
                    break;
                }
            }

            Bitmap imageBitmap;
            imageBitmap = Bitmap.createScaledBitmap(AppUtils.resizeAndCropCenter(bitmap, 250, true), 250, 250,
                    false);
            img_profile_square.setImageBitmap(imageBitmap);

            imagebaseProfilephoto = Generic.convertBitmapToByteStrem(imageBitmap);
            task = new ActivityProfile.UpdateProfilePhotoTask();
            task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
        }
    } catch (IOException e) {
        e.printStackTrace();
        //Set default image here
    }
}

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

private void fetchPhotoAsync(final RecipientEntry entry, final Uri photoThumbnailUri) {
    final AsyncTask<Void, Void, Void> photoLoadTask = new AsyncTask<Void, Void, Void>() {
        @Override//  w  w  w.j a v  a 2  s . c  om
        protected Void doInBackground(Void... params) {
            final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null,
                    null, null);
            if (photoCursor != null) {
                try {
                    if (photoCursor.moveToFirst()) {
                        final byte[] photoBytes = photoCursor.getBlob(PhotoQuery.PHOTO);
                        entry.setPhotoBytes(photoBytes);

                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                mPhotoCacheMap.put(photoThumbnailUri, photoBytes);
                                notifyDataSetChanged();
                            }
                        });
                    }
                } finally {
                    photoCursor.close();
                }
            }
            return null;
        }
    };
    photoLoadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}