Example usage for android.util Pair create

List of usage examples for android.util Pair create

Introduction

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

Prototype

public static <A, B> Pair<A, B> create(A a, B b) 

Source Link

Document

Convenience method for creating an appropriately typed pair.

Usage

From source file:com.facebook.keyframes.sample.MainActivity.java

private void setKFImage(KFImage kfImage) {
    clearImage();/*  w  w  w. j ava 2  s .  com*/
    mKfImage = kfImage;

    final Drawable logoDrawable = getResources().getDrawable(R.drawable.keyframes_launcher);
    if (logoDrawable != null) {
        logoDrawable.setBounds(0, 0, 80, 80);
        mKeyFramesDrawable = new KeyframesDrawableBuilder().withImage(mKfImage).withMaxFrameRate(60)
                .withExperimentalFeatures()
                .withParticleFeatureConfigs(Pair.create("keyframes", Pair.create(logoDrawable, new Matrix())))
                .build();
    }
    mKeyFramesDrawable.startAnimation();

    final ImageView imageView = (ImageView) findViewById(R.id.sample_image_view);
    imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    imageView.setImageDrawable(mKeyFramesDrawable);
}

From source file:org.commcare.android.util.StringUtils.java

/**
 * Identifies whether two strings are close enough that they are likely to be
 * intended to be the same string. Fuzzy matching is only performed on strings that are
 * longer than a certain size./* ww  w  .  j  a  v  a2 s  .c  om*/
 *
 * @return A pair with two values. First value represents a match: true if the two strings
 * meet CommCare's fuzzy match definition, false otherwise. Second value is the actual string
 * distance that was matched, in order to be able to rank or otherwise interpret results.
 */
public static Pair<Boolean, Integer> fuzzyMatch(String source, String target) {
    //tweakable parameter: Minimum length before edit distance
    //starts being used (this is probably not necessary, and
    //basically only makes sure that "at" doesn't match "or" or similar
    if (source.length() > 3) {
        int distance = StringUtils.LevenshteinDistance(source, target);
        //tweakable parameter: edit distance past string length disparity
        if (distance <= 2) {
            return Pair.create(true, distance);
        }
    }
    return Pair.create(false, -1);
}

From source file:com.karura.framework.plugins.WebViewPlugin.java

protected void reject(String callId, int errorCode, String errorMsg, Pair... params)
        throws IllegalArgumentException {
    Pair[] newparams;//from ww w  .j  a  va 2  s  . c om
    if (params == null) {
        newparams = new Pair[2];
    } else {
        newparams = new Pair[params.length + 2];
    }
    newparams[0] = Pair.create("code", errorCode);
    newparams[1] = Pair.create("msg", errorMsg);
    if (params != null) {
        System.arraycopy(params, 0, newparams, 2, params.length);
    }
    reject(callId, newparams);
}

From source file:dev.drsoran.moloko.fragments.dialogs.EstimatePickerDialogFragment.java

private Pair<Integer, Integer> getValueAndUnitFromMillis() {
    final EstimateStruct estimateStruct = MolokoDateUtils.parseEstimated(estimateMillis);

    int value = 1;
    int unit = UNIT_DAY;

    if (estimateStruct.days > 0) {
        value = estimateStruct.days;/*from  w w w.j a  v a  2 s .co  m*/
        unit = UNIT_DAY;
    }

    else if (estimateStruct.hours > 0) {
        value = estimateStruct.hours;
        unit = UNIT_HOUR;
    }

    else if (estimateStruct.minutes > 0) {
        value = estimateStruct.minutes;
        unit = UNIT_MINUTE;
    }

    return Pair.create(Integer.valueOf(value), Integer.valueOf(unit));
}

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

/**
 * Checks whether a Bitmap is a small grayscale icon.
 * Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp".
 *
 * @param bitmap The bitmap to test./*  w w w. j ava  2  s  . c  o m*/
 * @return True if the bitmap is grayscale; false if it is color or too large to examine.
 */
public boolean isGrayscaleIcon(Bitmap bitmap) {
    // quick test: reject large bitmaps
    if (bitmap.getWidth() > mGrayscaleIconMaxSize || bitmap.getHeight() > mGrayscaleIconMaxSize) {
        return false;
    }

    synchronized (sLock) {
        Pair<Boolean, Integer> cached = mGrayscaleBitmapCache.get(bitmap);
        if (cached != null) {
            if (cached.second == bitmap.getGenerationId()) {
                return cached.first;
            }
        }
    }
    boolean result;
    int generationId;
    synchronized (mImageUtils) {
        result = mImageUtils.isGrayscale(bitmap);

        // generationId and the check whether the Bitmap is grayscale can't be read atomically
        // here. However, since the thread is in the process of posting the notification, we can
        // assume that it doesn't modify the bitmap while we are checking the pixels.
        generationId = bitmap.getGenerationId();
    }
    synchronized (sLock) {
        mGrayscaleBitmapCache.put(bitmap, Pair.create(result, generationId));
    }
    return result;
}

From source file:retrovolley.request.RequestBuilder.java

/**
 * Add a request parameter for the request. <br>
 * <b>Note: </b> If {@link RequestBuilder#setBody(java.lang.String)}
 * is called, all parameters will be ignored.
 *
 * @param key   The parameter key//  w  w  w  . ja  v a2s . com
 * @param value The parameter value
 * @return The same builder instance
 */
public RequestBuilder addParam(String key, String value) {
    mParams.add(Pair.create(key, value));
    return this;
}

From source file:com.karura.framework.plugins.WebViewPlugin.java

public void event(String eventName, int timeOut, Object response) {
    event(eventName, timeOut, Pair.create(EVENT_PAYLOAD, response));
}

From source file:it.ms.theing.loquitur.functions.Storage.java

public Vector<Pair<String[], String>> loadCache(String name) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=?", new String[] { name });
    cursor.moveToFirst();/*from  w  w w  . jav  a2  s.com*/
    Vector<Pair<String[], String>> ja = new Vector<Pair<String[], String>>();
    while (!cursor.isAfterLast()) {
        String[] sv = cursor.getString(1).split("\'| ");
        String s = cursor.getString(2);
        Pair<String[], String> p = Pair.create(sv, s);
        ja.add(p);
        cursor.moveToNext();
    }
    return ja;
}

From source file:org.herrlado.websms.connector.smsge.ConnectorSmsge.java

private static Pair<String, String> getUidSys(String content) {
    int uididx = content.indexOf("uid");
    uididx = content.indexOf("value=\"", uididx);
    uididx += 7;//from w w w.  j  a  v  a  2 s . c  om
    int uididx2 = content.indexOf("\"", uididx);
    String uid = content.substring(uididx, uididx2);
    int sysidx = content.indexOf("sys", uididx + uid.length() + 1);
    sysidx = content.indexOf("value=\"", sysidx);
    sysidx += 7;
    int sysidx2 = content.indexOf("\"", sysidx);
    String sys = content.substring(sysidx, sysidx2);
    return Pair.create(uid, sys);
}

From source file:retrovolley.request.RequestBuilder.java

/**
 * Add an array parameter for the request. <br>
 * <b>Note: </b> If {@link RequestBuilder#setBody(java.lang.String)}
 * is called, all parameters will be ignored.
 *
 * @param key   The array parameter key/*from w w w . ja v  a 2  s.  c  om*/
 * @param values The array parameter values
 * @return The same builder instance
 */
public RequestBuilder addParams(String key, Iterable<String> values) {
    for (String value : values) {
        mParams.add(Pair.create(key, value));
    }
    return this;
}