androidx.core.util.Pair Java Examples
The following examples show how to use
androidx.core.util.Pair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SensorDatabaseImpl.java From science-journal with Apache License 2.0 | 7 votes |
private Cursor getCursor( String trialId, String[] sensorTags, TimeRange range, int resolutionTier, int maxRecords) { String[] columns = new String[] { ScalarSensorsTable.Column.TIMESTAMP_MILLIS, ScalarSensorsTable.Column.VALUE, ScalarSensorsTable.Column.TAG, ScalarSensorsTable.Column.TRIAL_ID }; Pair<String, String[]> selectionAndArgs = getSelectionAndArgs(trialId, sensorTags, range, resolutionTier); String selection = selectionAndArgs.first; String[] selectionArgs = selectionAndArgs.second; String orderBy = ScalarSensorsTable.Column.TIMESTAMP_MILLIS + (range.getOrder().equals(TimeRange.ObservationOrder.OLDEST_FIRST) ? " ASC" : " DESC"); String limit = maxRecords <= 0 ? null : String.valueOf(maxRecords); return openHelper .getReadableDatabase() .query( ScalarSensorsTable.NAME, columns, selection, selectionArgs, null, null, orderBy, limit); }
Example #2
Source File: SearchResultPresenterTest.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Test public void handleSuggestionClickedTest() { presenter.handleSuggestionClicked(); //When the user clicks on a sugestion when(searchResultView.listenToSuggestionClick()).thenReturn( Observable.just(new Pair<>("a", searchQueryEvent))); when(searchQueryEvent.hasQuery()).thenReturn(true); when(searchQueryEvent.isSubmitted()).thenReturn(true); when(searchQueryEvent.getQuery()).thenReturn("anyString"); lifecycleEvent.onNext(View.LifecycleEvent.CREATE); //Then it should make the search view disappear and navigate to correspondent result verify(searchResultView).collapseSearchBar(anyBoolean()); verify(searchResultView).hideSuggestionsViews(); verify(searchNavigator).navigate(any(SearchQueryModel.class)); }
Example #3
Source File: QiscusPhotoViewerPresenter.java From qiscus-sdk-android with Apache License 2.0 | 6 votes |
public void downloadFile(QiscusComment qiscusComment) { if (qiscusComment.isDownloading()) { return; } qiscusComment.setDownloading(true); downloadSubscription = QiscusApi.getInstance() .downloadFile(qiscusComment.getAttachmentUri().toString(), qiscusComment.getAttachmentName(), percentage -> qiscusComment.setProgress((int) percentage)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .compose(bindToLifecycle()) .doOnNext(file1 -> { QiscusFileUtil.notifySystem(file1); qiscusComment.setDownloading(false); Qiscus.getDataStore().addOrUpdateLocalPath(qiscusComment.getRoomId(), qiscusComment.getId(), file1.getAbsolutePath()); }) .subscribe(file1 -> view.onFileDownloaded(Pair.create(qiscusComment, file1)), throwable -> { QiscusErrorLogger.print(throwable); throwable.printStackTrace(); qiscusComment.setDownloading(false); view.showError(QiscusTextUtil.getString(R.string.qiscus_failed_download_file)); }); }
Example #4
Source File: FacePanelView.java From smart-farmer-android with Apache License 2.0 | 6 votes |
private List<List<Pair<Integer, String>>> getPagedFaces() { final int pageSize = 20; List<List<Pair<Integer, String>>> faces = new ArrayList<>(); int[] ids = Arrays.copyOf(FaceUtil.getFaceIds(), 92); String[] faceNames = Arrays.copyOf(FaceUtil.getFaceNames(), 92); int page = Math.round(ids.length / (float) pageSize); for (int i = 0; i < page; i++) { List<Pair<Integer, String>> pageFace = new ArrayList<>(); for (int j = 0; j < pageSize; ++j) { int pos = i * pageSize + j; if (pos < 92) { pageFace.add(new Pair<>(ids[pos], faceNames[pos])); } else { break; } } pageFace.add(new Pair<>(R.drawable.face_delete, KEY_DELETE)); faces.add(pageFace); } return faces; }
Example #5
Source File: RangeDateSelectorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void textInputFormatError() { View root = rangeDateSelector.onCreateTextInputView( LayoutInflater.from(context), null, null, new CalendarConstraints.Builder().build(), new OnSelectionChangedListener<Pair<Long, Long>>() { @Override public void onSelectionChanged(Pair<Long, Long> selection) {} }); TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start); TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end); startTextInput.getEditText().setText("22/22/2010", BufferType.EDITABLE); endTextInput.getEditText().setText("555-555-5555", BufferType.EDITABLE); assertThat(startTextInput.getError(), notNullValue()); assertThat(endTextInput.getError(), notNullValue()); }
Example #6
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToSint40(String input) { try { long val = Long.parseLong(input); byte[] returnVal = new byte[5]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); returnVal[2] = (byte) ((val >>> 16) & 0xFF); returnVal[3] = (byte) ((val >>> 24) & 0xFF); returnVal[4] = (byte) ((val >>> 32) & 0xFF); Boolean inRage = isValueInRange(-140737488355328L, 140737488355327L, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #7
Source File: PhoneTabRecyclerAdapter.java From ChromeLikeTabSwitcher with Apache License 2.0 | 6 votes |
/** * Inflates the view, which is associated with a tab, and adds it to the view hierarchy. * * @param tabItem * The tab item, which corresponds to the tab, whose associated view should be inflated, * as an instance of the class {@link TabItem}. The tab item may not be null */ private void addContentView(@NonNull final TabItem tabItem) { PhoneTabViewHolder viewHolder = (PhoneTabViewHolder) tabItem.getViewHolder(); View view = viewHolder.content; Tab tab = tabItem.getTab(); if (view == null) { ViewGroup parent = viewHolder.contentContainer; Pair<View, ?> pair = tabViewRecycler.inflate(tab, parent); view = pair.first; LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); Rect padding = getPadding(); layoutParams.setMargins(padding.left, padding.top, padding.right, padding.bottom); parent.addView(view, 0, layoutParams); viewHolder.content = view; } else { tabViewRecycler.getAdapter().onShowView(getModel().getContext(), view, tab, false); } viewHolder.previewImageView.setVisibility(View.GONE); viewHolder.previewImageView.setImageBitmap(null); viewHolder.borderView.setVisibility(View.GONE); }
Example #8
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToUint40(String input) { try { long val = Long.parseLong(input); byte[] returnVal = new byte[5]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); returnVal[2] = (byte) ((val >>> 16) & 0xFF); returnVal[3] = (byte) ((val >>> 24) & 0xFF); returnVal[4] = (byte) ((val >>> 32) & 0xFF); Boolean inRage = isValueInRange(0, 281474976710655L, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #9
Source File: UserInfoActivity.java From NewFastFrame with Apache License 2.0 | 6 votes |
@Override public void onClick(View v) { int i = v.getId(); if (i == R.id.btn_user_info_chat) { ChatActivity.start(this, ConstantUtil.TYPE_PERSON, uid); } else if (i == R.id.btn_user_info_add_friend) { sendAddFriendMsg(); } else if (i == R.id.btn_user_info_add_black) {// 添加对方为黑名单 if (!isBlack) { showAddBlackDialog(); } else { showCancelBlackDialog(); } } else if (i == R.id.riv_user_info_avatar) { UserDetailActivity.start(this,userEntity.getUid(), ActivityOptionsCompat.makeSceneTransitionAnimation(this, Pair.create(avatar, "avatar") , Pair.create(name, "name") , Pair.create(sex, "sex") ,Pair.create(signature,"signature"))); } }
Example #10
Source File: SearchFriendActivity.java From NewFastFrame with Apache License 2.0 | 6 votes |
@Override public void initData() { mAdapter = new SearchFriendAdapter(); mAdapter.setOnItemClickListener(new OnSimpleItemChildClickListener() { @Override public void onItemChildClick(int position, View view, int id) { UserDBManager.getInstance().addOrUpdateUser(UserManager.getInstance() .cover(mAdapter.getData(position), UserDBManager.getInstance().isStranger(mAdapter.getData().get(position).getObjectId()))); View itemView = display.getLayoutManager().findViewByPosition(position); View avatar = itemView.findViewById(R.id.riv_search_friend_item_avatar); View name = itemView.findViewById(R.id.tv_search_friend_item_name); ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(SearchFriendActivity.this , Pair.create(avatar, "avatar"), Pair.create(name, "name")); UserInfoActivity.start(SearchFriendActivity.this, mAdapter.getData(position).getObjectId(), activityOptionsCompat); } }); display.setAdapter(mAdapter); initActionBar(); }
Example #11
Source File: ThreadListAdapter.java From mimi-reader with Apache License 2.0 | 6 votes |
private Pair<VectorDrawableCompat, VectorDrawableCompat> initMetadataDrawables() { final Resources.Theme theme = MimiApplication.getInstance().getTheme(); final Resources res = MimiApplication.getInstance().getResources(); final int drawableColor = MimiUtil.getInstance().getTheme() == MimiUtil.THEME_LIGHT ? R.color.md_grey_800 : R.color.md_green_50; final VectorDrawableCompat pin; final VectorDrawableCompat lock; pin = VectorDrawableCompat.create(res, R.drawable.ic_pin, theme); lock = VectorDrawableCompat.create(res, R.drawable.ic_lock, theme); if (pin != null) { pin.setTint(res.getColor(drawableColor)); } if (lock != null) { lock.setTint(res.getColor(drawableColor)); } return Pair.create(pin, lock); }
Example #12
Source File: IntentHelper.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
public static void startSearchActivityForResult(Activity activity, View bar, int requestCode) { Intent intent = new Intent(activity, SearchActivity.class); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { activity.startActivityForResult(intent, requestCode); activity.overridePendingTransition(R.anim.activity_search_in, 0); } else { ActivityCompat.startActivityForResult( activity, intent, requestCode, ActivityOptionsCompat.makeSceneTransitionAnimation( activity, Pair.create(bar, activity.getString(R.string.transition_activity_search_bar)) ).toBundle() ); } }
Example #13
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToUint32(String input) { try { long val = Long.parseLong(input); byte[] returnVal = new byte[4]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); returnVal[2] = (byte) ((val >>> 16) & 0xFF); returnVal[3] = (byte) ((val >>> 24) & 0xFF); Boolean inRage = isValueInRange(0, 4294967295L, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #14
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToUint24(String input) { try { int val = Integer.parseInt(input); byte[] returnVal = new byte[3]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); returnVal[2] = (byte) ((val >>> 16) & 0xFF); Boolean inRage = isValueInRange(0, 16777215L, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #15
Source File: RangeDateSelectorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void textInputValid() { View root = rangeDateSelector.onCreateTextInputView( LayoutInflater.from(context), null, null, new CalendarConstraints.Builder().build(), new OnSelectionChangedListener<Pair<Long, Long>>() { @Override public void onSelectionChanged(Pair<Long, Long> selection) {} }); TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start); TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end); startTextInput.getEditText().setText("2/2/2010", BufferType.EDITABLE); endTextInput.getEditText().setText("2/2/2012", BufferType.EDITABLE); assertThat(startTextInput.getError(), nullValue()); assertThat(endTextInput.getError(), nullValue()); }
Example #16
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToSint16(String input) { try { int val = Integer.parseInt(input); byte[] returnVal = new byte[2]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); Boolean inRage = isValueInRange(-32768, 32767, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #17
Source File: Section.java From litho with Apache License 2.0 | 6 votes |
static Map<String, Pair<Section, Integer>> acquireChildrenMap( @Nullable Section currentComponent) { // TODO use pools instead t11953296 final HashMap<String, Pair<Section, Integer>> childrenMap = new HashMap<>(); if (currentComponent == null) { return childrenMap; } final List<Section> children = currentComponent.getChildren(); if (children == null) { throw new IllegalStateException( "Children of current section " + currentComponent + " is null!"); } for (int i = 0, size = children.size(); i < size; i++) { final Section child = children.get(i); childrenMap.put(child.getGlobalKey(), new Pair<Section, Integer>(child, i)); } return childrenMap; }
Example #18
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToSint24(String input) { try { int val = Integer.parseInt(input); byte[] returnVal = new byte[3]; returnVal[0] = (byte) (val & 0xFF); returnVal[1] = (byte) ((val >>> 8) & 0xFF); returnVal[2] = (byte) ((val >>> 16) & 0xFF); Boolean inRage = isValueInRange(-8388608, 8388607, val); return new Pair<>(returnVal, inRage); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #19
Source File: Converters.java From EFRConnect-android with Apache License 2.0 | 6 votes |
public static Pair<byte[], Boolean> convertToFloat64(String input) { try { double floatVal = Double.parseDouble(input); long longBits = Double.doubleToLongBits(floatVal); byte[] returnVal = new byte[8]; returnVal[0] = (byte) (longBits & 0xff); returnVal[1] = (byte) ((longBits >>> 8) & 0xff); returnVal[2] = (byte) ((longBits >>> 16) & 0xff); returnVal[3] = (byte) ((longBits >>> 24) & 0xff); returnVal[4] = (byte) ((longBits >>> 32) & 0xff); returnVal[5] = (byte) ((longBits >>> 40) & 0xff); returnVal[6] = (byte) ((longBits >>> 48) & 0xff); returnVal[7] = (byte) ((longBits >>> 56) & 0xff); return new Pair<>(returnVal, true); } catch (Exception e) { e.printStackTrace(); return new Pair<>(input.getBytes(), false); } }
Example #20
Source File: Times.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Nullable private static Pair<Alarm, LocalDateTime> getNextAlarm(Times t) { Alarm alarm = null; LocalDateTime time = null; for (Alarm a : t.getUserAlarms()) { if (!a.isEnabled()) continue; LocalDateTime nextAlarm = a.getNextAlarm(); if (nextAlarm == null) continue; if (time == null || time.isAfter(nextAlarm)) { alarm = a; time = nextAlarm; } } if (alarm == null) return null; alarm.setCity(t); return new Pair<>(alarm, time); }
Example #21
Source File: Main.java From DroidCast with Apache License 2.0 | 6 votes |
@Nullable private Pair<Bitmap.CompressFormat, String> getImageFormatInfo(String reqFormat) { ImageFormat format = ImageFormat.JPEG; if (!TextUtils.isEmpty(reqFormat)) { ImageFormat imageFormat = ImageFormat.resolveFormat(reqFormat); if (ImageFormat.UNKNOWN.equals(imageFormat)) { return null; } else { // default format format = imageFormat; } } return mapRequestFormatInfo(format); }
Example #22
Source File: RangeDateSelectorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void textInputRangeError() { rangeDateSelector = new RangeDateSelector(); View root = rangeDateSelector.onCreateTextInputView( LayoutInflater.from(context), null, null, new CalendarConstraints.Builder().build(), new OnSelectionChangedListener<Pair<Long, Long>>() { @Override public void onSelectionChanged(Pair<Long, Long> selection) {} }); TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start); TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end); startTextInput.getEditText().setText("2/2/2010", BufferType.EDITABLE); endTextInput.getEditText().setText("2/2/2008", BufferType.EDITABLE); assertThat( startTextInput.getError(), is((CharSequence) context.getString(R.string.mtrl_picker_invalid_range))); assertThat(endTextInput.getError(), notNullValue()); }
Example #23
Source File: Main.java From DroidCast with Apache License 2.0 | 5 votes |
@NonNull private static Pair<Integer, Integer> getDimension() { Point displaySize = displayUtil.getCurrentDisplaySize(); int width = 1080; int height = 1920; if (displaySize != null) { width = displaySize.x; height = displaySize.y; } return new Pair<>(width, height); }
Example #24
Source File: ActionSheet.java From smart-farmer-android with Apache License 2.0 | 5 votes |
public Builder setMenus2(List<String> menus) { if (this.menus == null) { this.menus = new ArrayList<>(); } else { this.menus.clear(); } for (String menu : menus) { this.menus.add(Pair.<String, String>create(menu, null)); } return this; }
Example #25
Source File: LoggedOutInteractorTest.java From RIBs with Apache License 2.0 | 5 votes |
@Test public void attach_whenViewEmitsName_shouldCallListener() { String fakeName1 = "1"; String fakeName2 = "2"; when(presenter.playerNames()).thenReturn(Observable.just(new Pair<>(fakeName1, fakeName2))); InteractorHelper.attach(interactor, presenter, router, null); verify(listener).requestLogin(any(String.class), any(String.class)); }
Example #26
Source File: QiscusApiParser.java From qiscus-sdk-android with Apache License 2.0 | 5 votes |
static Pair<QiscusChatRoom, List<QiscusComment>> parseQiscusChatRoomWithComments(JsonElement jsonElement) { if (jsonElement != null) { QiscusChatRoom qiscusChatRoom = parseQiscusChatRoom(jsonElement); JsonArray comments = jsonElement.getAsJsonObject().get("results").getAsJsonObject().get("comments").getAsJsonArray(); List<QiscusComment> qiscusComments = new ArrayList<>(); for (JsonElement jsonComment : comments) { qiscusComments.add(parseQiscusComment(jsonComment, qiscusChatRoom.getId())); } return Pair.create(qiscusChatRoom, qiscusComments); } return null; }
Example #27
Source File: AlbumAdapter.java From Music-Player with GNU General Public License v3.0 | 5 votes |
@Override public void onClick(View v) { if (isInQuickSelectMode()) { toggleChecked(getAdapterPosition()); } else { Pair[] albumPairs = new Pair[]{ Pair.create(image, activity.getResources().getString(R.string.transition_album_art) )}; NavigationUtil.goToAlbum(activity, dataSet.get(getAdapterPosition()).getId(), albumPairs); } }
Example #28
Source File: LoggedOutView.java From RIBs with Apache License 2.0 | 5 votes |
@Override public Observable<Pair<String, String>> loginName() { return RxView.clicks(findViewById(R.id.login_button)) .map(new Function<Object, Pair<String, String>>() { @Override public Pair<String, String> apply(Object o) throws Exception { TextView playerNameOne = (TextView) findViewById(R.id.player_name_1); TextView playerNameTwo = (TextView) findViewById(R.id.player_name_2); return Pair.create(playerNameOne.getText().toString(), playerNameTwo.getText().toString()); } }); }
Example #29
Source File: SensorDatabaseImpl.java From science-journal with Apache License 2.0 | 5 votes |
@Override public void deleteScalarReadings(String trialId, String sensorTag, TimeRange range) { Pair<String, String[]> selectionAndArgs = getSelectionAndArgs( trialId, new String[] {sensorTag}, range, -1 /* delete all resolutions */); String selection = selectionAndArgs.first; String[] selectionArgs = selectionAndArgs.second; openHelper.getWritableDatabase().delete(ScalarSensorsTable.NAME, selection, selectionArgs); }
Example #30
Source File: ConnectionConfiguration.java From easyble-x with Apache License 2.0 | 5 votes |
public ConnectionConfiguration() { scanIntervalPairsInAutoReconnection = new ArrayList<>(); scanIntervalPairsInAutoReconnection.add(Pair.create(0, 2000)); scanIntervalPairsInAutoReconnection.add(Pair.create(1, 5000)); scanIntervalPairsInAutoReconnection.add(Pair.create(3, 10000)); scanIntervalPairsInAutoReconnection.add(Pair.create(5, 30000)); scanIntervalPairsInAutoReconnection.add(Pair.create(10, 60000)); }