Example usage for android.support.v4.util Pair Pair

List of usage examples for android.support.v4.util Pair Pair

Introduction

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

Prototype

public Pair(F f, S s) 

Source Link

Usage

From source file:Main.java

private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) {
    if (view == null) {
        return;//from   ww w  . j a  v a 2s  .c om
    }
    participants.add(new Pair<>(view, view.getTransitionName()));
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) {
    if (view == null)
        return;//from w  w  w  .j av  a2 s .c  o  m
    participants.add(new Pair<>(view, view.getTransitionName()));
}

From source file:com.manaschaudhari.android_mvvm.sample.utils.RxUtils.java

@NonNull
public static <T> Pair<Observable<T>, Observable<Boolean>> trackActivity(@NonNull final Observable<T> source) {
    final BehaviorSubject<Integer> count = BehaviorSubject.createDefault(0);
    return new Pair<>(Observable.using(new Callable<Integer>() {
        @Override//from  w w w  . j  av a 2 s .  c  o m
        public Integer call() throws Exception {
            count.onNext(count.getValue() + 1);
            return null;
        }
    }, new Function<Integer, ObservableSource<? extends T>>() {
        @Override
        public ObservableSource<? extends T> apply(Integer integer) throws Exception {
            return source;
        }
    }, new Consumer<Integer>() {
        @Override
        public void accept(Integer integer) throws Exception {
            count.onNext(count.getValue() - 1);
        }
    }), count.map(new Function<Integer, Boolean>() {
        @Override
        public Boolean apply(Integer integer) throws Exception {
            return integer > 0;
        }
    }));
}

From source file:org.bubenheimer.android.preference.EditNonNegIntPreference.java

private static Pair<Integer, Integer> extractMinMax(final Context context, final AttributeSet attrs) {
    final int min;
    final int max;
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditNonNegIntPreference,
            0, 0);// ww  w .  j a v a 2 s .  c  om
    try {
        min = a.getInteger(R.styleable.EditNonNegIntPreference_min, 0);
        max = a.getInteger(R.styleable.EditNonNegIntPreference_max, Integer.MAX_VALUE);
    } finally {
        a.recycle();
    }
    return new Pair<>(min, max);
}

From source file:it.cosenonjaviste.twowaydatabinding.DataBindingConverters.java

@BindingAdapter({ "app:binding" })
public static void bindEditText(EditText view, final ObservableString observableString) {
    Pair<ObservableString, TextWatcherAdapter> pair = (Pair) view.getTag(R.id.bound_observable);
    if (pair == null || pair.first != observableString) {
        if (pair != null) {
            view.removeTextChangedListener(pair.second);
        }/*w w  w  .  ja va 2s .com*/
        TextWatcherAdapter watcher = new TextWatcherAdapter() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                observableString.set(s.toString());
            }
        };
        view.setTag(R.id.bound_observable, new Pair<>(observableString, watcher));
        view.addTextChangedListener(watcher);
    }
    String newValue = observableString.get();
    if (!view.getText().toString().equals(newValue)) {
        view.setText(newValue);
    }
}

From source file:by.gdgminsk.animationguide.util.AnimUtils.java

@SuppressWarnings("unchecked")
public static ActivityOptionsCompat makeSharedViewOptions(Activity activity, View... views) {
    List<Pair<View, String>> sharedPairs = new ArrayList<>();
    for (View view : views) {
        sharedPairs.add(new Pair<>(view, ViewCompat.getTransitionName(view)));
    }//  w  w  w.  j  a va  2 s .c  o m

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // always add status bar and navigation bar to shared element transition to play shared views animation
        // without UI glitch described here https://plus.google.com/+AlexLockwood/posts/RPtwZ5nNebb
        View decor = activity.getWindow().getDecorView();
        View statusBar = decor.findViewById(android.R.id.statusBarBackground);
        if (statusBar != null) {
            sharedPairs.add(new Pair<>(statusBar, ViewCompat.getTransitionName(statusBar)));
        }
        View navBar = decor.findViewById(android.R.id.navigationBarBackground);
        if (navBar != null) {
            sharedPairs.add(new Pair<>(navBar, ViewCompat.getTransitionName(navBar)));
        }
    }

    return ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
            sharedPairs.toArray(new Pair[sharedPairs.size()]));
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) {
    if (view == null) {
        return;//from w  w w. j a  v a  2  s  .c om
    }
    participants.add(new Pair<>(view, view.getTransitionName()));
}

From source file:com.nerderylabs.android.nerdalert.util.ProfileUtil.java

public static Pair<String, Bitmap> getUserProfile(Context context) {
    String name = "";
    String photo = "";

    Cursor c = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
    if (c != null && c.moveToFirst()) {
        String[] columnNames = c.getColumnNames();
        for (String columnName : columnNames) {
            String columnValue = c.getString(c.getColumnIndex(columnName));
            if (columnName.equals(ContactsContract.Profile.DISPLAY_NAME)) {
                if (columnValue != null) {
                    name = columnValue;//from   ww  w  .  j  a  v a2 s .c om
                }
            } else if (columnName.equals(ContactsContract.Profile.PHOTO_URI)) {
                if (columnValue != null) {
                    photo = columnValue;
                }
            }
        }
        c.close();
    }

    Log.d(TAG, "name: " + name + " | photo: " + photo);

    Bitmap bitmap = loadBitmapFromUriString(context, photo);

    return new Pair<>(name, bitmap);
}

From source file:im.neon.util.PhoneNumberUtils.java

/**
 * Build the country codes list//from w ww.j  a v a 2s.  co m
 */
private static void buildCountryCodesList() {
    if (null == mCountryCodes) {
        // retrieve the ISO country code
        String[] isoCountryCodes = Locale.getISOCountries();
        List<Pair<String, String>> countryCodes = new ArrayList<>();

        // retrieve the human display name
        for (String countryCode : isoCountryCodes) {
            Locale locale = new Locale("", countryCode);
            countryCodes.add(new Pair<>(countryCode, locale.getDisplayCountry()));
        }

        // sort by human display names
        Collections.sort(countryCodes, new Comparator<Pair<String, String>>() {
            @Override
            public int compare(Pair<String, String> lhs, Pair<String, String> rhs) {
                return lhs.second.compareTo(rhs.second);
            }
        });

        mCountryNameByCC = new HashMap<>(isoCountryCodes.length);
        mCountryCodes = new String[isoCountryCodes.length];
        mCountryNames = new String[isoCountryCodes.length];

        for (int index = 0; index < isoCountryCodes.length; index++) {
            Pair<String, String> pair = countryCodes.get(index);

            mCountryCodes[index] = pair.first;
            mCountryNames[index] = pair.second;
            mCountryNameByCC.put(pair.first, pair.second);
        }
    }
}

From source file:org.fs.todo.commons.modules.ActivityModule.java

@Provides
public StateToDoAdapter provideStateAdapter() {
    return new StateToDoAdapter(view.provideFragmentManager(),
            Arrays.asList(new Pair<>(DisplayOptions.ALL, "ALL"), new Pair<>(DisplayOptions.ACTIVE, "ACTIVE"),
                    new Pair<>(DisplayOptions.INACTIVE, "INACTIVE")));
}