Пример #1
0
 public override bool OnOptionsItemSelected(IMenuItem item)
 {
     switch (item.ItemId)
     {
     case Resource.Id.menu_add:
         // Show Add event screen
         Intent intent = new Intent(mActivity, typeof(AddCalendarEventActivity));
         intent.PutExtra("isAddEvent", true);
         mActivity.StartActivityForResult(intent, ConstantsDroid.CALENDAR_LIST_REQUEST_CODE);
         mActivity.OverridePendingTransition(Resource.Animation.animation_enter,
                                             Resource.Animation.animation_leave);
         break;
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        /// Start to select photo.
        /// </summary>
        /// <param name="requestCode"> identity of the requester activity. </param>
        public void ForResult(int requestCode)
        {
            if (engine == null)
            {
                throw new ExceptionInInitializerError(LoadEngine.INITIALIZE_ENGINE_ERROR);
            }

            Activity activity = Activity;

            if (activity == null)
            {
                return; // cannot continue;
            }
            mSelectionSpec.MimeTypes = MimeTypes;
            mSelectionSpec.Engine    = engine;
            Intent intent = new Intent(activity, typeof(ImageSelectActivity));

            intent.PutExtra(ImageSelectActivity.EXTRA_SELECTION_SPEC, mSelectionSpec);
            //        intent.putExtra(ImageSelectActivity.EXTRA_ENGINE, (Serializable) engine);

            intent.PutParcelableArrayListExtra(ImageSelectActivity.EXTRA_RESUME_LIST, mResumeList.AsIParcelableList());

            Fragment fragment = Fragment;

            if (fragment != null)
            {
                fragment.StartActivityForResult(intent, requestCode);
            }
            else
            {
                activity.StartActivityForResult(intent, requestCode);
            }
            hasInitPicker = false;
        }
Пример #3
0
        public async void LoadImage(String imageName)
        {
#if NETFX_CORE
            Mat m = CvInvoke.Imread(imageName, LoadImageType.AnyColor);
            InvokeOnImageLoaded(m);
#else
            if (_mediaPicker == null)
            {
#if __ANDROID__
                _mediaPicker = new MediaPicker(Forms.Context);
#else
                _mediaPicker = new MediaPicker();
#endif
            }

            var action = await(_mediaPicker.IsCameraAvailable?
                               DisplayActionSheet("Use Image from", "Cancel", null, "Default", "Photo Library", "Camera")
            : DisplayActionSheet("Use Image from", "Cancel", null, "Default", "Photo Library"));

            if (action.Equals("Default"))
            {
#if __ANDROID__
                InvokeOnImageLoaded(new Mat(Forms.Context.Assets, imageName));
#else
                Mat m = CvInvoke.Imread(imageName, LoadImageType.AnyColor);
                InvokeOnImageLoaded(m);
#endif
            }
            else if (action.Equals("Photo Library"))
            {
#if __ANDROID__
                Android.Content.Intent intent   = _mediaPicker.GetPickPhotoUI();
                Android.App.Activity   activity = Forms.Context as Android.App.Activity;
                activity.StartActivityForResult(intent, PickImageRequestCode);
                //once the image was picked, the MainActivity.OnActivityResult function will handle the remaining work flow
#else
                var file = await _mediaPicker.PickPhotoAsync();

                using (Stream s = file.GetStream())
                    using (MemoryStream ms = new MemoryStream())
                    {
                        s.CopyTo(ms);
                        byte[] data = ms.ToArray();
                        Mat    m    = new Mat();
                        CvInvoke.Imdecode(data, LoadImageType.Color, m);
                        InvokeOnImageLoaded(m);
                    }
#endif
            }
            else if (action.Equals("Camera"))
            {
#if __ANDROID__
                Android.Content.Intent intent   = _mediaPicker.GetTakePhotoUI(new StoreCameraMediaOptions());
                Android.App.Activity   activity = Forms.Context as Android.App.Activity;
                activity.StartActivityForResult(intent, PickImageRequestCode);
                //once the image was picked, the MainActivity.OnActivityResult function will handle the remaining work flow
#else
                var file = await _mediaPicker.TakePhotoAsync(new StoreCameraMediaOptions());

                using (Stream s = file.GetStream())
                    using (MemoryStream ms = new MemoryStream())
                    {
                        s.CopyTo(ms);
                        byte[] data = ms.ToArray();
                        Mat    m    = new Mat();
                        CvInvoke.Imdecode(data, LoadImageType.Color, m);
                        InvokeOnImageLoaded(m);
                    }
#endif
            }
#endif
        }
Пример #4
0
 /// <summary>
 /// 打印测试
 /// </summary>
 /// <param name="activity"></param>
 public BluetoothPrinter(Android.App.Activity activity)
 {
     this.activity = activity;
     //获得本地的蓝牙适配器
     localAdapter = Android.Bluetooth.BluetoothAdapter.DefaultAdapter;
     //打开蓝牙设备
     if (!localAdapter.IsEnabled)
     {
         Android.Content.Intent enableIntent = new Android.Content.Intent(Android.Bluetooth.BluetoothAdapter.ActionRequestEnable);
         activity.StartActivityForResult(enableIntent, 1);
     }
     //静默打开
     if (!localAdapter.IsEnabled)
     {
         localAdapter.Enable();
     }
     if (!localAdapter.IsEnabled)//用户拒绝打开或系统限制权限
     {
         Android.Widget.Toast.MakeText(activity, "蓝牙未打开", Android.Widget.ToastLength.Short).Show();
         return;
     }
     //获得已配对的设备列表
     bondedDevices = new List<Android.Bluetooth.BluetoothDevice>(localAdapter.BondedDevices);
     if (bondedDevices.Count <= 0)
     {
         Android.Widget.Toast.MakeText(activity, "未找到已配对的蓝牙设备", Android.Widget.ToastLength.Short).Show();
         return;
     }
     string[] items = new string[bondedDevices.Count];
     //查看本地已设置的printer名称
     string ls_localPrinterName = baseclass.MyConfig.of_GetMySysSet("printer", "name");
     if (!string.IsNullOrEmpty(ls_localPrinterName))
     {
         for (int j = 0; j < bondedDevices.Count; j++)
         {
             if(ls_localPrinterName== bondedDevices[j].Name)
             {
                 as_BluetoothName = ls_localPrinterName;
                 System.Threading.Thread thr2 = new System.Threading.Thread(new System.Threading.ThreadStart(Printer));
                 thr2.Start(activity);
                 return;
             }
         }
     }
     //弹窗选择
     for (int i = 0; i < bondedDevices.Count; i++)
     {
         items[i] = bondedDevices[i].Name;
     }
     Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(activity);
     builder.SetTitle("请选择打印设备:");
     builder.SetItems(items, new System.EventHandler<Android.Content.DialogClickEventArgs>(items_click));
     builder.SetNegativeButton("取消", delegate { return; });
     builder.Show();
 }
Пример #5
0
 public BluetoothPrinter(Android.App.Activity activity, PrinterType type, string Number)
 {
     this.as_Number = Number;
     this.printerType = type;
     this.activity = activity;
     //获得本地的蓝牙适配器
     localAdapter = Android.Bluetooth.BluetoothAdapter.DefaultAdapter;
     if (string.IsNullOrEmpty(Number))
     {
         Android.Widget.Toast.MakeText(activity, "传入的单号为空,打印失败", Android.Widget.ToastLength.Short).Show();
         return;
     }
     //打开蓝牙设备
     if (!localAdapter.IsEnabled)
     {
         Android.Content.Intent enableIntent = new Android.Content.Intent(Android.Bluetooth.BluetoothAdapter.ActionRequestEnable);
         activity.StartActivityForResult(enableIntent, 1);
     }
     //静默打开
     if (!localAdapter.IsEnabled)
     {
         localAdapter.Enable();
     }
     if (!localAdapter.IsEnabled)//用户拒绝打开或系统限制权限
     {
         Android.Widget.Toast.MakeText(activity, "蓝牙未打开", Android.Widget.ToastLength.Short).Show();
         return;
     }
     //获得已配对的设备列表
     bondedDevices = new List<Android.Bluetooth.BluetoothDevice>(localAdapter.BondedDevices);
     if (bondedDevices.Count <= 0)
     {
         Android.Widget.Toast.MakeText(activity, "未找到已配对的蓝牙设备", Android.Widget.ToastLength.Short).Show();
         return;
     }
     string[] items = new string[bondedDevices.Count];
     for (int i = 0; i < bondedDevices.Count; i++)
     {
         items[i] = bondedDevices[i].Name;
     }
     Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(activity);
     builder.SetTitle("请选择打印设备:");
     builder.SetItems(items, new System.EventHandler<Android.Content.DialogClickEventArgs>(items_click));
     builder.SetNegativeButton("取消", delegate { return; });
     builder.Show();
 }
Пример #6
0
        public virtual async void LoadImages(String[] imageNames, String[] labels = null)
        {
#if NETFX_CORE
            Mat[] mats = new Mat[imageNames.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                mats[i] = CvInvoke.Imread(imageNames[i], ImreadModes.Color);
            }
            InvokeOnImagesLoaded(mats);
#else
            if (_mediaPicker == null)
            {
#if __ANDROID__
                _mediaPicker = new MediaPicker(Forms.Context);
#else
                _mediaPicker = new MediaPicker();
#endif
            }

            Mat[] mats = new Mat[imageNames.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                String pickImgString = "Use Image from";
                if (labels != null && labels.Length > i)
                {
                    pickImgString = labels[i];
                }
                var action = await(_mediaPicker.IsCameraAvailable?
                                   DisplayActionSheet(pickImgString, "Cancel", null, "Default", "Photo Library", "Camera")
            : DisplayActionSheet(pickImgString, "Cancel", null, "Default", "Photo Library"));

                if (action.Equals("Default"))
                {
#if __ANDROID__
                    mats[i] = new Mat(Forms.Context.Assets, imageNames[i]);
#else
                    mats[i] = CvInvoke.Imread(imageNames[i], ImreadModes.AnyColor);
#endif
                }
                else if (action.Equals("Photo Library"))
                {
#if __ANDROID__
                    Android.Content.Intent intent   = _mediaPicker.GetPickPhotoUI();
                    Android.App.Activity   activity = Forms.Context as Android.App.Activity;
                    activity.StartActivityForResult(intent, PickImageRequestCode);
                    //once the image was picked, the MainActivity.OnActivityResult function will handle the remaining work flow
                    Task t = new Task(() =>
                                      { _waitHandle.WaitOne(); });
                    t.Start();
                    await t;
                    if (MatHandle == null) //Cancelled
                    {
                        return;
                    }
                    mats[i] = MatHandle;
#else
                    var file = await _mediaPicker.PickPhotoAsync();

                    using (Stream s = file.GetStream())
                        using (MemoryStream ms = new MemoryStream())
                        {
                            s.CopyTo(ms);
                            byte[] data = ms.ToArray();
                            Mat    m    = new Mat();
                            CvInvoke.Imdecode(data, ImreadModes.Color, m);
                            mats[i] = m;
                        }
#endif
                }
                else if (action.Equals("Camera"))
                {
#if __ANDROID__
                    Android.Content.Intent intent   = _mediaPicker.GetTakePhotoUI(new StoreCameraMediaOptions());
                    Android.App.Activity   activity = Forms.Context as Android.App.Activity;
                    activity.StartActivityForResult(intent, PickImageRequestCode);
                    //once the image was picked, the MainActivity.OnActivityResult function will handle the remaining work flow
                    Task t = new Task(() =>
                                      { _waitHandle.WaitOne(); });
                    t.Start();
                    await t;
                    if (MatHandle == null) //Cancelled
                    {
                        return;
                    }
                    mats[i] = MatHandle;
#else
                    var file = await _mediaPicker.TakePhotoAsync(new StoreCameraMediaOptions());

                    using (Stream s = file.GetStream())
                        using (MemoryStream ms = new MemoryStream())
                        {
                            s.CopyTo(ms);
                            byte[] data = ms.ToArray();
                            Mat    m    = new Mat();
                            CvInvoke.Imdecode(data, ImreadModes.Color, m);
                            mats[i] = m;
                        }
#endif
                }
            }
            InvokeOnImagesLoaded(mats);
#endif
        }