From 046e67bf78c322a7bc3e2f75ee7cdf5a22550c94 Mon Sep 17 00:00:00 2001 From: leafwai Date: Thu, 17 Feb 2022 15:40:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=BF=81=E7=A7=BB=E5=88=B0AndroidX=202.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E6=8C=81=E6=97=A0=E9=99=90=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=BB=91=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 3 +- .idea/modules.xml | 10 -- .idea/runConfigurations.xml | 12 -- StackLayoutManager/build.gradle | 10 +- .../stacklayoutmanager/DefaultAnimation.kt | 5 +- .../stacklayoutmanager/DefaultLayout.kt | 20 ++- .../stacklayoutmanager/StackLayoutManager.kt | 166 ++++++++++-------- build.gradle | 6 +- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 6 +- sample/build.gradle | 26 +-- .../ExampleInstrumentedTest.kt | 10 +- sample/src/main/AndroidManifest.xml | 3 +- .../FadeInFadeOutAnimation.java | 1 - .../MainActivity.java | 20 +-- sample/src/main/res/layout/activity_main.xml | 8 +- sample/src/main/res/layout/image_card.xml | 4 +- 17 files changed, 159 insertions(+), 153 deletions(-) delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 99202cc..aee17b1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,6 @@ + - + diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bb34f9c..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/StackLayoutManager/build.gradle b/StackLayoutManager/build.gradle index 598d599..cb2185a 100644 --- a/StackLayoutManager/build.gradle +++ b/StackLayoutManager/build.gradle @@ -3,15 +3,15 @@ apply plugin: 'kotlin-android' apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 27 + compileSdkVersion 31 defaultConfig { - minSdkVersion 14 - targetSdkVersion 27 + minSdkVersion 21 + targetSdkVersion 31 versionCode 6 versionName "1.0.5" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } @@ -30,7 +30,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'androidx.recyclerview:recyclerview:1.2.1' } repositories { mavenCentral() diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt index 9742e9e..d8b0b81 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt @@ -2,6 +2,7 @@ package com.littlemango.stacklayoutmanager import android.view.View import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation +import kotlin.math.pow class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) { @@ -72,8 +73,8 @@ class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) scale = 1 - ((1 - mOutScale) * firstMovePercent) rotation = mOutRotation * firstMovePercent } else { - val minScale = (Math.pow(mScale.toDouble(), position.toDouble())).toFloat() - val maxScale = (Math.pow(mScale.toDouble(), (position - 1).toDouble())).toFloat() + val minScale = (mScale.toDouble().pow(position.toDouble())).toFloat() + val maxScale = (mScale.toDouble().pow((position - 1).toDouble())).toFloat() scale = minScale + (maxScale - minScale) * firstMovePercent //只对最后一个 item 做透明度变化 if (position == mVisibleCount) { diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultLayout.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultLayout.kt index 31e06f2..7e943c6 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultLayout.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultLayout.kt @@ -47,12 +47,18 @@ class DefaultLayout(scrollOrientation: StackLayoutManager.ScrollOrientation, private fun getFirstVisibleItemLeft(): Int { return when(mScrollOrientation) { - StackLayoutManager.ScrollOrientation.RIGHT_TO_LEFT -> mStartMargin - mScrollOffset % mWidth + StackLayoutManager.ScrollOrientation.RIGHT_TO_LEFT -> { + var offset = mScrollOffset % mWidth + if (offset < 0) offset += mWidth + mStartMargin - offset + } StackLayoutManager.ScrollOrientation.LEFT_TO_RIGHT -> { return if (mScrollOffset % mWidth == 0) { mStartMargin } else { - mStartMargin + (mWidth - mScrollOffset % mWidth) + var offset = mScrollOffset % mWidth + if (offset < 0) offset += mWidth + mStartMargin + (mWidth - offset) } } else -> mWidthSpace / 2 @@ -61,12 +67,18 @@ class DefaultLayout(scrollOrientation: StackLayoutManager.ScrollOrientation, private fun getFirstVisibleItemTop(): Int { return when(mScrollOrientation) { - StackLayoutManager.ScrollOrientation.BOTTOM_TO_TOP -> mStartMargin - mScrollOffset % mHeight + StackLayoutManager.ScrollOrientation.BOTTOM_TO_TOP -> { + var offset = mScrollOffset % mHeight + if (offset < 0) offset += mHeight + mStartMargin - offset + } StackLayoutManager.ScrollOrientation.TOP_TO_BOTTOM -> { return if (mScrollOffset % mHeight == 0) { mStartMargin } else { - mStartMargin + (mHeight - mScrollOffset % mHeight) + var offset = mScrollOffset % mHeight + if (offset < 0) offset += mHeight + mStartMargin + (mHeight - offset) } } else -> mHeightSpace / 2 diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt index 5eef721..2049104 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt @@ -1,19 +1,23 @@ package com.littlemango.stacklayoutmanager -import android.support.annotation.IntRange -import android.support.v7.widget.RecyclerView -import android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING -import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE +import androidx.annotation.IntRange +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING +import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE import android.view.View import android.view.ViewGroup +import kotlin.math.ceil +import kotlin.math.floor -class StackLayoutManager(scrollOrientation: ScrollOrientation, - visibleCount: Int, - animation: Class, - layout: Class) : RecyclerView.LayoutManager() { - private enum class FlingOrientation{NONE, LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP} +class StackLayoutManager( + scrollOrientation: ScrollOrientation, + visibleCount: Int, + animation: Class, + layout: Class +) : RecyclerView.LayoutManager() { + private enum class FlingOrientation { NONE, LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP } - enum class ScrollOrientation{LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP} + enum class ScrollOrientation { LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP } private var mVisibleItemCount = visibleCount @@ -26,6 +30,7 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, //做动画的组件,支持自定义 private var mAnimation: StackAnimation? = null + //做布局的组件,支持自定义 private var mLayout: StackLayout? = null @@ -78,7 +83,7 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, * @param velocity 默认值是2000. */ fun setPagerFlingVelocity(@IntRange(from = 0, to = Int.MAX_VALUE.toLong()) velocity: Int) { - mPagerFlingVelocity = Math.min(Int.MAX_VALUE, Math.max(0, velocity)) + mPagerFlingVelocity = Int.MAX_VALUE.coerceAtMost(0.coerceAtLeast(velocity)) } /** @@ -92,8 +97,8 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, * 设置recyclerView 静止时候可见的itemView 个数. * @param count 可见 itemView,默认为3 */ - fun setVisibleItemCount(@IntRange(from = 1, to = Long.MAX_VALUE)count: Int) { - mVisibleItemCount = Math.min(itemCount - 1, Math.max(1, count)) + fun setVisibleItemCount(@IntRange(from = 1, to = Long.MAX_VALUE) count: Int) { + mVisibleItemCount = (itemCount - 1).coerceAtMost(1.coerceAtLeast(count)) mAnimation?.setVisibleCount(mVisibleItemCount) } @@ -157,11 +162,11 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, if (width == 0 || height == 0) { return 0 } - return when(mScrollOrientation) { - ScrollOrientation.RIGHT_TO_LEFT -> Math.floor((mScrollOffset * 1.0 / width)).toInt() - ScrollOrientation.LEFT_TO_RIGHT -> itemCount - 1 - Math.ceil((mScrollOffset * 1.0 / width)).toInt() - ScrollOrientation.BOTTOM_TO_TOP -> Math.floor((mScrollOffset * 1.0 / height)).toInt() - ScrollOrientation.TOP_TO_BOTTOM -> itemCount - 1 - Math.ceil((mScrollOffset * 1.0 / height)).toInt() + return when (mScrollOrientation) { + ScrollOrientation.RIGHT_TO_LEFT -> floor((mScrollOffset * 1.0 / width)).toInt() + ScrollOrientation.LEFT_TO_RIGHT -> itemCount - 1 - ceil((mScrollOffset * 1.0 / width)).toInt() + ScrollOrientation.BOTTOM_TO_TOP -> floor((mScrollOffset * 1.0 / height)).toInt() + ScrollOrientation.TOP_TO_BOTTOM -> itemCount - 1 - ceil((mScrollOffset * 1.0 / height)).toInt() } } @@ -179,14 +184,17 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, constructor() : this(ScrollOrientation.RIGHT_TO_LEFT) init { - mScrollOffset = when(mScrollOrientation) { + mScrollOffset = when (mScrollOrientation) { ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.BOTTOM_TO_TOP -> 0 else -> Int.MAX_VALUE } if (StackAnimation::class.java.isAssignableFrom(animation)) { try { - val cla = animation.getDeclaredConstructor(ScrollOrientation::class.java, Int::class.javaPrimitiveType) + val cla = animation.getDeclaredConstructor( + ScrollOrientation::class.java, + Int::class.javaPrimitiveType + ) mAnimation = cla.newInstance(scrollOrientation, visibleCount) as StackAnimation } catch (e: Exception) { e.printStackTrace() @@ -194,7 +202,11 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } if (StackLayout::class.java.isAssignableFrom(layout)) { try { - val cla = layout.getDeclaredConstructor(ScrollOrientation::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType) + val cla = layout.getDeclaredConstructor( + ScrollOrientation::class.java, + Int::class.javaPrimitiveType, + Int::class.javaPrimitiveType + ) mLayout = cla.newInstance(scrollOrientation, visibleCount, 30) as StackLayout } catch (e: Exception) { e.printStackTrace() @@ -203,8 +215,10 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { - return RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT) + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) } override fun onAttachedToWindow(view: RecyclerView) { @@ -212,7 +226,7 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, mOnFlingListener = object : RecyclerView.OnFlingListener() { override fun onFling(velocityX: Int, velocityY: Int): Boolean { if (mPagerMode) { - when(mScrollOrientation) { + when (mScrollOrientation) { ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> { mFlingOrientation = when { velocityX > mPagerFlingVelocity -> FlingOrientation.RIGHT_TO_LEFT @@ -299,11 +313,19 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } } - override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int { + override fun scrollHorizontallyBy( + dx: Int, + recycler: RecyclerView.Recycler, + state: RecyclerView.State + ): Int { return handleScrollBy(dx, recycler) } - override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State?): Int { + override fun scrollVerticallyBy( + dy: Int, + recycler: RecyclerView.Recycler, + state: RecyclerView.State? + ): Int { return handleScrollBy(dy, recycler) } @@ -315,7 +337,11 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, requestLayout() } - override fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State?, position: Int) { + override fun smoothScrollToPosition( + recyclerView: RecyclerView, + state: RecyclerView.State?, + position: Int + ) { if (position < 0 || position >= itemCount) { throw ArrayIndexOutOfBoundsException("$position is out of bound [0..$itemCount-1]") } @@ -337,59 +363,51 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } private fun handleScrollBy(offset: Int, recycler: RecyclerView.Recycler): Int { - //期望值,不得超过最大最小值,所以期望值不一定等于实际值 - val expectOffset = mScrollOffset + offset - - //实际值 - mScrollOffset = getValidOffset(expectOffset) - - //实际偏移,超过最大最小值之后的偏移都应该是0,该值作为返回值,否则在极限位置进行滚动的时候不会出现弹性阴影 - val exactMove = mScrollOffset - expectOffset + offset - - if (exactMove == 0) { - //itemViews 位置都不会改变,直接 return - return 0 - } - + mScrollOffset += offset detachAndScrapAttachedViews(recycler) - loadItemView(recycler) - return exactMove + + return offset } private fun loadItemView(recycler: RecyclerView.Recycler) { val firstVisiblePosition = getFirstVisibleItemPosition() - val lastVisiblePosition = getLastVisibleItemPosition() - + val lastVisiblePosition = getFirstVisibleItemPosition() + mVisibleItemCount - 1 //位移百分比 - val movePercent = getFirstVisibleItemMovePercent() + var movePercent = getFirstVisibleItemMovePercent() + if (movePercent < 0) movePercent += 1 - for (i in lastVisiblePosition downTo firstVisiblePosition) { - val view = recycler.getViewForPosition(i) + for (i in (mVisibleItemCount - 1) downTo 0) { + var position = (firstVisiblePosition + i) % itemCount + if (position < 0) { + position += itemCount + } + val view = recycler.getViewForPosition(position) //添加到recycleView 中 addView(view) //测量 measureChild(view, 0, 0) //布局 - mLayout?.doLayout(this, mScrollOffset, movePercent, view, i - firstVisiblePosition) + mLayout?.doLayout(this, mScrollOffset, movePercent, view, i) //做动画 - mAnimation?.doAnimation(movePercent, view, i - firstVisiblePosition) + mAnimation?.doAnimation(movePercent, view, i) } //尝试更新当前item的位置并通知外界 updatePositionRecordAndNotify(firstVisiblePosition) //重用 - if (firstVisiblePosition - 1 >= 0) { - val view = recycler.getViewForPosition(firstVisiblePosition - 1) - resetViewAnimateProperty(view) - removeAndRecycleView(view, recycler) - } - if (lastVisiblePosition + 1 < itemCount) { - val view = recycler.getViewForPosition(lastVisiblePosition + 1) - resetViewAnimateProperty(view) - removeAndRecycleView(view, recycler) - } + val lastPosition = firstVisiblePosition - 1 + val lastView = + recycler.getViewForPosition(if (lastPosition >= 0 || lastPosition % itemCount == 0) lastPosition % itemCount else lastPosition % itemCount + itemCount) + resetViewAnimateProperty(lastView) + removeAndRecycleView(lastView, recycler) + + val nextPosition = lastVisiblePosition + 1 + val nextView = + recycler.getViewForPosition(if (nextPosition >= 0 || nextPosition % itemCount == 0) nextPosition % itemCount else nextPosition % itemCount + itemCount) + resetViewAnimateProperty(nextView) + removeAndRecycleView(nextView, recycler) } private fun resetViewAnimateProperty(view: View) { @@ -405,9 +423,13 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, scrollToCenter(targetPosition, view, true) } - private fun scrollToCenter(targetPosition: Int, recyclerView: RecyclerView, animation: Boolean) { + private fun scrollToCenter( + targetPosition: Int, + recyclerView: RecyclerView, + animation: Boolean + ) { val targetOffset = getPositionOffset(targetPosition) - when(mScrollOrientation) { + when (mScrollOrientation) { ScrollOrientation.LEFT_TO_RIGHT, ScrollOrientation.RIGHT_TO_LEFT -> { if (animation) { recyclerView.smoothScrollBy(targetOffset - mScrollOffset, 0) @@ -426,14 +448,15 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } private fun getValidOffset(expectOffset: Int): Int { - return when(mScrollOrientation) { - ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0) - else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0) + return when (mScrollOrientation) { + ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> + (width * (itemCount - 1)).coerceAtMost(expectOffset).coerceAtLeast(0) + else -> (height * (itemCount - 1)).coerceAtMost(expectOffset).coerceAtLeast(0) } } private fun getPositionOffset(position: Int): Int { - return when(mScrollOrientation) { + return when (mScrollOrientation) { ScrollOrientation.RIGHT_TO_LEFT -> position * width ScrollOrientation.LEFT_TO_RIGHT -> (itemCount - 1 - position) * width ScrollOrientation.BOTTOM_TO_TOP -> position * height @@ -441,15 +464,6 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, } } - private fun getLastVisibleItemPosition(): Int { - val firstVisiblePosition = getFirstVisibleItemPosition() - return if (firstVisiblePosition + mVisibleItemCount > itemCount - 1) { - itemCount - 1 - } else { - firstVisiblePosition + mVisibleItemCount - } - } - private fun getFirstVisibleItemMovePercent(): Float { if (width == 0 || height == 0) { return 0f @@ -480,7 +494,7 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, //当是 Fling 触发的时候 val triggerOrientation = mFlingOrientation mFlingOrientation = FlingOrientation.NONE - when(mScrollOrientation) { + when (mScrollOrientation) { ScrollOrientation.RIGHT_TO_LEFT -> { if (triggerOrientation == FlingOrientation.RIGHT_TO_LEFT) { return position + 1 diff --git a/build.gradle b/build.gradle index 77a36c4..273f5c2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.60' + ext.kotlin_version = '1.6.10' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.novoda:bintray-release:0.8.1' } @@ -29,4 +29,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } -tasks.getByPath(":StackLayoutManager:releaseAndroidJavadocs").enabled = false +//tasks.getByPath(":StackLayoutManager:releaseAndroidJavadocs").enabled = false diff --git a/gradle.properties b/gradle.properties index 743d692..8de5058 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,8 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # 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. # This option should only be used with decoupled projects. More details, visit diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 40dfc80..fff31ae 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jun 28 17:28:50 CST 2018 +#Thu Feb 17 14:43:36 CST 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/sample/build.gradle b/sample/build.gradle index eff7b48..1f2e41a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,14 +5,14 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 27 + compileSdkVersion 31 defaultConfig { applicationId "com.littlemango.stacklayoutmanagermaster" - minSdkVersion 19 - targetSdkVersion 27 + minSdkVersion 21 + targetSdkVersion 31 versionCode 6 versionName "1.0.5" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -22,19 +22,19 @@ android { } } -ext.kotlin_version = '1.2.60' +ext.kotlin_version = '1.6.10' dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.android.support:recyclerview-v7:27.1.1' - implementation 'com.android.support:cardview-v7:27.1.1' + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + implementation 'androidx.recyclerview:recyclerview:1.2.1' + implementation 'androidx.cardview:cardview:1.0.0' implementation project(':StackLayoutManager') implementation 'com.afollestad.material-dialogs:core:0.9.6.0' - implementation 'com.android.support:design:27.1.1' + implementation 'com.google.android.material:material:1.5.0' } diff --git a/sample/src/androidTest/java/com/littlemango/stacklayoutmanagermaster/ExampleInstrumentedTest.kt b/sample/src/androidTest/java/com/littlemango/stacklayoutmanagermaster/ExampleInstrumentedTest.kt index b927e69..bcc200f 100644 --- a/sample/src/androidTest/java/com/littlemango/stacklayoutmanagermaster/ExampleInstrumentedTest.kt +++ b/sample/src/androidTest/java/com/littlemango/stacklayoutmanagermaster/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.littlemango.stacklayoutmanagermaster -import android.support.test.InstrumentationRegistry -import android.support.test.runner.AndroidJUnit4 - +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -18,7 +16,7 @@ class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. - val appContext = InstrumentationRegistry.getTargetContext() + val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.littlemango.stacklayoutmanagermaster", appContext.packageName) } } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 3f30da7..ce9be55 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/FadeInFadeOutAnimation.java b/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/FadeInFadeOutAnimation.java index c866d2c..7f76792 100644 --- a/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/FadeInFadeOutAnimation.java +++ b/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/FadeInFadeOutAnimation.java @@ -1,6 +1,5 @@ package com.littlemango.stacklayoutmanagermaster; -import android.support.v7.widget.LinearLayoutManager; import android.view.View; import com.littlemango.stacklayoutmanager.StackAnimation; diff --git a/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/MainActivity.java b/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/MainActivity.java index e58c78c..ed14620 100644 --- a/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/MainActivity.java +++ b/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/MainActivity.java @@ -1,11 +1,11 @@ package com.littlemango.stacklayoutmanagermaster; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.RecyclerView; -import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,7 +15,7 @@ import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import com.littlemango.stacklayoutmanager.StackLayoutManager; -import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation; + import java.util.Random; public class MainActivity extends AppCompatActivity { @@ -66,22 +66,22 @@ public class MainActivity extends AppCompatActivity { resetRandom(); break; case 2: - mStackLayoutManager = new StackLayoutManager(ScrollOrientation.LEFT_TO_RIGHT); + mStackLayoutManager = new StackLayoutManager(StackLayoutManager.ScrollOrientation.LEFT_TO_RIGHT); mRecyclerView.setLayoutManager(mStackLayoutManager); getSupportActionBar().setTitle("Picture 0"); break; case 3: - mStackLayoutManager = new StackLayoutManager(ScrollOrientation.RIGHT_TO_LEFT); + mStackLayoutManager = new StackLayoutManager(StackLayoutManager.ScrollOrientation.RIGHT_TO_LEFT); mRecyclerView.setLayoutManager(mStackLayoutManager); getSupportActionBar().setTitle("Picture 0"); break; case 4: - mStackLayoutManager = new StackLayoutManager(ScrollOrientation.TOP_TO_BOTTOM); + mStackLayoutManager = new StackLayoutManager(StackLayoutManager.ScrollOrientation.TOP_TO_BOTTOM); mRecyclerView.setLayoutManager(mStackLayoutManager); getSupportActionBar().setTitle("Picture 0"); break; case 5: - mStackLayoutManager = new StackLayoutManager(ScrollOrientation.BOTTOM_TO_TOP); + mStackLayoutManager = new StackLayoutManager(StackLayoutManager.ScrollOrientation.BOTTOM_TO_TOP); mRecyclerView.setLayoutManager(mStackLayoutManager); getSupportActionBar().setTitle("Picture 0"); break; diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 76870e7..31eb8c8 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -1,17 +1,17 @@ - - - - \ No newline at end of file + \ No newline at end of file diff --git a/sample/src/main/res/layout/image_card.xml b/sample/src/main/res/layout/image_card.xml index d31d327..912389c 100644 --- a/sample/src/main/res/layout/image_card.xml +++ b/sample/src/main/res/layout/image_card.xml @@ -1,5 +1,5 @@ - - +