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.open.file.manager.IconLoader.java

/**
 * Load icon for current grid element//from ww w  .  jav a 2  s . co m
 * @param holder holder associated to grid view
 * @param position view position in the grid
 */
@SuppressLint("NewApi")
public void loadIcon(Gridviewholder holder, int position) {
    ImageView iv = holder.fileicon;
    String key = holder.associatedfile.getAbsolutePath();
    if (bitmapCache.get(key) == null) {
        if (cancelPotentialWork(holder)) {
            holder.loader = new AsyncImgLoad(mycont, holder, position);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                holder.loader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                holder.loader.execute();
            }
        }
    } else {
        iv.setImageBitmap(bitmapCache.get(key));
    }
}

From source file:eu.power_switch.gui.fragment.RecyclerViewFragment.java

public void updateListContent() {
    showLoadingAnimation();/*www  .  j a v  a2 s  .  co m*/

    new AsyncTask<Context, Void, RecyclerViewUpdateResult>() {

        @Override
        protected RecyclerViewUpdateResult doInBackground(Context... contexts) {
            try {
                return new RecyclerViewUpdateResult(refreshListData());
            } catch (Exception e) {
                return new RecyclerViewUpdateResult(e);
            }
        }

        @Override
        protected void onPostExecute(RecyclerViewUpdateResult result) {
            getRecyclerViewAdapter().notifyDataSetChanged();

            if (result.isSuccess()) {
                if (result.getElements().size() == 0) {
                    showEmpty();
                } else {
                    showList();
                }
            } else {
                showError(result.getException(), Calendar.getInstance().getTimeInMillis());
                StatusMessageHandler.showErrorMessage(getActivity(), result.getException());
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getContext());
}

From source file:com.vadimfrolov.duorem.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create action bar as a toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    setSupportActionBar(toolbar);//from   w w w  .ja v a 2 s.com

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mPrefs.registerOnSharedPreferenceChangeListener(this);

    mViewName = (TextView) findViewById(R.id.id);
    // mViewAddress = (TextView) findViewById(R.id.content);
    mIconAlive = (ImageView) findViewById(R.id.alive);
    mBtnTogglePower = (Button) findViewById(R.id.btn_toggle_power);
    mBtnRestart = (Button) findViewById(R.id.btn_restart);
    mViewStatus = (TextView) findViewById(R.id.text_status);

    mViewStatus.setMovementMethod(new ScrollingMovementMethod());

    Gson gson = new Gson();
    String targetJson = mPrefs.getString(KEY_PREF_TARGET, "");
    if (targetJson.length() > 0) {
        mTarget = gson.fromJson(targetJson, HostBean.class);
    }

    mSshTasks = new Stack<>();
    mDelegate = this;
    mIsConnected = false;

    mBtnRestart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            stopTargetPolling();

            RemoteCommand cmd = new RemoteCommand(mTarget, RemoteCommand.SSH);
            cmd.command = "sudo shutdown -r now";
            mSshTasks.push(new RemoteAsyncTask(mDelegate));
            mSshTasks.peek().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cmd);

            logForUser(getResources().getString(R.string.reboot_sent));
        }
    });
    mBtnTogglePower.setOnClickListener(mPowerActor);

    // create a pool with only 3 threads
    mSch = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(3);
    mSch.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
}

From source file:it.feio.android.omninotes.utils.GeocodeHelper.java

public static void getAddressFromCoordinates(Context mContext, double latitude, double longitude,
        final OnGeoUtilResultListener listener) {
    class AddressResolverTask extends AsyncTask<Double, Void, String> {
        private Context mContext;

        public AddressResolverTask(Context context) {
            this.mContext = context;
        }//from  w w  w  .j av  a 2 s .c o  m

        @Override
        protected String doInBackground(Double... params) {
            String addressString;
            try {
                addressString = GeocodeHelper.getAddressFromCoordinates(this.mContext, params[0], params[1]);
            } catch (IOException ex) {
                addressString = null;
            }
            return addressString;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            listener.onAddressResolved(result);
        }
    }

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

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

private void nextServer() {
    if ((this.currentServer + 1) > this.serverList.size()) {
        return;//from ww  w  . j a v  a 2  s  . c  o m
    }
    Log.d(TAG, "MailService Tick - Checking " + this.serverList.get(this.currentServer).serverAddress);
    this.mailSession.setSessionListener(new Session.SessionListener() {

        @Override
        @SuppressWarnings("checkstyle:requirethis")
        public void onSessionConnected() {
            new CheckMailTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mailSession.getServer());
        }

        @Override
        @SuppressWarnings("checkstyle:requirethis")
        public void onSessionConnectionFailed(final String reason) {
            nextServer();
        }

    });
    this.mailSession.setServer(this.serverList.get(this.currentServer));
    this.currentServer++;
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardSplashActivity.java

private void prepareApp() {
    mPrepareApp = new AsyncTask<Void, Void, Boolean>() {
        @Override/*w  ww .  j a  v  a 2s .c o  m*/
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(500);
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                mPrepareApp = null;

                startActivity(new Intent(WallpaperBoardSplashActivity.this, mMainActivity));
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                finish();
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:joshuatee.wx.SPCCompmapActivity.java

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

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    theme_blue_current = preferences.getString("THEME_BLUE", "");
    setTheme(Utility.Theme(theme_blue_current));
    setContentView(R.layout.activity_spccompmap);

    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, model_params_labels));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.drawer, R.string.drawer_open,
            R.string.drawer_close) {/*from   w  w  w. j  a va 2 s.  c om*/
        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);

    img_url = "http://www.spc.noaa.gov/exper/compmap/basemap.gif";
    new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

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

@Override
public void onResume() {
    super.onResume();
    if (isMenuVisible()) {
        if (recyclerView != null && recyclerView.getAdapter() == null) {
            new ScheduleFetcher(false, true, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {//from  w w  w  .j a  v  a2  s  . com
            new ScheduleFetcher(false, false, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
}

From source file:cn.edu.wyu.documentviewer.RootsCache.java

/**
 * Gather roots from all known storage providers.
 *///from  w  w w  .  j  a v a 2  s .  co m
public void updateAsync() {
    // Special root for recents
    mRecentsRoot.authority = null;
    mRecentsRoot.rootId = null;
    mRecentsRoot.icon = R.drawable.ic_root_recent;
    mRecentsRoot.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE;
    mRecentsRoot.title = mContext.getString(R.string.root_recent);
    mRecentsRoot.availableBytes = -1;

    new UpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}