Exemplo n.º 1
0
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            switch (item.ItemId)
            {
                case Resource.Id.translate:
                    int min = 0;
                    int max = book.Text.Length;
                    if (book.IsFocused)
                    {
                        int selStart = book.SelectionStart;
                        int selEnd = book.SelectionEnd;

                        min = Math.Max(0, Math.Min(selStart, selEnd));
                        max = Math.Max(0, Math.Max(selStart, selEnd));
                    }
                    var selectedText = book.Text.Substring(min, max - min);
                    try
                    {
                        ConfigureTranslator();
                        var translator = new Translator(_langFrom, _langTo);
                        var res = translator.Translate(selectedText).GetAwaiter().GetResult();
                        ShowEditDialog(selectedText, res);
                    }
                    catch (System.Exception)
                    {
                        Toast.MakeText(ParentActivity, "Missing internet connection", ToastLength.Short).Show();
                    }
                    mode.Finish();
                    return true;
                default:
                    break;
            }
            return false;
        }
Exemplo n.º 2
0
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);

            ListView.ItemClick += (sender, e) => {
                //already in action mode?
                if (_actionMode != null)
                    return;

                //toggle system ui visibility
                if (_systemUiVisible)
                {
                    Activity.Window.ClearFlags (WindowManagerFlags.Fullscreen);
                    ListView.SystemUiVisibility = StatusBarVisibility.Visible;
                    Activity.ActionBar.Show ();
                }
                else
                {
                    Activity.Window.SetFlags (0, WindowManagerFlags.Fullscreen);
                    ListView.SystemUiVisibility = StatusBarVisibility.Hidden;
                    Activity.ActionBar.Hide ();
                }
                _systemUiVisible = !_systemUiVisible;
            };

            ListView.ItemLongClick += delegate(object sender, AdapterView.ItemLongClickEventArgs e) {
                if (_actionMode != null)
                    return;

                var callback = new MessageAction(Activity.GetString(Resource.String.message_action_title),
                                                 Activity.GetString(Resource.String.message_action_subtitle));

                callback.DeleteActionHandler += delegate {
                    DeleteMessage (_sortedItems[e.Position]);
                    _actionMode.Finish ();
                    _actionMode = null;
                };

                callback.ViewActionHandler += delegate {
                    ViewMessage(_sortedItems[e.Position]);
                    _actionMode.Finish ();
                    _actionMode = null;
                };

                callback.CopyActionHandler += delegate {
                    CopyMessage (_sortedItems[e.Position]);
                    _actionMode.Finish ();
                    _actionMode = null;
                };

                callback.DestroyActionHandler += delegate {
                    _actionMode = null;
                };

                _actionMode = Activity.StartActionMode (callback);
            };
        }
Exemplo n.º 3
0
 /** This is called when an item in the context menu is selected */
 public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
 {
   switch (item.ItemId)
   {
     case R.Id.submenu:
       Toast.MakeText(mainActivity.BaseContext, "Selected Action1 ", Toast.LENGTH_LONG).Show();
       mode.Finish();    // Automatically exists the action mode, when the user selects this action
       break;
   }
   return false;
 }
Exemplo n.º 4
0
		public bool OnActionItemClicked (ActionMode mode, IMenuItem item)
		{
			switch (item.ItemId) {
			case Resource.Id.share:
				Toast.MakeText (self, "Shared " + self.ListView.CheckedItemCount +
				               " items", ToastLength.Short).Show ();
				mode.Finish ();
				break;

			default:
				Toast.MakeText (self, "Clicked " + item.TitleFormatted,
				               ToastLength.Short).Show ();
				break;
			}
			return true;
		}
