From f7b547b9c792407ccec950871f8f8a4ef3d938ca Mon Sep 17 00:00:00 2001 From: vkay94 Date: Mon, 18 Nov 2019 17:42:02 +0100 Subject: [PATCH 01/11] Huge additions * Added new YT-Overlay option which is more like official YouTube app * Updated Demo app for customization tests and comparision between both options --- app/build.gradle | 21 +- app/proguard-rules.pro | 29 +- app/src/main/AndroidManifest.xml | 18 +- .../{MainActivity.kt => BaseVideoActivity.kt} | 111 ++---- .../DataAndUtils.kt | 20 + .../VideoActivityCircle.kt | 94 +++++ .../VideoActivityRipple.kt | 54 +++ .../dialogs/ConfigDialogColors.kt | 87 +++++ .../dialogs/ConfigDialogVarious.kt | 183 ++++++++++ app/src/main/res/anim/in_from_right.xml | 5 + app/src/main/res/anim/out_to_right.xml | 5 + .../main/res/layout/activity_video_circle.xml | 35 ++ ...ity_main.xml => activity_video_ripple.xml} | 19 +- app/src/main/res/layout/dialog_colors.xml | 90 +++++ app/src/main/res/layout/dialog_various.xml | 124 +++++++ .../exo_playback_control_view_circle.xml | 126 +++++++ ...l => exo_playback_control_view_ripple.xml} | 34 +- app/src/main/res/values/configdialog.xml | 30 ++ app/src/main/res/values/styles.xml | 2 +- build.gradle | 7 +- doubletapplayerview/build.gradle | 21 +- .../vkay94/dtpv/DoubleTapPlayerView.java | 10 +- .../vkay94/dtpv/PlayerDoubleTapListener.java | 6 +- .../dtpv/{ => youtube}/YouTubeDoubleTap.kt | 11 +- .../vkay94/dtpv/youtube/YouTubeOverlay.kt | 343 ++++++++++++++++++ .../dtpv/youtube/views/CircleClipTapView.kt | 213 +++++++++++ .../src/main/res/layout/yt_overlay_circle.xml | 68 ++++ .../src/main/res/values/yt_overlay_circle.xml | 17 + 28 files changed, 1619 insertions(+), 164 deletions(-) rename app/src/main/java/com/github/vkay94/doubletapplayerviewexample/{MainActivity.kt => BaseVideoActivity.kt} (55%) create mode 100644 app/src/main/java/com/github/vkay94/doubletapplayerviewexample/DataAndUtils.kt create mode 100644 app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityCircle.kt create mode 100644 app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityRipple.kt create mode 100644 app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogColors.kt create mode 100644 app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogVarious.kt create mode 100644 app/src/main/res/anim/in_from_right.xml create mode 100644 app/src/main/res/anim/out_to_right.xml create mode 100644 app/src/main/res/layout/activity_video_circle.xml rename app/src/main/res/layout/{activity_main.xml => activity_video_ripple.xml} (56%) create mode 100644 app/src/main/res/layout/dialog_colors.xml create mode 100644 app/src/main/res/layout/dialog_various.xml create mode 100644 app/src/main/res/layout/exo_playback_control_view_circle.xml rename app/src/main/res/layout/{exo_playback_control_view.xml => exo_playback_control_view_ripple.xml} (87%) create mode 100644 app/src/main/res/values/configdialog.xml rename doubletapplayerview/src/main/java/com/github/vkay94/dtpv/{ => youtube}/YouTubeDoubleTap.kt (96%) create mode 100644 doubletapplayerview/src/main/java/com/github/vkay94/dtpv/youtube/YouTubeOverlay.kt create mode 100644 doubletapplayerview/src/main/java/com/github/vkay94/dtpv/youtube/views/CircleClipTapView.kt create mode 100644 doubletapplayerview/src/main/res/layout/yt_overlay_circle.xml create mode 100644 doubletapplayerview/src/main/res/values/yt_overlay_circle.xml diff --git a/app/build.gradle b/app/build.gradle index 00c816f..324e876 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,18 +6,19 @@ apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 - buildToolsVersion "29.0.2" + buildToolsVersion '29.0.2' defaultConfig { applicationId "com.github.vkay94.doubletapplayerviewexample" - minSdkVersion 16 + minSdkVersion 21 targetSdkVersion 29 - versionCode 60 - versionName "0.6.0" + versionCode 70 + versionName "0.7.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled true + shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } @@ -30,16 +31,18 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "androidx.appcompat:appcompat:$appcompat_version" implementation 'androidx.core:core-ktx:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - implementation "com.google.android.exoplayer:exoplayer-core:2.10.6" - implementation "com.google.android.exoplayer:exoplayer-ui:2.10.6" implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' + // ExoPlayer2 + implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version" + implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version" + + implementation 'com.github.QuadFlask:colorpicker:0.0.15' implementation project(path: ':doubletapplayerview') } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f1b4245..831db07 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +1,8 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile +-assumenosideeffects class android.util.Log { + public static boolean isLoggable(java.lang.String, int); + public static int v(...); + public static int i(...); + public static int w(...); + public static int d(...); + public static int e(...); +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f0ed6b6..6610253 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,16 +6,24 @@ - + tools:ignore="AllowBackup,GoogleAppIndexingWarning"> + + + + + + + + diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/MainActivity.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/BaseVideoActivity.kt similarity index 55% rename from app/src/main/java/com/github/vkay94/doubletapplayerviewexample/MainActivity.kt rename to app/src/main/java/com/github/vkay94/doubletapplayerviewexample/BaseVideoActivity.kt index cc5bd20..64b9da0 100644 --- a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/MainActivity.kt +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/BaseVideoActivity.kt @@ -1,13 +1,13 @@ package com.github.vkay94.doubletapplayerviewexample +import android.annotation.SuppressLint +import android.content.Context +import android.content.Intent import android.net.Uri import android.os.Bundle -import android.util.Log import android.view.WindowManager -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import com.github.vkay94.dtpv.PlayerDoubleTapListener -import com.github.vkay94.dtpv.SeekListener +import com.github.vkay94.dtpv.DoubleTapPlayerView import com.google.android.exoplayer2.* import com.google.android.exoplayer2.source.ExtractorMediaSource import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection @@ -17,13 +17,14 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory import com.google.android.exoplayer2.util.Util -import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.android.synthetic.main.exo_playback_control_view.* +import kotlinx.android.synthetic.main.activity_video_circle.* -class MainActivity : AppCompatActivity(), PlayerDoubleTapListener { - private val TAG = ".MainActivity" - private var player: SimpleExoPlayer? = null +@SuppressLint("Registered") +open class BaseVideoActivity : AppCompatActivity() { + + var videoPlayer: DoubleTapPlayerView? = null + var player: SimpleExoPlayer? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -31,53 +32,24 @@ class MainActivity : AppCompatActivity(), PlayerDoubleTapListener { WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN ) - setContentView(R.layout.activity_main) supportActionBar?.hide() - - initializePlayer() - - // Add DoubleTap behavior - initializeDoubleTapPlayerView() } - private fun initializeDoubleTapPlayerView() { - youtubeDoubleTap - .setPlayer(playerView) - .setForwardRewindIncrementMs(10000) - .setSeekListener(object : SeekListener { - override fun onVideoStartReached() { - pausePlayer() - Toast.makeText(this@MainActivity, - "Video start reached", Toast.LENGTH_SHORT).show() - } - - override fun onVideoEndReached() { - Toast.makeText(this@MainActivity, - "Video end reached", Toast.LENGTH_SHORT).show() - } - }) - - playerView.activateDoubleTap(true) - .setDoubleTapListener(youtubeDoubleTap) -// .setDoubleTapListener(this) - .setDoubleTapDelay(500) - - btn_ffwd.setOnClickListener { - youtubeDoubleTap.forward() - } - - btn_rew.setOnClickListener { - youtubeDoubleTap.rewind() - } - - // Start video - // Found at: https://gist.github.com/jsturgis/3b19447b304616f18657 + fun buildMediaSource(mUri: Uri) { + val bandwidthMeter = DefaultBandwidthMeter() + val dataSourceFactory = DefaultDataSourceFactory( + this@BaseVideoActivity, + Util.getUserAgent(this@BaseVideoActivity, resources.getString(R.string.app_name)), + bandwidthMeter + ) + val videoSource = ExtractorMediaSource.Factory(dataSourceFactory) + .createMediaSource(mUri) - val videoUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" - buildMediaSource(Uri.parse(videoUrl)) + player?.prepare(videoSource) + player?.playWhenReady = true } - private fun initializePlayer() { + fun initializePlayer() { if (player == null) { val loadControl: LoadControl = DefaultLoadControl.Builder() .setBufferDurationsMs( @@ -105,36 +77,22 @@ class MainActivity : AppCompatActivity(), PlayerDoubleTapListener { } } - private fun buildMediaSource(mUri: Uri) { - val bandwidthMeter = DefaultBandwidthMeter() - val dataSourceFactory = DefaultDataSourceFactory( - this@MainActivity, - Util.getUserAgent(this@MainActivity, resources.getString(R.string.app_name)), - bandwidthMeter - ) - val videoSource = ExtractorMediaSource.Factory(dataSourceFactory) - .createMediaSource(mUri) - - player?.prepare(videoSource) - player?.playWhenReady = true - } - // Player Lifecycle - private fun releasePlayer() { + fun releasePlayer() { if (player != null) { player?.release() player = null } } - private fun pausePlayer() { + fun pausePlayer() { if (player != null) { player?.playWhenReady = false player?.playbackState } } - private fun resumePlayer() { + fun resumePlayer() { if (player != null) { player?.playWhenReady = true player?.playbackState @@ -161,21 +119,8 @@ class MainActivity : AppCompatActivity(), PlayerDoubleTapListener { } } - // For debugging purposes - - override fun onDoubleTapStarted(posX: Float, posY: Float) { - Log.d(TAG, "onDoubleTapStarted") - } - - override fun onDoubleTapProgressDown(posX: Float, posY: Float) { - Log.d(TAG, "onDoubleTapProgressDown") - } - - override fun onDoubleTapProgressUp(posX: Float, posY: Float) { - Log.d(TAG, "onDoubleTapProgressUp") - } - - override fun onDoubleTapFinished() { - Log.d(TAG, "onDoubleTapFinished") + companion object { + fun newIntent(context: Context, activity: Class): Intent = + Intent(context, activity) } } diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/DataAndUtils.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/DataAndUtils.kt new file mode 100644 index 0000000..15560aa --- /dev/null +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/DataAndUtils.kt @@ -0,0 +1,20 @@ +package com.github.vkay94.doubletapplayerviewexample + +import android.content.Context + +object DataAndUtils { + + /** + * This is a selected list of sample videos for demonstration + * Found at: https://gist.github.com/jsturgis/3b19447b304616f18657 + */ + val videoList = listOf( + "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" + ) + + fun dpToPx(context: Context, dp: Float) = + dp * context.resources.displayMetrics.density + + fun pxToDp(context: Context, px: Float) = + px / context.resources.displayMetrics.density +} \ No newline at end of file diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityCircle.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityCircle.kt new file mode 100644 index 0000000..b45d851 --- /dev/null +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityCircle.kt @@ -0,0 +1,94 @@ +package com.github.vkay94.doubletapplayerviewexample + +import android.net.Uri +import android.os.Bundle +import android.widget.Toast +import com.github.vkay94.doubletapplayerviewexample.dialogs.ConfigDialogColors +import com.github.vkay94.doubletapplayerviewexample.dialogs.ConfigDialogVarious +import com.github.vkay94.dtpv.SeekListener +import kotlinx.android.synthetic.main.activity_video_circle.* +import kotlinx.android.synthetic.main.exo_playback_control_view_circle.* + + +class VideoActivityCircle : BaseVideoActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_video_circle) + + this.videoPlayer = playerView + initializePlayer() + + // Add DoubleTap behavior + initializeDoubleTapPlayerView() + initializeConfigButtons() + + btn_switch_mode.setOnClickListener { + startActivity(newIntent(this@VideoActivityCircle, VideoActivityRipple::class.java)) + finish() + } + } + + private fun initializeDoubleTapPlayerView() { + youtubeDoubleTap + .setSeekListener(object : SeekListener { + override fun onVideoStartReached() { + pausePlayer() + Toast.makeText(this@VideoActivityCircle, + "Video start reached", Toast.LENGTH_SHORT + ).show() + } + + override fun onVideoEndReached() { + Toast.makeText(this@VideoActivityCircle, + "Video end reached", Toast.LENGTH_SHORT + ).show() + } + }) + + playerView.activateDoubleTap(true) + .setDoubleTapDelay(650) + .setDoubleTapListener(youtubeDoubleTap) + + val videoUrl = DataAndUtils.videoList.first() + buildMediaSource(Uri.parse(videoUrl)) + } + + private fun initializeConfigButtons() { + btn_colors.setOnClickListener { + ConfigDialogColors.newInstance(object : ConfigDialogColors.ColorChangedListener { + override fun onTapColorChanged(newColor: Int) { + youtubeDoubleTap.tapCircleColor = newColor + } + + override fun onBackgroundColorChanged(newColor: Int) { + youtubeDoubleTap.circleBackgroundColor = newColor + } + + }, youtubeDoubleTap.tapCircleColor, youtubeDoubleTap.circleBackgroundColor) + .show(supportFragmentManager, "COLORS DIALOG") + } + + btn_various.setOnClickListener { + val arcSizeInDp = DataAndUtils.pxToDp(this, youtubeDoubleTap.arcSize) + + ConfigDialogVarious.newInstance(object : ConfigDialogVarious.VariousChangedListener { + override fun onDoubleTapDurationChanged(newDuration: Long) { + playerView.setDoubleTapDelay(newDuration.toInt()) + } + + override fun onYoutubeAnimationDurationChanged(newDuration: Long) { + youtubeDoubleTap.animationDuration = newDuration + } + + override fun onArcSizeChanged(newDimen: Int) { + youtubeDoubleTap.arcSize = + DataAndUtils.dpToPx(this@VideoActivityCircle, newDimen.toFloat()) + } + + }, playerView.doubleTapDelay.toInt(), youtubeDoubleTap.animationDuration.toInt(), + arcSizeInDp.toInt()) + .show(supportFragmentManager, "VARIOUS DIALOG") + } + } +} diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityRipple.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityRipple.kt new file mode 100644 index 0000000..6da4f34 --- /dev/null +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/VideoActivityRipple.kt @@ -0,0 +1,54 @@ +package com.github.vkay94.doubletapplayerviewexample + +import android.net.Uri +import android.os.Bundle +import android.widget.Toast +import com.github.vkay94.dtpv.SeekListener +import kotlinx.android.synthetic.main.activity_video_ripple.* +import kotlinx.android.synthetic.main.exo_playback_control_view_ripple.* + +class VideoActivityRipple : BaseVideoActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_video_ripple) + + this.videoPlayer = playerView + initializePlayer() + + // Add DoubleTap behavior + initializeDoubleTapPlayerView() + + btn_switch_mode.setOnClickListener { + startActivity(newIntent(this@VideoActivityRipple, VideoActivityCircle::class.java)) + finish() + } + } + + private fun initializeDoubleTapPlayerView() { + youtubeDoubleTap + .setPlayer(playerView) + .setForwardRewindIncrementMs(10000) + .setSeekListener(object : SeekListener { + override fun onVideoStartReached() { + pausePlayer() + Toast.makeText(this@VideoActivityRipple, + "Video start reached", Toast.LENGTH_SHORT + ).show() + } + + override fun onVideoEndReached() { + Toast.makeText(this@VideoActivityRipple, + "Video end reached", Toast.LENGTH_SHORT + ).show() + } + }) + + playerView.activateDoubleTap(true) + .setDoubleTapDelay(700) + .setDoubleTapListener(youtubeDoubleTap) + + val videoUrl = DataAndUtils.videoList.first() + buildMediaSource(Uri.parse(videoUrl)) + } +} diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogColors.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogColors.kt new file mode 100644 index 0000000..87bb78f --- /dev/null +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogColors.kt @@ -0,0 +1,87 @@ +package com.github.vkay94.doubletapplayerviewexample.dialogs + +import android.os.Bundle +import android.view.* +import androidx.fragment.app.DialogFragment +import com.github.vkay94.doubletapplayerviewexample.R +import kotlinx.android.synthetic.main.dialog_colors.* + +class ConfigDialogColors : DialogFragment() { + + lateinit var listener: ColorChangedListener + var tapColor: Int = -1 + var backgroundColor: Int = -1 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(STYLE_NORMAL, + R.style.FullScreenPlayerSettingsDialogStyle + ) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_colors, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + activity?.let { + // Tap circle color + v_tap_alpha_slider.setColor(tapColor) + + tap_color_picker_view.setInitialColor(tapColor, false) + tap_color_picker_view.addOnColorChangedListener {selectedColor -> + listener.onTapColorChanged(selectedColor) + } + + // Background circle color + v_background_alpha_slider.setColor(backgroundColor) + + background_color_picker_view.setInitialColor(backgroundColor, false) + background_color_picker_view.addOnColorChangedListener {selectedColor -> + listener.onBackgroundColorChanged(selectedColor) + } + } + } + + override fun onStart() { + super.onStart() + + val dialog = dialog + if (dialog != null) { + + dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.setDimAmount(0.50f) + + val metrics = context!!.resources.displayMetrics + val widthRatio = + resources.getInteger(R.integer.playersettings_dialog_width_ratio).toDouble() / 100 + val width = (metrics.widthPixels * widthRatio).toInt() + + // W, H + dialog.window?.setLayout(width, ViewGroup.LayoutParams.MATCH_PARENT) + dialog.window?.setGravity(Gravity.END) + } + } + + interface ColorChangedListener { + fun onTapColorChanged(newColor: Int) + fun onBackgroundColorChanged(newColor: Int) + } + + companion object { + + val TAG = ConfigDialogColors::class.java.simpleName + + fun newInstance(listener: ColorChangedListener, tapColor: Int, backgroundColor: Int): ConfigDialogColors { + return ConfigDialogColors().apply { + this.listener = listener + this.tapColor = tapColor + this.backgroundColor = backgroundColor + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogVarious.kt b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogVarious.kt new file mode 100644 index 0000000..aaa9dfd --- /dev/null +++ b/app/src/main/java/com/github/vkay94/doubletapplayerviewexample/dialogs/ConfigDialogVarious.kt @@ -0,0 +1,183 @@ +package com.github.vkay94.doubletapplayerviewexample.dialogs + +import android.os.Bundle +import android.view.* +import android.widget.SeekBar +import android.widget.TextView +import androidx.appcompat.widget.AppCompatSeekBar +import androidx.fragment.app.DialogFragment +import com.github.vkay94.doubletapplayerviewexample.R +import kotlinx.android.synthetic.main.dialog_various.* + +class ConfigDialogVarious : DialogFragment() { + + lateinit var listener: VariousChangedListener + val minDoubleTapDuration = 500 + val minAnimationDuration = 500 + val minArcSize = 0 + + val maxDoubleTapDuration = 2000 + val maxAnimationDuration = 2500 + val maxArcSize = 200 + + val durationSteps = 25 + val arcSteps = 5 + + var currentDoubleTapDuration: Int = 500 + var currentYouTubeAnimationDuration: Int = 650 + var currentArcSize = 50 + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(STYLE_NORMAL, + R.style.FullScreenPlayerSettingsDialogStyle + ) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_various, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + activity?.let { + initializeDurationSeekBar( + seekbar_double_tap_duration, + tv_double_tap_duration, + maxDoubleTapDuration, + minDoubleTapDuration, + currentDoubleTapDuration + ) { + listener.onDoubleTapDurationChanged(it.toLong()) + } + + initializeDurationSeekBar( + seekbar_youtube_animation_duration, + tv_youtube_animation_duration, + maxAnimationDuration, + minAnimationDuration, + currentYouTubeAnimationDuration + ) { + listener.onYoutubeAnimationDurationChanged(it.toLong()) + } + + initializeDimensSeekBar( + seekbar_arc_size, + tv_arc_size, + maxArcSize, + minArcSize, + currentArcSize + ) { + listener.onArcSizeChanged(it) + } + } + } + + private fun initializeDurationSeekBar(seekBar: AppCompatSeekBar? = null, textView: TextView? = null, + maxValue: Int = 0, minValue: Int = 0, currentValue: Int = 0, + progressChanged: (progress: Int) -> Unit) { + + val textInitial = "$currentValue ms" + textView?.text = textInitial + + seekBar?.apply { + max = (maxValue - minValue) / durationSteps + progress = (currentValue - minValue) / durationSteps + setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + val value = minValue + (progress * durationSteps) + val text = "$value ms" + textView?.text = text + + progressChanged(value) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + // Do nothing + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + // Do nothing + } + + }) + } + } + + private fun initializeDimensSeekBar(seekBar: AppCompatSeekBar? = null, textView: TextView? = null, + maxValue: Int = 0, minValue: Int = 0, currentValue: Int = 0, + progressChanged: (progress: Int) -> Unit) { + + val textInitial = "$currentValue dp" + textView?.text = textInitial + + seekBar?.apply { + max = (maxValue - minValue) / arcSteps + progress = (currentValue - minValue) / arcSteps + setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + val value = minValue + (progress * arcSteps) + val text = "$value dp" + textView?.text = text + + progressChanged(value) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + // Do nothing + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + // Do nothing + } + + }) + } + } + + override fun onStart() { + super.onStart() + + val dialog = dialog + if (dialog != null) { + + dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.setDimAmount(0.50f) + + val metrics = context!!.resources.displayMetrics + val widthRatio = + resources.getInteger(R.integer.playersettings_dialog_width_ratio).toDouble() / 100 + val width = (metrics.widthPixels * widthRatio).toInt() + + // W, H + dialog.window?.setLayout(width, ViewGroup.LayoutParams.MATCH_PARENT) + dialog.window?.setGravity(Gravity.END) + } + } + + interface VariousChangedListener { + fun onDoubleTapDurationChanged(newDuration: Long) + fun onYoutubeAnimationDurationChanged(newDuration: Long) + fun onArcSizeChanged(newDimen: Int) + } + + companion object { + + val TAG = ConfigDialogVarious::class.java.simpleName + + fun newInstance(listener: VariousChangedListener, + dtDuration: Int, ytDuration: Int, arcSize: Int + ): ConfigDialogVarious { + return ConfigDialogVarious().apply { + this.listener = listener + this.currentDoubleTapDuration = dtDuration + this.currentYouTubeAnimationDuration = ytDuration + this.currentArcSize = arcSize + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/in_from_right.xml b/app/src/main/res/anim/in_from_right.xml new file mode 100644 index 0000000..3df112c --- /dev/null +++ b/app/src/main/res/anim/in_from_right.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/anim/out_to_right.xml b/app/src/main/res/anim/out_to_right.xml new file mode 100644 index 0000000..90fb416 --- /dev/null +++ b/app/src/main/res/anim/out_to_right.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_video_circle.xml b/app/src/main/res/layout/activity_video_circle.xml new file mode 100644 index 0000000..76f1192 --- /dev/null +++ b/app/src/main/res/layout/activity_video_circle.xml @@ -0,0 +1,35 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_video_ripple.xml similarity index 56% rename from app/src/main/res/layout/activity_main.xml rename to app/src/main/res/layout/activity_video_ripple.xml index 6f56c7d..f412acd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_video_ripple.xml @@ -1,6 +1,7 @@ @@ -14,12 +15,20 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:use_controller="true" /> + app:use_controller="true" + app:controller_layout_id="@layout/exo_playback_control_view_ripple" + tools:visibility="visible" /> - + android:layout_width="0dp" + android:layout_height="0dp" + android:background="@color/dtp_overlay_dim" + android:visibility="gone" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:visibility="visible" /> \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_colors.xml b/app/src/main/res/layout/dialog_colors.xml new file mode 100644 index 0000000..8c2e9e4 --- /dev/null +++ b/app/src/main/res/layout/dialog_colors.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_various.xml b/app/src/main/res/layout/dialog_various.xml new file mode 100644 index 0000000..980a9dc --- /dev/null +++ b/app/src/main/res/layout/dialog_various.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/exo_playback_control_view_circle.xml b/app/src/main/res/layout/exo_playback_control_view_circle.xml new file mode 100644 index 0000000..3da44c1 --- /dev/null +++ b/app/src/main/res/layout/exo_playback_control_view_circle.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + +