[mobile] support volume and brightness

pull/123/head
FongMi 3 years ago
parent 3ffff78cdb
commit 81336d6708
  1. 12
      app/src/main/res/anim/forward.xml
  2. 71
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java
  3. 32
      app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java
  4. 10
      app/src/mobile/res/drawable/ic_widget_bright_high.xml
  5. 10
      app/src/mobile/res/drawable/ic_widget_bright_low.xml
  6. 10
      app/src/mobile/res/drawable/ic_widget_bright_medium.xml
  7. 11
      app/src/mobile/res/drawable/ic_widget_volume_high.xml
  8. 11
      app/src/mobile/res/drawable/ic_widget_volume_low.xml
  9. 11
      app/src/mobile/res/drawable/ic_widget_volume_medium.xml
  10. 73
      app/src/mobile/res/layout/view_widget_vod.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:repeatMode="reverse">
<translate
android:duration="200"
android:fromXDelta="-50%"
android:repeatCount="infinite"
android:toXDelta="50%" />
</set>

@ -95,7 +95,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
private Runnable mR1;
private Runnable mR2;
private Runnable mR3;
private Runnable mR4;
public static void push(Activity activity, String url) {
start(activity, "push_agent", url, url);
@ -193,7 +192,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
mR1 = this::hideControl;
mR2 = this::setTraffic;
mR3 = this::setOrient;
mR4 = this::showTime;
mSiteKey = getKey();
setRecyclerView();
setVideoView();
@ -619,23 +617,18 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
mBinding.widget.error.setVisibility(View.GONE);
}
private void showTime() {
mBinding.widget.position.setText(mPlayers.getPositionTime(0));
App.post(mR4, 200);
private void showPosition(int resId) {
showPosition(resId, 0);
}
private void showState(int resId) {
showState(resId, 0);
}
private void showState(int resId, long time) {
private void showPosition(int resId, long time) {
mBinding.widget.action.setImageResource(resId);
mBinding.widget.state.setVisibility(View.VISIBLE);
mBinding.widget.position.setText(mPlayers.getPositionTime(time));
mBinding.widget.position.setVisibility(View.VISIBLE);
mBinding.widget.time.setText(mPlayers.getPositionTime(time));
}
private void hideState() {
mBinding.widget.state.setVisibility(View.GONE);
private void hidePosition() {
mBinding.widget.position.setVisibility(View.GONE);
}
private void showControl() {
@ -914,13 +907,13 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
}
private void onPause(boolean visible) {
if (visible) showState(R.drawable.ic_control_play);
if (visible) showPosition(R.drawable.ic_control_play);
mPlayers.pause();
}
private void onPlay() {
mPlayers.play();
hideState();
hidePosition();
}
private boolean isFullscreen() {
@ -993,26 +986,54 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
@Override
public void onSpeedUp() {
mBinding.widget.speed.startAnimation(ResUtil.getAnim(R.anim.forward));
mBinding.widget.speed.setVisibility(View.VISIBLE);
mPlayers.setSpeed(3.0f);
showState(R.drawable.ic_widget_forward);
showTime();
}
@Override
public void onSpeedReset() {
public void onSpeedEnd() {
mBinding.widget.speed.setVisibility(View.GONE);
mBinding.widget.speed.clearAnimation();
mPlayers.setSpeed(1.0f);
App.removeCallbacks(mR4);
hideState();
}
@Override
public void onSeeking(int time) {
showState(time > 0 ? R.drawable.ic_widget_forward : R.drawable.ic_widget_rewind, time);
public void onBright(int progress) {
mBinding.widget.bright.setVisibility(View.VISIBLE);
mBinding.widget.brightProgress.setProgress(progress);
if (progress < 35) mBinding.widget.brightIcon.setImageResource(R.drawable.ic_widget_bright_low);
else if (progress < 70) mBinding.widget.brightIcon.setImageResource(R.drawable.ic_widget_bright_medium);
else mBinding.widget.brightIcon.setImageResource(R.drawable.ic_widget_bright_high);
}
@Override
public void onBrightEnd() {
mBinding.widget.bright.setVisibility(View.GONE);
}
@Override
public void onVolume(int progress) {
mBinding.widget.volume.setVisibility(View.VISIBLE);
mBinding.widget.volumeProgress.setProgress(progress);
if (progress < 35) mBinding.widget.volumeIcon.setImageResource(R.drawable.ic_widget_volume_low);
else if (progress < 70) mBinding.widget.volumeIcon.setImageResource(R.drawable.ic_widget_volume_medium);
else mBinding.widget.volumeIcon.setImageResource(R.drawable.ic_widget_volume_high);
}
@Override
public void onVolumeEnd() {
mBinding.widget.volume.setVisibility(View.GONE);
}
@Override
public void onSeek(int time) {
showPosition(time > 0 ? R.drawable.ic_widget_forward : R.drawable.ic_widget_rewind, time);
hideProgress();
}
@Override
public void onSeekTo(int time) {
public void onSeekEnd(int time) {
mPlayers.seekTo(time);
showProgress();
onPlay();
@ -1104,6 +1125,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
protected void onDestroy() {
super.onDestroy();
mPlayers.release();
App.removeCallbacks(mR1, mR2, mR3, mR4);
App.removeCallbacks(mR1, mR2, mR3);
}
}

@ -43,8 +43,10 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
}
public boolean onTouchEvent(MotionEvent e) {
if (changeTime && e.getAction() == MotionEvent.ACTION_UP) seekTo();
if (changeSpeed && e.getAction() == MotionEvent.ACTION_UP) listener.onSpeedReset();
if (changeTime && e.getAction() == MotionEvent.ACTION_UP) onSeekEnd();
if (changeSpeed && e.getAction() == MotionEvent.ACTION_UP) listener.onSpeedEnd();
if (changeBright && e.getAction() == MotionEvent.ACTION_UP) listener.onBrightEnd();
if (changeVolume && e.getAction() == MotionEvent.ACTION_UP) listener.onVolumeEnd();
return detector.onTouchEvent(e);
}
@ -85,7 +87,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
float deltaX = e2.getX() - e1.getX();
float deltaY = e1.getY() - e2.getY();
if (touch) checkFunc(distanceX, distanceY, e2);
if (changeTime) listener.onSeeking(time = (int) deltaX * 50);
if (changeTime) listener.onSeek(time = (int) deltaX * 50);
if (changeBright) setBright(deltaY);
if (changeVolume) setVolume(deltaY);
return true;
@ -104,7 +106,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
}
private void subTime() {
listener.onSeeking(time = time - Constant.INTERVAL_SEEK);
listener.onSeek(time = time - Constant.INTERVAL_SEEK);
App.post(runnable, getDelay());
}
@ -115,9 +117,9 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
else return 50;
}
private void seekTo() {
private void onSeekEnd() {
App.removeCallbacks(runnable);
listener.onSeekTo(time);
listener.onSeekEnd(time);
changeTime = false;
time = 0;
}
@ -146,7 +148,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
WindowManager.LayoutParams attributes = App.activity().getWindow().getAttributes();
attributes.screenBrightness = brightness;
App.activity().getWindow().setAttributes(attributes);
int percent = (int) (brightness * 100);
listener.onBright((int) (brightness * 100));
}
private void setVolume(float deltaY) {
@ -157,18 +159,26 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
if (index > maxVolume) index = maxVolume;
if (index < 0) index = 0;
manager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) index, 0);
int percent = (int) (index / maxVolume * 100);
listener.onVolume((int) (index / maxVolume * 100));
}
public interface Listener {
void onSpeedUp();
void onSpeedReset();
void onSpeedEnd();
void onSeeking(int time);
void onBright(int progress);
void onSeekTo(int time);
void onBrightEnd();
void onVolume(int progress);
void onVolumeEnd();
void onSeek(int time);
void onSeekEnd(int time);
void onSingleTap();

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,8.69L20,4h-4.69L12,0.69 8.69,4L4,4v4.69L0.69,12 4,15.31L4,20h4.69L12,23.31 15.31,20L20,20v-4.69L23.31,12 20,8.69zM12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4z" />
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,15.31L23.31,12 20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69zM12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6z" />
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,15.31L23.31,12 20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69zM12,18V6c3.31,0 6,2.69 6,6s-2.69,6 -6,6z" />
</vector>

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z" />
</vector>

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,9v6h4l5,5V4l-5,5H7z" />
</vector>

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M18.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM5,9v6h4l5,5V4L9,9H5z" />
</vector>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
@ -56,10 +57,11 @@
</LinearLayout>
<LinearLayout
android:id="@+id/state"
android:id="@+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:background="@drawable/shape_widget"
android:gravity="center"
android:orientation="horizontal"
@ -74,7 +76,7 @@
android:src="@drawable/ic_widget_rewind" />
<TextView
android:id="@+id/position"
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
@ -82,4 +84,69 @@
tools:text="00:00:00" />
</LinearLayout>
<ImageView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:src="@drawable/ic_widget_forward"
android:visibility="gone" />
<LinearLayout
android:id="@+id/bright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:background="@drawable/shape_widget"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/brightIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
tools:src="@drawable/ic_widget_bright_high" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/brightProgress"
android:layout_width="120dp"
android:layout_height="wrap_content"
app:indicatorColor="@color/white"
app:trackColor="@color/grey_700" />
</LinearLayout>
<LinearLayout
android:id="@+id/volume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:background="@drawable/shape_widget"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/volumeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
tools:src="@drawable/ic_widget_volume_high" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/volumeProgress"
android:layout_width="120dp"
android:layout_height="wrap_content"
app:indicatorColor="@color/white"
app:trackColor="@color/grey_700" />
</LinearLayout>
</FrameLayout>
Loading…
Cancel
Save