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.taobao.weex.ui.animation.TransformParser.java

private static Pair<Float, Float> parsePivot(@NonNull List<String> list, int width, int height, int viewportW) {
    return new Pair<>(parsePivotX(list.get(0), width, viewportW), parsePivotY(list.get(1), height, viewportW));
}

From source file:com.fbartnitzek.tasteemall.showentry.ShowReviewFragment.java

@Override
public void onClick(View v) {
    //        Log.v(LOG_TAG, "onClick, mProducer_Id=" + mProducer_Id + ", mDrink_Id=" + mDrink_Id + ", mLocation_Id=" + mLocation_Id);
    if (v.getId() == R.id.producer_name && mProducer_Id > -1) { // open producer
        Bundle bundle = null;//from ww w  .  j  ava2s .c om
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            bundle = ActivityOptions
                    .makeSceneTransitionAnimation(getActivity(),
                            new Pair<View, String>(mProducerNameView,
                                    getString(R.string.shared_transition_producer_producer) + mProducer_Id))
                    .toBundle();
        }
        startActivity(new Intent(getActivity(), ShowProducerActivity.class)
                .setData(DatabaseContract.ProducerEntry.buildUri(mProducer_Id)), bundle);
    } else if (v.getId() == R.id.drink_name && mDrink_Id > -1) { // open drink
        Bundle bundle = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            bundle = ActivityOptions.makeSceneTransitionAnimation(getActivity(),
                    new Pair<View, String>(mProducerNameView,
                            getString(R.string.shared_transition_drink_producer) + mDrink_Id),
                    new Pair<View, String>(mDrinkNameView,
                            getString(R.string.shared_transition_drink_drink) + mDrink_Id))
                    .toBundle();
        }
        startActivity(new Intent(getActivity(), ShowDrinkActivity.class)
                .setData(DatabaseContract.DrinkEntry.buildUri(mDrink_Id)), bundle);
    } else if (v.getId() == R.id.review_location && mLocation_Id > -1) {
        startActivity(new Intent(getActivity(), ShowLocationActivity.class)
                .setData(DatabaseContract.LocationEntry.buildUri(mLocation_Id)));
    } else if (v.getId() == R.id.fab_share && mProducer_Id > -1) { // all loaded
        shareReview();
    }
}

From source file:ua.org.gdg.devfest.iosched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *//*from   ww w . ja va  2  s.c om*/
private void onSessionQueryComplete(Cursor cursor) {
    mSessionCursor = true;
    if (!cursor.moveToFirst()) {
        if (isAdded()) {
            // TODO: Remove this in favor of a callbacks interface that the activity
            // can implement.
            getActivity().finish();
        }
        return;
    }

    mTitleString = cursor.getString(SessionsQuery.TITLE);

    // Format time block this session occupies
    mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START);
    mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
    String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
    final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd,
            roomName, mBuffer, getActivity());

    mTitle.setText(mTitleString);

    mUrl = cursor.getString(SessionsQuery.URL);
    if (TextUtils.isEmpty(mUrl)) {
        mUrl = "";
    }

    mHashtags = cursor.getString(SessionsQuery.HASHTAGS);
    if (!TextUtils.isEmpty(mHashtags)) {
        enableSocialStreamMenuItemDeferred();
    }

    mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

    setupShareMenuItemDeferred();
    showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false);

    final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
    if (!TextUtils.isEmpty(sessionAbstract)) {
        UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
        mAbstract.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        mAbstract.setVisibility(View.GONE);
    }

    final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
    final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
    if (!TextUtils.isEmpty(sessionRequirements)) {
        UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
        requirementsBlock.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        requirementsBlock.setVisibility(View.GONE);
    }

    // Show empty message when all data is loaded, and nothing to show
    if (mSpeakersCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }

    // Compile list of links (submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    final Context context = mRootView.getContext();

    List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>();

    // Add session feedback link
    if (getResources().getBoolean(R.bool.has_feedback_enabled)) {
        links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink,
                new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class)));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(context);
        int columns = context.getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Intent> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    try {
                        startActivity(link.second);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.GONE);
    }

    // Show past/present/future and livestream status for this block.
    UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle);

    LOGD("Tracker", "Session: " + mTitleString);
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *//*from   www.j  a  va2  s . co  m*/
private void onSessionQueryComplete(Cursor cursor) {
    mSessionCursor = true;
    if (!cursor.moveToFirst()) {
        if (isAdded()) {
            // TODO: Remove this in favor of a callbacks interface that the activity
            // can implement.
            getActivity().finish();
        }
        return;
    }

    mTitleString = cursor.getString(SessionsQuery.TITLE);

    // Format time block this session occupies
    mType = cursor.getString(SessionsQuery.TYPE);
    mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START);
    mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
    String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
    final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd,
            roomName, mBuffer, getActivity());

    mTitle.setText(mTitleString);

    mUrl = cursor.getString(SessionsQuery.URL);
    if (TextUtils.isEmpty(mUrl)) {
        mUrl = "";
    }

    mHashtags = cursor.getString(SessionsQuery.HASHTAGS);
    if (!TextUtils.isEmpty(mHashtags)) {
        enableSocialStreamMenuItemDeferred();
    }

    mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

    setupShareMenuItemDeferred();
    showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false);

    final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
    if (!TextUtils.isEmpty(sessionAbstract)) {
        UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
        mAbstract.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        mAbstract.setVisibility(View.GONE);
    }

    final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
    final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
    if (!TextUtils.isEmpty(sessionRequirements)) {
        UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
        requirementsBlock.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
    } else {
        requirementsBlock.setVisibility(View.GONE);
    }

    // Show empty message when all data is loaded, and nothing to show
    if (mSpeakersCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }

    // Compile list of links (submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();

    final Context context = mRootView.getContext();

    List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>();

    // Add session feedback link
    if (getResources().getBoolean(R.bool.has_session_feedback_enabled)) {
        links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink,
                new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class)));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(context);
        int columns = context.getResources().getInteger(R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Intent> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    try {
                        startActivity(link.second);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row,
                            linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE);
        mRootView.findViewById(R.id.links_container).setVisibility(View.GONE);
    }

    // Show past/present/future and livestream status for this block.
    UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle);

    LOGD("Tracker", "Session: " + mTitleString);
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java

