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:org.thoughtcrime.securesms.conversation.ConversationActivity.java

private void handleMuteNotifications() {
    MuteDialog.show(this, until -> {
        recipient.setMuted(until);/*from   www.j  a v a2s.com*/

        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setMuted(recipient, until);

                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    });
}

From source file:com.apptentive.android.sdk.ApptentiveInternal.java

private void asyncFetchAppConfigurationAndInteractions() {
    boolean force = isAppDebuggable;

    // Don't get the app configuration unless no pending fetch AND either forced, or the cache has expired.
    if (isConfigurationFetchPending.compareAndSet(false, true)
            && (force || Configuration.load().hasConfigurationCacheExpired())) {
        AsyncTask<Void, Void, Void> fetchConfigurationTask = new AsyncTask<Void, Void, Void>() {
            // Hold onto the exception from the AsyncTask instance for later handling in UI thread
            private Exception e = null;

            @Override/*  w  ww  .  j ava  2  s .c om*/
            protected Void doInBackground(Void... params) {
                try {
                    fetchAppConfiguration();
                } catch (Exception e) {
                    this.e = e;
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void v) {
                // Update pending state on UI thread after finishing the task
                ApptentiveLog.i("Fetching new Configuration asyncTask finished.");
                isConfigurationFetchPending.set(false);
                if (e != null) {
                    ApptentiveLog.w("Unhandled Exception thrown from fetching configuration asyncTask", e);
                    MetricModule.sendError(e, null, null);
                } else {
                    // Check if need to start another asyncTask to fetch interaction after successfully fetching configuration
                    interactionManager.asyncFetchAndStoreInteractions();
                }
            }
        };

        ApptentiveLog.i("Fetching new Configuration asyncTask scheduled.");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            fetchConfigurationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            fetchConfigurationTask.execute();
        }
    } else {
        ApptentiveLog.v("Using cached Configuration.");
        // If configuration hasn't expire, then check if need to start another asyncTask to fetch interaction
        interactionManager.asyncFetchAndStoreInteractions();
    }
}

From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java

private void handleUnmuteNotifications() {
    recipient.setMuted(0);/*www.ja  v a2s. c  o m*/

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setMuted(recipient, 0);

            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.bt.heliniumstudentapp.ScheduleFragment.java

protected static void parseData(final int transition) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        new ParseData().execute(transition);
    else//from ww w  .j a v a 2s  .  c o  m
        new ParseData().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, transition);
}

From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java

public void openSlide() {

    countTask = new JobCountTask(this, currentAccount, getFilter(), getComparator(), qchanged);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        countTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {//from w  w w.j  av a 2s . c o  m
        countTask.execute();
    }

}

From source file:org.akop.crosswords.view.CrosswordView.java

private void regenerateBitmaps() {
    synchronized (this) {
        if (mAsyncRenderer != null) {
            mAsyncRenderer.cancel(false);
        }//ww w  .j av  a2s  . co  m

        mAsyncRenderer = new BitmapRenderer(mRenderScale);
        mAsyncRenderer.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}

From source file:com.amaze.filemanager.fragments.Main.java

public void loadlist(String path, boolean back, int openMode) {
    if (mActionMode != null) {
        mActionMode.finish();//from  w ww. ja va2  s .  com
    }
    /*if(openMode==-1 && android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches())
    bindDrive(path);
    else */
    if (loadList != null)
        loadList.cancel(true);
    loadList = new LoadList(back, ma.getActivity(), ma, openMode);
    loadList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (path));

}

From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java

