How to detect Phone Vibration - windows-phone-7

What is the difference between shake and vibrate? I need some help on these:
1) How to detect the phone vibration when phone lying on the surface.
2) How to detect the phone vibration when it is hanging.
Your help and code sample much appreciated. Thanks
--- Update
does shake mean movement along x and y ?
and Virbate means movement Up and down vertically?
// Constructor
public MainPage()
{
InitializeComponent();
acc.ReadingChanged += new EventHandler(acc_ReadingChanged);
acc.Start();
}
void acc_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => ThreadSafeAccelerometerChanged(e));
}
void ThreadSafeAccelerometerChanged(AccelerometerReadingEventArgs e)
{
XText.Text = e.X.ToString("0.000");
YText.Text = e.Y.ToString("0.000");
ZText.Text = e.Z.ToString("0.000");
}

Shake usually involves the use of accelerometer in the phone to detect any shake gesture/event. You may program your application accordingly on the occurrence of shake gesture. Whereas you may use vibration to prompt the user of some kind of output or event that has happened like in a game when you win/lose.
All in all shake is a kind of input gesture and vibration is output gesture.
For accelerometer refer this http://msdn.microsoft.com/en-us/library/ff604984.aspx
and for vibration behavior you may start of with this http://blog.xyzzer.me/2012/01/09/vibration-behaviors-for-windows-phone-part-1/
Hope it helps

Related

How to create a "clicking effect" on a 3d-object (3d-cube) in Unity3d?

I have a 3d-object (cube), which I want to use as a button. I've written the code in order to detect, if the cube was pressed but it doesn't look like it was pressed, since it lacks the "clicking animation". How can I create a clicking animation on my 3d-object ?
A good idea is to play an aninimation which skrinks the cube a bit and releases it immediately afterwards. The handler code you want to execute on a click might block the game loop, e.g. when you load a level. Then it might be useful to load the level aysnchronously to be able to see the animation. Or you execute the handler code after the animation. Or you play the scale down animation on the press event and the scale up animation on the release event.
Technically you can use the build in animation editor, the Update() method, start a coroutine or use the assets iTween or HOTween.
http://docs.unity3d.com/ScriptReference/Transform-localScale.html
Let me know if you like the idea or questions arise.
Unity makes it easier now to do this using Unity Canvas UI. Instead of real 3d buttons, you could place a canvas UI in world space at the location where you want the buttons. Add a UI Panel to the canvas then add a UI Button.
Now, you have out of the box several clicking effects. The default it color tint, but you can choose sprite swap, or animation.
If you do want animation, when you select button animation it will create an animator for you. Click on your UI button Game Object in the scene hierarchy and open the animation window. You can choose Pressed animation from the drop down, and press RECORD button, then edit your buttons scale, say make it 0.75 for x,y,z. Now when you click on the button it will animate a cool scale down for you.
Sorry, I know that is a lot of information dumped! But you will find it pretty great once you start working with it in world space.
You can scale it down a tiny bit once click happen. For example:
void OnMouseDown() {
this.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
}
Then after click scale it back to the original size.
Perhaps look into iTween (free on Unity Asset store).
Its very easy to use and you can produce some nice looking animations.
you can scale it when pressed or just change the color a little bit. On mouse up, rescale or recolor it.
void OnMouseDown()
{
transform.localScale -= new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color += new Color(40,40,40);
}
void OnMouseUp()
{
transform.localScale += new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color -= new Color(40,40,40);
}
You can implement your button using new Event system of unity. Here are the functions you can implement :
public class ExampleClass : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
//it is the function when you hover your mouse to the object
//You can change the color of your object to make your users
//understand that it is not just a cube but also a clickable item
}
public void OnPointerExit(PointerEventData eventData)
{
//You can revert your color back to its original
}
public void OnPointerDown (PointerEventData eventData)
{
//You can play with local scale as suggested by other answers here
}
public void OnPointerUp (PointerEventData eventData)
{
// Revert back the changes you made at onPointerDown
}
public void OnPointerClick (PointerEventData eventData)
{
//Use here for operations when your button is clicked
}
}

