Example usage for android.util Pair Pair

List of usage examples for android.util Pair Pair

Introduction

In this page you can find the example usage for android.util Pair Pair.

Prototype

public Pair(F first, S second) 

Source Link

Document

Constructor for a Pair.

Usage

From source file:com.tmall.wireless.tangram3.util.Utils.java

/**
 * <pre>//from  ww w. j a  v a2 s  .c o m
 * parse image ratio from imageurl with regex as follows:
 * (\d+)-(\d+)(_?q\d+)?(\.[jpg|png|gif])
 * (\d+)x(\d+)(_?q\d+)?(\.[jpg|png|gif])
 *
 * samples urls:
 * http://img.alicdn.com/tps/i1/TB1x623LVXXXXXZXFXXzo_ZPXXX-372-441.png --> return 372/441
 * http://img.alicdn.com/tps/i1/TB1P9AdLVXXXXa_XXXXzo_ZPXXX-372-441.png --> return 372/441
 * http://img.alicdn.com/tps/i1/TB1NZxRLFXXXXbwXFXXzo_ZPXXX-372-441.png --> return 372/441
 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100.jpg --> return 100/100
 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100q90.jpg --> return 100/100
 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100q90.jpg_.webp --> return 100/100
 * http://img03.taobaocdn.com/tps/i3/T1JYROXuRhXXajR_DD-1680-446.jpg_q50.jpg --> return 1680/446
 * </pre>
 *
 * @param imageUrl image url
 * @return ratio of with to height parsed from url
 */
