diff --git a/.gitignore b/.gitignore
index 144cfe7..b62d661 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
.idea
/library/build
*.iml
+**/*.iml
diff --git a/app/app.iml b/app/app.iml
deleted file mode 100644
index a6444d1..0000000
--- a/app/app.iml
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- generateDebugAndroidTestSources
- generateDebugSources
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 735cbe1..039c27a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
- buildToolsVersion "23.0.1"
+ buildToolsVersion "23.0.2"
defaultConfig {
applicationId "io.techery.properratingbar.sample"
@@ -22,8 +22,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:23.0.1'
- compile 'com.android.support:design:23.0.1'
+ compile 'com.android.support:appcompat-v7:23.1.1'
+ compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile project(':library')
}
diff --git a/app/src/main/java/io/techery/properratingbarsample/MainActivity.java b/app/src/main/java/io/techery/properratingbarsample/MainActivity.java
index dd7df9e..48ee587 100644
--- a/app/src/main/java/io/techery/properratingbarsample/MainActivity.java
+++ b/app/src/main/java/io/techery/properratingbarsample/MainActivity.java
@@ -16,8 +16,12 @@ public class MainActivity extends AppCompatActivity {
@Bind(R.id.rootView)
ViewGroup rootView;
- @Bind(R.id.ratingBar)
- ProperRatingBar ratingBar;
+ @Bind(R.id.upperRatingBar)
+ ProperRatingBar upperRatingBar;
+ @Bind(R.id.lowerRatingBar)
+ ProperRatingBar lowerRatingBar;
+
+ private String[] ticksArray = new String[] {"$", "★"};
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -27,17 +31,24 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//
- ratingBar.setListener(ratingListener);
+ lowerRatingBar.setListener(ratingListener);
+ }
+
+ @OnClick(R.id.toggleTick) void toggleTick() { // here goes shit-code. No time to do properly
+ String tick;
+ if (upperRatingBar.getSymbolicTick().equals(ticksArray[0])) tick = ticksArray[1];
+ else tick = ticksArray[0];
+ upperRatingBar.setSymbolicTick(tick);
}
@OnClick(R.id.getRatingButton) void getRatingClicked() {
Snackbar.make(rootView,
- String.format(getString(R.string.get_rating_snack_caption_format), ratingBar.getRating()),
+ String.format(getString(R.string.get_rating_snack_caption_format), lowerRatingBar.getRating()),
Snackbar.LENGTH_SHORT).show();
}
@OnClick(R.id.setRatingButton) void setRatingClicked() {
- ratingBar.setRating(2);
+ lowerRatingBar.setRating(2);
Snackbar.make(rootView, R.string.set_rating_snack_caption, Snackbar.LENGTH_SHORT).show();
}
diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml
index 7b6f83d..7ca04f6 100644
--- a/app/src/main/res/layout/content_main.xml
+++ b/app/src/main/res/layout/content_main.xml
@@ -23,6 +23,7 @@
/>
+
+
ProperRatingBar with symbolic tick:
ProperRatingBar with drawable tick, with attached listener, clickable:
+ Switch tick
Get rating
Set rating to \'2\'
Rating was set to \'2\'
diff --git a/library/AndroidManifest.xml b/library/AndroidManifest.xml
index 7cbb7f4..ffc9b26 100644
--- a/library/AndroidManifest.xml
+++ b/library/AndroidManifest.xml
@@ -1,5 +1,5 @@
diff --git a/library/build.gradle b/library/build.gradle
index 18f06e1..e3fb74a 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -5,7 +5,7 @@ group = "io.techery"
android {
compileSdkVersion 23
- buildToolsVersion "23.0.1"
+ buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
@@ -25,5 +25,5 @@ repositories {
mavenCentral()
}
dependencies {
- compile 'com.android.support:support-annotations:23.0.1'
+ compile 'com.android.support:support-annotations:23.1.1'
}
diff --git a/library/src/io/techery/properratingbar/ProperRatingBar.java b/library/src/io/techery/properratingbar/ProperRatingBar.java
index e1138c3..7648caf 100644
--- a/library/src/io/techery/properratingbar/ProperRatingBar.java
+++ b/library/src/io/techery/properratingbar/ProperRatingBar.java
@@ -74,7 +74,6 @@ public class ProperRatingBar extends LinearLayout {
public ProperRatingBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
- addChildren(context);
}
private void init(Context context, AttributeSet attrs) {
@@ -82,12 +81,12 @@ private void init(Context context, AttributeSet attrs) {
//
totalTicks = a.getInt(R.styleable.ProperRatingBar_prb_totalTicks, DF_TOTAL_TICKS);
rating = a.getInt(R.styleable.ProperRatingBar_prb_defaultRating, DF_DEFAULT_TICKS);
- if (rating > totalTicks) rating = totalTicks;
- lastSelectedTickIndex = rating - 1;
+ //
isClickable = a.getBoolean(R.styleable.ProperRatingBar_prb_clickable, DF_CLICKABLE);
//
symbolicTick = a.getString(R.styleable.ProperRatingBar_prb_symbolicTick);
if (symbolicTick == null) symbolicTick = context.getString(DF_SYMBOLIC_TICK_RES);
+ //
customTextSize = a.getDimensionPixelSize(R.styleable.ProperRatingBar_android_textSize,
context.getResources().getDimensionPixelOffset(DF_SYMBOLIC_TEXT_SIZE_RES));
customTextStyle = a.getInt(R.styleable.ProperRatingBar_android_textStyle, DF_SYMBOLIC_TEXT_STYLE);
@@ -101,14 +100,24 @@ private void init(Context context, AttributeSet attrs) {
tickSpacing = a.getDimensionPixelOffset(R.styleable.ProperRatingBar_prb_tickSpacing,
context.getResources().getDimensionPixelOffset(DF_TICK_SPACING_RES));
//
+ afterInit();
+ //
+ a.recycle();
+ }
+
+ private void afterInit() {
+ if (rating > totalTicks) rating = totalTicks;
+ lastSelectedTickIndex = rating - 1;
+ //
if (tickNormalDrawable == null || tickSelectedDrawable == null) {
useSymbolicTick = true;
}
//
- a.recycle();
+ addChildren(this.getContext());
}
private void addChildren(Context context) {
+ this.removeAllViews();
for (int i = 0; i < totalTicks; i++) {
addChild(context, i);
}
@@ -239,7 +248,7 @@ public SavedState[] newArray(int size) {
}
///////////////////////////////////////////////////////////////////////////
- // them getters and setters methods
+ // Them getter and setter methods
///////////////////////////////////////////////////////////////////////////
/**
@@ -254,9 +263,14 @@ public RatingListener getListener() {
/**
* Set the {@link RatingListener} to be called when user taps rating bar's ticks
* @param listener listener to set
+ *
+ * @throws IllegalArgumentException if listener is null
*/
public void setListener(RatingListener listener) {
+ if (listener == null) throw new IllegalArgumentException("listener cannot be null!");
+
this.listener = listener;
+ this.isClickable = true;
}
/**
@@ -284,4 +298,13 @@ public void setRating(int rating) {
lastSelectedTickIndex = rating - 1;
redrawChildren();
}
+
+ public void setSymbolicTick(String tick) {
+ this.symbolicTick = tick;
+ afterInit();
+ }
+
+ public String getSymbolicTick() {
+ return this.symbolicTick;
+ }
}