diff --git a/app/src/main/java/com/fongmi/android/tv/utils/Utils.java b/app/src/main/java/com/fongmi/android/tv/utils/Utils.java index dbf7eaef7..7d3041bb3 100644 --- a/app/src/main/java/com/fongmi/android/tv/utils/Utils.java +++ b/app/src/main/java/com/fongmi/android/tv/utils/Utils.java @@ -129,6 +129,14 @@ public class Utils { return Sniffer.RULE.matcher(url).find(); } + public static boolean isAutoRotate() { + return Settings.System.getInt(App.get().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1; + } + + public static boolean hasPermission(FragmentActivity activity) { + return PermissionX.isGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); + } + public static String checkProxy(String url) { if (url.startsWith("proxy://")) return url.replace("proxy://", Server.get().getAddress("proxy?")); return url; @@ -215,8 +223,4 @@ public class Utils { imm.hideSoftInputFromWindow(windowToken, 0); } } - - public static boolean hasPermission(FragmentActivity activity) { - return PermissionX.isGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); - } } diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java index 51006a2a7..e7c157a83 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java @@ -79,6 +79,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis private boolean initAuto; private boolean autoMode; private boolean useParse; + private boolean rotate; private boolean stop; private boolean lock; private Runnable mR1; @@ -158,19 +159,19 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis return view.getVisibility() == View.GONE; } - private boolean isReplay() { - return Prefers.getReset() == 1; - } - private boolean isFromSearch() { return getCallingActivity() != null && getCallingActivity().getShortClassName().contains(SearchActivity.class.getSimpleName()); } - private int getOrientation() { + private int getLockOrient() { if (isLock()) { return ResUtil.isLand(this) ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; - } else { + } else if (isRotate()) { + return ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT; + } else if (Utils.isAutoRotate()) { return ActivityInfo.SCREEN_ORIENTATION_FULL_USER; + } else { + return ResUtil.isLand(this) ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT; } } @@ -211,12 +212,11 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis //mBinding.control.video.setOnClickListener(this::onTrack); mBinding.control.full.setOnClickListener(view -> onFull()); mBinding.control.lock.setOnClickListener(view -> onLock()); - mBinding.control.play.setOnClickListener(view -> onPlay()); + mBinding.control.play.setOnClickListener(view -> checkPlay()); mBinding.control.next.setOnClickListener(view -> checkNext()); mBinding.control.prev.setOnClickListener(view -> checkPrev()); mBinding.control.scale.setOnClickListener(view -> onScale()); mBinding.control.speed.setOnClickListener(view -> onSpeed()); - //mBinding.control.reset.setOnClickListener(view -> onReset()); mBinding.control.rotate.setOnClickListener(view -> onRotate()); mBinding.control.player.setOnClickListener(view -> onPlayer()); mBinding.control.decode.setOnClickListener(view -> onDecode()); @@ -224,7 +224,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis mBinding.control.opening.setOnClickListener(view -> onOpening()); mBinding.control.setting.setOnClickListener(view -> onSetting()); mBinding.control.speed.setOnLongClickListener(view -> onSpeedLong()); - //mBinding.control.reset.setOnLongClickListener(view -> onResetToggle()); mBinding.control.ending.setOnLongClickListener(view -> onEndingReset()); mBinding.control.opening.setOnLongClickListener(view -> onOpeningReset()); mBinding.video.setOnTouchListener((view, event) -> mKeyDown.onTouchEvent(event)); @@ -252,7 +251,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis mBinding.control.player.setText(mPlayers.getPlayerText()); getExo().setVisibility(mPlayers.isExo() ? View.VISIBLE : View.GONE); getIjk().setVisibility(mPlayers.isIjk() ? View.VISIBLE : View.GONE); - //mBinding.control.reset.setText(ResUtil.getStringArray(R.array.select_reset)[Prefers.getReset()]); } private void setDecodeView() { @@ -421,11 +419,19 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis private void onLock() { setLock(!isLock()); - setRequestedOrientation(getOrientation()); + setRequestedOrientation(getLockOrient()); mBinding.control.lock.setImageResource(isLock() ? R.drawable.ic_lock_on : R.drawable.ic_lock_off); showControl(); } + private void checkPlay() { + setR1Callback(); + boolean playing = mPlayers.isPlaying(); + mBinding.control.play.setImageResource(playing ? R.drawable.ic_control_play : R.drawable.ic_control_pause); + if (playing) onPause(false); + else onPlay(); + } + private void checkNext() { setR1Callback(); if (mHistory.isRevPlay()) onPrev(); @@ -478,28 +484,10 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis getPlayer(getFlag(), getEpisode(), false); } - private void onReset() { - setR1Callback(); - Clock.get().setCallback(null); - if (mFlagAdapter.getItemCount() == 0) return; - if (mEpisodeAdapter.getItemCount() == 0) return; - getPlayer(getFlag(), getEpisode(), isReplay()); - } - - private boolean onResetToggle() { - Prefers.putReset(Math.abs(Prefers.getReset() - 1)); - //mBinding.control.reset.setText(ResUtil.getStringArray(R.array.select_reset)[Prefers.getReset()]); - setR1Callback(); - return true; - } - private void onRotate() { - if (ResUtil.isLand(this)) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT); - } else { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - } setR1Callback(); + setRotate(!isRotate()); + setRequestedOrientation(ResUtil.isLand(this) ? ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } private void onPlayer() { @@ -567,6 +555,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis mBinding.control.full.setImageResource(R.drawable.ic_full_off); App.post(mR3, 2000); setFullscreen(true); + setRotate(false); hideControl(); } @@ -578,6 +567,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis mBinding.video.setLayoutParams(mFrameParams); App.post(mR3, 2000); setFullscreen(false); + setRotate(false); hideControl(); } @@ -604,12 +594,13 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis } private void showControl() { - mBinding.control.top.setVisibility(isLock() ? View.GONE : View.VISIBLE); - mBinding.control.right.setVisibility(isLock() ? View.GONE : View.VISIBLE); - mBinding.control.bottom.setVisibility(isLock() ? View.GONE : View.VISIBLE); + mBinding.control.play.setImageResource(mPlayers.isPlaying() ? R.drawable.ic_control_pause : R.drawable.ic_control_play); mBinding.control.parse.setVisibility(isFullscreen() && isUseParse() ? View.VISIBLE : View.GONE); mBinding.control.action.setVisibility(isFullscreen() ? View.VISIBLE : View.GONE); mBinding.control.rotate.setVisibility(isFullscreen() ? View.VISIBLE : View.GONE); + mBinding.control.bottom.setVisibility(isLock() ? View.GONE : View.VISIBLE); + mBinding.control.right.setVisibility(isLock() ? View.GONE : View.VISIBLE); + mBinding.control.top.setVisibility(isLock() ? View.GONE : View.VISIBLE); mBinding.control.getRoot().setVisibility(View.VISIBLE); setR1Callback(); } @@ -625,7 +616,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis } private void setOrient() { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); + if (Utils.isAutoRotate()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); } private void setR1Callback() { @@ -811,6 +802,14 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis this.useParse = useParse; } + public boolean isRotate() { + return rotate; + } + + public void setRotate(boolean rotate) { + this.rotate = rotate; + } + public boolean isStop() { return stop; } @@ -866,7 +865,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis if (Utils.hasPIP() && isInPictureInPictureMode()) return; if (isFullscreen()) Utils.hideSystemUI(this); if (ResUtil.isLand(this)) enterFullscreen(); - if (ResUtil.isPort(this)) exitFullscreen(); + if (ResUtil.isPort(this) && !isRotate()) exitFullscreen(); } @Override diff --git a/app/src/mobile/res/layout/view_control_vod.xml b/app/src/mobile/res/layout/view_control_vod.xml index d15f320a4..d5adc4514 100644 --- a/app/src/mobile/res/layout/view_control_vod.xml +++ b/app/src/mobile/res/layout/view_control_vod.xml @@ -85,18 +85,19 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical" - android:paddingTop="8dp" - android:paddingBottom="8dp"> + android:paddingTop="4dp" + android:paddingBottom="4dp"> @@ -130,9 +132,7 @@ android:id="@+id/action" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginTop="4dp" - android:layout_marginEnd="16dp" + android:fillViewport="true" android:scrollbars="none" android:visibility="gone" tools:visibility="visible"> @@ -141,14 +141,22 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:clipChildren="false" + android:clipToPadding="false" android:gravity="center" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingStart="16dp" + android:paddingEnd="16dp"> @@ -157,8 +165,11 @@ android:id="@+id/decode" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" android:background="?attr/selectableItemBackgroundBorderless" + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" android:textColor="@color/white" android:textSize="14sp" tools:text="硬解" /> @@ -167,8 +178,11 @@ android:id="@+id/opening" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" android:background="?attr/selectableItemBackgroundBorderless" + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" android:textColor="@color/white" android:textSize="14sp" tools:text="片頭" /> @@ -177,33 +191,44 @@ android:id="@+id/prev" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="16dp" android:background="?attr/selectableItemBackgroundBorderless" + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" android:src="@drawable/ic_control_prev" /> + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" + android:src="@drawable/ic_control_pause" /> @@ -212,8 +237,11 @@ android:id="@+id/speed" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" android:background="?attr/selectableItemBackgroundBorderless" + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" android:textColor="@color/white" android:textSize="14sp" tools:text="速度" /> @@ -223,6 +251,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/selectableItemBackgroundBorderless" + android:paddingStart="8dp" + android:paddingTop="4dp" + android:paddingEnd="8dp" + android:paddingBottom="4dp" android:textColor="@color/white" android:textSize="14sp" tools:text="縮放" />