import java.util.ArrayList;
-
/**
* <p>
* Visual indicator of progress in some operation. Displays a bar to the user
final Drawable progressDrawable = a.getDrawable(R.styleable.ProgressBar_progressDrawable);
if (progressDrawable != null) {
- // Calling this method can set mMaxHeight, make sure the corresponding
- // XML attribute for mMaxHeight is read after calling this method
- setProgressDrawableTiled(progressDrawable);
+ // Calling setProgressDrawable can set mMaxHeight, so make sure the
+ // corresponding XML attribute for mMaxHeight is read after calling
+ // this method.
+ if (needsTileify(progressDrawable)) {
+ setProgressDrawableTiled(progressDrawable);
+ } else {
+ setProgressDrawable(progressDrawable);
+ }
}
setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));
- setSecondaryProgress(
- a.getInt(R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));
+ setSecondaryProgress(a.getInt(
+ R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));
final Drawable indeterminateDrawable = a.getDrawable(
R.styleable.ProgressBar_indeterminateDrawable);
if (indeterminateDrawable != null) {
- setIndeterminateDrawableTiled(indeterminateDrawable);
+ if (needsTileify(indeterminateDrawable)) {
+ setIndeterminateDrawableTiled(indeterminateDrawable);
+ } else {
+ setIndeterminateDrawable(indeterminateDrawable);
+ }
}
mOnlyIndeterminate = a.getBoolean(
}
/**
+ * Returns {@code true} if the target drawable needs to be tileified.
+ *
+ * @param dr the drawable to check
+ * @return {@code true} if the target drawable needs to be tileified,
+ * {@code false} otherwise
+ */
+ private static boolean needsTileify(Drawable dr) {
+ if (dr instanceof LayerDrawable) {
+ final LayerDrawable orig = (LayerDrawable) dr;
+ final int N = orig.getNumberOfLayers();
+ for (int i = 0; i < N; i++) {
+ if (needsTileify(orig.getDrawable(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ if (dr instanceof StateListDrawable) {
+ final StateListDrawable in = (StateListDrawable) dr;
+ final int N = in.getStateCount();
+ for (int i = 0; i < N; i++) {
+ if (needsTileify(in.getStateDrawable(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // If there's a bitmap that's not wrapped with a ClipDrawable or
+ // ScaleDrawable, we'll need to wrap it and apply tiling.
+ if (dr instanceof BitmapDrawable) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
mSampleTile = tileBitmap;
}
- final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
- final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
- Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
- shapeDrawable.getPaint().setShader(bitmapShader);
+ final BitmapDrawable clone = (BitmapDrawable) bitmap.getConstantState().newDrawable();
+ clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
- // Ensure the tint and filter are propagated in the correct order.
- shapeDrawable.setTintList(bitmap.getTint());
- shapeDrawable.setTintMode(bitmap.getTintMode());
- shapeDrawable.setColorFilter(bitmap.getColorFilter());
-
- return clip ? new ClipDrawable(
- shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
+ if (clip) {
+ return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
+ } else {
+ return clone;
+ }
}
return drawable;
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:state_pressed="true"
+ android:color="?attr/colorControlActivated"
+ android:alpha="?attr/disabledAlpha" />
+ <item
+ android:color="?attr/colorControlNormal"
+ android:alpha="?attr/disabledAlpha" />
+</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
- <bitmap android:src="@drawable/btn_rating_star_off_mtrl_alpha"
- android:tint="?attr/colorControlActivated" />
+ <bitmap
+ android:src="@drawable/btn_rating_star_off_mtrl_alpha"
+ android:tint="?attr/colorControlActivated"
+ android:alpha="?attr/disabledAlpha"/>
</item>
<item>
- <bitmap android:src="@drawable/btn_rating_star_off_mtrl_alpha"
+ <bitmap
+ android:src="@drawable/btn_rating_star_off_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
- <bitmap android:src="@drawable/btn_rating_star_on_mtrl_alpha"
+ <bitmap
+ android:src="@drawable/btn_rating_star_on_mtrl_alpha"
android:tint="?attr/colorControlActivated" />
</item>
<item>
- <bitmap android:src="@drawable/btn_rating_star_on_mtrl_alpha"
+ <bitmap
+ android:src="@drawable/btn_rating_star_on_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
</selector>
limitations under the License.
-->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@id/background"
- android:drawable="@drawable/ratingbar_full_empty_material" />
- <item android:id="@id/secondaryProgress"
- android:drawable="@drawable/ratingbar_full_empty_material" />
- <item android:id="@id/progress"
- android:drawable="@drawable/ratingbar_full_filled_material" />
-</layer-list>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true">
+ <bitmap
+ android:src="@drawable/btn_rating_star_off_mtrl_alpha"
+ android:tint="?attr/colorControlActivated" />
+ </item>
+ <item>
+ <bitmap
+ android:src="@drawable/btn_rating_star_off_mtrl_alpha"
+ android:tint="?attr/colorControlNormal" />
+ </item>
+</selector>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/background">
+ <bitmap
+ android:src="@drawable/ic_star_black_36dp"
+ android:tint="?attr/colorControlNormal"
+ android:alpha="?attr/disabledAlpha" />
+ </item>
+ <item android:id="@+id/secondaryProgress">
+ <bitmap
+ android:src="@drawable/ic_star_half_black_36dp"
+ android:tint="?attr/colorControlActivated" />
+ </item>
+ <item android:id="@+id/progress">
+ <bitmap
+ android:src="@drawable/ic_star_black_36dp"
+ android:tint="?attr/colorControlActivated"
+ android:tileModeX="repeat" />
+ </item>
+</layer-list>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/background">
+ <bitmap
+ android:src="@drawable/ic_star_black_48dp"
+ android:tint="@color/ratingbar_background_material" />
+ </item>
+ <item android:id="@+id/secondaryProgress">
+ <bitmap
+ android:src="@drawable/ic_star_half_black_48dp"
+ android:tint="?attr/colorControlActivated" />
+ </item>
+ <item android:id="@+id/progress">
+ <bitmap
+ android:src="@drawable/ic_star_black_48dp"
+ android:tint="?attr/colorControlActivated" />
+ </item>
+</layer-list>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/background">
+ <bitmap
+ android:src="@drawable/ic_star_black_16dp"
+ android:tint="?attr/colorControlNormal"
+ android:alpha="?attr/disabledAlpha" />
+ </item>
+ <item android:id="@+id/secondaryProgress">
+ <bitmap
+ android:src="@drawable/ic_star_half_black_16dp"
+ android:tint="?attr/colorControlActivated" />
+ </item>
+ <item android:id="@+id/progress">
+ <bitmap
+ android:src="@drawable/ic_star_black_16dp"
+ android:tint="?attr/colorControlActivated"
+ android:tileModeX="repeat" />
+ </item>
+</layer-list>
<item>@drawable/progress_large_material</item>
<item>@drawable/progress_medium_material</item>
<item>@drawable/progress_small_material</item>
- <item>@drawable/ratingbar_full_empty_material</item>
- <item>@drawable/ratingbar_full_filled_material</item>
- <item>@drawable/ratingbar_full_material</item>
+ <item>@drawable/ratingbar_material</item>
+ <item>@drawable/ratingbar_small_material</item>
+ <item>@drawable/ratingbar_indicator_material</item>
<item>@drawable/scrollbar_handle_material</item>
<item>@drawable/scrubber_control_material_anim</item>
<item>@drawable/scrubber_control_selector_material</item>
</style>
<style name="Widget.Material.RatingBar" parent="Widget.RatingBar">
- <item name="progressDrawable">@drawable/ratingbar_full_material</item>
- <item name="indeterminateDrawable">@drawable/ratingbar_full_material</item>
+ <item name="progressDrawable">@drawable/ratingbar_material</item>
+ <item name="indeterminateDrawable">@drawable/ratingbar_material</item>
</style>
<style name="Widget.Material.RatingBar.Indicator" parent="Widget.RatingBar.Indicator">
- <item name="progressDrawable">@drawable/ratingbar_holo_dark</item>
- <item name="indeterminateDrawable">@drawable/ratingbar_holo_dark</item>
- <item name="minHeight">35dip</item>
- <item name="maxHeight">35dip</item>
+ <item name="progressDrawable">@drawable/ratingbar_indicator_material</item>
+ <item name="indeterminateDrawable">@drawable/ratingbar_indicator_material</item>
+ <item name="minHeight">36dp</item>
+ <item name="maxHeight">36dp</item>
</style>
<style name="Widget.Material.RatingBar.Small" parent="Widget.RatingBar.Small">
- <item name="progressDrawable">@drawable/ratingbar_small_holo_dark</item>
- <item name="indeterminateDrawable">@drawable/ratingbar_small_holo_dark</item>
- <item name="minHeight">16dip</item>
- <item name="maxHeight">16dip</item>
+ <item name="progressDrawable">@drawable/ratingbar_small_material</item>
+ <item name="indeterminateDrawable">@drawable/ratingbar_small_material</item>
+ <item name="minHeight">16dp</item>
+ <item name="maxHeight">16dp</item>
</style>
<style name="Widget.Material.ScrollView" parent="Widget.ScrollView"/>
<style name="Widget.Material.Light.ProgressBar.Small.Inverse" parent="Widget.Material.ProgressBar.Small.Inverse"/>
<style name="Widget.Material.Light.ProgressBar.Large.Inverse" parent="Widget.Material.ProgressBar.Large.Inverse"/>
<style name="Widget.Material.Light.SeekBar" parent="Widget.Material.SeekBar"/>
- <style name="Widget.Material.Light.RatingBar" parent="Widget.Material.RatingBar" />
-
- <style name="Widget.Material.Light.RatingBar.Indicator" parent="Widget.RatingBar.Indicator">
- <item name="progressDrawable">@drawable/ratingbar_holo_light</item>
- <item name="indeterminateDrawable">@drawable/ratingbar_holo_light</item>
- <item name="minHeight">35dip</item>
- <item name="maxHeight">35dip</item>
- </style>
-
- <style name="Widget.Material.Light.RatingBar.Small" parent="Widget.RatingBar.Small">
- <item name="progressDrawable">@drawable/ratingbar_small_holo_light</item>
- <item name="indeterminateDrawable">@drawable/ratingbar_small_holo_light</item>
- <item name="minHeight">16dip</item>
- <item name="maxHeight">16dip</item>
- </style>
-
+ <style name="Widget.Material.Light.RatingBar" parent="Widget.Material.RatingBar"/>
+ <style name="Widget.Material.Light.RatingBar.Indicator" parent="Widget.Material.RatingBar.Indicator"/>
+ <style name="Widget.Material.Light.RatingBar.Small" parent="Widget.Material.RatingBar.Small"/>
<style name="Widget.Material.Light.ScrollView" parent="Widget.Material.ScrollView"/>
<style name="Widget.Material.Light.HorizontalScrollView" parent="Widget.Material.HorizontalScrollView"/>
<style name="Widget.Material.Light.Spinner" parent="Widget.Material.Spinner" />