I have been searching for many hours and cant find a reason for this
so I thought I would put it to the list. I am creating a custom view
which I am planning on animating. Here is what I do based on the
pattern shown by LabelView example in the API demos.
What I am expecting is to log the value "23,56 34,45 39,23" to be
printed when the shape initializes but instead the value s is NULL. I
thought I followed the example exactly. I am using r8 of the API.
Any help or pointers appreciated.
//custom view
public class StarOne extends View {
private static final String TAG = StarOne.class.getName();
private ShapeDrawable[] mDrawables;
private static class MyShapeDrawable extends ShapeDrawable {
private Paint mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public MyShapeDrawable(Shape s) {
super(s);
mStrokePaint.setStyle(Paint.Style.STROKE);
//006837
mStrokePaint.setARGB(0xFF, 0x00, 0x68, 0x37);
}
public Paint getStrokePaint() {
return mStrokePaint;
}
@Override protected void onDraw(Shape s, Canvas c, Paint p) {
//006837
s.draw(c, p);
s.draw(c, mStrokePaint);
}
private void setText(String s)
{
this.setText(s);
}
private String getText()
{
return this.getText();
}
}
public StarOne(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
initShape();
}
//should load custom properties
public StarOne(Context context, AttributeSet attrs) {
super(context, attrs);
initShape();
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.StarOne);
CharSequence s = a.getString(R.styleable.StarOne_points);
if(s != null)
Log.d(TAG, s.toString());
}
public StarOne(Context context) {
super(context);
initShape();
}
private void initShape()
{
Animation runner =
AnimationUtils.loadAnimation(super.getContext(),
R.anim.star_runner);
startAnimation(runner);
setFocusable(true);
//<polygon fill="#8CC63F" stroke="#006837"
points="88.541,44.544 70.2,41.768 57.515,55.303 54.488,37.002
37.696,29.121
// 54.166,20.586 56.472,2.181 69.678,15.207 87.896,11.713
79.588,28.298 "/>
Path path = new Path();
path.moveTo(88,44);
path.lineTo(70,41);
path.lineTo(56,55);
path.lineTo(54,37);
path.lineTo(38,29);
path.lineTo(54,21);
path.lineTo(56,2);
path.lineTo(70,15);
path.lineTo(88,12);
path.lineTo(80,28);
path.close();
mDrawables = new ShapeDrawable[1];
mDrawables[0] = new MyShapeDrawable(new PathShape(path, 100,
100));
mDrawables[0].getPaint().setColor(Color.argb(0xFF, 0x8C, 0xC6,
0x3F));
MyShapeDrawable msd = (MyShapeDrawable)mDrawables[0];
msd.getStrokePaint().setStrokeWidth(4);
}
@Override protected void onDraw(Canvas canvas) {
//setting width and height and location of Pie Chart
mDrawables[0].setBounds(10, 10, 100, 100);
mDrawables[0].draw(canvas);
}
}
//layout with custom namespace
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.sightlyinc.com/apk/res/
com.sightlyinc.ratecred.android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/
white">
<com.sightlyinc.ratecred.android.view.StarOne
app:points="23,56 34,45 39,23"
android:animationCache="true"
android:id="@+id/sample_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
//atts.xml file in values dir
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="StarOne">
<attr name="points" format="string" />
</declare-styleable>
</resources>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en