diff --git a/README.md b/README.md index 839e5dc..657b59e 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,8 @@ To do this, you can add the attributes to your layout xml: ``` - +## Compose support +None planned. PRs welcome! ## License diff --git a/app/build.gradle b/app/build.gradle index 4b1b752..d68a27d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,34 +2,33 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' - defaultConfig { - applicationId "com.teresaholfeld.stories.app" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + compileSdkVersion 30 + defaultConfig { + applicationId "com.teresaholfeld.stories.app" + minSdkVersion 15 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } } - } } dependencies { - implementation 'com.github.teresaholfeld:Stories:1.1.2' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.13' + androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation project(':library') } repositories { - mavenCentral() + mavenCentral() } diff --git a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt index 7172626..4a78550 100644 --- a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt +++ b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt @@ -1,76 +1,55 @@ package com.teresaholfeld.stories.app import android.os.Bundle -import android.support.v7.app.AppCompatActivity -import android.view.MotionEvent import android.view.View import android.view.WindowManager import android.widget.ImageView +import androidx.appcompat.app.AppCompatActivity import com.teresaholfeld.stories.StoriesProgressView class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { - private var storiesProgressView: StoriesProgressView? = null + private lateinit var storiesProgressView: StoriesProgressView private var image: ImageView? = null private var counter = 0 private val resources = intArrayOf( - R.drawable.sample1, - R.drawable.sample2, - R.drawable.sample3, - R.drawable.sample4, - R.drawable.sample5, - R.drawable.sample6 + R.drawable.sample1, + R.drawable.sample2, + R.drawable.sample3, + R.drawable.sample4, + R.drawable.sample5, + R.drawable.sample6 ) - private val durations = longArrayOf(500L, 1000L, 1500L, 4000L, 5000L, 1000) - - private var pressTime = 0L - private var limit = 500L - - private val onTouchListener = View.OnTouchListener { v, event -> - when (event.action) { - MotionEvent.ACTION_DOWN -> { - pressTime = System.currentTimeMillis() - storiesProgressView?.pause() - return@OnTouchListener false - } - MotionEvent.ACTION_UP -> { - val now = System.currentTimeMillis() - storiesProgressView?.resume() - return@OnTouchListener limit < now - pressTime - } - } - false - } +// private val durations = longArrayOf(500L, 1000L, 1500L, 4000L, 5000L, 1000) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) setContentView(R.layout.activity_main) - storiesProgressView?.setStoriesCount(PROGRESS_COUNT) - storiesProgressView?.setStoryDuration(3000L) + storiesProgressView = findViewById(R.id.stories) + storiesProgressView.setStoriesCount(PROGRESS_COUNT) + storiesProgressView.setStoryDuration(3000L) // or // storiesProgressView.setStoriesCountWithDurations(durations); - storiesProgressView?.setStoriesListener(this) + storiesProgressView.setStoriesListener(this) counter = 2 - storiesProgressView?.startStories(counter) + storiesProgressView.startStories(counter) image = findViewById(R.id.image) as ImageView image?.setImageResource(resources[counter]) // bind reverse view val reverse = findViewById(R.id.reverse) - reverse.setOnClickListener { storiesProgressView?.reverse() } - reverse.setOnTouchListener(onTouchListener) + reverse.setOnClickListener { storiesProgressView.reverse() } // bind skip view val skip = findViewById(R.id.skip) - skip.setOnClickListener { storiesProgressView?.skip() } - skip.setOnTouchListener(onTouchListener) + skip.setOnClickListener { storiesProgressView.skip() } } override fun onNext() { @@ -86,7 +65,7 @@ class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { override fun onDestroy() { // Very important ! - storiesProgressView?.destroy() + storiesProgressView.destroy() super.onDestroy() } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index abc7fa3..c7d6502 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,9 +1,9 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + tools:src="@drawable/sample1" /> + android:layout_weight="1" /> + android:layout_weight="1" /> + app:cornerRadius="4dp" + app:progressColor="@color/colorAccent" + app:progressGap="4dp" /> \ No newline at end of file diff --git a/build.gradle b/build.gradle index 330b58c..a1f6ea9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,29 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.21' - repositories { - google() - jcenter() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } + ext.kotlin_version = '1.5.10' + repositories { + google() + jcenter() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } } allprojects { - repositories { - google() - jcenter() - maven { url "https://jitpack.io" } - } + repositories { + google() + jcenter() + maven { url "https://jitpack.io" } + } } task clean(type: Delete) { - delete rootProject.buildDir + delete rootProject.buildDir } diff --git a/gradle.properties b/gradle.properties index aac7c9b..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 096f39d..f03a026 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 10 10:57:05 WEST 2018 +#Thu Sep 24 18:15:02 BST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 98a57f5..2f597b3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -3,35 +3,35 @@ apply plugin: 'kotlin-android' apply plugin: 'com.github.dcendents.android-maven' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' - group = "com.teresaholfeld.stories" + compileSdkVersion 30 + group = "com.teresaholfeld.stories" - defaultConfig { - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.1.4" + defaultConfig { + minSdkVersion 15 + targetSdkVersion 30 + versionCode 2 + versionName "1.1.5" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } - } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.3.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { + exclude group: 'com.android.support', module: 'support-annotations' + }) } repositories { - mavenCentral() + mavenCentral() } diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index 7921f3a..cd6acea 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -2,6 +2,7 @@ package com.teresaholfeld.stories import android.annotation.SuppressLint import android.content.Context +import android.content.res.ColorStateList import android.util.AttributeSet import android.view.LayoutInflater import android.view.View @@ -10,13 +11,25 @@ import android.view.animation.LinearInterpolator import android.view.animation.ScaleAnimation import android.view.animation.Transformation import android.widget.FrameLayout +import androidx.core.view.ViewCompat +import com.google.android.material.shape.CornerFamily +import com.google.android.material.shape.MaterialShapeDrawable +import com.google.android.material.shape.ShapeAppearanceModel @SuppressLint("ViewConstructor") -internal class PausableProgressBar constructor(context: Context, - attrs: AttributeSet? = null, - progressColor: Int, - progressBackgroundColor: Int) - : FrameLayout(context, attrs) { +internal class PausableProgressBar( + context: Context, + attrs: AttributeSet? = null, + progressColor: Int, + progressBackgroundColor: Int, + cornerRadius: Int +) : FrameLayout(context, attrs) { + constructor( + context: Context, + progressColor: Int, + progressBackgroundColor: Int, + cornerRadius: Int + ) : this(context, null, progressColor, progressBackgroundColor, cornerRadius) private val frontProgressView: View? private val backProgressView: View? @@ -30,17 +43,21 @@ internal class PausableProgressBar constructor(context: Context, fun onFinishProgress() } - constructor(context: Context, - progressColor: Int, - progressBackgroundColor: Int) - : this(context, null, progressColor, progressBackgroundColor) - init { LayoutInflater.from(context).inflate(R.layout.pausable_progress, this) frontProgressView = findViewById(R.id.front_progress) backProgressView = findViewById(R.id.back_progress) - backProgressView?.setBackgroundColor(progressBackgroundColor) - frontProgressView?.setBackgroundColor(progressColor) + ViewCompat.setBackground(frontProgressView, createBackgroundDrawable(progressColor, cornerRadius)) + ViewCompat.setBackground(backProgressView, createBackgroundDrawable(progressBackgroundColor, cornerRadius)) + } + + private fun createBackgroundDrawable(color: Int, cornerRadius: Int): MaterialShapeDrawable { + val allCorners = ShapeAppearanceModel().toBuilder() + .setAllCorners(CornerFamily.ROUNDED, cornerRadius.toFloat()) + .build() + val materialShapeDrawable = MaterialShapeDrawable(allCorners) + materialShapeDrawable.fillColor = ColorStateList.valueOf(color) + return materialShapeDrawable } fun setDuration(duration: Long) { @@ -115,14 +132,14 @@ internal class PausableProgressBar constructor(context: Context, animation = null } - private inner class PausableScaleAnimation internal constructor(fromX: Float, - toX: Float, - fromY: Float, - toY: Float, - pivotXType: Int, - pivotXValue: Float, - pivotYType: Int, - pivotYValue: Float) + private class PausableScaleAnimation(fromX: Float, + toX: Float, + fromY: Float, + toY: Float, + pivotXType: Int, + pivotXValue: Float, + pivotYType: Int, + pivotYValue: Float) : ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue) { private var mElapsedAtPause: Long = 0 @@ -141,7 +158,7 @@ internal class PausableProgressBar constructor(context: Context, /*** * pause animation */ - internal fun pause() { + fun pause() { if (mPaused) return mElapsedAtPause = 0 mPaused = true @@ -150,7 +167,7 @@ internal class PausableProgressBar constructor(context: Context, /*** * resume animation */ - internal fun resume() { + fun resume() { mPaused = false } } diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 36d3f5f..2d20b38 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -5,25 +5,31 @@ package com.teresaholfeld.stories import android.annotation.TargetApi import android.content.Context import android.os.Build -import android.support.v4.content.ContextCompat import android.util.AttributeSet import android.view.View import android.widget.LinearLayout -import java.util.ArrayList +import androidx.core.content.ContextCompat class StoriesProgressView : LinearLayout { - private val progressBarLayoutParam = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f) - private val spaceLayoutParam = LinearLayout.LayoutParams(5, LinearLayout.LayoutParams.WRAP_CONTENT) + private val progressBarLayoutParams = LayoutParams(0, LayoutParams.MATCH_PARENT, 1f) + + private val defaultGap = 5 + private var progressGapInPixels = defaultGap + + private val defaultCornerRadius = 0 + private var progressCornerRadius = defaultCornerRadius + private val defaultColor = ContextCompat.getColor(context, R.color.progress_primary) private val defaultBackgroundColor = ContextCompat.getColor(context, R.color.progress_secondary) private var progressColor = defaultColor private var progressBackgroundColor = defaultBackgroundColor - private val progressBars = ArrayList() + private val progressBars = mutableListOf() private var storiesCount = -1 + /** * pointer of running animation */ @@ -42,7 +48,8 @@ class StoriesProgressView : LinearLayout { fun onComplete() } - @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) { + @JvmOverloads + constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) { init(context, attrs) } @@ -57,12 +64,13 @@ class StoriesProgressView : LinearLayout { } private fun init(context: Context, attrs: AttributeSet?) { - orientation = LinearLayout.HORIZONTAL + orientation = HORIZONTAL val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StoriesProgressView) storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0) progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) - progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, - defaultBackgroundColor) + progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, defaultBackgroundColor) + progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, defaultGap) + progressCornerRadius = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_cornerRadius, defaultCornerRadius) typedArray.recycle() bindViews() } @@ -82,14 +90,14 @@ class StoriesProgressView : LinearLayout { } private fun createProgressBar(): PausableProgressBar { - val p = PausableProgressBar(context, progressColor, progressBackgroundColor) - p.layoutParams = progressBarLayoutParam + val p = PausableProgressBar(context, progressColor, progressBackgroundColor, progressCornerRadius) + p.layoutParams = progressBarLayoutParams return p } private fun createSpace(): View { val v = View(context) - v.layoutParams = spaceLayoutParam + v.layoutParams = LayoutParams(progressGapInPixels, LayoutParams.MATCH_PARENT) return v } diff --git a/library/src/main/res/layout/pausable_progress.xml b/library/src/main/res/layout/pausable_progress.xml index 0aef0cf..816694c 100644 --- a/library/src/main/res/layout/pausable_progress.xml +++ b/library/src/main/res/layout/pausable_progress.xml @@ -1,27 +1,28 @@ + android:layout_height="match_parent" + tools:layout_height="8dp"> + tools:visibility="visible" /> diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 1f527d8..50537c0 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -1,8 +1,10 @@ - - - + + + + + \ No newline at end of file