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:piuk.blockchain.android.ui.SendCoinsFragment.java

public List<Pair<String, String>> getLabelList() {
    List<Pair<String, String>> array = new ArrayList<Pair<String, String>>();

    if (application.getRemoteWallet() == null) {
        return array;
    }/*from   w  w  w  .j  a  v a 2  s. c o m*/

    Map<String, String> labelMap = application.getRemoteWallet().getLabelMap();

    synchronized (labelMap) {
        for (Map.Entry<String, String> entry : labelMap.entrySet()) {
            array.add(new Pair<String, String>(entry.getValue(), entry.getKey()) {
                public String toString() {
                    return first.toString();
                }
            });
        }
    }

    return array;
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

private void toggleRegPermissions(PackingItem packingItem, int row) {
    PackageInfo packInfo = packingItem.m_packInfo;
    ArrayListPairString valueListStr = packingItem.valueListStr();
    row++;//from   w  w  w.  jav a2  s .co  m
    if (row < valueListStr.size() && valueListStr.get(row).first.startsWith(PERM_PREFIX)) {
        do {
            if (valueListStr.get(row).first.startsWith(PERM_PREFIX)) {
                valueListStr.remove(row);
            } else {
                break;
            }
        } while (row < valueListStr.size());
    } else {
        for (int pidx = 0; pidx != packInfo.requestedPermissions.length; pidx++) {
            String perm = packInfo.requestedPermissions[pidx].replaceAll("[a-z.]*", "");
            if (perm.length() > 30)
                perm = perm.substring(0, 30);
            valueListStr.add(row++, new Pair<String, String>(String.format("  %2d", pidx), perm));
        }
    }
}

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

/**
 * @return List of Pair("dupestr", List[nids])
 *//*from   w  w w. j  a v a  2 s  . com*/
public static List<Pair<String, List<Long>>> findDupes(Collection col, String fieldName, String search) {
    // limit search to notes with applicable field name
    if (!TextUtils.isEmpty(search)) {
        search = "(" + search + ") ";
    }
    search += "'" + fieldName + ":*'";
    // go through notes
    Map<String, List<Long>> vals = new HashMap<String, List<Long>>();
    List<Pair<String, List<Long>>> dupes = new ArrayList<Pair<String, List<Long>>>();
    Map<Long, Integer> fields = new HashMap<Long, Integer>();
    Cursor cur = null;
    try {
        cur = col.getDb().getDatabase().rawQuery(
                "select id, mid, flds from notes where id in " + Utils.ids2str(col.findNotes(search)), null);
        while (cur.moveToNext()) {
            long nid = cur.getLong(0);
            long mid = cur.getLong(1);
            String[] flds = Utils.splitFields(cur.getString(2));
            Integer ord = ordForMid(col, fields, mid, fieldName);
            if (ord == null) {
                continue;
            }
            String val = flds[fields.get(mid)];
            val = Utils.stripHTMLMedia(val);
            // empty does not count as duplicate
            if (TextUtils.isEmpty(val)) {
                continue;
            }
            if (!vals.containsKey(val)) {
                vals.put(val, new ArrayList<Long>());
            }
            vals.get(val).add(nid);
            if (vals.get(val).size() == 2) {
                dupes.add(new Pair<String, List<Long>>(val, vals.get(val)));
            }
        }
    } finally {
        if (cur != null) {
            cur.close();
        }
    }
    return dupes;
}

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

/**
 * Updates a registration//from  www.ja v  a  2s. c  o m
 *
 * @param registration The registration to update
 * @param callback     The operation callback
 * @throws java.io.UnsupportedEncodingException
 * @throws Exception
 */
private ListenableFuture<Void> upsertRegistrationInternal(final Registration registration) {

    final SettableFuture<Void> resultFuture = SettableFuture.create();

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder = gsonBuilder.excludeFieldsWithoutExposeAnnotation();

    Gson gson = gsonBuilder.create();

    String resource = registration.getURI();
    String path = PNS_API_URL + resource;
    JsonElement json = gson.toJsonTree(registration);
    String body = json.toString();

    byte[] content;
    try {
        content = body.getBytes(MobileServiceClient.UTF8_ENCODING);
    } catch (UnsupportedEncodingException e) {
        resultFuture.setException(e);
        return resultFuture;
    }

    List<Pair<String, String>> requestHeaders = new ArrayList<Pair<String, String>>();

    requestHeaders.add(new Pair<String, String>(HTTP.CONTENT_TYPE, MobileServiceConnection.JSON_CONTENTTYPE));

    ListenableFuture<ServiceFilterResponse> serviceFilterFuture = mHttpClient.request(path, content, "PUT",
            requestHeaders, null);

    Futures.addCallback(serviceFilterFuture, new FutureCallback<ServiceFilterResponse>() {
        @Override
        public void onFailure(Throwable exception) {
            resultFuture.setException(exception);
        }

        @Override
        public void onSuccess(ServiceFilterResponse response) {
            resultFuture.set(null);
        }
    });

    return resultFuture;
}

From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java

private void buildLinksSection(Cursor cursor) {
    final Context context = mRootView.getContext();

    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container);
    linkContainer.removeAllViews();/*  w  w w  .j a v  a 2s  .c o m*/

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(context);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(R.string.session_link_livestream, getWatchLiveIntent(context)));
    }

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    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, Object>(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, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            if (link.first == R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } 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);
    }

}

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

