Set7Activity.java
package ps.set7;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Set7Activity extends Activity implements OnItemClickListener
{
/**
* www.master-gtu.blogspot.com
* pankaj sharma (8460479175)
* vijay chavda (8460420769)
*/
String flags[]={"circle","square","rectangle","round rect","arc","oval"};
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv=(ListView) findViewById(R.id.listView1);
ArrayAdapter<String>aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,flags);
lv.setAdapter(aa);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
Intent i=new Intent(this, screen.class);
i.putExtra("id", arg2);
startActivity(i);
}
}
screen.java
package ps.set7;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
import android.view.View;
public class screen extends Activity
{
/**
* www.master-gtu.blogspot.com
* pankaj sharma (8460479175)
* vijay chavda (8460420769)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new screen1(this,getIntent().getIntExtra("id", 0)));
}
private class screen1 extends View
{
int shape=0;
public screen1(Context context, int id) {
super(context);
shape=id;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Shape s=new Shape() {
@Override
public void draw(Canvas c, Paint paint)
{
paint.setColor(Color.RED);
if(shape==0)
{
c.drawCircle(100, 100, 50, paint);
}
else if(shape==1)
{
c.drawRect(100, 100, 200, 200,paint);
}
else if(shape==2)
{
c.drawRect(100, 100, 150, 200, paint);
}
else if(shape==3)
{
RectF rect=new RectF(100, 100, 150, 200);
c.drawRoundRect(rect, 5, 5, paint);
}
else if(shape==4)
{
RectF rect=new RectF(100, 100, 150, 200);
c.drawArc(rect, 0, 150, true, paint);
}
else if(shape==5)
{
RectF rect=new RectF(100, 100, 150, 200);
c.drawOval(rect,paint);
}
}
};
ShapeDrawable obj=new ShapeDrawable();
obj.setShape(s);
obj.draw(canvas);
}
}
}
very well written and organized tutorials…its indeed a great help for beginners like me to keep up the interest and at the same time learn this important subject.
ReplyDeletepresentations
nice one
ReplyDeletejignesh kanjariya