From c7ccf9bab84041e00c95c16f42e744b72e85c4eb Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Tue, 21 Jul 2020 01:43:49 +0300 Subject: [PATCH] AndroidTvUtils -> DeviceUtils --- .../java/org/schabi/newpipe/MainActivity.java | 6 +++--- .../org/schabi/newpipe/RouterActivity.java | 4 ++-- .../newpipe/download/DownloadActivity.java | 4 ++-- .../fragments/detail/VideoDetailFragment.java | 12 +++++------ .../fragments/list/search/SearchFragment.java | 4 ++-- .../holder/CommentsMiniInfoItemHolder.java | 4 ++-- .../subscription/dialog/FeedGroupDialog.kt | 4 ++-- .../newpipe/player/MainVideoPlayer.java | 10 +++++----- .../newpipe/player/VideoPlayerImpl.java | 11 +++++----- .../newpipe/player/helper/PlayerHelper.java | 7 ------- .../newpipe/settings/SettingsActivity.java | 4 ++-- .../{AndroidTvUtils.java => DeviceUtils.java} | 20 +++++++++++++------ .../newpipe/views/FocusAwareSeekBar.java | 4 ++-- 13 files changed, 47 insertions(+), 47 deletions(-) rename app/src/main/java/org/schabi/newpipe/util/{AndroidTvUtils.java => DeviceUtils.java} (81%) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index ad5741503..fb1ca2342 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -68,7 +68,7 @@ import org.schabi.newpipe.player.VideoPlayer; import org.schabi.newpipe.player.event.OnKeyDownListener; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.Localization; @@ -144,7 +144,7 @@ public class MainActivity extends AppCompatActivity { ErrorActivity.reportUiError(this, e); } - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } } @@ -545,7 +545,7 @@ public class MainActivity extends AppCompatActivity { Log.d(TAG, "onBackPressed() called"); } - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { View drawerPanel = findViewById(R.id.navigation); if (drawer.isDrawerOpen(drawerPanel)) { drawer.closeDrawers(); diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index 423e88b76..e9e166c22 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -44,7 +44,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ListHelper; @@ -347,7 +347,7 @@ public class RouterActivity extends AppCompatActivity { alertDialog.show(); - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(alertDialog); } } diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index e46ded40d..5415c4ff8 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -13,7 +13,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import org.schabi.newpipe.R; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.views.FocusOverlayView; @@ -57,7 +57,7 @@ public class DownloadActivity extends AppCompatActivity { } }); - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index a87864a63..5310570c8 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -92,7 +92,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ImageDisplayConstants; @@ -767,7 +767,7 @@ public class VideoDetailFragment thumbnailBackgroundButton.requestFocus(); - if (AndroidTvUtils.isTv(getContext())) { + if (DeviceUtils.isTv(getContext())) { // remove ripple effects from detail controls final int transparent = getResources().getColor(R.color.transparent_background_color); detailControlsAddToPlaylist.setBackgroundColor(transparent); @@ -880,7 +880,7 @@ public class VideoDetailFragment // If we are in fullscreen mode just exit from it via first back press if (player != null && player.isFullscreen()) { - if (!PlayerHelper.isTablet(activity)) { + if (!DeviceUtils.isTablet(activity)) { player.onPause(); } restoreDefaultOrientation(); @@ -1449,7 +1449,7 @@ public class VideoDetailFragment // User can tap on Play button and video will be in fullscreen mode again // Note for tablet: trying to avoid orientation changes since it's not easy // to physically rotate the tablet every time - if (!PlayerHelper.isTablet(activity)) { + if (!DeviceUtils.isTablet(activity)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } @@ -1945,7 +1945,7 @@ public class VideoDetailFragment // In tablet user experience will be better if screen will not be rotated // from landscape to portrait every time. // Just turn on fullscreen mode in landscape orientation - if (isLandscape() && PlayerHelper.isTablet(activity)) { + if (isLandscape() && DeviceUtils.isTablet(activity)) { player.toggleFullscreen(); return; } @@ -2185,7 +2185,7 @@ public class VideoDetailFragment && player != null && player.isPlaying() && !player.isFullscreen() - && !PlayerHelper.isTablet(activity) + && !DeviceUtils.isTablet(activity) && player.videoPlayerSelected()) { player.toggleFullscreen(); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 33ab001c7..12abc29ae 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -48,7 +48,7 @@ import org.schabi.newpipe.fragments.list.BaseListFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.ExtractorHelper; @@ -525,7 +525,7 @@ public class SearchFragment extends BaseListFragment { - if (AndroidTvUtils.isTv(itemBuilder.getContext())) { + if (DeviceUtils.isTv(itemBuilder.getContext())) { openCommentAuthor(item); } else { ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText); diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index 66387d298..80036cd4a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -40,7 +40,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupDialogViewModel.Dia import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.PickerIconItem import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem -import org.schabi.newpipe.util.AndroidTvUtils +import org.schabi.newpipe.util.DeviceUtils import org.schabi.newpipe.util.ThemeHelper class FeedGroupDialog : DialogFragment(), BackPressable { @@ -237,7 +237,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable { } toolbar_search_edit_text.setOnClickListener { - if (AndroidTvUtils.isTv(context)) { + if (DeviceUtils.isTv(context)) { showKeyboardSearch() } } diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 51e159469..f87887685 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -80,7 +80,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder; import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback; import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.ListHelper; @@ -179,7 +179,7 @@ public final class MainVideoPlayer extends AppCompatActivity final String orientKey = getString(R.string.last_orientation_landscape_key); final boolean lastOrientationWasLandscape = defaultPreferences - .getBoolean(orientKey, AndroidTvUtils.isTv(getApplicationContext())); + .getBoolean(orientKey, DeviceUtils.isTv(getApplicationContext())); setLandscape(lastOrientationWasLandscape); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); @@ -191,7 +191,7 @@ public final class MainVideoPlayer extends AppCompatActivity Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), false, rotationObserver); - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } } @@ -223,7 +223,7 @@ public final class MainVideoPlayer extends AppCompatActivity default: break; case KeyEvent.KEYCODE_BACK: - if (AndroidTvUtils.isTv(getApplicationContext()) + if (DeviceUtils.isTv(getApplicationContext()) && playerImpl.isControlsVisible()) { playerImpl.hideControls(0, 0); hideSystemUi(); @@ -272,7 +272,7 @@ public final class MainVideoPlayer extends AppCompatActivity final String orientKey = getString(R.string.last_orientation_landscape_key); boolean lastOrientationWasLandscape = defaultPreferences - .getBoolean(orientKey, AndroidTvUtils.isTv(getApplicationContext())); + .getBoolean(orientKey, DeviceUtils.isTv(getApplicationContext())); setLandscape(lastOrientationWasLandscape); } diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index ec01ef11e..fd3f38ab7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -94,7 +94,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback; import org.schabi.newpipe.player.resolver.AudioPlaybackResolver; import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KoreUtil; @@ -117,7 +117,6 @@ import static org.schabi.newpipe.player.MainPlayer.ACTION_REPEAT; import static org.schabi.newpipe.player.MainPlayer.NOTIFICATION_ID; import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND; import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString; -import static org.schabi.newpipe.player.helper.PlayerHelper.isTablet; import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA; import static org.schabi.newpipe.util.AnimationUtils.animateRotation; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -481,7 +480,7 @@ public class VideoPlayerImpl extends VideoPlayer default: break; case KeyEvent.KEYCODE_BACK: - if (AndroidTvUtils.isTv(service) && isControlsVisible()) { + if (DeviceUtils.isTv(service) && isControlsVisible()) { hideControls(0, 0); hideSystemUIIfNeeded(); return true; @@ -930,7 +929,7 @@ public class VideoPlayerImpl extends VideoPlayer private void setupScreenRotationButton() { final boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); - final boolean tabletInLandscape = isTablet(service) && service.isLandscape(); + final boolean tabletInLandscape = DeviceUtils.isTablet(service) && service.isLandscape(); final boolean showButton = videoPlayerSelected() && (orientationLocked || isVerticalVideo || tabletInLandscape); screenRotationButton.setVisibility(showButton ? View.VISIBLE : View.GONE); @@ -1542,7 +1541,7 @@ public class VideoPlayerImpl extends VideoPlayer // And the situations when we need to set custom height is // in fullscreen mode in tablet in non-multiWindow mode or with vertical video. // Other than that MATCH_PARENT is good - final boolean navBarAtTheBottom = PlayerHelper.isTablet(service) || !service.isLandscape(); + final boolean navBarAtTheBottom = DeviceUtils.isTablet(service) || !service.isLandscape(); controlsRoot.getLayoutParams().height = isFullscreen && !isInMultiWindow() && navBarAtTheBottom ? size.y : ViewGroup.LayoutParams.MATCH_PARENT; controlsRoot.requestLayout(); @@ -1612,7 +1611,7 @@ public class VideoPlayerImpl extends VideoPlayer if (parent != null && videoInLandscapeButNotInFullscreen && playingState - && !PlayerHelper.isTablet(service)) { + && !DeviceUtils.isTablet(service)) { toggleFullscreen(); } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index bd681ec44..58732bda2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -362,13 +362,6 @@ public final class PlayerHelper { context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0; } - public static boolean isTablet(@NonNull final Context context) { - return (context - .getResources() - .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) - >= Configuration.SCREENLAYOUT_SIZE_LARGE; - } - //////////////////////////////////////////////////////////////////////////// // Private helpers //////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java index 18cbece6f..26a33917f 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -13,7 +13,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import org.schabi.newpipe.R; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.views.FocusOverlayView; @@ -62,7 +62,7 @@ public class SettingsActivity extends AppCompatActivity .commit(); } - if (AndroidTvUtils.isTv(this)) { + if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } } diff --git a/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java similarity index 81% rename from app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java rename to app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java index db2ab4aa7..0afa0663c 100644 --- a/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -8,22 +8,23 @@ import android.os.BatteryManager; import android.os.Build; import android.view.KeyEvent; +import androidx.annotation.NonNull; import org.schabi.newpipe.App; import static android.content.Context.BATTERY_SERVICE; import static android.content.Context.UI_MODE_SERVICE; -public final class AndroidTvUtils { +public final class DeviceUtils { private static final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv"; private static Boolean isTV = null; - private AndroidTvUtils() { + private DeviceUtils() { } public static boolean isTv(final Context context) { - if (AndroidTvUtils.isTV != null) { - return AndroidTvUtils.isTV; + if (isTV != null) { + return isTV; } PackageManager pm = App.getApp().getPackageManager(); @@ -48,8 +49,15 @@ public final class AndroidTvUtils { isTv = isTv || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK); } - AndroidTvUtils.isTV = isTv; - return AndroidTvUtils.isTV; + DeviceUtils.isTV = isTv; + return DeviceUtils.isTV; + } + + public static boolean isTablet(@NonNull final Context context) { + return (context + .getResources() + .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) + >= Configuration.SCREENLAYOUT_SIZE_LARGE; } public static boolean isConfirmKey(final int keyCode) { diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java b/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java index 6dbcded48..a50d5a64c 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java @@ -26,7 +26,7 @@ import android.widget.SeekBar; import androidx.appcompat.widget.AppCompatSeekBar; -import org.schabi.newpipe.util.AndroidTvUtils; +import org.schabi.newpipe.util.DeviceUtils; /** * SeekBar, adapted for directional navigation. It emulates touch-related callbacks @@ -60,7 +60,7 @@ public final class FocusAwareSeekBar extends AppCompatSeekBar { @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { - if (!isInTouchMode() && AndroidTvUtils.isConfirmKey(keyCode)) { + if (!isInTouchMode() && DeviceUtils.isConfirmKey(keyCode)) { releaseTrack(); }