Exemplo n.º 5
0
            public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
            {
                switch (item.ItemId)
                {
                //ifuserclickmenu print_me
                case Resource.Id.print_me:
                    //createanalert dialog
                    AlertDialog.Builder builder = new AlertDialog.Builder(parent);
                    string msg = "Are you sure you want to print items?";
                    builder.SetMessage(msg)
                    .SetCancelable(false)
                    .SetPositiveButton("Yes", (or, er) =>
                    {
                        SparseBooleanArray selected = parent.myAdapter.getSelectedIds();
                        List <string> list_item     = new List <string>();
                        for (int i = (selected.Size() - 1); i >= 0; i--)
                        {
                            //checkisvaluecheckedby user
                            if (selected.ValueAt(i))
                            {
                                int selectedItem = (int)parent.myAdapter.GetItem(selected.KeyAt(i));
                                list_item.Add(selectedItem.ToString());
                            }
                        }
                        //print message
                        Toast.MakeText(parent, "YouSelect" + parent.myAdapter.getSelectedCount() + "Item:[" + string.Join(",", list_item) + "]", ToastLength.Long).Show();
                        mode.Finish();

                        parent.below_layout.Visibility = ViewStates.Gone;      // Gone
                    })
                    .SetNegativeButton("No", (or, er) =>
                    {
                        parent.below_layout.Visibility = ViewStates.Gone;      // Gone

                        ((Dialog)or).Cancel();
                    });

                    AlertDialog alert = builder.Create();
                    alert.Show();

                    return(true);

                default:
                    return(false);
                }
            }
Exemplo n.º 6
0
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            if (item.ItemId == Resource.Id.ActionModeDeleteItem)
            {
                if (actionModePosition == -1)
                    return false;

                var feed = feeds [actionModePosition];

                new DataAccess.FeedRepository().Delete(feed.Id);

                FillListView();

                actionModePosition = -1;

                mode.Finish();

                Toast.MakeText(this, String.Format("{0} deleted.", feed.Name), ToastLength.Short).Show();

                return true;
            }

            return false;
        }
