mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 06:35:48 +03:00
Merge pull request #9482 from nextcloud/fullscreenToggle
Fullscreen toggle
This commit is contained in:
commit
d0038c6a3b
5 changed files with 142 additions and 13 deletions
|
@ -29,6 +29,7 @@ import android.content.res.Configuration;
|
|||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -41,10 +42,11 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerControlView;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
|
@ -73,6 +75,7 @@ import javax.inject.Inject;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
|
||||
/**
|
||||
|
@ -94,7 +97,6 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
|
|||
private static final String EXTRA_PLAY_POSITION = "PLAY_POSITION";
|
||||
private static final String EXTRA_PLAYING = "PLAYING";
|
||||
private static final double MIN_DENSITY_RATIO = 24.0;
|
||||
private static final int MENU_FULLSCREEN_ID = 3344;
|
||||
|
||||
private static final String FILE = "FILE";
|
||||
private static final String USER = "USER";
|
||||
|
@ -113,7 +115,7 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
|
|||
@Inject UserAccountManager accountManager;
|
||||
FragmentPreviewMediaBinding binding;
|
||||
LinearLayout emptyListView;
|
||||
private SimpleExoPlayer exoPlayer;
|
||||
private ExoPlayer exoPlayer;
|
||||
|
||||
/**
|
||||
* Creates a fragment to preview a file.
|
||||
|
@ -297,9 +299,26 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
|
|||
// bind to any existing player
|
||||
mediaPlayerServiceConnection.bind();
|
||||
|
||||
exoPlayer = new SimpleExoPlayer.Builder(getContext()).build();
|
||||
exoPlayer = new ExoPlayer.Builder(requireContext()).build();
|
||||
binding.exoplayerView.setPlayer(exoPlayer);
|
||||
|
||||
LinearLayout linearLayout = binding.exoplayerView.findViewById(R.id.exo_center_controls);
|
||||
|
||||
if (linearLayout.getChildCount() == 5) {
|
||||
AppCompatImageButton fullScreenButton = new AppCompatImageButton(requireContext());
|
||||
fullScreenButton.setImageResource(R.drawable.exo_styled_controls_fullscreen_exit);
|
||||
fullScreenButton.setLayoutParams(new LinearLayout.LayoutParams(143, 143));
|
||||
fullScreenButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
fullScreenButton.setBackgroundColor(Color.TRANSPARENT);
|
||||
|
||||
fullScreenButton.setOnClickListener(l -> {
|
||||
startFullScreenVideo();
|
||||
});
|
||||
|
||||
linearLayout.addView(fullScreenButton);
|
||||
linearLayout.invalidate();
|
||||
}
|
||||
|
||||
if (MimeTypeUtil.isAudio(file)) {
|
||||
binding.mediaController.setMediaPlayer(mediaPlayerServiceConnection);
|
||||
binding.mediaController.setVisibility(View.VISIBLE);
|
||||
|
@ -324,10 +343,6 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
|
|||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
menu.removeItem(R.id.action_search);
|
||||
OCFile file = getFile();
|
||||
if (file != null && MimeTypeUtil.isImageOrVideo(file)) {
|
||||
menu.add(Menu.NONE, MENU_FULLSCREEN_ID, 99, R.string.fullscreen);
|
||||
}
|
||||
inflater.inflate(R.menu.item_file, menu);
|
||||
}
|
||||
|
||||
|
@ -422,9 +437,6 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
|
|||
return true;
|
||||
} else if (itemId == R.id.action_stream_media) {
|
||||
containerActivity.getFileOperationsHelper().streamMediaFile(getFile());
|
||||
} else if (itemId == MENU_FULLSCREEN_ID) {
|
||||
startFullScreenVideo();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
exoPlayer = new SimpleExoPlayer.Builder(this).build();
|
||||
playerView.setPlayer(exoPlayer);
|
||||
|
||||
findViewById(R.id.exo_exit_fs).setOnClickListener(v -> finish());
|
||||
|
||||
if (mSavedPlaybackPosition >= 0) {
|
||||
exoPlayer.seekTo(mSavedPlaybackPosition);
|
||||
}
|
||||
|
|
107
src/main/res/layout/exo_player_control_view.xml
Normal file
107
src/main/res/layout/exo_player_control_view.xml
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layoutDirection="ltr"
|
||||
android:background="#CC000000"
|
||||
android:orientation="vertical"
|
||||
tools:targetApi="28">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingTop="4dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_prev"
|
||||
style="@style/ExoMediaButton.Previous" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_rew"
|
||||
style="@style/ExoMediaButton.Rewind" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_shuffle"
|
||||
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_pause"
|
||||
style="@style/ExoMediaButton.Pause" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_ffwd"
|
||||
style="@style/ExoMediaButton.FastForward" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_vr"
|
||||
style="@style/ExoMediaButton.VR" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/exo_exit_fs"
|
||||
style="@style/ExoMediaButton.ExitFullscreen" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@id/exo_position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:includeFontPadding="false"
|
||||
android:textColor="#FFBEBEBE" />
|
||||
|
||||
<View
|
||||
android:id="@id/exo_progress_placeholder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="26dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@id/exo_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:includeFontPadding="false"
|
||||
android:textColor="#FFBEBEBE" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -19,8 +19,10 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<com.google.android.exoplayer2.ui.StyledPlayerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/videoPlayer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/black" />
|
||||
android:background="@color/black"
|
||||
app:controller_layout_id="@layout/exo_player_control_view" />
|
||||
|
|
|
@ -428,4 +428,10 @@
|
|||
<item name="android:typeface">sans</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="ExoMediaButton.ExitFullscreen" parent="ExoStyledControls.Button.Center">
|
||||
<item name="android:src">@drawable/exo_styled_controls_fullscreen_exit</item>
|
||||
<item name="android:contentDescription">@string/exo_controls_fullscreen_exit_description</item>
|
||||
<item name="android:padding">@dimen/exo_icon_padding</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in a new issue