List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.facebook.GraphRequest.java
static void runCallbacks(final GraphRequestBatch requests, List<GraphResponse> 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, GraphResponse>> callbacks = new ArrayList<Pair<Callback, GraphResponse>>(); for (int i = 0; i < numRequests; ++i) { GraphRequest request = requests.get(i); if (request.callback != null) { callbacks.add(new Pair<Callback, GraphResponse>(request.callback, responses.get(i))); }//from w w w . j a va 2 s. co m } if (callbacks.size() > 0) { Runnable runnable = new Runnable() { public void run() { for (Pair<Callback, GraphResponse> pair : callbacks) { pair.first.onCompleted(pair.second); } List<GraphRequestBatch.Callback> batchCallbacks = requests.getCallbacks(); for (GraphRequestBatch.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:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void deleteUserParameterWithSystemPropertiesIntId( final EnumSet<MobileServiceSystemProperty> systemProperties) throws Throwable { final String tableName = "MyTableName"; final String responseContent = "{\"id\":5,\"String\":\"Hey\"}"; final JsonObject obj = new JsonParser().parse("{\"id\":5,\"String\":\"what\"}").getAsJsonObject(); MobileServiceClient client = null;//w w w . j av a 2 s.co m try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { e.printStackTrace(); } // Add a filter to handle the request and create a new json // object with an id defined client = client.withFilter(getTestFilter(responseContent)); client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { assertTrue(request.getUrl().contains("__systemproperties=unknown")); return nextServiceFilterCallback.onNext(request); } }); // Create get the MobileService table MobileServiceJsonTable msTable = client.getTable(tableName); msTable.setSystemProperties(systemProperties); List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>(); parameters.add(new Pair<String, String>("__systemproperties", "unknown")); try { // Call the delete method msTable.delete(obj, parameters).get(); } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:ti.modules.titanium.ui.widget.abslistview.TiAbsListView.java
protected Pair<AbsListSectionProxy, Pair<Integer, Integer>> getSectionInfoByEntryIndex(int index) { if (index < 0) { return null; }//from w w w .j av a 2s.c om // if (mSectionInfoCache .containsKey(index)) { // return (Pair<AbsListSectionProxy, Pair<Integer, Integer>>) mSectionInfoCache.get(index); // } synchronized (sections) { for (int i = 0; i < sections.size(); i++) { AbsListSectionProxy section = sections.get(i); int sectionItemCount = section.getItemCount(); if (index <= sectionItemCount - 1) { Pair<AbsListSectionProxy, Pair<Integer, Integer>> result = new Pair<AbsListSectionProxy, Pair<Integer, Integer>>( section, new Pair<Integer, Integer>(i, index)); // mSectionInfoCache.put(index, result); return result; } else { index -= sectionItemCount; } } } return null; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
@Override public byte[] encodeAppStart(UUID uuid, boolean start) { if (mFwMajor >= 3) { final short LENGTH_APPRUNSTATE = 17; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPRUNSTATE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_APPRUNSTATE); buf.putShort(ENDPOINT_APPRUNSTATE); buf.put(start ? APPRUNSTATE_START : APPRUNSTATE_STOP); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); return buf.array(); } else {//from www .ja v a 2 s . c o m ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(); int param = start ? 1 : 0; pairs.add(new Pair<>(1, (Object) param)); return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs); } }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private ListenableFuture<Boolean> initializeIdentityRecords() { final SettableFuture<Boolean> future = new SettableFuture<>(); new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() { @Override/*from w w w .jav a2 s . c o m*/ protected @NonNull Pair<IdentityRecordList, String> doInBackground(Recipient... params) { IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this); IdentityRecordList identityRecordList = new IdentityRecordList(); List<Recipient> recipients = new LinkedList<>(); if (params[0].isGroupRecipient()) { recipients.addAll(DatabaseFactory.getGroupDatabase(ConversationActivity.this) .getGroupMembers(params[0].getAddress().toGroupString(), false)); } else { recipients.add(params[0]); } for (Recipient recipient : recipients) { Log.i(TAG, "Loading identity for: " + recipient.getAddress()); identityRecordList.add(identityDatabase.getIdentity(recipient.getAddress())); } String message = null; if (identityRecordList.isUnverified()) { message = IdentityUtil.getUnverifiedBannerDescription(ConversationActivity.this, identityRecordList.getUnverifiedRecipients(ConversationActivity.this)); } return new Pair<>(identityRecordList, message); } @Override protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) { Log.i(TAG, "Got identity records: " + result.first.isUnverified()); identityRecords.replaceWith(result.first); if (result.second != null) { Log.d(TAG, "Replacing banner..."); unverifiedBannerView.get().display(result.second, result.first.getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener()); } else if (unverifiedBannerView.resolved()) { Log.d(TAG, "Clearing banner..."); unverifiedBannerView.get().hide(); } titleView.setVerified(isSecureText && identityRecords.isVerified()); future.set(true); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient); return future; }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public List<Pair<String, String>> getLabelList() { List<Pair<String, String>> array = new ArrayList<Pair<String, String>>(); Map<String, String> labelMap = this.getLabelMap(); synchronized (labelMap) { for (Map.Entry<String, String> entry : labelMap.entrySet()) { array.add(new Pair<String, String>(entry.getValue(), entry.getKey()) { public String toString() { return first.toString(); }/* w w w . ja va 2 s . c om*/ }); } } return array; }
From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java
private List<Pair<ExperimentObject, Long>> getObjectsMatching(int scopeLevel, int callerKind, long callerId, int filter) { List<Pair<ExperimentObject, Long>> objects = new ArrayList<Pair<ExperimentObject, Long>>(); if (scopeLevel == SCOPE_RULE) { final long ruleId = findRuleIdForDescendant(callerKind, callerId); Rule rule = mExperiment.rules.get(ruleId); // Presently, there are only trigger events in the rule scope level. ExperimentObject eventObject = getTriggerEventDataForRule(rule); if (eventObject != null && eventObject.satisfiesFilter(filter)) { // Fake an id from the tagged event data kind so we can later // rebuild the right kind of event. Long fakeId = (long) eventObject.getTag(); objects.add(new Pair<ExperimentObject, Long>(eventObject, fakeId)); }/*from ww w . ja va 2 s .c o m*/ } else if (scopeLevel == SCOPE_SCENE) { final long sceneId = findSceneIdForDescendant(callerKind, callerId); Scene scene = mExperiment.scenes.get(sceneId); if (scene.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(scene, sceneId)); } for (Long propId : scene.props) { Prop prop = mExperiment.props.get(propId); if (prop.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(prop, propId)); } } for (Long timerId : scene.timers) { Timer timer = mExperiment.timers.get(timerId); if (timer.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(timer, timerId)); } } } else if (scopeLevel == SCOPE_LOOP) { final long loopId = findLoopIdForDescendant(callerKind, callerId); Loop loop = mExperiment.loops.get(loopId); if (loop.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(loop, loopId)); } } else if (scopeLevel == SCOPE_EXPERIMENT) { for (Entry<Long, DataChannel> entry : mExperiment.dataChannels.entrySet()) { DataChannel dataChannel = entry.getValue(); if (dataChannel.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(dataChannel, entry.getKey())); } } for (Entry<Long, Asset> entry : mExperiment.assets.entrySet()) { Asset asset = entry.getValue(); if (asset.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(asset, entry.getKey())); } } for (Entry<Long, Generator> entry : mExperiment.generators.entrySet()) { Generator generator = entry.getValue(); if (generator.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(generator, entry.getKey())); } } for (Entry<Long, Variable> entry : mExperiment.variables.entrySet()) { Variable variable = entry.getValue(); if (variable.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(variable, entry.getKey())); } } for (Entry<Long, Source> entry : mExperiment.sources.entrySet()) { Source source = entry.getValue(); if (source.satisfiesFilter(filter)) { objects.add(new Pair<ExperimentObject, Long>(source, entry.getKey())); } } } return objects; }
From source file:com.ruesga.rview.fragments.ChangeDetailsFragment.java
@SuppressWarnings("ConstantConditions") private Observable<Pair<ReviewInput, ReviewInfo>> reviewChange(final ReviewInput input) { final Context ctx = getActivity(); final GerritApi api = ModelHelper.getGerritApi(ctx); return SafeObservable.fromNullCallable(() -> { ReviewInfo response = api/*from w ww.j av a 2s. co m*/ .setChangeRevisionReview(String.valueOf(mLegacyChangeId), mCurrentRevision, input) .blockingFirst(); return new Pair<>(input, response); }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private ArrayList<Pair<Integer, Object>> decodeDict(ByteBuffer buf) { ArrayList<Pair<Integer, Object>> dict = new ArrayList<>(); buf.order(ByteOrder.LITTLE_ENDIAN); byte dictSize = buf.get(); while (dictSize-- > 0) { Integer key = buf.getInt(); byte type = buf.get(); short length = buf.getShort(); switch (type) { case TYPE_INT: case TYPE_UINT: if (length == 1) { dict.add(new Pair<Integer, Object>(key, buf.get())); } else if (length == 2) { dict.add(new Pair<Integer, Object>(key, buf.getShort())); } else { dict.add(new Pair<Integer, Object>(key, buf.getInt())); }//from www . j av a 2 s . co m break; case TYPE_CSTRING: case TYPE_BYTEARRAY: byte[] bytes = new byte[length]; buf.get(bytes); if (type == TYPE_BYTEARRAY) { dict.add(new Pair<Integer, Object>(key, bytes)); } else { dict.add(new Pair<Integer, Object>(key, new String(bytes))); } break; default: } } return dict; }
From source file:com.androzic.Androzic.java
public void initializePlugins() { PackageManager packageManager = getPackageManager(); List<ResolveInfo> plugins; Intent initializationIntent = new Intent("com.androzic.plugins.action.INITIALIZE"); // enumerate initializable plugins plugins = packageManager.queryBroadcastReceivers(initializationIntent, 0); for (ResolveInfo plugin : plugins) { // send initialization broadcast, we send it directly instead of sending // one broadcast for all plugins to wake up stopped plugins: // http://developer.android.com/about/versions/android-3.1.html#launchcontrols Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); intent.setAction(initializationIntent.getAction()); sendBroadcast(intent);/* w w w . ja v a2s . c o m*/ } // enumerate plugins with preferences plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.preferences"), 0); for (ResolveInfo plugin : plugins) { Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); pluginPreferences.put(plugin.activityInfo.loadLabel(packageManager).toString(), intent); } // enumerate plugins with views plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.view"), 0); for (ResolveInfo plugin : plugins) { // get menu icon Drawable icon = null; try { Resources resources = packageManager .getResourcesForApplication(plugin.activityInfo.applicationInfo); int id = resources.getIdentifier("ic_menu_view", "drawable", plugin.activityInfo.packageName); if (id != 0) icon = resources.getDrawable(id); } catch (Resources.NotFoundException e) { e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); Pair<Drawable, Intent> pair = new Pair<>(icon, intent); pluginViews.put(plugin.activityInfo.loadLabel(packageManager).toString(), pair); } }