Thursday, August 25, 2011

Canvas.drawTextOnPath on circle path

Canvas.drawTextOnPath on circle path

package com.exercise.AndroidDraw;


import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.View;

public class AndroidDrawActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}

public class MyView extends View {

public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);

float width = (float)getWidth();
float height = (float)getHeight();
float radius;

if (width > height){
radius = height/4;
}else{
radius = width/4;
}

Path path = new Path();
path.addCircle(width/2,
height/2, radius,
Path.Direction.CW);

Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setTextSize(37);

canvas.drawTextOnPath(
"Android-er http://android-er.blogspot.com/",
path, 0, 0,
paint);

paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
canvas.drawTextOnPath("Android-er http://android-er.blogspot.com/",
path, 0, 0,
paint);
}
}
}