public HashMap<String, String> _renderQA(Object[] data, String qfmt, String afmt) {
    // data is [cid, nid, mid, did, ord, tags, flds]
    // unpack fields and create dict
    String[] flist = Utils.splitFields((String) data[6]);
    Map<String, String> fields = new HashMap<String, String>();
    JSONObject model = mModels.get((Long) data[2]);
    Map<String, Pair<Integer, JSONObject>> fmap = mModels.fieldMap(model);
    for (String name : fmap.keySet()) {
        fields.put(name, flist[fmap.get(name).first]);
    }//from w w w .j  a  v  a  2 s.  c o m
    try {
        int cardNum = ((Integer) data[4]) + 1;
        fields.put("Tags", ((String) data[5]).trim());
        fields.put("Type", (String) model.get("name"));
        fields.put("Deck", mDecks.name((Long) data[3]));
        String[] parents = fields.get("Deck").split("::", -1);
        fields.put("Subdeck", parents[parents.length - 1]);
        JSONObject template;
        if (model.getInt("type") == Consts.MODEL_STD) {
            template = model.getJSONArray("tmpls").getJSONObject((Integer) data[4]);
        } else {
            template = model.getJSONArray("tmpls").getJSONObject(0);
        }
        fields.put("Card", template.getString("name"));
        fields.put(String.format(Locale.US, "c%d", cardNum), "1");
        // render q & a
        HashMap<String, String> d = new HashMap<String, String>();
        d.put("id", Long.toString((Long) data[0]));
        qfmt = TextUtils.isEmpty(qfmt) ? template.getString("qfmt") : qfmt;
        afmt = TextUtils.isEmpty(afmt) ? template.getString("afmt") : afmt;
        for (Pair<String, String> p : new Pair[] { new Pair<String, String>("q", qfmt),
                new Pair<String, String>("a", afmt) }) {
            String type = p.first;
            String format = p.second;
            if (type.equals("q")) {
                format = fClozePatternQ.matcher(format)
                        .replaceAll(String.format(Locale.US, "{{$1cq-%d:", cardNum));
                format = fClozeTagStart.matcher(format)
                        .replaceAll(String.format(Locale.US, "<%%cq:%d:", cardNum));
            } else {
                format = fClozePatternA.matcher(format)
                        .replaceAll(String.format(Locale.US, "{{$1ca-%d:", cardNum));
                format = fClozeTagStart.matcher(format)
                        .replaceAll(String.format(Locale.US, "<%%ca:%d:", cardNum));
                // the following line differs from libanki // TODO: why?
                fields.put("FrontSide", d.get("q")); // fields.put("FrontSide", mMedia.stripAudio(d.get("q")));
            }
            fields = (Map<String, String>) Hooks.runFilter("mungeFields", fields, model, data, this);
            String html = new Template(format, fields).render();
            d.put(type, (String) Hooks.runFilter("mungeQA", html, type, fields, model, data, this));
            // empty cloze?
            if (type.equals("q") && model.getInt("type") == Consts.MODEL_CLOZE) {
                if (getModels()._availClozeOrds(model, (String) data[6], false).size() == 0) {
                    String link = String.format("<a href=%s#cloze>%s</a>", Consts.HELP_SITE, "help");
                    d.put("q", String.format("Please edit this note and add some cloze deletions. (%s)", link));
                }
            }
        }
        return d;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java

private void buildLinksSection(Cursor cursor) {
    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) findViewById(R.id.links_container);
    linkContainer.removeAllViews();//from   w w w .  j  a v a  2s . c o m

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(this);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(R.string.session_link_livestream, getWatchLiveIntent(this)));
    }

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    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, Object>(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(this);
        int columns = getResources().getInteger(R.integer.links_columns);

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

            // Create link view
            TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer,
                    false);
            if (link.first == R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } 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);
            }
        }

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

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

}

From source file:com.landenlabs.all_devtool.PackageFragment.java

private void togglePermissions(PackingItem packingItem, int row) {
    PackageInfo packInfo = packingItem.m_packInfo;
    ArrayListPairString valueListStr = packingItem.valueListStr();
    row++;//from   w w w .ja  v  a2s  .c om
    if (row < valueListStr.size() && valueListStr.get(row).first.startsWith(PERM_PREFIX)) {
        do {
            if (valueListStr.get(row).first.startsWith(PERM_PREFIX)) {
                valueListStr.remove(row);
            } else {
                break;
            }
        } while (row < valueListStr.size());
    } else {
        for (int pidx = 0; pidx != packInfo.permissions.length; pidx++) {
            PermissionInfo pInfo = packInfo.permissions[pidx];
            String perm = pInfo.name.replaceAll("[a-z.]*", "");
            if (perm.length() > 30)
                perm = perm.substring(0, 30);
            valueListStr.add(row++, new Pair<String, String>(String.format("  %2d", pidx), perm));
        }
    }
}

From source file:com.owncloud.android.services.OperationsService.java

/**
 * Notifies the currently subscribed listeners about the end of an operation.
 *
 * @param operation         Finished operation.
 * @param result            Result of the operation.
 *//*from w w w .  j  av  a 2s  .c  om*/
protected void dispatchResultToOperationListeners(final RemoteOperation operation,
        final RemoteOperationResult result) {
    int count = 0;
    Iterator<OnRemoteOperationListener> listeners = mOperationsBinder.mBoundListeners.keySet().iterator();
    while (listeners.hasNext()) {
        final OnRemoteOperationListener listener = listeners.next();
        final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    listener.onRemoteOperationFinish(operation, result);
                }
            });
            count += 1;
        }
    }
    if (count == 0) {
        Pair<RemoteOperation, RemoteOperationResult> undispatched = new Pair<>(operation, result);
        mUndispatchedFinishedOperations.put(operation.hashCode(), undispatched);
    }
    Log_OC.d(TAG, "Called " + count + " listeners");
}

From source file:com.microsoft.windowsazure.mobileservices.table.MobileServiceTableBase.java

/**
 * Adds the tables requested system properties to the parameters collection.
 *
 * @param systemProperties The system properties to add.
 * @param parameters       The parameters collection.
 * @return The parameters collection with any requested system properties
 * included.//from w w w.j  av a2  s.  com
 */
public List<Pair<String, String>> addSystemProperties(EnumSet<MobileServiceSystemProperty> systemProperties,
        List<Pair<String, String>> parameters) {
    boolean containsSystemProperties = false;

    List<Pair<String, String>> result = new ArrayList<Pair<String, String>>(
            parameters != null ? parameters.size() : 0);

    // Make sure we have a case-insensitive parameters list
    if (parameters != null) {
        for (Pair<String, String> parameter : parameters) {
            result.add(parameter);
            containsSystemProperties = containsSystemProperties
                    || parameter.first.equalsIgnoreCase(SystemPropertiesQueryParameterName);
        }
    }

    // If there is already a user parameter for the system properties, just
    // use it
    if (!containsSystemProperties) {
        String systemPropertiesString = getSystemPropertiesString(systemProperties);

        if (systemPropertiesString != null) {
            result.add(new Pair<String, String>(SystemPropertiesQueryParameterName, systemPropertiesString));
        }
    }

    return result;
}