├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── nikitagordia │ │ │ └── cosinloading │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── nikitagordia │ │ │ └── cosinloading │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── nikitagordia │ │ └── cosinloading │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── cosin ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── nikitagordia │ │ │ └── cosin │ │ │ ├── textAdapters │ │ │ ├── WordTextAdapter.java │ │ │ └── DefaultBinaryTextAdapter.java │ │ │ ├── colorAdapters │ │ │ ├── ColorAdapterBG.java │ │ │ ├── ColorAdapterBR.java │ │ │ ├── ColorAdapterGR.java │ │ │ ├── ColorAdapterRB.java │ │ │ ├── ColorAdapterRG.java │ │ │ └── DefaultColorAdapterGB.java │ │ │ └── Cosin.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── nikitagordia │ │ │ └── cosin │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── nikitagordia │ │ └── cosin │ │ └── ExampleInstrumentedTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── github ├── 1.gif ├── 1.png ├── 2.gif ├── 2.png ├── 3.gif ├── 3.png ├── 4.gif ├── 4.png ├── 5.png ├── 6.png ├── main.gif └── main.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .idea ├── vcs.xml ├── runConfigurations.xml ├── gradle.xml ├── modules.xml └── misc.xml ├── gradle.properties ├── LICENSE ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /cosin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':cosin' 2 | -------------------------------------------------------------------------------- /github/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/1.gif -------------------------------------------------------------------------------- /github/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/1.png -------------------------------------------------------------------------------- /github/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/2.gif -------------------------------------------------------------------------------- /github/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/2.png -------------------------------------------------------------------------------- /github/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/3.gif -------------------------------------------------------------------------------- /github/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/3.png -------------------------------------------------------------------------------- /github/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/4.gif -------------------------------------------------------------------------------- /github/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/4.png -------------------------------------------------------------------------------- /github/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/5.png -------------------------------------------------------------------------------- /github/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/6.png -------------------------------------------------------------------------------- /github/main.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/main.gif -------------------------------------------------------------------------------- /github/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/github/main.png -------------------------------------------------------------------------------- /cosin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Cosin 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CosinLoading 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /cosin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mykytahordia/Cosin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 02 15:37:47 EET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #ececec 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /cosin/src/test/java/com/nikitagordia/cosin/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/nikitagordia/cosinloading/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosinloading; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /cosin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 13 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | } 28 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/textAdapters/WordTextAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.textAdapters; 2 | 3 | import com.nikitagordia.cosin.Cosin; 4 | 5 | /** 6 | * Created by nikitagordia on 05.03.18. 7 | */ 8 | 9 | public class WordTextAdapter implements Cosin.TextAdapter { 10 | 11 | private String word; 12 | 13 | public WordTextAdapter(String word) { 14 | this.word = word; 15 | } 16 | 17 | @Override 18 | public char getString(int numOfRect) { 19 | if (word.isEmpty()) return ' '; 20 | return word.charAt(numOfRect % word.length()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/ColorAdapterBG.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class ColorAdapterBG implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, 0, (int)(255 * (1d - percentOfHeight)), (int)(255 * percentOfHeight)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/ColorAdapterBR.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class ColorAdapterBR implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, (int)(255 * (1d - percentOfHeight)), 0, (int)(255 * percentOfHeight)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/ColorAdapterGR.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class ColorAdapterGR implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, (int)(255 * (1d - percentOfHeight)), (int)(255 * percentOfHeight), 0); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/ColorAdapterRB.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class ColorAdapterRB implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, (int)(255 * percentOfHeight), 0, (int)(255 * (1d - percentOfHeight))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/ColorAdapterRG.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class ColorAdapterRG implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, (int)(255 * percentOfHeight), (int)(255 * (1d - percentOfHeight)), 0); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/colorAdapters/DefaultColorAdapterGB.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.colorAdapters; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.nikitagordia.cosin.Cosin; 6 | 7 | /** 8 | * Created by nikitagordia on 05.03.18. 9 | */ 10 | 11 | public class DefaultColorAdapterGB implements Cosin.ColorAdapter { 12 | 13 | @Override 14 | public int getBackgroundColor() { 15 | return Color.TRANSPARENT; 16 | } 17 | 18 | @Override 19 | public int calcColor(int numOfRect, double percentOfHeight) { 20 | return Color.argb(150, 0, (int)(255 * percentOfHeight), (int)(255 * (1d - percentOfHeight))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/textAdapters/DefaultBinaryTextAdapter.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin.textAdapters; 2 | 3 | import com.nikitagordia.cosin.Cosin; 4 | 5 | import java.util.Date; 6 | import java.util.Random; 7 | 8 | /** 9 | * Created by nikitagordia on 05.03.18. 10 | */ 11 | 12 | public class DefaultBinaryTextAdapter implements Cosin.TextAdapter { 13 | 14 | private static final char ZERO = '0'; 15 | private static final char ONE = '1'; 16 | 17 | private Random random; 18 | 19 | public DefaultBinaryTextAdapter() { 20 | random = new Random(new Date().getTime()); 21 | } 22 | 23 | @Override 24 | public char getString(int numOfRect) { 25 | if (random.nextBoolean()) return ONE; else return ZERO; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /cosin/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /cosin/src/androidTest/java/com/nikitagordia/cosin/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.nikitagordia.cosin.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/nikitagordia/cosinloading/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosinloading; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.nikitagordia.cosinloading", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.nikitagordia.cosinloading" 7 | minSdkVersion 16 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | dataBinding { 20 | enabled = true 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation fileTree(include: ['*.jar'], dir: 'libs') 26 | compile project(':cosin'); 27 | implementation 'com.android.support:appcompat-v7:27.0.2' 28 | implementation 'com.android.support:cardview-v7:27.0.2' 29 | implementation 'com.android.support:design:27.0.2' 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 NikitaGordia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

