Video playback on TextureView and DepthPageTransformer.
This commit is contained in:
parent
0c0d7aeead
commit
a6890fc8dd
4 changed files with 56 additions and 26 deletions
|
@ -1,17 +0,0 @@
|
||||||
<?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"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<com.google.android.exoplayer2.ui.PlayerView
|
|
||||||
android:id="@+id/video_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:gravity="center"
|
|
||||||
app:player_layout_id="@layout/media_preview_exoplayer_layout"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
|
@ -1,13 +1,18 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout
|
||||||
android:orientation="vertical"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="match_parent">
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<VideoView android:id="@+id/video_view"
|
<com.google.android.exoplayer2.ui.PlayerView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/video_view"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"/>
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
app:surface_type="texture_view"
|
||||||
|
app:player_layout_id="@layout/media_preview_exoplayer_layout"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -47,6 +47,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.animation.DepthPageTransformer;
|
||||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||||
import org.thoughtcrime.securesms.components.viewpager.ExtendedOnPageChangedListener;
|
import org.thoughtcrime.securesms.components.viewpager.ExtendedOnPageChangedListener;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
|
@ -192,6 +193,7 @@ public final class MediaPreviewActivity extends PassphraseRequiredActionBarActiv
|
||||||
private void initializeViews() {
|
private void initializeViews() {
|
||||||
mediaPager = findViewById(R.id.media_pager);
|
mediaPager = findViewById(R.id.media_pager);
|
||||||
mediaPager.setOffscreenPageLimit(1);
|
mediaPager.setOffscreenPageLimit(1);
|
||||||
|
mediaPager.setPageTransformer(true, new DepthPageTransformer());
|
||||||
|
|
||||||
viewPagerListener = new ViewPagerListener();
|
viewPagerListener = new ViewPagerListener();
|
||||||
mediaPager.addOnPageChangeListener(viewPagerListener);
|
mediaPager.addOnPageChangeListener(viewPagerListener);
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.thoughtcrime.securesms.animation;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on https://developer.android.com/training/animation/screen-slide#depth-page
|
||||||
|
*/
|
||||||
|
public final class DepthPageTransformer implements ViewPager.PageTransformer {
|
||||||
|
private static final float MIN_SCALE = 0.75f;
|
||||||
|
|
||||||
|
public void transformPage(@NonNull View view, float position) {
|
||||||
|
final int pageWidth = view.getWidth();
|
||||||
|
|
||||||
|
if (position < -1f) {
|
||||||
|
view.setAlpha(0f);
|
||||||
|
|
||||||
|
} else if (position <= 0f) {
|
||||||
|
view.setAlpha(1f);
|
||||||
|
view.setTranslationX(0f);
|
||||||
|
view.setScaleX(1f);
|
||||||
|
view.setScaleY(1f);
|
||||||
|
|
||||||
|
} else if (position <= 1f) {
|
||||||
|
view.setAlpha(1f - position);
|
||||||
|
|
||||||
|
view.setTranslationX(pageWidth * -position);
|
||||||
|
|
||||||
|
final float scaleFactor = MIN_SCALE + (1f - MIN_SCALE) * (1f - Math.abs(position));
|
||||||
|
|
||||||
|
view.setScaleX(scaleFactor);
|
||||||
|
view.setScaleY(scaleFactor);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
view.setAlpha(0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue