Skip to content

Commit

Permalink
Added search example
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebluestein committed Oct 19, 2012
1 parent 039610f commit 15f3b28
Show file tree
Hide file tree
Showing 25 changed files with 664 additions and 0 deletions.
7 changes: 7 additions & 0 deletions SearchDemo/Metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<SampleMetadata>
<ID>0857a1e5-1178-4973-85ba-08655ae7b565</ID>
<IsFullApplication>false</IsFullApplication>
<Level>Beginner</Level>
<Tags>User Interface</Tags>
</SampleMetadata>
8 changes: 8 additions & 0 deletions SearchDemo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Search Demo
===========

This sample demonstrates how to create a master-detail style of application with a UITableViewController and UINavigationController. It also shows how to add a UISearchBar to a UITableView. The search in this case calls the Bing web service to retrieve results. The associated web page is loaded in a UIWebView when a row is selcted in the table.

The Bing web service requires an API key, which can be obtained at https://datamarket.azure.com

Once you have an API key, set it to the AZURE_KEY constant in Bing.cs.
Binary file added SearchDemo/Screenshots/SearchDemo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/Screenshots/SearchDemo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions SearchDemo/SearchDemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SearchDemo", "SearchDemo\SearchDemo.csproj", "{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
Ad-Hoc|iPhone = Ad-Hoc|iPhone
AppStore|iPhone = AppStore|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.AppStore|iPhone.ActiveCfg = AppStore|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.AppStore|iPhone.Build.0 = AppStore|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Debug|iPhone.ActiveCfg = Debug|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Debug|iPhone.Build.0 = Debug|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Release|iPhone.ActiveCfg = Release|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Release|iPhone.Build.0 = Release|iPhone
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = SearchDemo\SearchDemo.csproj
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions SearchDemo/SearchDemo/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SearchDemo
{
// 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
{
// class-level declarations
UIWindow window;
UINavigationController navController;
SearchResultsController searchResultsController;


//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);

searchResultsController = new SearchResultsController ();
navController = new UINavigationController (searchResultsController);
window.RootViewController = navController;
window.MakeKeyAndVisible ();

return true;
}
}
}
59 changes: 59 additions & 0 deletions SearchDemo/SearchDemo/Bing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Net;
using System.Linq;
using System.Json;
using System.Web;
using MonoTouch.Foundation;

namespace SearchDemo
{
public delegate void SynchronizerDelegate (List<SearchItem> results);

public class Bing
{
const string AZURE_KEY = "Enter API key here";

static SynchronizerDelegate sync;

public Bing (SynchronizerDelegate sync)
{
Bing.sync = sync;
}

public void Search (string text)
{
var t = new Thread (Search);
t.Start (text);
}

void Search (object text)
{
string bingSearch = String.Format ("https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Web?Query=%27{0}%27&$top=10&$format=Json", text);

var httpReq = (HttpWebRequest)HttpWebRequest.Create (new Uri (bingSearch));

httpReq.Credentials = new NetworkCredential (AZURE_KEY, AZURE_KEY);

try {
using (HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse ()) {

var response = httpRes.GetResponseStream ();
var json = (JsonObject)JsonObject.Load (response);

var results = (from result in (JsonArray)json ["d"] ["results"]
let jResult = result as JsonObject
select new SearchItem { Title = jResult["Title"], Url = jResult["Url"] }).ToList ();

if (sync != null)
sync (results);
}
} catch (Exception) {
if (sync != null)
sync (null);
}
}

}
}
Binary file added SearchDemo/SearchDemo/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/Icon-72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SearchDemo/SearchDemo/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions SearchDemo/SearchDemo/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>Icon.png</string>
<string>Icon-72.png</string>
<string>[email protected]</string>
</array>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
20 changes: 20 additions & 0 deletions SearchDemo/SearchDemo/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SearchDemo
{
public class Application
{
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}
118 changes: 118 additions & 0 deletions SearchDemo/SearchDemo/SearchDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?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>{E57BD6EE-FC50-4553-80A5-CE89CA66A78B}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>SearchDemo</RootNamespace>
<AssemblyName>SearchDemo</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>
<MtouchDebug>True</MtouchDebug>
<MtouchProfiling>True</MtouchProfiling>
<MtouchLink>None</MtouchLink>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>True</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>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>True</MtouchDebug>
<MtouchProfiling>True</MtouchProfiling>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\iPhone\Ad-Hoc</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
<BuildIpa>True</BuildIpa>
<CodesignKey>iPhone Distribution</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\iPhone\AppStore</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
<CodesignKey>iPhone Distribution</CodesignKey>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
<Reference Include="System.Json" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Web.Services" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="Bing.cs" />
<Compile Include="SearchResultsController.cs" />
<Compile Include="SearchItem.cs" />
<Compile Include="SearchItemViewController.cs" />
<Compile Include="SearchItemViewController.designer.cs">
<DependentUpon>SearchItemViewController.cs</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<InterfaceDefinition Include="SearchItemViewController.xib" />
</ItemGroup>
<ItemGroup>
<Content Include="Icon-72.png" />
<Content Include="Icon-72%402x.png" />
<Content Include="Icon.png" />
<Content Include="Icon%402x.png" />
<Content Include="iTunesArtwork%402x.png" />
<Content Include="Default.png" />
<Content Include="Default%402x.png" />
<Content Include="Default-568h%402x.png" />
</ItemGroup>
<ItemGroup>
<ITunesArtwork Include="iTunesArtwork.png" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions SearchDemo/SearchDemo/SearchItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SearchDemo
{
public class SearchItem
{
public SearchItem ()
{
}

public string Title { get; set; }

public string Url { get; set; }
}
}

33 changes: 33 additions & 0 deletions SearchDemo/SearchDemo/SearchItemViewController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SearchDemo
{
public partial class SearchItemViewController : UIViewController
{
public SearchItem Item { get; set; }

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

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

webView.LoadStarted += (sender, e) => {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
};

webView.LoadFinished += (sender, e) => {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
};

webView.LoadRequest (new NSUrlRequest (new NSUrl (Item.Url)));
}
}
}

25 changes: 25 additions & 0 deletions SearchDemo/SearchDemo/SearchItemViewController.designer.cs

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

Loading

0 comments on commit 15f3b28

Please sign in to comment.