Contains() 공개 메소드

Checks to see if the DataPackageView contains a specific data format.
public Contains ( string formatId ) : bool
formatId string The name of the format.
리턴 bool
예제 #1
0
        /// <summary>
        /// Programmatically initiates the user interface for sharing content with another app.
        /// </summary>
        public async static void ShowShareUI()
        {
            DataRequestedEventArgs e = new DataRequestedEventArgs();

            instance.OnDataRequested(e);
            instance.currentDataPackage = e.Request.Data;
            DataPackageView view = instance.currentDataPackage.GetView();

            if (view.AvailableFormats.Count > 0)
            {
                foreach (string format in view.AvailableFormats)
                {
                    Debug.WriteLine(format);
                }
#if __ANDROID__
                string text = null;
                if (view.Contains(StandardDataFormats.Text))
                {
                    text = await view.GetTextAsync();
                }
                else if (view.Contains(StandardDataFormats.WebLink))
                {
                    text = (await view.GetWebLinkAsync()).ToString();
                }
                Intent shareIntent = new Intent();
                shareIntent.SetAction(Intent.ActionSend);
                shareIntent.AddFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
                shareIntent.PutExtra(Intent.ExtraText, text);
                shareIntent.SetType("text/plain");
                Intent shareChooserIntent = Intent.CreateChooser(shareIntent, "Share");
                shareChooserIntent.AddFlags(ActivityFlags.ClearWhenTaskReset);
                Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(shareChooserIntent);
                //Platform.Android.ContextManager.Context.ApplicationContext.StartActivity(shareChooserIntent);
#elif __IOS__
                List <NSObject> values = new List <NSObject>();
                if (view.Contains(StandardDataFormats.WebLink))
                {
                    values.Add(new NSUrl((await view.GetWebLinkAsync()).ToString()));
                }
                else if (view.Contains(StandardDataFormats.Text))
                {
                    values.Add(new NSString(await view.GetTextAsync()));
                }
                else if (view.Contains(StandardDataFormats.ApplicationLink))
                {
                    values.Add(new NSUrl((await view.GetApplicationLinkAsync()).ToString()));
                }
                UIActivityViewController activity = new UIActivityViewController(values.ToArray(), null);
                activity.CompletionWithItemsHandler = (text, success, items, error) =>
                {
                    if (success)
                    {
                        instance.OnTargetApplicationChosen(text);
                    }
                    else
                    {
                        Debug.WriteLine(error);
                    }
                };
                UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                while (currentController.PresentedViewController != null)
                {
                    currentController = currentController.PresentedViewController;
                }
                currentController.PresentModalViewController(activity, true);
#elif WINDOWS_PHONE
                /*if (view.Contains(StandardDataFormats.Bitmap))
                 * {
                 *  string path = view.GetBitmapFilename();
                 *  if (string.IsNullOrEmpty(path))
                 *  {
                 *      System.IO.Stream /Windows.Storage.Streams.RandomAccessStreamReference/ strRef = await view.GetBitmapAsync();
                 *      Microsoft.Xna.Framework.Media.MediaLibrary ml = new Microsoft.Xna.Framework.Media.MediaLibrary();
                 *      Microsoft.Xna.Framework.Media.Picture pic = ml.SavePicture("share", strRef);
                 *      path = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPath(pic);
                 *  }
                 *
                 *  Microsoft.Phone.Tasks.ShareMediaTask shareMediaTask = new Microsoft.Phone.Tasks.ShareMediaTask();
                 *  shareMediaTask.FilePath = path; // "isostore:///shared/shellcontent/share.temp." + filename + ".png";
                 *  shareMediaTask.Show();
                 * }
                 * else
                 * {*/

                // for 8.0 apps running on 8.1 provide "light-up" to use shell sharing feature
                if (Environment.OSVersion.Version >= new Version(8, 10))
                {
                    if (view.Contains(StandardDataFormats.WebLink))
                    {
                        Microsoft.Phone.Tasks.ShareLinkTask shareLinkTask = new Microsoft.Phone.Tasks.ShareLinkTask();
                        shareLinkTask.LinkUri = await view.GetWebLinkAsync();

                        shareLinkTask.Message = await view.GetTextAsync();

                        shareLinkTask.Title = view.Properties.Title;
                        shareLinkTask.Show();
                    }
                    else if (view.Contains(StandardDataFormats.ApplicationLink))
                    {
                        Microsoft.Phone.Tasks.ShareLinkTask shareLinkTask = new Microsoft.Phone.Tasks.ShareLinkTask();
                        shareLinkTask.LinkUri = await view.GetApplicationLinkAsync();

                        shareLinkTask.Message = await view.GetTextAsync();

                        shareLinkTask.Title = view.Properties.Title;
                        shareLinkTask.Show();
                    }
                    else if (view.Contains(StandardDataFormats.Text))
                    {
                        Microsoft.Phone.Tasks.ShareStatusTask shareStatusTask = new Microsoft.Phone.Tasks.ShareStatusTask();
                        shareStatusTask.Status = await view.GetTextAsync();

                        shareStatusTask.Show();
                    }
                }
                else
                {
                    // use "custom" page to match OS 8.0 support
                    ((Microsoft.Phone.Controls.PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/InTheHand.ApplicationModel;component/SharePage.xaml", UriKind.Relative));
                }
                //}
#endif
            }


            else
            {
                // nothing to share
#if WINDOWS_PHONE
                //System.Windows.MessageBox.Show(Resources.Resources.NothingToShare, Resources.Resources.ShareHeader, MessageBoxButton.OK);
#endif
            }
        }
예제 #2
0
        /// <summary>
        /// Sets the current content that is stored in the clipboard object.
        /// </summary>
        /// <param name="content">Contains the content of the clipboard.
        /// If NULL, the clipboard is emptied.</param>

        public async static void SetContent(DataPackage content)
        {
#if WINDOWS_PHONE_APP
            if (_on10)
            {
                _type10.GetRuntimeMethod("SetContent", new Type[] { typeof(Windows.ApplicationModel.DataTransfer.DataPackage) }).Invoke(null, new object[] { content });
                ContentChanged?.Invoke(null, null);
                return;
            }
#endif
            string text = "";
            Uri    uri  = null;

            if (content != null)
            {
                DataPackageView view = content.GetView();
                if (view.Contains(StandardDataFormats.Text))
                {
                    text = await view.GetTextAsync();
                }
                if (view.Contains(StandardDataFormats.WebLink))
                {
                    uri = await view.GetWebLinkAsync();
                }
                else if (view.Contains(StandardDataFormats.ApplicationLink))
                {
                    uri = await view.GetApplicationLinkAsync();
                }
            }
            else
            {
                Clear();
                return;
            }

#if __ANDROID__
            if (string.IsNullOrEmpty(text) && uri != null)
            {
                _clipboardManager.PrimaryClip = ClipData.NewUri(null, content.Properties.Title, Android.Net.Uri.Parse(uri.ToString()));
            }
            else
            {
                _clipboardManager.PrimaryClip = ClipData.NewPlainText(content.Properties.Title, text);
            }
#elif __IOS__
            UIPasteboard.General.String = text;
            if (uri != null)
            {
                UIPasteboard.General.Url = NSUrl.FromString(uri.ToString());
            }
#elif __MAC__
            NSPasteboard.GeneralPasteboard.SetStringForType(text, NSPasteboard.NSPasteboardTypeString);
#elif WINDOWS_PHONE || WINDOWS_PHONE_APP
            if (string.IsNullOrEmpty(text) && uri != null)
            {
                global::System.Windows.Clipboard.SetText(uri.ToString());
            }
            else
            {
                global::System.Windows.Clipboard.SetText(text);
            }
#elif WIN32
            if (string.IsNullOrEmpty(text) && uri != null)
            {
                SetText(uri.ToString());
            }
            else
            {
                SetText(text);
            }
#else
            throw new PlatformNotSupportedException();
#endif
            ContentChanged?.Invoke(null, null);
        }