List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.vagrant.usefultest.view.PagerSlidingTabStrip.java
private Pair<Float, Float> getIndicatorCoordinates() { // default: line below current tab View currentTab = mTabsContainer.getChildAt(mCurrentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (mCurrentPositionOffset > 0f && mCurrentPosition < mTabCount - 1) { View nextTab = mTabsContainer.getChildAt(mCurrentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (mCurrentPositionOffset * nextTabLeft + (1f - mCurrentPositionOffset) * lineLeft); lineRight = (mCurrentPositionOffset * nextTabRight + (1f - mCurrentPositionOffset) * lineRight); }//ww w . ja v a2 s .c o m return new Pair<Float, Float>(lineLeft, lineRight); }
From source file:export.GarminUploader.java
@Override public Status listWorkouts(List<Pair<String, String>> list) { Status s;/*from w w w.j a v a2 s .c om*/ if ((s = connect()) != Status.OK) { return s; } HttpURLConnection conn = null; Exception ex = null; try { conn = (HttpURLConnection) new URL(LIST_WORKOUTS_URL).openConnection(); conn.setRequestMethod("GET"); addCookies(conn); conn.connect(); getCookies(conn); InputStream in = new BufferedInputStream(conn.getInputStream()); JSONObject obj = parse(in); conn.disconnect(); int responseCode = conn.getResponseCode(); String amsg = conn.getResponseMessage(); if (responseCode == 200) { obj = obj.getJSONObject("com.garmin.connect.workout.dto.BaseUserWorkoutListDto"); JSONArray arr = obj.getJSONArray("baseUserWorkouts"); for (int i = 0;; i++) { obj = arr.optJSONObject(i); if (obj == null) break; list.add(new Pair<String, String>(obj.getString("workoutId"), obj.getString("workoutName") + ".json")); } return Status.OK; } ex = new Exception(amsg); } catch (IOException e) { ex = e; } catch (JSONException e) { ex = e; } s = Uploader.Status.ERROR; s.ex = ex; if (ex != null) { ex.printStackTrace(); } return s; }
From source file:com.zaparound.PagerSlidingTabStrip.java
private Pair<Float, Float> getIndicatorCoordinates() { // default: line below current tab View currentTab = mTabsContainer.getChildAt(mCurrentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (mCurrentPositionOffset > 0f && mCurrentPosition < mTabCount - 1) { View nextTab = mTabsContainer.getChildAt(mCurrentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (mCurrentPositionOffset * nextTabLeft + (1f - mCurrentPositionOffset) * lineLeft); lineRight = (mCurrentPositionOffset * nextTabRight + (1f - mCurrentPositionOffset) * lineRight); }/*from w ww. j av a 2 s. com*/ return new Pair<>(lineLeft, lineRight); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//*from ww w. j av a2 s .c o 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 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); } updatePlusOneButton(); 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 (I/O live link, 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>>(); final boolean hasLivestream = !TextUtils.isEmpty(cursor.getString(SessionsQuery.LIVESTREAM_URL)); long currentTimeMillis = UIUtils.getCurrentTime(context); if (UIUtils.hasHoneycomb() // Needs Honeycomb+ for the live stream && hasLivestream && currentTimeMillis > mSessionBlockStart && currentTimeMillis <= mSessionBlockEnd) { links.add(new Pair<Integer, Intent>(R.string.session_link_livestream, new Intent(Intent.ACTION_VIEW, mSessionUri).setClass(context, SessionLivestreamActivity.class))); } // Add session feedback link // 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.updateTimeAndLivestreamBlockUI(context, mSessionBlockStart, mSessionBlockEnd, hasLivestream, null, mSubtitle, subtitle); EasyTracker.getTracker().sendView("Session: " + mTitleString); LOGD("Tracker", "Session: " + mTitleString); }
From source file:be.blinkt.openvpn.views.PagerSlidingTabStrip.java
private Pair<Float, Float> getIndicatorCoordinates() { // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); }/*from w ww. ja v a 2s.co m*/ return new Pair<Float, Float>(lineLeft, lineRight); }
From source file:com.google.samples.apps.iosched.session.SessionDetailModel.java
private void buildLinks(Cursor cursor) { mLinks.clear();/* w w w . j a v a 2s. c o m*/ if (hasLiveStream() && isSessionOngoing()) { mLinks.add(new Pair<Integer, Intent>(R.string.session_link_livestream, getWatchLiveIntent())); } if (!hasFeedback() && isSessionReadyForFeedback()) { mLinks.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink, getFeedbackIntent())); } for (int i = 0; i < LINKS_CURSOR_FIELDS.length; i++) { final String linkUrl = cursor.getString(cursor.getColumnIndex(LINKS_CURSOR_FIELDS[i])); if (TextUtils.isEmpty(linkUrl)) { continue; } mLinks.add(new Pair<Integer, Intent>(LINKS_DESCRIPTION_RESOURCE_IDS[i], new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)).addFlags(getFlagForUrlLink()))); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java
public void testJsonTableDeleteWithParametersFeatureHeader() { testTableFeatureHeader(new TableTestOperation() { @Override/* w w w .ja v a 2s . c o m*/ 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.delete(jo, queryParams).get(); } }, false, "QS,TU"); }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
static List<Pair<TaskList, GoogleTaskList>> synchronizeListsRemotely(final Context context, final List<Pair<TaskList, GoogleTaskList>> listPairs, final GoogleAPITalker apiTalker) throws ClientProtocolException, IOException, PreconditionException, JSONException { final List<Pair<TaskList, GoogleTaskList>> syncedPairs = new ArrayList<Pair<TaskList, GoogleTaskList>>(); // For every list for (final Pair<TaskList, GoogleTaskList> pair : listPairs) { Pair<TaskList, GoogleTaskList> syncedPair = pair; if (pair.second == null) { // New list to create final GoogleTaskList newList = new GoogleTaskList(pair.first, apiTalker.accountName); apiTalker.uploadList(newList); // Save to db also newList.save(context);//from w w w .j a v a2s .co m pair.first.save(context, newList.updated); syncedPair = new Pair<TaskList, GoogleTaskList>(pair.first, newList); } else if (pair.second.isDeleted()) { Log.d(TAG, "remotesync: isDeletedLocally"); // Deleted locally, delete remotely also pair.second.remotelyDeleted = true; try { apiTalker.uploadList(pair.second); } catch (PreconditionException e) { // Deleted the default list. Ignore error } // and delete from db if it exists there pair.second.delete(context); syncedPair = null; } else if (pair.first.updated > pair.second.updated) { // If local update is different than remote, that means we // should update apiTalker.uploadList(pair.second); // No need to save remote object pair.first.save(context, pair.second.updated); } // else remote has already been saved locally, nothing to upload if (syncedPair != null) { syncedPairs.add(syncedPair); } } // return (updated) pairs return syncedPairs; }
From source file:com.facebook.reflection.SelectionFragment.java
private Pair<File, Integer> getImageFileAndMinDimension() { File photoFile = null;/* w ww.j a v a 2s. c o m*/ String photoUriString = photoUri.toString(); if (photoUriString.startsWith("file://")) { photoFile = new File(photoUri.getPath()); } else if (photoUriString.startsWith("content://")) { String[] filePath = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().getContentResolver().query(photoUri, filePath, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePath[0]); String filename = cursor.getString(columnIndex); cursor.close(); photoFile = new File(filename); } } if (photoFile != null) { InputStream is = null; try { is = new FileInputStream(photoFile); // We only want to get the bounds of the image, rather than load the whole thing. BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, options); return new Pair<File, Integer>(photoFile, Math.min(options.outWidth, options.outHeight)); } catch (Exception e) { return null; } finally { Utility.closeQuietly(is); } } return null; }
From source file:com.tmall.wireless.tangram3.dataparser.concrete.PojoGroupBasicAdapter.java
@Override public void removeComponents(Card group) { if (group != null && mCards != null) { List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>(); int cardIdx = findCardIdxForCard(group); int removeItemCount = 0; int removePosition = 0; for (int i = 0, size = mCards.size(); i < size; i++) { Pair<Range<Integer>, Card> pair = mCards.get(i); int start = pair.first.getLower(); int end = pair.first.getUpper(); if (i < cardIdx) { //do nothing newCards.add(pair);//from w w w .j a v a 2 s. c o m } else if (i == cardIdx) { removePosition = start; removeItemCount = end - start; } else { Pair<Range<Integer>, Card> newPair = new Pair<>( Range.create(start - removeItemCount, end - removeItemCount), pair.second); newCards.add(newPair); } } group.removed(); mCards.clear(); mCards.addAll(newCards); mData.removeAll(group.getCells()); notifyItemRangeRemoved(removePosition, removeItemCount); int last = mLayoutManager.findLastVisibleItemPosition(); notifyItemRangeChanged(removePosition, last - removePosition); } }