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.example.mahendran.moviecritic.DetailFragment.java

private void removeFavorite() {

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

        @Override/*from   ww  w . j  a v a  2 s.  co m*/
        protected Void doInBackground(Void... params) {
            if (isFavorite()) {
                getContext().getContentResolver().delete(MovieContract.MovieEntry.CONTENT_URI,
                        MovieContract.MovieEntry.COLUMN_MOVIE_ID + " = " + mMovie.getId(), null);

            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            Toast.makeText(getActivity(), mMovie.getTitle() + " Removed From Favorite", Toast.LENGTH_LONG)
                    .show();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:it.gulch.linuxday.android.activities.MainActivity.java

@SuppressLint("NewApi")
public void startDownloadSchedule() {
    // Start by displaying indeterminate progress, determinate will come later
    //setSupportProgressBarIndeterminate(true);
    //setSupportProgressBarVisibility(true);

    DownloadScheduleAsyncTask instance = new DownloadScheduleAsyncTask(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        instance.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {/*from w  ww  .  j  a va  2s  . co  m*/
        instance.execute();
    }
}

From source file:org.akop.crosswords.fragment.SubscriptionDetailFragment.java

private void saveAndOpen(PuzzleWrapper wrapper) {
    WriterTask task = new WriterTask(true);
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wrapper);
}

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

public final void onCreate(final Bundle savedInstanceState) {
    this.application = (PerisApp) getApplication();
    this.dbHelper = new PerisDBHelper(this);

    final Bundle bundle = getIntent().getExtras();
    this.subforum = bundle.getString("subforum_id");
    this.postType = Type.valueOf(bundle.getString("post_type"));
    this.parent = bundle.getString("parent");
    this.category = bundle.getString("category");
    this.originalText = bundle.getString("original_text");
    this.picture = bundle.getString("picture");
    this.postId = bundle.getString("postid");
    final String boxTitle = bundle.getString("boxTitle");
    this.theSubject = bundle.getString("subject");

    if (this.postType == Type.Message && this.theSubject.length() > 0) {
        this.theSubject = "Re: " + this.theSubject;
    }/*  w  w w . j  av a2s  .  c  o  m*/

    if (bundle.containsKey("server")) {
        Log.i(TAG, "Mail bundle contains server!");
        final Server server = ServerRepository.findOneByAddress(this.dbHelper.getReadableDatabase(),
                bundle.getString("server"));
        if (server == null) {
            Log.i(TAG, "Conversation Server is null!");
            return;
        }

        this.mailSession = new Session(this, (PerisApp) getApplication(), this.dbHelper);
        this.mailSession.setSessionListener(new Session.SessionListener() {

            @Override
            public void onSessionConnected() {
                return;
            }

            @Override
            public void onSessionConnectionFailed(final String reason) {
                return;
            }

        });
        this.mailSession.setServer(server);
    } else {
        this.mailSession = this.application.getSession();
    }

    this.tagline = this.mailSession.getServer().serverTagline;
    final String accent = this.mailSession.getServer().serverColor;
    ThemeSetter.setTheme(this, accent);
    super.onCreate(savedInstanceState);
    ThemeSetter.setActionBar(this, accent);

    //Track app analytics
    this.ah = ((PerisApp) getApplication()).getAnalyticsHelper();
    this.ah.trackScreen(getClass().getName(), false);
    this.setResult(0);
    setContentView(R.layout.new_post);
    setTitle(boxTitle);

    this.subjectInputter = (EditText) findViewById(R.id.new_post_subject);
    this.bodyInputter = (EditText) findViewById(R.id.new_post_body);
    this.submitter = (Button) findViewById(R.id.new_post_submit);
    this.pictureAttacher = (Button) findViewById(R.id.new_post_picture);
    this.bodyInputter.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        @SuppressWarnings("checkstyle:requirethis")
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                postSubmitted = false;
            }
        }
    });

    if (this.postType == Type.Five) {
        this.pictureAttacher.setVisibility(View.GONE);
    }
    final Button bold = (Button) findViewById(R.id.new_post_bold);
    final Button itialic = (Button) findViewById(R.id.new_post_italic);
    final Button underline = (Button) findViewById(R.id.new_post_underline);
    final Button picker = (Button) findViewById(R.id.new_post_color);

    picker.setTextColor(Color.parseColor(accent));

    this.submitter.setOnClickListener(this.launchSubmit);
    this.pictureAttacher.setOnClickListener(this.submissionOptionsListener);
    bold.setOnClickListener(this.setBold);
    itialic.setOnClickListener(this.setItalic);
    underline.setOnClickListener(this.setUnderline);
    picker.setOnClickListener(this.clickListener);

    if (this.postType != Type.NewThread && this.postType != Type.Message) {
        this.subjectInputter.setVisibility(View.GONE);
        this.subjectInputter.setText(this.theSubject);
    } else if (this.postType == Type.Message) {
        this.subjectInputter.setText(this.theSubject);
        this.bodyInputter.setSelection(0);
    }

    this.originalText = this.originalText.replace("</blockquote>", "[/quote]")
            .replace("<blockquote>", "[quote]").replace("<u>", "[u]").replace("</u>", "[/u]")
            .replace("<i>", "[i]").replace("</i>", "[/i]").replace("<b>", "[b]").replace("</b>", "[/b]")
            .replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&amp;", "&")
            .replace("<br />", "\n");
    this.originalText = this.originalText.replaceAll("\\<font color=\"([^<]*)\"\\>([^<]*)\\</font\\>",
            "[color=$1]$2[/color]");
    this.bodyInputter.setText(this.originalText);

    if (this.postType == Type.Tagline) {
        this.bodyInputter.setText(this.tagline);
    } else if (this.postType == Type.Instapost) {
        this.postType = Type.Reply;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            new PostDataTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            new PostDataTask().execute();
        }
    } else if (this.postType == Type.Reply && this.originalText.length() > 0) {
        this.bodyInputter.setSelection(this.originalText.length() - 1);
    }
}

