3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar;
7 |
8 | import android.content.res.ColorStateList;
9 | import android.graphics.ColorFilter;
10 | import android.graphics.PorterDuff;
11 | import android.graphics.drawable.Drawable;
12 |
13 | import androidx.annotation.ColorInt;
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 |
17 | /**
18 | * A {@code Drawable} that is tintable.
19 | */
20 | public interface TintableDrawable {
21 |
22 | /**
23 | * Specifies tint color for this drawable.
24 | *
25 | * A Drawable's drawing content will be blended together with its tint
26 | * before it is drawn to the screen. This functions similarly to
27 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)}.
28 | *
29 | *
30 | * To clear the tint, pass {@code null} to
31 | * {@link #setTintList(ColorStateList)}.
32 | *
33 | * Note: Setting a color filter via
34 | * {@link Drawable#setColorFilter(ColorFilter)} or
35 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
36 | *
37 | *
38 | * @param tintColor Color to use for tinting this drawable
39 | * @see #setTintList(ColorStateList)
40 | * @see #setTintMode(PorterDuff.Mode)
41 | */
42 | void setTint(@ColorInt int tintColor);
43 |
44 | /**
45 | * Specifies tint color for this drawable as a color state list.
46 | *
47 | * A Drawable's drawing content will be blended together with its tint
48 | * before it is drawn to the screen. This functions similarly to
49 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)}.
50 | *
51 | * Note: Setting a color filter via
52 | * {@link Drawable#setColorFilter(ColorFilter)} or
53 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
54 | *
55 | *
56 | * @param tint Color state list to use for tinting this drawable, or
57 | * {@code null} to clear the tint
58 | * @see #setTint(int)
59 | * @see #setTintMode(PorterDuff.Mode)
60 | */
61 | void setTintList(@Nullable ColorStateList tint);
62 |
63 | /**
64 | * Specifies a tint blending mode for this drawable.
65 | *
66 | * Defines how this drawable's tint color should be blended into the drawable
67 | * before it is drawn to screen. Default tint mode is {@link PorterDuff.Mode#SRC_IN}.
68 | *
69 | * Note: Setting a color filter via
70 | * {@link Drawable#setColorFilter(ColorFilter)} or
71 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
72 | *
73 | *
74 | * @param tintMode A Porter-Duff blending mode
75 | * @see #setTint(int)
76 | * @see #setTintList(ColorStateList)
77 | */
78 | void setTintMode(@NonNull PorterDuff.Mode tintMode);
79 | }
80 |
--------------------------------------------------------------------------------
/library/src/main/java/me/zhanghai/android/materialratingbar/internal/DrawableCompat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar.internal;
7 |
8 | import android.graphics.PorterDuff;
9 |
10 | public class DrawableCompat {
11 |
12 | /**
13 | * Parses a {@link PorterDuff.Mode} from a tintMode attribute's enum value.
14 | */
15 | public static PorterDuff.Mode parseTintMode(int value, PorterDuff.Mode defaultMode) {
16 | switch (value) {
17 | case 3: return PorterDuff.Mode.SRC_OVER;
18 | case 5: return PorterDuff.Mode.SRC_IN;
19 | case 9: return PorterDuff.Mode.SRC_ATOP;
20 | case 14: return PorterDuff.Mode.MULTIPLY;
21 | case 15: return PorterDuff.Mode.SCREEN;
22 | case 16: return PorterDuff.Mode.ADD;
23 | default: return defaultMode;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/me/zhanghai/android/materialratingbar/internal/ThemeUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar.internal;
7 |
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 |
11 | public class ThemeUtils {
12 |
13 | private ThemeUtils() {}
14 |
15 | public static int getColorFromAttrRes(int attrRes, Context context) {
16 | TypedArray a = context.obtainStyledAttributes(new int[] { attrRes });
17 | try {
18 | return a.getColor(0, 0);
19 | } finally {
20 | a.recycle();
21 | }
22 | }
23 |
24 | public static float getFloatFromAttrRes(int attrRes, Context context) {
25 | TypedArray a = context.obtainStyledAttributes(new int[] { attrRes });
26 | try {
27 | return a.getFloat(0, 0);
28 | } finally {
29 | a.recycle();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/mrb_star_border_icon_black_36dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
14 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/mrb_star_icon_black_36dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
14 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
20 |
21 |
25 |
26 |
29 |
30 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | apply plugin: 'com.android.application'
7 |
8 | android {
9 |
10 | compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
11 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
12 |
13 | defaultConfig {
14 | applicationId "me.zhanghai.android.materialratingbar.sample"
15 | minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
16 | targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
17 | versionCode Integer.parseInt(project.VERSION_CODE)
18 | versionName project.VERSION_NAME
19 | }
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 |
26 | signingConfigs {
27 | release {
28 | storeFile file('../../github.jks')
29 | storePassword System.console() != null ? System.console().readLine("\nKeystore password: ") : ""
30 | keyAlias 'materialratingbar'
31 | keyPassword System.console() != null ? System.console().readLine("\nKey password: ") : ""
32 | }
33 | }
34 |
35 | buildTypes {
36 | release {
37 | minifyEnabled true
38 | shrinkResources true
39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
40 | signingConfig signingConfigs.release
41 | }
42 | }
43 | }
44 |
45 | dependencies {
46 | implementation fileTree(dir: 'libs', include: ['*.jar'])
47 | implementation 'androidx.appcompat:appcompat:1.1.0'
48 | implementation 'com.jakewharton:butterknife:10.2.0'
49 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
50 | implementation project(':library')
51 | }
52 |
--------------------------------------------------------------------------------
/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 /opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
11 |
12 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
34 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/zhanghai/android/materialratingbar/sample/AboutActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar.sample;
7 |
8 | import android.os.Bundle;
9 | import android.text.method.LinkMovementMethod;
10 | import android.view.MenuItem;
11 | import android.widget.TextView;
12 |
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import butterknife.BindView;
15 | import butterknife.ButterKnife;
16 |
17 | public class AboutActivity extends AppCompatActivity {
18 |
19 | @BindView(R.id.version)
20 | TextView mVersionText;
21 | @BindView(R.id.github)
22 | TextView mGithubText;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 |
28 | setContentView(R.layout.about_activity);
29 | ButterKnife.bind(this);
30 |
31 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
32 |
33 | String version = getString(R.string.about_version_format, BuildConfig.VERSION_NAME);
34 | mVersionText.setText(version);
35 | mGithubText.setMovementMethod(LinkMovementMethod.getInstance());
36 | }
37 |
38 | @Override
39 | public boolean onOptionsItemSelected(MenuItem item) {
40 | switch (item.getItemId()) {
41 | case android.R.id.home:
42 | AppUtils.navigateUp(this);
43 | return true;
44 | default:
45 | return super.onOptionsItemSelected(item);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/zhanghai/android/materialratingbar/sample/AppUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar.sample;
7 |
8 | import android.app.Activity;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.content.pm.PackageInfo;
12 | import android.content.pm.PackageManager;
13 | import android.os.Bundle;
14 |
15 | import androidx.core.app.NavUtils;
16 | import androidx.core.app.TaskStackBuilder;
17 |
18 | public class AppUtils {
19 |
20 | private AppUtils() {}
21 |
22 | public static PackageInfo getPackageInfo(Context context) {
23 | try {
24 | return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
25 | } catch (PackageManager.NameNotFoundException e) {
26 | // Should never happen.
27 | throw new RuntimeException(e);
28 | }
29 | }
30 |
31 | // From http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp .
32 | public static void navigateUp(Activity activity, Bundle extras) {
33 | Intent upIntent = NavUtils.getParentActivityIntent(activity);
34 | if (upIntent != null) {
35 | if (extras != null) {
36 | upIntent.putExtras(extras);
37 | }
38 | if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
39 | // This activity is NOT part of this app's task, so create a new task
40 | // when navigating up, with a synthesized back stack.
41 | TaskStackBuilder.create(activity)
42 | // Add all of this activity's parents to the back stack.
43 | .addNextIntentWithParentStack(upIntent)
44 | // Navigate up to the closest parent.
45 | .startActivities();
46 | } else {
47 | // This activity is part of this app's task, so simply
48 | // navigate up to the logical parent activity.
49 | // According to http://stackoverflow.com/a/14792752/2420519
50 | //NavUtils.navigateUpTo(activity, upIntent);
51 | upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
52 | activity.startActivity(upIntent);
53 | }
54 | }
55 | activity.finish();
56 | }
57 |
58 | public static void navigateUp(Activity activity) {
59 | navigateUp(activity, null);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/sample/src/main/java/me/zhanghai/android/materialratingbar/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | package me.zhanghai.android.materialratingbar.sample;
7 |
8 | import android.content.Intent;
9 | import android.os.Bundle;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.animation.Animation;
13 | import android.view.animation.LinearInterpolator;
14 | import android.view.animation.Transformation;
15 | import android.widget.RatingBar;
16 |
17 | import androidx.appcompat.app.AppCompatActivity;
18 | import butterknife.BindViews;
19 | import butterknife.ButterKnife;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | @BindViews({
24 | R.id.framework_decimal_ratingbar,
25 | R.id.library_decimal_ratingbar,
26 | R.id.library_tinted_decimal_ratingbar
27 | })
28 | RatingBar[] mDecimalRatingBars;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 |
34 | setContentView(R.layout.main_activity);
35 | ButterKnife.bind(this);
36 |
37 | mDecimalRatingBars[0].startAnimation(new RatingAnimation());
38 | }
39 |
40 | @Override
41 | public boolean onCreateOptionsMenu(Menu menu) {
42 | getMenuInflater().inflate(R.menu.menu_main, menu);
43 | return true;
44 | }
45 |
46 | @Override
47 | public boolean onOptionsItemSelected(MenuItem item) {
48 | switch (item.getItemId()) {
49 | case R.id.action_about:
50 | startActivity(new Intent(this, AboutActivity.class));
51 | default:
52 | return super.onOptionsItemSelected(item);
53 | }
54 | }
55 |
56 | private class RatingAnimation extends Animation {
57 |
58 | public RatingAnimation() {
59 | setDuration(mDecimalRatingBars[0].getNumStars()
60 | * 4 * getResources().getInteger(android.R.integer.config_longAnimTime));
61 | setInterpolator(new LinearInterpolator());
62 | setRepeatCount(Animation.INFINITE);
63 | }
64 |
65 | @Override
66 | protected void applyTransformation(float interpolatedTime, Transformation t) {
67 | int progress = Math.round(interpolatedTime * mDecimalRatingBars[0].getMax());
68 | for (RatingBar ratingBar : mDecimalRatingBars) {
69 | ratingBar.setProgress(progress);
70 | }
71 | }
72 |
73 | @Override
74 | public boolean willChangeTransformationMatrix() {
75 | return false;
76 | }
77 |
78 | @Override
79 | public boolean willChangeBounds() {
80 | return false;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/sample/src/main/launcher_icon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/launcher_icon-web.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/about_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
15 |
16 |
25 |
26 |
34 |
35 |
42 |
43 |
50 |
51 |
58 |
59 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/main_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
15 |
16 |
24 |
25 |
26 |
27 |
32 |
33 |
38 |
39 |
48 |
49 |
54 |
55 |
63 |
64 |
69 |
70 |
80 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
102 |
103 |
108 |
109 |
115 |
116 |
121 |
122 |
130 |
131 |
132 |
133 |
138 |
139 |
144 |
145 |
153 |
154 |
159 |
160 |
166 |
167 |
172 |
173 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
20 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/launcher_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/res/mipmap-hdpi/launcher_icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/launcher_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/res/mipmap-mdpi/launcher_icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/launcher_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/res/mipmap-xhdpi/launcher_icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/launcher_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/res/mipmap-xxhdpi/launcher_icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/launcher_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/sample/src/main/res/mipmap-xxxhdpi/launcher_icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | 24dp
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | #f44336
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | 16dp
10 | 16dp
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 | MaterialRatingBar Sample
11 |
12 | Normal Layout
13 | Wide Layout
14 | Decimal Step Size
15 | Framework Implementation
16 | Library Implementation
17 | Library Implementation (Tinted)
18 | About
19 |
20 | About
21 | MaterialRatingBar
22 | Version %1$s
23 | Zhang Hai 2016
24 | View on GitHub
25 |
26 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/screenshot/google_io.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/google_io.jpg
--------------------------------------------------------------------------------
/screenshot/google_io_raw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/google_io_raw.png
--------------------------------------------------------------------------------
/screenshot/google_play_store.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/google_play_store.jpg
--------------------------------------------------------------------------------
/screenshot/google_play_store_raw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/google_play_store_raw.png
--------------------------------------------------------------------------------
/screenshot/material_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/material_icons.png
--------------------------------------------------------------------------------
/screenshot/sample_app.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/sample_app.jpg
--------------------------------------------------------------------------------
/screenshot/sample_app_raw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghai/MaterialRatingBar/50ec0bff414cbdf7993d3c110c6cd4db0c70a099/screenshot/sample_app_raw.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 Zhang Hai
3 | * All Rights Reserved.
4 | */
5 |
6 | include ':sample', ':library'
7 |
--------------------------------------------------------------------------------