List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void updateUserParameterWithSystemPropertiesIntId( 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;/*from w w w .j av a2s. com*/ 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 update method JsonObject jsonObject = msTable.update(obj, parameters).get(); // Asserts if (jsonObject == null) { fail("Expected result"); } } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java
@Override public ListAdapter getTimersAdapter(long sceneId) { if (mCurrentTimerAdapter != null && mCurrentTimerAdapter.first == sceneId) { return mCurrentTimerAdapter.second; }/*from w ww .j a v a 2 s .co m*/ ProgramComponentAdapter<Timer> adapter = new ProgramComponentAdapter<Timer>(mExperiment.timers, mExperiment.scenes.get(sceneId).timers, new TimerListItemViewBinder(this, this)); mCurrentTimerAdapter = new Pair<Long, ProgramComponentAdapter<Timer>>(sceneId, adapter); return adapter; }
From source file:de.mrapp.android.sidebar.Sidebar.java
/** * Calculates and returns the position of the sidebar's left and right edge, depending on its * location and a specific boolean value, which specifies, whether it should be shown or not. * * @param shown/*from w w w.ja va 2 s .co m*/ * True, if the sidebar should be shown, false otherwise * @return The position of the sidebar's left and right edge as an instance of the class {@link * Pair} */ private Pair<Integer, Integer> calculateSidebarConstraints(final boolean shown) { int leftEdge; int rightEdge; if (getLocation() == Location.LEFT) { if (shown) { leftEdge = 0; } else { leftEdge = mOffset - mSidebarWidth; } } else { if (shown) { leftEdge = getWidth() - mSidebarWidth - sidebarView.getShadowWidth(); } else { leftEdge = getWidth() - mOffset - sidebarView.getShadowWidth(); } } rightEdge = leftEdge + mSidebarWidth + sidebarView.getShadowWidth(); return new Pair<>(leftEdge, rightEdge); }
From source file:im.vector.VectorApp.java
/** * Provides the supported application locales list * * @param context the context/*from w w w .j a va 2 s. c o m*/ * @return the supported application locales list */ public static List<Locale> getApplicationLocales(Context context) { if (mApplicationLocales.isEmpty()) { Set<Pair<String, String>> knownLocalesSet = new HashSet<>(); try { final Locale[] availableLocales = Locale.getAvailableLocales(); for (Locale locale : availableLocales) { knownLocalesSet.add(new Pair<>(getString(context, locale, R.string.resouces_language), getString(context, locale, R.string.resouces_country))); } } catch (Exception e) { Log.e(LOG_TAG, "## getApplicationLocales() : failed " + e.getMessage()); knownLocalesSet.add(new Pair<>(context.getString(R.string.resouces_language), context.getString(R.string.resouces_country))); } for (Pair<String, String> knownLocale : knownLocalesSet) { mApplicationLocales.add(new Locale(knownLocale.first, knownLocale.second)); } } List<Locale> sortedLocalesList = new ArrayList<>(mApplicationLocales); // sort by human display names Collections.sort(sortedLocalesList, new Comparator<Locale>() { @Override public int compare(Locale lhs, Locale rhs) { return localeToLocalisedString(lhs).compareTo(localeToLocalisedString(rhs)); } }); return sortedLocalesList; }
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 and whether the sidebar is currently shown, using the content mode * <code>SCROLL</code>.//w ww .jav a2 s .c o m * * @return The position of the content's left and right edge as an instance of the class {@link * Pair} */ private Pair<Integer, Integer> calculateScrolledContentConstraints() { int leftEdge; int rightEdge; if (getLocation() == Location.LEFT) { if (isSidebarShown()) { leftEdge = mOffset + Math.round((mSidebarWidth - mOffset) * scrollRatio); } else { leftEdge = mOffset; } } else { if (isSidebarShown()) { leftEdge = Math.round((-mSidebarWidth + mOffset) * scrollRatio); } else { leftEdge = 0; } } rightEdge = leftEdge + mContentWidth; return new Pair<>(leftEdge, rightEdge); }
From source file:net.robotmedia.acv.ui.widget.OcrLayout.java
/** Substitute common OCR mistakes with the correct text. */ private String performOcrTextSubstitutions(String ocrText) { if (!this.substitutionsDbFile.exists()) { return ocrText; }//from w w w .ja va2 s. c om // Populate the substitutions list if needed if (this.substitutionsList == null) { try { this.substitutionsList = new ArrayList<Pair<String, String>>(); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(this.substitutionsDbFile), "UTF8")); String line = ""; // Skip header line reader.readLine(); while ((line = reader.readLine()) != null) { // Skip comment lines and blank lines if (line.startsWith("#") || (line.length() == 0)) { continue; } String[] fields = line.split("="); String from = ""; String to = ""; if (fields.length == 1) { from = fields[0]; to = ""; } else if (fields.length == 2) { from = fields[0]; to = fields[1]; } else { continue; } // Replace tokens from = from.replaceAll("%eq%", "="); from = from.replaceAll("%perc%", "%"); to = to.replaceAll("%eq%", "="); to = to.replaceAll("%perc%", "%"); Pair<String, String> fromTo = new Pair<String, String>(from, to); this.substitutionsList.add(fromTo); } reader.close(); } catch (Exception e) { // Don't care } } String correctedText = ocrText; // Make substitutions from substitutions file for (Pair<String, String> fromTo : this.substitutionsList) { correctedText = correctedText.replaceAll(fromTo.first, fromTo.second); } // Force a few substitutions correctedText = correctedText.replaceAll("[?'` ]", "").trim(); if (correctedText.length() >= 1) { String firstChar = correctedText.substring(0, 1); String newFirstChar = firstChar; // Convert small hiragana to large hiragana if (newFirstChar.equals("??")) newFirstChar = "?"; else if (newFirstChar.equals("?")) newFirstChar = "?"; else if (newFirstChar.equals("?")) newFirstChar = "?"; else if (newFirstChar.equals("?")) newFirstChar = "?"; else if (newFirstChar.equals("?")) newFirstChar = "?"; else if (newFirstChar.equals("?")) newFirstChar = "?"; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = "?"; // Convert small katakana to large katakana else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; else if (newFirstChar.equals("")) newFirstChar = ""; // Japanese words don't start with else if (newFirstChar.equals("")) newFirstChar = ""; // Convert prolonged sound mark to "ichi" else if (newFirstChar.equals("")) newFirstChar = ""; correctedText = newFirstChar + correctedText.substring(1); } return correctedText; }
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 and whether the sidebar is currently shown, using the content mode * <code>RESIZE</code>./* w ww. j a v a 2 s . c o m*/ * * @return The position of the content's left and right edge as an instance of the class {@link * Pair} */ private Pair<Integer, Integer> calculateResizedContentConstraints() { int leftEdge; int rightEdge; if (getLocation() == Location.LEFT) { rightEdge = getWidth(); if (isSidebarShown()) { leftEdge = mSidebarWidth; } else { leftEdge = mOffset; } } else { leftEdge = 0; if (isSidebarShown()) { rightEdge = getWidth() - mSidebarWidth; } else { rightEdge = getWidth() - mOffset; } } return new Pair<>(leftEdge, rightEdge); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
private void lookupUserParameterWithSystemProperties( final EnumSet<MobileServiceSystemProperty> systemProperties) throws Throwable { final String tableName = "MyTableName"; final String responseContent = "{\"id\":\"an id\",\"String\":\"Hey\"}"; MobileServiceClient client = null;// ww w . j a v a 2 s . c om 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("an id", parameters).get(); // Asserts if (jsonObject == null) { fail("Expected result"); } } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public Pair<Transaction, Long> makeTransaction(boolean isSimpleSend, 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 ava 2 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 makeTransaction 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); BigInteger minFreeOutputSize = BigInteger.valueOf(1000000); MyTransactionOutPoint changeOutPoint = null; 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(); //if isSimpleSend don't use address as input if is output if (isSimpleSend && receivingAddresses.get(address) != null) continue; MyTransactionInput input = new MyTransactionInput(getParams(), null, new byte[0], outPoint); input.outpoint = outPoint; // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction fromAddress: " + address + "amount: " + outPoint.value); tx.addInput(input); valueSelected = valueSelected.add(outPoint.value); priority += outPoint.value.longValue() * outPoint.confirmations; if (changeAddress == null) changeOutPoint = outPoint; 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"); } BigInteger change = valueSelected.subtract(outputValueSum).subtract(fee); //Now add the change if there is any if (change.compareTo(BigInteger.ZERO) > 0) { BitcoinScript change_script; if (changeAddress != null) { change_script = BitcoinScript.createSimpleOutBitoinScript(new BitcoinAddress(changeAddress)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction changeAddress != null: " + changeAddress + "change: " + change); } else if (changeOutPoint != null) { BitcoinScript inputScript = new BitcoinScript(changeOutPoint.getConnectedPubKeyScript()); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransaction changeAddress == null: " + inputScript.getAddress() + "change: " + change); //Return change to the first address change_script = BitcoinScript.createSimpleOutBitoinScript(inputScript.getAddress()); } else { throw new Exception("Invalid transaction attempt"); } TransactionOutput change_output = new TransactionOutput(getParams(), null, change, change_script.getProgram()); tx.addOutput(change_output); } long estimatedSize = tx.bitcoinSerialize().length + (114 * tx.getInputs().size()); priority /= estimatedSize; return new Pair<Transaction, Long>(tx, priority); }
From source file:de.mrapp.android.sidebar.Sidebar.java
/** * Calculates and returns the position of the sidebar's left and right edge, depending on its * location, while the user performs a drag gesture. * * @return The position of the sidebar's left and right edge as an instance of the class {@link * Pair}//from w ww. ja v a2 s . c o m */ private Pair<Integer, Integer> calculateSidebarConstraintsWhileDragging() { Pair<Integer, Integer> shownSidebarConstraints = calculateSidebarConstraints(true); Pair<Integer, Integer> hiddenSidebarConstraints = calculateSidebarConstraints(false); int leftEdge = calculateSidebarConstraints().first + dragHelper.getDistance(); if (getLocation() == Location.LEFT) { leftEdge = Math.max(hiddenSidebarConstraints.first, leftEdge); leftEdge = Math.min(shownSidebarConstraints.first, leftEdge); } else { leftEdge = Math.max(shownSidebarConstraints.first, leftEdge); leftEdge = Math.min(hiddenSidebarConstraints.first, leftEdge); } int rightEdge = leftEdge + mSidebarWidth + sidebarView.getShadowWidth(); return new Pair<>(leftEdge, rightEdge); }