private void handleUnblock() {
    int titleRes = R.string.ConversationActivity_unblock_this_contact_question;
    int bodyRes = R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact;

    if (recipient.isGroupRecipient()) {
        titleRes = R.string.ConversationActivity_unblock_this_group_question;
        bodyRes = R.string.ConversationActivity_unblock_this_group_description;
    }/*  w  w  w .j  a  v  a 2s.c o  m*/

    //noinspection CodeBlock2Expr
    new AlertDialog.Builder(this).setTitle(titleRes).setMessage(bodyRes)
            .setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(R.string.ConversationActivity_unblock, (dialog, which) -> {
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setBlocked(recipient,
                                false);

                        ApplicationContext.getInstance(ConversationActivity.this).getJobManager()
                                .add(new MultiDeviceBlockedUpdateJob());

                        return null;
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }).show();
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * Notes list adapter initialization and association to view
 *//* w w w. j  a va 2  s  . c  o  m*/
void initNotesList(Intent intent) {
    Log.d(Constants.TAG, "initNotesList intent: " + intent.getAction());

    progress_wheel.setAlpha(1);
    list.setAlpha(0);

    // Search for a tag
    // A workaround to simplify it's to simulate normal search
    if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getCategories() != null
            && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)) {
        searchTags = intent.getDataString().replace(UrlCompleter.HASHTAG_SCHEME, "");
        goBackOnToggleSearchLabel = true;
    }

    // Searching
    searchQuery = searchQueryInstant;
    searchQueryInstant = null;
    if (searchTags != null || searchQuery != null || Intent.ACTION_SEARCH.equals(intent.getAction())) {

        // Using tags
        if (searchTags != null && intent.getStringExtra(SearchManager.QUERY) == null) {
            searchQuery = searchTags;
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getNotesByTag",
                    searchQuery);
        } else {
            // Get the intent, verify the action and get the query
            if (intent.getStringExtra(SearchManager.QUERY) != null) {
                searchQuery = intent.getStringExtra(SearchManager.QUERY);
                searchTags = null;
            }
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getNotesByPattern",
                    searchQuery);
        }

        toggleSearchLabel(true);

    } else {
        // Check if is launched from a widget with categories
        if ((Constants.ACTION_WIDGET_SHOW_LIST.equals(intent.getAction())
                && intent.hasExtra(Constants.INTENT_WIDGET))
                || !TextUtils.isEmpty(mainActivity.navigationTmp)) {
            String widgetId = intent.hasExtra(Constants.INTENT_WIDGET)
                    ? intent.getExtras().get(Constants.INTENT_WIDGET).toString()
                    : null;
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                mainActivity.navigationTmp = !TextUtils.isEmpty(categoryId) ? categoryId : null;
            }
            intent.removeExtra(Constants.INTENT_WIDGET);
            if (mainActivity.navigationTmp != null) {
                Long categoryId = Long.parseLong(mainActivity.navigationTmp);
                NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                        "getNotesByCategory", categoryId);
            } else {
                NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getAllNotes",
                        true);
            }

        } else {
            NoteLoaderTask.getInstance().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "getAllNotes", true);
        }
    }
}

From source file:com.speed.traquer.app.TraqComplaintTaxi.java

