Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

ContactPickerTask.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. namespace WPCordovaClassLib.Cordova.Commands
  18. {
  19. using System;
  20. using System.Windows;
  21. using Microsoft.Phone.Controls;
  22. using Microsoft.Phone.Tasks;
  23. using Microsoft.Phone.UserData;
  24. /// <summary>
  25. /// Allows an application to pick contact.
  26. /// Use this to allow users to pick contact from your application.
  27. /// </summary>
  28. public class ContactPickerTask
  29. {
  30. /// <summary>
  31. /// Occurs when a Pick task is completed.
  32. /// </summary>
  33. public event EventHandler<PickResult> Completed;
  34. /// <summary>
  35. /// Shows Contact pick application
  36. /// </summary>
  37. public void Show()
  38. {
  39. Deployment.Current.Dispatcher.BeginInvoke(() =>
  40. {
  41. var root = Application.Current.RootVisual as PhoneApplicationFrame;
  42. string baseUrl = "/";
  43. if (root != null)
  44. {
  45. root.Navigated += this.OnNavigate;
  46. // dummy parameter is used to always open a fresh version
  47. root.Navigate(
  48. new Uri(
  49. baseUrl + "Plugins/cordova-plugin-contacts/ContactPicker.xaml?dummy="
  50. + Guid.NewGuid(),
  51. UriKind.Relative));
  52. }
  53. });
  54. }
  55. /// <summary>
  56. /// Performs additional configuration of the picker application.
  57. /// </summary>
  58. /// <param name="sender">The source of the event.</param>
  59. /// <param name="e">The <see cref="System.Windows.Navigation.NavigationEventArgs"/> instance containing the event data.</param>
  60. private void OnNavigate(object sender, System.Windows.Navigation.NavigationEventArgs e)
  61. {
  62. if (!(e.Content is ContactPicker))
  63. {
  64. return;
  65. }
  66. var phoneApplicationFrame = Application.Current.RootVisual as PhoneApplicationFrame;
  67. if (phoneApplicationFrame != null)
  68. {
  69. phoneApplicationFrame.Navigated -= this.OnNavigate;
  70. }
  71. ContactPicker contactPicker = (ContactPicker)e.Content;
  72. if (contactPicker != null)
  73. {
  74. contactPicker.Completed += this.Completed;
  75. }
  76. else if (this.Completed != null)
  77. {
  78. this.Completed(this, new PickResult(TaskResult.Cancel));
  79. }
  80. }
  81. /// <summary>
  82. /// Represents contact returned
  83. /// </summary>
  84. public class PickResult : TaskEventArgs
  85. {
  86. /// <summary>
  87. /// Initializes a new instance of the PickResult class.
  88. /// </summary>
  89. public PickResult()
  90. {
  91. }
  92. /// <summary>
  93. /// Initializes a new instance of the PickResult class
  94. /// with the specified Microsoft.Phone.Tasks.TaskResult.
  95. /// </summary>
  96. /// <param name="taskResult">Associated Microsoft.Phone.Tasks.TaskResult</param>
  97. public PickResult(TaskResult taskResult)
  98. : base(taskResult)
  99. {
  100. }
  101. /// <summary>
  102. /// Gets the contact.
  103. /// </summary>
  104. public Contact Contact { get; internal set; }
  105. }
  106. }
  107. }