Catch the event of slip with one finger to the right/left in a Windows Phone application

All is in the title. I'm actually developing a kind of image gallery and I would like the user slip with one finger to the right to see the next picture and to the left picture for the previous. Whence my question : Is there a way to capture the event when the user slip his finger on the screen in Windows Phone?
You can use the GestureService in the Silverlight Control Toolkit for Windows Phone. In your UI element, add the following piece of code.
XAML:
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="OnFlick"/>
</toolkit:GestureService.GestureListener>
.cs:
private void OnFlick(object sender, FlickGestureEventArgs e)
{
var vm = DataContext as SelectedCatalogViewModel;
if (vm != null)
{
// User flicked towards left
if (e.HorizontalVelocity < 0)
{
// Load the next image
LoadNextPage(null);
}
// User flicked towards right
if (e.HorizontalVelocity > 0)
{
// Load the previous image
LoadPreviousPage();
}
}
}
Have a look here : Implement Swipe event on WP8
Hope it helps!

Display different data while in different orientation in windows phone

What I wud like my app to ideally do is this, to show pivots with their contents in portrait mode and to show a graph when the phone is tilted and set to landscape mode.
I have used OnOrientationChanged() to detect the orientation changes.
Do i have to navigate to a new page if i have to show the graph? Or can i manage it in the same pivot page??
Again does windows phone have graphing tools? or have to rely on the 3rd party tools?
Alfah
Why not just draw both controls and in OrientationChanged adjust the visibilities to what you need? Remember to set your controls correctly for the initial state, too...
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.Portrait)
{
MyPivot.Visibility = Visibility.Visible;
MyGraph.Visibility = Visibility.Collapsed;
}
else
{
MyPivot.Visibility = Visibility.Collapsed;
MyGraph.Visibility = Visibility.Visible;
}
}

WP7 MessageBox stops vibrate from happening when displayed

I am having some trouble getting my application to cause the phone to vibrate and play a sound at the same time as displaying a messagebox.
I have managed to get the sound to repeat whilst the messagebox is displayed but I cannot get the vibrate to work at the same time as a messagebox.
I currently use the following code to play a vibrating pulse:
public void vibrate()
{
DispatcherTimer vibrateTimer = new DispatcherTimer();
vibrateTimer.Tick += new EventHandler(vibrateTimer_Tick);
vibrateTimer.Interval = new TimeSpan(0, 0, 1);
vibrateTimer.Start();
}
void vibrateTimer_Tick(object sender, EventArgs e)
{
vc.Start(TimeSpan.FromMilliseconds(300));
}
I then call the vibrate() method. If I call a simple vibrate that plays for say 10 seconds without pulsing then this works however the pulse does not.
Is there anyway around this so I can play a pulsing vibrate while the message box has been displayed?
Thanks
You can use XNA's Guide.BeginShowMessageBox as the message box instead. I believe this doesn't vibrate or play a sound, so you should have full control.

Enabling slide animation on windows phone while changing textBlock text

I have a textBlock which covers the entire screen. When the user flicks the screen horizontally, textBlock content is changed. I wanted to show that the new text is shown sliding on the screen when the user does flick gesture.
I tried this:
void listener_Flick(object sender, FlickGestureEventArgs e)
{
if (e.Direction == System.Windows.Controls.Orientation.Horizontal)
{
if (e.HorizontalVelocity.CompareTo(0.0) < 0)
{
SlideTransition sTx = new SlideTransition();
sTx.Mode = SlideTransitionMode.SlideLeftFadeIn;
ITransition transition = sTx.GetTransition(textBlock1);
transition.Completed += delegate
{
transition.Stop();
};
transition.Begin();
textBlock1.Text = "New Text";
}
}
}
Though, I do see a little animation for the new text But I don't see new text really sliding from right. How do I achieve this?
Thanks
I'm not clear how your process is supposed to work as you are only doing one animation. In theory you need to animations. One for sliding out and one for sliding in. If doing this with a single control you wouldn't be able to see the items moving in and out at the same time.
A very similar question was also asked previously: how to implement textblock flick animation windows mobile 7

Resources