3

I have rotated a dial around its center with the helop from the link below:

http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/

Now I have an icon beside the dialer and I need to rotate it around the dialer, along with the dialer in a circular path.

    private void rotateLogo(float degrees){
                 Matrix nMatrix = new Matrix();
                 Bitmap peopleOrg = BitmapFactory.decodeResource(getResources(), R.drawable.peoplelogo);
                 float translateX = dialerWidth / 2 - dialerWidth / 2;
                 float translateY = dialerHeight / 2 - dialerWidth / 2;
                 nMatrix.preTranslate(-turntable.getWidth()/2, -turntable.getHeight()/2);
                 nMatrix.postRotate(degrees, translateX, translateY);
                 nMatrix.postTranslate(turntable.getWidth()/2, turntable.getHeight()/2); 
                 Bitmap peopleScale = Bitmap.createBitmap(peopleOrg, 0, 0, peopleOrg.getWidth(), peopleOrg.getHeight(), nMatrix, true);
                 peopleLogo.setImageBitmap(peopleScale);        
                 peopleLogo.setImageMatrix(nMatrix);                  
    }

This just causes the image to rotate around its own center and not around the dialer's center point. I cant find out where i am wrong :(

Updates

  1. I basically need the logo to move in a circular path and be a clickable view.
  2. Tried using rotateAnim but the view doesnt animate and i have trouble getting the onclick event.
  3. Would like any help that can rotate the same using matrices
Community
  • 1
  • 1
Preethi
  • 154
  • 14

1 Answers1

2

Try only rotate with peopleOrg width and height.

nMatrix.postRotate(degrees, peopleOrg.getWidth()/2, peopleOrg.getHeight()/2);

Update :

Now that you let me know that your logo should be a clickable view, merging the logo image with your dialer is not applicable. To rotate the logo view around the center of dialer you should be actually calculating the (top,left) point for your logo view and moving it around, than just rotating it.

Use sine and cosine functions to get the point on the circumference of an imaginary circle for drawing your logo view.

This post will help you with calculations : How do I calculate a point on a circle’s circumference?

Community
  • 1
  • 1
Ron
  • 24,175
  • 8
  • 56
  • 97
  • i had initially used translateX and later changed to dialerWidth, as per my understanding in matrix operations you first translate the point you need rotate about and then set it back. i had initially done only pretranslate, but read in http://groups.google.com/group/android-developers/browse_thread/thread/a3050b5902af33b7 that both must be done. – Preethi Jun 19 '12 at 12:09
  • Even just calling `setIMageMatrix` should work. No need to create bitmaps. Just set the bitmap to image view and set the matrix.. – Ron Jun 19 '12 at 13:12
  • sorry for the late reply. i tried the mentioned updates but the image still rotates about its own center point, not about a point – Preethi Jun 20 '12 at 03:43
  • what do you mean "not about a point"? What should be the pivot point for roatation? the logo center point or the dialer center point? As I understand, both are centered at same point over each other. Now you need to rotate the logo along with the dialer.. Is that what you want? – Ron Jun 20 '12 at 07:18
  • i wish i could attach an image to confirm what i need. i need the logo to rotate around the center of dialer. – Preethi Jun 20 '12 at 07:34
  • Center points of both images are not aligned over each other..? – Ron Jun 20 '12 at 07:38
  • No, they are not :( thats why i was using translate to first translate the center and then rotate like i had seen in other links – Preethi Jun 20 '12 at 07:39
  • You should get the distance between the center of logo and center of dialer. translate the logo by this distance, rotate, and translate back to original.. I cant be more specific as you have not given snapshot.. – Ron Jun 20 '12 at 07:42
  • Thats what i had tried to implement in the code in the question, but it doesnot make any difference.. the logo still rotates about its own center and not about the center of the dial. – Preethi Jun 20 '12 at 07:47
  • I think you r not calculating the translateX and Y properly. – Ron Jun 20 '12 at 07:50
  • why dont you merge both the images? that way you will have to rotate just 1 image. Does the logo change every now and then, for it to be the reason for not merging them both? – Ron Jun 20 '12 at 07:53
  • it is actually a button and i wanted to handle the onclick event that is why i was not merging it to one image.. – Preethi Jun 20 '12 at 07:58
  • 1
    You should be actually calculating the top left point for your logo view and moving it around, then just rotating the logo. Use sin/cos function to get the point on the circumference of the circle at a given degree to draw your view. – Ron Jun 20 '12 at 08:09
  • 1
    Using sin function is not that difficult, but figuring out the what parameters and calculations to do is. So that will take some time. Sorry I cant see any other way. – Ron Jun 20 '12 at 16:27
  • Raise a bounty as soon as its due, to get someone else interested. Also edit your question and add all revelations that happened in these comments. – Ron Jun 20 '12 at 16:34
  • Thanks a lot for the help so far.. i dont have enough reputation to raise a bounty. will add the updates . Thanks once again :) – Preethi Jun 21 '12 at 03:22