private void PromptCustomDialog() {

    // Create custom dialog object
    final Dialog dialog = new Dialog(TraqComplaintTaxi.this);
    // Include dialog.xml file
    dialog.setContentView(R.layout.activity_submit_social);
    // Set dialog title
    dialog.setTitle("Submit via");

    // set values for custom dialog components - text, image and button
    final TextView twitterText = (TextView) dialog.findViewById(R.id.textTwitterDialog);
    twitterText.setText("Twitter");

    final TextView facebookText = (TextView) dialog.findViewById(R.id.textFacebookDialog);
    facebookText.setText("Facebook");

    final TextView defaultText = (TextView) dialog.findViewById(R.id.textDefaultDialog);
    defaultText.setText("Default");
    defaultText.setTextColor(getResources().getColor(R.color.Orange));

    final TextView smsText = (TextView) dialog.findViewById(R.id.textSMSDialog);
    smsText.setText("SMS");

    final ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog);
    image.setImageResource(R.drawable.icon_twitter);

    final ImageView imageFb = (ImageView) dialog.findViewById(R.id.imageDialogFb);
    imageFb.setImageResource(R.drawable.ic_fb_grey);

    final ImageView imageDefault = (ImageView) dialog.findViewById(R.id.imageDialogDefault);
    imageDefault.setImageResource(R.drawable.icon_traquer_color);
    isDefaultSelected = true;/* w  w w  .j  ava 2s .co m*/

    final ImageView imageSMS = (ImageView) dialog.findViewById(R.id.imageDialogSMS);
    imageSMS.setImageResource(R.drawable.icon_sms);

    dialog.show();

    //Retrieve form info
    taxi_id = inputTaxi.getText().toString().toUpperCase();
    taxi_id = taxi_id.replace(" ", "");
    taxi_comp = actv_comp_taxi.getText().toString();
    taxi_driver = taxiDriver.getText().toString();
    taxi_license = taxiLic.getText().toString();
    loc_frm = actv_from.getText().toString();
    loc_to = actv_to.getText().toString();
    dateBus = editDate.getText().toString();
    timeBus = editTime.getText().toString();
    curr_time = editCurrTime.getText().toString();
    user_name = SaveSharedPreference.getUserName(TraqComplaintTaxi.this);

    //Twitter Button
    final RelativeLayout twitterLogin = (RelativeLayout) dialog.findViewById(R.id.twitterImageButton);
    twitterLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTwitterSelected) {
                image.setImageResource(R.drawable.icon_twitter);
                twitterText.setTextColor(getResources().getColor(R.color.DarkGray));
                isTwitterSelected = false;
            } else {
                loginToTwitter();
                image.setImageResource(R.drawable.icon_twitter_blue);
                twitterText.setTextColor(getResources().getColor(R.color.TwitterBlue));
                isTwitterSelected = true;
            }

        }
    });

    //facebook Button
    final RelativeLayout facebookLogin = (RelativeLayout) dialog.findViewById(R.id.facebookImageButton);
    facebookLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isFacebookSelected) {
                imageFb.setImageResource(R.drawable.ic_fb_grey);
                if (fbUserName != null)
                    facebookText.setText("Facebook");

                facebookText.setTextColor(getResources().getColor(R.color.DarkGray));
                isFacebookSelected = false;
            } else {

                //loginToTwitter();
                // start Facebook Login
                loginToFacebook();
                if (fbUserName != null)
                    facebookText.setText(fbUserName);
                imageFb.setImageResource(R.drawable.ic_fb_blue);
                facebookText.setTextColor(getResources().getColor(R.color.TwitterBlue));
                isFacebookSelected = true;
            }

        }
    });

    //SMS Button
    final RelativeLayout SMSLogin = (RelativeLayout) dialog.findViewById(R.id.smsImageButton);
    SMSLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isSmsSelected) {
                imageSMS.setImageResource(R.drawable.icon_sms);
                smsText.setTextColor(getResources().getColor(R.color.DarkGray));
                isSmsSelected = false;
            } else {
                imageSMS.setImageResource(R.drawable.icon_sms_color);
                smsText.setTextColor(getResources().getColor(R.color.Orange));
                isSmsSelected = true;
            }

        }
    });

    /*/Default Button
    final RelativeLayout defaultLogin = (RelativeLayout)dialog.findViewById(R.id.defaultImageButton);
    defaultLogin.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(isDefaultSelected)
        {
            imageDefault.setImageResource(R.drawable.icon_traquer_color);
            defaultText.setTextColor(getResources().getColor(R.color.Orange));
            isDefaultSelected = false;
        }
        else
        {
            imageDefault.setImageResource(R.drawable.icon_traquer_color);
            defaultText.setTextColor(getResources().getColor(R.color.Orange));
            isDefaultSelected = true;
        }
            
    }
    });*/

    //Submit Button
    Button declineButton = (Button) dialog.findViewById(R.id.submitButton);
    // if decline button is clicked, close the custom dialog
    declineButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //submit complaint
            isSubmitButtonClicked = true;
            if (isNetworkConnected() == true) {
                Toast.makeText(TraqComplaintTaxi.this, "Complaint sent. Thank you for taking action!",
                        Toast.LENGTH_SHORT).show();

                //Combine Strings for Twitter Status

                String status = taxi_id + ", " + taxi_comp + " taxi is speeding with " + speedTaxiExceed
                        + "km/h at " + Double.toString(gLatitude) + "N, " + Double.toString(gLongitude)
                        + "E, " + curr_time + " @aduanSPAD @MyTraquer #Traquer";

                finalStatus = status;

                if (isFacebookSelected) {
                    //share to facebook
                    ShareToFacebook(status);
                    //publishFeedDialog();
                }

                if (isTwitterSelected) {

                    //Toast.makeText(TraqComplaintTaxi.this, Long.toString(twitterID) + userName, Toast.LENGTH_SHORT).show();

                    // Check for blank text
                    if (status.trim().length() > 0) {
                        // update status
                        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR1) {
                            new updateTwitterStatus().execute(status);
                        }

                        else
                            new updateTwitterStatus().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, status);

                    } else {
                        // EditText is empty
                        Toast.makeText(getApplicationContext(), "Please enter status message",
                                Toast.LENGTH_SHORT).show();
                    }

                } else {
                    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR1)
                        new InsertForm().execute();
                    else
                        new InsertForm().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

                }

                // Close dialog
                dialog.dismiss();

            } else {
                if (isSmsSelected) {
                    Log.i("Clicks", "You clicked sent.");

                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.putExtra("address", "15888");
                    sendIntent.putExtra("sms_body",
                            "SPAD Aduan " + taxi_id + ", " + taxi_comp + " taxi is speeding with "
                                    + speedTaxiExceed + "km/h at " + Double.toString(gLatitude) + "N, "
                                    + Double.toString(gLongitude) + "E, " + curr_time + " - Traquer");
                    sendIntent.setType("vnd.android-dir/mms-sms");
                    startActivity(sendIntent);

                    //1800-88-7723
                } else {
                    Toast.makeText(TraqComplaintTaxi.this,
                            "Failed to send. Please check your network connection.", Toast.LENGTH_SHORT).show();
                }
            }

        }

    });
    //TraqComplaintTaxi.this.showDialog(ALERT_DIALOG);
}