|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | + |
| 5 | +using Foundation; |
| 6 | +using UIKit; |
| 7 | +using System.IO; |
| 8 | +using SQLite; |
| 9 | +using CoreSpotlight; |
| 10 | + |
| 11 | +using Intents; |
| 12 | +using UserNotifications; |
| 13 | + |
| 14 | +namespace To11oApp |
| 15 | +{ |
| 16 | + // The UIApplicationDelegate for the application. This class is responsible for launching the |
| 17 | + // User Interface of the application, as well as listening (and optionally responding) to |
| 18 | + // application events from iOS. |
| 19 | + [Register ("AppDelegate")] |
| 20 | + public partial class AppDelegate : UIApplicationDelegate |
| 21 | + { |
| 22 | + public override UIWindow Window { |
| 23 | + get; |
| 24 | + set; |
| 25 | + } |
| 26 | + |
| 27 | + public static INSiriAuthorizationStatus SiriAuthorizationStatus { get; set; } |
| 28 | + |
| 29 | + #region Database set-up |
| 30 | + public static AppDelegate Current { get; private set; } |
| 31 | + public TodoManager TodoMgr { get; set; } |
| 32 | + SQLite.SQLiteConnection conn; |
| 33 | + #endregion |
| 34 | + |
| 35 | + |
| 36 | + public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) |
| 37 | + { |
| 38 | + Current = this; |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + #region Database set-up |
| 43 | + var sqliteFilename = "TodoDB.db3"; |
| 44 | + // we need to put in /Library/ on iOS5.1 to meet Apple's iCloud terms |
| 45 | + // (they don't want non-user-generated data in Documents) |
| 46 | + string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder |
| 47 | + string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder |
| 48 | + var path = Path.Combine(libraryPath, sqliteFilename); |
| 49 | + conn = new SQLite.SQLiteConnection(path); |
| 50 | + TodoMgr = new TodoManager(conn); |
| 51 | + #endregion |
| 52 | + |
| 53 | + #region Theme |
| 54 | + UINavigationBar.Appearance.TintColor = UIColor.FromRGB (0x61, 0x4C, 0xA0); // 614CA0 dark-purple |
| 55 | + UINavigationBar.Appearance.BarTintColor = UIColor.FromRGB (0xCE, 0xC0, 0xEC); // CEC0EC light-purple |
| 56 | + |
| 57 | + UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() { |
| 58 | + TextColor = UIColor.FromRGB (0x61, 0x4C, 0xA0), // 614CA0 dark-purple |
| 59 | + TextShadowColor = UIColor.Clear |
| 60 | + }); |
| 61 | + #endregion |
| 62 | + |
| 63 | + Console.WriteLine ("bbbbbbbbbb FinishedLaunching"); |
| 64 | + |
| 65 | + #region Quick Action |
| 66 | + var shouldPerformAdditionalDelegateHandling = true; |
| 67 | + |
| 68 | + // Get possible shortcut item |
| 69 | + if (launchOptions != null) { |
| 70 | + LaunchedShortcutItem = launchOptions [UIApplication.LaunchOptionsShortcutItemKey] as UIApplicationShortcutItem; |
| 71 | + shouldPerformAdditionalDelegateHandling = (LaunchedShortcutItem == null); |
| 72 | + } |
| 73 | + #endregion |
| 74 | + |
| 75 | + return shouldPerformAdditionalDelegateHandling; |
| 76 | + } |
| 77 | + |
| 78 | + #region Quick Action |
| 79 | + // |
| 80 | + // if app is already running (otherwise went through FinishedLaunching) |
| 81 | + public override void PerformActionForShortcutItem (UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) |
| 82 | + { |
| 83 | + Console.WriteLine ("dddddddd PerformActionForShortcutItem"); |
| 84 | + // Perform action |
| 85 | + var handled = HandleShortcutItem(shortcutItem); |
| 86 | + completionHandler(handled); |
| 87 | + } |
| 88 | + |
| 89 | + public UIApplicationShortcutItem LaunchedShortcutItem { get; set; } |
| 90 | + public override void OnActivated (UIApplication application) |
| 91 | + { |
| 92 | + Console.WriteLine ("ccccccc OnActivated"); |
| 93 | + |
| 94 | + // Handle any shortcut item being selected |
| 95 | + HandleShortcutItem(LaunchedShortcutItem); |
| 96 | + |
| 97 | + // Clear shortcut after it's been handled |
| 98 | + LaunchedShortcutItem = null; |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | + public bool HandleShortcutItem(UIApplicationShortcutItem shortcutItem) { |
| 103 | + Console.WriteLine ("eeeeeeeeeee HandleShortcutItem "); |
| 104 | + var handled = false; |
| 105 | + |
| 106 | + // Anything to process? |
| 107 | + if (shortcutItem == null) return false; |
| 108 | + |
| 109 | + // Take action based on the shortcut type |
| 110 | + switch (shortcutItem.Type) { |
| 111 | + case ShortcutIdentifiers.Add: |
| 112 | + Console.WriteLine ("QUICKACTION: Add new item"); |
| 113 | + |
| 114 | + handled = true; |
| 115 | + break; |
| 116 | + case ShortcutIdentifiers.Share: |
| 117 | + Console.WriteLine ("QUICKACTION: Share summary of items"); |
| 118 | + handled = true; |
| 119 | + break; |
| 120 | + } |
| 121 | + |
| 122 | + //HACK: show the detail viewcontroller |
| 123 | + ContinueNavigation (); |
| 124 | + |
| 125 | + Console.Write (handled); |
| 126 | + // Return results |
| 127 | + return handled; |
| 128 | + } |
| 129 | + #endregion |
| 130 | + |
| 131 | + #region NSUserActivity AND CoreSpotlight |
| 132 | + // http://www.raywenderlich.com/84174/ios-8-handoff-tutorial |
| 133 | + public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) |
| 134 | + { |
| 135 | + Console.WriteLine ("ffffffff ContinueUserActivity"); |
| 136 | + |
| 137 | + UIViewController tvc = null; |
| 138 | + |
| 139 | + // NSUserActivity |
| 140 | + if ((userActivity.ActivityType == ActivityTypes.Add) |
| 141 | + || (userActivity.ActivityType == ActivityTypes.Detail)) |
| 142 | + { |
| 143 | + if (userActivity.UserInfo.Count == 0) { |
| 144 | + // new item |
| 145 | + |
| 146 | + } else { |
| 147 | + var uid = userActivity.UserInfo.ObjectForKey ((NSString)"id").ToString (); |
| 148 | + if (uid == "0") { |
| 149 | + Console.WriteLine ("No userinfo found for " + ActivityTypes.Detail); |
| 150 | + } else { |
| 151 | + Console.WriteLine ("Should display id " + uid); |
| 152 | + // handled in DetailViewController.RestoreUserActivityState |
| 153 | + } |
| 154 | + } |
| 155 | + tvc = ContinueNavigation (); |
| 156 | + |
| 157 | + } |
| 158 | + // CoreSpotlight |
| 159 | + if (userActivity.ActivityType == CSSearchableItem.ActionType) { |
| 160 | + var uid = userActivity.UserInfo.ObjectForKey |
| 161 | + (CSSearchableItem.ActivityIdentifier).ToString(); |
| 162 | + |
| 163 | + System.Console.WriteLine ("Show the detail for id:" + uid); |
| 164 | + |
| 165 | + tvc = ContinueNavigation (); |
| 166 | + |
| 167 | + } |
| 168 | + completionHandler(new NSObject[] {tvc}); |
| 169 | + |
| 170 | + return true; |
| 171 | + } |
| 172 | + #endregion |
| 173 | + |
| 174 | + // |
| 175 | + // called for Quick Action AND NSUserActivity |
| 176 | + UIViewController ContinueNavigation (){ |
| 177 | + Console.WriteLine ("gggggggggg ContinueNavigation"); |
| 178 | + |
| 179 | + // 1. load screen |
| 180 | + var sb = UIStoryboard.FromName ("MainStoryboard", null); |
| 181 | + var tvc = sb.InstantiateViewController("detailvc") as DetailViewController; |
| 182 | + |
| 183 | + // 2. set initial state |
| 184 | + var r = Window.RootViewController as UINavigationController; |
| 185 | + r.PopToRootViewController (false); |
| 186 | + |
| 187 | + // 3. populate and display screen |
| 188 | + tvc.SetTodo (new TodoItem {Name="(new action)"}); // from 3D Touch menu |
| 189 | + tvc.Delegate = CollectionController.Current; |
| 190 | + r.PushViewController (tvc, false); |
| 191 | + return tvc; |
| 192 | + } |
| 193 | + |
| 194 | + |
| 195 | + } |
| 196 | +} |
0 commit comments