├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── tr │ │ └── xip │ │ └── widget │ │ └── simpleratingview │ │ └── SimpleRatingView.java │ └── res │ ├── drawable-hdpi │ ├── ic_rating_negative.png │ ├── ic_rating_neutral.png │ └── ic_rating_positive.png │ ├── drawable-mdpi │ ├── ic_rating_negative.png │ ├── ic_rating_neutral.png │ └── ic_rating_positive.png │ ├── drawable-xhdpi │ ├── ic_rating_negative.png │ ├── ic_rating_neutral.png │ └── ic_rating_positive.png │ ├── drawable-xxhdpi │ ├── ic_rating_negative.png │ ├── ic_rating_neutral.png │ └── ic_rating_positive.png │ └── values │ ├── attrs.xml │ ├── colors.xml │ └── strings.xml ├── maven_push.gradle ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── tr │ │ └── xip │ │ └── widget │ │ └── simpleratingview │ │ └── sample │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-v21 │ └── selector.xml │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable-xxxhdpi │ └── ic_launcher.png │ ├── drawable │ └── selector.xml │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .DS_Store 4 | .idea 5 | *.iml 6 | /build 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SimpleRatingView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1189) 2 | 3 | SimpleRatingView 4 | ================ 5 | 6 | A rating toggle for Android which switches between 3 rating levels: positive, neutral, and negative. 7 | 8 | ![simpleratingview](https://cloud.githubusercontent.com/assets/2550945/5184090/c143e70e-74b4-11e4-8bfa-a7ec17416d05.gif) 9 | 10 | # Usage 11 | Since, SimpleRatingView is pushed to the Maven Central repository, all you have to do is to add the following line to your dependencies. 12 | 13 | ``` 14 | dependencies { 15 | compile 'com.github.xiprox.simpleratingview:library:+' 16 | } 17 | ``` 18 | 19 | Once you have the library added as a dependency to your project, you can start with including the view in your layout: 20 | ```xml 21 | 25 | ``` 26 | You can also customize SimpleRatingView by telling it to display the icons you want, in the color you want. The following xml attributes will allow you to set the icons for different rating levels. 27 | ``` 28 | srv:srv_positiveIcon="@drawable/rating_positive" 29 | srv:srv_neutralIcon="@drawable/rating_neutral" 30 | srv:srv_negativeIcon="@drawable/rating_negative" 31 | ``` 32 | As for a custom color, you'll need to insert the following attribute: 33 | ``` 34 | srv:srv_iconColor="@color/my_rating_icon_color" 35 | ``` 36 | 37 | On the Java side, all you have to do is catching rating changes from the view: 38 | ```java 39 | mSimpleRatingView = (SimpleRatingView) findViewById(R.id.simple_rating_view); 40 | mSimpleRatingView.setOnRatingChangedListener(new SimpleRatingView.OnRatingChangeListener() { 41 | @Override 42 | public void onRatingChanged(SimpleRatingView.Rating ratingType) { 43 | switch (ratingType) { 44 | case POSITIVE: 45 | // Do something 46 | break; 47 | case NEUTRAL: 48 | // Do something 49 | break; 50 | case NEGATIVE: 51 | // Do something 52 | break; 53 | } 54 | } 55 | }); 56 | ``` 57 | Of course, you can directly set the rating too. 58 | ```java 59 | setSelectedRating(Rating rating) 60 | ``` 61 | 62 | And lastly, all customization can be applied programmatically too: 63 | ```java 64 | setIconColor(int color) 65 | setIconColor(Resources res, int color) // Set the icon color to a color resource 66 | setPositiveIconResource(int res) 67 | setPositiveIconDrawable(Drawable drawable) 68 | setNeutralIconResource(int res) 69 | setNeutralIconDrawable(Drawable drawable) 70 | setNegativeIconResource(int res) 71 | setNegativeIconDrawable(Drawable drawable) 72 | ``` 73 | 74 | # Sample App 75 | 76 | Get it on Google Play 78 | 79 | 80 | # License 81 | ``` 82 | Copyright (C) 2014 Ihsan Isik 83 | 84 | Licensed under the Apache License, Version 2.0 (the "License"); 85 | you may not use this file except in compliance with the License. 86 | You may obtain a copy of the License at 87 | 88 | http://www.apache.org/licenses/LICENSE-2.0 89 | 90 | Unless required by applicable law or agreed to in writing, software 91 | distributed under the License is distributed on an "AS IS" BASIS, 92 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 93 | See the License for the specific language governing permissions and 94 | limitations under the License. 95 | ``` 96 | -------------------------------------------------------------------------------- /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:1.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | def isReleaseBuild() { 16 | return version.contains("SNAPSHOT") == false 17 | } 18 | 19 | allprojects { 20 | version = VERSION_NAME 21 | group = GROUP 22 | 23 | repositories { 24 | mavenCentral() 25 | jcenter() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | VERSION_NAME=1.1.0 21 | VERSION_CODE=3 22 | GROUP=com.github.xiprox.simpleratingview 23 | 24 | POM_DESCRIPTION=An android library which switches between neutral, positive, and negative rating levels on touch. 25 | POM_URL=https://github.com/xiprox/SimpleRatingView 26 | POM_SCM_URL=https://github.com/xiprox/SimpleRatingView 27 | POM_SCM_CONNECTION=scm:git@github.com:xiprox/SimpleRatingView.git 28 | POM_SCM_DEV_CONNECTION=scm:git@github.com:xiprox/SimpleRatingView.git 29 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 30 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 31 | POM_LICENCE_DIST=repo 32 | POM_DEVELOPER_ID=xiprox 33 | POM_DEVELOPER_NAME=Ihsan Isik 34 | 35 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2 36 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots 37 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 16 12:00:24 CEST 2015 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-2.4-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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .DS_Store? 3 | ._* 4 | .Spotlight-V100 5 | .Trashes 6 | ehthumbs.db 7 | Thumbs.db 8 | 9 | bin/ 10 | gen/ 11 | out/ 12 | .settings/ 13 | /build 14 | 15 | .project 16 | .classpath 17 | proguard-project.txt 18 | project.properties -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "21.1.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 7 9 | targetSdkVersion 22 10 | versionCode Integer.parseInt(project.VERSION_CODE) 11 | versionName project.VERSION_NAME 12 | } 13 | 14 | compileOptions { 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | targetCompatibility JavaVersion.VERSION_1_7 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 | } 30 | 31 | // Used to upload project to maven central 32 | // apply from: '../maven_push.gradle' -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=SimpleRatingView Library 2 | POM_ARTIFACT_ID=library 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /library/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 /Applications/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 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/java/tr/xip/widget/simpleratingview/SimpleRatingView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Ihsan Isik 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package tr.xip.widget.simpleratingview; 18 | 19 | import android.content.Context; 20 | import android.content.res.Resources; 21 | import android.content.res.TypedArray; 22 | import android.graphics.PorterDuff; 23 | import android.graphics.drawable.Drawable; 24 | import android.util.AttributeSet; 25 | import android.view.View; 26 | import android.widget.ImageView; 27 | 28 | /** 29 | * @author Ihsan Isik 30 | *

31 | * A rating selector view. Rating changes on each click, looping between neutral, positive, 32 | * and negative. 33 | *

34 | */ 35 | public class SimpleRatingView extends ImageView { 36 | 37 | public enum Rating { 38 | NEGATIVE, NEUTRAL, POSITIVE 39 | } 40 | 41 | private Rating mSelectedRating = Rating.NEUTRAL; 42 | 43 | private OnRatingChangeListener mListener; 44 | 45 | private int mIconColor; 46 | private Drawable mPositiveIcon; 47 | private Drawable mNeutralIcon; 48 | private Drawable mNegativeIcon; 49 | 50 | public SimpleRatingView(Context context) { 51 | super(context); 52 | } 53 | 54 | public SimpleRatingView(Context context, AttributeSet attrs) { 55 | super(context, attrs); 56 | init(context, attrs); 57 | } 58 | 59 | public SimpleRatingView(Context context, AttributeSet attrs, int defStyleAttr) { 60 | super(context, attrs, defStyleAttr); 61 | init(context, attrs); 62 | } 63 | 64 | private void init(Context context, AttributeSet attrs) { 65 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SimpleRatingView, 0, 0); 66 | 67 | try { 68 | mIconColor = a.getColor(R.styleable.SimpleRatingView_srv_iconColor, 69 | getResources().getColor(R.color.srv_icon_color_default)); 70 | 71 | int positiveIconRes = a.getResourceId(R.styleable.SimpleRatingView_srv_positiveIcon, 72 | R.drawable.ic_rating_positive); 73 | int neutralIconRes = a.getResourceId(R.styleable.SimpleRatingView_srv_neutralIcon, 74 | R.drawable.ic_rating_neutral); 75 | int negativeIconRes = a.getResourceId(R.styleable.SimpleRatingView_srv_negativeIcon, 76 | R.drawable.ic_rating_negative); 77 | 78 | setPositiveIconResource(positiveIconRes); 79 | setNeutralIconResource(neutralIconRes); 80 | setNegativeIconResource(negativeIconRes); 81 | } finally { 82 | a.recycle(); 83 | } 84 | 85 | setImageResource(R.drawable.ic_rating_neutral); 86 | } 87 | 88 | /** 89 | * Sets the rating level and rating image. 90 | * 91 | * @param rating The rating level to be set to the view. 92 | */ 93 | public void setSelectedRating(Rating rating) { 94 | mSelectedRating = rating; 95 | 96 | switch (rating) { 97 | case POSITIVE: 98 | setImageDrawable(mPositiveIcon); 99 | break; 100 | case NEUTRAL: 101 | setImageDrawable(mNeutralIcon); 102 | break; 103 | case NEGATIVE: 104 | setImageDrawable(mNegativeIcon); 105 | break; 106 | } 107 | } 108 | 109 | /** 110 | * Returns the currently selected rating level. 111 | * 112 | * @return Rating enum 113 | */ 114 | public Rating getSelectedRating() { 115 | return mSelectedRating; 116 | } 117 | 118 | /** 119 | * Used to set the color of the rating icons/indicators. 120 | * 121 | * @param color int color value. 122 | */ 123 | public void setIconColor(int color) { 124 | mIconColor = color; 125 | notifyIconColorChanged(); 126 | } 127 | 128 | /** 129 | * Used to set the color of the rating icons/indicators. 130 | * 131 | * @param res Resources 132 | * @param color int color resource. 133 | */ 134 | public void setIconColor(Resources res, int color) { 135 | mIconColor = getResources().getColor(color); 136 | notifyIconColorChanged(); 137 | } 138 | 139 | /** 140 | * Used to set the positive rating icon. 141 | * 142 | * @param res int icon resource. 143 | */ 144 | public void setPositiveIconResource(int res) { 145 | setPositiveIconDrawable(getResources().getDrawable(res)); 146 | } 147 | 148 | /** 149 | * Used to set the positive rating icon. 150 | * 151 | * @param drawable icon drawable. 152 | */ 153 | public void setPositiveIconDrawable(Drawable drawable) { 154 | setIconDrawable(drawable, Rating.POSITIVE); 155 | } 156 | 157 | /** 158 | * USed to set the neutral rating icon. 159 | * 160 | * @param res int icon resource. 161 | */ 162 | public void setNeutralIconResource(int res) { 163 | setNeutralIconDrawable(getResources().getDrawable(res)); 164 | } 165 | 166 | /** 167 | * Used to set the neutral rating icon. 168 | * 169 | * @param drawable icon drawable. 170 | */ 171 | public void setNeutralIconDrawable(Drawable drawable) { 172 | setIconDrawable(drawable, Rating.NEUTRAL); 173 | } 174 | 175 | /** 176 | * Used to set the negative rating icon. 177 | * 178 | * @param res int icon resource. 179 | */ 180 | public void setNegativeIconResource(int res) { 181 | setNegativeIconDrawable(getResources().getDrawable(res)); 182 | } 183 | 184 | /** 185 | * Used to set the negative rating icon. 186 | * 187 | * @param drawable icon drawable. 188 | */ 189 | public void setNegativeIconDrawable(Drawable drawable) { 190 | setIconDrawable(drawable, Rating.NEGATIVE); 191 | } 192 | 193 | /** 194 | * 195 | * 196 | * @param drawable icon drawable. 197 | * @param rating The rating level used to select the drawable to be set. 198 | */ 199 | private void setIconDrawable(Drawable drawable, Rating rating) { 200 | switch (mSelectedRating) { 201 | case NEUTRAL: 202 | mNeutralIcon = drawable; 203 | break; 204 | case POSITIVE: 205 | mPositiveIcon = drawable; 206 | break; 207 | case NEGATIVE: 208 | mNegativeIcon = drawable; 209 | break; 210 | } 211 | notifyIconChanged(); 212 | } 213 | 214 | /** 215 | * Used to attach a listener to the view. 216 | * 217 | * @param listener The listener to be attached. 218 | */ 219 | public void setOnRatingChangedListener(OnRatingChangeListener listener) { 220 | mListener = listener; 221 | this.setOnClickListener(new MyOnClickListener()); 222 | } 223 | 224 | @Override 225 | public void setImageResource(int resId) { 226 | super.setImageResource(resId); 227 | setColorFilter(); 228 | } 229 | 230 | @Override 231 | public void setImageDrawable(Drawable drawable) { 232 | super.setImageDrawable(drawable); 233 | setColorFilter(); 234 | } 235 | 236 | private void setColorFilter() { 237 | setColorFilter(mIconColor, PorterDuff.Mode.SRC_ATOP); 238 | } 239 | 240 | /** 241 | * Notifies the view that the icon color has been changed and the view should update itself 242 | */ 243 | public void notifyIconColorChanged() { 244 | setColorFilter(); 245 | } 246 | 247 | /** 248 | * Notifies the view that the icon has been changed and the view should update itself 249 | */ 250 | public void notifyIconChanged() { 251 | setSelectedRating(getSelectedRating()); 252 | } 253 | 254 | private class MyOnClickListener implements OnClickListener { 255 | 256 | @Override 257 | public void onClick(View view) { 258 | switch (mSelectedRating) { 259 | case NEUTRAL: 260 | setSelectedRating(Rating.POSITIVE); 261 | break; 262 | case POSITIVE: 263 | setSelectedRating(Rating.NEGATIVE); 264 | break; 265 | case NEGATIVE: 266 | setSelectedRating(Rating.NEUTRAL); 267 | } 268 | 269 | if (mListener != null) 270 | mListener.onRatingChanged(mSelectedRating); 271 | } 272 | } 273 | 274 | public interface OnRatingChangeListener { 275 | void onRatingChanged(Rating ratingType); 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /library/src/main/res/drawable-hdpi/ic_rating_negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-hdpi/ic_rating_negative.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-hdpi/ic_rating_neutral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-hdpi/ic_rating_neutral.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-hdpi/ic_rating_positive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-hdpi/ic_rating_positive.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-mdpi/ic_rating_negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-mdpi/ic_rating_negative.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-mdpi/ic_rating_neutral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-mdpi/ic_rating_neutral.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-mdpi/ic_rating_positive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-mdpi/ic_rating_positive.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xhdpi/ic_rating_negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xhdpi/ic_rating_negative.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xhdpi/ic_rating_neutral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xhdpi/ic_rating_neutral.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xhdpi/ic_rating_positive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xhdpi/ic_rating_positive.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xxhdpi/ic_rating_negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xxhdpi/ic_rating_negative.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xxhdpi/ic_rating_neutral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xxhdpi/ic_rating_neutral.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xxhdpi/ic_rating_positive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/library/src/main/res/drawable-xxhdpi/ic_rating_positive.png -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #454545 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SimpleRatingView 3 | 4 | positive 5 | neutral 6 | negative 7 | 8 | -------------------------------------------------------------------------------- /maven_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | apply plugin: 'signing' 3 | 4 | def sonatypeRepositoryUrl 5 | if (isReleaseBuild()) { 6 | println 'RELEASE BUILD' 7 | sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 8 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 9 | } else { 10 | println 'DEBUG BUILD' 11 | sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 12 | : "https://oss.sonatype.org/content/repositories/snapshots/" 13 | } 14 | 15 | def getRepositoryUsername() { 16 | return hasProperty('nexusUsername') ? nexusUsername : "" 17 | } 18 | 19 | def getRepositoryPassword() { 20 | return hasProperty('nexusPassword') ? nexusPassword : "" 21 | } 22 | 23 | afterEvaluate { project -> 24 | uploadArchives { 25 | repositories { 26 | mavenDeployer { 27 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 28 | 29 | pom.artifactId = POM_ARTIFACT_ID 30 | 31 | repository(url: sonatypeRepositoryUrl) { 32 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 33 | } 34 | 35 | pom.project { 36 | name POM_NAME 37 | packaging POM_PACKAGING 38 | description POM_DESCRIPTION 39 | url POM_URL 40 | 41 | scm { 42 | url POM_SCM_URL 43 | connection POM_SCM_CONNECTION 44 | developerConnection POM_SCM_DEV_CONNECTION 45 | } 46 | 47 | licenses { 48 | license { 49 | name POM_LICENCE_NAME 50 | url POM_LICENCE_URL 51 | distribution POM_LICENCE_DIST 52 | } 53 | } 54 | 55 | developers { 56 | developer { 57 | id POM_DEVELOPER_ID 58 | name POM_DEVELOPER_NAME 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | signing { 67 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 68 | sign configurations.archives 69 | } 70 | 71 | task androidJavadocs(type: Javadoc) { 72 | source = android.sourceSets.main.java.sourceFiles 73 | } 74 | 75 | task androidJavadocsJar(type: Jar) { 76 | classifier = 'javadoc' 77 | //basename = artifact_id 78 | from androidJavadocs.destinationDir 79 | } 80 | 81 | task androidSourcesJar(type: Jar) { 82 | classifier = 'sources' 83 | //basename = artifact_id 84 | from android.sourceSets.main.java.sourceFiles 85 | } 86 | 87 | artifacts { 88 | //archives packageReleaseJar 89 | archives androidSourcesJar 90 | archives androidJavadocsJar 91 | } 92 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .DS_Store? 3 | ._* 4 | .Spotlight-V100 5 | .Trashes 6 | ehthumbs.db 7 | Thumbs.db 8 | 9 | bin/ 10 | gen/ 11 | out/ 12 | .settings/ 13 | /build 14 | 15 | .project 16 | .classpath 17 | proguard-project.txt 18 | project.properties -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.1" 6 | 7 | defaultConfig { 8 | applicationId "tr.xip.widget.simpleratingview.sample" 9 | minSdkVersion 8 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_7 17 | targetCompatibility JavaVersion.VERSION_1_7 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 | compile 'com.android.support:appcompat-v7:21.0.0' 30 | compile project(':library') 31 | } 32 | -------------------------------------------------------------------------------- /sample/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 /Applications/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 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/tr/xip/widget/simpleratingview/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package tr.xip.widget.simpleratingview.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.ActionBarActivity; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | import android.widget.TextView; 8 | 9 | import tr.xip.widget.simpleratingview.SimpleRatingView; 10 | 11 | 12 | public class MainActivity extends ActionBarActivity { 13 | 14 | TextView mRatingText; 15 | SimpleRatingView mSimpleRatingView; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | mRatingText = (TextView) findViewById(R.id.rating_text); 23 | 24 | mSimpleRatingView = (SimpleRatingView) findViewById(R.id.simple_rating_view); 25 | mSimpleRatingView.setOnRatingChangedListener(new SimpleRatingView.OnRatingChangeListener() { 26 | @Override 27 | public void onRatingChanged(SimpleRatingView.Rating ratingType) { 28 | switch (ratingType) { 29 | case POSITIVE: 30 | mRatingText.setText(R.string.srv_rating_positive); 31 | break; 32 | case NEUTRAL: 33 | mRatingText.setText(R.string.srv_rating_neutral); 34 | break; 35 | case NEGATIVE: 36 | mRatingText.setText(R.string.srv_rating_negative); 37 | break; 38 | } 39 | } 40 | }); 41 | } 42 | 43 | 44 | @Override 45 | public boolean onCreateOptionsMenu(Menu menu) { 46 | // Inflate the menu; this adds items to the action bar if it is present. 47 | getMenuInflater().inflate(R.menu.menu_main, menu); 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean onOptionsItemSelected(MenuItem item) { 53 | // Handle action bar item clicks here. The action bar will 54 | // automatically handle clicks on the Home/Up button, so long 55 | // as you specify a parent activity in AndroidManifest.xml. 56 | int id = item.getItemId(); 57 | 58 | //noinspection SimplifiableIfStatement 59 | if (id == R.id.action_settings) { 60 | return true; 61 | } 62 | 63 | return super.onOptionsItemSelected(item); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v21/selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiprox/SimpleRatingView/5a8cc9fa2d5f331d30ad4cba623a658e97cff41e/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 16 | 17 | 21 | 22 | 26 | 27 | 32 | 33 | 34 | 42 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F44336 4 | #D32F2F 5 | #FFFFFF 6 | 7 | #25000000 8 | #30000000 9 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SimpleRatingView Sample 5 | Current rating 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | --------------------------------------------------------------------------------