I am interested in implementing a user interface navigation control mechanism based on a wheel shaped device (or pie chart shaped or circle shaped) in my Android app.
I would like only half of the wheel to be visible at any time. That is, only the top half of the wheel should be visible since the bottom half should be below the border of the screen. The user can then turn the 'half wheel' to show options hidden by the screen border. The visible top half should then be divided into three parts like a pie chart, so the user can press either one of them to invoke some action. The following pic should explain (it is an example with seven (A-G) options).
http://imgur.com/lNu1F
The rotation itself should not be hard, but I am having a hard time understanding how to position the wheel so that half of it is outside the actual screen. I am thinking that loading the entire wheel (but hiding half of it) is best, since that is that graphics I have and it will also allow a smooth animation when the user swipes to show some other options. How can I make Android show the wheel in this way?
Also. Any comment on how to implement the 'swipe along the wheel shape' would be appreciated.
Thank you.
So for the wheel - you are hving trouble knowing how to position the wheel because you are using XML to align you objects and would like to use something like "Align Object Center To Bottom" which does not exist.
Here is one approach that might work fine: Mask the wheel view.
Is it possible to mask a View in android?
As for swipe the wheel along, I would register the wheel to take touche events, and use only the horizontal componenet of move events to apply to the rotation of the wheel. This setup is common in audio software that uses knobs.
However if you want to have it stick to the users finger in a more realistic fashion, you will need to do the following:
When the user first touches the wheel, calculate the angle from the wheel center to the finger.
Every time the finger moves, check the angle from the wheel center to the finger - and rotate the wheel the amount that the angle has changed from the last touch event.
The formula for getting the angle between two points is this:
Float angleInRadians = Math.atan2(point1.y-point2.y, point1.x-point2.x);
Related
I am trying to learn some more about gestures and graphics in Android, so I am trying to make a sort of game where you start with a ball (just a red circle) in the middle of the screen, and if you swipe in a direction, the ball will be launched in that direction, bouncing of the screen etc. Now, I have succeeded in detecting when somebody swipes in a certain direction, and currently I just display the direction on the screen. My question is: how do I continue? How can I draw the ball, make the user able to move it and make it bounce off the sides of the screen? I think I need to use onDraw somehow, but I'm not sure.
There's a guy with similar problem, he has managed to get circles going around the screen and bouncing from the edges, you may use his code as a basis for your drawing and animation routines: Moving circles in android
I was just playing with Android SDK Demos and I found the rotating dialer example which you can find here : Android Rotating Dialer and I'm curious about one thing. How can I set the image to rotate only when I click on image..not inside in or out. I don't want to rotate it if I click at the center (in white area) or outside of the image (again in white area).
Any suggestions how can I achieve this?
Interesting question.
This would be possible by modifiying the code of myOnTouchListener. Just before the switch statement you would perform a calculation to check whether the x,y coords of the touch were outside an inner radius and inside an outer radius.
Some simple Pythagoras and it wouldn't be too hard. If this was not the case then return true at that point.
I want to build a custom gallery.
a 2d Dimension gallery , user can swiping page vertical and horizontal.
i store information like a 2d map, each page have its x and y coordinate.
========================
like first page is (0,0)
upper of first page is (0,-1)
second page is (1,0)
========================
if upper of first page swiping right , then will go second page.
but i don't know how do i go forward.
Thanks
-- update --
more detail what i want.
originally gallery only have left and right swiping.
user see photo by swiping left or right.
now user not only swiping left or right, but also swiping up and down to see the photo.
data structure is, each page have own x and y coordinate.
It is very hard to give an answer for this - you mention no programming language nor more specifics of what it is you want to do.
I guess it depends on where you want this gallery - one solution could be to make it webbased - while this is a sidescroller and I am planning to use the top buttons to change the page you should think about it...
http://globability.org/webapp/androidtest_20111105_1.html
It is a rough prototype - scrolling sideways on the Android with buttons following top and bottom.
I am not sure how you'd go about the automatic changing of pages whether you should create a button boundry, or set some sort of a listener that follows the x,y coordinates in the visible viewport and set event listeners that are triggered when the visible area reaches specific coordinates, use a different layout than me off course - but it all depends on the programming language - the example is plain old HTML but you get the idea, and the listener thing for x/y in visible viewport should be valid for most modern programming languages.
how to overlap a horizontal gallery with a vertical gallery - has some ideas for how to create similar functionality
Depending upon the user i may need to move it to right ,left,top or bottom.
Should i use animation for the purpose?
Or is there any method to move image dynamically?
I meant the things in android application
You use animation for a movement that has a distinct start and stop point. For example you might move the image right to left at a button push. It would slide a cross the screen and then appear back at its original position.
If you wanted to move things around this way you could do so by having 2 (or more) copies of the same view.. hiding the view at the old position and showing it again at the new one. You generally won't be stopping this animation between its begin and end point.
If you want some more interactive movement (say move along with the user's finger on the screen), you'll need to make use of the canvas and some touch listeners. In that case I recommend looking up drag and drop samples as they address what is needed for this to happen (and then some).
i am trying to do this:
1) user long touches the screen,
2) a circle/ball pops up (centered around the user's finger) and grows in size as long as the user is touching the screen
3) once the user lets go of the finger, the ball (now in its final size) will bounce around.
i think i have the bouncing around figure out from the DivideAndConquer example, but i am not sure how to animate the ball's growth. i looked at various view flipper examples such as this:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
but it seems like view flipper is best for swapping two static pictures. i wasn't able to find a good view animator example other than the flippers. also, i would prefer to use images as opposed to just a circle. can someone point me in the right direction?
thanks.
Here are two simple tutorials to help you get started with drawing basic animations including touch input: balls bouncing randomly around the screen and basic drag and drop.
In brief: You're right, ViewFlipper is really not suited for this. You want to draw on a Canvas by making your own custom View. This is the basic framework for 2D graphics. Canvases let you draw image files, solid colors and other things to the screen, while applying transformations ot them at the same time. Handling the user input (i.e. the finger on the screen) is done via the onTouchEvent(...) method, which lets you do something when the finger touches the screen, moves on the screen or lifts off. Have a play with those two tutorials, they should give you the basics.
If you're using a bitmap on a canvas to draw it
http://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap(android.graphics.Bitmap, android.graphics.Matrix, android.graphics.Paint)
Use a scale matrix, the identity multiplied by the scalar of the size you want the image to be.