-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for RatingBar and SeekBar
- Loading branch information
Showing
7 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
untriggered/src/main/java/com/commit451/untriggered/UntriggeredRatingBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.commit451.untriggered; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.CallSuper; | ||
import android.support.v7.widget.AppCompatRatingBar; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* {@link AppCompatRatingBar} that allows you to set the rating without triggering the | ||
* {@link android.widget.RatingBar.OnRatingBarChangeListener} | ||
*/ | ||
public class UntriggeredRatingBar extends AppCompatRatingBar { | ||
|
||
OnRatingBarChangeListener onSeekBarChangeListener; | ||
|
||
public UntriggeredRatingBar(Context context) { | ||
super(context); | ||
} | ||
|
||
public UntriggeredRatingBar(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public UntriggeredRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
public void setOnRatingBarChangeListener(OnRatingBarChangeListener listener) { | ||
super.setOnRatingBarChangeListener(listener); | ||
onSeekBarChangeListener = listener; | ||
} | ||
|
||
/** | ||
* Set the rating without triggering the registered {@link android.widget.RatingBar.OnRatingBarChangeListener} | ||
* @param rating rating | ||
* @see {@link #setRating(float)} | ||
*/ | ||
public void setRatingUntriggered(float rating) { | ||
OnRatingBarChangeListener currentListener = onSeekBarChangeListener; | ||
setOnRatingBarChangeListener(null); | ||
setRating(rating); | ||
setOnRatingBarChangeListener(currentListener); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
untriggered/src/main/java/com/commit451/untriggered/UntriggeredSeekBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.commit451.untriggered; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.support.annotation.CallSuper; | ||
import android.support.v7.widget.AppCompatSeekBar; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* {@link AppCompatSeekBar} that allows you to set the progress without triggering the | ||
* {@link android.widget.SeekBar.OnSeekBarChangeListener} | ||
*/ | ||
public class UntriggeredSeekBar extends AppCompatSeekBar { | ||
|
||
OnSeekBarChangeListener onSeekBarChangeListener; | ||
|
||
public UntriggeredSeekBar(Context context) { | ||
super(context); | ||
} | ||
|
||
public UntriggeredSeekBar(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public UntriggeredSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
public void setOnSeekBarChangeListener(OnSeekBarChangeListener onSeekBarChangeListener) { | ||
super.setOnSeekBarChangeListener(onSeekBarChangeListener); | ||
this.onSeekBarChangeListener = onSeekBarChangeListener; | ||
} | ||
|
||
/** | ||
* Set the progress without triggering the registered {@link android.widget.SeekBar.OnSeekBarChangeListener} | ||
* @param progress progress | ||
* @see {@link #setProgress(int)} | ||
*/ | ||
public void setProgressUntriggered(int progress) { | ||
OnSeekBarChangeListener currentListener = onSeekBarChangeListener; | ||
setOnSeekBarChangeListener(null); | ||
setProgress(progress); | ||
setOnSeekBarChangeListener(currentListener); | ||
} | ||
|
||
/** | ||
* Set the progress without triggering the registered {@link android.widget.SeekBar.OnSeekBarChangeListener} | ||
* @param progress progress | ||
* @param animate animate | ||
* @see {@link #setProgress(int, boolean)} (int)} | ||
*/ | ||
@TargetApi(24) | ||
public void setProgressUntriggered(int progress, boolean animate) { | ||
OnSeekBarChangeListener currentListener = onSeekBarChangeListener; | ||
setOnSeekBarChangeListener(null); | ||
setProgress(progress, animate); | ||
setOnSeekBarChangeListener(currentListener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters