Java Code Examples for androidx.core.util.Pair#create()

The following examples show how to use androidx.core.util.Pair#create() . 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: VideoBrowserFragment.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
public void itemClicked(View view, MediaInfo item, int position) {
    if (view instanceof ImageButton) {
        Utils.showQueuePopup(getActivity(), view, item);
    } else {
        String transitionName = getString(R.string.transition_image);
        VideoListAdapter.ViewHolder viewHolder =
                (VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
        Pair<View, String> imagePair = Pair
                .create((View) viewHolder.getImageView(), transitionName);
        ActivityOptionsCompat options = ActivityOptionsCompat
                .makeSceneTransitionAnimation(getActivity(), imagePair);

        Intent intent = new Intent(getActivity(), LocalPlayerActivity.class);
        intent.putExtra("media", item);
        intent.putExtra("shouldStart", false);
        ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    }
}
 
Example 2
Source File: ThreadListAdapter.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ActivityUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 设置跳转动画
 * @param activity       {@link Activity}
 * @param sharedElements 转场动画 View
 * @return {@link Bundle}
 */
public static Bundle getOptionsBundle(final Activity activity, final View[] sharedElements) {
    if (activity == null) return null;
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int len = sharedElements.length;
            @SuppressWarnings("unchecked")
            Pair<View, String>[] pairs = new Pair[len];
            for (int i = 0; i < len; i++) {
                pairs[i] = Pair.create(sharedElements[i], sharedElements[i].getTransitionName());
            }
            return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs).toBundle();
        }
        return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, null, null).toBundle();
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getOptionsBundle");
    }
    return null;
}
 
Example 4
Source File: SongAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
protected boolean onSongMenuItemClick(MenuItem item) {
    if ((image != null) && (image.getVisibility() == View.VISIBLE) && (item.getItemId() == R.id.action_go_to_album)) {
        Pair[] albumPairs = new Pair[]{
                Pair.create(image, activity.getResources().getString(R.string.transition_album_art))
        };
        NavigationUtil.goToAlbum(activity, getSong().albumId, albumPairs);
        return true;
    }
    return false;
}
 
Example 5
Source File: QiscusApiParser.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
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 6
Source File: IntroActivity.java    From material-intro with MIT License 5 votes vote down vote up
@Nullable
private Pair<CharSequence, ? extends View.OnClickListener> getButtonCta(int position) {
    if (position < getCount() && getSlide(position) instanceof ButtonCtaSlide) {
        ButtonCtaSlide slide = (ButtonCtaSlide) getSlide(position);
        if (slide.getButtonCtaClickListener() != null &&
                (slide.getButtonCtaLabel() != null || slide.getButtonCtaLabelRes() != 0)) {
            if (slide.getButtonCtaLabel() != null) {
                return Pair.create(slide.getButtonCtaLabel(),
                        slide.getButtonCtaClickListener());
            } else {
                return Pair.create((CharSequence) getString(slide.getButtonCtaLabelRes()),
                        slide.getButtonCtaClickListener());
            }
        }
    }
    if (buttonCtaVisible) {
        if (buttonCtaLabelRes != 0) {
            return Pair.create((CharSequence) getString(buttonCtaLabelRes),
                    new ButtonCtaClickListener());
        }
        if (!TextUtils.isEmpty(buttonCtaLabel)) {
            return Pair.create(buttonCtaLabel, new ButtonCtaClickListener());
        } else {
            return Pair.create((CharSequence) getString(R.string.mi_label_button_cta),
                    new ButtonCtaClickListener());
        }
    }
    return null;
}
 
Example 7
Source File: DateStrings.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Return a pair of strings representing the start and end dates of this date range.
 *
 * <p>Does not show year if dates are within the same year (Nov 17 - Dec 19).
 *
 * <p>Shows year for end date if range is not within the current year (Nov 17 - Nov 19, 2018).
 *
 * <p>Shows year for start and end date if range spans several years (Dec 31, 2016 - Jan 1, 2017).
 *
 * <p>If userDefinedDateFormat is set, this format overrides the rules above.
 *
 * @param start Start date.
 * @param end End date.
 * @param userDefinedDateFormat {@link SimpleDateFormat} specified by the user, if set.
 * @return Formatted date range string.
 */
static Pair<String, String> getDateRangeString(
    @Nullable Long start, @Nullable Long end, @Nullable SimpleDateFormat userDefinedDateFormat) {
  if (start == null && end == null) {
    return Pair.create(null, null);
  } else if (start == null) {
    return Pair.create(null, getDateString(end, userDefinedDateFormat));
  } else if (end == null) {
    return Pair.create(getDateString(start, userDefinedDateFormat), null);
  }

  Calendar currentCalendar = UtcDates.getTodayCalendar();
  Calendar startCalendar = UtcDates.getUtcCalendar();
  startCalendar.setTimeInMillis(start);
  Calendar endCalendar = UtcDates.getUtcCalendar();
  endCalendar.setTimeInMillis(end);

  if (userDefinedDateFormat != null) {
    Date startDate = new Date(start);
    Date endDate = new Date(end);
    return Pair.create(
        userDefinedDateFormat.format(startDate), userDefinedDateFormat.format(endDate));
  } else if (startCalendar.get(Calendar.YEAR) == endCalendar.get(Calendar.YEAR)) {
    if (startCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR)) {
      return Pair.create(
          getMonthDay(start, Locale.getDefault()), getMonthDay(end, Locale.getDefault()));
    } else {
      return Pair.create(
          getMonthDay(start, Locale.getDefault()), getYearMonthDay(end, Locale.getDefault()));
    }
  }
  return Pair.create(
      getYearMonthDay(start, Locale.getDefault()), getYearMonthDay(end, Locale.getDefault()));
}
 
Example 8
Source File: ArtistAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (isInQuickSelectMode()) {
        toggleChecked(getAdapterPosition());
    } else {
        Pair[] artistPairs = new Pair[]{
                Pair.create(image,
                        activity.getResources().getString(R.string.transition_artist_image)
                )};
        NavigationUtil.goToArtist(activity, dataSet.get(getAdapterPosition()).getId(), artistPairs);
    }
}
 
Example 9
Source File: AlbumAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@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 10
Source File: PlaylistSongAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean onSongMenuItemClick(MenuItem item) {
    if (item.getItemId() == R.id.action_go_to_album) {
        Pair[] albumPairs = new Pair[]{
                Pair.create(image, activity.getString(R.string.transition_album_art))
        };
        NavigationUtil.goToAlbum(activity, dataSet.get(getAdapterPosition() - 1).albumId, albumPairs);
        return true;
    }
    return super.onSongMenuItemClick(item);
}
 
Example 11
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected final Pair<Integer, Float> onDetachLayout(final boolean tabsOnly) {
    Pair<Integer, Float> result = null;

    if (getTabSwitcher().isSwitcherShown() && getFirstVisibleIndex() != -1) {
        TabItem tabItem =
                TabItem.create(getModel(), getTabViewRecycler(), getFirstVisibleIndex());
        Tag tag = tabItem.getTag();

        if (tag.getState() != State.HIDDEN) {
            float position = tag.getPosition();
            float draggingAxisSize =
                    getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false);
            float orthogonalAxisSize =
                    getArithmetics().getTabContainerSize(Axis.ORTHOGONAL_AXIS, false);
            result = Pair.create(getFirstVisibleIndex(),
                    position / Math.max(draggingAxisSize, orthogonalAxisSize));
        }
    }

    contentViewRecycler.removeAll();
    contentViewRecycler.clearCache();
    tabRecyclerAdapter.clearCachedPreviews();
    detachEmptyView();

    if (!tabsOnly) {
        getModel().removeListener(tabRecyclerAdapter);
    }

    return result;
}
 
Example 12
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected final Pair<Integer, Float> onDetachLayout(final boolean tabsOnly) {
    // TODO: contentViewRecycler.removeAll();
    // TODO: contentViewRecycler.clearCache();
    Pair<Integer, Float> result = null;
    ItemIterator iterator =
            new ItemIterator.Builder(getModel(), getTabViewRecycler()).start(getItemCount() - 1)
                    .reverse(true).create();
    AbstractItem item;

    if (!areTabsFittingIntoTabContainer()) {
        while ((item = iterator.next()) != null) {
            if (item.getTag().getState() == State.FLOATING) {
                float position = item.getTag().getPosition();
                float tabContainerSize =
                        getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false);
                result = Pair.create(item.getIndex(), position / tabContainerSize);
                break;
            }
        }
    }

    if (!tabsOnly) {
        getModel().removeListener(tabRecyclerAdapter);
        AttachedViewRecycler.Adapter<Tab, Void> contentViewRecyclerAdapter =
                contentViewRecycler.getAdapter();

        if (contentViewRecyclerAdapter instanceof TabletContentRecyclerAdapterWrapper) {
            getModel().removeListener(
                    (TabletContentRecyclerAdapterWrapper) contentViewRecyclerAdapter);
        }
    }

    return result;
}
 
