Ejemplo n.º 1
0
        public void PickFolder()
        {
            try
            {
                FilePickerFragment filePickerFragment = new FilePickerFragment(null, null, FilePickerMode.Directory);
                filePickerFragment.FileSelected += (sender, path) =>
                {
                    filePickerFragment.Dismiss();

                    SavaSetting("DownPath", path);
                    if (UpdatePath != null)
                    {
                        UpdatePath(this, null);
                    }
                };
                var activity = (Activity)Forms.Context;
                FragmentTransaction transaction = activity.FragmentManager.BeginTransaction();
                filePickerFragment.Cancel += sender => filePickerFragment.Dismiss();
                filePickerFragment.Show(transaction, "FilePicker");
            }
            catch (Exception ex)
            {
                Toast.MakeText(Forms.Context, "无法打开目录选择器!\r\n" + ex.Message, ToastLength.Long);
            }
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            var buttonDirectoryActivity = FindViewById <Button>(Resource.Id.btnDirectoryActivity);
            var buttonFileActivity      = FindViewById <Button>(Resource.Id.btnFileActivity);
            var buttonDirectoryDialog   = FindViewById <Button>(Resource.Id.btnDirectoryDialog);
            var buttonFileDialog        = FindViewById <Button>(Resource.Id.btnFileDialog);

            buttonDirectoryActivity.Click += delegate
            {
                var intent = new Intent(this, typeof(FilePickerActivity));
                intent.PutExtra(FilePickerActivity.ExtraNewDirName, "NewFolder");
                intent.PutExtra(FilePickerActivity.ExtraInitialDirectory, SelectedDirectory);
                intent.PutExtra(FilePickerActivity.ExtraMode, (int)FilePickerMode.Directory);
                StartActivityForResult(intent, FilePickerActivity.ResultCodeDirSelected);
            };

            buttonFileActivity.Click += delegate
            {
                var intent = new Intent(this, typeof(FilePickerActivity));
                StartActivityForResult(intent, FilePickerActivity.ResultCodeDirSelected);
            };

            buttonDirectoryDialog.Click += delegate
            {
                filePickerFragment = new FilePickerFragment(null, null, FilePickerMode.Directory);
                filePickerFragment.FileSelected += (sender, path) =>
                {
                    filePickerFragment.Dismiss();
                    UpdateSelectedText(path);
                };
                filePickerFragment.Cancel += sender => filePickerFragment.Dismiss();
                filePickerFragment.Show(FragmentManager, "FilePicker");
            };

            buttonFileDialog.Click += delegate
            {
                filePickerFragment = new FilePickerFragment();
                filePickerFragment.FileSelected += (sender, path) =>
                {
                    filePickerFragment.Dismiss();
                    UpdateSelectedText(path);
                };
                filePickerFragment.Cancel += sender => filePickerFragment.Dismiss();
                filePickerFragment.Show(FragmentManager, "FilePicker");
            };
        }