aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java45
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/layout/activity_motion_test.xml17
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/video_preferences.xml5
8 files changed, 49 insertions, 72 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 30cfcf72..b870c591 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -52,9 +52,6 @@
android:theme="@style/AppTheme.TranslucentStatusBar"
android:windowSoftInputMode="adjustPan" />
<activity
- android:name=".activities.MotionTestActivity"
- android:theme="@style/AppTheme.NoActionBar" />
- <activity
android:name=".activities.LockScreenActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java
deleted file mode 100644
index ba8d0681..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java
+++ /dev/null
@@ -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);
- }
- });
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
index a09d0954..3ba9d497 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -3,8 +3,10 @@ package ml.docilealligator.infinityforreddit.activities;
import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -15,6 +17,7 @@ import android.os.Handler;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
@@ -135,6 +138,7 @@ public class ViewVideoActivity extends AppCompatActivity {
private int videoType;
private boolean isDataSavingMode;
private boolean isHd;
+ private Integer originalOrientation;
@Inject
@Named("no_oauth")
@@ -184,10 +188,12 @@ public class ViewVideoActivity extends AppCompatActivity {
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
+ Resources resources = getResources();
+
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.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);
int networkType = Utils.getConnectedNetwork(this);
@@ -199,18 +205,18 @@ public class ViewVideoActivity extends AppCompatActivity {
isHd = !isDataSavingMode;
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
- 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);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
- params.bottomMargin = getResources().getDimensionPixelSize(resourceId);
+ params.bottomMargin = resources.getDimensionPixelSize(resourceId);
} else {
//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);
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);
if (savedInstanceState == null) {
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();
wasPlaying = player.getPlayWhenReady();
player.setPlayWhenReady(false);
+ if (originalOrientation != null) {
+ setRequestedOrientation(originalOrientation);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
index 2f798c1e..44ff8f9f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
@@ -51,10 +51,6 @@ public class MaterialYouUtils {
WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
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 colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3);
int backgroundColor = lightenColor(colorPrimaryInt, 0.2);
@@ -65,6 +61,10 @@ public class MaterialYouUtils {
int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt);
int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor);
+ CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context);
+ CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
+ CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
+
lightTheme.colorPrimary = colorPrimaryInt;
lightTheme.colorPrimaryDark = colorPrimaryDarkInt;
lightTheme.colorAccent = colorAccentInt;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 7f43ff5a..0f2c2a33 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -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 ENABLE_MATERIAL_YOU = "enable_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 MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
diff --git a/app/src/main/res/layout/activity_motion_test.xml b/app/src/main/res/layout/activity_motion_test.xml
deleted file mode 100644
index c65afba9..00000000
--- a/app/src/main/res/layout/activity_motion_test.xml
+++ /dev/null
@@ -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> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d752bffa..276f2746 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -585,6 +585,7 @@
<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_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>
diff --git a/app/src/main/res/xml/video_preferences.xml b/app/src/main/res/xml/video_preferences.xml
index a0924140..93ccff6b 100644
--- a/app/src/main/res/xml/video_preferences.xml
+++ b/app/src/main/res/xml/video_preferences.xml
@@ -25,6 +25,11 @@
app:title="@string/settings_video_player_ignore_nav_bar_title"
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
app:title="@string/settings_video_autoplay_title" />