Hello Circle

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Hello Circle

Postby kellbot » Sat Jun 27, 2009 5:21 pm

Sort of a graphical version of "hello world" I put this "hello circle" mini tutorial together, mostly as a way of documenting my own work for future use.

The program places a red dot on the screen wherever you touch.

I'm sure there are a number of things I could be doing better, but it can at least serve as a starting point for folks. Any feedback is appreciated.

http://www.kellbot.com/2009/06/android-hello-circle/
kellbot
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Jun 27, 2009 5:17 pm

Top

Postby smbody » Tue Jul 21, 2009 1:37 pm

nice tutorial! TNX!
smbody
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jul 21, 2009 1:31 pm

Re: Hello Circle

Postby feduza » Fri Oct 23, 2009 12:12 am

Thank you for your tutor!

But in the emulator this works very slow. Will it works the same on the real device?

Can I use this tutor to make simple game?
Те жив!
feduza
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Sep 27, 2009 3:03 pm

Postby rmcdonal » Thu Nov 12, 2009 5:43 am

I'm pretty new, but this has been the best tutorial I've seen yet. In other words, it's very easy, direct, and gratifying. Thanks!
rmcdonal
Freshman
Freshman
 
Posts: 2
Joined: Thu Nov 12, 2009 5:38 am
Location: Seattle

missing..

Postby rmcdonal » Thu Nov 12, 2009 5:48 am

I forgot to mention, there were a couple of things I added. An import to the main class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.view.MotionEvent;
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


A return to the onTouch method:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         main.setOnTouchListener(new OnTouchListener() {
  2.  
  3.                 public boolean onTouch(View v, MotionEvent e) {
  4.  
  5.                         float x = e.getX();
  6.  
  7.                         float y = e.getY();
  8.  
  9.                         FrameLayout flView = (FrameLayout) v;
  10.  
  11.                         flView.addView(new Ball(getParent(), x, y, 25));
  12.  
  13.                        
  14.  
  15.                         return true;
  16.  
  17.                 }
  18.  
  19.         });
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


And, I added an extra circle as a test in the Ball class (for fun and test):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.content.Context;
  2.  
  3. import android.graphics.Canvas;
  4.  
  5. import android.graphics.Color;
  6.  
  7. import android.graphics.Paint;
  8.  
  9. import android.view.View;
  10.  
  11.  
  12.  
  13. public class Ball extends View {
  14.  
  15.  
  16.  
  17.         private final float x;
  18.  
  19.         private final float y;
  20.  
  21.         private final int r;
  22.  
  23.         private final Paint mRed = new Paint(Paint.ANTI_ALIAS_FLAG);
  24.  
  25.         private final Paint mBlack = new Paint(Paint.ANTI_ALIAS_FLAG);
  26.  
  27.        
  28.  
  29.        
  30.  
  31.         public Ball(Context context, float x, float y, int r) {
  32.  
  33.                 super(context);
  34.  
  35.                 this.x = x;
  36.  
  37.                 this.y = y;
  38.  
  39.                 this.r = r;
  40.  
  41.                 mRed.setColor(Color.RED);
  42.  
  43.                 mBlack.setColor(Color.BLACK);          
  44.  
  45.         }
  46.  
  47.        
  48.  
  49.         @Override
  50.  
  51.         protected void onDraw(Canvas canvas) {
  52.  
  53.                 super.onDraw(canvas);
  54.  
  55.                 canvas.drawCircle(x, y, r, mRed);
  56.  
  57.                 canvas.drawCircle(x, y, r/2, mBlack);
  58.  
  59.         }
  60.  
  61.  
  62.  
  63. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
rmcdonal
Freshman
Freshman
 
Posts: 2
Joined: Thu Nov 12, 2009 5:38 am
Location: Seattle

Postby Jadis » Thu Nov 12, 2009 3:13 pm

Hah, hello! I found your tutorial about a week ago and have been reading and reading to try and figure out how to clear the canvas each time Ball() is called. Do you have any ideas? I'm still very new to Java, and even moreso to android :shock:
Jadis
Freshman
Freshman
 
Posts: 7
Joined: Thu Oct 29, 2009 9:11 pm

Top

Postby Cyphic » Fri Nov 13, 2009 9:04 pm

First tutorial I've tried on anddev.org. Got it working with the comments on the post. Also did some changes to it, only having one circle which moves etc. Thanks!
Cyphic
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Nov 13, 2009 8:48 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests