Fullscreen Button

This commit is contained in:
Stefan Schueller 2018-12-29 14:21:08 +01:00
parent 36c36a3ea7
commit f468a9998f
4 changed files with 116 additions and 36 deletions

View File

@ -1,3 +1,21 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* License: GPL-3.0+
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.schueller.peertube.activity;
import android.content.ComponentName;
@ -5,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
@ -38,6 +57,7 @@ import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import com.mikepenz.iconics.Iconics;
import com.squareup.picasso.Picasso;
import net.schueller.peertube.R;
import net.schueller.peertube.fragment.VideoOptionsFragment;
@ -53,6 +73,7 @@ import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY;
import static net.schueller.peertube.helper.Constants.DEFAULT_THEME;
import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY;
@ -64,6 +85,8 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
private PlayerView simpleExoPlayerView;
private Intent videoPlayerIntent;
private Context context = this;
private TextView fullscreenButton;
private Boolean isFullscreen = false;
boolean mBound = false;
VideoPlayerService mService;
@ -111,8 +134,24 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
simpleExoPlayerView = new PlayerView(this);
simpleExoPlayerView = findViewById(R.id.video_view);
videoPlayerIntent = new Intent(this, VideoPlayerService.class);
bindService(videoPlayerIntent, mConnection, Context.BIND_AUTO_CREATE);
// Full screen Icon
fullscreenButton = findViewById(R.id.exo_fullscreen);
fullscreenButton.setText(R.string.video_expand_icon);
new Iconics.IconicsBuilder().ctx(this).on(fullscreenButton).build();
fullscreenButton.setOnClickListener(view -> {
Log.d(TAG, "Fullscreen");
if (!isFullscreen) {
isFullscreen = true;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
fullscreenButton.setText(R.string.video_compress_icon);
} else {
isFullscreen = false;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
fullscreenButton.setText(R.string.video_expand_icon);
}
new Iconics.IconicsBuilder().ctx(this).on(fullscreenButton).build();
});
}
@ -381,6 +420,16 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
@Override
protected void onStop() {
super.onStop();
// SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
//
// Log.v(TAG, "" + sharedPref.getBoolean(BACKGROUND_PLAY_PREF_KEY, false));
//
// if (!sharedPref.getBoolean(BACKGROUND_PLAY_PREF_KEY, false)) {
// Log.v(TAG, "BACKGROUND_PLAY_PREF_KEY...");
// stopService(new Intent(this, VideoPlayerService.class));
// }
if (mBound) {
unbindService(mConnection);
mBound = false;
@ -391,6 +440,11 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
@Override
protected void onStart() {
super.onStart();
//
// if (!mBound) {
// videoPlayerIntent = new Intent(this, VideoPlayerService.class);
// bindService(videoPlayerIntent, mConnection, Context.BIND_AUTO_CREATE);
// }
Log.v(TAG, "onStart()...");
}

View File

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:layoutDirection="ltr"
android:background="#CC000000"
android:layoutDirection="ltr"
android:orientation="vertical"
tools:targetApi="28">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -23,14 +22,14 @@
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton android:src="@drawable/ic_action_more_vert"
<ImageButton
android:id="@+id/exo_more"
android:tint="#ffffff"
android:background="@null"
android:paddingTop="0dp"
android:layout_width="wrap_content"
android:layout_height="48dp"
/>
android:background="@null"
android:paddingTop="0dp"
android:src="@drawable/ic_action_more_vert"
android:tint="#ffffff" />
</LinearLayout>
@ -44,23 +43,28 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingTop="4dp">
<ImageButton android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind"/>
<ImageButton
android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind" />
<ImageButton android:id="@id/exo_repeat_toggle"
style="@style/ExoMediaButton"/>
<ImageButton
android:id="@id/exo_repeat_toggle"
style="@style/ExoMediaButton" />
<ImageButton android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"/>
<ImageButton
android:id="@id/exo_play"
style="@style/ExoMediaButton.Play" />
<ImageButton android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"/>
<ImageButton
android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause" />
<ImageButton android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward"/>
<ImageButton
android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward" />
</LinearLayout>
@ -70,7 +74,6 @@
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -78,30 +81,43 @@
android:gravity="bottom"
android:orientation="horizontal">
<TextView android:id="@id/exo_position"
<TextView
android:id="@id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:includeFontPadding="false"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
android:textColor="#FFBEBEBE"
android:textSize="14sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView android:id="@id/exo_duration"
<TextView
android:id="@id/exo_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
android:gravity="center_vertical"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:textColor="#FFBEBEBE"
android:textSize="14sp" />
<TextView
android:id="@+id/exo_fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:textColor="#FFBEBEBE"
android:textSize="12sp" />
</LinearLayout>
@ -116,9 +132,9 @@
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@id/exo_progress"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="26dp"
app:played_color="?attr/colorPrimary"/>
android:layout_weight="1"
app:played_color="?attr/colorPrimary" />
</LinearLayout>

View File

@ -91,5 +91,9 @@
<string name="video_speed_active_icon">{faw-check}</string>
<string name="video_expand_icon">{faw-expand}</string>
<string name="video_compress_icon">{faw-compress}</string>
<string name="pref_title_background_play">Background Playback</string>
<string name="pref_description_background_play">If enabled, continues to play video in background.</string>
</resources>

View File

@ -10,6 +10,12 @@
android:singleLine="true"
android:title="@string/pref_title_peertube_server" />
<!--<SwitchPreference-->
<!--android:key="pref_background_play"-->
<!--android:title="@string/pref_title_background_play"-->
<!--android:summary="@string/pref_description_background_play"-->
<!--android:defaultValue="true" />-->
<SwitchPreference
android:key="pref_show_nsfw"
android:title="@string/pref_title_show_nsfw"