0% found this document useful (0 votes)
6 views2 pages

Android Traffic Sign Drawing App

This document contains code for an Android application that displays traffic signs. The MainActivity class sets up the TrafficView, which overrides the onDraw method to draw different shapes and text representing traffic signs using RectF and Paint objects. Red, yellow and green ovals are drawn within a larger black rectangle to represent a stop, caution, and go traffic sign.

Uploaded by

Ehab Zaben
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Android Traffic Sign Drawing App

This document contains code for an Android application that displays traffic signs. The MainActivity class sets up the TrafficView, which overrides the onDraw method to draw different shapes and text representing traffic signs using RectF and Paint objects. Red, yellow and green ovals are drawn within a larger black rectangle to represent a stop, caution, and go traffic sign.

Uploaded by

Ehab Zaben
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Key solution : Traffic sign

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


TrafficView tView;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
tView = new TrafficView(this);

setContentView(tView);
}
}
class TrafficView extends View

{ public TrafficView(Context context)


{ super(context); }

@Override

protected void onDraw (Canvas canvas)


{
[Link](canvas);

RectF oval1 = new RectF(100, 100, 350,350);


RectF oval2 = new RectF(100, 350, 350,600);
RectF oval3 = new RectF(100, 600, 350,850);
RectF rect1 = new RectF(50,50,400,900);
RectF rect2 = new RectF(200,900,250,1500);
Paint paint = new Paint();
[Link]([Link]);
Paint p1 = new Paint();
[Link]([Link]);
Paint p2 = new Paint();
[Link]([Link]);
Paint p3 = new Paint();
[Link]([Link]);
[Link]("Parent", 30, 50, p1);
[Link]("Parent", 30, 50, p2);
[Link]("Parent", 30, 50, p3);
[Link]("Parent", 30, 50, paint);
[Link](rect2, paint);
[Link](rect1, paint);
[Link](oval1, p1);
[Link](oval2, p2);
[Link](oval3, p3);

}
}

You might also like