[Android] Copy track title to clipboard by long click
AlexSviridov
git at videolan.org
Tue Mar 31 15:36:46 CEST 2020
vlc-android | branch: master | AlexSviridov <alexsviridov22 at gmail.com> | Tue Mar 31 15:36:45 2020 +0200| [ee17b6b8b307189bef4f0876e6315ecf39a64ab1] | committer: Nicolas Pomepuy
Copy track title to clipboard by long click
https://code.videolan.org/videolan/vlc-android/issues/1211
> https://code.videolan.org/videolan/vlc-android/commit/ee17b6b8b307189bef4f0876e6315ecf39a64ab1
---
application/resources/src/main/res/values/strings.xml | 1 +
.../src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 19 ++++++++++++++++---
.../org/videolan/vlc/gui/view/AudioMediaSwitcher.kt | 7 +++++++
.../src/org/videolan/vlc/gui/view/FlingViewGroup.kt | 16 +++++++++++++++-
4 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 5a22a6401..05a57c272 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -74,6 +74,7 @@
<item quantity="one">1 song</item>
<item quantity="other">%d songs</item>
</plurals>
+ <string name="track_info_copied_to_clipboard">Track info copied to clipboard</string>
<string name="artists">Artists</string>
<string name="albums">Albums</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 9d9fe8a3f..39e5711e8 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -21,9 +21,7 @@
package org.videolan.vlc.gui.audio
import android.Manifest
-import android.content.Context
-import android.content.Intent
-import android.content.SharedPreferences
+import android.content.*
import android.os.Bundle
import android.os.Handler
import android.support.v4.media.session.PlaybackStateCompat
@@ -582,6 +580,21 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
activity.slideUpOrDownAudioPlayer()
}
+ override fun onTouchLongClick() {
+ val trackInfo = playlistModel.title ?: return
+ val ctx = context ?: return
+
+ val data = ClipData.newPlainText(ctx.getString(R.string.app_name), trackInfo)
+ (ctx.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
+ .setPrimaryClip(data)
+
+ Snackbar.make(
+ binding.root,
+ R.string.track_info_copied_to_clipboard,
+ Snackbar.LENGTH_LONG
+ ).show()
+ }
+
override fun onTouchDown() {}
override fun onTouchUp() {}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
index 66c319919..96a195f3e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
@@ -68,6 +68,10 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
audioMediaSwitcherListener.onTouchClick()
}
+ override fun onTouchLongClick() {
+ audioMediaSwitcherListener.onTouchLongClick()
+ }
+
override fun onBackSwitched() {}
}
@@ -121,6 +125,8 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
fun onTouchClick()
+ fun onTouchLongClick()
+
companion object {
const val PREVIOUS_MEDIA = 1
const val CURRENT_MEDIA = 2
@@ -134,5 +140,6 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
override fun onTouchDown() {}
override fun onTouchUp() {}
override fun onTouchClick() {}
+ override fun onTouchLongClick() = Unit
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.kt
index 45de581a8..f48b8af68 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.kt
@@ -45,6 +45,8 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
abstract val viewSwitchListener: ViewSwitchListener
+ private var lastActionDownMillis = 0L
+
init {
layoutParams = LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)
@@ -139,6 +141,7 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
MotionEvent.ACTION_DOWN -> {
if (!scroller.isFinished) scroller.abortAnimation()
lastX = x
+ lastActionDownMillis = event.eventTime
viewSwitchListener.onTouchDown()
}
MotionEvent.ACTION_MOVE -> {
@@ -174,7 +177,16 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
this.velocityTracker = null
viewSwitchListener.onTouchUp()
- if (dx * dx + dy * dy < touchSlop * touchSlop) viewSwitchListener.onTouchClick()
+ if (dx * dx + dy * dy < touchSlop * touchSlop) {
+ val isLongClick = lastActionDownMillis.let {
+ lastActionDownMillis = 0L
+ it > 0L && event.eventTime - it > ViewConfiguration.getLongPressTimeout()
+ }
+ if (isLongClick)
+ viewSwitchListener.onTouchLongClick()
+ else
+ viewSwitchListener.onTouchClick()
+ }
}
}
return true
@@ -234,6 +246,8 @@ interface ViewSwitchListener {
fun onTouchClick()
+ fun onTouchLongClick()
+
fun onBackSwitched()
}
More information about the Android
mailing list