COSIN

3 |

Loading android view lib

4 |

5 | 6 | 7 |

8 | 9 |

10 | 11 | 12 | 13 |

14 |

15 | 16 | 17 | 18 |

19 | 20 | # Gradle : 21 | 22 | build.gradle (Project) 23 | ```groovy 24 | allprojects { 25 | repositories { 26 | ... 27 | maven { url 'https://jitpack.io' } 28 | } 29 | } 30 | ``` 31 | 32 | build.gradle (Module) 33 | ```groovy 34 | implementation 'com.github.NikitaGordia:Cosin:1.1.0' 35 | ``` 36 | 37 | # Quick start guide 38 | 39 | ## Declaration 40 | 41 | ```xml 42 | 45 | ``` 46 | 47 | ## Properties 48 | 49 | | Property | Description | 50 | | --------------------------------------|-----------------------------------------------------------------------------------------------------------| 51 | | speed | Angle speed | 52 | | isLoading | If 'true' shows symbols on rectangle | 53 | | setEnd | Shows end animation (optionally you may pass onEnd(OnEnd)) 54 | | rectWidth | Width each of rectangle | 55 | | period | Determine period of cosinusoidal function | 56 | | colorAdapter | Define color changes by two parameters (position count, height percent) for each rectagle | 57 | | offset | Moving bottom offset | 58 | | directionRight | Determine movement side | 59 | | textAdapter | Define text changes by position count for each rectangle | 60 | 61 | ## There are 6 default ColorAdapter implementation in box : 62 | 63 | * DefaultColorAdapterGB (Green -> Blue) 64 | * ColorAdapterBG (Blue -> Green) 65 | * ColorAdapterBR (Blue -> Red) 66 | * ColorAdapterGR (Green -> Blue) 67 | * ColorAdapterRB (Red -> Blue) 68 | * ColorAdapterRG (Red -> Green) 69 | * ColorAdapterBG (Blue -> Green) 70 | 71 | 72 | ## There are 2 default TextAdapter implementation in box : 73 | 74 | * DefaultBinaryTextAdapter (shows random [0, 1] symbols in each rectagle) 75 | * WordTextAdapter (shows specified cycle String) 76 | 77 | 78 | #### ColorAdapter overriding example : 79 | ```java 80 | public class ColorAdapterBR implements Cosin.ColorAdapter { 81 | 82 | @Override 83 | public int getBackgroundColor() { 84 | return Color.TRANSPARENT; 85 | } 86 | 87 | @Override 88 | public int calcColor(int numOfRect, double percentOfHeight) { 89 | return Color.argb(150, (int)(255 * (1d - percentOfHeight)), 0, (int)(255 * percentOfHeight)); 90 | } 91 | } 92 | ``` 93 | 94 | #### TextAdapter overriding example : 95 | ```java 96 | public class WordTextAdapter implements Cosin.TextAdapter { 97 | 98 | private String word; 99 | 100 | public WordTextAdapter(String word) { 101 | this.word = word; 102 | } 103 | 104 | @Override 105 | public char getString(int numOfRect) { 106 | if (word.isEmpty()) return ' '; 107 | return word.charAt(numOfRect % word.length()); 108 | } 109 | } 110 | ``` 111 | 112 | #### A bit more gifs 113 |

