List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.taobao.weex.dom.WXDomStatement.java
private void addAnimationForDomTree(WXDomObject domObject) { animations.add(new Pair<String, Map<String, Object>>(domObject.getRef(), domObject.getStyles())); for (int i = 0; i < domObject.childCount(); i++) { addAnimationForDomTree(domObject.getChild(i)); }/*from w ww .j a va2 s . co m*/ }
From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java
private void onAfterPostsLoad(boolean fromCache) { PageHolder pageHolder = getPageHolder(); PostsExtra extra = getExtra();/* ww w.j av a2s. c o m*/ if (!extra.isAddedToHistory) { extra.isAddedToHistory = true; HistoryDatabase.getInstance().addHistory(pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, pageHolder.threadTitle); } if (extra.cachedPosts != null) { Pair<String, Uri> originalThreadData = null; Uri archivedThreadUri = extra.cachedPosts.getArchivedThreadUri(); if (archivedThreadUri != null) { String chanName = ChanManager.getInstance().getChanNameByHost(archivedThreadUri.getAuthority()); if (chanName != null) { originalThreadData = new Pair<>(chanName, archivedThreadUri); } } if ((this.originalThreadData == null) != (originalThreadData == null)) { this.originalThreadData = originalThreadData; updateOptionsMenu(false); } } if (!fromCache) { FavoritesStorage.getInstance().modifyPostsCount(pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, getAdapter().getExistingPostsCount()); } Iterator<PostItem> iterator = getAdapter().iterator(); if (iterator.hasNext()) { String title = iterator.next().getSubjectOrComment(); if (StringUtils.isEmptyOrWhitespace(title)) { title = null; } FavoritesStorage.getInstance().modifyTitle(pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, title, false); if (!StringUtils.equals(StringUtils.nullIfEmpty(pageHolder.threadTitle), title)) { HistoryDatabase.getInstance().refreshTitles(pageHolder.chanName, pageHolder.boardName, pageHolder.threadNumber, title); pageHolder.threadTitle = title; notifyTitleChanged(); } } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void lookupUserParameterWithSystemPropertiesIntId( final EnumSet<MobileServiceSystemProperty> systemProperties) throws Throwable { final String tableName = "MyTableName"; final String responseContent = "{\"id\":5,\"String\":\"Hey\"}"; MobileServiceClient client = null;// w w w .j a v a 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 lookup method JsonElement jsonObject = msTable.lookUp(5, parameters).get(); // Asserts if (jsonObject == null) { fail("Expected result"); } } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:de.mrapp.android.sidebar.Sidebar.java
/** * Calculates and returns the position of the content's left and right edge, depending on the * sidebar's location, using the content mode <code>SCROLL</code>, while the user performs a * drag gesture.// w w w . j a va 2 s .c o m * * @param sidebarConstraints * The current position of the sidebar's left and right edge, as an instance of the * class {@link Pair} * @return The position of the content's left and right edge as an instance of the class {@link * Pair} */ private Pair<Integer, Integer> calculateScrolledContentConstraintsWhileDragging( final Pair<Integer, Integer> sidebarConstraints) { int leftEdge; int rightEdge; if (getLocation() == Location.LEFT) { leftEdge = mOffset + Math .round((sidebarConstraints.second - sidebarView.getShadowWidth() - mOffset) * scrollRatio); } else { leftEdge = Math .round((sidebarConstraints.first + sidebarView.getShadowWidth() - mContentWidth) * scrollRatio); } rightEdge = leftEdge + mContentWidth; return new Pair<>(leftEdge, rightEdge); }
From source file:de.mrapp.android.sidebar.Sidebar.java
/** * Calculates and returns the position of the content's left and right edge, depending on the * sidebar's location, using the content mode <code>RESIZE</code>, while the user performs a * drag gesture./* ww w . ja va2s .co m*/ * * @param sidebarConstraints * The current position of the sidebar's left and right edge, as an instance of the * class {@link Pair} * @return The position of the content's left and right edge as an instance of the class {@link * Pair} */ private Pair<Integer, Integer> calculateResizedContentConstraintsWhileDragging( final Pair<Integer, Integer> sidebarConstraints) { int leftEdge; int rightEdge; if (getLocation() == Location.LEFT) { leftEdge = sidebarConstraints.second - sidebarView.getShadowWidth(); rightEdge = getWidth(); } else { leftEdge = 0; rightEdge = sidebarConstraints.first + sidebarView.getShadowWidth(); } return new Pair<>(leftEdge, rightEdge); }
From source file:com.microsoft.windowsazure.mobileservices.MobileServiceClient.java
/** * Invokes a custom API/* www . j ava 2s . co m*/ * * @param apiName The API name * @param body The json element to send as the request body * @param httpMethod The HTTP Method used to invoke the API * @param parameters The query string parameters sent in the request * @param features The features used in the request */ private ListenableFuture<JsonElement> invokeApiInternal(String apiName, JsonElement body, String httpMethod, List<Pair<String, String>> parameters, EnumSet<MobileServiceFeatures> features) { byte[] content = null; if (body != null) { try { content = body.toString().getBytes(UTF8_ENCODING); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } List<Pair<String, String>> requestHeaders = new ArrayList<Pair<String, String>>(); if (body != null) { requestHeaders .add(new Pair<String, String>(HTTP.CONTENT_TYPE, MobileServiceConnection.JSON_CONTENTTYPE)); } if (parameters != null && !parameters.isEmpty()) { features.add(MobileServiceFeatures.AdditionalQueryParameters); } final SettableFuture<JsonElement> future = SettableFuture.create(); ListenableFuture<ServiceFilterResponse> internalFuture = invokeApiInternal(apiName, content, httpMethod, requestHeaders, parameters, features); Futures.addCallback(internalFuture, new FutureCallback<ServiceFilterResponse>() { @Override public void onFailure(Throwable e) { future.setException(e); } @Override public void onSuccess(ServiceFilterResponse response) { String content = response.getContent(); if (content == null) { future.set(null); return; } JsonElement json = new JsonParser().parse(content); future.set(json); } }); return future; }
From source file:org.thoughtcrime.securesms.ProfileFragment.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(GService.appContext, groupRecipientId, false);/*from ww w .j av a 2 s .c o m*/ TextSecureProtos.GroupContext context = TextSecureProtos.GroupContext.newBuilder() .setId(ByteString.copyFrom(groupId)).setType(TextSecureProtos.GroupContext.Type.UPDATE) .setName(groupName).addAllMembers(e164numbers).build(); OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(GService.appContext, groupRecipient, context, avatar); long threadId = MessageSender.send(GService.appContext, masterSecret, outgoingMessage, -1, false); return new Pair<>(threadId, groupRecipient); }
From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private Pair<Integer, Float> getProgress(int position, float positionOffset) { if (isRtl()) { position = (count - 1) - position; if (position < 0) { position = 0;// ww w .j a v a 2s . com } } boolean isRightOverScrolled = position > selectedPosition; boolean isLeftOverScrolled; if (isRtl()) { isLeftOverScrolled = position - 1 < selectedPosition; } else { isLeftOverScrolled = position + 1 < selectedPosition; } if (isRightOverScrolled || isLeftOverScrolled) { selectedPosition = position; } boolean isSlideToRightSide = selectedPosition == position && positionOffset != 0; int selectingPosition; float selectingProgress; if (isSlideToRightSide) { selectingPosition = isRtl() ? position - 1 : position + 1; selectingProgress = positionOffset; } else { selectingPosition = position; selectingProgress = 1 - positionOffset; } if (selectingProgress > 1) { selectingProgress = 1; } else if (selectingProgress < 0) { selectingProgress = 0; } return new Pair<>(selectingPosition, selectingProgress); }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public Pair<Transaction, Long> makeTransactionCustom(final HashMap<String, BigInteger> sendingAddresses, List<MyTransactionOutPoint> unspent, HashMap<String, BigInteger> receivingAddresses, BigInteger fee, final String changeAddress) throws Exception { long priority = 0; if (unspent == null || unspent.size() == 0) throw new InsufficientFundsException("No free outputs to spend."); if (fee == null) fee = BigInteger.ZERO;/*w w w . j a va2 s .c o m*/ //Construct a new transaction Transaction tx = new Transaction(getParams()); BigInteger outputValueSum = BigInteger.ZERO; for (Iterator<Entry<String, BigInteger>> iterator = receivingAddresses.entrySet().iterator(); iterator .hasNext();) { Map.Entry<String, BigInteger> mapEntry = iterator.next(); String toAddress = mapEntry.getKey(); BigInteger amount = mapEntry.getValue(); if (amount == null || amount.compareTo(BigInteger.ZERO) <= 0) throw new Exception("You must provide an amount"); outputValueSum = outputValueSum.add(amount); //Add the output BitcoinScript toOutputScript = BitcoinScript.createSimpleOutBitoinScript(new BitcoinAddress(toAddress)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom toAddress: " + toAddress + "amount: " + amount); TransactionOutput output = new TransactionOutput(getParams(), null, amount, toOutputScript.getProgram()); tx.addOutput(output); } //Now select the appropriate inputs BigInteger valueSelected = BigInteger.ZERO; BigInteger valueNeeded = outputValueSum.add(fee); Map<String, BigInteger> addressTotalUnspentValues = new HashMap<String, BigInteger>(); for (MyTransactionOutPoint outPoint : unspent) { BitcoinScript script = new BitcoinScript(outPoint.getScriptBytes()); if (script.getOutType() == BitcoinScript.ScriptOutTypeStrange) continue; BitcoinScript inputScript = new BitcoinScript(outPoint.getConnectedPubKeyScript()); String address = inputScript.getAddress().toString(); BigInteger addressSendAmount = sendingAddresses.get(address); if (addressSendAmount == null) { throw new Exception("Invalid transaction address send amount is null"); } final BigInteger addressTotalUnspentValue = addressTotalUnspentValues.get(address); if (addressTotalUnspentValue == null) { addressTotalUnspentValues.put(address, outPoint.value); } else { addressTotalUnspentValues.put(address, addressTotalUnspentValue.add(outPoint.value)); } MyTransactionInput input = new MyTransactionInput(getParams(), null, new byte[0], outPoint); input.outpoint = outPoint; // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom fromAddress: " + address + "amount: " + outPoint.value); tx.addInput(input); valueSelected = valueSelected.add(outPoint.value); priority += outPoint.value.longValue() * outPoint.confirmations; //if (valueSelected.compareTo(valueNeeded) == 0 || valueSelected.compareTo(valueNeeded.add(minFreeOutputSize)) >= 0) // break; } //Check the amount we have selected is greater than the amount we need if (valueSelected.compareTo(valueNeeded) < 0) { throw new InsufficientFundsException("Insufficient Funds"); } //decide change if (changeAddress == null) { BigInteger feeAmountLeftToAccountedFor = fee; for (Iterator<Entry<String, BigInteger>> iterator = addressTotalUnspentValues.entrySet() .iterator(); iterator.hasNext();) { final Entry<String, BigInteger> entry = iterator.next(); final String address = entry.getKey(); final BigInteger addressTotalUnspentValue = entry.getValue(); final BigInteger addressSendAmount = sendingAddresses.get(address); BigInteger addressChangeAmount = addressTotalUnspentValue.subtract(addressSendAmount); if (feeAmountLeftToAccountedFor.compareTo(BigInteger.ZERO) > 0) { if (addressChangeAmount.compareTo(feeAmountLeftToAccountedFor) >= 0) { //have enough to fill fee addressChangeAmount = addressChangeAmount.subtract(feeAmountLeftToAccountedFor); feeAmountLeftToAccountedFor = BigInteger.ZERO; } else { // do not have enough to fill fee feeAmountLeftToAccountedFor = feeAmountLeftToAccountedFor.subtract(addressChangeAmount); addressChangeAmount = BigInteger.ZERO; } } if (addressChangeAmount.compareTo(BigInteger.ZERO) > 0) { //Add the output BitcoinScript toOutputScript = BitcoinScript .createSimpleOutBitoinScript(new BitcoinAddress(address)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom changeAddress == null: " + address + "addressChangeAmount: " + addressChangeAmount); TransactionOutput output = new TransactionOutput(getParams(), null, addressChangeAmount, toOutputScript.getProgram()); tx.addOutput(output); } } } else { BigInteger addressChangeAmountSum = BigInteger.ZERO; for (Iterator<Entry<String, BigInteger>> iterator = addressTotalUnspentValues.entrySet() .iterator(); iterator.hasNext();) { final Entry<String, BigInteger> entry = iterator.next(); final String address = entry.getKey(); final BigInteger addressTotalUnspentValue = entry.getValue(); final BigInteger addressSendAmount = sendingAddresses.get(address); final BigInteger addressChangeAmount = addressTotalUnspentValue.subtract(addressSendAmount); addressChangeAmountSum = addressChangeAmountSum.add(addressChangeAmount); } if (addressChangeAmountSum.compareTo(BigInteger.ZERO) > 0) { //Add the output BitcoinScript toOutputScript = BitcoinScript .createSimpleOutBitoinScript(new BitcoinAddress(changeAddress)); TransactionOutput output = new TransactionOutput(getParams(), null, addressChangeAmountSum.subtract(fee), toOutputScript.getProgram()); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom changeAddress != null: " + changeAddress + "addressChangeAmount: " + output.getValue()); tx.addOutput(output); } } long estimatedSize = tx.bitcoinSerialize().length + (114 * tx.getInputs().size()); priority /= estimatedSize; return new Pair<Transaction, Long>(tx, priority); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void deleteUserParameterWithSystemProperties( final EnumSet<MobileServiceSystemProperty> systemProperties) throws Throwable { final String tableName = "MyTableName"; final String responseContent = "{\"id\":\"an id\",\"String\":\"Hey\"}"; MobileServiceClient client = null;/*from w w w .j a v 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("an id", parameters).get(); } catch (Exception exception) { fail(exception.getMessage()); } }