aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-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
4 files changed, 43 insertions, 52 deletions
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";