aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-12-14 19:54:13 +0100
committerBananeweizen <bananeweizen@gmx.de>2014-12-14 19:54:13 +0100
commit2d89b3f88b9ff79933b1fd07ee08cbead160f441 (patch)
tree007397f502153f1e5071d2647f5b29a46826d7dc
parent319a8bca0acde29f5e2bd80e90774e0f33afe192 (diff)
downloadcgeo-2d89b3f88b9ff79933b1fd07ee08cbead160f441.zip
cgeo-2d89b3f88b9ff79933b1fd07ee08cbead160f441.tar.gz
cgeo-2d89b3f88b9ff79933b1fd07ee08cbead160f441.tar.bz2
refactoring: replace star images in cache details by rating bar
-rw-r--r--main/res/drawable-hdpi/star_half.pngbin766 -> 0 bytes
-rw-r--r--main/res/drawable-mdpi/star_half.pngbin522 -> 0 bytes
-rw-r--r--main/res/drawable/star_rating.xml9
-rw-r--r--main/res/layout/cache_information_item.xml8
-rw-r--r--main/res/layout/star_image.xml11
-rw-r--r--main/res/values/styles.xml11
-rw-r--r--main/src/cgeo/geocaching/ui/CacheDetailsCreator.java25
7 files changed, 27 insertions, 37 deletions
diff --git a/main/res/drawable-hdpi/star_half.png b/main/res/drawable-hdpi/star_half.png
deleted file mode 100644
index 000208c..0000000
--- a/main/res/drawable-hdpi/star_half.png
+++ /dev/null
Binary files differ
diff --git a/main/res/drawable-mdpi/star_half.png b/main/res/drawable-mdpi/star_half.png
deleted file mode 100644
index 1ea9152..0000000
--- a/main/res/drawable-mdpi/star_half.png
+++ /dev/null
Binary files differ
diff --git a/main/res/drawable/star_rating.xml b/main/res/drawable/star_rating.xml
new file mode 100644
index 0000000..0d8a8e2
--- /dev/null
+++ b/main/res/drawable/star_rating.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+android:id/background"
+ android:drawable="@drawable/star_off" />
+ <item android:id="@+android:id/secondaryProgress"
+ android:drawable="@drawable/star_off" />
+ <item android:id="@+android:id/progress"
+ android:drawable="@drawable/star_on" />
+</layer-list> \ No newline at end of file
diff --git a/main/res/layout/cache_information_item.xml b/main/res/layout/cache_information_item.xml
index 1b766e4..d213e56 100644
--- a/main/res/layout/cache_information_item.xml
+++ b/main/res/layout/cache_information_item.xml
@@ -34,17 +34,17 @@
android:textIsSelectable="false"
android:textSize="14sp" />
- <LinearLayout
+ <RatingBar
android:id="@+id/stars"
+ style="@style/cacheRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
+ android:layout_gravity="center_horizontal"
android:layout_toRightOf="@+id/value"
android:baselineAligned="false"
android:gravity="center_vertical"
- android:orientation="horizontal"
- android:visibility="gone" >
- </LinearLayout>
+ android:visibility="gone" />
<TextView
android:id="@+id/addition"
diff --git a/main/res/layout/star_image.xml b/main/res/layout/star_image.xml
deleted file mode 100644
index 809a17d..0000000
--- a/main/res/layout/star_image.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="12dip"
- android:layout_height="12dip"
- android:layout_gravity="center"
- android:layout_margin="1dip"
- android:gravity="center"
- android:scaleType="fitXY"
- android:src="@drawable/star_off"
- tools:context=".ui.CacheDetailsCreator" />
diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml
index be1e1a4..5f280f2 100644
--- a/main/res/values/styles.xml
+++ b/main/res/values/styles.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- system definitions -->
@@ -338,4 +338,13 @@
<item name="android:src">@drawable/mark_green</item>
</style>
+ <style name="cacheRatingBar" parent="@android:style/Widget.RatingBar">
+ <item name="android:progressDrawable">@drawable/star_rating</item>
+ <item name="android:minHeight">12dip</item>
+ <item name="android:maxHeight">22dip</item>
+ <item name="android:max">5</item>
+ <item name="android:stepSize">0.5</item>
+ <item name="android:isIndicator">true</item>
+ </style>
+
</resources> \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
index 55e9cfc..ff52fb3 100644
--- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
+++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
@@ -17,11 +17,9 @@ import org.eclipse.jdt.annotation.NonNull;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
+import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -71,33 +69,18 @@ public final class CacheDetailsCreator {
final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, null, false);
final TextView nameView = ButterKnife.findById(layout, R.id.name);
lastValueView = ButterKnife.findById(layout, R.id.value);
- final LinearLayout layoutStars = ButterKnife.findById(layout, R.id.stars);
nameView.setText(activity.getResources().getString(nameId));
lastValueView.setText(String.format("%.1f", value) + ' ' + activity.getResources().getString(R.string.cache_rating_of) + " " + String.format("%d", max));
- createStarImages(layoutStars, value, max);
+
+ final RatingBar layoutStars = ButterKnife.findById(layout, R.id.stars);
+ layoutStars.setRating(value);
layoutStars.setVisibility(View.VISIBLE);
parentView.addView(layout);
return layout;
}
- private void createStarImages(final ViewGroup starsContainer, final float value, final int max) {
- final LayoutInflater inflater = LayoutInflater.from(activity);
-
- for (int i = 0; i < max; i++) {
- final ImageView star = (ImageView) inflater.inflate(R.layout.star_image, starsContainer, false);
- if (value - i >= 0.75) {
- star.setImageResource(R.drawable.star_on);
- } else if (value - i >= 0.25) {
- star.setImageResource(R.drawable.star_half);
- } else {
- star.setImageResource(R.drawable.star_off);
- }
- starsContainer.addView(star);
- }
- }
-
public void addCacheState(final Geocache cache) {
if (cache.isLogOffline() || cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) {
final List<String> states = new ArrayList<>(5);