public static Pair<Integer, Integer> getImageSize(String imageUrl) {
    if (TextUtils.isEmpty(imageUrl)) {
        return null;
    }

    if (imageSizeMap.get(imageUrl) != null) {
        return imageSizeMap.get(imageUrl);
    }

    try {
        Matcher matcher = REGEX_1.matcher(imageUrl);
        String widthStr;
        String heightStr;
        if (matcher.find()) {
            if (matcher.groupCount() >= 2) {
                widthStr = matcher.group(1);
                heightStr = matcher.group(2);
                if (widthStr.length() < 5 && heightStr.length() < 5) {
                    int urlWidth = Integer.parseInt(widthStr);
                    int urlHeight = Integer.parseInt(heightStr);
                    Pair<Integer, Integer> result = new Pair<>(urlWidth, urlHeight);
                    imageSizeMap.put(imageUrl, result);
                    return result;
                }
            }
        } else {
            matcher = REGEX_2.matcher(imageUrl);
            if (matcher.find()) {
                if (matcher.groupCount() >= 2) {
                    widthStr = matcher.group(1);
                    heightStr = matcher.group(2);
                    if (widthStr.length() < 5 && heightStr.length() < 5) {
                        int urlWidth = Integer.parseInt(widthStr);
                        int urlHeight = Integer.parseInt(heightStr);
                        Pair<Integer, Integer> result = new Pair<>(urlWidth, urlHeight);
                        imageSizeMap.put(imageUrl, result);
                        return result;
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:conexionSiabra.ConexionSiabra.java

public JSONObject cancelarPerfil(String codigo) {
    Pair<String, String> elemento = new Pair<String, String>("codigo", codigo);
    ArrayList<Pair<String, String>> elementos = new ArrayList<Pair<String, String>>();
    elementos.add(elemento);//  w  w w .  j ava 2s. c  o  m
    return oauth.peticionPost(elementos, url_cancelar_perfil);
}

From source file:com.cuddlesoft.nori.database.APISettingsDatabase.java

/**
 * Get all {@link SearchClient.Settings} objects from the database.
 *
 * @return List of pairs mapping database IDs to {@link SearchClient.Settings} objects.
 *//*from   w  ww . ja  v a  2  s. c  o  m*/
public List<Pair<Integer, SearchClient.Settings>> getAll() {
    // Query the database.
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.query(TABLE_NAME, null, null, null, null, null, COLUMN_ID);

    // Convert database Cursor to List.
    final List<Pair<Integer, SearchClient.Settings>> settingsList = new ArrayList<>(c.getCount());
    while (c.moveToNext()) {
        settingsList.add(new Pair<>(c.getInt(c.getColumnIndex(COLUMN_ID)), cursorToSearchClientSettings(c)));
    }

    // Clean up native resources.
    c.close();
    db.close();

    return settingsList;
}

From source file:test.hugo.ui.ImgShowActivity.java

private void prepareDrawable(GlideDrawable resource, PhotoView view, int position) {
    view.setImageDrawable(resource);//w  w w  .j av  a  2s .  c om
    float screenWidth = getResources().getDisplayMetrics().widthPixels;
    float screenHeight = getResources().getDisplayMetrics().heightPixels;
    float intrinsicWidth = resource.getIntrinsicWidth(); //
    float intrinsicHeight = resource.getIntrinsicHeight();
    float scale = Math.min(screenWidth / intrinsicWidth, screenHeight / intrinsicHeight);
    float endPicWidth = (intrinsicWidth * scale);
    float endPicHeight = (intrinsicHeight * scale);
    pairs[position] = new Pair<>(endPicWidth, endPicHeight);

}

From source file:org.droidparts.http.worker.HttpClientWorker.java

public Pair<Integer, BufferedInputStream> getInputStream(String uri) throws HTTPException {
    HttpGet req = new HttpGet(uri);
    HttpResponse resp = getHttpResponse(req);
    HttpEntity entity = resp.getEntity();
    // 2G limit/* w  w  w.ja  va 2 s.c  om*/
    int contentLength = (int) entity.getContentLength();
    ConsumingInputStream cis = new ConsumingInputStream(getUnpackedInputStream(entity), entity);
    return new Pair<Integer, BufferedInputStream>(contentLength, cis);
}

From source file:com.learnit.LearnIt.async_tasks.GetTranslationsWebTask.java

@Override
protected Pair<String, List<String>> doInBackground(Object... unused) {
    String newWord = StringUtils.stripFromArticle(_context, _word);
    String fullUrl = null;//  w ww .  ja  va 2s .c o  m
    StringBuilder builder = new StringBuilder();
    try {
        fullUrl = String.format(GOOGLE_COMPLETE_URL, _langFrom, _langTo, URLEncoder.encode(newWord, ENCODING));
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
    }
    if (fullUrl == null) {
        return null;
    }
    Set<String> words = new TreeSet<>();
    HttpUriRequest getRequest = new HttpGet(fullUrl);
    try {
        HttpResponse getResponse = client.execute(getRequest);
        HttpEntity resEntityGet = getResponse.getEntity();

        if (resEntityGet != null) {
            InputStream in = resEntityGet.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            try {
                JSONObject jsonReader = new JSONObject(builder.toString());
                JSONArray tuc = jsonReader.getJSONArray("tuc");
                for (int i = 0; i < tuc.length(); i++) {
                    JSONObject obj = tuc.getJSONObject(i);
                    words.add(obj.getJSONObject("phrase").getString("text"));
                }
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
        }
    } catch (IOException ex) {
        Log.e(Constants.LOG_TAG, ex.getMessage());
    }
    return new Pair<String, List<String>>(null, new ArrayList(words));
}

From source file:com.zd.vpn.fragments.AboutFragment.java

private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) {
    try {/*from ww w.  ja  va 2  s.  co m*/
        Vector<Pair<String, String>> gdonation = new Vector<Pair<String, String>>();

        gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore), null));
        HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>();
        for (String thisResponse : responseList) {
            JSONObject object = new JSONObject(thisResponse);
            responseMap.put(object.getString("productId"),
                    new SkuResponse(object.getString("price"), object.getString("title")));

        }
        for (String sku : donationSkus)
            if (responseMap.containsKey(sku))
                gdonation.add(
                        getSkuTitle(sku, responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus));

        String gmsTextString = "";
        for (int i = 0; i < gdonation.size(); i++) {
            if (i == 1)
                gmsTextString += "  ";
            else if (i > 1)
                gmsTextString += ", ";
            gmsTextString += gdonation.elementAt(i).first;
        }
        SpannableString gmsText = new SpannableString(gmsTextString);

        int lStart = 0;
        int lEnd = 0;
        for (Pair<String, String> item : gdonation) {
            lEnd = lStart + item.first.length();
            if (item.second != null) {
                final String mSku = item.second;
                ClickableSpan cspan = new ClickableSpan() {
                    @Override
                    public void onClick(View widget) {
                        triggerBuy(mSku);
                    }
                };
                gmsText.setSpan(cspan, lStart, lEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            lStart = lEnd + 2; // Account for ", " between items
        }

        if (gmsTextView != null) {
            gmsTextView.setText(gmsText);
            gmsTextView.setMovementMethod(LinkMovementMethod.getInstance());
            gmsTextView.setVisibility(View.VISIBLE);
        }

    } catch (JSONException e) {
        VpnStatus.logException("Parsing Play Store IAP", e);
    }

}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.AppMessageHandlerObsidian.java

private byte[] encodeObisdianWeather(WeatherSpec weatherSpec) {

    if (weatherSpec == null) {
        return null;
    }/*w w w .  j ava  2  s.c o m*/

    ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
    boolean isNight = false; //TODO: use the night icons when night
    pairs.add(new Pair<>(messageKeys.get("CONFIG_WEATHER_REFRESH"), (Object) 60));
    pairs.add(new Pair<>(messageKeys.get("CONFIG_WEATHER_UNIT_LOCAL"), (Object) 1)); //celsius
    pairs.add(new Pair<>(messageKeys.get("MSG_KEY_WEATHER_ICON"),
            (Object) getIconForConditionCode(weatherSpec.currentConditionCode, isNight))); //celsius
    pairs.add(new Pair<>(messageKeys.get("MSG_KEY_WEATHER_TEMP"), (Object) (weatherSpec.currentTemp - 273)));

    return mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID,
            pairs);
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.AppMessageHandlerTimeStylePebble.java

private byte[] encodeTimeStylePebbleWeather(WeatherSpec weatherSpec) {

    if (weatherSpec == null) {
        return null;
    }/*w  ww.j  av a  2s.c  o  m*/

    ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
    boolean isNight = false; //TODO: use the night icons when night
    pairs.add(new Pair<>(messageKeys.get("SettingUseMetric"), (Object) 1)); //celsius
    pairs.add(new Pair<>(messageKeys.get("WeatherUseNightIcon"), (Object) (isNight ? 1 : 0)));
    pairs.add(new Pair<>(messageKeys.get("WeatherTemperature"), (Object) (weatherSpec.currentTemp - 273)));
    pairs.add(new Pair<>(messageKeys.get("WeatherCondition"),
            (Object) (getIconForConditionCode(weatherSpec.currentConditionCode, isNight))));
    pairs.add(new Pair<>(messageKeys.get("WeatherForecastCondition"),
            (Object) (getIconForConditionCode(weatherSpec.tomorrowConditionCode, isNight))));
    pairs.add(
            new Pair<>(messageKeys.get("WeatherForecastHighTemp"), (Object) (weatherSpec.todayMaxTemp - 273)));
    pairs.add(new Pair<>(messageKeys.get("WeatherForecastLowTemp"), (Object) (weatherSpec.todayMinTemp - 273)));

    return mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID,
            pairs);
}

From source file:org.droidparts.http.worker.HttpURLConnectionWorker.java

public Pair<Integer, BufferedInputStream> getInputStream(String uri) throws HTTPException {
    HttpURLConnection conn = getConnection(uri, GET);
    HttpURLConnectionWorker.connectAndGetResponseCodeOrThrow(conn);
    int contentLength = conn.getContentLength();
    HTTPInputStream is = HTTPInputStream.getInstance(conn, false);
    return new Pair<Integer, BufferedInputStream>(contentLength, is);
}