List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:org.xwalk.extensions.iap.java
@Override public void onMessage(int instanceId, String message) { if (message.isEmpty()) return;/* w w w . j a va 2 s . co m*/ try { JSONObject jsonInput = new JSONObject(message); JSONObject jsonOutput = new JSONObject(); jsonOutput.put("_promise_id", jsonInput.getString("_promise_id")); String cmd = jsonInput.getString("cmd"); if (cmd.equals(CMD_INIT)) { init(jsonInput.getString("key")); postMessage(instanceId, jsonOutput.toString()); return; } cmdMap.put(cmd, new Pair<Integer, JSONObject>(instanceId, jsonOutput)); if (cmd.equals(CMD_BUY)) { purchase(jsonInput.getString("id")); // will consume it immediately after purchase finished. } else if (cmd.equals(CMD_QUERYPRODUCTS)) { queryProductDetails(jsonInput.getString("ids")); } else { Log.e(TAG, "Unexpected message received: " + message); } } catch (JSONException e) { Log.e(TAG, e.toString()); } }
From source file:com.xing.android.sdk.network.request.RequestUtilsTest.java
@Test public void appendParamsToBuilder() throws Exception { Uri uriBase = new Uri.Builder().scheme("test").authority("test").build(); Uri.Builder builder = uriBase.buildUpon(); // Check nothing happens RequestUtils.appendParamsToBuilder(builder, null); assertEquals(uriBase.toString(), builder.build().toString()); // Check param with empty key will not be added List<Pair<String, String>> pairs = new ArrayList<>(); pairs.add(new Pair<String, String>(null, null)); RequestUtils.appendParamsToBuilder(builder, pairs); assertEquals(uriBase.toString(), builder.build().toString()); // Check param with empty value will not be added pairs.clear();//from w w w . j ava 2 s.com pairs.add(new Pair<String, String>("test", null)); RequestUtils.appendParamsToBuilder(builder, pairs); assertEquals(uriBase.toString(), builder.build().toString()); // Check actual param is added pairs.clear(); pairs.add(new Pair<>("a", "a")); RequestUtils.appendParamsToBuilder(builder, pairs); assertEquals(uriBase + "?a=a", builder.build().toString()); // Check next 2 params will be appended pairs.clear(); pairs.add(new Pair<>("b", "b")); pairs.add(new Pair<String, String>(null, "d")); pairs.add(new Pair<String, String>("f", null)); pairs.add(new Pair<>("c", "c")); RequestUtils.appendParamsToBuilder(builder, pairs); assertEquals(uriBase + "?a=a&b=b&c=c", builder.build().toString()); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.AppMessageHandlerSquare.java
private byte[] encodeSquareWeatherMessage(WeatherSpec weatherSpec) { if (weatherSpec == null) { return null; }// www. ja v a 2s . c om ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2); pairs.add(new Pair<>(CfgKeyWeatherMode, (Object) 1)); pairs.add(new Pair<>(CfgKeyConditions, (Object) weatherSpec.currentCondition)); pairs.add(new Pair<>(CfgKeyUseCelsius, (Object) 1)); pairs.add(new Pair<>(CfgKeyCelsiusTemperature, (Object) (weatherSpec.currentTemp - 273))); pairs.add(new Pair<>(CfgKeyWeatherLocation, (Object) (weatherSpec.location))); byte[] weatherMessage = mPebbleProtocol .encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs); ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length); buf.put(weatherMessage); return buf.array(); }
From source file:net.illusor.swipeplayer.fragments.AboutDialog.java
/** * Gets the general information about the app * @return Pair of strings (app name - e.g. "Swipe Player", version info - version:build) *//* ww w . j a v a 2 s .co m*/ private Pair<String, String> getApkInfo() { try { Context context = this.getActivity(); PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); String name = packageInfo.applicationInfo.nonLocalizedLabel.toString(); String version = packageInfo.versionName;//manifest contains string looking like version@build return new Pair<>(name, version); } catch (PackageManager.NameNotFoundException ignore) { } return new Pair<>("Unknown", "Unknown"); }
From source file:com.facebook.imageutils.BitmapUtil.java
/** * Decodes only the bounds of an image and returns its width and height or null if the size can't * be determined/* w ww . j a va2 s . c o m*/ * @param is the InputStream containing the image data * @return dimensions of the image */ public static @Nullable Pair<Integer, Integer> decodeDimensions(InputStream is) { Preconditions.checkNotNull(is); ByteBuffer byteBuffer = DECODE_BUFFERS.acquire(); if (byteBuffer == null) { byteBuffer = ByteBuffer.allocate(DECODE_BUFFER_SIZE); } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; try { options.inTempStorage = byteBuffer.array(); BitmapFactory.decodeStream(is, null, options); return (options.outWidth == -1 || options.outHeight == -1) ? null : new Pair(options.outWidth, options.outHeight); } finally { DECODE_BUFFERS.release(byteBuffer); } }
From source file:com.kii.cloud.sync.DownloadManager.java
public synchronized int add(KiiFile file, String dest) { if ((file != null) && file.hasServerRecord()) { for (Pair<KiiFile, String> dn : dnList) { if (dn.first.getId() == file.getId()) { return SyncMsg.OK; }//from ww w . ja v a 2 s . c om } synchronized (this) { dnList.add(new Pair<KiiFile, String>(file, dest)); } return SyncMsg.OK; } return SyncMsg.ERROR_FILE_NOT_FOUND; }
From source file:im.neon.fragments.VectorUnknownDevicesFragment.java
/** * Convert a MXUsersDevicesMap to a list of List * * @return the list of list//from w w w . j a va 2 s. c o m */ private static List<Pair<String, List<MXDeviceInfo>>> getDevicesList() { List<Pair<String, List<MXDeviceInfo>>> res = new ArrayList<>(); List<String> userIds = mUnknownDevicesMap.getUserIds(); for (String userId : userIds) { List<MXDeviceInfo> deviceInfos = new ArrayList<>(); List<String> deviceIds = mUnknownDevicesMap.getUserDeviceIds(userId); for (String deviceId : deviceIds) { deviceInfos.add(mUnknownDevicesMap.getObject(deviceId, userId)); } res.add(new Pair<>(userId, deviceInfos)); } return res; }
From source file:free.rm.skytube.gui.businessobjects.updates.UpgradeAppTask.java
@Override protected Pair<File, Throwable> doInBackground(Void... params) { File apkFile;//from w ww .j ava2 s. c o m Throwable exception = null; // delete old apk files deleteOldApkFiles(); // try to download the remote APK file try { apkFile = downloadApk(); } catch (Throwable e) { apkFile = null; exception = e; } return new Pair<>(apkFile, exception); }
From source file:com.polyvi.xface.view.XWebChromeClient.java
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {//from www . j a v a2 s. c o m boolean reqOk = false; if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) { reqOk = true; } if (reqOk && defaultValue != null && defaultValue.equals("xFace_close_application:")) { XAppWebView appView = ((XAppWebView) view); int viewId = appView.getViewId(); XEvent evt = XEvent.createEvent(XEventType.CLOSE_APP, viewId); ((XFaceMainActivity) mInterface.getActivity()).getEventCenter().sendEventSync(evt); result.confirm(""); return true; } else if (reqOk && defaultValue != null && defaultValue.equals("xFace_app_send_message:")) { try { JSONArray args = new JSONArray(message); Pair<XAppWebView, String> appMessage = new Pair<XAppWebView, String>((XAppWebView) view, args.getString(0)); XEvent evt = XEvent.createEvent(XEventType.XAPP_MESSAGE, appMessage); ((XFaceMainActivity) mInterface.getActivity()).getEventCenter().sendEventSync(evt); } catch (JSONException e) { XLog.e(CLASS_NAME, ""); XLog.e(CLASS_NAME, e.getMessage()); } result.confirm(""); return true; } return super.onJsPrompt(view, url, message, defaultValue, result); }
From source file:cx.ring.model.Conversation.java
public Pair<HistoryEntry, HistoryCall> findHistoryByCallId(String id) { for (HistoryEntry e : history.values()) { for (HistoryCall c : e.getCalls().values()) { if (c.getCallId().equals(id)) return new Pair<>(e, c); }//from w w w .j a v a 2 s .c o m } return null; }