├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── idlestar
│ │ └── androidratingstar
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── docs
└── RatingStarScreenshot.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── ratingstar
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── idlestar
│ │ └── ratingstar
│ │ ├── RatingStarView.java
│ │ ├── StarModel.java
│ │ └── VertexF.java
│ └── res
│ └── values
│ ├── attrs_rating_star_view.xml
│ └── strings.xml
└── 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/
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidRatingStar
2 | RatingStar is specific RatingBar use star drawable as the rating mark.
3 |
4 | # Features
5 | The following screenshot shows the features RatingStar provides:
6 |
7 | 
8 |
9 | # Usage
10 | ## gradle dependencies
11 | See "https://jitpack.io/#everhad/AndroidRatingStar/v1.0.4".
12 |
13 | ### Step 1. Add the JitPack repository to your build file
14 | ```code
15 | allprojects {
16 | repositories {
17 | ...
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 | ```
22 |
23 | ### Step 2. Add the dependency
24 | ```code
25 | dependencies {
26 | compile 'com.github.everhad:AndroidRatingStar:v1.0.4'
27 | }
28 | ```
29 |
30 | ## In Your 'layout.xml'
31 | ```xml
32 |
53 | ```
54 |
55 | ## In Your Code
56 | ```code
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | setContentView(R.layout.activity_main);
61 |
62 | RatingStarView rsv_rating = (RatingStarView) findViewById(R.id.rsv_rating);
63 | rsv_rating.setRating(1.5f);
64 | }
65 | ```
66 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "28.0.3"
6 | defaultConfig {
7 | applicationId "com.idlestar.androidratingstar"
8 | minSdkVersion 18
9 | targetSdkVersion 28
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:28.0.0'
28 | testCompile 'junit:junit:4.12'
29 | implementation 'com.github.everhad:AndroidRatingStar:v1.0'
30 | }
31 |
--------------------------------------------------------------------------------
/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 F:\adtbundlewinx86_64\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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/idlestar/androidratingstar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.idlestar.androidratingstar;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import com.idlestar.ratingstar.RatingStarView;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 | RatingStarView rsv_rating = (RatingStarView) findViewById(R.id.rsv_rating);
16 | rsv_rating.setRating(1.5f);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
38 |
39 |
45 |
46 |
64 |
65 |
71 |
72 |
91 |
92 |
98 |
99 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidRatingStar
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | google()
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.2.1'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | jcenter()
23 | maven { url 'https://jitpack.io' }
24 | maven {
25 | url 'https://maven.google.com/'
26 | name 'Google'
27 | }
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/docs/RatingStarScreenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/docs/RatingStarScreenshot.png
--------------------------------------------------------------------------------
/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/everhad/AndroidRatingStar/9c0d6fb82194cd8b8207eb7b2c75ed07614278d3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 25 14:03:35 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-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 |
--------------------------------------------------------------------------------
/ratingstar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/ratingstar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "28.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 26
10 | versionCode 2
11 | versionName "1.1"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:26.1.0'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/ratingstar/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 F:\adtbundlewinx86_64\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 |
--------------------------------------------------------------------------------
/ratingstar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ratingstar/src/main/java/com/idlestar/ratingstar/RatingStarView.java:
--------------------------------------------------------------------------------
1 | package com.idlestar.ratingstar;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.CornerPathEffect;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.RectF;
11 | import android.util.AttributeSet;
12 | import android.util.Log;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 |
16 | import java.util.ArrayList;
17 |
18 | import static android.graphics.Canvas.CLIP_SAVE_FLAG;
19 |
20 | /**
21 | * RatingStar is specific RatingBar use star drawable as the progress mark.
22 | *
23 | * NOTE:
24 | * Padding will be larger if is {@link #cornerRadius} is set (No exact calc to handle this issue).
25 | */
26 | public class RatingStarView extends View implements View.OnClickListener {
27 | private static final String TAG = "RatingStarView";
28 | private static final int DEFAULT_STAR_HEIGHT = 32;
29 | private float cornerRadius = 4f;
30 | private int starForegroundColor = 0xffED4A4B;
31 | private int strokeColor = 0xffED4A4B;
32 | private int starBackgroundColor = Color.WHITE;
33 | /** used to make round smooth star horn */
34 | private CornerPathEffect pathEffect;
35 | private ArrayList starList;
36 | private float rating;
37 | /**
38 | * expected star number.
39 | */
40 | private int starNum = 5;
41 | /**
42 | * real drawn star number.
43 | */
44 | private int starCount;
45 | /** calculated value */
46 | private float starWidth;
47 | /** calculated value */
48 | private float starHeight;
49 | private float starMargin = 8;
50 | private float strokeWidth = 2f;
51 | private boolean drawStrokeForFullStar;
52 | private boolean drawStrokeForHalfStar = true;
53 | private boolean drawStrokeForEmptyStar = true;
54 | private boolean enableSelectRating = false;
55 | private boolean onlyHalfStar = true;
56 | private float starThicknessFactor = StarModel.DEFAULT_THICKNESS;
57 | private float dividerX;
58 | private float clickedX, clickedY;
59 | private Paint paint;
60 | private OnClickListener mOuterOnClickListener;
61 |
62 | // region constructors
63 | public RatingStarView(Context context) {
64 | super(context);
65 | init(null, 0);
66 | }
67 |
68 | public RatingStarView(Context context, AttributeSet attrs) {
69 | super(context, attrs);
70 | init(attrs, 0);
71 | }
72 |
73 | public RatingStarView(Context context, AttributeSet attrs, int defStyle) {
74 | super(context, attrs, defStyle);
75 | init(attrs, defStyle);
76 | }
77 | // endregion
78 |
79 | private void init(AttributeSet attrs, int defStyle) {
80 | loadAttributes(attrs, defStyle);
81 |
82 | // init paint
83 | paint = new Paint();
84 | paint.setFlags(Paint.ANTI_ALIAS_FLAG);
85 | paint.setStrokeWidth(strokeWidth);
86 |
87 | // properties
88 | pathEffect = new CornerPathEffect(cornerRadius);
89 |
90 | // click to rate
91 | super.setOnClickListener(this);
92 | }
93 |
94 | private void loadAttributes(AttributeSet attrs, int defStyle) {
95 | final TypedArray a = getContext().obtainStyledAttributes(
96 | attrs, R.styleable.RatingStarView, defStyle, 0);
97 | strokeColor = a.getColor(R.styleable.RatingStarView_rsv_strokeColor, strokeColor);
98 | starForegroundColor = a.getColor(R.styleable.RatingStarView_rsv_starForegroundColor, starForegroundColor);
99 | starBackgroundColor = a.getColor(R.styleable.RatingStarView_rsv_starBackgroundColor, starBackgroundColor);
100 | cornerRadius = a.getDimension(R.styleable.RatingStarView_rsv_cornerRadius, cornerRadius);
101 | starMargin = a.getDimension(R.styleable.RatingStarView_rsv_starMargin, starMargin);
102 | strokeWidth = a.getDimension(R.styleable.RatingStarView_rsv_strokeWidth, strokeWidth);
103 | starThicknessFactor = a.getFloat(R.styleable.RatingStarView_rsv_starThickness, starThicknessFactor);
104 | rating = a.getFloat(R.styleable.RatingStarView_rsv_rating, rating);
105 | starNum = a.getInteger(R.styleable.RatingStarView_rsv_starNum, starNum);
106 | drawStrokeForEmptyStar = a.getBoolean(R.styleable.RatingStarView_rsv_drawStrokeForEmptyStar, true);
107 | drawStrokeForFullStar = a.getBoolean(R.styleable.RatingStarView_rsv_drawStrokeForFullStar, false);
108 | drawStrokeForHalfStar = a.getBoolean(R.styleable.RatingStarView_rsv_drawStrokeForHalfStar, true);
109 | enableSelectRating = a.getBoolean(R.styleable.RatingStarView_rsv_enableSelectRating, false);
110 | onlyHalfStar = a.getBoolean(R.styleable.RatingStarView_rsv_onlyHalfStar, true);
111 | a.recycle();
112 | }
113 |
114 | private void setStarBackgroundColor(int color) {
115 | starBackgroundColor = color;
116 | invalidate();
117 | }
118 |
119 | /**
120 | * @see StarModel#setThickness(float)
121 | */
122 | public void setStarThickness(float thicknessFactor) {
123 | for (StarModel star : starList) {
124 | star.setThickness(thicknessFactor);
125 | }
126 | invalidate();
127 | }
128 |
129 | public void setStrokeWidth(float width) {
130 | this.strokeWidth = width;
131 | invalidate();
132 | }
133 |
134 | /**
135 | * Finally progress is: progress = rating / starNum
136 | * @param rating should be [0, starNum]
137 | */
138 | public void setRating(float rating) {
139 | if (rating != this.rating) {
140 | this.rating = rating;
141 | invalidate();
142 | }
143 | }
144 |
145 | /**
146 | * Set the smooth of the star's horn.
147 | * @param cornerRadius corner circle radius
148 | */
149 | public void setCornerRadius(float cornerRadius) {
150 | this.cornerRadius = cornerRadius;
151 | invalidate();
152 | }
153 |
154 | /**
155 | * The horizontal margin between two stars. The {@link #setCornerRadius} would make extra space
156 | * as it make the star smaller.
157 | * @param margin horizontal space
158 | */
159 | public void setStarMargin(int margin) {
160 | this.starMargin = margin;
161 | calcStars();
162 | invalidate();
163 | }
164 |
165 | /**
166 | * How many stars to show, one star means one score = 1f. See {@link #setRating(float)}
167 | * NOTE: The star's height is made by contentHeight by default.So, be sure to has defined the
168 | * correct StarView's height.
169 | * @param count star count.
170 | */
171 | public void setStarNum(int count) {
172 | if (starNum != count) {
173 | starNum = count;
174 | calcStars();
175 | invalidate();
176 | }
177 | }
178 |
179 | private void onPaddingChanged() {
180 | int left = getPaddingLeft();
181 | int top = getPaddingTop();
182 | for (StarModel star : starList) {
183 | star.moveStarTo(left, top);
184 | }
185 | }
186 |
187 | public void setDrawStrokeForFullStar(boolean draw) {
188 | drawStrokeForFullStar = draw;
189 | }
190 |
191 | public void setDrawStrokeForEmptyStar(boolean draw) {
192 | drawStrokeForEmptyStar = draw;
193 | }
194 |
195 | /**
196 | * Create all stars data, according to the contentWidth/contentHeight.
197 | */
198 | private void calcStars() {
199 | int paddingLeft = getPaddingLeft();
200 | int paddingTop = getPaddingTop();
201 | int paddingRight = getPaddingRight();
202 | int paddingBottom = getPaddingBottom();
203 | int contentWidth = getWidth() - paddingLeft - paddingRight;
204 | int contentHeight = getHeight() - paddingTop - paddingBottom;
205 |
206 | int left = paddingLeft;
207 | int top = paddingTop;
208 |
209 | // according to the View's height , make star height.
210 | int starHeight = contentHeight;
211 | if (contentHeight > contentWidth) {
212 | starHeight = contentWidth;
213 | }
214 |
215 | if (starHeight <= 0) return;
216 | float startWidth = StarModel.getStarWidth(starHeight);
217 |
218 | // starCount * startWidth + (starCount - 1) * starMargin = contentWidth
219 | int starCount = (int) ((contentWidth + starMargin) / (startWidth + starMargin));
220 | if (starCount > starNum) {
221 | starCount = starNum;
222 | }
223 |
224 | this.starHeight = starHeight;
225 | this.starWidth = startWidth;
226 | Log.d(TAG, "drawing starCount = " + starCount + ", contentWidth = " + contentWidth
227 | + ", startWidth = " + startWidth + ", starHeight = " + starHeight);
228 |
229 | starList = new ArrayList<>(starCount);
230 |
231 | for (int i = 0; i < starCount; i++) {
232 | StarModel star = new StarModel(starThicknessFactor);
233 | starList.add(star);
234 | star.setDrawingOuterRect(left, top, starHeight);
235 | left += startWidth + 0.5f + starMargin;
236 | }
237 |
238 | this.starCount = starCount;
239 | this.starWidth = startWidth;
240 | this.starHeight = starHeight;
241 | }
242 |
243 | @Override
244 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
245 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
246 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
247 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
248 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
249 |
250 | float width;
251 | int height; // must have height
252 |
253 | if (heightMode == MeasureSpec.EXACTLY) {
254 | height = heightSize;
255 | } else {
256 | height = DEFAULT_STAR_HEIGHT;
257 | if (heightMode == MeasureSpec.AT_MOST) {
258 | height = Math.min(height, heightSize);
259 | }
260 | }
261 |
262 | float starHeight = height - getPaddingBottom() - getPaddingTop();
263 |
264 | if (widthMode == MeasureSpec.EXACTLY) {
265 | // Parent has told us how big to be. So be it.
266 | width = widthSize;
267 | } else {
268 | // get the perfect width
269 | width = getPaddingLeft() + getPaddingRight();
270 | if (starNum > 0) {
271 | if (starHeight > 0) {
272 | width += starMargin * (starNum - 1);
273 | width += StarModel.getStarWidth(starHeight) * starNum;
274 | }
275 | }
276 |
277 | if (widthMode == MeasureSpec.AT_MOST) {
278 | width = Math.min(widthSize, width);
279 | }
280 | }
281 |
282 | Log.d(TAG, "[onMeasure] width = " + width + ", pLeft = " + getPaddingLeft()
283 | + ", pRight = " + getPaddingRight() + ", starMargin = " + starMargin
284 | + ", starHeight = " + starHeight + ", starWidth = " + StarModel.getStarWidth(starHeight));
285 |
286 | int widthInt = (int) (width);
287 | if (widthInt < width) {
288 | widthInt++;
289 | }
290 |
291 | setMeasuredDimension(widthInt, height);
292 | }
293 |
294 | @Override
295 | protected void onDraw(Canvas canvas) {
296 | super.onDraw(canvas);
297 |
298 | if (starList == null) {
299 | calcStars();
300 | }
301 |
302 | if (starList == null || starList.size() == 0) {
303 | return;
304 | }
305 |
306 | for (int i = 0; i < starList.size(); i++) {
307 | if (rating >= i + 1) {
308 | drawFullStar(starList.get(i), canvas);
309 | } else {
310 | float decimal = rating - i;
311 | if (decimal > 0) {
312 | if (onlyHalfStar) {
313 | decimal = 0.5f;
314 | }
315 | drawPartialStar(starList.get(i), canvas, decimal);
316 | } else {
317 | drawEmptyStar(starList.get(i), canvas);
318 | }
319 | }
320 | }
321 | }
322 |
323 | private void drawFullStar(StarModel star, Canvas canvas) {
324 | drawSolidStar(star, canvas, starForegroundColor);
325 | if (drawStrokeForFullStar) {
326 | drawStarStroke(star, canvas);
327 | }
328 | }
329 |
330 | private void drawEmptyStar(StarModel star, Canvas canvas) {
331 | drawSolidStar(star, canvas, starBackgroundColor);
332 | if (drawStrokeForEmptyStar) {
333 | drawStarStroke(star, canvas);
334 | }
335 | }
336 |
337 | @Override
338 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
339 | super.onSizeChanged(w, h, oldw, oldh);
340 | if (h != oldh) {
341 | calcStars();
342 | }
343 | }
344 |
345 | private void drawPartialStar(StarModel star, Canvas canvas, float percent) {
346 | Log.d(TAG, "drawPartialStar percent = " + percent);
347 | if (percent <= 0) {
348 | drawEmptyStar(star, canvas);
349 | return;
350 | } else if (percent >= 1) {
351 | drawFullStar(star, canvas);
352 | return;
353 | }
354 |
355 | // layer 1
356 | drawSolidStar(star, canvas, starBackgroundColor);
357 |
358 | float dividerX = star.getOuterRect().left + star.getOuterRect().width() * percent;
359 | this.dividerX = dividerX;
360 |
361 | // layer 2
362 | RectF r = star.getOuterRect();
363 | canvas.saveLayerAlpha(r.left, r.top, r.right, r.bottom, 0xff, CLIP_SAVE_FLAG);
364 | RectF clip = new RectF(star.getOuterRect());
365 | clip.right = dividerX;
366 | canvas.clipRect(clip);
367 | drawSolidStar(star, canvas, starForegroundColor);
368 | canvas.restore();
369 |
370 | // layer 1
371 | if (drawStrokeForHalfStar) {
372 | drawStarStroke(star, canvas);
373 | }
374 | }
375 |
376 | private void drawSolidStar(StarModel star, Canvas canvas, int fillColor) {
377 | paint.setStyle(Paint.Style.FILL_AND_STROKE);
378 | paint.setColor(fillColor);
379 | paint.setPathEffect(pathEffect);
380 |
381 | VertexF prev = star.getVertex(1);
382 | Path path = new Path();
383 |
384 | for (int i = 0; i < 5; i++) {
385 | path.rewind();
386 | path.moveTo(prev.x, prev.y);
387 |
388 | VertexF next = prev.next;
389 |
390 | path.lineTo(next.x, next.y);
391 | path.lineTo(next.next.x, next.next.y);
392 | path.lineTo(next.next.x, next.next.y);
393 | canvas.drawPath(path, paint);
394 |
395 | prev = next.next;
396 | }
397 |
398 | // fill the middle hole. use +1.0 +1.5 because the path-API will leave 1px gap.
399 | path.rewind();
400 | prev = star.getVertex(1);
401 | path.moveTo(prev.x - 1f, prev.y - 1f);
402 | prev = prev.next.next;
403 | path.lineTo(prev.x + 1.5f, prev.y - 0.5f);
404 | prev = prev.next.next;
405 | path.lineTo(prev.x + 1.5f, prev.y + 1f);
406 | prev = prev.next.next;
407 | path.lineTo(prev.x, prev.y + 1f);
408 | prev = prev.next.next;
409 | path.lineTo(prev.x - 1f, prev.y + 1f);
410 |
411 | paint.setPathEffect(null);
412 | canvas.drawPath(path, paint);
413 | }
414 |
415 | private void drawStarStroke(StarModel star, Canvas canvas) {
416 | paint.setStyle(Paint.Style.STROKE);
417 | paint.setColor(strokeColor);
418 | paint.setPathEffect(pathEffect);
419 | VertexF prev = star.getVertex(1);
420 | Path path = new Path();
421 |
422 | for (int i = 0; i < 5; i++) {
423 | path.rewind();
424 | path.moveTo(prev.x, prev.y);
425 |
426 | VertexF next = prev.next;
427 |
428 | path.lineTo(next.x, next.y);
429 | path.lineTo(next.next.x, next.next.y);
430 | path.lineTo(next.next.x, next.next.y);
431 |
432 | canvas.drawPath(path, paint);
433 | prev = next.next;
434 | }
435 | }
436 |
437 | @Override
438 | public boolean onTouchEvent(MotionEvent event) {
439 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
440 | clickedX = event.getX();
441 | clickedY = event.getY();
442 | }
443 | return super.onTouchEvent(event);
444 | }
445 |
446 | @Override
447 | public void setOnClickListener(OnClickListener l) {
448 | mOuterOnClickListener = l;
449 | }
450 |
451 | @Override
452 | public void onClick(View v) {
453 | if (mOuterOnClickListener != null) {
454 | mOuterOnClickListener.onClick(v);
455 | }
456 |
457 | if (enableSelectRating) {
458 | changeRatingByClick();
459 | }
460 | }
461 |
462 | private void changeRatingByClick() {
463 | int paddingTop = getPaddingTop();
464 | if (clickedY < paddingTop || clickedY > paddingTop + starHeight) {
465 | return;
466 | }
467 |
468 | int paddingLeft = getPaddingLeft();
469 | float starWidth = this.starWidth;
470 | float starMargin = this.starMargin;
471 |
472 | float left = paddingLeft;
473 | for (int i = 1; i <= starCount; i++) {
474 | float right = left + starWidth;
475 | if (clickedX >= left && clickedX <= right) {
476 | if (this.rating == i) {
477 | setRating(0);
478 | } else {
479 | setRating(i);
480 | }
481 | break;
482 | }
483 |
484 | left += (starWidth + starMargin);
485 | }
486 | }
487 |
488 | public float getRating() {
489 | return rating;
490 | }
491 | }
492 |
--------------------------------------------------------------------------------
/ratingstar/src/main/java/com/idlestar/ratingstar/StarModel.java:
--------------------------------------------------------------------------------
1 | package com.idlestar.ratingstar;
2 |
3 | import android.graphics.RectF;
4 |
5 | /**
6 | * Holds all vertexes (x,y) and bounds (outerRect) info about a drawing Star.
7 | * used by {@link RatingStarView}, Most calculations (about x,y、size etc.) is done here.
8 | *
9 | * [Based Idea or Concept]
10 | *
11 | * ## Standard Coordinate:
12 | * The coordinate is —— toward right for x+ ,toward up for y+ .
13 | *
14 | * ## 5 outer vertexes
15 | * The outer circle's (means "circumcircle") radius is 1f, original point O is the star's center,
16 | * so, the 5 vertexes at 5 outer corner is (from top A, at clockwise order):
17 | *
18 | * A(0,1)
19 | * B(cos18°,sin18°)
20 | * C(cos54°,-sin54°)
21 | * D(-cos54°,-sin54°)
22 | * E(-cos18°,sin18°)
23 | *
24 | * Created by hxw on 2017-04-23.
25 | */
26 | class StarModel {
27 |
28 | private static final String TAG = "StarModel";
29 | public static final float DEFAULT_THICKNESS = 0.5f;
30 | public static final float MIN_THICKNESS = 0.3f;
31 | public static final float MAX_THICKNESS = 0.9f;
32 | public static final float DEFAULT_SCALE_FACTOR = 0.9511f;
33 | private float currentScaleFactor = DEFAULT_SCALE_FACTOR;
34 | private RectF outerRect = new RectF();
35 | private float currentThicknessFactor = DEFAULT_THICKNESS;
36 |
37 | /**
38 | * @param thicknessFactor see {@link #setThickness(float)}
39 | */
40 | public StarModel(float thicknessFactor) {
41 | reset(thicknessFactor);
42 | }
43 |
44 | public StarModel() {
45 | this(DEFAULT_THICKNESS);
46 | }
47 |
48 | /**
49 | * Reset all vertexes values to based on radius-1f, will call adjustCoordinate() automatically,
50 | * So after reset() the Coordinate is match with Android.
51 | *
52 | * @param thickness {@link #setThicknessOnStandardCoordinate }
53 | */
54 | private void reset(float thickness) {
55 | currentScaleFactor = DEFAULT_SCALE_FACTOR;
56 | initAllVertexesToStandard();
57 | updateOuterRect();
58 | setThicknessOnStandardCoordinate(thickness);
59 | adjustCoordinate();
60 | }
61 |
62 | public void setDrawingOuterRect(int left, int top, int height) {
63 | // ScaleFactor=1f means width is 1f
64 | float resizeFactor = height / aspectRatio;
65 | offsetStar(-outerRect.left, -outerRect.top);
66 | changeScaleFactor(resizeFactor);
67 | offsetStar(left, top);
68 | updateOuterRect();
69 | }
70 |
71 | public void moveStarTo(float left, float top) {
72 | float offsetX = left - outerRect.left;
73 | float offsetY = left - outerRect.top;
74 | offsetStar(offsetX, offsetY);
75 | updateOuterRect();
76 | }
77 |
78 | // region vertexes fields
79 |
80 | /**
81 | * 10 float values for star's 5 vertex's (x,y) —— outer circle's radius is 1f (
82 | * NOTE: In the "Standard Coordinate".) , first vertex is for top corner, in clockwise order.
83 | */
84 | private static final float[] starVertexes = new float[]{
85 | -0.9511f, 0.3090f, // E (left)
86 | 0.0000f, 1.0000f, // A (top vertex)
87 | 0.9511f, 0.3090f, // B (right)
88 | 0.5878f, -0.8090f, // C (bottom right)
89 | -0.5878f, -0.8090f, // D (bottom left)
90 | };
91 |
92 | /**
93 | * ratio = height / width.
94 | * width is think as 1f, because the star's width is lager.
95 | * NOTE: In the "Standard Coordinate"
96 | */
97 | private static final float aspectRatio
98 | = (starVertexes[3] - starVertexes[7]) / (starVertexes[4] - starVertexes[0]);
99 |
100 | /**
101 | * firstVertex is vertex: E (very left one)
102 | *
103 | * @see StarModel
104 | */
105 | private VertexF firstVertex;
106 |
107 | /**
108 | * All star vertexes, from the most left one. then clockwise.
109 | *
110 | * NOTE: init or update by {@link #initAllVertexesToStandard() }
111 | *
112 | * @see #firstVertex
113 | * @see #starVertexes
114 | */
115 | private VertexF[] vertexes;
116 |
117 | // endregion
118 |
119 | private void initAllVertexesToStandard() {
120 | if (firstVertex == null) {
121 | firstVertex = new VertexF(starVertexes[0], starVertexes[1]);
122 | } else {
123 | firstVertex.x = starVertexes[0];
124 | firstVertex.y = starVertexes[1];
125 | }
126 |
127 | // create all 10 vertexes into #vertexes
128 | if (vertexes == null) {
129 | vertexes = new VertexF[10];
130 | vertexes[0] = firstVertex;
131 |
132 | for (int i = 1; i < 10; i++) {
133 | vertexes[i] = new VertexF();
134 | vertexes[i - 1].next = vertexes[i];
135 | }
136 |
137 | // link tail and head
138 | vertexes[9].next = vertexes[0];
139 | }
140 |
141 | // update all 5 outer vertexes.
142 | VertexF current = firstVertex;
143 | for (int i = 0; i < 5; i++) {
144 | current.x = starVertexes[i * 2];
145 | current.y = starVertexes[i * 2 + 1];
146 |
147 | current = current.next.next;
148 | }
149 |
150 | // update all 5 inner vertexes.
151 | VertexF prevOuter = firstVertex;
152 | for (int i = 0; i < 5; i++) {
153 | VertexF innerV = prevOuter.next;
154 |
155 | innerV.x = (prevOuter.x + innerV.next.x) / 2f;
156 | innerV.y = (prevOuter.y + innerV.next.y) / 2f;
157 |
158 | prevOuter = innerV.next;
159 | }
160 | }
161 |
162 | /**
163 | * Get vertex at index in {@link #vertexes}
164 | * @param index see {@link #vertexes}
165 | */
166 | public VertexF getVertex(int index) {
167 | return vertexes[index];
168 | }
169 |
170 | public RectF getOuterRect() {
171 | return new RectF(outerRect);
172 | }
173 |
174 | /**
175 | * Keep the star's outer bounds exactly.
176 | * NOTE: call this after any vertex value changed.
177 | */
178 | private void updateOuterRect() {
179 | outerRect.top = vertexes[2].y;
180 | outerRect.right = vertexes[4].x;
181 | outerRect.bottom = vertexes[8].y;
182 | outerRect.left = vertexes[0].x;
183 | }
184 |
185 | private void offsetStar(float left, float top) {
186 | for (int i = 0; i < vertexes.length; i++) {
187 | vertexes[i].x += left;
188 | vertexes[i].y += top;
189 | }
190 | }
191 |
192 | private void changeScaleFactor(float newFactor) {
193 | float scale = newFactor / currentScaleFactor;
194 | if (scale == 1f) return;
195 | for (int i = 0; i < vertexes.length; i++) {
196 | vertexes[i].x *= scale;
197 | vertexes[i].y *= scale;
198 | }
199 | currentScaleFactor = newFactor;
200 | }
201 |
202 | /**
203 | * change the thickness of star.
204 | * value {@link #DEFAULT_THICKNESS}is about to make a standard star.
205 | *
206 | * @param factor between {@link #MIN_THICKNESS} and {@link #MAX_THICKNESS}.
207 | */
208 | public void setThickness(float factor) {
209 | if (currentThicknessFactor == factor) return;
210 | float oldScale = currentScaleFactor;
211 | float left = outerRect.left;
212 | float top = outerRect.top;
213 |
214 | reset(factor);
215 |
216 | changeScaleFactor(oldScale);
217 | moveStarTo(left, top);
218 | }
219 |
220 | private void setThicknessOnStandardCoordinate(float thicknessFactor) {
221 | if (thicknessFactor < MIN_THICKNESS) {
222 | thicknessFactor = MIN_THICKNESS;
223 | } else if (thicknessFactor > MAX_THICKNESS) {
224 | thicknessFactor = MAX_THICKNESS;
225 | }
226 |
227 | for (int i = 1; i < vertexes.length; i += 2) {
228 | vertexes[i].x *= thicknessFactor;
229 | vertexes[i].y *= thicknessFactor;
230 | }
231 |
232 | currentThicknessFactor = thicknessFactor;
233 | }
234 |
235 | /**
236 | * reverse Y, and move to y=0
237 | */
238 | private void adjustCoordinate() {
239 | float offsetX = -outerRect.left;
240 | float offsetY = outerRect.top;
241 |
242 | for (int i = 0; i < vertexes.length; i++) {
243 | vertexes[i].y = -vertexes[i].y + offsetY;
244 | vertexes[i].x += offsetX;
245 |
246 | // standard value is in radius = 1f, so..
247 | vertexes[i].x /= 2f;
248 | vertexes[i].y /= 2f;
249 | }
250 |
251 | updateOuterRect();
252 | }
253 |
254 | /**
255 | * ratio = height / width. width is think as 1f, because the star's width is lager.
256 | * NOTE: In the "Standard Coordinate"
257 | *
258 | * @return ratio = height / width.
259 | */
260 | public static float getOuterRectAspectRatio() {
261 | return aspectRatio;
262 | }
263 |
264 | public static float getStarWidth(float starHeight) {
265 | return starHeight / getOuterRectAspectRatio();
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/ratingstar/src/main/java/com/idlestar/ratingstar/VertexF.java:
--------------------------------------------------------------------------------
1 | package com.idlestar.ratingstar;
2 |
3 | /**
4 | * Created by hxw on 2017-04-23.
5 | */
6 | class VertexF {
7 | public VertexF() {
8 | }
9 |
10 | public VertexF(float x, float y) {
11 | this.x = x;
12 | this.y = y;
13 | }
14 |
15 | public float x;
16 | public float y;
17 |
18 | public VertexF next;
19 | }
20 |
--------------------------------------------------------------------------------
/ratingstar/src/main/res/values/attrs_rating_star_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/ratingstar/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ratingstar
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':ratingstar'
2 |
--------------------------------------------------------------------------------