diff --git a/README.md b/README.md index 202c303..79a8e19 100644 --- a/README.md +++ b/README.md @@ -9,39 +9,33 @@ latest version : [ ![Download](https://api.bintray.com/packages/agrawalsuneet/an -### LazyLoader ![lazyloader](https://user-images.githubusercontent.com/12999622/36225792-b7044432-11c3-11e8-8e22-5bbdcafa2312.gif) -### TashieLoader ![tashieloader](https://user-images.githubusercontent.com/12999622/36225793-b71f694c-11c3-11e8-9a81-8414bafb26c5.gif) -### SlidingLoader ![slidingloader](https://user-images.githubusercontent.com/12999622/34130222-f58ba220-e43e-11e7-8f60-4971918fecde.gif) -### RotatingCircularDotsLoader ![RotatingCircularDotsLoader](https://user-images.githubusercontent.com/12999622/34453427-d9aa8294-ed4c-11e7-8b1d-fe98d0c2c3dc.gif) -### TrailingCircularDotsLoader ![trailingcirculardotsloader](https://user-images.githubusercontent.com/12999622/39367184-f3bb706a-4a2d-11e8-9120-5027bbef2861.gif) -### ZeeLoader ![zeeloader](https://user-images.githubusercontent.com/12999622/44630261-8ba41980-a952-11e8-9ba5-45f4cafb473b.gif) -### AllianceLoader ![allianceloader](https://user-images.githubusercontent.com/12999622/44946787-d1e9f480-adfa-11e8-82ff-23e5f19a656b.gif) -### LinearDotsLoader +![lightsloader](https://user-images.githubusercontent.com/12999622/50548389-bb9d5980-0c71-11e9-8803-f25d1175ced0.gif) + + ![lineardotsloader](https://user-images.githubusercontent.com/12999622/35482391-54665328-042c-11e8-954b-93a92ebe2b0c.gif) -### CircularDotsLoader ![circulardotsloader](https://user-images.githubusercontent.com/12999622/36224573-f274b956-11bf-11e8-8f97-e4c031959465.gif) Check all other loaders [here](https://agrawalsuneet.github.io/agrawalsuneet/opensourcecontribution/) @@ -49,7 +43,7 @@ Check all other loaders [here](https://agrawalsuneet.github.io/agrawalsuneet/ope ## How To use include below dependency in build.gradle of application and compile it ``` -compile 'com.agrawalsuneet.androidlibs:dotsloader:1.1' +implementation 'com.agrawalsuneet.androidlibs:dotsloader:1.2' ``` @@ -122,14 +116,13 @@ compile 'com.agrawalsuneet.androidlibs:dotsloader:1.1' * Kotlin ``` -var tashie = TashieLoader(this) +var tashie = TashieLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.green)) .apply { - noOfDots = 5 - dotsDist = 10 - dotsRadius = 30 animDuration = 500 animDelay = 100 - dotsColor = resources.getColor(R.color.green) interpolator = LinearInterpolator() } containerLL.addView(tashie) @@ -138,15 +131,15 @@ var tashie = TashieLoader(this) * Java ``` -TashieLoader tashie = new TashieLoader(this); - tashie.setNoOfDots(8); - tashie.setDotsRadius(20); - tashie.setDotsDist(10); - tashie.setDotsColor(ContextCompat.getColor(this, R.color.blue_selected)); +TashieLoader tashie = new TashieLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.green)); + tashie.setAnimDuration(500); tashie.setAnimDelay(100); tashie.setInterpolator(new LinearInterpolator()); - + containerLL.addView(tashie); ``` @@ -375,6 +368,44 @@ AllianceLoader allianceLoader = new AllianceLoader( containerLL.addView(allianceLoader); ``` +### LightsLoader +##### Through XML +``` + +``` + +##### Through Code + +* Kotlin +``` +val lightsLoader = LightsLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.red)) + + + containerLL.addView(lightsLoader) + +``` + +* Java +``` +LightsLoader lightsLoader = new LightsLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.red)); + + + containerLL.addView(lightsLoader); +``` + ### LinearDotsLoader ##### Through XML diff --git a/app/build.gradle b/app/build.gradle index 051b4f1..6ce5da1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,21 +1,12 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -repositories { - mavenCentral() - maven { - url 'https://maven.google.com/' - name 'Google' - } -} - android { - compileSdkVersion 25 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { applicationId "com.agrawalsuneet.loaders" minSdkVersion 16 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -29,9 +20,9 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.1.0' - compile project(':dotsloader') - //compile 'com.agrawalsuneet.androidlibs:dotsloader:1.0' - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation project(':dotsloader') + //implementation 'com.agrawalsuneet.androidlibs:dotsloader:1.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt index 4dceff0..d36712b 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt @@ -14,9 +14,9 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main_alliance) + setContentView(R.layout.main_lights) - supportActionBar!!.title = "AllianceLoader" + supportActionBar?.title = "LightsLoader" containerLL = findViewById(R.id.container) as LinearLayout @@ -32,6 +32,17 @@ class MainActivity : AppCompatActivity() { //initZeeLoader() //initAllianceLoader() + //initLightsLoader() + } + + private fun initLightsLoader() { + val lightsLoader = LightsLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.red)) + + + containerLL.addView(lightsLoader) } private fun initAllianceLoader() { @@ -104,14 +115,13 @@ class MainActivity : AppCompatActivity() { } private fun initTashieLoader() { - var tashie = TashieLoader(this) + var tashie = TashieLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.green)) .apply { - noOfDots = 5 - dotsDist = 10 - dotsRadius = 30 animDuration = 500 animDelay = 100 - dotsColor = resources.getColor(R.color.green) interpolator = LinearInterpolator() } containerLL.addView(tashie) diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java index 758649b..cef52bb 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivityJava.java @@ -8,6 +8,7 @@ import android.widget.LinearLayout; import com.agrawalsuneet.dotsloader.loaders.AllianceLoader; +import com.agrawalsuneet.dotsloader.loaders.LightsLoader; import com.agrawalsuneet.dotsloader.loaders.RotatingCircularDotsLoader; import com.agrawalsuneet.dotsloader.loaders.SlidingLoader; import com.agrawalsuneet.dotsloader.loaders.TashieLoader; @@ -35,11 +36,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { loader.setInterpolator(new LinearInterpolator());*/ - TashieLoader tashie = new TashieLoader(this); - tashie.setNoOfDots(8); - tashie.setDotsRadius(20); - tashie.setDotsDist(10); - tashie.setDotsColor(ContextCompat.getColor(this, R.color.blue_selected)); + + TashieLoader tashie = new TashieLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.green)); + tashie.setAnimDuration(500); tashie.setAnimDelay(100); tashie.setInterpolator(new LinearInterpolator()); @@ -103,6 +105,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { allianceLoader.setAnimDuration(500); containerLL.addView(allianceLoader); + + LightsLoader lightsLoader = new LightsLoader( + this, 5, + 30, 10, + ContextCompat.getColor(this, R.color.red)); + + + containerLL.addView(lightsLoader); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 24e9f1f..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_main_alliance.xml b/app/src/main/res/layout/main_alliance.xml similarity index 100% rename from app/src/main/res/layout/activity_main_alliance.xml rename to app/src/main/res/layout/main_alliance.xml diff --git a/app/src/main/res/layout/activity_main_circulardotsloader.xml b/app/src/main/res/layout/main_circulardotsloader.xml similarity index 100% rename from app/src/main/res/layout/activity_main_circulardotsloader.xml rename to app/src/main/res/layout/main_circulardotsloader.xml diff --git a/app/src/main/res/layout/activity_main_lazyloader.xml b/app/src/main/res/layout/main_lazyloader.xml similarity index 100% rename from app/src/main/res/layout/activity_main_lazyloader.xml rename to app/src/main/res/layout/main_lazyloader.xml diff --git a/app/src/main/res/layout/main_lights.xml b/app/src/main/res/layout/main_lights.xml new file mode 100644 index 0000000..409befe --- /dev/null +++ b/app/src/main/res/layout/main_lights.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main_lineardotsloader.xml b/app/src/main/res/layout/main_lineardotsloader.xml similarity index 100% rename from app/src/main/res/layout/activity_main_lineardotsloader.xml rename to app/src/main/res/layout/main_lineardotsloader.xml diff --git a/app/src/main/res/layout/activity_main_3.xml b/app/src/main/res/layout/main_rotatingcircular.xml similarity index 100% rename from app/src/main/res/layout/activity_main_3.xml rename to app/src/main/res/layout/main_rotatingcircular.xml diff --git a/app/src/main/res/layout/activity_main_2.xml b/app/src/main/res/layout/main_sliding.xml similarity index 100% rename from app/src/main/res/layout/activity_main_2.xml rename to app/src/main/res/layout/main_sliding.xml diff --git a/app/src/main/res/layout/activity_main_tashieloader.xml b/app/src/main/res/layout/main_tashie.xml similarity index 100% rename from app/src/main/res/layout/activity_main_tashieloader.xml rename to app/src/main/res/layout/main_tashie.xml diff --git a/app/src/main/res/layout/activity_main_trailingcirculer.xml b/app/src/main/res/layout/main_trailingcirculer.xml similarity index 100% rename from app/src/main/res/layout/activity_main_trailingcirculer.xml rename to app/src/main/res/layout/main_trailingcirculer.xml diff --git a/app/src/main/res/layout/activity_main_zee.xml b/app/src/main/res/layout/main_zee.xml similarity index 100% rename from app/src/main/res/layout/activity_main_zee.xml rename to app/src/main/res/layout/main_zee.xml diff --git a/build.gradle b/build.gradle index 2581dab..7ddb3b5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,20 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.1.3-2' + ext.kotlin_version = '1.2.51' repositories { + google() jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.2.0' 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() } } diff --git a/dotsloader/build.gradle b/dotsloader/build.gradle index 23e8654..86c3dfd 100644 --- a/dotsloader/build.gradle +++ b/dotsloader/build.gradle @@ -1,26 +1,22 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -repositories { - mavenCentral() -} - buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } ext { PUBLISH_GROUP_ID = 'com.agrawalsuneet.androidlibs' PUBLISH_ARTIFACT_ID = 'dotsloader' - PUBLISH_VERSION = '1.1' + PUBLISH_VERSION = '1.2' } configurations { @@ -28,14 +24,13 @@ configurations { } android { - compileSdkVersion 25 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { minSdkVersion 16 - targetSdkVersion 25 - versionCode 11 - versionName "1.1" + targetSdkVersion 28 + versionCode 12 + versionName "1.2" } buildTypes { release { @@ -46,8 +41,8 @@ android { } dependencies { - javadocDeps 'com.android.support:support-annotations:25.1.0' - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + javadocDeps 'com.android.support:support-annotations:28.0.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' \ No newline at end of file diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircleView.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircleView.kt index 0657508..a7a8528 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircleView.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircleView.kt @@ -19,11 +19,15 @@ class CircleView : View { var circleColor: Int = 0 var drawOnlyStroke: Boolean = false + private var xyCordinates: Float = 0.0f + private val paint: Paint = Paint() constructor(context: Context, circleRadius: Int, circleColor: Int) : super(context) { this.circleRadius = circleRadius this.circleColor = circleColor + + initValues() } constructor(context: Context, circleRadius: Int, circleColor: Int, drawOnlyStroke: Boolean, strokeWidth: Int) : super(context) { @@ -32,16 +36,22 @@ class CircleView : View { this.drawOnlyStroke = drawOnlyStroke this.strokeWidth = strokeWidth + + initValues() } - constructor(context: Context) : super(context) + constructor(context: Context) : super(context) { + initValues() + } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initAttributes(attrs) + initValues() } constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initAttributes(attrs) + initValues() } @@ -63,16 +73,13 @@ class CircleView : View { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - + val widthHeight = (2 * (circleRadius)) + strokeWidth setMeasuredDimension(widthHeight, widthHeight) } - - override fun onDraw(canvas: Canvas?) { - super.onDraw(canvas) - + private fun initValues() { paint.isAntiAlias = true if (drawOnlyStroke) { @@ -85,9 +92,13 @@ class CircleView : View { //adding half of strokeWidth because //the stroke will be half inside the drawing circle and half outside - val xyCordinates = (circleRadius + (strokeWidth / 2)).toFloat() + xyCordinates = (circleRadius + (strokeWidth / 2)).toFloat() + } - canvas!!.drawCircle(xyCordinates, xyCordinates, circleRadius.toFloat(), paint) + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.drawCircle(xyCordinates, xyCordinates, circleRadius.toFloat(), paint) } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircularLoaderBaseView.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircularLoaderBaseView.kt index 5ef6f13..3ff5569 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircularLoaderBaseView.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/CircularLoaderBaseView.kt @@ -1,25 +1,14 @@ package com.agrawalsuneet.dotsloader.basicviews import android.content.Context -import android.graphics.Canvas import android.util.AttributeSet import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.contracts.CircularAbstractView /** * Created by suneet on 12/29/17. */ -open class CircularLoaderBaseView : DotsLoaderBaseView { - - protected val mNoOfDots = 8 - private val SIN_45 = 0.7071f - - lateinit var dotsYCorArr: FloatArray - - var bigCircleRadius: Int = 60 - set(bigCircleRadius) { - field = bigCircleRadius - initCordinates() - } +class CircularLoaderBaseView : CircularAbstractView { constructor(context: Context) : super(context) { initCordinates() @@ -49,57 +38,4 @@ open class CircularLoaderBaseView : DotsLoaderBaseView { initShadowPaints() } - override fun initAttributes(attrs: AttributeSet) { - super.initAttributes(attrs) - - val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularLoaderBaseView, 0, 0) - - this.bigCircleRadius = typedArray.getDimensionPixelSize(R.styleable.CircularLoaderBaseView_loader_bigCircleRadius, 60) - - typedArray.recycle() - } - - override fun initCordinates() { - val sin45Radius = SIN_45 * this.bigCircleRadius - - dotsXCorArr = FloatArray(mNoOfDots) - dotsYCorArr = FloatArray(mNoOfDots) - - for (i in 0..mNoOfDots - 1) { - dotsYCorArr[i] = (this.bigCircleRadius + radius).toFloat() - dotsXCorArr[i] = dotsYCorArr[i] - } - - dotsXCorArr[1] = dotsXCorArr[1] + sin45Radius - dotsXCorArr[2] = dotsXCorArr[2] + this.bigCircleRadius - dotsXCorArr[3] = dotsXCorArr[3] + sin45Radius - - dotsXCorArr[5] = dotsXCorArr[5] - sin45Radius - dotsXCorArr[6] = dotsXCorArr[6] - this.bigCircleRadius - dotsXCorArr[7] = dotsXCorArr[7] - sin45Radius - - dotsYCorArr[0] = dotsYCorArr[0] - this.bigCircleRadius - dotsYCorArr[1] = dotsYCorArr[1] - sin45Radius - dotsYCorArr[3] = dotsYCorArr[3] + sin45Radius - - dotsYCorArr[4] = dotsYCorArr[4] + this.bigCircleRadius - dotsYCorArr[5] = dotsYCorArr[5] + sin45Radius - dotsYCorArr[7] = dotsYCorArr[7] - sin45Radius - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec) - - val calWidth = 2 * this.bigCircleRadius + 2 * radius - val calHeight = calWidth - - setMeasuredDimension(calWidth, calHeight) - } - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - for (i in 0..mNoOfDots - 1) { - canvas.drawCircle(dotsXCorArr[i], dotsYCorArr[i], radius.toFloat(), defaultCirclePaint) - } - } } \ No newline at end of file diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/ThreeDotsBaseView.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/ThreeDotsBaseView.kt index 862260c..a1a2803 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/ThreeDotsBaseView.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/ThreeDotsBaseView.kt @@ -3,11 +3,12 @@ package com.agrawalsuneet.dotsloader.basicviews import android.content.Context import android.util.AttributeSet import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.contracts.AbstractLinearLayout /** * Created by suneet on 12/14/17. */ -abstract class ThreeDotsBaseView : AnimatingLinearLayout { +abstract class ThreeDotsBaseView : AbstractLinearLayout { var firstDotColor: Int = resources.getColor(R.color.loader_defalut) @@ -26,16 +27,12 @@ abstract class ThreeDotsBaseView : AnimatingLinearLayout { this.firstDotColor = firstDotColor this.secondDotColor = secondDotColor this.thirdDotColor = thirdDotColor - initView() } - constructor(context: Context?) : super(context) { - } + constructor(context: Context?) : super(context) - constructor(context: Context?, attrs: AttributeSet) : super(context, attrs) { - } + constructor(context: Context?, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - } + constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/AnimatingLinearLayout.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/AbstractLinearLayout.kt similarity index 54% rename from dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/AnimatingLinearLayout.kt rename to dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/AbstractLinearLayout.kt index 64a537b..710857a 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/AnimatingLinearLayout.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/AbstractLinearLayout.kt @@ -1,4 +1,4 @@ -package com.agrawalsuneet.dotsloader.basicviews +package com.agrawalsuneet.dotsloader.contracts import android.content.Context import android.util.AttributeSet @@ -6,47 +6,30 @@ import android.view.animation.Interpolator import android.view.animation.LinearInterpolator import android.widget.LinearLayout import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.contracts.LoaderContract /** * Created by suneet on 10/10/17. */ -abstract class AnimatingLinearLayout : LinearLayout, LoaderContract { +abstract class AbstractLinearLayout : LinearLayout, LoaderContract { open var animDuration: Int = 500 open var interpolator: Interpolator = LinearInterpolator() var dotsRadius: Int = 30 - get() = field - set(value) { - field = value - initView() - } var dotsDist: Int = 15 - get() = field - set(value) { - field = value - initView() - } var dotsColor: Int = resources.getColor(R.color.loader_defalut) - get() = field - set(value) { - field = value - initView() - } abstract fun initView() - constructor(context: Context?) : super(context) { - } + constructor(context: Context?) : super(context) - constructor(context: Context?, attrs: AttributeSet) : super(context, attrs) { - } + constructor(context: Context?, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - } + constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/CircularAbstractView.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/CircularAbstractView.kt new file mode 100644 index 0000000..8c77a66 --- /dev/null +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/CircularAbstractView.kt @@ -0,0 +1,63 @@ +package com.agrawalsuneet.dotsloader.contracts + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet + +abstract class CircularAbstractView : DotsLoaderBaseView { + + protected val noOfDots = 8 + private val SIN_45 = 0.7071f + + lateinit var dotsYCorArr: FloatArray + + var bigCircleRadius: Int = 60 + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + override fun initCordinates() { + val sin45Radius = SIN_45 * bigCircleRadius + + dotsXCorArr = FloatArray(noOfDots) + dotsYCorArr = FloatArray(noOfDots) + + for (i in 0 until noOfDots) { + dotsYCorArr[i] = (this.bigCircleRadius + radius).toFloat() + dotsXCorArr[i] = dotsYCorArr[i] + } + + dotsXCorArr[1] = dotsXCorArr[1] + sin45Radius + dotsXCorArr[2] = dotsXCorArr[2] + bigCircleRadius + dotsXCorArr[3] = dotsXCorArr[3] + sin45Radius + + dotsXCorArr[5] = dotsXCorArr[5] - sin45Radius + dotsXCorArr[6] = dotsXCorArr[6] - bigCircleRadius + dotsXCorArr[7] = dotsXCorArr[7] - sin45Radius + + dotsYCorArr[0] = dotsYCorArr[0] - bigCircleRadius + dotsYCorArr[1] = dotsYCorArr[1] - sin45Radius + dotsYCorArr[3] = dotsYCorArr[3] + sin45Radius + + dotsYCorArr[4] = dotsYCorArr[4] + this.bigCircleRadius + dotsYCorArr[5] = dotsYCorArr[5] + sin45Radius + dotsYCorArr[7] = dotsYCorArr[7] - sin45Radius + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + + val calWidthHeight = 2 * bigCircleRadius + 2 * radius + setMeasuredDimension(calWidthHeight, calWidthHeight) + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + for (i in 0 until noOfDots) { + canvas.drawCircle(dotsXCorArr[i], dotsYCorArr[i], radius.toFloat(), defaultCirclePaint) + } + } +} \ No newline at end of file diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/DotsLoaderBaseView.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/DotsLoaderBaseView.kt similarity index 86% rename from dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/DotsLoaderBaseView.kt rename to dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/DotsLoaderBaseView.kt index 3078e83..f352d2b 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/DotsLoaderBaseView.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/DotsLoaderBaseView.kt @@ -1,10 +1,11 @@ -package com.agrawalsuneet.dotsloader.basicviews +package com.agrawalsuneet.dotsloader.contracts import android.content.Context import android.graphics.Paint import android.util.AttributeSet import android.view.View import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.contracts.LoaderContract import com.agrawalsuneet.dotsloader.utils.Helper /** @@ -22,7 +23,7 @@ abstract class DotsLoaderBaseView : View, LoaderContract { protected lateinit var firstShadowPaint: Paint protected lateinit var secondShadowPaint: Paint - protected var isShadowColorSet = false + private var isShadowColorSet = false protected var shouldAnimate = true @@ -63,14 +64,14 @@ abstract class DotsLoaderBaseView : View, LoaderContract { //init paints for drawing dots fun initPaints() { defaultCirclePaint = Paint() - defaultCirclePaint!!.isAntiAlias = true - defaultCirclePaint!!.style = Paint.Style.FILL - defaultCirclePaint!!.color = defaultColor + defaultCirclePaint?.isAntiAlias = true + defaultCirclePaint?.style = Paint.Style.FILL + defaultCirclePaint?.color = defaultColor selectedCirclePaint = Paint() - selectedCirclePaint!!.isAntiAlias = true - selectedCirclePaint!!.style = Paint.Style.FILL - selectedCirclePaint!!.color = selectedColor + selectedCirclePaint?.isAntiAlias = true + selectedCirclePaint?.style = Paint.Style.FILL + selectedCirclePaint?.color = selectedColor } //init paints for drawing shadow dots @@ -107,16 +108,14 @@ abstract class DotsLoaderBaseView : View, LoaderContract { var defaultColor: Int = resources.getColor(R.color.loader_defalut) set(defaultColor) { field = defaultColor - if (defaultCirclePaint != null) { - defaultCirclePaint!!.color = defaultColor - } + defaultCirclePaint?.color = defaultColor } open var selectedColor: Int = resources.getColor(R.color.loader_selected) set(selectedColor) { field = selectedColor - if (selectedCirclePaint != null) { - selectedCirclePaint!!.color = selectedColor + selectedCirclePaint?.let { + it.color = selectedColor initShadowPaints() } } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/LoaderContract.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/LoaderContract.kt similarity index 75% rename from dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/LoaderContract.kt rename to dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/LoaderContract.kt index b5ad6de..ae6c9af 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/basicviews/LoaderContract.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/contracts/LoaderContract.kt @@ -1,4 +1,4 @@ -package com.agrawalsuneet.dotsloader.basicviews +package com.agrawalsuneet.dotsloader.contracts import android.util.AttributeSet diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/AllianceLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/AllianceLoader.kt index 26ad3a1..3a04532 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/AllianceLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/AllianceLoader.kt @@ -11,7 +11,7 @@ import android.widget.LinearLayout import android.widget.RelativeLayout import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.basicviews.CircleView -import com.agrawalsuneet.dotsloader.basicviews.LoaderContract +import com.agrawalsuneet.dotsloader.contracts.LoaderContract /** * Created by agrawalsuneet on 9/1/18. @@ -235,11 +235,11 @@ class AllianceLoader : LinearLayout, LoaderContract { nextStep = 0 } - val fromXPos = posArrayList.get(circleCount - 1).get(step).first - val fromYPos = posArrayList.get(circleCount - 1).get(step).second + val fromXPos = posArrayList[circleCount - 1][step].first + val fromYPos = posArrayList[circleCount - 1][step].second - val toXPos = posArrayList.get(circleCount - 1).get(nextStep).first - val toYPos = posArrayList.get(circleCount - 1).get(nextStep).second + val toXPos = posArrayList[circleCount - 1][nextStep].first + val toYPos = posArrayList[circleCount - 1][nextStep].second val transAnim = TranslateAnimation(fromXPos, toXPos, fromYPos, toYPos) transAnim.duration = animDuration.toLong() diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt index f84737a..2b04c49 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt @@ -1,52 +1,88 @@ package com.agrawalsuneet.dotsloader.loaders +import android.app.Activity import android.content.Context import android.graphics.Canvas -import android.os.Handler import android.util.AttributeSet -import com.agrawalsuneet.dotsloader.basicviews.CircularLoaderBaseView +import android.view.View +import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.contracts.CircularAbstractView +import java.util.* /** * Created by ballu on 04/07/17. */ -class CircularDotsLoader : CircularLoaderBaseView { +class CircularDotsLoader : CircularAbstractView { - constructor(context: Context) : super(context) + private var timer: Timer? = null - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + constructor(context: Context) : super(context) { + initCordinates() + initPaints() + initShadowPaints() + } - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + initAttributes(attrs) + initCordinates() + initPaints() + initShadowPaints() + } - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initAttributes(attrs) + initCordinates() + initPaints() + initShadowPaints() + } - drawCircle(canvas) + override fun initAttributes(attrs: AttributeSet) { + super.initAttributes(attrs) - if (shouldAnimate) { - Handler().postDelayed({ - if (System.currentTimeMillis() - logTime >= animDur) { + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularDotsLoader, 0, 0) - selectedDotPos++ + this.bigCircleRadius = typedArray.getDimensionPixelSize(R.styleable.CircularDotsLoader_loader_bigCircleRadius, 60) - if (selectedDotPos > mNoOfDots) { - selectedDotPos = 1 - } + typedArray.recycle() + } - invalidate() - logTime = System.currentTimeMillis() - } - }, animDur.toLong()) + + override fun onVisibilityChanged(changedView: View, visibility: Int) { + super.onVisibilityChanged(changedView, visibility) + + if (visibility != VISIBLE) { + timer?.cancel() + } else if (shouldAnimate) { + scheduleTimer() } } + private fun scheduleTimer() { + timer = Timer() + timer?.scheduleAtFixedRate(object : TimerTask() { + override fun run() { + selectedDotPos++ + + if (selectedDotPos > noOfDots) { + selectedDotPos = 1 + } + + (context as Activity).runOnUiThread { invalidate() } + } + }, 0, animDur.toLong()) + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + drawCircle(canvas) + } + private fun drawCircle(canvas: Canvas) { val firstShadowPos = if (selectedDotPos == 1) 8 else selectedDotPos - 1 val secondShadowPos = if (firstShadowPos == 1) 8 else firstShadowPos - 1 - for (i in 0..mNoOfDots - 1) { - //boolean isSelected = (i + 1 == selectedDotPos); - //canvas.drawCircle(dotsXCorArr[i], dotsYCorArr[i], radius, isSelected ? selectedCirclePaint : defaultCirclePaint); + for (i in 0 until noOfDots) { if (i + 1 == selectedDotPos) { canvas.drawCircle(dotsXCorArr[i], dotsYCorArr[i], radius.toFloat(), selectedCirclePaint) diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LazyLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LazyLoader.kt index 803071c..2f730de 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LazyLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LazyLoader.kt @@ -24,7 +24,9 @@ class LazyLoader : ThreeDotsBaseView { constructor(context: Context, dotsRadius: Int, dotsDist: Int, firstDotColor: Int, secondDotColor: Int, thirdDotColor: Int) - : super(context, dotsRadius, dotsDist, firstDotColor, secondDotColor, thirdDotColor) + : super(context, dotsRadius, dotsDist, firstDotColor, secondDotColor, thirdDotColor){ + initView() + } constructor(context: Context?) : super(context) { initView() diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LightsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LightsLoader.kt new file mode 100644 index 0000000..ba2ac30 --- /dev/null +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LightsLoader.kt @@ -0,0 +1,153 @@ +package com.agrawalsuneet.dotsloader.loaders + +import android.content.Context +import android.util.AttributeSet +import android.util.Range +import android.view.ViewTreeObserver +import android.view.animation.AlphaAnimation +import android.view.animation.Animation +import android.view.animation.AnimationUtils +import android.widget.LinearLayout +import com.agrawalsuneet.dotsloader.R +import com.agrawalsuneet.dotsloader.basicviews.CircleView +import com.agrawalsuneet.dotsloader.contracts.LoaderContract +import com.agrawalsuneet.dotsloader.utils.random +import java.util.ArrayList + +class LightsLoader : LinearLayout, LoaderContract { + + var noOfCircles: Int = 3 + set(value) { + field = if (value < 1) 1 else value + } + + var circleRadius: Int = 30 + var circleDistance: Int = 10 + + var circleColor: Int = resources.getColor(android.R.color.holo_purple) + + private var calWidthHeight: Int = 0 + + private lateinit var circlesList: ArrayList + + + constructor(context: Context) : super(context) { + initView() + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + initAttributes(attrs) + initView() + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initAttributes(attrs) + initView() + } + + constructor(context: Context, noOfCircles: Int, circleRadius: Int, circleDistance: Int, circleColor: Int) : super(context) { + this.noOfCircles = noOfCircles + this.circleRadius = circleRadius + this.circleDistance = circleDistance + this.circleColor = circleColor + + initView() + } + + override fun initAttributes(attrs: AttributeSet) { + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.LightsLoader, 0, 0) + + noOfCircles = typedArray.getInteger(R.styleable.LightsLoader_lights_noOfCircles, 3) + + circleRadius = typedArray.getDimensionPixelSize(R.styleable.LightsLoader_lights_circleRadius, 30) + circleDistance = typedArray.getDimensionPixelSize(R.styleable.LightsLoader_lights_circleDistance, 10) + + circleColor = typedArray.getColor(R.styleable.LightsLoader_lights_circleColor, + resources.getColor(android.R.color.holo_purple)) + + typedArray.recycle() + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + + if (calWidthHeight == 0) { + calWidthHeight = (2 * circleRadius * noOfCircles) + ((noOfCircles - 1) * circleDistance) + } + + setMeasuredDimension(calWidthHeight, calWidthHeight) + } + + + private fun initView() { + removeAllViews() + removeAllViewsInLayout() + + orientation = LinearLayout.VERTICAL + + circlesList = ArrayList() + + if (calWidthHeight == 0) { + calWidthHeight = (2 * circleRadius * noOfCircles) + ((noOfCircles - 1) * circleDistance) + } + + for (countI in 0 until noOfCircles) { + val linearLayout = LinearLayout(context) + linearLayout.orientation = LinearLayout.HORIZONTAL + val params = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT) + + if (countI != 0) { + params.topMargin = circleDistance + } + + linearLayout.layoutParams = params + + for (countJ in 0 until noOfCircles) { + val circleView = CircleView(context, circleRadius, circleColor) + + val innerParam = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT) + + if (countJ != 0) { + innerParam.leftMargin = circleDistance + } + + linearLayout.addView(circleView, innerParam) + circlesList.add(circleView) + } + + addView(linearLayout) + } + + viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + startLoading() + this@LightsLoader.viewTreeObserver.removeOnGlobalLayoutListener(this) + } + }) + } + + private fun startLoading() { + for (count in 0 until noOfCircles) { + for (item in circlesList) { + item.startAnimation(getAlphaAnimation()) + } + } + } + + private fun getAlphaAnimation(): Animation { + val fromAplha = (0.5f..1.0f).random() + val toAplha = (0.1f..0.5f).random() + + val alphaAnim = AlphaAnimation(fromAplha, toAplha) + .apply { + duration = (100..1000).random().toLong() + repeatMode = Animation.REVERSE + repeatCount = Animation.INFINITE + } + + return alphaAnim + } +} + diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt index f6f7d4d..bef4cc6 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt @@ -1,11 +1,13 @@ package com.agrawalsuneet.dotsloader.loaders +import android.app.Activity import android.content.Context import android.graphics.Canvas -import android.os.Handler import android.util.AttributeSet +import android.view.View import com.agrawalsuneet.dotsloader.R -import com.agrawalsuneet.dotsloader.basicviews.DotsLoaderBaseView +import com.agrawalsuneet.dotsloader.contracts.DotsLoaderBaseView +import java.util.* /** * Created by ballu on 04/07/17. @@ -13,6 +15,8 @@ import com.agrawalsuneet.dotsloader.basicviews.DotsLoaderBaseView class LinearDotsLoader : DotsLoaderBaseView { + private var timer: Timer? = null + var isSingleDir = true private var diffRadius: Int = 0 @@ -38,9 +42,11 @@ class LinearDotsLoader : DotsLoaderBaseView { } override fun initAttributes(attrs: AttributeSet) { + super.initAttributes(attrs) val typedArray = context.obtainStyledAttributes(attrs, R.styleable.LinearDotsLoader, 0, 0) + this.noOfDots = typedArray.getInt(R.styleable.LinearDotsLoader_loader_noOfDots, 3) this.selRadius = typedArray.getDimensionPixelSize(R.styleable.LinearDotsLoader_loader_selectedRadius, radius + 10) @@ -59,7 +65,7 @@ class LinearDotsLoader : DotsLoaderBaseView { dotsXCorArr = FloatArray(this.noOfDots) //init X cordinates for all dots - for (i in 0..this.noOfDots - 1) { + for (i in 0 until noOfDots) { dotsXCorArr[i] = (i * dotsDistance + (i * 2 + 1) * radius).toFloat() } } @@ -80,43 +86,52 @@ class LinearDotsLoader : DotsLoaderBaseView { setMeasuredDimension(calWidth, calHeight) } + override fun onVisibilityChanged(changedView: View, visibility: Int) { + super.onVisibilityChanged(changedView, visibility) - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - drawCircle(canvas) - - if (shouldAnimate) { - Handler().postDelayed({ - if (System.currentTimeMillis() - logTime >= animDur) { + if (visibility != VISIBLE) { + timer?.cancel() + } else if (shouldAnimate) { + scheduleTimer() + } + } - if (isSingleDir) { + private fun scheduleTimer() { + timer = Timer() + timer?.scheduleAtFixedRate(object : TimerTask() { + override fun run() { + if (isSingleDir) { + selectedDotPos++ + if (selectedDotPos > noOfDots) { + selectedDotPos = 1 + } + } else { + if (isFwdDir) { selectedDotPos++ - if (selectedDotPos > noOfDots) { - selectedDotPos = 1 + if (selectedDotPos == noOfDots) { + isFwdDir = !isFwdDir } } else { - if (isFwdDir) { - selectedDotPos++ - if (selectedDotPos == noOfDots) { - isFwdDir = !isFwdDir - } - } else { - selectedDotPos-- - if (selectedDotPos == 1) { - isFwdDir = !isFwdDir - } + selectedDotPos-- + if (selectedDotPos == 1) { + isFwdDir = !isFwdDir } } - - invalidate() - logTime = System.currentTimeMillis() } - }, animDur.toLong()) - } + + (context as Activity).runOnUiThread { invalidate() } + } + }, 0, animDur.toLong()) + } + + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + drawCircle(canvas) } private fun drawCircle(canvas: Canvas) { - for (i in 0..this.noOfDots - 1) { + for (i in 0 until noOfDots) { var xCor = dotsXCorArr[i] if (expandOnSelect) { @@ -168,28 +183,24 @@ class LinearDotsLoader : DotsLoaderBaseView { } var dotsDistance: Int = 15 - get() = field set(value) { field = value initCordinates() } var noOfDots: Int = 3 - get() = field set(noOfDots) { field = noOfDots initCordinates() } var selRadius: Int = 38 - get() = field set(selRadius) { field = selRadius initCordinates() } var expandOnSelect: Boolean = false - get() = field set(expandOnSelect) { field = expandOnSelect initCordinates() diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/RotatingCircularDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/RotatingCircularDotsLoader.kt index 3ee4183..dc7f520 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/RotatingCircularDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/RotatingCircularDotsLoader.kt @@ -9,7 +9,7 @@ import android.view.animation.RotateAnimation import android.widget.LinearLayout import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.basicviews.CircularLoaderBaseView -import com.agrawalsuneet.dotsloader.basicviews.LoaderContract +import com.agrawalsuneet.dotsloader.contracts.LoaderContract /** * Created by suneet on 12/29/17. diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/SlidingLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/SlidingLoader.kt index 6bfa381..7d56273 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/SlidingLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/SlidingLoader.kt @@ -38,7 +38,9 @@ class SlidingLoader : ThreeDotsBaseView { constructor(context: Context, dotsRadius: Int, dotsDist: Int, firstDotColor: Int, secondDotColor: Int, thirdDotColor: Int) - : super(context, dotsRadius, dotsDist, firstDotColor, secondDotColor, thirdDotColor) + : super(context, dotsRadius, dotsDist, firstDotColor, secondDotColor, thirdDotColor) { + initView() + } constructor(context: Context?) : super(context) { initView() diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TashieLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TashieLoader.kt index c909ad9..a626335 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TashieLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TashieLoader.kt @@ -11,13 +11,13 @@ import android.view.animation.AnimationUtils import android.view.animation.ScaleAnimation import android.widget.LinearLayout import com.agrawalsuneet.dotsloader.R -import com.agrawalsuneet.dotsloader.basicviews.AnimatingLinearLayout import com.agrawalsuneet.dotsloader.basicviews.CircleView +import com.agrawalsuneet.dotsloader.contracts.AbstractLinearLayout /** * Created by suneet on 10/10/17. */ -class TashieLoader : AnimatingLinearLayout { +class TashieLoader : AbstractLinearLayout { var noOfDots: Int = 8 var animDelay: Int = 100 @@ -40,6 +40,16 @@ class TashieLoader : AnimatingLinearLayout { initView() } + constructor(context: Context?, noOfDots: Int, dotsRadius: Int, dotsDist: Int, dotsColor: Int) : super(context) { + this.noOfDots = noOfDots + this.dotsRadius = dotsRadius + this.dotsDist = dotsDist + this.dotsColor = dotsColor + + initView() + } + + override fun initAttributes(attrs: AttributeSet) { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TashieLoader, 0, 0) @@ -79,7 +89,7 @@ class TashieLoader : AnimatingLinearLayout { for (iCount in 0 until noOfDots) { val circle = CircleView(context, dotsRadius, dotsColor) - var params = LinearLayout.LayoutParams(2 * dotsRadius, 2 * dotsRadius) + val params = LinearLayout.LayoutParams(2 * dotsRadius, 2 * dotsRadius) if (iCount != noOfDots - 1) { params.rightMargin = dotsDist @@ -89,14 +99,10 @@ class TashieLoader : AnimatingLinearLayout { dotsArray[iCount] = circle } - val loaderView = this - viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { + this@TashieLoader.viewTreeObserver.removeOnGlobalLayoutListener(this) startLoading() - - val vto = loaderView.viewTreeObserver - vto.removeOnGlobalLayoutListener(this) } }) } @@ -104,7 +110,7 @@ class TashieLoader : AnimatingLinearLayout { private fun startLoading() { for (iCount in 0 until noOfDots) { - var anim = getScaleAnimation(isDotsExpanding, iCount) + val anim = getScaleAnimation(isDotsExpanding, iCount) dotsArray[iCount]!!.startAnimation(anim) setAnimationListener(anim, iCount) @@ -113,18 +119,16 @@ class TashieLoader : AnimatingLinearLayout { } private fun getScaleAnimation(isExpanding: Boolean, delay: Int): AnimationSet { - var anim = AnimationSet(true); - - var scaleAnim: ScaleAnimation + val anim = AnimationSet(true) - when (isExpanding) { + val scaleAnim: ScaleAnimation = when (isExpanding) { true -> { - scaleAnim = ScaleAnimation(0f, 1f, 0f, 1f, + ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f) } false -> { - scaleAnim = ScaleAnimation(1f, 0f, 1f, 0f, + ScaleAnimation(1f, 0f, 1f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f) } } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TrailingCircularDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TrailingCircularDotsLoader.kt index f58e277..d23dc6c 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TrailingCircularDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/TrailingCircularDotsLoader.kt @@ -10,7 +10,7 @@ import android.widget.LinearLayout import android.widget.RelativeLayout import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.basicviews.CircleView -import com.agrawalsuneet.dotsloader.basicviews.LoaderContract +import com.agrawalsuneet.dotsloader.contracts.LoaderContract class TrailingCircularDotsLoader : LinearLayout, LoaderContract { diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/ZeeLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/ZeeLoader.kt index 2df8d79..002c7ab 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/ZeeLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/ZeeLoader.kt @@ -11,7 +11,7 @@ import android.widget.LinearLayout import android.widget.RelativeLayout import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.basicviews.CircleView -import com.agrawalsuneet.dotsloader.basicviews.LoaderContract +import com.agrawalsuneet.dotsloader.contracts.LoaderContract /** * Created by agrawalsuneet on 8/26/18. @@ -125,15 +125,10 @@ class ZeeLoader : LinearLayout, LoaderContract { this.addView(relativeLayout, relParam) - val loaderView = this - - viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { startLoading() - - val vto = loaderView.viewTreeObserver - vto.removeOnGlobalLayoutListener(this) + this@ZeeLoader.viewTreeObserver.removeOnGlobalLayoutListener(this) } }) } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Helper.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Helper.kt index 246ebc8..74618ce 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Helper.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Helper.kt @@ -1,6 +1,7 @@ package com.agrawalsuneet.dotsloader.utils import android.graphics.Color +import java.util.* /** * Created by suneet on 17/7/17. @@ -17,3 +18,9 @@ object Helper { } } +fun ClosedFloatingPointRange.random() = + (Random().nextFloat() * (endInclusive - start)) + start + +fun ClosedRange.random() = + Random().nextInt((endInclusive + 1) - start) + start + diff --git a/dotsloader/src/main/res/values/attrs.xml b/dotsloader/src/main/res/values/attrs.xml index 5e41bd0..852a957 100644 --- a/dotsloader/src/main/res/values/attrs.xml +++ b/dotsloader/src/main/res/values/attrs.xml @@ -11,6 +11,10 @@ + + + + @@ -19,9 +23,6 @@ - - - @@ -99,4 +100,11 @@ + + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7825e8c..7d698f3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Aug 31 23:56:41 BST 2018 +#Tue Dec 18 08:21:33 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip