-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Player seekbar thumbnail preview #6434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
43133df
Added settings for seekbar-preview-thumbnail
litetex 2e2dbaf
Added seekbar-preview to the player layout
litetex 253526e
Updated build.gradle so the PR-build works
litetex 384d964
Added seekbarThumbnailPreview
litetex c5f2eb1
Enlarged currentDisplaySeek a bit
litetex 88c4195
Enlarged currentDisplaySeek-text on large-handed player
litetex 2a24532
Fine tuned padding
litetex a9b5ef3
Set minWidth to 10dp so that the popup player works (mostly) correctly
litetex 0b2629e
Moved time to the top
litetex efd038a
Increased padding of preview thumbnail
litetex 621af8d
Removed unused import (rebasing/merge problem)
litetex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package org.schabi.newpipe.player.seekbarpreview; | ||
|
|
||
| import android.content.Context; | ||
| import android.graphics.Bitmap; | ||
| import android.util.Log; | ||
| import android.view.View; | ||
| import android.widget.ImageView; | ||
|
|
||
| import androidx.annotation.IntDef; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.preference.PreferenceManager; | ||
|
|
||
| import org.schabi.newpipe.R; | ||
| import org.schabi.newpipe.util.DeviceUtils; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.function.IntSupplier; | ||
|
|
||
| import static java.lang.annotation.RetentionPolicy.SOURCE; | ||
| import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.HIGH_QUALITY; | ||
| import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.LOW_QUALITY; | ||
| import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.NONE; | ||
|
|
||
| /** | ||
| * Helper for the seekbar preview. | ||
| */ | ||
| public final class SeekbarPreviewThumbnailHelper { | ||
|
|
||
| // This has to be <= 23 chars on devices running Android 7 or lower (API <= 25) | ||
| // or it fails with an IllegalArgumentException | ||
| // https://stackoverflow.com/a/54744028 | ||
| public static final String TAG = "SeekbarPrevThumbHelper"; | ||
|
|
||
| private SeekbarPreviewThumbnailHelper() { | ||
| // No impl pls | ||
| } | ||
|
|
||
| @Retention(SOURCE) | ||
| @IntDef({HIGH_QUALITY, LOW_QUALITY, | ||
| NONE}) | ||
| public @interface SeekbarPreviewThumbnailType { | ||
| int HIGH_QUALITY = 0; | ||
| int LOW_QUALITY = 1; | ||
| int NONE = 2; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| // Settings Resolution | ||
| /////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| @SeekbarPreviewThumbnailType | ||
| public static int getSeekbarPreviewThumbnailType(@NonNull final Context context) { | ||
| final String type = PreferenceManager.getDefaultSharedPreferences(context).getString( | ||
| context.getString(R.string.seekbar_preview_thumbnail_key), ""); | ||
| if (type.equals(context.getString(R.string.seekbar_preview_thumbnail_none))) { | ||
| return NONE; | ||
| } else if (type.equals(context.getString(R.string.seekbar_preview_thumbnail_low_quality))) { | ||
| return LOW_QUALITY; | ||
| } else { | ||
| return HIGH_QUALITY; // default | ||
| } | ||
| } | ||
|
|
||
| public static void tryResizeAndSetSeekbarPreviewThumbnail( | ||
| @NonNull final Context context, | ||
| @NonNull final Optional<Bitmap> optPreviewThumbnail, | ||
| @NonNull final ImageView currentSeekbarPreviewThumbnail, | ||
| @NonNull final IntSupplier baseViewWidthSupplier) { | ||
|
|
||
| if (!optPreviewThumbnail.isPresent()) { | ||
| currentSeekbarPreviewThumbnail.setVisibility(View.GONE); | ||
| return; | ||
| } | ||
|
|
||
| currentSeekbarPreviewThumbnail.setVisibility(View.VISIBLE); | ||
| final Bitmap srcBitmap = optPreviewThumbnail.get(); | ||
|
|
||
| // Resize original bitmap | ||
| try { | ||
| Objects.requireNonNull(srcBitmap); | ||
|
|
||
| final int srcWidth = srcBitmap.getWidth() > 0 ? srcBitmap.getWidth() : 1; | ||
| final int newWidth = Math.max( | ||
| Math.min( | ||
| // Use 1/4 of the width for the preview | ||
| Math.round(baseViewWidthSupplier.getAsInt() / 4f), | ||
| // Scaling more than that factor looks really pixelated -> max | ||
| Math.round(srcWidth * 2.5f) | ||
| ), | ||
| // Min width = 10dp | ||
| DeviceUtils.dpToPx(10, context) | ||
| ); | ||
|
|
||
| final float scaleFactor = (float) newWidth / srcWidth; | ||
| final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor); | ||
|
|
||
| currentSeekbarPreviewThumbnail.setImageBitmap( | ||
| Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight, true)); | ||
| } catch (final Exception ex) { | ||
| Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex); | ||
| currentSeekbarPreviewThumbnail.setVisibility(View.GONE); | ||
| } finally { | ||
| srcBitmap.recycle(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.