private void Initialize() { Id = _viewId; _maxNumberOfIndiagrams = LazyResolver<IScreenService>.Service.Width / IndiagramView.DefaultWidth - 1; ISettingsService settings = LazyResolver<ISettingsService>.Service; ColorStringToIntConverter colorConverter = new ColorStringToIntConverter(); // Init views for (int i = 0; i < _maxNumberOfIndiagrams; ++i) { IndiagramView view = new IndiagramView(Context) { TextColor = (uint) colorConverter.Convert(settings.TextColor, null, null, null), Id = _viewId++, DefaultColor = 0, }; view.Touch += OnIndiagramTouched; var layoutParams = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); layoutParams.AddRule(LayoutRules.CenterVertical); if (i == 0) { layoutParams.AddRule(LayoutRules.AlignParentLeft); } else { layoutParams.AddRule(LayoutRules.RightOf, _viewId - 2); } AddView(view, layoutParams); _indiagramViews.Add(view); } // Init play button _playButton = new IndiagramView(Context) { TextColor = 0, Id = _viewId++, Indiagram = new Indiagram() { Text = "play", ImagePath = LazyResolver<IStorageService>.Service.ImagePlayButtonPath } }; _playButton.Touch += (sender, args) => { if (args.Event.ActionMasked == MotionEventActions.Up){ if(args.Event.RawX<(LazyResolver<IScreenService>.Service.Width/4.0)){ if (CorrectionCommand != null && CorrectionCommand.CanExecute(null)) { CorrectionCommand.Execute(null); } } else if (ReadCommand != null && ReadCommand.CanExecute(null)) { ReadCommand.Execute(null); } } }; var lp = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); lp.AddRule(LayoutRules.AlignParentRight); lp.AddRule(LayoutRules.CenterVertical); AddView(_playButton, lp); }
private bool Reset() { int newColumnCount = (int)(ActualWidth / IndiagramView.DefaultWidth); int newLineCount = (int)(ActualHeight / IndiagramView.DefaultHeight); if ((int)ActualHeight == 0) newLineCount = (int)(Height / IndiagramView.DefaultHeight); if (newColumnCount != _columnCount || newLineCount != _lineCount) { _columnCount = newColumnCount; _lineCount = newLineCount; } else { return false; } if (_displayableViews != null) { Children.Clear(); _displayableViews = null; } _displayableViews = new IndiagramView[_lineCount][]; for (int line = 0; line < _lineCount; ++line) { _displayableViews[line] = new IndiagramView[_columnCount - ((line == 0) ? 1 : 0)]; for (int column = 0; column < _displayableViews[line].Length; ++column) { var view = new IndiagramView { TextColor = TextColor }; view.Tapped += view_Tapped; _displayableViews[line][column] = view; } } ResetGrid(); return true; }
private void OnTopIndiagramViewTouched(IndiagramView view) { if (SettingsService.IsDragAndDropEnabled && !view.Indiagram.IsCategory && !TextToSpeechService.IsReading) { Indiagram indiagram = view.Indiagram; // command should only be executed when the indiagram is "dropped" in sentence view if (!SettingsService.IsMultipleIndiagramSelectionEnabled || IsCorrectionModeEnabled) { _topView.HideIndiagram(indiagram); } // get existing view view.Touch += OnIndiagramTouched; _currentView = view; _topView.SwitchViewForDragAndDrop(view); float left = _currentView.LastTouchArgs.Event.RawX; float top = _currentView.LastTouchArgs.Event.RawY; // attach to new layout AddView(view, new LayoutParams(IndiagramView.DefaultWidth, _currentView.RealHeight, (int)(left - IndiagramView.DefaultWidth / 2f), (int)(top - _currentView.RealHeight /2f))); _topView.RefreshView(); if (TopIndiagramDragStartCommand != null && TopIndiagramDragStartCommand.CanExecute(indiagram)) { TopIndiagramDragStartCommand.Execute(indiagram); } } }
private void OnIndiagramTouched(object sender, TouchEventArgs touchEventArgs) { IndiagramView view = sender as IndiagramView; if (view == null || view != _currentView) { return; } if (touchEventArgs.Event.ActionMasked == MotionEventActions.Move) { float left = touchEventArgs.Event.RawX; float top = touchEventArgs.Event.RawY; _currentView.LayoutParameters = new LayoutParams(IndiagramView.DefaultWidth, _currentView.RealHeight, (int)(left - IndiagramView.DefaultWidth / 2f), (int)(top - _currentView.RealHeight /2f)); } else if (touchEventArgs.Event.ActionMasked == MotionEventActions.Up) { bool selected = touchEventArgs.Event.RawY >= _botViewYOffset; //in any case, remove from the current view _currentView.Touch -= OnIndiagramTouched; RemoveView(_currentView); _currentView = null; if(selected) { var command = TopIndiagramSelectedCommand; if (command != null && command.CanExecute(view.Indiagram)) { command.Execute(view.Indiagram); } } if (!SettingsService.IsMultipleIndiagramSelectionEnabled) { _topView.ShowAllIndiagrams(); _topView.RefreshView(); } } }
void SentenceAreaView_SizeChanged(object sender, SizeChangedEventArgs e) { var oldmaxnumber = _maxNumberOfIndiagrams; _maxNumberOfIndiagrams = ((int)ActualWidth / IndiagramView.DefaultWidth) - 1; if (_maxNumberOfIndiagrams == oldmaxnumber) return; ColumnDefinitions.Clear(); for (var i = 0; i < _maxNumberOfIndiagrams + 1; i++) { ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); } SetColumn(_playButton, _maxNumberOfIndiagrams); Children.Clear(); Children.Add(_playButton); var settings = LazyResolver<ISettingsService>.Service; // Init views for (var i = 0; i < _maxNumberOfIndiagrams; ++i) { var view = new IndiagramView() { TextColor = (SolidColorBrush)_colorConverter.Convert(settings.TextColor, null, null, "") }; view.Tapped += OnIndiagramTouched; SetColumn(view, i); Children.Add(view); _indiagramViews.Add(view); } }