// DrawRivers Example // Source code file: MyView.java // Draw the rivers in the onDraw // method of this class. package it372.smiths.drawrivers; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; import java.io.InputStream; import java.util.Scanner; public class MyView extends View { private InputStream is; private Scanner s; public MyView(Context context) { super(context); is = getResources( ).openRawResource(R.raw.rivers); s = new Scanner(is); } @Override public void onDraw(Canvas canvas) { float prevx = 0.0f; float prevy = 0.0f; Paint paint = new Paint( ); paint.setColor(Color.BLUE); paint.setStrokeWidth(3.0f); s.nextLine( ); while(s.hasNextLine( )) { String line = s.nextLine( ); String[ ] fields = line.split(","); float x = 30.0f * Float.parseFloat(fields[0]); float y = 30.0f * Float.parseFloat(fields[1]); int startPoint = Integer.parseInt(fields[2]); if (startPoint == 0) { canvas.drawLine(prevx, prevy, x, y, paint); } prevx = x; prevy = y; } s.close( ); } }