From source file:com.google.android.gm.ay.java

public static void dC(final String s) {
    if (ay.aZc != null) {
        ay.aZc.cancel(false);/*w  w  w  . j a v  a 2 s .  c o  m*/
    }
    (ay.aZc = new aB(s)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) new Void[0]);
}

From source file:org.thezero.qrfi.SuperAwesomeCardFragment.java

public static void connectAP(Result a) {
    WifiParsedResult wifiResult = (new WifiResultParser()).parse(a);
    if (wifiResult != null) {
        WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        if (wifiManager == null) {
            Toast.makeText(c.getApplicationContext(), c.getString(R.string.error_wifimanager),
                    Toast.LENGTH_LONG).show();
            return;
        }//from   www.  j  av a2 s  .c  o m
        Toast.makeText(c.getApplicationContext(),
                c.getString(R.string.connecting) + wifiResult.getSsid() + "...", Toast.LENGTH_LONG).show();
        new WifiConfigManager(wifiManager).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wifiResult);
    } else {
        Toast.makeText(c.getApplicationContext(), c.getString(R.string.error_wifiqr), Toast.LENGTH_LONG).show();
    }
}

From source file:com.github.sgelb.booket.SearchResultActivity.java

private void processResult(String result) {
    JSONArray items = null;/* w  w  w. java  2s  .  c  om*/
    try {
        JSONObject jsonObject = new JSONObject(result);
        items = jsonObject.getJSONArray("items");
    } catch (JSONException e) {
        noResults.setVisibility(View.VISIBLE);
        return;
    }

    try {

        // iterate over items aka books
        Log.d("R2R", "Items: " + items.length());
        for (int i = 0; i < items.length(); i++) {
            Log.d("R2R", "\nBook " + (i + 1));
            JSONObject item = (JSONObject) items.get(i);
            JSONObject info = item.getJSONObject("volumeInfo");
            Book book = new Book();

            // add authors
            String authors = "";
            if (info.has("authors")) {
                JSONArray jAuthors = info.getJSONArray("authors");
                for (int j = 0; j < jAuthors.length() - 1; j++) {
                    authors += jAuthors.getString(j) + ", ";
                }
                authors += jAuthors.getString(jAuthors.length() - 1);
            } else {
                authors = "n/a";
            }
            book.setAuthors(authors);
            Log.d("R2R", "authors " + book.getAuthors());

            // add title
            if (info.has("title")) {
                book.setTitle(info.getString("title"));
                Log.d("R2R", "title " + book.getTitle());
            }

            // add pageCount
            if (info.has("pageCount")) {
                book.setPageCount(info.getInt("pageCount"));
                Log.d("R2R", "pageCount " + book.getPageCount());
            }

            // add publisher
            if (info.has("publisher")) {
                book.setPublisher(info.getString("publisher"));
                Log.d("R2R", "publisher " + book.getPublisher());
            }

            // add description
            if (info.has("description")) {
                book.setDescription(info.getString("description"));
                Log.d("R2R", "description " + book.getDescription());
            }

            // add isbn
            if (info.has("industryIdentifiers")) {
                JSONArray ids = info.getJSONArray("industryIdentifiers");
                for (int k = 0; k < ids.length(); k++) {
                    JSONObject id = ids.getJSONObject(k);
                    if (id.getString("type").equalsIgnoreCase("ISBN_13")) {
                        book.setIsbn(id.getString("identifier"));
                        break;
                    }
                    if (id.getString("type").equalsIgnoreCase("ISBN_10")) {
                        book.setIsbn(id.getString("identifier"));
                    }
                }
                Log.d("R2R", "isbn " + book.getIsbn());
            }

            // add published date
            if (info.has("publishedDate")) {
                book.setYear(info.getString("publishedDate").substring(0, 4));
                Log.d("R2R", "publishedDate " + book.getYear());
            }

            // add cover thumbnail
            book.setThumbnailBitmap(defaultThumbnail);

            if (info.has("imageLinks")) {
                // get cover url from google
                JSONObject imageLinks = info.getJSONObject("imageLinks");
                if (imageLinks.has("thumbnail")) {
                    book.setThumbnailUrl(imageLinks.getString("thumbnail"));
                }
            } else if (book.getIsbn() != null) {
                // get cover url from amazon
                String amazonCoverUrl = "http://ecx.images-amazon.com/images/P/" + isbn13to10(book.getIsbn())
                        + ".01._SCMZZZZZZZ_.jpg";
                book.setThumbnailUrl(amazonCoverUrl);
            }

            // download cover thumbnail
            if (book.getThumbnailUrl() != null && !book.getThumbnailUrl().isEmpty()) {
                new DownloadThumbNail(book).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                        book.getThumbnailUrl());
                Log.d("R2R", "thumbnail " + book.getThumbnailUrl());
            }

            // add google book id
            if (item.has("id")) {
                book.setGoogleId(item.getString("id"));
            }

            bookList.add(book);

        }
    } catch (Exception e) {
        Log.d("R2R", "Exception: " + e.toString());
        // FIXME: catch exception
    }
}

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

