// Create new views (invoked by the layout manager) public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { // create a new view LocationPanel v = new LocationPanel(parent.Context); // set the view's size, margins, paddings and layout parameters RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); int margin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 4, parent.Context.Resources.DisplayMetrics); layoutParams.SetMargins(0, margin, 0, margin); // l, t, r, b v.LayoutParameters = layoutParams; return(new ViewHolder(v, OnClick, OnLongClick)); }
public ViewHolder(LocationPanel v, Action <RecyclerClickEventArgs> clickListener, Action <RecyclerClickEventArgs> longClickListener) : base(v) { mLocView = v; mBgImageView = v.FindViewById <ImageView>(Resource.Id.image_view); mLocView.Click += (sender, e) => clickListener?.Invoke(new RecyclerClickEventArgs { View = mLocView, Position = AdapterPosition }); mLocView.LongClick += (sender, e) => longClickListener?.Invoke(new RecyclerClickEventArgs { View = mLocView, Position = AdapterPosition }); }
private void OpenExecuted(object sender, ExecutedRoutedEventArgs e) { if (GlobalState.IsPlaying) { ExplosionPanel.PlayPauseSequenceEventHandler(null, null); } if (GlobalState.HasMadeChanges && MessageBox.Show($"Do you want save changes to {currentFileName}?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (fileExists) { SaveExecuted(sender, e); } else { SaveAsExecuted(sender, e); } } var dialog = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".xml", Filter = "Extensible Markup Language File|*.xml" }; bool?result = dialog.ShowDialog(); if (result == true) { string filename = dialog.FileName; List <MapLocation> backupLocations = GlobalState.Locations; List <BoundSequence> backupSequences = GlobalState.Sequences; try { BoundMakerFile fileData = XmlHandler.ReadXmlDocument(filename); NewExecuted(null, null); GlobalState.Locations = fileData.Locations.ToList(); GlobalState.Sequences = fileData.Sequences.ToList(); foreach (MapTerrainTile newTile in fileData.Tiles) { MapEditor.MapTerrain.GetCell(Grid.GetRow(newTile), Grid.GetColumn(newTile)).SetTerrain(newTile.Terrain); } foreach (MapLocation m in GlobalState.Locations) { MapEditor.MapCanvas.Children.Add(m); m.SetWindowInstance(this); } LocationPanel.SetLocationNames(); if (GlobalState.Sequences.Count == 0) { GlobalState.Sequences.Add(new BoundSequence()); } ExplosionPanel.CurrentSequence = GlobalState.Sequences[0]; ExplosionPanel.UpdateNavigation(); if (GlobalState.TerrainPanelIsActive) { SetToTerrainMode(null, null); } else if (GlobalState.LocationPanelIsActive) { SetToLocationMode(null, null); } else if (GlobalState.ExplosionPanelIsActive) { SetToExplosionMode(null, null); } currentFileName = dialog.SafeFileName; fullFilePath = dialog.FileName; fileExists = true; GlobalState.HasMadeChanges = false; RefreshTitle(); } catch { GlobalState.Locations = backupLocations; GlobalState.Sequences = backupSequences; MessageBox.Show("Failed to read file. And I tried really hard, too :("); } } e.Handled = true; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.Inflate(Resource.Layout.fragment_locations, container, false); mMainView = view; view.FindViewById(Resource.Id.search_fragment_container).Click += delegate { ExitSearchUi(); }; view.FocusableInTouchMode = true; view.RequestFocus(); view.KeyPress += (sender, e) => { if (e.KeyCode == Keycode.Back && EditMode) { ToggleEditMode(); e.Handled = true; } else { e.Handled = false; } }; // Setup ActionBar HasOptionsMenu = true; mRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.locations_container); addLocationsButton = view.FindViewById <FloatingActionButton>(Resource.Id.locations_add); addLocationsButton.Click += delegate { mActionMode = AppCompatActivity.StartSupportActionMode(mActionModeCallback); }; gpsPanelLayout = view.FindViewById(Resource.Id.gps_follow_layout); gpsPanel = view.FindViewById <LocationPanel>(Resource.Id.gps_panel); gpsPanel.Click += OnPanelClick; // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.HasFixedSize = false; // use a linear layout manager mLayoutManager = new LinearLayoutManager(AppCompatActivity); mRecyclerView.SetLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new LocationPanelAdapter(Glide.With(this.Context), new List <LocationPanelViewModel>()); mAdapter.ItemClick += OnPanelClick; mAdapter.ItemLongClick += OnPanelLongClick; mAdapter.CollectionChanged += LocationPanels_CollectionChanged; mRecyclerView.SetAdapter(mAdapter); mITHCallback = new ItemTouchHelperCallback(mAdapter); mItemTouchHelper = new ItemTouchHelper(mITHCallback); mItemTouchHelper.AttachToRecyclerView(mRecyclerView); // Turn off by default mITHCallback.SetLongPressDragEnabled(false); mITHCallback.SetItemViewSwipeEnabled(false); Loaded = true; return(view); }