Implement screen orientation toggle

This commit is contained in:
Mauricio Colli 2017-03-27 10:12:22 -03:00
parent b43c56085d
commit 71ae342f52
13 changed files with 36 additions and 9 deletions

View File

@ -18,7 +18,6 @@ import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
@ -232,8 +231,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
this.playbackSeekBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) this.qualityPopupMenu = new PopupMenu(context, qualityTextView, Gravity.CENTER | Gravity.BOTTOM);
else this.qualityPopupMenu = new PopupMenu(context, qualityTextView);
this.qualityPopupMenu = new PopupMenu(context, qualityTextView);
((ProgressBar) this.loadingPanel.findViewById(R.id.progressBarLoadingPanel)).getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
@ -419,7 +417,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (DEBUG) Log.d(TAG, "onBuffering() called");
loadingPanel.setBackgroundColor(Color.TRANSPARENT);
animateView(loadingPanel, true, 500, 0);
animateView(controlsRoot, false, 0, 0);
animateView(controlsRoot, false, 0, 0, true);
}
@Override

View File

@ -5,6 +5,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.media.AudioManager;
import android.net.Uri;
@ -173,6 +174,12 @@ public class ExoPlayerActivity extends Activity {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void toggleOrientation() {
setRequestedOrientation(getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels
? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
///////////////////////////////////////////////////////////////////////////
@SuppressWarnings({"unused", "WeakerAccess"})
@ -183,6 +190,7 @@ public class ExoPlayerActivity extends Activity {
private TextView brightnessTextView;
private ImageButton repeatButton;
private ImageButton screenRotationButton;
private ImageButton playPauseButton;
AbstractPlayerImpl() {
@ -198,6 +206,7 @@ public class ExoPlayerActivity extends Activity {
this.brightnessTextView = (TextView) rootView.findViewById(R.id.brightnessTextView);
this.repeatButton = (ImageButton) rootView.findViewById(R.id.repeatButton);
this.screenRotationButton = (ImageButton) rootView.findViewById(R.id.screenRotationButton);
this.playPauseButton = (ImageButton) rootView.findViewById(R.id.playPauseButton);
// Due to a bug on lower API, lets set the alpha instead of using a drawable
@ -219,6 +228,7 @@ public class ExoPlayerActivity extends Activity {
repeatButton.setOnClickListener(this);
playPauseButton.setOnClickListener(this);
screenRotationButton.setOnClickListener(this);
}
@Override
@ -285,6 +295,7 @@ public class ExoPlayerActivity extends Activity {
super.onClick(v);
if (v.getId() == repeatButton.getId()) onRepeatClicked();
else if (v.getId() == playPauseButton.getId()) onVideoPlayPause();
else if (v.getId() == screenRotationButton.getId()) onScreenRotationClicked();
if (getCurrentState() != STATE_COMPLETED) {
animateView(playerImpl.getControlsRoot(), true, 300, 0, new Runnable() {
@ -298,6 +309,11 @@ public class ExoPlayerActivity extends Activity {
}
}
private void onScreenRotationClicked() {
if (DEBUG) Log.d(TAG, "onScreenRotationClicked() called");
toggleOrientation();
}
@Override
public void onVideoPlayPause() {
super.onVideoPlayPause();
@ -348,7 +364,6 @@ public class ExoPlayerActivity extends Activity {
@Override
public void onLoading() {
super.onLoading();
hideSystemUi();
playPauseButton.setImageResource(R.drawable.ic_pause_white);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -105,9 +105,9 @@
android:id="@+id/qualityTextView"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="4dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@+id/repeatButton"
android:layout_toLeftOf="@+id/screenRotationButton"
android:gravity="center"
android:minWidth="50dp"
android:text="720p"
@ -115,12 +115,26 @@
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded"/>
<ImageButton
android:id="@+id/screenRotationButton"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@+id/repeatButton"
android:background="#00ffffff"
android:clickable="true"
android:padding="8dp"
android:scaleType="fitXY"
android:src="@drawable/ic_screen_rotation_white"
tools:ignore="ContentDescription,RtlHardcoded"/>
<ImageButton
android:id="@+id/repeatButton"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@+id/fullScreenButton"
android:background="#00ffffff"
android:clickable="true"