Skip to content

Commit ff774a1

Browse files
han-szAudricV
authored andcommitted
Fix persistent hover overlay when mouse connected
1 parent 95a65d5 commit ff774a1

2 files changed

Lines changed: 73 additions & 13 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,7 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
639639
? View.VISIBLE
640640
: View.GONE
641641
);
642-
643-
if (DeviceUtils.isTv(getContext())) {
644-
// remove ripple effects from detail controls
645-
final int transparent = ContextCompat.getColor(requireContext(),
646-
R.color.transparent_background_color);
647-
binding.detailControlsPlaylistAppend.setBackgroundColor(transparent);
648-
binding.detailControlsBackground.setBackgroundColor(transparent);
649-
binding.detailControlsPopup.setBackgroundColor(transparent);
650-
binding.detailControlsDownload.setBackgroundColor(transparent);
651-
binding.detailControlsShare.setBackgroundColor(transparent);
652-
binding.detailControlsOpenInBrowser.setBackgroundColor(transparent);
653-
binding.detailControlsPlayWithKodi.setBackgroundColor(transparent);
654-
}
642+
accommodateForTvAndDesktopMode();
655643
}
656644

657645
@Override
@@ -2106,6 +2094,30 @@ private void setupBrightness() {
21062094
}
21072095
}
21082096

2097+
/**
2098+
* Make changes to the UI to accommodate for better usability on bigger screens such as TVs
2099+
* or in Android's desktop mode (DeX etc.)
2100+
*/
2101+
private void accommodateForTvAndDesktopMode() {
2102+
if (DeviceUtils.isTv(getContext())) {
2103+
// remove ripple effects from detail controls
2104+
final int transparent = ContextCompat.getColor(requireContext(),
2105+
R.color.transparent_background_color);
2106+
binding.detailControlsPlaylistAppend.setBackgroundColor(transparent);
2107+
binding.detailControlsBackground.setBackgroundColor(transparent);
2108+
binding.detailControlsPopup.setBackgroundColor(transparent);
2109+
binding.detailControlsDownload.setBackgroundColor(transparent);
2110+
binding.detailControlsShare.setBackgroundColor(transparent);
2111+
binding.detailControlsOpenInBrowser.setBackgroundColor(transparent);
2112+
binding.detailControlsPlayWithKodi.setBackgroundColor(transparent);
2113+
}
2114+
if (DeviceUtils.isDesktopMode(getContext())) {
2115+
// Remove the "hover" overlay (since it is visible on all mouse events and interferes
2116+
// with the video content being played)
2117+
binding.detailThumbnailRootLayout.setForeground(null);
2118+
}
2119+
}
2120+
21092121
private void checkLandscape() {
21102122
if ((!player.isPlaying() && player.getPlayQueue() != playQueue)
21112123
|| player.getPlayQueue() == null) {

app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.util;
22

3+
import android.annotation.SuppressLint;
34
import android.app.UiModeManager;
45
import android.content.Context;
56
import android.content.pm.PackageManager;
@@ -22,6 +23,9 @@
2223
import org.schabi.newpipe.App;
2324
import org.schabi.newpipe.R;
2425

26+
import java.lang.reflect.InvocationTargetException;
27+
import java.lang.reflect.Method;
28+
2529
public final class DeviceUtils {
2630

2731
private static final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv";
@@ -84,6 +88,50 @@ public static boolean isTv(final Context context) {
8488
return DeviceUtils.isTV;
8589
}
8690

91+
public static boolean isDesktopMode(final Context context) {
92+
final boolean isDesktopMode = ContextCompat.getSystemService(context, UiModeManager.class)
93+
.getCurrentModeType() == Configuration.UI_MODE_TYPE_DESK;
94+
95+
// DeX check for standalone and multi-window mode
96+
boolean isDeXMode = false;
97+
try {
98+
final Configuration config = context.getResources().getConfiguration();
99+
final Class<?> configClass = config.getClass();
100+
final int semDesktopModeEnabledConst =
101+
configClass.getField("SEM_DESKTOP_MODE_ENABLED").getInt(configClass);
102+
final int currentMode =
103+
configClass.getField("semDesktopModeEnabled").getInt(config);
104+
if (semDesktopModeEnabledConst == currentMode) {
105+
isDeXMode = true;
106+
}
107+
} catch (final NoSuchFieldException | IllegalAccessException e) {
108+
// empty
109+
}
110+
@SuppressLint("WrongConstant") final Object desktopModeManager = context
111+
.getApplicationContext()
112+
.getSystemService("desktopmode");
113+
if (desktopModeManager != null) {
114+
try {
115+
final Method getDesktopModeStateMethod = desktopModeManager.getClass()
116+
.getDeclaredMethod("getDesktopModeState");
117+
final Object desktopModeState = getDesktopModeStateMethod
118+
.invoke(desktopModeManager);
119+
final Class<?> desktopModeStateClass = desktopModeState.getClass();
120+
final Method getEnabledMethod = desktopModeStateClass
121+
.getDeclaredMethod("getEnabled");
122+
final int enabled = (int) getEnabledMethod.invoke(desktopModeState);
123+
final boolean isEnabled = enabled == desktopModeStateClass
124+
.getDeclaredField("ENABLED").getInt(desktopModeStateClass);
125+
126+
isDeXMode = isEnabled;
127+
} catch (NoSuchFieldException | NoSuchMethodException
128+
| IllegalAccessException | InvocationTargetException e) {
129+
// Device does not support DeX 3.0
130+
}
131+
}
132+
return isDesktopMode || isDeXMode;
133+
}
134+
87135
public static boolean isTablet(@NonNull final Context context) {
88136
final String tabletModeSetting = PreferenceManager.getDefaultSharedPreferences(context)
89137
.getString(context.getString(R.string.tablet_mode_key), "");

0 commit comments

Comments
 (0)