3

It is a difficult task to create an app for kids and i am given a task of creating an connect the dots app. example

https://play.google.com/store/apps/details?id=zok.android.dots

i have done some tutorials of onTouchEvent.

i know how to paint on screen Draw in Canvas by finger, Android

i am getting the dot coordinates using this Android: How do I get the x y coordinates within an image / ImageView? example

but I really don't know how to achieve this target. I'd really appreciate a solution to this! Thanks!

input image is https://i.stack.imgur.com/vlmcp.png

EDIT

@Override
protected void onDraw(Canvas canvas) {
//backgroundBitmap is the image i want to show in background
if(DISPLAY_ALPHABET==0)
{   
    canvas.drawBitmap(backgroundBitmap, 0f, 0f, null);
    DISPLAY_ALPHABET=1;
}
show(canvas);
}

 public void show(Canvas canvas)
{
      Paint paint = new Paint();
      int cnt=1;
     canvas.drawPaint(paint); 
 //color of numbers
 paint.setColor(Color.BLUE); 
 paint.setTextSize(16); 
 canvas.drawColor(BACKGROUND);
 ** canvas.drawBitmap(mBitmap, 0, 0, null);**
 canvas.drawPath(mPath, mPaint);
 mPaint.setColor(Color.BLACK);
 //Drawing points on canvas

 for (Point point : mPoints) {
    canvas.drawPoint(point.x, point.y, mPaint);
    canvas.drawText(""+cnt++, point.x-7, point.y-7, paint);
 }
  mPaint.setColor(Color.RED);
}
Community
  • 1
  • 1
hardik9850
  • 581
  • 1
  • 9
  • 26

1 Answers1

2

I don't have much idea about this but still felt like worth thinking

You can save the next dot coordinates in a arraylist or a vector. when you are drawing the line using canvas, check whether the Motion-Event x and y coordinates matches to that of the next point in the vector.

Once a coordinate is touched search for the next one in the vector

You can use a counter to increase the vector position, once the dot touched increment the counter.

EDIT: Check out my Demo App in this Link and check what you might need.

Ari
  • 1,296
  • 1
  • 18
  • 36
  • i got what you said ,using coordinates of dots but achieving this way would be difficult since user might not touch those coordinates set in arraylist even if we try adding or subtracting value on touched coordinates (suppose 20) – hardik9850 Jan 28 '14 at 10:34
  • See if you have the dots arranged in a order numerically, then you can check it as per the order, if the order is wrong then mark the line color different(say if correct line is green,wrong line is red), and if you don't have the dots in an order then just check all the dots coordinate when the user lifts his finger up – Ari Jan 28 '14 at 12:57
  • thank you :@Ari imgur.com/Z24yQUx,t6nL71r see this image guessing if the order is wrong is difficult as i am using MotionEvent.ACTION_MOVE: path.lineTo(pointX, pointY); public float[][] co_ordinates={{18,429},{68,220},{169,26},{245,220},{279,426}}; this are the coordinates ,but this logic will fail on different screensize device. – hardik9850 Jan 29 '14 at 06:57
  • Please add this links as links in your question, I'm not able to open the link from here – Ari Jan 29 '14 at 07:39
  • done,any alternative you can suggest? what if we allow user to only touch the dots and if he is touching the dots in order only then line should be drawn. – hardik9850 Jan 29 '14 at 08:03
  • No you can do like user can draw line anywhere but if its not in correct coordinates then that line color will be different, suppose user draws line from 1 to 3 instead of 2, then he should be able to draw the line but when he will be done drawing the line the line color will be different,you can add a erase button which will erase all the lines again – Ari Jan 29 '14 at 09:26
  • yes,i tried that yesterday but then i found that the static coordinates will work for only devices of my screen size.another problem is that finding if user is on correct track in 'MotionEvent.ACTION_MOVE' slows down the app because we are comparing xy coordinates every single time – hardik9850 Jan 30 '14 at 05:46
  • Just compare it when he raises his finger up, don't put a listener on it, it will slow the app a lot, by the way please tell me how are you finding the dot coordinates from the image?? are you placing the dots dynamically or you are taking static values of the dots in that device you are checking? – Ari Jan 30 '14 at 05:50
  • i am taking static values of the dots (public float[][] co_ordinates={{18,429},{68,220},{169,26},{245,220},{279,426}}; ) – hardik9850 Jan 30 '14 at 05:53
  • well that is not at all good, it will be like too much of device specific, like whichever device you are testing it, try to create the dots dynamically as per the device dimension – Ari Jan 30 '14 at 05:56
  • what if user starts from 1st dot and goes to 2,3,4,5 and raises his finger ,ideally he is right but our logic will fail then – hardik9850 Jan 30 '14 at 05:57
  • 1 last step,sorry to trouble you again. How to change these coordinates as per the screen size? – hardik9850 Jan 30 '14 at 09:42
  • I think its better to do some calculation as per the device dimensions, for example let x=100,y=150 now if(ldpi){x*1 & y*1} else if(mdpi){x*2 y*2} else if(hdpi){x*4 y*2} I think you got the idea. After completing this total thing post atleast a demo project in github or anywhere, I would love to see what you have done. – Ari Jan 30 '14 at 10:10
  • another problem,i have that image as a background (canvas.setBitmap(backgroundBitmap)) and i am drawing points on canvas : for (Point point : mPoints) { canvas.drawPoint(point.x, point.y, mPaint); canvas.drawText(""+cnt++, point.x-7, point.y-7, paint); } the line is getting drawn but at MotionEvent.ACTION_UP event the line vanishes ,i think because the background bitmaps overlaps the canvas and directly erases the working. do u know how to solve this ? – hardik9850 Feb 03 '14 at 07:26
  • Don't inflate the background everytime just do it once when you are opening that screen or when you will refresh the view – Ari Feb 03 '14 at 07:47
  • wait i bit im trying to upload my code in github once it is done i will send the link to you check it there, im not unable to understand what prb u r facing right now – Ari Feb 03 '14 at 09:36
  • Check my Edit in my answer. – Ari Feb 03 '14 at 14:22
  • forgot to ask your email id. – hardik9850 Feb 07 '14 at 13:29
  • Hi, @hardikm, can you please tell me if your working code is available in github? – Gabriella Angelova Jan 11 '18 at 16:01
  • It's not on GitHub, it was my first app back in good old days.I will try to create that app again or will find an app on GitHub. – hardik9850 Jan 12 '18 at 16:34