List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:Main.java
public static Pair<Integer, Integer> getDimensionsForStream(InputStream in) { Options options = new Options(); options.inJustDecodeBounds = true;//from w w w.j av a 2 s . c o m BitmapFactory.decodeStream(in, null, options); return new Pair<Integer, Integer>(options.outWidth, options.outHeight); }
From source file:Main.java
public static Pair<Boolean, Uri> isTrackExist(Context context, String artist, String track) { File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_MUSIC), artist + " - " + track + ".mp3"); return new Pair<>(file.exists(), Uri.fromFile(file)); }
From source file:Main.java
private static Pair<Integer, Integer> rankPosition(String taxon) { int i = taxon.indexOf("subsp."); if (i < 0) { i = taxon.indexOf("form."); if (i < 0) { i = taxon.indexOf("var."); if (i < 0) { return new Pair<Integer, Integer>(-1, -1); } else { return new Pair<Integer, Integer>(i, 4); }/*w ww .j a v a2 s .c o m*/ } else { return new Pair<Integer, Integer>(i, 5); } } else { return new Pair<Integer, Integer>(i, 6); } }
From source file:Main.java
/** * @param entries//from ww w .j a va 2 s. c o m * @param delim * @return delim-delimited keys and comma-delimited values; string values are put between ' */ public static Pair<String, String> getAsStrings(Set<Entry<String, Object>> entries, String delim) { if (entries == null) return new Pair<String, String>("", ""); StringBuilder keysBuilder = new StringBuilder(); StringBuilder valuesBuilder = new StringBuilder(); boolean first = true; for (Entry<String, Object> entry : entries) { if (first) { first = false; } else { keysBuilder.append(delim); valuesBuilder.append(delim); } keysBuilder.append(entry.getKey()); Object value = entry.getValue(); if (value instanceof String) { valuesBuilder.append("'").append(value).append("'"); } else { valuesBuilder.append(value); } } return new Pair<String, String>(keysBuilder.toString(), valuesBuilder.toString()); }
From source file:Main.java
public static Pair<String, String> ReorderRTLTextForPebble(String source, int charLimit) { if (source == null || source.equals("")) return new Pair<>("", ""); if (!hebrewPattern.matcher(source).find()) { return new Pair<>(source, ""); } else {//from ww w.j a v a 2 s.c o m StringBuilder sbResult = new StringBuilder(); StringBuilder sbExtraResult = new StringBuilder(); StringBuilder sbTemp = new StringBuilder(); String[] words = source.split(" "); int charCount = 0; for (int wordIndex = 0; wordIndex < words.length; wordIndex++, sbTemp.setLength(0)) { sbTemp.append(words[wordIndex]); charCount += sbTemp.length(); Matcher hebrewWord = hebrewPattern.matcher(words[wordIndex]); if (hebrewWord.find()) { sbTemp.reverse(); if (sbTemp.charAt(0) == ')') { sbTemp.replace(0, 1, "("); } if (sbTemp.charAt(sbTemp.length() - 1) == '(') { sbTemp.replace(sbTemp.length() - 1, sbTemp.length(), ")"); } } if (charCount <= charLimit) { sbResult.insert(0, sbTemp + " "); } else { sbExtraResult.insert(0, sbTemp + " "); } charCount++; } if (sbExtraResult.length() > charLimit) { sbExtraResult.replace(0, sbExtraResult.length() - charLimit, "..."); } return new Pair<>(sbResult.toString().trim(), sbExtraResult.toString().trim()); } }
From source file:Main.java
public static Pair<String, String> parseQuoteUsernamePostid(final String usernamePostId) { if (TextUtils.isEmpty(usernamePostId)) { return null; }/* w w w . ja v a 2s . co m*/ final String[] split = usernamePostId.split(";"); if (split.length == 0) { return null; } else if (split.length == 1) { return new Pair<>(split[0], null); } return new Pair<>(split[0], split[1]); }
From source file:Main.java
private static Pair<Boolean, String> evaluateAsConstantExpression(String parameter) { // String constant? // TODO: Error, this matches something like "hello" + "how are you?" which is not a constant // (but can't be evaluated by getValueFromEntities() anyway). String[] quoteSet = new String[] { "\"", "'" }; //$NON-NLS-1$ //$NON-NLS-2$ for (String quote : quoteSet) if (parameter.startsWith(quote) && parameter.endsWith(quote)) return new Pair<Boolean, String>(true, parameter.substring(1, parameter.length() - 1)); // Numeric constant? if (parameter.matches("^(-)?[0-9.]+$")) //$NON-NLS-1$ return new Pair<Boolean, String>(true, parameter); // Boolean constant? if (parameter.equalsIgnoreCase("true") || parameter.equalsIgnoreCase("false")) //$NON-NLS-1$ //$NON-NLS-2$ return new Pair<Boolean, String>(true, parameter); // Special constants? if (parameter.equalsIgnoreCase("nowait") || parameter.equalsIgnoreCase("status") //$NON-NLS-1$//$NON-NLS-2$ || parameter.equalsIgnoreCase("keep")) return new Pair<Boolean, String>(true, parameter); // Not a constant value, apparently. return new Pair<Boolean, String>(false, parameter); }
From source file:Main.java
/** * Get the latitude and longitude from the Location object returned by * Location Services.// ww w . j a v a2 s . co m * * @param currentLocation A Location object containing the current location * @return The latitude and longitude of the current location, or null if no * location is available. */ public static Pair<Double, Double> getLatLng(Context context, Location currentLocation) { // If the location is valid if (currentLocation != null) { return new Pair<Double, Double>(currentLocation.getLatitude(), currentLocation.getLongitude()); } else { return null; } }
From source file:Main.java
public static Pair<Integer, Integer> getScreenDimensions(Context paramContext) { WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window"); DisplayMetrics localDisplayMetrics = new DisplayMetrics(); localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics); int i = Math.min(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); int j = Math.max(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); return new Pair(Integer.valueOf(i), Integer.valueOf(j)); }
From source file:Main.java
public static Pair<Integer, Integer> getResolution(Activity activity) { if (null == sResolution) { int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); sResolution = new Pair<Integer, Integer>(width, height); }/*from w w w. j ava2 s .c o m*/ return sResolution; }