├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── tech │ │ └── oom │ │ └── luckview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── tech │ │ │ └── oom │ │ │ └── luckview │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-hdpi │ │ ├── huawei.png │ │ ├── image_one.png │ │ ├── iphone.png │ │ ├── macbook.png │ │ ├── meizu.png │ │ ├── node.png │ │ └── xiaomi.png │ │ ├── layout │ │ └── activity_main.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── tech │ └── oom │ └── luckview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── luckpan ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── tech │ │ └── oom │ │ └── luckpan │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── tech │ │ │ └── oom │ │ │ └── luckpan │ │ │ ├── LuckBean.java │ │ │ ├── LuckItemInfo.java │ │ │ └── NewLuckView.java │ └── res │ │ └── values │ │ ├── luckview_styleable.xml │ │ └── strings.xml │ └── test │ └── java │ └── tech │ └── oom │ └── luckpan │ └── ExampleUnitTest.java ├── screenshots └── screenshot.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LuckView 抽奖转盘 2 | 3 | # 效果图 4 | 5 | 6 | # 属性 7 | 8 | ``` 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ``` 45 | # 声明-布局中 46 | ```java 47 | 59 | ``` 60 | # Activity中的使用 61 | 62 | ```java 63 | luckView = (NewLuckView) findViewById(R.id.luck_view); 64 | luckView.setIndicatorResourceId(R.drawable.node); 65 | ArrayList items = new ArrayList<>(); 66 | ArrayList bitmaps = new ArrayList<>(); 67 | 68 | for (int i = 0; i < 8; i++) { 69 | LuckItemInfo luckItem = new LuckItemInfo(); 70 | luckItem.prize_name = strs[i]; 71 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), images[i]); 72 | bitmaps.add(bitmap); 73 | items.add(luckItem); 74 | } 75 | 76 | LuckBean luck = new LuckBean(); 77 | luck.details = items; 78 | // load数据 79 | luckView.loadData(luck, bitmaps); 80 | // luckView.setEnable(false); 设置是否可用 默认为true 81 | //添加监听 当luckview检测到indicator所在位置被点击时,会自动开始旋转 82 | luckView.setLuckViewListener(new NewLuckView.LuckViewListener() { 83 | @Override 84 | public void onStart() { 85 | 86 | //模拟网络请求获取抽奖结果,然后设置选中项的index值 87 | luckView.postDelayed(new Runnable() { 88 | @Override 89 | public void run() { 90 | Random random = new Random(); 91 | int i = random.nextInt(6); 92 | luckView.setStop(i); 93 | } 94 | }, 3000); 95 | } 96 | 97 | @Override 98 | public void onStop(int index) { 99 | 100 | } 101 | }); 102 | 103 | } 104 | ``` 105 | 106 | # Gradle 107 | [![](https://jitpack.io/v/ideastudios/LuckView.svg)](https://jitpack.io/#ideastudios/LuckView) 108 | 109 | 1. Add it in your root build.gradle at the end of repositories: 110 | ``` 111 | allprojects { 112 | repositories { 113 | ... 114 | maven { url 'https://jitpack.io' } 115 | } 116 | } 117 | ``` 118 | 2. Add the dependency 119 | ``` 120 | dependencies { 121 | compile 'com.github.ideastudios:LuckView:0.0.1' 122 | } 123 | 124 | ``` 125 | 126 | # 注意 127 | * LuckView属性中,只有奖品图片的偏移量 和 文字的偏移量 是相对于圆盘半径的,其他的相关属性都是相对于圆盘的直径 128 | * LuckView中奖项的数量大小应该设置为可以能被360整除的数,如果不能被360整除,则会出现相应bug 129 | * LuckView draw不同奖项图片 draw不同奖项名称是通过canvas.rotate(sectorAnger)的方式实现的 130 | 131 | 132 | 133 | # 感谢 134 | 该工程参考了[Nipuream/LuckPan](https://github.com/Nipuream/LuckPan) 的相关代码和UI,感谢这位小伙伴 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "tech.oom.luckview" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile 'com.github.ideastudios:LuckView:0.0.1' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\tools\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/tech/oom/luckview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckview; 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 | * Instrumentation 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("tech.oom.luckview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/tech/oom/luckview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckview; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Random; 10 | 11 | import tech.oom.luckpan.LuckBean; 12 | import tech.oom.luckpan.LuckItemInfo; 13 | import tech.oom.luckpan.NewLuckView; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | private NewLuckView luckView; 17 | private int[] images = new int[]{R.drawable.huawei, R.drawable.image_one, R.drawable.iphone, R.drawable.image_one, R.drawable.macbook, R.drawable.image_one, R.drawable.meizu, R.drawable.xiaomi}; 18 | private String[] strs = {"华为手机", "谢谢惠顾", "iPhone 6s", "谢谢惠顾", "mac book", "谢谢惠顾", "魅族手机", "小米手机"}; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | luckView = (NewLuckView) findViewById(R.id.luck_view); 25 | luckView.setIndicatorResourceId(R.drawable.node); 26 | ArrayList items = new ArrayList<>(); 27 | ArrayList bitmaps = new ArrayList<>(); 28 | 29 | for (int i = 0; i < 8; i++) { 30 | LuckItemInfo luckItem = new LuckItemInfo(); 31 | luckItem.prize_name = strs[i]; 32 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), images[i]); 33 | bitmaps.add(bitmap); 34 | items.add(luckItem); 35 | } 36 | 37 | LuckBean luck = new LuckBean(); 38 | luck.details = items; 39 | // load数据 40 | luckView.loadData(luck, bitmaps); 41 | // luckView.setEnable(false); 设置是否可用 默认为true 42 | //添加监听 当luckview检测到indicator所在位置被点击时,会自动开始旋转 43 | luckView.setLuckViewListener(new NewLuckView.LuckViewListener() { 44 | @Override 45 | public void onStart() { 46 | 47 | //模拟网络请求获取抽奖结果,然后设置选中项的index值 48 | luckView.postDelayed(new Runnable() { 49 | @Override 50 | public void run() { 51 | Random random = new Random(); 52 | int i = random.nextInt(6); 53 | luckView.setStop(i); 54 | } 55 | }, 3000); 56 | } 57 | 58 | @Override 59 | public void onStop(int index) { 60 | 61 | } 62 | }); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/huawei.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/huawei.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/image_one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/image_one.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/iphone.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/macbook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/macbook.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/meizu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/meizu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/node.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/xiaomi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/drawable-hdpi/xiaomi.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LuckView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/tech/oom/luckview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckview; 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 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.0' 9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 26 15:59:51 CST 2017 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /luckpan/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /luckpan/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.ideastudios' 5 | 6 | android { 7 | compileSdkVersion 25 8 | buildToolsVersion "25.0.3" 9 | 10 | defaultConfig { 11 | minSdkVersion 15 12 | targetSdkVersion 25 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 30 | exclude group: 'com.android.support', module: 'support-annotations' 31 | }) 32 | compile 'com.android.support:appcompat-v7:25.1.1' 33 | testCompile 'junit:junit:4.12' 34 | } 35 | -------------------------------------------------------------------------------- /luckpan/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\tools\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /luckpan/src/androidTest/java/tech/oom/luckpan/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckpan; 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 | * Instrumentation 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("tech.oom.luckpan.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /luckpan/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /luckpan/src/main/java/tech/oom/luckpan/LuckBean.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckpan; 2 | 3 | import java.util.List; 4 | 5 | 6 | 7 | public class LuckBean { 8 | public List details; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /luckpan/src/main/java/tech/oom/luckpan/LuckItemInfo.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckpan; 2 | 3 | 4 | 5 | public class LuckItemInfo { 6 | public String prize_name; //奖品名称 7 | 8 | } 9 | -------------------------------------------------------------------------------- /luckpan/src/main/java/tech/oom/luckpan/NewLuckView.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckpan; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.Matrix; 11 | import android.graphics.Paint; 12 | import android.graphics.RectF; 13 | import android.support.annotation.ColorInt; 14 | import android.text.TextPaint; 15 | import android.util.AttributeSet; 16 | import android.view.MotionEvent; 17 | import android.view.View; 18 | import android.view.animation.DecelerateInterpolator; 19 | import android.view.animation.LinearInterpolator; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | 25 | public class NewLuckView extends View { 26 | 27 | 28 | /** 29 | * 默认显示奖品字体大小 30 | */ 31 | private final float default_text_size; 32 | /** 33 | * 默认显示奖品的字体颜色 34 | */ 35 | private final int default_text_color = Color.rgb(255, 255, 255); 36 | /** 37 | * 默认显示奖品字体距离圆心的偏移量占半径长度的比 38 | */ 39 | private final float defaultTextOffsetRatio = 0.85f; 40 | /** 41 | * 奇数扇形的填充色 42 | */ 43 | private final int default_odd_sector_color = Color.rgb(255, 133, 132); 44 | /** 45 | * 偶数扇形的填充色 46 | */ 47 | private final int default_even_sector_color = Color.rgb(254, 104, 105); 48 | /** 49 | * 默认奖品图片的宽度占转盘宽度的比 50 | */ 51 | private final float defaultWidthRatio = 1f / 8; 52 | /** 53 | * 默认奖品图片距离圆心的偏移长度占圆盘半径长度的比 54 | */ 55 | private final float defaultItemOffsetRatio = 3f / 5; 56 | /** 57 | * 默认indicator的宽度和直径的比 58 | */ 59 | private final float defaultIndicatorWidthRatio = 1f / 5; 60 | /** 61 | * 默认indicator的高度和直径的比 62 | */ 63 | private final float defaultIndicatorHeightRatio = 1f / 5; 64 | /** 65 | * 默认转一圈所用的时间 66 | */ 67 | private final int defaultCycleInMilliseconds = 800; 68 | 69 | private RectF luckViewRect = new RectF(); 70 | private RectF indicatorRect = new RectF(); 71 | 72 | private LuckBean mLuckBean; 73 | private boolean isRolling; 74 | private int radius; 75 | private int firstAngle = 0; 76 | 77 | /** 78 | * 转盘所有图片的bitmap集合 79 | */ 80 | private List bitmaps = new ArrayList<>(); 81 | 82 | /** 83 | * 默认奖品图片的高度占转盘高度度的比 84 | */ 85 | private float defaultHeightRatio = 1f / 8; 86 | 87 | /** 88 | * 控件的最小长宽 89 | */ 90 | private int min_size; 91 | 92 | /** 93 | * 奖项字体大小 94 | */ 95 | private float textSize; 96 | 97 | /** 98 | * 奖项字体颜色 99 | */ 100 | private int textColor; 101 | 102 | /** 103 | * 奖品字体距离圆心的偏移量占半径长度的比 104 | */ 105 | private float textOffsetRatio; 106 | 107 | 108 | /** 109 | * 奇数扇形的填充色 110 | */ 111 | private int oddSectorColor; 112 | 113 | /** 114 | * 偶数扇形的填充色 115 | */ 116 | private int evenSectorColor; 117 | 118 | private Paint oddSectorPaint; 119 | private Paint evenSectorPaint; 120 | private TextPaint textPaint; 121 | 122 | /** 123 | * 奖品图片的宽度占转盘宽度的比 124 | */ 125 | private float itemWidthRatio; 126 | 127 | /** 128 | * 奖品图片的高度占转盘宽度的比 129 | */ 130 | private float itemHeightRatio; 131 | 132 | /** 133 | * 奖品图片距离圆心的偏移长度占圆盘半径长度的比 134 | */ 135 | private float itemOffsetRatio; 136 | 137 | /** 138 | * indicator 的资源ID 139 | */ 140 | private int indicatorResourceId; 141 | 142 | /** 143 | * 默认indicator的宽度和直径的比 144 | */ 145 | private float indicatorWidthRatio; 146 | 147 | /** 148 | * 默认indicator的高度和直径的比 149 | */ 150 | private float indicatorHeightRatio; 151 | 152 | private boolean enable = true; 153 | 154 | private Bitmap indicatorBitmap; 155 | private int cycleInMilliseconds; 156 | private ValueAnimator animator; 157 | private LuckViewListener luckViewListener; 158 | 159 | public NewLuckView(Context context) { 160 | this(context, null); 161 | } 162 | 163 | public NewLuckView(Context context, AttributeSet attrs) { 164 | this(context, attrs, 0); 165 | } 166 | 167 | public NewLuckView(Context context, AttributeSet attrs, int defStyleAttr) { 168 | super(context, attrs, defStyleAttr); 169 | default_text_size = dip2px(context, 14); 170 | min_size = dip2px(context, 200); 171 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.NewLuckView, defStyleAttr, 0); 172 | initByAttributes(attributes); 173 | attributes.recycle(); 174 | initPainters(); 175 | } 176 | 177 | 178 | private void initByAttributes(TypedArray attributes) { 179 | textSize = attributes.getDimension(R.styleable.NewLuckView_luck_text_size, default_text_size); 180 | textColor = attributes.getColor(R.styleable.NewLuckView_luck_text_color, default_text_color); 181 | textOffsetRatio = attributes.getFloat(R.styleable.NewLuckView_luck_text_offset_ratio, defaultTextOffsetRatio); 182 | oddSectorColor = attributes.getColor(R.styleable.NewLuckView_luck_odd_sector_color, default_odd_sector_color); 183 | evenSectorColor = attributes.getColor(R.styleable.NewLuckView_luck_even_sector_color, default_even_sector_color); 184 | itemWidthRatio = attributes.getFloat(R.styleable.NewLuckView_luck_item_width_ratio, defaultWidthRatio); 185 | itemHeightRatio = attributes.getFloat(R.styleable.NewLuckView_luck_item_height_ratio, defaultHeightRatio); 186 | itemOffsetRatio = attributes.getFloat(R.styleable.NewLuckView_luck_item_offset_ratio, defaultItemOffsetRatio); 187 | indicatorResourceId = attributes.getResourceId(R.styleable.NewLuckView_luck_indicator_drawable, 0); 188 | indicatorWidthRatio = attributes.getFloat(R.styleable.NewLuckView_luck_indicator_width_ratio, defaultIndicatorWidthRatio); 189 | indicatorHeightRatio = attributes.getFloat(R.styleable.NewLuckView_luck_indicator_height_ratio, defaultIndicatorHeightRatio); 190 | cycleInMilliseconds = attributes.getInteger(R.styleable.NewLuckView_luck_cycle_millis, defaultCycleInMilliseconds); 191 | } 192 | 193 | private void initPainters() { 194 | oddSectorPaint = new Paint(); 195 | oddSectorPaint.setColor(oddSectorColor); 196 | oddSectorPaint.setStyle(Paint.Style.FILL); 197 | oddSectorPaint.setAntiAlias(true); 198 | 199 | evenSectorPaint = new Paint(); 200 | evenSectorPaint.setColor(evenSectorColor); 201 | evenSectorPaint.setStyle(Paint.Style.FILL); 202 | evenSectorPaint.setAntiAlias(true); 203 | 204 | textPaint = new TextPaint(); 205 | textPaint.setColor(textColor); 206 | textPaint.setTextSize(textSize); 207 | textPaint.setTextAlign(Paint.Align.CENTER); 208 | textPaint.setAntiAlias(true); 209 | } 210 | 211 | 212 | /** 213 | * 设置相应的实体类 214 | * 215 | * @param bean 216 | */ 217 | public void loadData(LuckBean bean, List bitmaps) { 218 | mLuckBean = bean; 219 | this.bitmaps.addAll(bitmaps); 220 | invalidate(); 221 | } 222 | 223 | /** 224 | * 设置抽奖指针的bitmap 225 | * 226 | * @param indicatorBitmap 227 | */ 228 | public void setIndicator(Bitmap indicatorBitmap) { 229 | this.indicatorBitmap = indicatorBitmap; 230 | invalidate(); 231 | } 232 | 233 | /** 234 | * 设置抽奖指针的bitmap resources id 235 | * @param indicatorResourceId 236 | */ 237 | public void setIndicatorResourceId(int indicatorResourceId) { 238 | this.indicatorResourceId = indicatorResourceId; 239 | invalidate(); 240 | } 241 | 242 | /** 243 | * 设置奇数扇形区域的颜色 244 | * 245 | * @param color 246 | */ 247 | public void setOddSectorColor(@ColorInt int color) { 248 | oddSectorColor = color; 249 | invalidateNow(); 250 | } 251 | 252 | /** 253 | * 设置偶数扇形区域的颜色 254 | * 255 | * @param color 256 | */ 257 | public void setEvenSectorColor(@ColorInt int color) { 258 | evenSectorColor = color; 259 | invalidateNow(); 260 | } 261 | 262 | /** 263 | * 设置奖项文字颜色 264 | * 265 | * @param color 266 | */ 267 | public void setItemTextColor(@ColorInt int color) { 268 | textColor = color; 269 | invalidateNow(); 270 | } 271 | 272 | /** 273 | * 设置奖项文字大小 274 | * 275 | * @param size 276 | */ 277 | public void setItemTextSize(float size) { 278 | textSize = size; 279 | invalidateNow(); 280 | } 281 | 282 | public float getTextOffsetRatio() { 283 | return textOffsetRatio; 284 | } 285 | 286 | /** 287 | * 奖品字体距离圆心的偏移量占半径长度的比 288 | */ 289 | public void setTextOffsetRatio(float textOffsetRatio) { 290 | this.textOffsetRatio = textOffsetRatio; 291 | } 292 | 293 | public float getItemWidthRatio() { 294 | return itemWidthRatio; 295 | } 296 | 297 | /** 298 | * 奖品图片的宽度占转盘宽度的比 299 | */ 300 | public void setItemWidthRatio(float itemWidthRatio) { 301 | this.itemWidthRatio = itemWidthRatio; 302 | } 303 | 304 | public float getItemHeightRatio() { 305 | return itemHeightRatio; 306 | } 307 | 308 | /** 309 | * 奖品图片的高度占转盘宽度的比 310 | */ 311 | public void setItemHeightRatio(float itemHeightRatio) { 312 | this.itemHeightRatio = itemHeightRatio; 313 | } 314 | 315 | public float getItemOffsetRatio() { 316 | return itemOffsetRatio; 317 | } 318 | 319 | /** 320 | * 奖品图片距离圆心的偏移长度占圆盘半径长度的比 321 | */ 322 | public void setItemOffsetRatio(float itemOffsetRatio) { 323 | this.itemOffsetRatio = itemOffsetRatio; 324 | } 325 | 326 | public float getIndicatorWidthRatio() { 327 | return indicatorWidthRatio; 328 | } 329 | 330 | /** 331 | * 默认indicator的宽度和直径的比 332 | * @param indicatorWidthRatio 333 | */ 334 | public void setIndicatorWidthRatio(float indicatorWidthRatio) { 335 | this.indicatorWidthRatio = indicatorWidthRatio; 336 | } 337 | 338 | public float getIndicatorHeightRatio() { 339 | return indicatorHeightRatio; 340 | } 341 | 342 | /** 343 | * 默认indicator的高度和直径的比 344 | * @param indicatorHeightRatio 345 | */ 346 | public void setIndicatorHeightRatio(float indicatorHeightRatio) { 347 | this.indicatorHeightRatio = indicatorHeightRatio; 348 | } 349 | 350 | public int getCycleInMilliseconds() { 351 | return cycleInMilliseconds; 352 | } 353 | 354 | /** 355 | * 转一圈所用的时间 356 | * @param cycleInMilliseconds 357 | */ 358 | public void setCycleInMilliseconds(int cycleInMilliseconds) { 359 | this.cycleInMilliseconds = cycleInMilliseconds; 360 | } 361 | 362 | /** 363 | * 是否可用 默认为true 364 | * @return 365 | */ 366 | public boolean isEnable() { 367 | return enable; 368 | } 369 | 370 | /** 371 | * 设置是否可用 当为false时,表示不对点击事件进行监听 372 | * @param enable 373 | */ 374 | public void setEnable(boolean enable) { 375 | this.enable = enable; 376 | } 377 | 378 | /** 379 | * 如果改变相应配置 需要刷新相应属性 380 | */ 381 | public void invalidateNow() { 382 | initPainters(); 383 | invalidate(); 384 | } 385 | 386 | public Bitmap getIndicatorBitmap() { 387 | if (indicatorBitmap == null) { 388 | if (indicatorResourceId != 0) { 389 | return BitmapFactory.decodeResource(getResources(), indicatorResourceId); 390 | } 391 | } 392 | return indicatorBitmap; 393 | 394 | } 395 | 396 | 397 | @Override 398 | protected void onDraw(Canvas canvas) { 399 | super.onDraw(canvas); 400 | 401 | if (mLuckBean == null || mLuckBean.details == null) { 402 | return; 403 | } 404 | 405 | int MinValue = Math.min(getWidth(), getHeight()); 406 | radius = MinValue / 2; 407 | // RectF rectF = new RectF(0, 0, MinValue, MinValue); 408 | luckViewRect.set(0, 0, MinValue, MinValue); 409 | int size = mLuckBean.details.size(); 410 | int sectorAnger = (int) (360 / size + 0.5f); 411 | int startAngle = (int) (270 - sectorAnger / 2 + 0.5f) + firstAngle; 412 | for (int i = 0; i < size; i++) { 413 | if (i % 2 == 0) { 414 | canvas.drawArc(luckViewRect, startAngle, sectorAnger, true, oddSectorPaint); 415 | } else { 416 | canvas.drawArc(luckViewRect, startAngle, sectorAnger, true, evenSectorPaint); 417 | } 418 | startAngle += sectorAnger; 419 | } 420 | canvas.translate(radius, radius); 421 | // RectF rect = new RectF(-indicatorWidthRatio * radius, (-indicatorHeightRatio) * radius, indicatorWidthRatio * radius, (indicatorHeightRatio) * radius); 422 | indicatorRect.set(-getIndicatorWidthRatio() * radius, (-getIndicatorHeightRatio()) * radius, getIndicatorWidthRatio() * radius, (getIndicatorHeightRatio()) * radius); 423 | // if (indicatorBitmap != null) { 424 | // canvas.drawBitmap(indicatorBitmap, null, indicatorRect, null); 425 | // } else { 426 | // if (indicatorResourceId != 0) { 427 | // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), indicatorResourceId); 428 | // canvas.drawBitmap(bitmap, null, indicatorRect, null); 429 | // } 430 | // } 431 | 432 | canvas.drawBitmap(getIndicatorBitmap(), null, indicatorRect, null); 433 | int rotatedDegree = firstAngle; 434 | canvas.rotate(firstAngle); 435 | for (int i = 0; i < size; i++) { 436 | LuckItemInfo luckItemInfo = mLuckBean.details.get(i); 437 | drawText(canvas, luckItemInfo.prize_name); 438 | drawIcon(canvas, bitmaps.get(i)); 439 | rotatedDegree += sectorAnger; 440 | canvas.rotate(sectorAnger); 441 | } 442 | 443 | } 444 | 445 | private void drawText(Canvas mCanvas, String drawText) { 446 | mCanvas.drawText(drawText, 0, -radius * getTextOffsetRatio(), textPaint); 447 | } 448 | 449 | private void drawIcon(Canvas mCanvas, Bitmap bitmap) { 450 | RectF rect = new RectF(-getItemWidthRatio() * radius, (-getItemHeightRatio() + (-getItemOffsetRatio())) * radius, getItemWidthRatio() * radius, (getItemHeightRatio() + (-getItemOffsetRatio())) * radius); 451 | mCanvas.drawBitmap(bitmap, null, rect, null); 452 | } 453 | 454 | /** 455 | * 选择变换 456 | * 457 | * @param origin 原图 458 | * @param alpha 旋转角度,可正可负 459 | * @return 旋转后的图片 460 | */ 461 | private Bitmap rotateBitmap(Bitmap origin, float alpha) { 462 | if (origin == null) { 463 | return null; 464 | } 465 | int width = origin.getWidth(); 466 | int height = origin.getHeight(); 467 | Matrix matrix = new Matrix(); 468 | matrix.setRotate(alpha); 469 | // 围绕原地进行旋转 470 | Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false); 471 | if (newBM.equals(origin)) { 472 | return newBM; 473 | } 474 | 475 | return newBM; 476 | } 477 | 478 | @Override 479 | public boolean onTouchEvent(MotionEvent event) { 480 | 481 | if(!enable){ 482 | return false; 483 | } 484 | int centerX = getMeasuredWidth() / 2; 485 | int centerY = getMeasuredHeight() / 2; 486 | 487 | //还没在Viewtree视图上面绘制出来的时候,不管点击事件 488 | if (centerX <= 0 || centerY <= 0) { 489 | return true; 490 | } 491 | 492 | //宽度位置超过箭头图标区域 493 | if (Math.abs(event.getX() - centerX) > indicatorWidthRatio * radius) { 494 | return true; 495 | } 496 | //高度位置超过箭头图标区域 497 | if (Math.abs(event.getY() - centerY) > indicatorHeightRatio * radius) { 498 | return true; 499 | } 500 | 501 | //点击在箭头上面 502 | if (event.getAction() == MotionEvent.ACTION_DOWN) { 503 | startRolling(); 504 | } 505 | 506 | return true; 507 | } 508 | 509 | private void startRolling() { 510 | if (isRolling) { 511 | return; 512 | } 513 | animator = ValueAnimator.ofInt(0, 360); 514 | animator.setDuration(getCycleInMilliseconds()); 515 | animator.setRepeatCount(ValueAnimator.INFINITE); 516 | animator.setRepeatMode(ValueAnimator.RESTART); 517 | animator.setInterpolator(new LinearInterpolator()); 518 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 519 | @Override 520 | public void onAnimationUpdate(ValueAnimator animation) { 521 | firstAngle = (Integer) animation.getAnimatedValue(); 522 | invalidate(); 523 | } 524 | }); 525 | animator.start(); 526 | if (luckViewListener != null) { 527 | luckViewListener.onStart(); 528 | } 529 | isRolling = true; 530 | } 531 | 532 | public void setStop(int index) { 533 | int size = mLuckBean.details.size(); 534 | if (index < 0 || index >= size) { 535 | animator.cancel(); 536 | return; 537 | } 538 | int sectorAnger = (int) (360 / size + 0.5f); 539 | animator.setIntValues(firstAngle, 360 + (size - index) * sectorAnger); 540 | animator.setInterpolator(new DecelerateInterpolator()); 541 | animator.setRepeatCount(1); 542 | if (luckViewListener != null) { 543 | luckViewListener.onStop(index); 544 | } 545 | isRolling = false; 546 | 547 | } 548 | 549 | 550 | /** 551 | * 设置抽奖的监听回调 552 | * @param luckViewListener 553 | */ 554 | public void setLuckViewListener(LuckViewListener luckViewListener) { 555 | this.luckViewListener = luckViewListener; 556 | } 557 | 558 | 559 | @Override 560 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 561 | 562 | setMeasuredDimension(measure(widthMeasureSpec), measure(heightMeasureSpec)); 563 | } 564 | 565 | private int measure(int measureSpec) { 566 | int result; 567 | int mode = MeasureSpec.getMode(measureSpec); 568 | int size = MeasureSpec.getSize(measureSpec); 569 | if (mode == MeasureSpec.EXACTLY) { 570 | return size; 571 | } else { 572 | 573 | result = min_size; 574 | if (mode == MeasureSpec.AT_MOST) { 575 | result = Math.min(size, result); 576 | } 577 | } 578 | return result; 579 | } 580 | 581 | @Override 582 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 583 | super.onSizeChanged(w, h, oldw, oldh); 584 | if (w != h) { 585 | throw new RuntimeException("the width of luck view must be the same as it's height"); 586 | } 587 | } 588 | 589 | /** 590 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 591 | */ 592 | public int dip2px(Context context, float dpValue) { 593 | final float scale = context.getResources().getDisplayMetrics().density; 594 | return (int) (dpValue * scale + 0.5f); 595 | } 596 | 597 | 598 | public interface LuckViewListener { 599 | 600 | void onStart(); 601 | 602 | void onStop(int index); 603 | } 604 | 605 | 606 | } 607 | -------------------------------------------------------------------------------- /luckpan/src/main/res/values/luckview_styleable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /luckpan/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LuckPan 3 | 4 | -------------------------------------------------------------------------------- /luckpan/src/test/java/tech/oom/luckpan/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package tech.oom.luckpan; 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 | } -------------------------------------------------------------------------------- /screenshots/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ideastudios/LuckView/da3acf3ab303fd2d217d22b970aa0630ae588a4e/screenshots/screenshot.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':luckpan' 2 | --------------------------------------------------------------------------------