114 | 115 | 116 | 117 | 118 |

-------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /cosin/src/main/java/com/nikitagordia/cosin/Cosin.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosin; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Typeface; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | import com.nikitagordia.cosin.colorAdapters.DefaultColorAdapterGB; 12 | import com.nikitagordia.cosin.textAdapters.DefaultBinaryTextAdapter; 13 | 14 | 15 | /** 16 | * Created by nikitagordia on 04.03.18. 17 | */ 18 | 19 | public class Cosin extends View { 20 | 21 | private static final double DOUBLE_PI = Math.PI * 2d; 22 | 23 | private ColorAdapter colorAdapter; 24 | private TextAdapter textAdapter; 25 | private OnEnd callback; 26 | 27 | private int count, alphaText; 28 | private double angle, part, intervalRad, heightMid, endingPart; 29 | private Paint paint, paintBack, paintText; 30 | private double[] cosBuff; 31 | private char[] textBuff; 32 | private float[] widthBuff; 33 | private float[] peekBuff; 34 | private long tm; 35 | 36 | private int rectWidth = 60; 37 | private double period = Math.PI; 38 | private double speed = 0.005d; 39 | private double offset = 1.5d; 40 | private double endingSpeed = 0.0008d; 41 | private boolean directionRight = false; 42 | 43 | public Limit limRectWidth = new Limit(5, 100); 44 | public Limit limPeriod = new Limit(0d, Math.PI * 10); 45 | public Limit limSpeed = new Limit(0.0001d, 0.05d); 46 | public Limit limLayoutWidth= new Limit(0, 1000); 47 | public Limit limLayoutHeight = new Limit(0, 1000); 48 | public Limit limOffset = new Limit(0d, 10d); 49 | 50 | private boolean isLoadingData; 51 | private boolean isEnding; 52 | 53 | public Cosin(Context context, AttributeSet attributesSet) { 54 | super(context, attributesSet); 55 | angle = 0; 56 | endingPart = 1d; 57 | isEnding = false; 58 | paint = new Paint(); 59 | paintBack = new Paint(); 60 | paintText = new Paint(); 61 | paintText.setTextSize(rectWidth / 2); 62 | paintText.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); 63 | paintBack.setColor(Color.argb(255, 255, 255, 255)); 64 | paint.setColor(Color.GREEN); 65 | colorAdapter = new DefaultColorAdapterGB(); 66 | textAdapter = new DefaultBinaryTextAdapter(); 67 | } 68 | 69 | @Override 70 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 71 | super.onSizeChanged(w, h, oldw, oldh); 72 | updateProp(); 73 | } 74 | 75 | private void updateProp() { 76 | 77 | paintText.setTextSize(rectWidth / 2); 78 | count = getWidth() / rectWidth; 79 | intervalRad = period / count; 80 | heightMid = getHeight() / 2d; 81 | 82 | cosBuff = new double[count]; 83 | textBuff = new char[count]; 84 | widthBuff = new float[count]; 85 | peekBuff = new float[count + 1]; 86 | 87 | for (int i = 0; i <= count; i++) 88 | peekBuff[i] = rectWidth * i; 89 | 90 | for (int i = 0; i < count; i++) { 91 | cosBuff[i] = (intervalRad * i + intervalRad * (i + 1)) / 2d; 92 | 93 | updateText(i); 94 | 95 | widthBuff[i] = peekBuff[i] + rectWidth / 2f - paintText.measureText(textBuff[i] + "") / 2f; 96 | } 97 | 98 | } 99 | 100 | private void updateText(int pos) { 101 | textBuff[pos] = textAdapter.getString(pos); 102 | } 103 | 104 | @Override 105 | protected void onDraw(Canvas canvas) { 106 | super.onDraw(canvas); 107 | 108 | canvas.drawColor(colorAdapter.getBackgroundColor()); 109 | 110 | if (!directionRight) angle += ((double)System.currentTimeMillis() - tm) * speed; 111 | else angle -= ((double)System.currentTimeMillis() - tm) * speed; 112 | if (angle > DOUBLE_PI) angle -= DOUBLE_PI; 113 | if (angle < -DOUBLE_PI) angle += DOUBLE_PI; 114 | 115 | if (isEnding) { 116 | endingPart -= ((double)System.currentTimeMillis() - tm) * endingSpeed; 117 | if (endingPart < 0 && callback != null) callback.onEnd(); 118 | } 119 | 120 | tm = System.currentTimeMillis(); 121 | 122 | for (int i = 0; i < count; i++) { 123 | part = (Math.cos(cosBuff[i] + angle) + offset) / (offset + 1d); 124 | paint.setColor(colorAdapter.calcColor(i, part)); 125 | canvas.drawRect(peekBuff[i], (float)(getHeight() * (1d - part * endingPart)), peekBuff[i + 1], getHeight(), paint); 126 | if (isLoadingData) { 127 | alphaText = (int)(Math.max(0, 1000d * part - 750d)); 128 | paintText.setColor(Color.argb(alphaText, 255, 255, 255)); 129 | if (alphaText == 0) updateText(i); 130 | canvas.drawText(textBuff[i] + "", widthBuff[i], (float) heightMid, paintText); 131 | } 132 | } 133 | invalidate(); 134 | } 135 | 136 | public void setEnd(OnEnd callback) { 137 | isEnding = true; 138 | this.callback = callback; 139 | } 140 | 141 | public void setEnd() { 142 | isEnding = true; 143 | } 144 | 145 | public double getSpeed() { 146 | return speed; 147 | } 148 | 149 | public void setSpeed(double speed) { 150 | if (!limSpeed.inLimit(speed)) throw new IndexOutOfBoundsException(speed + " not in limit " + limSpeed); 151 | this.speed = speed; 152 | updateProp(); 153 | } 154 | 155 | public boolean isLoadingData() { 156 | return isLoadingData; 157 | } 158 | 159 | public void setLoadingData(boolean loadingData) { 160 | isLoadingData = loadingData; 161 | updateProp(); 162 | } 163 | 164 | public int getRectWidth() { 165 | return rectWidth; 166 | } 167 | 168 | public void setRectWidth(int rectWidth) { 169 | if (!limRectWidth.inLimit(rectWidth)) throw new IndexOutOfBoundsException(rectWidth + " not in limit " + limRectWidth); 170 | this.rectWidth = rectWidth; 171 | updateProp(); 172 | } 173 | 174 | public double getPeriod() { 175 | return period; 176 | } 177 | 178 | public void setPeriod(double period) { 179 | if (!limPeriod.inLimit(period)) throw new IndexOutOfBoundsException(period + " not in limit " + limPeriod); 180 | this.period = period; 181 | updateProp(); 182 | } 183 | 184 | public int getViewWidth() { 185 | return getLayoutParams().width; 186 | } 187 | 188 | public void setLayoutWidth(int width) { 189 | if (!limLayoutWidth.inLimit(width)) throw new IndexOutOfBoundsException(width + " not in limit " + limLayoutWidth); 190 | getLayoutParams().width = width; 191 | requestLayout(); 192 | updateProp(); 193 | } 194 | 195 | public int getViewHeight() { 196 | return getLayoutParams().height; 197 | } 198 | 199 | public void setLayoutHeight(int height) { 200 | if (!limLayoutHeight.inLimit(height)) throw new IndexOutOfBoundsException(height + " not in limit " + limLayoutHeight); 201 | getLayoutParams().height = height; 202 | requestLayout(); 203 | updateProp(); 204 | } 205 | 206 | public ColorAdapter getColorAdapter() { 207 | return colorAdapter; 208 | } 209 | 210 | public void setColorAdapter(ColorAdapter colorAdapter) { 211 | this.colorAdapter = colorAdapter; 212 | requestLayout(); 213 | updateProp(); 214 | } 215 | 216 | public double getOffset() { 217 | return offset; 218 | } 219 | 220 | public TextAdapter getTextAdapter() { 221 | return textAdapter; 222 | } 223 | 224 | public void setTextAdapter(TextAdapter textAdapter) { 225 | this.textAdapter = textAdapter; 226 | } 227 | 228 | public void setOffset(double offset) { 229 | this.offset = offset; 230 | updateProp(); 231 | } 232 | 233 | public boolean isDirectionRight() { 234 | return directionRight; 235 | } 236 | 237 | public void setDirectionRight(boolean directionRight) { 238 | this.directionRight = directionRight; 239 | } 240 | 241 | public class Limit> { 242 | public T min, max; 243 | 244 | public Limit(T min, T max) { 245 | this.min = min; 246 | this.max = max; 247 | } 248 | 249 | public boolean inLimit(T t) { 250 | return min.compareTo(t) < 1 && max.compareTo(t) > -1; 251 | } 252 | 253 | @Override 254 | public String toString() { 255 | return "[" + min + ", " + max + "]"; 256 | } 257 | } 258 | 259 | public interface OnEnd { 260 | void onEnd(); 261 | } 262 | 263 | public interface ColorAdapter { 264 | 265 | int getBackgroundColor(); 266 | 267 | int calcColor(int numOfRect, double percentOfHeight); 268 | 269 | } 270 | 271 | public interface TextAdapter { 272 | 273 | char getString(int numOfRect); 274 | 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /app/src/main/java/com/nikitagordia/cosinloading/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.nikitagordia.cosinloading; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.text.Editable; 7 | import android.text.TextWatcher; 8 | import android.view.View; 9 | import android.widget.CompoundButton; 10 | import android.widget.RadioGroup; 11 | import android.widget.SeekBar; 12 | import com.nikitagordia.cosin.Cosin; 13 | 14 | import com.nikitagordia.cosin.colorAdapters.ColorAdapterBG; 15 | import com.nikitagordia.cosin.colorAdapters.ColorAdapterBR; 16 | import com.nikitagordia.cosin.colorAdapters.ColorAdapterGR; 17 | import com.nikitagordia.cosin.colorAdapters.ColorAdapterRB; 18 | import com.nikitagordia.cosin.colorAdapters.ColorAdapterRG; 19 | import com.nikitagordia.cosin.colorAdapters.DefaultColorAdapterGB; 20 | import com.nikitagordia.cosin.textAdapters.DefaultBinaryTextAdapter; 21 | import com.nikitagordia.cosin.textAdapters.WordTextAdapter; 22 | import com.nikitagordia.cosinloading.databinding.ActivityMainBinding; 23 | 24 | 25 | public class MainActivity extends AppCompatActivity { 26 | 27 | private ActivityMainBinding bind; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | bind = DataBindingUtil.setContentView(this, R.layout.activity_main); 33 | 34 | loadView(); 35 | } 36 | 37 | private void loadView() { 38 | 39 | bind.isLoading.setChecked(bind.cosin.isLoadingData()); 40 | bind.isLoading.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 41 | @Override 42 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 43 | bind.cosin.setLoadingData(isChecked); 44 | } 45 | }); 46 | 47 | bind.tvRectWidth.setText(partRev(bind.cosin.getRectWidth(), bind.cosin.limRectWidth) + ""); 48 | bind.rectWidth.setProgress(partRev(bind.cosin.getRectWidth(), bind.cosin.limRectWidth)); 49 | bind.rectWidth.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 50 | @Override 51 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 52 | bind.cosin.setRectWidth(part(progress, bind.cosin.limRectWidth)); 53 | bind.tvRectWidth.setText(part(progress, bind.cosin.limRectWidth) + ""); 54 | } 55 | 56 | @Override 57 | public void onStartTrackingTouch(SeekBar seekBar) { 58 | 59 | } 60 | 61 | @Override 62 | public void onStopTrackingTouch(SeekBar seekBar) { 63 | 64 | } 65 | }); 66 | 67 | bind.tvViewWidth.setText(partRev(bind.cosin.getViewWidth(), bind.cosin.limLayoutWidth) + ""); 68 | bind.viewWidth.setProgress(partRev(bind.cosin.getViewWidth(), bind.cosin.limLayoutWidth)); 69 | bind.viewWidth.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 70 | @Override 71 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 72 | bind.cosin.setLayoutWidth(part(progress, bind.cosin.limLayoutWidth)); 73 | bind.tvViewWidth.setText(part(progress, bind.cosin.limLayoutWidth) + ""); 74 | } 75 | 76 | @Override 77 | public void onStartTrackingTouch(SeekBar seekBar) { 78 | 79 | } 80 | 81 | @Override 82 | public void onStopTrackingTouch(SeekBar seekBar) { 83 | 84 | } 85 | }); 86 | 87 | bind.tvViewHeight.setText(partRev(bind.cosin.getViewHeight(), bind.cosin.limLayoutHeight) + ""); 88 | bind.viewHeight.setProgress(partRev(bind.cosin.getViewHeight(), bind.cosin.limLayoutHeight)); 89 | bind.viewHeight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 90 | @Override 91 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 92 | bind.cosin.setLayoutHeight(part(progress, bind.cosin.limLayoutHeight)); 93 | bind.tvViewHeight.setText(part(progress, bind.cosin.limLayoutHeight) + ""); 94 | } 95 | 96 | @Override 97 | public void onStartTrackingTouch(SeekBar seekBar) { 98 | 99 | } 100 | 101 | @Override 102 | public void onStopTrackingTouch(SeekBar seekBar) { 103 | 104 | } 105 | }); 106 | 107 | bind.period.check(R.id.p1); 108 | bind.period.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 109 | @Override 110 | public void onCheckedChanged(RadioGroup group, int checkedId) { 111 | switch (checkedId) { 112 | case R.id.p0 : 113 | bind.cosin.setPeriod(Math.PI / 2d); 114 | break; 115 | case R.id.p1 : 116 | bind.cosin.setPeriod(Math.PI); 117 | break; 118 | case R.id.p2 : 119 | bind.cosin.setPeriod(Math.PI * 2d); 120 | break; 121 | case R.id.p3 : 122 | bind.cosin.setPeriod(Math.PI * 5d); 123 | break; 124 | case R.id.p4 : 125 | bind.cosin.setPeriod(Math.PI * 10d); 126 | break; 127 | } 128 | } 129 | }); 130 | 131 | bind.tvSpeed.setText(Math.round(partRev(bind.cosin.getSpeed(), bind.cosin.limSpeed)) + ""); 132 | bind.speed.setProgress((int)partRev(bind.cosin.getSpeed(), bind.cosin.limSpeed)); 133 | bind.speed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 134 | @Override 135 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 136 | bind.cosin.setSpeed(part(progress, bind.cosin.limSpeed)); 137 | bind.tvSpeed.setText(Math.round(partRev(bind.cosin.getSpeed(), bind.cosin.limSpeed)) + ""); 138 | } 139 | 140 | @Override 141 | public void onStartTrackingTouch(SeekBar seekBar) { 142 | 143 | } 144 | 145 | @Override 146 | public void onStopTrackingTouch(SeekBar seekBar) { 147 | 148 | } 149 | }); 150 | 151 | bind.colorAdapter.check(R.id.gb); 152 | bind.colorAdapter.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 153 | @Override 154 | public void onCheckedChanged(RadioGroup group, int checkedId) { 155 | switch (checkedId) { 156 | case R.id.rb : 157 | bind.cosin.setColorAdapter(new ColorAdapterRB()); 158 | break; 159 | case R.id.br : 160 | bind.cosin.setColorAdapter(new ColorAdapterBR()); 161 | break; 162 | case R.id.rg : 163 | bind.cosin.setColorAdapter(new ColorAdapterRG()); 164 | break; 165 | case R.id.gr : 166 | bind.cosin.setColorAdapter(new ColorAdapterGR()); 167 | break; 168 | case R.id.bg : 169 | bind.cosin.setColorAdapter(new ColorAdapterBG()); 170 | break; 171 | case R.id.gb : 172 | bind.cosin.setColorAdapter(new DefaultColorAdapterGB()); 173 | break; 174 | } 175 | } 176 | }); 177 | 178 | bind.tvOffset.setText(partRev(bind.cosin.getOffset(), bind.cosin.limOffset) + ""); 179 | bind.offset.setProgress((int)partRev(bind.cosin.getOffset(), bind.cosin.limOffset)); 180 | bind.offset.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 181 | @Override 182 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 183 | bind.cosin.setOffset(part(progress, bind.cosin.limOffset)); 184 | bind.tvOffset.setText(part(progress, bind.cosin.limOffset) + ""); 185 | } 186 | 187 | @Override 188 | public void onStartTrackingTouch(SeekBar seekBar) { 189 | 190 | } 191 | 192 | @Override 193 | public void onStopTrackingTouch(SeekBar seekBar) { 194 | 195 | } 196 | }); 197 | 198 | bind.rectText.check(R.id.binary); 199 | bind.rectText.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 200 | @Override 201 | public void onCheckedChanged(RadioGroup group, int checkedId) { 202 | switch (checkedId) { 203 | case R.id.binary : 204 | bind.cosin.setTextAdapter(new DefaultBinaryTextAdapter()); 205 | break; 206 | case R.id.rb_text : 207 | bind.cosin.setTextAdapter(new WordTextAdapter(bind.etText.getText().toString())); 208 | } 209 | } 210 | }); 211 | bind.etText.addTextChangedListener(new TextWatcher() { 212 | @Override 213 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 214 | 215 | } 216 | 217 | @Override 218 | public void onTextChanged(CharSequence s, int start, int before, int count) { 219 | bind.cosin.setTextAdapter(new WordTextAdapter(s.toString())); 220 | } 221 | 222 | @Override 223 | public void afterTextChanged(Editable s) { 224 | 225 | } 226 | }); 227 | 228 | bind.dir.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 229 | @Override 230 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 231 | bind.cosin.setDirectionRight(isChecked); 232 | } 233 | }); 234 | 235 | bind.stop.setOnClickListener(new View.OnClickListener() { 236 | @Override 237 | public void onClick(View v) { 238 | bind.cosin.setEnd(); 239 | } 240 | }); 241 | } 242 | 243 | private int part(int x, Cosin.Limit lim) { 244 | int len = lim.max - lim.min; 245 | return (x * len) / 100 + lim.min; 246 | } 247 | 248 | private int partRev(int x, Cosin.Limit lim) { 249 | int len = lim.max - lim.min; 250 | return ((x - lim.min) * 100) / len; 251 | } 252 | 253 | private double part(double x, Cosin.Limit lim) { 254 | double len = lim.max - lim.min; 255 | return ((x * len) / 100d + lim.min); 256 | } 257 | 258 | private double partRev(double x, Cosin.Limit lim) { 259 | double len = lim.max - lim.min; 260 | return ((x - lim.min) * 100d) / len; 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 18 | 19 | 25 | 26 | 27 | 28 | 32 | 33 | 38 | 39 | 40 | 45 | 46 | 51 | 52 | 53 | 60 | 61 | 66 | 67 | 71 | 72 | 79 | 80 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 96 | 97 | 102 | 103 | 108 | 109 | 116 | 117 | 122 | 123 | 124 | 130 | 131 | 132 | 133 | 134 | 135 | 140 | 141 | 146 | 147 | 152 | 153 | 160 | 161 | 166 | 167 | 168 | 174 | 175 | 176 | 177 | 178 | 179 | 184 | 185 | 190 | 191 | 196 | 197 | 204 | 205 | 210 | 211 | 212 | 218 | 219 | 220 | 221 | 222 | 223 | 228 | 229 | 234 | 235 | 240 | 241 | 246 | 247 | 252 | 253 | 258 | 259 | 264 | 265 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 283 | 284 | 289 | 290 | 295 | 296 | 303 | 304 | 309 | 310 | 311 | 317 | 318 | 319 | 320 | 321 | 322 | 327 | 328 | 333 | 334 | 339 | 340 | 347 | 348 | 349 | 350 | 356 | 357 | 362 | 363 | 368 | 369 | 374 | 375 | 380 | 381 | 386 | 387 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 404 | 405 | 410 | 411 | 416 | 417 | 424 | 425 | 430 | 431 | 432 | 438 | 439 | 440 | 441 | 442 | 443 | 448 | 449 | 454 | 455 | 462 | 463 | 468 | 469 | 474 | 475 | 480 | 481 | 482 | 483 | 487 | 488 | 489 | 490 | 491 | 492 |