Skip to content

Commit

Permalink
iPhone interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron He committed Mar 18, 2012
1 parent 9071d23 commit e3f88ed
Show file tree
Hide file tree
Showing 37 changed files with 2,811 additions and 10 deletions.
128 changes: 126 additions & 2 deletions Nav-Demo/Nav-Demo/InfoViewController.cs
@@ -1,6 +1,5 @@
using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

Expand All @@ -9,6 +8,8 @@ namespace NavDemo
public partial class InfoViewController : UIViewController
{
NSTimer UpdateBatteryStatusTimer;
NSTimer ClearMotionLabelTimer;
private PointF StartCoord;

public InfoViewController () : base ("InfoViewController", null)
{
Expand All @@ -25,6 +26,7 @@ public override void DidReceiveMemoryWarning ()
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
View.MultipleTouchEnabled = true;

// Perform any additional setup after loading the view, typically from a nib.
}
Expand All @@ -44,7 +46,7 @@ public override void ViewDidUnload ()
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
return true;
}

public override void ViewDidAppear (bool animated)
Expand All @@ -62,6 +64,8 @@ public override void ViewDidAppear (bool animated)
proximityLabel.Text = "Proximity sensor not available";
UpdateBatteryStatusTimer = NSTimer.CreateRepeatingScheduledTimer(60, ReadBatteryStatus);
ReadBatteryStatus();
BecomeFirstResponder();
UIApplication.SharedApplication.ApplicationSupportsShakeToEdit = true;
}

void HandleStatusBarSwitchValueChanged (object sender, EventArgs e)
Expand Down Expand Up @@ -89,6 +93,8 @@ public override void ViewDidDisappear (bool animated)
base.ViewDidDisappear (animated);
if(UIDevice.CurrentDevice.ProximityMonitoringEnabled)
UIDevice.CurrentDevice.ProximityMonitoringEnabled = false;
UpdateBatteryStatusTimer.Invalidate();
ResignFirstResponder();
}

private void ReadBatteryStatus()
Expand All @@ -110,6 +116,124 @@ private void ReadBatteryStatus()
UpdateBatteryStatusTimer.Invalidate();
}
}

public override void WillAnimateRotation (UIInterfaceOrientation toInterfaceOrientation, double duration)
{
switch(toInterfaceOrientation)
{
case UIInterfaceOrientation.Portrait:
interactionLabel.Text = "iPhone is oriented normally";
break;
case UIInterfaceOrientation.LandscapeLeft:
interactionLabel.Text = "iPhone has been rotated right";
break;
case UIInterfaceOrientation.LandscapeRight:
interactionLabel.Text = "iPhone has been rotated left";
break;
case UIInterfaceOrientation.PortraitUpsideDown:
interactionLabel.Text = "iPhone is upside down";
break;
}
//SetTiimerToClearMotionLabel();
UpdateUIMetrics();
}

private void SetTimerToClearMotionLabel()
{
if(ClearMotionLabelTimer != null)
ClearMotionLabelTimer.Invalidate();
ClearMotionLabelTimer = NSTimer.CreateScheduledTimer(3, () =>
{
interactionLabel.Text = "None";
ClearMotionLabelTimer = null;
});
}

public override bool CanBecomeFirstResponder
{
get { return true;}
}

public override void MotionEnded (UIEventSubtype motion, UIEvent evt)
{
if(motion == UIEventSubtype.MotionShake)
{
interactionLabel.Text= "iPhone was shaken";
SetTimerToClearMotionLabel();
}
}

private string DescribeTouch(UITouch touch)
{
string desc;
switch(touch.TapCount)
{
case 0:
desc = "Swipe";
break;
case 1:
desc = "Single Tap";
break;
case 2:
desc = "Double Tap";
break;
default:
desc = "Multiple tap";
break;
}
switch(touch.Phase)
{
case UITouchPhase.Began:
desc += " started";
break;
case UITouchPhase.Moved:
desc += " moved";
break;
case UITouchPhase.Cancelled:
desc += " cancelled";
break;
case UITouchPhase.Ended:
desc += " ended";
break;
case UITouchPhase.Stationary:
desc += " hasn't moved";
break;
}
return desc;
}

public override void TouchesBegan (NSSet touches, UIEvent evt)
{
var touchArray = touches.ToArray<UITouch>();
if(touches.Count>0)
{
var coord = touchArray[0].LocationInView(touchArray[0].View);
if(touchArray[0].TapCount < 2)
StartCoord = coord;
interactionLabel.Text= string.Format("{0} ({1},{2})", DescribeTouch(touchArray[0]), coord.X, coord.Y);
}
}

