aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Controls
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2020-09-23 20:04:04 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2020-09-24 09:04:33 +0300
commitd0d1425f7605a98a17e92586360c0cb192727d35 (patch)
tree49f7fdcbebee18c58e09216701e289e4c863d0e1 /Software/Visual_Studio/Tango.Touch/Controls
parent47ab5344d38f85eceeb7a80dbb64ef9ed5de974b (diff)
downloadTango-d0d1425f7605a98a17e92586360c0cb192727d35.tar.gz
Tango-d0d1425f7605a98a17e92586360c0cb192727d35.zip
Implement new Notification Control for PPC. Removed all resizeNotifications
, IsExpanded from Notification item, changes in GUI.
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch/Controls')
-rw-r--r--Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs212
-rw-r--r--Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml18
2 files changed, 76 insertions, 154 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
index d7f79cb8d..2710a1d27 100644
--- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
+++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
@@ -27,6 +27,7 @@ namespace Tango.Touch.Controls
public class TouchNotificationBar : ContentControl
{
private const double HEIGHT_RATIO = 0.75;
+ private const double DRAGPATH_HEIGH = 20.0;
private bool _isMouseDown;
private Point _mouseDownLocation;
@@ -47,18 +48,9 @@ namespace Tango.Touch.Controls
private Grid _notification_counter_grid;
private LightTouchScrollViewer _scrollViewer;
- static TouchNotificationBar()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar)));
- }
- public String ItemExpandedPropertyPath
- {
- get { return (String)GetValue(ItemExpandedPropertyPathProperty); }
- set { SetValue(ItemExpandedPropertyPathProperty, value); }
- }
- public static readonly DependencyProperty ItemExpandedPropertyPathProperty =
- DependencyProperty.Register("ItemExpandedPropertyPath", typeof(String), typeof(TouchNotificationBar), new PropertyMetadata(null));
+
+ #region Dep_Properties
public bool HasNotifications
{
@@ -115,8 +107,18 @@ namespace Tango.Touch.Controls
}
public static readonly DependencyProperty NotificationBarVisibilityProperty =
DependencyProperty.Register("NotificationBarVisibility", typeof(Visibility), typeof(TouchNotificationBar), new PropertyMetadata(Visibility.Visible));
+
+ #endregion
+
+ #region constructors
+
+ static TouchNotificationBar()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar)));
+ }
public TouchNotificationBar()
{
+ IsExpanded = false;
Loaded += TouchNotificationBar_Loaded;
NotificationPressedCommand = new RelayCommand(() =>
@@ -128,10 +130,10 @@ namespace Tango.Touch.Controls
});
}
- private void TouchNotificationBar_Loaded(object sender, RoutedEventArgs e)
- {
- _border_drag.MaxHeight = ActualHeight;
- }
+ #endregion
+
+
+ #region Override_Base
public override void OnApplyTemplate()
{
@@ -143,188 +145,120 @@ namespace Tango.Touch.Controls
_items_control = GetTemplateChild("PART_ItemsControl") as ItemsControl;
_notification_counter_grid = GetTemplateChild("PART_NotificationCounterGrid") as Grid;
_scrollViewer = GetTemplateChild("PART_ScrollViewer") as LightTouchScrollViewer;
-
- //border_notifications.IsManipulationEnabled = true;
+
_border_drag.RegisterForPreviewMouseOrTouchDown(GridNotificationMouseDown);
_border_drag.RegisterForMouseOrTouchMove(GridNotificationMouseMove);
_border_drag.RegisterForPreviewMouseOrTouchUp(GridNotificationMouseUp);
-
_border_drag.SizeChanged += Drag_Border_SizeChanged;
- _items_control.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
- }
-
- private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
- {
- if (_items_control.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- if (_items_control.Items.Count > 0)
- {
- var element = _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
- if (element != null)
- {
- element.RegisterForLoadedOrNow((x, y) =>
- {
- var userControl = element.FindChild<UserControl>();
-
- if (userControl != null)
- {
- CurrentMinHeight = userControl.MinHeight;
- }
- });
- }
- }
- else
- {
- CurrentMinHeight = 0;
- }
- }
}
+ #endregion
+
private FrameworkElement GetLastNotification()
{
return _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
}
+ private void TouchNotificationBar_Loaded(object sender, RoutedEventArgs e)
+ {
+ _border_drag.MaxHeight = ActualHeight;
+ }
private void Drag_Border_SizeChanged(object sender, SizeChangedEventArgs e)
{
_grid_mask.Opacity = _border_drag.ActualHeight / ActualHeight;
- ResizeNotifications();
-
- if (e.NewSize.Height > CurrentMinHeight && CurrentMinHeight > 0)
+ if (e.NewSize.Height > CurrentMinHeight && CurrentMinHeight > 0 )
{
_notification_counter_grid.Visibility = Visibility.Hidden;
}
- else
+ else if(Notifications.Count > 1 && CurrentMinHeight > 0)
{
_notification_counter_grid.Visibility = Visibility.Visible;
}
}
- private void ResizeNotifications()
+ /// <summary>
+ /// Called when has notifications items or all items removed
+ /// </summary>
+ private void OnHasNotificationsChanged()
{
- for (int i = 0; i < _items_control.Items.Count; i++)
+ if (HasNotifications)
{
- FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
- ResizeNotification(element);
+ UpdateMinHeightByDispalyedItem();
}
- }
-
- private void ResizeNotification(FrameworkElement element)
- {
- var control = element.FindChild<UserControl>();
-
- if (control != null && !double.IsNaN(_border_drag.Height))
+ else
{
- control.Height = ((_border_drag.Height - CurrentMinHeight) / ActualHeight) * (control.MaxHeight - control.MinHeight) + control.MinHeight;
+ CurrentMinHeight = 0;
+ if (IsExpanded)
+ {
+ CloseNotifications();
+ }
+ _border_notifications.Height = CurrentMinHeight;
+ _grid_container.MinHeight = 0;
+ _grid_container.Height = 0;
}
}
- private void OnHasNotificationsChanged()
+ private void UpdateMinHeightByDispalyedItem()
{
- DoubleAnimation ani = new DoubleAnimation();
- ani.Duration = TimeSpan.FromSeconds(0.2);
-
- _grid_container.EnsureHeight();
-
- if (HasNotifications)
+ var last = GetLastNotification();
+ if(last != null)
{
- var last = GetLastNotification();
-
- last.RegisterForLoadedOrNow((x, e) =>
+ last.RegisterForLoadedOrNow((x, y) =>
{
- ani.To = last.ActualHeight;
- _grid_container.BeginAnimation(Grid.HeightProperty, ani);
+ CurrentMinHeight = last.ActualHeight;
_border_notifications.Height = last.ActualHeight;
+ _grid_container.MinHeight = last.ActualHeight;
+ _grid_container.Height = CurrentMinHeight;
});
}
- else
- {
- CurrentMinHeight = 0;
- ani.To = 0;
- CloseNotifications();
- _grid_container.BeginAnimation(Grid.HeightProperty, ani);
- }
}
-
- private void OnNotificationsChanged()
+ /// <summary>
+ /// Callback function on Notifications property
+ /// </summary>
+ private void OnNotificationsChanged()
{
- UpdateExpanded(IsExpanded);
-
if (Notifications is INotifyCollectionChanged)
{
(Notifications as INotifyCollectionChanged).CollectionChanged += (_, e) =>
{
this.BeginInvoke(() =>
{
- if (e.NewItems != null && e.NewItems.Count > 0)
+ if(Notifications.Count > 0)
{
- foreach (var item in e.NewItems.Cast<Object>().ToList())
- {
- var element = _items_control.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
- if (element != null)
- {
- element.RegisterForLoadedOrNow((___, ____) =>
- {
- ResizeNotification(element);
- });
- }
- }
+ UpdateMinHeightByDispalyedItem();
+ }
+ if (IsExpanded == false && Notifications.Count > 1)
+ {
+ _notification_counter_grid.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ _notification_counter_grid.Visibility = Visibility.Hidden;
}
-
- UpdateExpanded(IsExpanded);
});
- };
+ };
+
}
}
-
- private void UpdateExpanded(bool expanded)
- {
- if (ItemExpandedPropertyPath != null)
- {
- foreach (var item in Notifications.Cast<Object>().ToList())
- {
- item.SetPropertyValueByPath(ItemExpandedPropertyPath, expanded);
- }
- }
- }
-
+
+ #region Mouse handlers
private void OpenNotifications()
{
- _border_drag.EnsureHeight();
- _border_notifications.EnsureHeight();
-
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), _border_drag.MaxHeight, null, null, 1, () =>
- {
- IsExpanded = true;
- });
+ {
+ IsExpanded = true;
+ });
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), ActualHeight * HEIGHT_RATIO, null, null, 1);
-
- UpdateExpanded(true);
}
private void CloseNotifications()
{
- _border_drag.EnsureHeight();
- _border_notifications.EnsureHeight();
-
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
{
_border_notifications.BeginAnimation(Border.HeightProperty, null);
_border_notifications.Height = CurrentMinHeight;
-
- for (int i = 0; i < _items_control.Items.Count; i++)
- {
- FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
-
- var control = element.FindChild<UserControl>();
-
- if (control != null)
- {
- control.Height = control.MinHeight;
- }
- }
});
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
@@ -337,9 +271,7 @@ namespace Tango.Touch.Controls
tAni.Duration = TimeSpan.FromSeconds(0.3);
tAni.To = new Thickness(0);
_border_notifications.BeginAnimation(Border.BorderThicknessProperty, tAni);
-
- UpdateExpanded(false);
-
+
IsExpanded = false;
Task.Delay(400).ContinueWith((x) =>
@@ -432,7 +364,7 @@ namespace Tango.Touch.Controls
if (_border_notifications.ActualHeight > CurrentMinHeight)
{
- _border_notifications.BorderThickness = new Thickness(0, 0, 0, 20);
+ _border_notifications.BorderThickness = new Thickness(0, 0, 0, DRAGPATH_HEIGH);
}
else
{
@@ -455,5 +387,7 @@ namespace Tango.Touch.Controls
_isMouseDown = true;
}
}
+
+ #endregion
}
}
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml
index d097aa2bb..689981de6 100644
--- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml
+++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml
@@ -8,7 +8,6 @@
<ResourceDictionary Source="../Resources/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
- <converters:GreaterThanToBooleanConverter x:Key="GreaterThanToBooleanConverter" />
<Style TargetType="{x:Type local:TouchNotificationBar}">
<Setter Property="Template">
@@ -27,7 +26,6 @@
<ContentPresenter Grid.Row="1" Content="{TemplateBinding Content}" />
<Grid x:Name="PART_GridMask" Grid.RowSpan="2" Background="{StaticResource TangoNotificationBarMaskBrush}" Opacity="0" IsHitTestVisible="False">
-
</Grid>
<Grid x:Name="PART_Grid_Container" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent},Path=NotificationBarVisibility}" VerticalAlignment="Top" Background="Transparent" ClipToBounds="False">
@@ -36,6 +34,7 @@
<Border x:Name="PART_BorderNotifications" VerticalAlignment="Top" BorderBrush="{StaticResource TangoNotificationBarBottomBorderBrush}" Background="{StaticResource TangoNotificationBarBackgroundBrush}">
<local:LightTouchScrollViewer x:Name="PART_ScrollViewer">
<ItemsControl x:Name="PART_ItemsControl" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Notifications}">
+
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="{StaticResource TangoNotificationBackgroundBrush}" BorderBrush="{StaticResource TangoNotificationBorderBrush}" BorderThickness="0 0 0 0">
@@ -53,20 +52,9 @@
</Border>
</Border>
- <Grid x:Name="PART_NotificationCounterGrid" Canvas.Left="41" Canvas.Top="19" Width="24" Height="24" HorizontalAlignment="Left" VerticalAlignment="Bottom" IsHitTestVisible="False">
+ <Grid x:Name="PART_NotificationCounterGrid" Canvas.Left="41" Canvas.Top="19" Width="24" Height="24" HorizontalAlignment="Left" VerticalAlignment="Bottom" IsHitTestVisible="False" Visibility="Collapsed">
<Grid>
- <Grid.Style>
- <Style TargetType="Grid">
- <Setter Property="Visibility" Value="Collapsed"></Setter>
- <Style.Triggers>
- <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchNotificationBar},Path=Notifications.Count,Converter={StaticResource GreaterThanToBooleanConverter},ConverterParameter=1}" Value="True">
- <Setter Property="Visibility" Value="Visible"></Setter>
- </DataTrigger>
- </Style.Triggers>
- </Style>
- </Grid.Style>
- <Ellipse Fill="White" StrokeThickness="1" Stroke="{StaticResource TangoPrimaryAccentBrush}">
- </Ellipse>
+ <Ellipse Fill="White" StrokeThickness="1" Stroke="{StaticResource TangoPrimaryAccentBrush}"/>
<TextBlock HorizontalAlignment="Center" FontSize="12" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=local:TouchNotificationBar},Path=Notifications.Count}"></TextBlock>
</Grid>
</Grid>