Exemplo n.º 7
0
        private void OnListItemSelect(int position)
        {
            myAdapter.toggleSelection(position);
            bool hasCheckedItems = myAdapter.getSelectedCount() > 0;

            if (hasCheckedItems && mActionMode == null)
            {
                mActionMode = StartActionMode(new ActionModeCallback(this));

                below_layout.Visibility = ViewStates.Visible;// display the menu bar
            }
            else if (!hasCheckedItems && mActionMode != null)
            {
                mActionMode.Finish();
                below_layout.Visibility = ViewStates.Gone;// display the menu bar
            }

            if (mActionMode != null)
            {
                mActionMode.Title = (myAdapter.getSelectedCount().ToString() + "selected");

                below_layout.Visibility = ViewStates.Visible;// display the menu bar
            }
        }
		// Called when the user selects a contextual menu item
		public bool OnActionItemClicked (ActionMode mode, IMenuItem item)
		{
			switch (item.ItemId)
			{

				case Resource.Id.context_action_share:
					Toast.MakeText (Activity, "Sharing coming soon...", ToastLength.Short).Show ();
					return false;
				case Resource.Id.context_action_delete:
					Adapter.RemoveSelectedItems ();
					mode.Finish ();
					return true;
				case Resource.Id.context_action_select_all:
					Adapter.SelectAllItems ();
					return true;
				default:
					return false;
			}
		}
			public bool OnActionItemClicked (ActionMode mode, IMenuItem item)
			{
				switch (item.ItemId) {
					case Resource.Id.start:
						brickController.SpawnThread( delegate() {
							FileItem currentItemSelected = adapter.SelectedItems.First();
							if(currentItemSelected.FileType == MonoBrick.FileType.Program){
								brickController.NXT.StartProgram(currentItemSelected.Name, true);
								this.Activity.RunOnUiThread(delegate(){
									TabActivity.ShowToast(this.Activity, "Program successfully started");
								});
								
							}
							else{
								brickController.NXT.PlaySoundFile(currentItemSelected.Name,false,true);
								this.Activity.RunOnUiThread(delegate(){
									TabActivity.ShowToast(this.Activity, "Sound file started");
								});
							}
						});
					break;
					case Resource.Id.stop:
						brickController.SpawnThread( delegate() {
							brickController.NXT.StopProgram(true);
							this.Activity.RunOnUiThread(delegate(){
								TabActivity.ShowToast(this.Activity,"All programs stoped");
							});
						});
					break;
					case Resource.Id.delete:
						
						AlertDialog.Builder dialog = new AlertDialog.Builder(this.View.Context);
						dialog.SetIcon(Android.Resource.Drawable.IcMenuInfoDetails);
						dialog.SetTitle("Delete file(s)");
						string message;
						if(adapter.SelectedItems.Count> 1){
							message = "Are you sure you want to delete " + adapter.SelectedItems.Count + " files ?";
						}
						else{
							message = "Are you sure you want to delete " + adapter.SelectedItems.First().Name + " ?";
						}
						dialog.SetMessage(message);
						dialog.SetPositiveButton("Yes",delegate(object sender, DialogClickEventArgs e){	
							ProgressDialog progress = null;
							this.Activity.RunOnUiThread(delegate() {
								progress = ProgressDialog.Show(this.View.Context,"Deleting files","PLease Wait...       ");
							});
							System.Threading.Thread t =  new System.Threading.Thread( delegate(object obj){
								brickController.ExecuteOnCurrentThread(delegate() {
									Exception ex = null;
									List<FileItem> uncheckList = new List<FileItem>();
									try{
										int i = 0;
										foreach(FileItem myFileItem in adapter.SelectedItems){
											if(adapter.SelectedItems.Count > 1){
												progress.SetMessage("Deleteing file " + (i+1) + " of " + adapter.SelectedItems.Count);
											}
											else{
												progress.SetMessage("Deleteing " + myFileItem.Name);
											}
											brickController.NXT.FileSystem.DeleteFile(myFileItem.Name);
											adapter.Items.Remove(myFileItem);
											uncheckList.Add(myFileItem);
											i++;
										}
									}
									catch (Exception excep){
										ex = excep;
									}
									finally
        							{
           								foreach(FileItem fi in uncheckList){
           									adapter.SelectedItems.Remove(fi);
           								}
           								this.Activity.RunOnUiThread(delegate() {
	           								progress.Dismiss();
											adapter.NotifyDataSetChanged();
											if(mode != null){
	           									mode.Finish();
	           								}
	           							});
	           								
       								}
       								if(ex != null)
       									throw ex;
									
								});
							});
							t.IsBackground = true;
							t.Priority = System.Threading.ThreadPriority.Normal;
							t.Start();
						});
						dialog.SetNegativeButton("No", delegate(object sender, DialogClickEventArgs e){});
						dialog.Show();
					break;
					case Resource.Id.download:
						Console.WriteLine("Download");
					break;
				}
			
				return true;
			}
Exemplo n.º 10
0
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            switch (item.ItemId)
            {
                case 0:
                    int min = 0;
                    int max = book.Text.Length;
                    if (book.IsFocused)
                    {
                        int selStart = book.SelectionStart;
                        int selEnd = book.SelectionEnd;

                        min = Math.Max(0, Math.Min(selStart, selEnd));
                        max = Math.Max(0, Math.Max(selStart, selEnd));
                    }
                    // Perform your definition lookup with the selected text
                    var selectedText = book.Text.Substring(min, max-min);
                    // Finish and close the ActionMode
                    mode.Finish();
                    return true;
                default:
                    break;
            }
            return false;
        }
        bool ActionMode.ICallback.OnActionItemClicked (ActionMode mode, IMenuItem item)
        {
            switch (item.ItemId) {
            case Resource.Id.DeleteMenuItem:
                DeleteCheckedTimeEntries ();
                mode.Finish ();
                return true;
//            case Resource.Id.EditMenuItem:
            // TODO: Show time entry editing
//                return true;
            default:
                return false;
            }
        }