public override void TouchesMoved (NSSet touches, UIEvent evt)
{
var touchArray = touches.ToArray<UITouch>();
if(touches.Count>0)
{
var coord = touchArray[0].LocationInView(touchArray[0].View);
interactionLabel.Text= string.Format("{0} ({1},{2})", DescribeTouch(touchArray[0]), coord.X, coord.Y);
}
}

public override void TouchesEnded (NSSet touches, UIEvent evt)
{
var touchArray = touches.ToArray<UITouch>();
if(touches.Count>0)
{
var coord = touchArray[0].LocationInView(touchArray[0].View);
interactionLabel.Text= string.Format("{0} ({1},{2})", DescribeTouch(touchArray[0]), coord.X, coord.Y);
SetTimerToClearMotionLabel();
}
}
}
}

8 changes: 8 additions & 0 deletions Nav-Demo/Nav-Demo/InfoViewController.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 78 additions & 6 deletions Nav-Demo/Nav-Demo/InfoViewController.xib
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1280</int>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11D50</string>
<string key="IBDocument.InterfaceBuilderVersion">2177</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1173</string>
<string key="NS.object.0">1179</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUISwitch</string>
Expand Down Expand Up @@ -67,6 +67,27 @@
<int key="NSfFlags">16</int>
</object>
</object>
<object class="IBUILabel" id="152822888">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 311}, {183, 21}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="277288078"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Interaction</string>
<reference key="IBUITextColor" ref="121916558"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<float key="IBUIMinimumFontSize">10</float>
<reference key="IBUIFontDescription" ref="356882867"/>
<reference key="IBUIFont" ref="775405498"/>
</object>
<object class="IBUILabel" id="531895149">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
Expand Down Expand Up @@ -200,6 +221,26 @@
<int key="NSfFlags">16</int>
</object>
</object>
<object class="IBUILabel" id="277288078">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 340}, {272, 19}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">None</string>
<reference key="IBUITextColor" ref="121916558"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<float key="IBUIMinimumFontSize">10</float>
<reference key="IBUIFontDescription" ref="411013433"/>
<reference key="IBUIFont" ref="70685457"/>
</object>
<object class="IBUILabel" id="153010950">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
Expand Down Expand Up @@ -283,7 +324,7 @@
<string key="NSFrame">{{28, 284}, {272, 19}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="NSNextKeyView" ref="152822888"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand Down Expand Up @@ -373,6 +414,14 @@
</object>
<int key="connectionID">28</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">interactionLabel</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="277288078"/>
</object>
<int key="connectionID">32</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand All @@ -398,6 +447,8 @@
<reference ref="88057200"/>
<reference ref="437245998"/>
<reference ref="814203036"/>
<reference ref="277288078"/>
<reference ref="152822888"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -472,6 +523,16 @@
<reference key="object" ref="814203036"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">30</int>
<reference key="object" ref="277288078"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">31</int>
<reference key="object" ref="152822888"/>
<reference key="parent" ref="191373211"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -492,12 +553,14 @@
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="21.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="30.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="31.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">28</int>
<int key="maxID">32</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -508,6 +571,7 @@
<string key="DeviceLabel">UILabel</string>
<string key="batteryLabel">UILabel</string>
<string key="frameSizeLabel">UILabel</string>
<string key="interactionLabel">UILabel</string>
<string key="proximityLabel">UILabel</string>
<string key="resolutionLabel">UILabel</string>
<string key="statusBarSwitch">UISwitch</string>
Expand All @@ -525,6 +589,10 @@
<string key="name">frameSizeLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="interactionLabel">
<string key="name">interactionLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="proximityLabel">
<string key="name">proximityLabel</string>
<string key="candidateClassName">UILabel</string>
Expand All @@ -547,8 +615,12 @@
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<real value="1296" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1173</string>
<string key="IBCocoaTouchPluginVersion">1179</string>
</data>
</archive>
Binary file not shown.
Binary file modified Nav-Demo/Nav-Demo/bin/iPhoneSimulator/Debug/NavDemo.exe
Binary file not shown.
Binary file modified Nav-Demo/Nav-Demo/bin/iPhoneSimulator/Debug/NavDemo.exe.mdb
Binary file not shown.
16 changes: 16 additions & 0 deletions Nav-Demo/Nav-Demo/obj/Xcode/0/AppDelegate.h
@@ -0,0 +1,16 @@
// WARNING
// This file has been generated automatically by MonoDevelop to
// mirror C# types. Changes in this file made by drag-connecting
// from the UI designer will be synchronized back to C#, but
// more complex manual changes may not transfer correctly.


#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>


@interface AppDelegate : NSObject {
}

@end

0 comments on commit e3f88ed

Please sign in to comment.