private void loadPosts() {
    //getActivity().getActionBar().setSubtitle("Page " + pageNumber + " of " + totalPages);

    final SharedPreferences appPreferences = this.activity.getSharedPreferences("prefs", 0);

    //Save what page we are on
    final SharedPreferences.Editor editor = appPreferences.edit();
    editor.putInt(this.storagePrefix + "thread_" + this.threadId + "_retained_page", this.pageNumber);
    editor.commit();// w  ww  .j  av  a  2s .com

    this.endCurrentlyRunning();

    this.postsDownloader = new DownloadPostsTask();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        this.postsDownloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        this.postsDownloader.execute();
    }
}

From source file:at.flack.FacebookMainActivity.java

public Bitmap getProfilePicture(String s) {
    try {// w  w  w . jav  a2  s.c o m
        return new ImageDownloader().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, s).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:im.vector.fragments.PeopleFragment.java

/**
 * Get the known contacts list, sort it by presence and give it to adapter
 *///from  w ww  .  j av  a  2  s.c om
private void initKnownContacts() {
    final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            // do not sort anymore the full known participants list
            // as they are not displayed unfiltered
            // it saves a lot of times
            // eg with about 17000 items
            // sort requires about 2 seconds
            // sort a 1000 items subset during a search requires about 75ms
            mKnownContacts.clear();
            mKnownContacts.addAll(new ArrayList<>(VectorUtils.listKnownParticipants(mSession).values()));
            return null;
        }

        @Override
        protected void onPostExecute(Void args) {
            mAdapter.setKnownContacts(mKnownContacts);
        }
    };

    try {
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } catch (final Exception e) {
        Log.e(LOG_TAG, "## initKnownContacts() failed " + e.getMessage());
        asyncTask.cancel(true);

        (new android.os.Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
            @Override
            public void run() {
                initKnownContacts();
            }
        }, 1000);
    }
}