1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-01-31 02:54:57 +01:00

メディアビューアにミュート機能

This commit is contained in:
tateisu 2019-11-16 10:58:09 +09:00
parent 73360e2269
commit a7bada0dee
2 changed files with 57 additions and 33 deletions

View File

@ -15,6 +15,7 @@ import android.os.Environment
import android.os.SystemClock import android.os.SystemClock
import android.view.View import android.view.View
import android.view.Window import android.view.Window
import android.widget.CheckBox
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
@ -66,6 +67,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
internal const val STATE_PLAYER_POS = "playerPos" internal const val STATE_PLAYER_POS = "playerPos"
internal const val STATE_PLAYER_PLAY_WHEN_READY = "playerPlayWhenReady" internal const val STATE_PLAYER_PLAY_WHEN_READY = "playerPlayWhenReady"
internal const val STATE_LAST_VOLUME = "lastVolume"
internal fun <T : TootAttachmentLike> encodeMediaList(list : ArrayList<T>?) = internal fun <T : TootAttachmentLike> encodeMediaList(list : ArrayList<T>?) =
list?.encodeJson()?.toString() ?: "[]" list?.encodeJson()?.toString() ?: "[]"
@ -106,6 +108,9 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
private lateinit var svDescription : View private lateinit var svDescription : View
private lateinit var tvDescription : TextView private lateinit var tvDescription : TextView
private lateinit var tvStatus : TextView private lateinit var tvStatus : TextView
private lateinit var cbMute: CheckBox
private var lastVolume = Float.NaN
internal var buffering_last_shown : Long = 0 internal var buffering_last_shown : Long = 0
@ -183,6 +188,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
outState.putLong(STATE_PLAYER_POS, exoPlayer.currentPosition) outState.putLong(STATE_PLAYER_POS, exoPlayer.currentPosition)
outState.putBoolean(STATE_PLAYER_PLAY_WHEN_READY, exoPlayer.playWhenReady) outState.putBoolean(STATE_PLAYER_PLAY_WHEN_READY, exoPlayer.playWhenReady)
outState.putFloat(STATE_LAST_VOLUME,lastVolume)
} }
override fun onCreate(savedInstanceState : Bundle?) { override fun onCreate(savedInstanceState : Bundle?) {
@ -234,6 +240,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
svDescription = findViewById(R.id.svDescription) svDescription = findViewById(R.id.svDescription)
tvDescription = findViewById(R.id.tvDescription) tvDescription = findViewById(R.id.tvDescription)
tvStatus = findViewById(R.id.tvStatus) tvStatus = findViewById(R.id.tvStatus)
cbMute = findViewById(R.id.cbMute)
val enablePaging = media_list.size > 1 val enablePaging = media_list.size > 1
btnPrevious.isEnabled = enablePaging btnPrevious.isEnabled = enablePaging
@ -246,6 +253,22 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
findViewById<View>(R.id.btnDownload).setOnClickListener(this) findViewById<View>(R.id.btnDownload).setOnClickListener(this)
findViewById<View>(R.id.btnMore).setOnClickListener(this) findViewById<View>(R.id.btnMore).setOnClickListener(this)
cbMute.setOnCheckedChangeListener{_,isChecked->
if(isChecked) {
// mute
lastVolume = exoPlayer.volume
exoPlayer.volume = 0f
}else{
// unmute
exoPlayer.volume = when{
lastVolume.isNaN() -> 1f
lastVolume <= 0f -> 1f
else -> lastVolume
}
lastVolume = Float.NaN
}
}
pbvImage.setCallback(object : PinchBitmapView.Callback { pbvImage.setCallback(object : PinchBitmapView.Callback {
override fun onSwipe(deltaX : Int, deltaY : Int) { override fun onSwipe(deltaX : Int, deltaY : Int) {
if(isDestroyed) return if(isDestroyed) return
@ -338,6 +361,11 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private fun loadVideo(ta : TootAttachment, state : Bundle? = null) { private fun loadVideo(ta : TootAttachment, state : Bundle? = null) {
vg(cbMute,true)
if(cbMute.isChecked && lastVolume.isFinite() ) {
exoPlayer.volume = 0f
}
val url = ta.getLargeUrl(App1.pref) val url = ta.getLargeUrl(App1.pref)
if(url == null) { if(url == null) {
showError("missing media attachment url.") showError("missing media attachment url.")
@ -372,6 +400,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
} else { } else {
exoPlayer.playWhenReady = state.getBoolean(STATE_PLAYER_PLAY_WHEN_READY, true) exoPlayer.playWhenReady = state.getBoolean(STATE_PLAYER_PLAY_WHEN_READY, true)
exoPlayer.seekTo(max(0L, state.getLong(STATE_PLAYER_POS, 0L))) exoPlayer.seekTo(max(0L, state.getLong(STATE_PLAYER_POS, 0L)))
lastVolume = state.getFloat(STATE_LAST_VOLUME,1f)
} }
} }
@ -457,6 +486,9 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private fun loadBitmap(ta : TootAttachment) { private fun loadBitmap(ta : TootAttachment) {
vg(cbMute,false)
val urlList = ta.getLargeUrlList(App1.pref) val urlList = ta.getLargeUrlList(App1.pref)
if(urlList.isEmpty()) { if(urlList.isEmpty()) {
showError("missing media attachment url.") showError("missing media attachment url.")

View File

@ -1,62 +1,53 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical">
>
<ScrollView <ScrollView
android:id="@+id/svDescription" android:id="@+id/svDescription"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="64dp" android:layout_height="64dp"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingBottom="6dp"
android:paddingEnd="12dp"
android:paddingStart="12dp" android:paddingStart="12dp"
android:paddingTop="6dp" android:paddingTop="6dp"
> android:paddingEnd="12dp"
android:paddingBottom="6dp">
<TextView <TextView
android:id="@+id/tvDescription" android:id="@+id/tvDescription"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
/>
</ScrollView> </ScrollView>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1">
>
<jp.juggler.subwaytooter.view.PinchBitmapView <jp.juggler.subwaytooter.view.PinchBitmapView
android:id="@+id/pbvImage" android:id="@+id/pbvImage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/media_background" android:background="@drawable/media_background" />
/>
<com.google.android.exoplayer2.ui.SimpleExoPlayerView <com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/exoView" android:id="@+id/exoView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
/>
<TextView <TextView
android:id="@+id/tvError" android:id="@+id/tvError"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:padding="12dp" android:padding="12dp" />
/>
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
>
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
@ -65,8 +56,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:alignItems="center" app:alignItems="center"
app:flexWrap="wrap" app:flexWrap="wrap"
app:justifyContent="center" app:justifyContent="center">
>
<ImageButton <ImageButton
android:id="@+id/btnPrevious" android:id="@+id/btnPrevious"
@ -75,8 +65,7 @@
android:contentDescription="@string/previous" android:contentDescription="@string/previous"
android:minWidth="48dp" android:minWidth="48dp"
android:src="@drawable/ic_left" android:src="@drawable/ic_left"
android:tint="?attr/colorVectorDrawable" android:tint="?attr/colorVectorDrawable" />
/>
<ImageButton <ImageButton
android:id="@+id/btnNext" android:id="@+id/btnNext"
@ -85,8 +74,7 @@
android:contentDescription="@string/next" android:contentDescription="@string/next"
android:minWidth="48dp" android:minWidth="48dp"
android:src="@drawable/ic_right" android:src="@drawable/ic_right"
android:tint="?attr/colorVectorDrawable" android:tint="?attr/colorVectorDrawable" />
/>
<ImageButton <ImageButton
android:id="@+id/btnDownload" android:id="@+id/btnDownload"
@ -95,8 +83,7 @@
android:contentDescription="@string/download" android:contentDescription="@string/download"
android:minWidth="48dp" android:minWidth="48dp"
android:src="@drawable/ic_download" android:src="@drawable/ic_download"
android:tint="?attr/colorVectorDrawable" android:tint="?attr/colorVectorDrawable" />
/>
<ImageButton <ImageButton
android:id="@+id/btnMore" android:id="@+id/btnMore"
@ -105,7 +92,13 @@
android:contentDescription="@string/more" android:contentDescription="@string/more"
android:minWidth="48dp" android:minWidth="48dp"
android:src="@drawable/ic_more" android:src="@drawable/ic_more"
android:tint="?attr/colorVectorDrawable" android:tint="?attr/colorVectorDrawable" />
<CheckBox
android:id="@+id/cbMute"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="@string/mute"
/> />
</com.google.android.flexbox.FlexboxLayout> </com.google.android.flexbox.FlexboxLayout>
@ -115,13 +108,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|bottom" android:layout_gravity="start|bottom"
android:layout_marginBottom="6dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:gravity="start|bottom" android:layout_marginEnd="12dp"
android:textSize="12sp" android:layout_marginBottom="6dp"
android:alpha="0.5" android:alpha="0.5"
android:gravity="start|bottom"
android:textColor="#ffffff" android:textColor="#ffffff"
/> android:textSize="12sp" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>