List of usage examples for android.util Pair create
public static <A, B> Pair<A, B> create(A a, B b)
From source file:org.openhab.habdroid.ui.activity.ContentController.java
/** * Follow a link in a sitemap page// w ww.j ava 2 s . co m * Sets up UI to show the contents of the given page * * @param page Page link to follow * @param source Fragment this action was triggered from */ public void openPage(OpenHABLinkedPage page, OpenHABWidgetListFragment source) { Log.d(TAG, "Opening page " + page); OpenHABWidgetListFragment f = makePageFragment(page); while (!mPageStack.isEmpty() && mPageStack.peek().second != source) { mPageStack.pop(); } mPageStack.push(Pair.create(page, f)); handleNewWidgetFragment(f); mActivity.setProgressIndicatorVisible(true); }
From source file:org.herrlado.websms.connector.smsge.ConnectorSmsge.java
private Pair<String, String> normalizeNumber(String number) { if (number.startsWith("00995")) { number = number.substring(5);// w w w. ja va 2s.co m } else if (number.startsWith("+995")) { number = number.substring(4); } if (number.startsWith("5") == false) { throw new WebSMSException("Not a valid recipient!"); } return Pair.create("995" + number.substring(0, 3), number.substring(3)); }
From source file:com.renard.ocr.help.OCRLanguageActivity.java
public static final List<Pair<String, Long>> getInstalledLanguages(Context appContext) { final List<Pair<String, Long>> result = new ArrayList<Pair<String, Long>>(); final File tessDir = Util.getTrainingDataDir(appContext); if (!tessDir.exists()) { return result; }/*from w ww . j av a 2s . co m*/ final String[] languageFiles = tessDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(".traineddata")) { return true; } return false; } }); for (final String val : languageFiles) { final int dotIndex = val.indexOf('.'); if (dotIndex > -1) { File f = new File(tessDir, val); result.add(Pair.create(val.substring(0, dotIndex), f.length())); } } return result; }
From source file:io.plaidapp.ui.FeedAdapter.java
@NonNull private DesignerNewsStoryHolder createDesignerNewsStoryHolder(ViewGroup parent) { final DesignerNewsStoryHolder holder = new DesignerNewsStoryHolder( layoutInflater.inflate(R.layout.designer_news_story_item, parent, false), pocketIsInstalled); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override/*from ww w.j a v a2 s .co m*/ public void onClick(View v) { final Story story = (Story) getItem(holder.getAdapterPosition()); CustomTabActivityHelper.openCustomTab(host, DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url)); } }); holder.comments.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View commentsView) { final Intent intent = new Intent(); intent.setClass(host, DesignerNewsStory.class); intent.putExtra(DesignerNewsStory.EXTRA_STORY, (Story) getItem(holder.getAdapterPosition())); setGridItemContentTransitions(holder.itemView); final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)), Pair.create(holder.itemView, host.getString(R.string.transition_story_background))); host.startActivity(intent, options.toBundle()); } }); if (pocketIsInstalled) { holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble... holder.pocket.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { PocketUtils.addToPocket(host, ((Story) getItem(holder.getAdapterPosition())).url); // notify changed with a payload asking RV to run the anim notifyItemChanged(holder.getAdapterPosition(), HomeGridItemAnimator.ANIMATE_ADD_POCKET); } }); } return holder; }
From source file:org.chromium.android_webview.test.AwContentsTest.java
@SmallTest @Feature({ "AndroidWebView" }) public void testClearCacheMemoryAndDisk() throws Throwable { final AwTestContainerView testContainer = createAwTestContainerViewOnMainSync(mContentsClient); final AwContents awContents = testContainer.getAwContents(); TestWebServer webServer = null;/* w ww .j a v a 2s. c om*/ try { webServer = new TestWebServer(false); final String pagePath = "/clear_cache_test.html"; List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>(); // Set Cache-Control headers to cache this request. One century should be long enough. headers.add(Pair.create("Cache-Control", "max-age=3153600000")); headers.add(Pair.create("Last-Modified", "Wed, 3 Oct 2012 00:00:00 GMT")); final String pageUrl = webServer.setResponse(pagePath, "<html><body>foo</body></html>", headers); // First load to populate cache. clearCacheOnUiThread(awContents, true); loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(1, webServer.getRequestCount(pagePath)); // Load about:blank so next load is not treated as reload by webkit and force // revalidate with the server. loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), "about:blank"); // No clearCache call, so should be loaded from cache. loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(1, webServer.getRequestCount(pagePath)); // Same as above. loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), "about:blank"); // Clear cache, so should hit server again. clearCacheOnUiThread(awContents, true); loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(2, webServer.getRequestCount(pagePath)); } finally { if (webServer != null) webServer.shutdown(); } }
From source file:com.arantius.tivocommander.MyShows.java
protected Pair<ArrayList<String>, ArrayList<Integer>> getLongPressChoices(JsonNode item) { final ArrayList<String> choices = new ArrayList<String>(); final ArrayList<Integer> actions = new ArrayList<Integer>(); final String folderType = item.path("folderType").asText(); if ("series".equals(folderType) || "wishlist".equals(folderType)) { // For season pass and/or wish list folders. choices.add(getResources().getString(R.string.watch_folder)); actions.add(R.string.watch_folder); choices.add(getResources().getString(R.string.delete_folder)); actions.add(R.string.delete_folder); } else if (!"".equals(folderType)) { // Other folders not supported. return null; } else {/*ww w . j a v a2 s. co m*/ // For individual recordings. JsonNode recording = item.path("recordingForChildRecordingId"); if ("deleted".equals(mFolderId)) { choices.add(getResources().getString(R.string.undelete)); actions.add(R.string.undelete); } else { choices.add(getResources().getString(R.string.watch_now)); actions.add(R.string.watch_now); if ("inProgress" == recording.path("state").asText()) { choices.add(getResources().getString(R.string.stop_recording)); actions.add(R.string.stop_recording); choices.add(getResources().getString(R.string.stop_recording_and_delete)); actions.add(R.string.stop_recording_and_delete); } else { choices.add(getResources().getString(R.string.delete)); actions.add(R.string.delete); } } } return Pair.create(choices, actions); }
From source file:nu.yona.app.utils.AppUtils.java
/** * Gets time for otp./* w w w. jav a2s. c o m*/ * * @param time the time * @return the time for otp */ public static Pair<String, Long> getTimeForOTP(String time) { try { StringBuffer buffer = new StringBuffer(); long totalTime = 0; Period period = new Period(time); if (period.getHours() > 0) { totalTime += period.getHours() * AppConstant.ONE_SECOND * 60 * 60; buffer.append(YonaApplication.getAppContext().getString(R.string.hours, period.getHours() + "")); } if (period.getMinutes() > 0) { totalTime += period.getMinutes() * AppConstant.ONE_SECOND * 60; buffer.append(YonaApplication.getAppContext().getString(R.string.minute, period.getMinutes() + "")); } if (period.getSeconds() > 0) { totalTime += period.getSeconds() * AppConstant.ONE_SECOND; buffer.append( YonaApplication.getAppContext().getString(R.string.seconds, period.getSeconds() + "")); } return Pair.create(buffer.toString(), totalTime); } catch (Exception e) { AppUtils.reportException(AppUtils.class.getSimpleName(), e, Thread.currentThread()); } return Pair.create(time, (long) 0); }
From source file:org.herrlado.websms.connector.magtifunge.ConnectorMagtifun.java
/** * Login to arcor./*from w w w .j a v a2s .c o m*/ * * @param ctx * {@link ConnectorContext} * @return true if successfullu logged in, false otherwise. * @throws WebSMSException * if any Exception occures. */ private Pair<Boolean, String> login(final ConnectorContext ctx) throws WebSMSException { String content; try { final SharedPreferences p = ctx.getPreferences(); final HttpPost request = createPOST(LOGIN_URL, getLoginPost(p.getString(Preferences.USERNAME, ""), p.getString(Preferences.PASSWORD, ""))); final HttpResponse response = ctx.getClient().execute(request); content = Utils.stream2str(response.getEntity().getContent()); if (content.indexOf(MATCH_LOGIN_SUCCESS) == -1) { throw new WebSMSException(ctx.getContext(), R.string.error_pw); } notifyFreeCount(ctx, content); } catch (final Exception e) { throw new WebSMSException(e.getMessage()); } return Pair.create(true, content); }
From source file:com.google.android.dialer.reverselookup.PeopleJsonParser.java
public static Pair<Integer, String> parsePhoneType(String s, String s2) { Integer n = PHONE_TYPE_MAP.get(s); if (n != null && n != 0) { return Pair.create(n, null); } else {// ww w. j ava 2s. c o m return Pair.create(n, s2); } }
From source file:dev.drsoran.moloko.util.UIUtils.java
public final static Pair<Integer, Integer> getTaggedViewRange(ViewGroup container, String tag) { int tagStart = -1; int tagEnd = -1; final int cnt = container.getChildCount(); for (int i = 0; i < cnt && (tagStart == -1 || tagEnd == -1); ++i) { if (tagStart == -1 && tag.equals(container.getChildAt(i).getTag())) tagStart = i;//from w ww. ja va2s . co m else if (tagStart != -1 && !tag.equals(container.getChildAt(i).getTag())) tagEnd = i; } if (tagStart != -1) return Pair.create(tagStart, tagEnd != -1 ? tagEnd : cnt); else return Pair.create(0, 0); }