public void testJsonTableInsertWithParametersFeatureHeader() {
    testTableFeatureHeader(new TableTestOperation() {

        @Override/*from   w w  w. ja  v a  2s.c  om*/
        public void executeOperation(MobileServiceTable<PersonTestObjectWithStringId> typedTable,
                MobileServiceJsonTable jsonTable) throws Exception {
            JsonObject jo = createJsonObject();
            List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>();
            queryParams.add(new Pair<String, String>("a", "b"));
            jsonTable.insert(jo, queryParams).get();
        }
    }, false, "QS,TU");
}

From source file:com.appeaser.sublimepicker.Sampler.java

Pair<Boolean, SublimeOptions> getOptions() {
    SublimeOptions options = new SublimeOptions();
    int displayOptions = 0;

    if (cbDatePicker.isChecked()) {
        displayOptions |= SublimeOptions.ACTIVATE_DATE_PICKER;
    }/*from  ww  w. jav a  2 s.c o m*/

    if (cbTimePicker.isChecked()) {
        displayOptions |= SublimeOptions.ACTIVATE_TIME_PICKER;
    }

    if (cbRecurrencePicker.isChecked()) {
        displayOptions |= SublimeOptions.ACTIVATE_RECURRENCE_PICKER;
    }

    if (rbDatePicker.getVisibility() == View.VISIBLE && rbDatePicker.isChecked()) {
        options.setPickerToShow(SublimeOptions.Picker.DATE_PICKER);
    } else if (rbTimePicker.getVisibility() == View.VISIBLE && rbTimePicker.isChecked()) {
        options.setPickerToShow(SublimeOptions.Picker.TIME_PICKER);
    } else if (rbRecurrencePicker.getVisibility() == View.VISIBLE && rbRecurrencePicker.isChecked()) {
        options.setPickerToShow(SublimeOptions.Picker.REPEAT_OPTION_PICKER);
    }

    options.setDisplayOptions(displayOptions);

    // Enable/disable the date range selection feature
    options.setCanPickDateRange(cbAllowDateRangeSelection.isChecked());

    // Example for setting date range:
    // Note that you can pass a date range as the initial date params
    // even if you have date-range selection disabled. In this case,
    // the user WILL be able to change date-range using the header
    // TextViews, but not using long-press.

    /*Calendar startCal = Calendar.getInstance();
    startCal.set(2016, 2, 4);
    Calendar endCal = Calendar.getInstance();
    endCal.set(2016, 2, 17);
            
    options.setDateParams(startCal, endCal);*/

    // If 'displayOptions' is zero, the chosen options are not valid
    return new Pair<>(displayOptions != 0 ? Boolean.TRUE : Boolean.FALSE, options);
}

From source file:com.microsoft.windowsazure.mobileservices.MobileServicePush.java

