├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.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
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_user_count.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── jeanboy
│ │ │ └── app
│ │ │ └── wheelfortune
│ │ │ └── MainActivity.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jeanboy
│ │ │ └── app
│ │ │ └── wheelfortune
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jeanboy
│ │ └── app
│ │ └── wheelfortune
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── component_wheelfortune
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── bg_wheel_panel.png
│ │ │ │ ├── bg_wheel_tray.png
│ │ │ │ ├── default_avatar.png
│ │ │ │ ├── bg_wheel_border.png
│ │ │ │ ├── bg_wheel_dialog.png
│ │ │ │ ├── bg_wheel_shadow.png
│ │ │ │ ├── bg_wheel_action_join.png
│ │ │ │ ├── bg_wheel_border_light1.png
│ │ │ │ ├── bg_wheel_border_light2.png
│ │ │ │ └── bg_wheel_action_running.png
│ │ │ ├── drawable
│ │ │ │ ├── bg_sector.xml
│ │ │ │ └── bg_circle.xml
│ │ │ └── layout
│ │ │ │ ├── layout_disk_container.xml
│ │ │ │ ├── layout_disk_avatar.xml
│ │ │ │ └── layout_wheel_fortune.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jeanboy
│ │ │ │ └── component
│ │ │ │ └── wheelfortune
│ │ │ │ ├── ItemData.kt
│ │ │ │ ├── DiskTray.kt
│ │ │ │ ├── WheelFortuneView.kt
│ │ │ │ └── DiskLayout.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jeanboy
│ │ │ └── component
│ │ │ └── wheelfortune
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jeanboy
│ │ └── component
│ │ └── wheelfortune
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── resources
├── 00.gif
├── 00.mp4
├── 01.jpeg
├── 02.jpeg
├── 03.jpeg
└── 04.jpeg
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── LICENSE
├── gradle.properties
├── README.md
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/component_wheelfortune/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/component_wheelfortune/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/resources/00.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/00.gif
--------------------------------------------------------------------------------
/resources/00.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/00.mp4
--------------------------------------------------------------------------------
/resources/01.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/01.jpeg
--------------------------------------------------------------------------------
/resources/02.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/02.jpeg
--------------------------------------------------------------------------------
/resources/03.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/03.jpeg
--------------------------------------------------------------------------------
/resources/04.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/resources/04.jpeg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':component_wheelfortune'
2 | include ':app'
3 | rootProject.name = "WheelFortune"
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_user_count.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/drawable-xxhdpi/ic_user_count.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/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/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WheelFortune
3 | %d/%d
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/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/jeanboydev/Android-WheelFortune/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/jeanboydev/Android-WheelFortune/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_panel.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_tray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_tray.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/default_avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/default_avatar.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_dialog.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_shadow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_shadow.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_action_join.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_action_join.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border_light1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border_light1.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border_light2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_border_light2.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_action_running.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/HEAD/component_wheelfortune/src/main/res/drawable-xxhdpi/bg_wheel_action_running.png
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/java/com/jeanboy/component/wheelfortune/ItemData.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
2 |
3 | /**
4 | * Created by jeanboy on 2021/1/23 17:10.
5 | */
6 | data class ItemData(
7 | val avatar: String,
8 | val self: Boolean
9 | )
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jan 21 14:24:25 CST 2021
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-6.5-bin.zip
7 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable/bg_sector.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/drawable/bg_circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jeanboy/app/wheelfortune/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.app.wheelfortune
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/component_wheelfortune/src/test/java/com/jeanboy/component/wheelfortune/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/layout/layout_disk_container.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jeanboy/app/wheelfortune/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.app.wheelfortune
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jeanboy.app.wheelfortune", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/component_wheelfortune/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
--------------------------------------------------------------------------------
/component_wheelfortune/src/androidTest/java/com/jeanboy/component/wheelfortune/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jeanboy.component.wheelfortune.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Jeanboy
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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/layout/layout_disk_avatar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
17 |
25 |
26 |
37 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 30
8 | buildToolsVersion "30.0.2"
9 |
10 | defaultConfig {
11 | applicationId "com.jeanboy.app.wheelfortune"
12 | minSdkVersion 21
13 | targetSdkVersion 30
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | }
33 | }
34 |
35 | dependencies {
36 |
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
38 | implementation 'androidx.core:core-ktx:1.3.2'
39 | implementation 'androidx.appcompat:appcompat:1.2.0'
40 | implementation 'com.google.android.material:material:1.2.1'
41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
42 | implementation project(path: ':component_wheelfortune')
43 | testImplementation 'junit:junit:4.+'
44 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
46 |
47 | }
--------------------------------------------------------------------------------
/component_wheelfortune/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 30
8 | buildToolsVersion "30.0.2"
9 |
10 | defaultConfig {
11 | minSdkVersion 21
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles "consumer-rules.pro"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | }
33 | }
34 |
35 | dependencies {
36 | testImplementation 'junit:junit:4.+'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
39 |
40 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41 | implementation 'androidx.core:core-ktx:1.3.2'
42 | implementation 'androidx.appcompat:appcompat:1.2.0'
43 | implementation 'com.google.android.material:material:1.2.1'
44 |
45 | implementation "com.makeramen:roundedimageview:2.3.0"
46 | implementation 'com.github.bumptech.glide:glide:4.11.0'
47 | annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
48 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WheelFortune
2 |
3 | 幸运抽奖转盘,类似于StarMaker直播间抽奖。
4 |
5 | ## 效果图
6 |
7 | 
8 | 
9 | 
10 | 
11 |
12 | 
13 | [点击查看效果视频](https://raw.githubusercontent.com/jeanboydev/Android-WheelFortune/main/resources/00.mp4)
14 |
15 | ## 使用
16 |
17 | - 设置布局
18 |
19 | ```xml
20 |
25 | ```
26 |
27 | - 处理回调
28 |
29 | ```kotlin
30 | val wheelFortuneView = findViewById(R.id.wheelFortuneView)
31 | tv_user_count = findViewById(R.id.tv_user_count)
32 |
33 | wheelFortuneView?.setListener(object : WheelFortuneView.WheelStateListener {
34 | override fun onJoinClick() {
35 | // join 按钮点击时回调,移除 item
36 | wheelFortuneView?.toRunning(0)
37 | }
38 |
39 | override fun onCountChange(count: Int) {
40 | // item 数量变化回调
41 | tv_user_count?.text = resources.getString(R.string.user_count, count, dataList.size)
42 | }
43 |
44 | override fun onRemove(removeData: ItemData) {
45 | // item 移除时回调
46 | }
47 | })
48 | ```
49 |
50 | - 处理数据
51 |
52 | ```kotlin
53 | // 添加数据
54 | wheelFortuneView?.addData(dataList[index])
55 |
56 | // 清除数据
57 | wheelFortuneView?.clearData()
58 | ```
59 |
60 |
61 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | # Android Studio 3 in .gitignore file.
48 | .idea/caches
49 | .idea/modules.xml
50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
51 | .idea/navEditor.xml
52 |
53 | # Keystore files
54 | # Uncomment the following lines if you do not want to check your keystore files in.
55 | #*.jks
56 | #*.keystore
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 | .cxx/
61 |
62 | # Google Services (e.g. APIs or Firebase)
63 | # google-services.json
64 |
65 | # Freeline
66 | freeline.py
67 | freeline/
68 | freeline_project_description.json
69 |
70 | # fastlane
71 | fastlane/report.xml
72 | fastlane/Preview.html
73 | fastlane/screenshots
74 | fastlane/test_output
75 | fastlane/readme.md
76 |
77 | # Version control
78 | vcs.xml
79 |
80 | # lint
81 | lint/intermediates/
82 | lint/generated/
83 | lint/outputs/
84 | lint/tmp/
85 | # lint/reports/
86 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/res/layout/layout_wheel_fortune.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
12 |
13 |
14 |
21 |
22 |
23 |
28 |
29 |
30 |
35 |
36 |
37 |
44 |
45 |
46 |
53 |
54 |
55 |
61 |
62 |
63 |
70 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
25 |
26 |
37 |
38 |
47 |
48 |
53 |
54 |
59 |
60 |
69 |
70 |
71 |
72 |
78 |
79 |
84 |
85 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/java/com/jeanboy/component/wheelfortune/DiskTray.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
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.RectF
8 | import android.util.AttributeSet
9 | import android.view.View
10 |
11 | /**
12 | * Created by jeanboy on 2021/1/21 14:42.
13 | *
14 | * 转盘彩色托盘
15 | */
16 | class DiskTray : View {
17 |
18 | private val colorDefault = Color.parseColor("#652CC9")
19 | private val colorPalette: Array = arrayOf(
20 | Color.parseColor("#652CC9"),
21 | Color.parseColor("#BD3C8C"),
22 | Color.parseColor("#1E4AC1"),
23 | Color.parseColor("#232AAF"),
24 | Color.parseColor("#386730"),
25 | Color.parseColor("#712636"),
26 | Color.parseColor("#BE5F14"),
27 | Color.parseColor("#957C15"),
28 | Color.parseColor("#1D7973"),
29 | )
30 |
31 | private var mWidth: Int = 0
32 | private var mHeight: Int = 0
33 |
34 | private var mLeft: Float = 0f
35 | private var mTop: Float = 0f
36 | private var panelSize: Float = 0f
37 |
38 | private var paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
39 | private val resetAngle: Float = -90f // 开始角度
40 | private val totalAngle: Float = 360f // 一圈角度
41 | private var sweepAngle: Float = 0f // 每个 item 角度
42 | private var rotateAngle: Float = 0f // 旋转角度
43 |
44 | private var itemCount = 0
45 |
46 | constructor(context: Context) : this(context, null)
47 |
48 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
49 |
50 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
51 | context,
52 | attrs,
53 | defStyleAttr
54 | )
55 |
56 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
57 | val width = MeasureSpec.getSize(widthMeasureSpec)
58 | val height = MeasureSpec.getSize(heightMeasureSpec)
59 |
60 | val finalSpec = if (width < height) widthMeasureSpec else heightMeasureSpec
61 | super.onMeasure(finalSpec, finalSpec)
62 | }
63 |
64 | override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
65 | super.onLayout(changed, left, top, right, bottom)
66 | mWidth = measuredWidth - paddingLeft - paddingRight
67 | mHeight = measuredHeight - paddingTop - paddingBottom
68 |
69 | mLeft = paddingLeft.toFloat()
70 | mTop = paddingTop.toFloat()
71 | panelSize = mWidth.toFloat()
72 | }
73 |
74 | override fun onDraw(canvas: Canvas?) {
75 | super.onDraw(canvas)
76 | drawPanel(canvas)
77 | }
78 |
79 | private fun drawPanel(canvas: Canvas?) {
80 | val rectF = RectF(mLeft, mTop, mLeft + panelSize, mTop + panelSize)
81 | if (itemCount == 0) {
82 | paint.color = colorDefault
83 | canvas?.drawArc(rectF, resetAngle, totalAngle, true, paint)
84 | } else {
85 | var startAngle = resetAngle + rotateAngle
86 | for (i in 0 until itemCount) {
87 | val colorIndex = if (i >= colorPalette.size) 0 else i
88 | paint.color = colorPalette[colorIndex]
89 | canvas?.drawArc(rectF, startAngle, sweepAngle, true, paint)
90 | startAngle += sweepAngle
91 | }
92 | }
93 | }
94 |
95 | fun setData(itemCount: Int) {
96 | this.itemCount = itemCount
97 | this.sweepAngle = if (itemCount == 0) totalAngle else totalAngle / itemCount
98 | postInvalidate()
99 | }
100 |
101 | fun setRotateAngle(rotateAngle: Float) {
102 | this.rotateAngle = rotateAngle
103 | postInvalidate()
104 | }
105 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jeanboy/app/wheelfortune/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.app.wheelfortune
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import android.widget.TextView
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.jeanboy.component.wheelfortune.ItemData
8 | import com.jeanboy.component.wheelfortune.WheelFortuneView
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | private val dataList = mutableListOf(
13 | ItemData(
14 | "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3510986481,3852924315&fm=11&gp=0.jpg",
15 | false
16 | ),
17 | ItemData(
18 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic4.zhimg.com%2F50%2Fv2-095b2db945e2d3e0644ccbb26eab8ed8_hd.jpg&refer=http%3A%2F%2Fpic4.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=050b31134d572e38ca02ecb23ac33870",
19 | false
20 | ),
21 | ItemData(
22 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201901%2F17%2F20190117092809_ffwKZ.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=d59a5f1124cd37e84645f54dc08219d1",
23 | true
24 | ),
25 | ItemData(
26 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202007%2F01%2F20200701063944_5VaBk.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=8715e2f970e934447e6d158a6254b159",
27 | false
28 | ),
29 | ItemData(
30 | "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3155998395,3600507640&fm=26&gp=0.jpg",
31 | false
32 | ),
33 | ItemData(
34 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201510%2F01%2F20151001174653_L3wEF.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=40b8181ae924bb82396318b301803e0a",
35 | false
36 | ),
37 | ItemData(
38 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201510%2F18%2F20151018172940_5etXi.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=a162ce2a6f394e4825e5ba788047507a",
39 | false
40 | ),
41 | ItemData(
42 | "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=387639067,1599589691&fm=26&gp=0.jpg",
43 | false
44 | ),
45 | ItemData(
46 | "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201812%2F7%2F2018127203650_KvXLM.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614157465&t=4dc2acf58b9b3a1c44db1fef14fb36a4",
47 | false
48 | ),
49 | )
50 |
51 | var wheelFortuneView: WheelFortuneView? = null
52 | var tv_user_count: TextView? = null
53 |
54 | override fun onCreate(savedInstanceState: Bundle?) {
55 | super.onCreate(savedInstanceState)
56 | setContentView(R.layout.activity_main)
57 |
58 | wheelFortuneView = findViewById(R.id.wheelFortuneView)
59 | tv_user_count = findViewById(R.id.tv_user_count)
60 |
61 | wheelFortuneView?.setListener(object : WheelFortuneView.WheelStateListener {
62 | override fun onJoinClick() {
63 | wheelFortuneView?.toRunning(0)
64 | }
65 |
66 | override fun onCountChange(count: Int) {
67 | tv_user_count?.text = resources.getString(R.string.user_count, count, dataList.size)
68 | }
69 |
70 | override fun onRemove(removeData: ItemData) {
71 |
72 | }
73 | })
74 |
75 | }
76 |
77 | private var index = 0
78 | fun onAdd(view: View) {
79 | if (index >= dataList.size) {
80 | return
81 | }
82 | if (index >= 0 && index < dataList.size) {
83 | wheelFortuneView?.addData(dataList[index])
84 | }
85 | index++
86 | }
87 |
88 | fun onClear(view: View) {
89 | index = 0
90 | wheelFortuneView?.clearData()
91 | }
92 | }
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/java/com/jeanboy/component/wheelfortune/WheelFortuneView.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.os.Handler
6 | import android.os.Looper
7 | import android.os.Message
8 | import android.util.AttributeSet
9 | import android.view.View
10 | import android.widget.FrameLayout
11 | import java.lang.ref.WeakReference
12 |
13 | /**
14 | * Created by jeanboy on 2021/1/21 14:42.
15 | *
16 | * 转盘入口
17 | */
18 | class WheelFortuneView : FrameLayout {
19 |
20 | private var view_light1: View? = null
21 | private var view_light2: View? = null
22 | private var view_action_join: View? = null
23 | private var view_action_running: View? = null
24 | private var diskLayout: DiskLayout? = null
25 |
26 | private val myHandler = MyHandler(this)
27 | private var index = 0
28 |
29 | constructor(context: Context) : this(context, null)
30 |
31 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
32 |
33 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
34 | context,
35 | attrs,
36 | defStyleAttr
37 | ) {
38 | inflate(context, R.layout.layout_wheel_fortune, this)
39 |
40 | view_light1 = findViewById(R.id.view_light1)
41 | view_light2 = findViewById(R.id.view_light2)
42 | view_action_join = findViewById(R.id.view_action_join)
43 | view_action_running = findViewById(R.id.view_action_running)
44 |
45 | view_action_join?.setOnClickListener {
46 | onJoinClick()
47 | }
48 |
49 | diskLayout = findViewById(R.id.discLayout)
50 | diskLayout?.setListener(object : DiskLayout.OnRunningListener {
51 | override fun onStart() {
52 | view_action_join?.visibility = View.GONE
53 | view_action_running?.visibility = View.VISIBLE
54 | }
55 |
56 | override fun onEnd(removeData: ItemData, count: Int) {
57 | view_action_join?.visibility = View.VISIBLE
58 | view_action_running?.visibility = View.GONE
59 | listener?.onCountChange(count)
60 | listener?.onRemove(removeData)
61 | }
62 | })
63 | }
64 |
65 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
66 | val width = MeasureSpec.getSize(widthMeasureSpec)
67 | val height = MeasureSpec.getSize(heightMeasureSpec)
68 |
69 | val finalSpec = if (width < height) widthMeasureSpec else heightMeasureSpec
70 | super.onMeasure(finalSpec, finalSpec)
71 | }
72 |
73 | override fun onAttachedToWindow() {
74 | super.onAttachedToWindow()
75 | toStartMarquee()
76 | }
77 |
78 | override fun onDetachedFromWindow() {
79 | myHandler.removeCallbacksAndMessages(null)
80 | super.onDetachedFromWindow()
81 | }
82 |
83 | private fun toStartMarquee() {
84 | val message = Message.obtain(myHandler, MSG_LIGHT)
85 | val bundle = Bundle()
86 | bundle.putInt(KEY_INDEX, index++);
87 | message.data = bundle
88 | myHandler.sendMessageDelayed(message, 600)
89 | }
90 |
91 | private fun toSwitchLight(count: Int) {
92 | if (count % 2 == 0) {
93 | view_light1?.visibility = View.VISIBLE
94 | view_light2?.visibility = View.GONE
95 | } else {
96 | view_light1?.visibility = View.GONE
97 | view_light2?.visibility = View.VISIBLE
98 | }
99 | toStartMarquee()
100 | }
101 |
102 |
103 | private fun onJoinClick() {
104 | this.listener?.onJoinClick()
105 | }
106 |
107 | private var listener: WheelStateListener? = null
108 |
109 | fun setListener(listener: WheelStateListener) {
110 | this.listener = listener
111 | }
112 |
113 | interface WheelStateListener {
114 | fun onJoinClick()
115 | fun onCountChange(count: Int)
116 | fun onRemove(removeData: ItemData)
117 | }
118 |
119 | fun toRunning(removeIndex: Int) {
120 | diskLayout?.toRunning(removeIndex)
121 | }
122 |
123 | fun setData(dataList: MutableList) {
124 | diskLayout?.setData(dataList)
125 | listener?.onCountChange(diskLayout?.getDataSize() ?: 0)
126 | }
127 |
128 | fun addData(itemData: ItemData) {
129 | diskLayout?.addData(itemData)
130 | listener?.onCountChange(diskLayout?.getDataSize() ?: 0)
131 | }
132 |
133 | fun clearData() {
134 | diskLayout?.clearData()
135 | listener?.onCountChange(diskLayout?.getDataSize() ?: 0)
136 | }
137 |
138 | private class MyHandler(context: WheelFortuneView) : Handler(Looper.myLooper()!!) {
139 | private var reference: WeakReference? = WeakReference(context)
140 | override fun handleMessage(msg: Message) {
141 | super.handleMessage(msg)
142 | if (reference?.get() == null) return
143 | when (msg.what) {
144 | MSG_LIGHT -> {
145 | reference?.get()?.toSwitchLight(msg.data.getInt(KEY_INDEX))
146 | }
147 | }
148 | }
149 | }
150 |
151 | companion object {
152 | const val MSG_LIGHT = 0x101
153 | const val KEY_INDEX = "index"
154 | }
155 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/component_wheelfortune/src/main/java/com/jeanboy/component/wheelfortune/DiskLayout.kt:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.wheelfortune
2 |
3 | import android.animation.Animator
4 | import android.animation.ValueAnimator
5 | import android.content.Context
6 | import android.graphics.PointF
7 | import android.util.AttributeSet
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.animation.DecelerateInterpolator
11 | import android.widget.FrameLayout
12 | import android.widget.ImageView
13 | import android.widget.TextView
14 | import com.bumptech.glide.Glide
15 | import kotlin.math.abs
16 | import kotlin.math.cos
17 | import kotlin.math.sin
18 | import kotlin.random.Random
19 |
20 | /**
21 | * Created by jeanboy on 2021/1/21 14:42.
22 | *
23 | * 转盘用户头像
24 | */
25 | class DiskLayout : FrameLayout {
26 |
27 | private var diskTray: DiskTray? = null
28 |
29 | private var mWidth: Int = 0
30 | private var mHeight: Int = 0
31 |
32 | private val resetAngle1: Float = 90f // 开始角度只有一条数据
33 | private val resetAngle2: Float = -90f // 开始角度
34 | private val totalAngle: Float = 360f // 一圈角度
35 | private var sweepAngle: Float = 0f // 每个 item 角度
36 | private var rotateAngle: Float = 0f // 旋转角度
37 |
38 | private var isRunning: Boolean = false
39 |
40 | private val dataList = mutableListOf()
41 |
42 | constructor(context: Context) : this(context, null)
43 |
44 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
45 |
46 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
47 | context,
48 | attrs,
49 | defStyleAttr
50 | ) {
51 | diskTray = DiskTray(context)
52 | diskTray?.apply {
53 | alpha = 0.9f
54 | }
55 | }
56 |
57 | override fun onFinishInflate() {
58 | super.onFinishInflate()
59 | toAddTray()
60 | }
61 |
62 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
63 | val width = MeasureSpec.getSize(widthMeasureSpec)
64 | val height = MeasureSpec.getSize(heightMeasureSpec)
65 |
66 | val finalSpec = if (width < height) widthMeasureSpec else heightMeasureSpec
67 | super.onMeasure(finalSpec, finalSpec)
68 | }
69 |
70 | override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
71 | super.onLayout(changed, left, top, right, bottom)
72 | mWidth = measuredWidth - paddingLeft - paddingRight
73 | mHeight = measuredHeight - paddingTop - paddingBottom
74 |
75 | val sweepAngleHalf = sweepAngle * 0.5f
76 | val radius = measuredWidth * 0.5f * 0.56f
77 | val centerX = measuredWidth * 0.5f
78 | val centerY = measuredHeight * 0.5f
79 |
80 |
81 | val childCount = childCount
82 | val resetAngle = if (dataList.size == 1) resetAngle1 else resetAngle2
83 | val rotateOffsetAngle = if (dataList.size == 1) 180f else 0f
84 | val startAngle = resetAngle - sweepAngle
85 | for (i in 0 until childCount) {
86 | val childAt = getChildAt(i)
87 | if (childAt !is DiskTray) {
88 | val offsetAngle = rotateAngle + sweepAngle * i + sweepAngleHalf
89 | val childAngle = startAngle + offsetAngle
90 | val point = getCirclePoint(centerX, centerY, radius, childAngle)
91 |
92 | val widthOffset = childAt.measuredWidth * 0.5f
93 | val heightOffset = childAt.measuredHeight * 0.5f
94 |
95 | childAt.layout(
96 | (point.x - widthOffset).toInt(),
97 | (point.y - heightOffset).toInt(),
98 | (point.x + widthOffset).toInt(),
99 | (point.y + heightOffset).toInt()
100 | )
101 | childAt.rotation = offsetAngle - sweepAngle - rotateOffsetAngle
102 | }
103 | }
104 | }
105 |
106 | private fun getCirclePoint(
107 | centerX: Float,
108 | centerY: Float,
109 | radius: Float,
110 | angle: Float
111 | ): PointF {
112 | val x = (centerX + radius * cos(angle * Math.PI / 180)).toFloat()
113 | val y = (centerY + radius * sin(angle * Math.PI / 180)).toFloat()
114 | return PointF(x, y)
115 | }
116 |
117 | private fun toUpdateView() {
118 | removeAllViews()
119 | toAddTray()
120 | for (i in 0 until dataList.size) {
121 | toAddItemView(dataList[i])
122 | }
123 | }
124 |
125 | private fun toAddItemView(data: ItemData) {
126 | val itemView =
127 | LayoutInflater.from(context).inflate(R.layout.layout_disk_avatar, this, false)
128 | val iv_shape = itemView.findViewById(R.id.iv_shape)
129 | val tv_me = itemView.findViewById(R.id.tv_me)
130 |
131 | if (data.self) {
132 | iv_shape.drawable.level = 3333
133 | iv_shape.visibility = View.VISIBLE
134 | tv_me.visibility = View.VISIBLE
135 | } else {
136 | iv_shape.visibility = View.GONE
137 | tv_me.visibility = View.GONE
138 | }
139 |
140 | val iv_avatar = itemView.findViewById(R.id.iv_avatar)
141 | Glide.with(context).load(data.avatar).placeholder(R.drawable.default_avatar)
142 | .error(R.drawable.default_avatar).into(iv_avatar)
143 | addView(itemView)
144 | }
145 |
146 | private fun toClearItemView() {
147 | this.dataList.clear()
148 | removeAllViews()
149 | toAddTray()
150 | }
151 |
152 | private fun toAddTray() {
153 | diskTray?.setData(dataList.size)
154 | addView(diskTray, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
155 | }
156 |
157 | fun setData(dataList: MutableList) {
158 | this.dataList.clear()
159 | this.dataList.addAll(dataList)
160 | this.sweepAngle = totalAngle / this.dataList.size
161 | toUpdateView()
162 | requestLayout()
163 | }
164 |
165 | fun addData(itemData: ItemData) {
166 | this.dataList.add(itemData)
167 | this.sweepAngle = totalAngle / this.dataList.size
168 | toUpdateView()
169 | requestLayout()
170 | }
171 |
172 | fun removeData(itemData: ItemData) {
173 | if (this.dataList.isEmpty()) return
174 | this.dataList.remove(itemData)
175 | this.sweepAngle = totalAngle / this.dataList.size
176 | toUpdateView()
177 | requestLayout()
178 | }
179 |
180 | fun getDataSize(): Int {
181 | return dataList.size
182 | }
183 |
184 | fun remove(index: Int) {
185 | if (this.dataList.isEmpty()) return
186 | if (index >= 0 && index < dataList.size) {
187 | this.dataList.removeAt(index)
188 | if (this.dataList.size > 0) {
189 | this.sweepAngle = totalAngle / dataList.size
190 | if (this.dataList.size == 1) {
191 | this.rotateAngle = 0f;
192 | this.diskTray?.setRotateAngle(rotateAngle)
193 | }
194 | } else {
195 | this.sweepAngle = totalAngle
196 | }
197 | toUpdateView()
198 | requestLayout()
199 | }
200 | }
201 |
202 | fun clearData() {
203 | this.dataList.clear()
204 | this.rotateAngle = 0f;
205 | this.diskTray?.setRotateAngle(rotateAngle)
206 | toClearItemView()
207 | requestLayout()
208 | }
209 |
210 | fun toRunning(removeIndex: Int) {
211 | if (dataList.isEmpty() || dataList.size == 1) return
212 | if (isRunning) return
213 | isRunning = true
214 |
215 | val circleAngle = getRandomAngleForRotate() // 随机旋转圈数
216 | val rangeAngle = totalAngle - sweepAngle * removeIndex // 旋转到目标 item 需要的角度
217 | val offsetAngle =
218 | (getRandomAngleInItem(sweepAngle) + abs(rotateAngle)) % sweepAngle // item 中随机角度
219 | val targetAngle = circleAngle + rangeAngle - offsetAngle
220 | val startAngle = rotateAngle % totalAngle
221 | val valueAnimator = ValueAnimator.ofFloat(startAngle, targetAngle).apply {
222 | interpolator = DecelerateInterpolator()
223 | duration = 2500
224 | }
225 | valueAnimator.addUpdateListener {
226 | rotateAngle = it.animatedValue as Float
227 | diskTray?.setRotateAngle(rotateAngle)
228 | requestLayout()
229 | }
230 |
231 | valueAnimator.addListener(object : Animator.AnimatorListener {
232 | override fun onAnimationStart(animation: Animator?) {
233 | isRunning = true
234 | listener?.onStart()
235 | }
236 |
237 | override fun onAnimationEnd(animation: Animator?) {
238 | remove(removeIndex)
239 | isRunning = false
240 | listener?.onEnd(dataList[removeIndex], dataList.size)
241 | }
242 |
243 | override fun onAnimationCancel(animation: Animator?) {
244 | isRunning = false
245 | }
246 |
247 | override fun onAnimationRepeat(animation: Animator?) {
248 | }
249 | })
250 | valueAnimator.start()
251 | }
252 |
253 | /**
254 | * 获取命中 item 区间的旋转角度
255 | */
256 | private fun getRandomAngleInItem(sweepAngle: Float): Float {
257 | return Random.nextInt(1, sweepAngle.toInt()).toFloat()
258 | }
259 |
260 | /**
261 | * 获取旋转圈数的旋转角度
262 | */
263 | private fun getRandomAngleForRotate(): Float {
264 | return Random.nextInt(1, 3) * totalAngle
265 | }
266 |
267 | private var listener: OnRunningListener? = null
268 |
269 | fun setListener(listener: OnRunningListener) {
270 | this.listener = listener
271 | }
272 |
273 | interface OnRunningListener {
274 | fun onStart()
275 | fun onEnd(removeData: ItemData, count: Int)
276 | }
277 | }
--------------------------------------------------------------------------------