Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Added CoreTelephony demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Sep 9, 2011
1 parent 7d28a5d commit d948dc5
Show file tree
Hide file tree
Showing 14 changed files with 592 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CoreTelephonyDemo/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace CoreTelephonyDemo
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
CoreTelephonyDemoViewController viewController;
UIWindow window;
UINavigationController navigationController;

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow ();
navigationController = new UINavigationController ();
viewController = new CoreTelephonyDemoViewController ();
navigationController.PushViewController (viewController, true);
window.AddSubview (navigationController.View);
window.MakeKeyAndVisible ();
return true;
}
}
}

88 changes: 88 additions & 0 deletions CoreTelephonyDemo/CoreTelephonyDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A6EED034-12CE-4339-AB96-81277A3A9AD8}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>CoreTelephonyDemo</RootNamespace>
<AssemblyName>CoreTelephonyDemo</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="CoreTelephonyDemoViewController.cs" />
<Compile Include="CoreTelephonyDemoViewController.designer.cs">
<DependentUpon>CoreTelephonyDemoViewController.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="CoreTelephonyDemoViewController.xib" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Content Include="icons\114_icon.png" />
<Content Include="icons\29_icon.png" />
<Content Include="icons\50_icon.png" />
<Content Include="icons\512_icon.png" />
<Content Include="icons\57_icon.png" />
<Content Include="icons\58_icon.png" />
<Content Include="icons\72_icon.png" />
</ItemGroup>
</Project>
196 changes: 196 additions & 0 deletions CoreTelephonyDemo/CoreTelephonyDemoViewController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using MonoTouch.UIKit;
using System.Drawing;
using System;
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.CoreTelephony;

namespace CoreTelephonyDemo
{
public partial class CoreTelephonyDemoViewController : UITableViewController
{
CTTelephonyNetworkInfo networkInfo;
CTCallCenter callCenter;
string carrierName;
CTCall[] calls = new CTCall [0];

public CoreTelephonyDemoViewController ()
: base ("CoreTelephonyDemoViewController", null)
{
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

this.Title = "Core Telephony Info";
this.TableView.AllowsSelection = false;
this.TableView.DataSource = new TableViewDataSource (this);

networkInfo = new CTTelephonyNetworkInfo ();
callCenter = new CTCallCenter ();
callCenter.CallEventHandler += CallEvent;
carrierName = networkInfo.SubscriberCellularProvider == null ? null : networkInfo.SubscriberCellularProvider.CarrierName;
networkInfo.CellularProviderUpdatedEventHandler += ProviderUpdatedEvent;
}

private void ProviderUpdatedEvent (CTCarrier carrier)
{
MonoTouch.CoreFoundation.DispatchQueue.MainQueue.DispatchSync (() =>
{
carrierName = carrier == null ? null : carrier.CarrierName;
TableView.ReloadData ();
});
}

private void CallEvent (CTCall inCTCall)
{
MonoTouch.CoreFoundation.DispatchQueue.MainQueue.DispatchSync (() =>
{
NSSet calls = callCenter.CurrentCalls;
calls = callCenter.CurrentCalls;
if (calls == null) {
this.calls = new CTCall [0];
} else {
this.calls = calls.ToArray<CTCall> ();
}
Array.Sort (this.calls, (CTCall a, CTCall b) =>
{
return string.Compare (a.CallID, b.CallID);
});
TableView.ReloadData ();
});
}

public override void ViewDidUnload ()
{
base.ViewDidUnload ();

// Release any retained subviews of the main view.
// e.g. myOutlet = null;
networkInfo.CellularProviderUpdatedEventHandler -= ProviderUpdatedEvent;
callCenter.CallEventHandler -= CallEvent;
}

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}

enum SectionIndex {
CurrentCall = 0,
CallCenter,
Carrier,
Count,
}

enum SectionRow {
CurrentCall = 1,
CallCenter = 1,
Carrier = 1,
Count,
}

class TableViewDataSource : UITableViewDataSource {
CoreTelephonyDemoViewController controller;
List<UITableViewCell> table_cells = new List<UITableViewCell> ();

public TableViewDataSource (CoreTelephonyDemoViewController controller)
{
this.controller = controller;
}

#region implemented abstract members of MonoTouch.UIKit.UITableViewDataSource
public override int RowsInSection (UITableView tableView, int section)
{
switch ((SectionIndex) section) {
case SectionIndex.CurrentCall:
return Math.Max (controller.calls.Length, 1);
case SectionIndex.CallCenter:
return (int) SectionRow.CallCenter;
case SectionIndex.Carrier:
return (int) SectionRow.Carrier;
default:
return 1;
}
}

string GetCallState (string callState)
{
switch (callState) {
case "CTCallStateDialing":
return "Dialing";
case "CTCallStateIncoming":
return "Incoming";
case "CTCallStateConnected":
return "Connected";
case "CTCallStateDisconnected":
return "Disconnected";
default:
return callState;
}
}

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell;
string cellText = string.Empty;

cell = tableView.DequeueReusableCell ("Cell");
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, "Cell");
table_cells.Add (cell);
}

switch ((SectionIndex) indexPath.Section) {
case SectionIndex.CurrentCall:
if (controller.calls.Length > 0) {
cellText = string.Format ("Call {0}: {1}", indexPath.Row + 1, GetCallState (controller.calls [indexPath.Row].CallState));
} else {
cellText = "No calls";
}
break;
case SectionIndex.CallCenter:
if (controller.calls.Length == 0) {
cellText = "No calls";
} else if (controller.calls.Length == 1) {
cellText = "1 call at Call Center";
} else {
cellText = string.Format ("{0} calls at Call Center", controller.calls.Length);
}
break;
case SectionIndex.Carrier:
if (!string.IsNullOrEmpty (controller.carrierName)) {
cellText = controller.carrierName;
} else {
cellText = "Unknown";
}
break;
}

cell.TextLabel.Text = cellText;
return cell;
}
#endregion

public override int NumberOfSections (UITableView tableView)
{
return (int) SectionIndex.Count;
}

public override string TitleForHeader (UITableView tableView, int section)
{
switch ((SectionIndex) section) {
case SectionIndex.CurrentCall:
return "Current call";
case SectionIndex.CallCenter:
return "Call center";
case SectionIndex.Carrier:
return "Carrier";
default:
return null;
}
}
}
}
}
14 changes: 14 additions & 0 deletions CoreTelephonyDemo/CoreTelephonyDemoViewController.designer.cs

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

Loading

0 comments on commit d948dc5

Please sign in to comment.