List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.facebook.Request.java
static void runCallbacks(final RequestBatch requests, List<Response> responses) { int numRequests = requests.size(); // Compile the list of callbacks to call and then run them either on this thread or via the Handler we received final ArrayList<Pair<Callback, Response>> callbacks = new ArrayList<Pair<Callback, Response>>(); for (int i = 0; i < numRequests; ++i) { Request request = requests.get(i); if (request.callback != null) { callbacks.add(new Pair<Callback, Response>(request.callback, responses.get(i))); }/*from www . ja v a 2s. co m*/ } if (callbacks.size() > 0) { Runnable runnable = new Runnable() { public void run() { for (Pair<Callback, Response> pair : callbacks) { pair.first.onCompleted(pair.second); } List<RequestBatch.Callback> batchCallbacks = requests.getCallbacks(); for (RequestBatch.Callback batchCallback : batchCallbacks) { batchCallback.onBatchCompleted(requests); } } }; Handler callbackHandler = requests.getCallbackHandler(); if (callbackHandler == null) { // Run on this thread. runnable.run(); } else { // Post to the handler. callbackHandler.post(runnable); } } }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeApplicationMessageFromJSON(UUID uuid, JSONArray jsonArray) { ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try {//from w w w . j a va 2 s .co m JSONObject jsonObject = (JSONObject) jsonArray.get(i); String type = (String) jsonObject.get("type"); int key = jsonObject.getInt("key"); int length = jsonObject.getInt("length"); switch (type) { case "uint": case "int": if (length == 1) { pairs.add(new Pair<>(key, (Object) (byte) jsonObject.getInt("value"))); } else if (length == 2) { pairs.add(new Pair<>(key, (Object) (short) jsonObject.getInt("value"))); } else { if (type.equals("uint")) { pairs.add(new Pair<>(key, (Object) (int) (jsonObject.getInt("value") & 0xffffffffL))); } else { pairs.add(new Pair<>(key, (Object) jsonObject.getInt("value"))); } } break; case "string": pairs.add(new Pair<>(key, (Object) jsonObject.getString("value"))); break; case "bytes": byte[] bytes = Base64.decode(jsonObject.getString("value"), Base64.NO_WRAP); pairs.add(new Pair<>(key, (Object) bytes)); break; } } catch (JSONException e) { return null; } } return encodeApplicationMessagePush(ENDPOINT_APPLICATIONMESSAGE, uuid, pairs); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addNextImages(int level, boolean recycle) { if (level < BACKGROUNDS.length) { // Add the background image ImageView iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); // This is being background loaded. Should already be loaded, but if not, wait. while (mBackgrounds[level] == null) { synchronized (mBackgrounds) { if (mBackgrounds[level] == null) { try { mBackgrounds.wait(); } catch (InterruptedException e) { }/*from ww w. j av a 2 s . c om*/ } } } iv.setImageBitmap(mBackgrounds[level]); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } iv.setImageBitmap(mBackgrounds2[level]); mBackgroundLayout.addView(iv, lp); // Add the foreground image if (FOREGROUNDS[level] == -1) { View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10); mForegroundLayout.addView(view, lp); } else { iv = new ImageView(this); iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); if (recycle) { iv.setTag(level); } lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT); mForegroundLayout.addView(iv, lp); iv = new ImageView(this); if (recycle) { iv.setTag(level); } iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); mForegroundLayout.addView(iv, lp); } } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addNextTransitionImages(int level) { mTransitionImagesCount = 0;//from w ww . ja v a 2 s.c o m if ((level > 0) && ((level - 1) < EXIT_TRANSITIONS.length)) { if (EXIT_TRANSITIONS[level - 1] != -1) { // Add the exit transition image ImageView iv = new ImageView(this); iv.setTag(new Pair<Integer, Integer>(1, (level - 1))); // This is being background loaded. Should already be loaded, but if not, wait. while (mExitTransitions[level - 1] == null) { synchronized (mExitTransitions) { if (mExitTransitions[level - 1] == null) { try { mExitTransitions.wait(); } catch (InterruptedException e) { continue; } } } } iv.setImageBitmap(mExitTransitions[level - 1]); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); // No foreground on transistions. Transition images are a single screen long View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth, 10); mForegroundLayout.addView(view, lp); mTransitionImagesCount++; } } if ((level > 0) && (level < ENTRY_TRANSITIONS.length)) { if (ENTRY_TRANSITIONS[level] != -1) { // Add the exit transition image ImageView iv = new ImageView(this); iv.setTag(new Pair<Integer, Integer>(2, level)); // This is being background loaded. Should already be loaded, but if not, wait. while (mEntryTransitions[level] == null) { synchronized (mEntryTransitions) { if (mEntryTransitions[level] == null) { try { mEntryTransitions.wait(); } catch (InterruptedException e) { continue; } } } } iv.setImageBitmap(mEntryTransitions[level]); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); // No foreground on transistions. Transition images are a single screen long View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth, 10); mForegroundLayout.addView(view, lp); mTransitionImagesCount++; } } }
From source file:io.requery.android.database.sqlite.SQLiteDatabase.java
/** * Returns list of full pathnames of all attached databases including the main database * by executing 'pragma database_list' on the database. * * @return ArrayList of pairs of (database name, database file path) or null if the database * is not open./*from ww w.ja v a2s. co m*/ */ public List<Pair<String, String>> getAttachedDbs() { ArrayList<Pair<String, String>> attachedDbs = new ArrayList<>(); synchronized (mLock) { if (mConnectionPoolLocked == null) { return null; // not open } acquireReference(); } try { // has attached databases. query sqlite to get the list of attached databases. Cursor c = null; try { c = rawQuery("pragma database_list;", null); while (c.moveToNext()) { // sqlite returns a row for each database in the returned list of databases. // in each row, // 1st column is the database name such as main, or the database // name specified on the "ATTACH" command // 2nd column is the database file path. attachedDbs.add(new Pair<>(c.getString(1), c.getString(2))); } } finally { if (c != null) { c.close(); } } return attachedDbs; } finally { releaseReference(); } }
From source file:com.ruesga.rview.fragments.ChangeDetailsFragment.java
private void performRemoveReviewerVote(AccountInfo account, Object tag) { if (!isLocked()) { mRemoveReviewerVoteLoader.clear(); mRemoveReviewerVoteLoader.restart(new Pair<>((String) tag, account)); }/*from w w w. j a v a 2 s . c om*/ }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private Pair<String, Optional<Slide>> getSplitMessage(String rawText, int maxPrimaryMessageSize) { String bodyText = rawText;//from ww w .jav a2s. com Optional<Slide> textSlide = Optional.absent(); if (bodyText.length() > maxPrimaryMessageSize) { bodyText = rawText.substring(0, maxPrimaryMessageSize); byte[] textData = rawText.getBytes(); String timestamp = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US).format(new Date()); String filename = String.format("signal-%s.txt", timestamp); Uri textUri = BlobProvider.getInstance().forData(textData).withMimeType(MediaUtil.LONG_TEXT) .withFileName(filename).createForSingleSessionInMemory(); textSlide = Optional.of(new TextSlide(this, textUri, filename, textData.length)); } return new Pair<>(bodyText, textSlide); }
From source file:io.requery.android.database.sqlite.SQLiteDatabase.java
/** * Runs 'pragma integrity_check' on the given database (and all the attached databases) * and returns true if the given database (and all its attached databases) pass integrity_check, * false otherwise./* www.ja va2 s .c om*/ *<p> * If the result is false, then this method logs the errors reported by the integrity_check * command execution. *<p> * Note that 'pragma integrity_check' on a database can take a long time. * * @return true if the given database (and all its attached databases) pass integrity_check, * false otherwise. */ public boolean isDatabaseIntegrityOk() { acquireReference(); try { List<Pair<String, String>> attachedDbs; try { attachedDbs = getAttachedDbs(); if (attachedDbs == null) { throw new IllegalStateException("databaselist for: " + getPath() + " couldn't " + "be retrieved. probably because the database is closed"); } } catch (SQLiteException e) { // can't get attachedDb list. do integrity check on the main database attachedDbs = new ArrayList<>(); attachedDbs.add(new Pair<>("main", getPath())); } for (Pair<String, String> p : attachedDbs) { SQLiteStatement prog = null; try { prog = compileStatement("PRAGMA " + p.first + ".integrity_check(1);"); String rslt = prog.simpleQueryForString(); if (!rslt.equalsIgnoreCase("ok")) { // integrity_checker failed on main or attached databases Log.e(TAG, "PRAGMA integrity_check on " + p.second + " returned: " + rslt); return false; } } finally { if (prog != null) prog.close(); } } } finally { releaseReference(); } return true; }