private void getFullRegistrationInformation(String pnsHandle,
        final GetFullRegistrationInformationCallback callback) {
    if (isNullOrWhiteSpace(pnsHandle)) {
        callback.onCompleted(null, new IllegalArgumentException("pnsHandle"));
        return;//from   w w w. java 2  s .c o  m
    }

    // get existing registrations
    String resource = "/registrations/";

    List<Pair<String, String>> requestHeaders = new ArrayList<Pair<String, String>>();
    List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>();
    parameters.add(new Pair<String, String>("platform", mPnsSpecificRegistrationFactory.getPlatform()));
    parameters.add(new Pair<String, String>("deviceId", pnsHandle));
    requestHeaders.add(new Pair<String, String>(HTTP.CONTENT_TYPE, MobileServiceConnection.JSON_CONTENTTYPE));

    mClient.invokeApiInternal(resource, null, "GET", requestHeaders, parameters,
            MobileServiceClient.PNS_API_URL, new ServiceFilterResponseCallback() {

                @Override
                public void onResponse(ServiceFilterResponse response, Exception exception) {
                    if (exception != null) {
                        callback.onCompleted(null, exception);

                        return;
                    } else {

                        ArrayList<Registration> registrationsList = new ArrayList<Registration>();

                        JsonArray registrations = new JsonParser().parse(response.getContent())
                                .getAsJsonArray();

                        for (JsonElement registrationJson : registrations) {
                            Registration registration = null;
                            if (registrationJson.getAsJsonObject().has("templateName")) {
                                registration = mPnsSpecificRegistrationFactory
                                        .parseTemplateRegistration(registrationJson.getAsJsonObject());
                            } else {
                                registration = mPnsSpecificRegistrationFactory
                                        .parseNativeRegistration(registrationJson.getAsJsonObject());
                            }

                            registrationsList.add(registration);
                        }

                        callback.onCompleted(registrationsList, null);

                        return;
                    }
                }
            });
}

From source file:dev.drsoran.moloko.sync.SyncAdapter.java

private final Pair<Long, Long> getSyncTime() {
    Pair<Long, Long> result = null;

    final ContentProviderClient client = context.getContentResolver()
            .acquireContentProviderClient(Sync.CONTENT_URI);

    if (client != null) {
        result = SyncProviderPart.getLastInAndLastOut(client);

        client.release();//from w  w w . j a v  a  2  s.  c o  m

        if (result != null) {
            // SPECIAL CASE: We check the returned dates. In case the device clock
            // was adjusted, we may have stored a date that is way too far in the
            // future. This may break the incremental sync for a long time. In this case we do a
            // full sync and store the new date.
            if ((result.first != null && result.first > System.currentTimeMillis())
                    || (result.second != null && result.second > System.currentTimeMillis())) {
                result = new Pair<Long, Long>(null, null);
            }
        } else {
            MolokoApp.Log.e(TAG, LogUtils.GENERIC_DB_ERROR);
        }
    }

    return result;
}

From source file:com.ichi2.libanki.Finder.java

/**
 * Ordering/*  w ww.ja  v  a 2 s .  c  om*/
 * ***********************************************************
 */

/*
 * NOTE: In the python code, _order() follows a code path based on:
 * - Empty order string (no order)
 * - order = False (no order)
 * - Non-empty order string (custom order)
 * - order = True (built-in order)
 * The python code combines all code paths in one function. In Java, we must overload the method
 * in order to consume either a String (no order, custom order) or a Boolean (no order, built-in order).
 */

private Pair<String, Boolean> _order(String order) {
    if (TextUtils.isEmpty(order)) {
        return _order(false);
    } else {
        // custom order string provided
        return new Pair<String, Boolean>(" order by " + order, false);
    }
}

From source file:com.ichi2.libanki.Finder.java

private Pair<String, Boolean> _order(Boolean order) {
    if (!order) {
        return new Pair<String, Boolean>("", false);
    }/*from  w w  w  . j ava2  s . co  m*/
    try {
        // use deck default
        String type = mCol.getConf().getString("sortType");
        String sort = null;
        if (type.startsWith("note")) {
            if (type.startsWith("noteCrt")) {
                sort = "n.id, c.ord";
            } else if (type.startsWith("noteMod")) {
                sort = "n.mod, c.ord";
            } else if (type.startsWith("noteFld")) {
                sort = "n.sfld COLLATE NOCASE, c.ord";
            }
        } else if (type.startsWith("card")) {
            if (type.startsWith("cardMod")) {
                sort = "c.mod";
            } else if (type.startsWith("cardReps")) {
                sort = "c.reps";
            } else if (type.startsWith("cardDue")) {
                sort = "c.type, c.due";
            } else if (type.startsWith("cardEase")) {
                sort = "c.factor";
            } else if (type.startsWith("cardLapses")) {
                sort = "c.lapses";
            } else if (type.startsWith("cardIvl")) {
                sort = "c.ivl";
            }
        }
        if (sort == null) {
            // deck has invalid sort order; revert to noteCrt
            sort = "n.id, c.ord";
        }
        boolean sortBackwards = mCol.getConf().getBoolean("sortBackwards");
        return new Pair<String, Boolean>(" ORDER BY " + sort, sortBackwards);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}