Some changes I made while using your control
GoogleCodeExporter opened this issue · 0 comments
GoogleCodeExporter commented
Hi! this is the list of changes I made to your code to adapt it for my needs,
with comments, you might be insterested to see them:
Index: src/kankan/wheel/widget/WheelView.java
===================================================================
--- src/kankan/wheel/widget/WheelView.java (revision 20)
+++ src/kankan/wheel/widget/WheelView.java (working copy)
@@ -22,14 +22,15 @@
import java.util.LinkedList;
import java.util.List;
-import kankan.wheel.R;
import kankan.wheel.widget.adapters.WheelViewAdapter;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
+import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -45,7 +46,7 @@
public class WheelView extends View {
/** Top and bottom shadows colors */
- private static final int[] SHADOWS_COLORS = new int[] { 0xFF111111,
+ private static final int[] SHADOWS_COLORS = new int[] { 0xEEEEEEEE,
0x00AAAAAA, 0x00AAAAAA };
/** Top and bottom items offset (to hide that) */
@@ -424,7 +425,10 @@
*/
private void initResourcesIfNecessary() {
if (centerDrawable == null) {
- centerDrawable =
getContext().getResources().getDrawable(R.drawable.wheel_val);
+ centerDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, new
int[]{Color.argb(0x70,0x22, 0x22, 0x22), Color.argb(0x70,0xEE, 0xEE, 0xEE)});
+ ((GradientDrawable)centerDrawable).setStroke(1, Color.argb(0x70, 0x33,
0x33, 0x33));
+ ((GradientDrawable)centerDrawable).setGradientType(GradientDrawable.LINEAR_G
RADIENT);
+ ((GradientDrawable)centerDrawable).setGradientRadius(90);
}
if (topShadow == null) {
@@ -435,7 +439,26 @@
bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
}
- setBackgroundResource(R.drawable.wheel_bg);
+ Drawable[] layers = new Drawable[3];
+
+ layers[0] = new GradientDrawable(Orientation.BOTTOM_TOP, new
int[]{Color.argb(0xFF,0x33, 0x33, 0x33), Color.argb(0xFF,0xDD, 0xDD, 0xDD)});
+ ((GradientDrawable)layers[0]).setStroke(1, Color.argb(0xFF, 0x33, 0x33,
0x33));
+
((GradientDrawable)layers[0]).setGradientType(GradientDrawable.LINEAR_GRADIENT);
+ ((GradientDrawable)layers[0]).setGradientRadius(90);
+
+ layers[1] = new GradientDrawable(Orientation.TOP_BOTTOM, new
int[]{Color.argb(0xFF,0xAA, 0xAA, 0xAA), Color.argb(0xFF,0xFF, 0xFF, 0xFF)});
+
((GradientDrawable)layers[1]).setGradientType(GradientDrawable.LINEAR_GRADIENT);
+ ((GradientDrawable)layers[1]).setGradientRadius(90);
+ layers[1].setBounds(getLeft() - 4, getTop() - 1, getRight() - 4,
getBottom() - 1 + getHeight()/2 );
+
+ layers[2] = new GradientDrawable(Orientation.BOTTOM_TOP, new
int[]{Color.argb(0xFF,0xAA, 0xAA, 0xAA), Color.argb(0xFF,0xFF, 0xFF, 0xFF)});
+
((GradientDrawable)layers[2]).setGradientType(GradientDrawable.LINEAR_GRADIENT);
+ ((GradientDrawable)layers[2]).setGradientRadius(90);
+ layers[2].setBounds(getLeft() - 4, getTop() - getHeight()/2 - 1,
getRight() - 4, getBottom() - 1 );
+
+ LayerDrawable ld = new LayerDrawable(layers);
+
+ setBackgroundDrawable(ld);
}
/**
@@ -622,7 +648,7 @@
distance -= getItemHeight() / 2;
}
int items = distance / getItemHeight();
- if (items != 0 && isValidItemIndex(currentItem + items)) {
+ if (isValidItemIndex(currentItem + items)) {
notifyClickListenersAboutClick(currentItem + items);
}
}
In main class I changed the shadow color to white (absolutely optional), added
programmatical generation of gradients instead of resource one - the case is,
jar does not contain those resources so the project is unusable unless you do
that directly importing the code. Click listeners will notify the selected item
click as well - I needed universal behaviour, and you can check in the listener
if it's the selected item and skip it, if you want
Index: src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java
===================================================================
--- src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java (revision 20)
+++ src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java (working
copy)
@@ -177,7 +177,7 @@
* @param index the item index
* @return the text of specified items
*/
- protected abstract CharSequence getItemText(int index);
+ public abstract CharSequence getItemText(int index);
@Override
public View getItem(int index, View convertView, ViewGroup parent) {
Index: src/kankan/wheel/widget/adapters/AdapterWheel.java
===================================================================
--- src/kankan/wheel/widget/adapters/AdapterWheel.java (revision 20)
+++ src/kankan/wheel/widget/adapters/AdapterWheel.java (working copy)
@@ -54,7 +54,7 @@
}
@Override
- protected CharSequence getItemText(int index) {
+ public CharSequence getItemText(int index) {
return adapter.getItem(index);
}
The method getItemText has been made public, since some users might want to
implement the same behaviour for different wheels and might need the contained
strings for display in the list or wherever they want. This allows us to cast
the similar wheel adapters to abstract and use the strings
Original issue reported on code.google.com by volkov.r...@gmail.com
on 14 Dec 2012 at 12:22