mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
New option: Switch to landscape orientation in video player automatically.
This commit is contained in:
parent
5924c921cf
commit
988989826f
@ -51,9 +51,6 @@
|
|||||||
android:parentActivityName=".activities.MainActivity"
|
android:parentActivityName=".activities.MainActivity"
|
||||||
android:theme="@style/AppTheme.TranslucentStatusBar"
|
android:theme="@style/AppTheme.TranslucentStatusBar"
|
||||||
android:windowSoftInputMode="adjustPan" />
|
android:windowSoftInputMode="adjustPan" />
|
||||||
<activity
|
|
||||||
android:name=".activities.MotionTestActivity"
|
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.LockScreenActivity"
|
android:name=".activities.LockScreenActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package ml.docilealligator.infinityforreddit.activities;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout;
|
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
|
||||||
|
|
||||||
public class MotionTestActivity extends AppCompatActivity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_motion_test);
|
|
||||||
|
|
||||||
MotionLayout motionLayout = findViewById(R.id.motion_layout);
|
|
||||||
motionLayout.addTransitionListener(new MotionLayout.TransitionListener() {
|
|
||||||
@Override
|
|
||||||
public void onTransitionStarted(MotionLayout motionLayout, int i, int i1) {
|
|
||||||
Log.i("asdfasdf", "start " + (i == R.id.start) + " " + (i1 == R.id.end));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTransitionChange(MotionLayout motionLayout, int i, int i1, float v) {
|
|
||||||
Log.i("asdfasdf", "start " + (i == R.id.start) + " " + (i1 == R.id.end) + " " + v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTransitionCompleted(MotionLayout motionLayout, int i) {
|
|
||||||
Log.i("asdfasdf", "complete " + (i == R.id.start));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTransitionTrigger(MotionLayout motionLayout, int i, boolean b, float v) {
|
|
||||||
Log.i("asdfasdf", "trigger " + (i == R.id.start) + " " + v + " " + b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,8 +3,10 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
@ -15,6 +17,7 @@ import android.os.Handler;
|
|||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.OrientationEventListener;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
@ -135,6 +138,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
private int videoType;
|
private int videoType;
|
||||||
private boolean isDataSavingMode;
|
private boolean isDataSavingMode;
|
||||||
private boolean isHd;
|
private boolean isHd;
|
||||||
|
private Integer originalOrientation;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("no_oauth")
|
@Named("no_oauth")
|
||||||
@ -184,10 +188,12 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
|
||||||
|
Resources resources = getResources();
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
|
Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp);
|
||||||
actionBar.setHomeAsUpIndicator(upArrow);
|
actionBar.setHomeAsUpIndicator(upArrow);
|
||||||
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
|
actionBar.setBackgroundDrawable(new ColorDrawable(resources.getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
|
||||||
|
|
||||||
String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
int networkType = Utils.getConnectedNetwork(this);
|
int networkType = Utils.getConnectedNetwork(this);
|
||||||
@ -199,18 +205,18 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
isHd = !isDataSavingMode;
|
isHd = !isDataSavingMode;
|
||||||
|
|
||||||
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
|
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
|
||||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) {
|
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
|
||||||
//Set player controller bottom margin in order to display it above the navbar
|
//Set player controller bottom margin in order to display it above the navbar
|
||||||
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||||
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
|
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
|
||||||
params.bottomMargin = getResources().getDimensionPixelSize(resourceId);
|
params.bottomMargin = resources.getDimensionPixelSize(resourceId);
|
||||||
} else {
|
} else {
|
||||||
//Set player controller right margin in order to display it above the navbar
|
//Set player controller right margin in order to display it above the navbar
|
||||||
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||||
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
|
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
|
||||||
params.rightMargin = getResources().getDimensionPixelSize(resourceId);
|
params.rightMargin = resources.getDimensionPixelSize(resourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +231,28 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
|
isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1);
|
resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1);
|
||||||
|
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION, false)) {
|
||||||
|
originalOrientation = resources.getConfiguration().orientation;
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||||
|
|
||||||
|
OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
|
||||||
|
@Override
|
||||||
|
public void onOrientationChanged(int orientation) {
|
||||||
|
int epsilon = 10;
|
||||||
|
int leftLandscape = 90;
|
||||||
|
int rightLandscape = 270;
|
||||||
|
if(epsilonCheck(orientation, leftLandscape, epsilon) ||
|
||||||
|
epsilonCheck(orientation, rightLandscape, epsilon)){
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean epsilonCheck(int a, int b, int epsilon) {
|
||||||
|
return a > b - epsilon && a < b + epsilon;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
orientationEventListener.enable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -575,6 +603,9 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
wasPlaying = player.getPlayWhenReady();
|
wasPlaying = player.getPlayWhenReady();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
|
if (originalOrientation != null) {
|
||||||
|
setRequestedOrientation(originalOrientation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,10 +51,6 @@ public class MaterialYouUtils {
|
|||||||
WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
|
WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
|
||||||
|
|
||||||
if (wallpaperColors != null) {
|
if (wallpaperColors != null) {
|
||||||
CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context);
|
|
||||||
CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
|
|
||||||
CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
|
|
||||||
|
|
||||||
int colorPrimaryInt = lightenColor(wallpaperColors.getPrimaryColor().toArgb(), 0.4);
|
int colorPrimaryInt = lightenColor(wallpaperColors.getPrimaryColor().toArgb(), 0.4);
|
||||||
int colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3);
|
int colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3);
|
||||||
int backgroundColor = lightenColor(colorPrimaryInt, 0.2);
|
int backgroundColor = lightenColor(colorPrimaryInt, 0.2);
|
||||||
@ -65,6 +61,10 @@ public class MaterialYouUtils {
|
|||||||
int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt);
|
int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt);
|
||||||
int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor);
|
int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor);
|
||||||
|
|
||||||
|
CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context);
|
||||||
|
CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
|
||||||
|
CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
|
||||||
|
|
||||||
lightTheme.colorPrimary = colorPrimaryInt;
|
lightTheme.colorPrimary = colorPrimaryInt;
|
||||||
lightTheme.colorPrimaryDark = colorPrimaryDarkInt;
|
lightTheme.colorPrimaryDark = colorPrimaryDarkInt;
|
||||||
lightTheme.colorAccent = colorAccentInt;
|
lightTheme.colorAccent = colorAccentInt;
|
||||||
|
@ -182,6 +182,7 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String SHOW_ONLY_ONE_COMMENT_LEVEL_INDICATOR = "show_only_one_comment_level_indicator";
|
public static final String SHOW_ONLY_ONE_COMMENT_LEVEL_INDICATOR = "show_only_one_comment_level_indicator";
|
||||||
public static final String ENABLE_MATERIAL_YOU = "enable_material_you";
|
public static final String ENABLE_MATERIAL_YOU = "enable_material_you";
|
||||||
public static final String APPLY_MATERIAL_YOU = "apply_material_you";
|
public static final String APPLY_MATERIAL_YOU = "apply_material_you";
|
||||||
|
public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation";
|
||||||
|
|
||||||
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
|
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
|
||||||
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ml.docilealligator.infinityforreddit.customviews.ClickableMotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/motion_layout"
|
|
||||||
tools:context=".activities.MotionTestActivity"
|
|
||||||
app:layoutDescription="@xml/activity_motion_test_scene">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/button"
|
|
||||||
android:background="@color/colorAccent"
|
|
||||||
android:layout_width="64dp"
|
|
||||||
android:layout_height="64dp" />
|
|
||||||
|
|
||||||
</ml.docilealligator.infinityforreddit.customviews.ClickableMotionLayout>
|
|
@ -585,6 +585,7 @@
|
|||||||
<string name="settings_nsfw_and_spoiler_dangerous_group_title">Dangerous</string>
|
<string name="settings_nsfw_and_spoiler_dangerous_group_title">Dangerous</string>
|
||||||
<string name="settings_disable_nsfw_forever_title">Disable NSFW Forever</string>
|
<string name="settings_disable_nsfw_forever_title">Disable NSFW Forever</string>
|
||||||
<string name="settings_show_only_one_comment_level_indicator">Show Only One Comment Level Indicator</string>
|
<string name="settings_show_only_one_comment_level_indicator">Show Only One Comment Level Indicator</string>
|
||||||
|
<string name="settings_video_player_automatic_landscape_orientation">Switch to Landscape Orientation in Video Player Automatically</string>
|
||||||
|
|
||||||
<string name="no_link_available">Cannot get the link</string>
|
<string name="no_link_available">Cannot get the link</string>
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
app:title="@string/settings_video_player_ignore_nav_bar_title"
|
app:title="@string/settings_video_player_ignore_nav_bar_title"
|
||||||
app:summary="@string/settings_video_player_ignore_nav_bar_summary" />
|
app:summary="@string/settings_video_player_ignore_nav_bar_summary" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:key="video_player_automatic_landscape_orientation"
|
||||||
|
app:title="@string/settings_video_player_automatic_landscape_orientation" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
app:title="@string/settings_video_autoplay_title" />
|
app:title="@string/settings_video_autoplay_title" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user