Example 13
Source File: ArtistAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (isInQuickSelectMode()) {
        toggleChecked(getAdapterPosition());
    } else {
        Pair[] artistPairs = new Pair[]{
                Pair.create(image,
                        activity.getResources().getString(R.string.transition_artist_image)
                )};
        NavigationUtil.goToArtist(activity, dataSet.get(getAdapterPosition()).getId(), artistPairs);
    }
}
 
Example 14
Source File: AlbumAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@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 15
Source File: PlaylistSongAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean onSongMenuItemClick(MenuItem item) {
    if (item.getItemId() == R.id.action_go_to_album) {
        Pair[] albumPairs = new Pair[]{
                Pair.create(image, activity.getString(R.string.transition_album_art))
        };
        NavigationUtil.goToAlbum(activity, dataSet.get(getAdapterPosition() - 1).albumId, albumPairs);
        return true;
    }
    return super.onSongMenuItemClick(item);
}
 
Example 16
Source File: SongAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
protected boolean onSongMenuItemClick(MenuItem item) {
    if (image != null && image.getVisibility() == View.VISIBLE) {
        switch (item.getItemId()) {
            case R.id.action_go_to_album:
                Pair[] albumPairs = new Pair[]{
                        Pair.create(image, activity.getResources().getString(R.string.transition_album_art))
                };
                NavigationUtil.goToAlbum(activity, getSong().albumId, albumPairs);
                return true;
        }
    }
    return false;
}
 
Example 17
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected final Pair<Float, State> calculatePositionAndStateWhenStackedAtEnd(final int index) {
    float tabContainerWidth = getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false);
    int selectedTabIndex = getModel().getSelectedTabIndex();
    int selectedItemIndex = selectedTabIndex + (getModel().isAddTabButtonShown() ? 1 : 0);
    int i = getModel().isAddTabButtonShown() ? index - 1 : index;
    float position;
    State state;

    if (index == 0 && getModel().isAddTabButtonShown()) {
        position = tabContainerWidth - addTabButtonWidth;
        state = State.STACKED_END;
    } else if (index == selectedItemIndex) {
        position = tabContainerWidth - calculateAddTabButtonSpacing() - calculateTabSpacing() -
                (getStackedTabSpacing() * Math.min(getStackedTabCount(), i));
        state = State.STACKED_END;
    } else if (index < selectedItemIndex) {
        if (i < getStackedTabCount()) {
            position =
                    tabContainerWidth - calculateAddTabButtonSpacing() - calculateTabSpacing() -
                            (getStackedTabSpacing() * i);
            state = State.STACKED_END;
        } else {
            position =
                    tabContainerWidth - calculateAddTabButtonSpacing() - calculateTabSpacing() -
                            (getStackedTabSpacing() * getStackedTabCount());
            state = State.STACKED_END;
        }
    } else {
        float selectedItemPosition =
                tabContainerWidth - calculateAddTabButtonSpacing() - calculateTabSpacing() -
                        (getStackedTabSpacing() *
                                Math.min(getStackedTabCount(), selectedTabIndex));

        if (index <= selectedItemIndex + getStackedTabCount()) {
            position = selectedItemPosition -
                    (getStackedTabSpacing() * (index - selectedItemIndex));
            state = State.STACKED_END;
        } else {
            position = selectedItemPosition - (getStackedTabSpacing() * getStackedTabCount());
            state = State.HIDDEN;
        }
    }

    return Pair.create(position, state);
}
 
Example 18
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected final Pair<Float, State> calculatePositionAndStateWhenStackedAtStart(final int count,
                                                                               final int index,
                                                                               @Nullable final State predecessorState) {
    int selectedItemIndex =
            getModel().getSelectedTabIndex() + (getModel().isAddTabButtonShown() ? 1 : 0);
    float position;
    State state;

    if (index == 0 && getModel().isAddTabButtonShown()) {
        position = getStackedTabSpacing() * Math.min(count - 2, getStackedTabCount()) +
                calculateTabSpacing() + addTabButtonOffset;
        state = State.FLOATING;
    } else if (index == selectedItemIndex) {
        position = getStackedTabSpacing() * Math.min(count - (index + 1), getStackedTabCount());
        state = State.STACKED_START_ATOP;
    } else if (index < selectedItemIndex) {
        if ((selectedItemIndex - index) < getStackedTabCount()) {
            position = (getStackedTabSpacing() *
                    Math.min(count - (selectedItemIndex + 1), getStackedTabCount())) +
                    (getStackedTabSpacing() * (selectedItemIndex - index));
            state = State.STACKED_END;
        } else {
            position = (getStackedTabSpacing() *
                    Math.min(count - (selectedItemIndex + 1), getStackedTabCount())) +
                    (getStackedTabSpacing() * getStackedTabCount());
            state = State.HIDDEN;
        }
    } else {
        if ((count - index) <= getStackedTabCount()) {
            position = getStackedTabSpacing() * (count - (index + 1));
            state = predecessorState == null || predecessorState == State.FLOATING ?
                    State.STACKED_START_ATOP : State.STACKED_START;
        } else {
            position = getStackedTabSpacing() * getStackedTabCount();
            state = predecessorState == null || predecessorState == State.FLOATING ?
                    State.STACKED_START_ATOP : State.HIDDEN;
        }
    }

    return Pair.create(position, state);
}
 
Example 19
Source File: RefreshJobService.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
private Pair<ChanThread, Integer> processPosts(ThreadRegistryModel model, ChanThread thread, NotificationCompat.InboxStyle style) {
    if (model != null && model.getUnreadCount() > 0) {
        final String hasUnread = getResources().getQuantityString(R.plurals.has_unread_plural, model.getUnreadCount(), model.getUnreadCount());
        final String notificationTitle = "/" + model.getBoardName() + "/" + model.getThreadId() + " " + hasUnread;
        style.addLine(notificationTitle);

        int repliesToYou = -1;

        if (model.getUserPosts() != null && model.getUserPosts().size() > 0) {

            if (thread == null) {
                return Pair.create(ChanThread.empty(), -1);
            }

            final ChanThread currentThread = ProcessThreadTask.processThread(
                    thread.getPosts(),
                    model.getUserPosts(),
                    model.getBoardName(),
                    model.getThreadId()
            );

            final int pos = model.getLastReadPosition() < model.getThreadSize() ?
                    model.getLastReadPosition() : model.getThreadSize();

            if (currentThread != null && currentThread.getPosts() != null) {
                repliesToYou = 0;
                for (int i = pos; i < currentThread.getPosts().size(); i++) {
                    final ChanPost post = currentThread.getPosts().get(i);
                    if (LOG_DEBUG) {
                        Log.d(LOG_TAG, "post id=" + post.getNo());
                    }
                    if (post.getRepliesTo() != null && post.getRepliesTo().size() > 0) {
                        for (Long l : model.getUserPosts()) {
                            final String s = String.valueOf(l);

                            if (LOG_DEBUG) {
                                Log.d(LOG_TAG, "Checking post id " + s);
                            }

                            if (post.getRepliesTo().indexOf(s) >= 0) {
                                if (LOG_DEBUG) {
                                    Log.d(LOG_TAG, "Found reply to " + s);
                                }
                                repliesToYou++;
                                userPosts++;
                            }
                        }
                    }
                }
            }

            return new Pair<>(currentThread, repliesToYou);
        }
    }

    return Pair.create(ChanThread.empty(), -1);
}
 
Example 20
Source File: Bech32.java    From zap-android with MIT License 4 votes vote down vote up
public static Pair<String, byte[]> bech32Decode(String bech, boolean checkLength) throws Exception {

        byte[] buffer = bech.getBytes();
        for (byte b : buffer) {
            if (b < 0x21 || b > 0x7e) {
                throw new Exception("bech32 characters out of range");
            }
        }

        if (!bech.equals(bech.toLowerCase(Locale.ROOT)) && !bech.equals(bech.toUpperCase(Locale.ROOT))) {
            throw new Exception("bech32 cannot mix upper and lower case");
        }

        bech = bech.toLowerCase();
        int pos = bech.lastIndexOf("1");
        if (pos < 1) {
            throw new Exception("bech32 missing separator");
        } else if (pos + 7 > bech.length()) {
            throw new Exception("bech32 separator misplaced");
        } else if (bech.length() < 8) {
            throw new Exception("bech32 input too short");
        } else if (bech.length() > 90) {
            if (checkLength) {
                throw new Exception("bech32 input too long");
            }
        } else {
            ;
        }

        String s = bech.substring(pos + 1);
        for (int i = 0; i < s.length(); i++) {
            if (CHARSET.indexOf(s.charAt(i)) == -1) {
                throw new Exception("bech32 characters out of range");
            }
        }

        byte[] hrp = bech.substring(0, pos).getBytes();

        byte[] dataWithChecksum = new byte[bech.length() - pos - 1];
        for (int j = 0, i = pos + 1; i < bech.length(); i++, j++) {
            dataWithChecksum[j] = (byte) CHARSET.indexOf(bech.charAt(i));
        }

        if (!verifyChecksum(hrp, dataWithChecksum)) {
            throw new Exception("invalid bech32 checksum");
        }

        byte[] data = new byte[dataWithChecksum.length - 6];
        System.arraycopy(dataWithChecksum, 0, data, 0, dataWithChecksum.length - 6);

        return Pair.create(new String(hrp), data);
    }