List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:org.thoughtcrime.securesms.GroupCreateActivity.java
private Pair<Long, Recipients> handlePushOperation(byte[] groupId, String groupName, byte[] avatar, Set<String> e164numbers) throws InvalidNumberException { String groupRecipientId = GroupUtil.getEncodedId(groupId); Recipients groupRecipient = RecipientFactory.getRecipientsFromString(this, groupRecipientId, false); GroupContext context = GroupContext.newBuilder().setId(ByteString.copyFrom(groupId)) .setType(GroupContext.Type.UPDATE).setName(groupName).addAllMembers(e164numbers).build(); OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(this, groupRecipient, context, avatar);/*from w ww .j a v a 2s .c o m*/ long threadId = MessageSender.send(this, masterSecret, outgoingMessage, -1, false); return new Pair<>(threadId, groupRecipient); }
From source file:org.runnerup.export.GarminSynchronizer.java
@Override public Status listWorkouts(List<Pair<String, String>> list) { Status s;/*from www . j a v a 2s . co m*/ if ((s = connect()) != Status.OK) { return s; } // s = Status.OK HttpURLConnection conn = null; try { Calendar today = Calendar.getInstance(); int month = today.get(Calendar.MONTH); //jan = 0 String str_today = String.format("%1$tY-%1$tm-%1td", today); String workout_url = String.format(CALENDAR_URL, today, month); conn = (HttpURLConnection) new URL(workout_url).openConnection(); conn.setRequestMethod(RequestMethod.GET.name()); addCookies(conn); conn.connect(); getCookies(conn); InputStream in = new BufferedInputStream(conn.getInputStream()); JSONObject obj = SyncHelper.parse(in); conn.disconnect(); int responseCode = conn.getResponseCode(); String amsg = conn.getResponseMessage(); if (responseCode == HttpStatus.SC_OK) { JSONArray arr = obj.getJSONArray("calendarItems"); for (int i = 0;; i++) { obj = arr.optJSONObject(i); if (obj == null) break; else if (!obj.getString("itemType").equals("workout")) continue; String title = obj.getString("title"); if (obj.optString("date").equals(str_today)) { title = '*' + title; //mark workout scheduled for today } list.add(new Pair<String, String>(getWorkoutIdFromSchedule(obj.getString("id")), title + ".json")); } } else { s = Synchronizer.Status.ERROR; s.ex = new Exception(amsg); } } catch (IOException e) { s = Synchronizer.Status.ERROR; s.ex = e; } catch (JSONException e) { s = Synchronizer.Status.ERROR; s.ex = e; } try { conn = (HttpURLConnection) new URL(LIST_WORKOUTS_URL).openConnection(); conn.setRequestMethod(RequestMethod.GET.name()); addCookies(conn); conn.connect(); getCookies(conn); InputStream in = new BufferedInputStream(conn.getInputStream()); JSONObject obj = SyncHelper.parse(in); conn.disconnect(); int responseCode = conn.getResponseCode(); String amsg = conn.getResponseMessage(); if (responseCode == HttpStatus.SC_OK) { obj = obj.getJSONObject("com.garmin.connect.workout.dto.BaseUserWorkoutListDto"); JSONArray arr = obj.getJSONArray("baseUserWorkouts"); for (int i = 0;; i++) { obj = arr.optJSONObject(i); if (obj == null) break; list.add(new Pair<String, String>(obj.getString("workoutId"), obj.getString("workoutName") + ".json")); } } else { s = Synchronizer.Status.ERROR; s.ex = new Exception(amsg); } } catch (IOException e) { s = Synchronizer.Status.ERROR; s.ex = e; } catch (JSONException e) { s = Synchronizer.Status.ERROR; s.ex = e; } if (s != Status.OK) { s.ex.printStackTrace(); } return s; }
From source file:com.microsoft.windowsazure.mobileservices.notifications.MobileServicePush.java
private ListenableFuture<ArrayList<Registration>> getFullRegistrationInformation(String pnsHandle) { final SettableFuture<ArrayList<Registration>> resultFuture = SettableFuture.create(); if (isNullOrWhiteSpace(pnsHandle)) { resultFuture.setException(new IllegalArgumentException("pnsHandle")); return resultFuture; }/*ww w. j ava2 s .c om*/ // get existing registrations String path = PNS_API_URL + "/registrations/"; List<Pair<String, String>> requestHeaders = new ArrayList<Pair<String, String>>(); List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>(); parameters.add(new Pair<String, String>("platform", mPnsSpecificRegistrationFactory.getPlatform())); parameters.add(new Pair<String, String>("deviceId", pnsHandle)); requestHeaders.add(new Pair<String, String>(HTTP.CONTENT_TYPE, MobileServiceConnection.JSON_CONTENTTYPE)); ListenableFuture<ServiceFilterResponse> serviceFilterFuture = mHttpClient.request(path, null, "GET", requestHeaders, parameters); Futures.addCallback(serviceFilterFuture, new FutureCallback<ServiceFilterResponse>() { @Override public void onFailure(Throwable exception) { resultFuture.setException(exception); } @Override public void onSuccess(ServiceFilterResponse response) { ArrayList<Registration> registrationsList = new ArrayList<Registration>(); JsonArray registrations = new JsonParser().parse(response.getContent()).getAsJsonArray(); for (JsonElement registrationJson : registrations) { Registration registration = null; if (registrationJson.getAsJsonObject().has("templateName")) { registration = mPnsSpecificRegistrationFactory .parseTemplateRegistration(registrationJson.getAsJsonObject()); } else { registration = mPnsSpecificRegistrationFactory .parseNativeRegistration(registrationJson.getAsJsonObject()); } registrationsList.add(registration); } resultFuture.set(registrationsList); } }); return resultFuture; }
From source file:com.tmall.wireless.tangram3.dataparser.concrete.PojoGroupBasicAdapter.java
@Override public void insertBatchComponents(int idx, List<Card> group) { if (mCards != null && group != null) { List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>(); List<BaseCell> newData = new ArrayList<>(); int newItemSize = 0; int lastEnd = 0; int insertPosition = 0; if (idx >= 0 && idx < mCards.size()) { for (int i = 0, size = mCards.size(); i < size; i++) { Pair<Range<Integer>, Card> pair = mCards.get(i); int start = pair.first.getLower(); int end = pair.first.getUpper(); if (i < idx) { //do nothing newCards.add(pair);//from w w w.ja va 2 s. c o m lastEnd = end; } else if (i == idx) { insertPosition = start; for (int j = 0, gs = group.size(); j < gs; j++) { Card newGroup = group.get(j); int childrenSize = newGroup.getCells().size(); newItemSize += childrenSize; Pair<Range<Integer>, Card> insertPair = new Pair<>( Range.create(lastEnd, lastEnd + childrenSize), newGroup); newCards.add(insertPair); newData.addAll(newGroup.getCells()); lastEnd = lastEnd + childrenSize; } Pair<Range<Integer>, Card> newPair = new Pair<>( Range.create(start + newItemSize, end + newItemSize), pair.second); newCards.add(newPair); lastEnd = end + newItemSize; } else { Pair<Range<Integer>, Card> newPair = new Pair<>( Range.create(start + newItemSize, end + newItemSize), pair.second); newCards.add(newPair); lastEnd = end; } } } else { newCards.addAll(mCards); lastEnd = mCards.size() > 0 ? mCards.get(mCards.size() - 1).first.getUpper() : 0; insertPosition = lastEnd; for (int j = 0, gs = group.size(); j < gs; j++) { Card newGroup = group.get(j); int childrenSize = newGroup.getCells().size(); newItemSize += childrenSize; Pair<Range<Integer>, Card> insertPair = new Pair<>( Range.create(lastEnd, lastEnd + childrenSize), newGroup); newCards.add(insertPair); newData.addAll(newGroup.getCells()); lastEnd = lastEnd + childrenSize; } } for (int i = 0, size = group.size(); i < size; i++) { Card card = group.get(i); if (card != null) { card.added(); } } mCards.clear(); mCards.addAll(newCards); mData.addAll(insertPosition, newData); notifyItemRangeInserted(insertPosition, newItemSize); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java
public void testJsonApiWithQueryParametersFeatureHeader() { testInvokeApiFeatureHeader(new ClientTestOperation() { @Override/* w ww . j a va 2s . co m*/ public void executeOperation(MobileServiceClient client) throws Exception { List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>(); queryParams.add(new Pair<String, String>("a", "b")); client.invokeApi("apiName", "DELETE", queryParams).get(); } }, "AJ,QS"); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void insertUserParameterWithSystemPropertiesIntId( final EnumSet<MobileServiceSystemProperty> systemProperties) throws Throwable { final String tableName = "MyTableName"; final String responseContent = "{\"id\":5,\"String\":\"Hey\"}"; final JsonObject obj = new JsonParser().parse("{\"String\":\"what\"}").getAsJsonObject(); MobileServiceClient client = null;/* w w w. j a va 2 s .c o 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=__createdAt")); 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", "__createdAt")); try { // Call the insert method JsonObject jsonObject = msTable.insert(obj, parameters).get(); // Asserts if (jsonObject == null) { fail("Expected result"); } } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java
public void testTypedApiWithQueryParametersFeatureHeader() { testInvokeApiFeatureHeader(new ClientTestOperation() { @Override//w ww . java2 s.c o m public void executeOperation(MobileServiceClient client) throws Exception { List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>(); queryParams.add(new Pair<String, String>("a", "b")); client.invokeApi("apiName", "GET", queryParams, Address.class).get(); } }, "AT,QS"); }
From source file:cx.ring.service.LocalService.java
public Pair<Conference, SipCall> getCall(String id) { for (Conversation conv : conversations.values()) { ArrayList<Conference> confs = conv.getCurrentCalls(); for (Conference c : confs) { SipCall call = c.getCallById(id); if (call != null) return new Pair<>(c, call); }/*from w w w.jav a 2 s . co m*/ } return new Pair<>(null, null); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java
public void testGenericApiFeatureHeader() { testInvokeApiFeatureHeader(new ClientTestOperation() { @Override/*from ww w.j av a 2 s . c o m*/ public void executeOperation(MobileServiceClient client) throws Exception { List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>(); queryParams.add(new Pair<String, String>("a", "b")); List<Pair<String, String>> requestHeaders = new ArrayList<Pair<String, String>>(); requestHeaders.add(new Pair<String, String>("Content-Type", "text/plain")); byte[] content = "hello world".getBytes(); client.invokeApi("apiName", content, "POST", requestHeaders, queryParams).get(); } }, "AG"); }
From source file:piuk.blockchain.android.MyRemoteWallet.java
private Pair<ECKey, String> generateNewMiniPrivateKey() { SecureRandom random = new SecureRandom(); while (true) { // Log.d("generateNewMiniPrivateKey", "generateNewMiniPrivateKey"); //Make Candidate Mini Key byte randomBytes[] = new byte[16]; random.nextBytes(randomBytes);// ww w . ja va 2 s . c om String encodedBytes = Base58.encode(randomBytes); //TODO: Casascius Series 1 22-character variant, remember to notify Ben about updating to 30-character variant String minikey = 'S' + encodedBytes.substring(0, 21); try { //Append ? & hash it again byte[] bytes_appended = MessageDigest.getInstance("SHA-256").digest((minikey + '?').getBytes()); //If zero byte then the key is valid if (bytes_appended[0] == 0) { try { //SHA256 byte[] bytes = MessageDigest.getInstance("SHA-256").digest(minikey.getBytes()); final ECKey eckey = new ECKey(bytes, null); final DumpedPrivateKey dumpedPrivateKey1 = eckey.getPrivateKeyEncoded(getParams()); String privateKey1 = Base58.encode(dumpedPrivateKey1.bytes); final String toAddress = eckey.toAddress(getParams()).toString(); /* Log.d("sendCoinsToFriend", "generateNewMiniPrivateKey: minikey: " + minikey); Log.d("sendCoinsToFriend", "generateNewMiniPrivateKey: privateKey: " + privateKey1); Log.d("sendCoinsToFriend", "generateNewMiniPrivateKey: address: " + toAddress); */ return new Pair<ECKey, String>(eckey, minikey); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }