AndroidTvUtils -> DeviceUtils

This commit is contained in:
Avently 2020-07-21 01:43:49 +03:00
parent 06e70abb86
commit c7ccf9bab8
13 changed files with 47 additions and 47 deletions

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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<SearchInfo, ListExtractor.I
if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) {
showSuggestionsPanel();
}
if (AndroidTvUtils.isTv(getContext())) {
if (DeviceUtils.isTv(getContext())) {
showKeyboardSearch();
}
});

View File

@ -15,7 +15,7 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.AndroidTvUtils;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.CommentTextOnTouchListener;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
@ -126,7 +126,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
itemView.setOnLongClickListener(view -> {
if (AndroidTvUtils.isTv(itemBuilder.getContext())) {
if (DeviceUtils.isTv(itemBuilder.getContext())) {
openCommentAuthor(item);
} else {
ShareUtils.copyToClipboard(itemBuilder.getContext(), commentText);

View File

@ -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()
}
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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
////////////////////////////////////////////////////////////////////////////

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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();
}