- RFC : http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+10+-+FloatingButton?showComments=true
Change-Id: Icafcf939b671a01ad517f9c1598ec3b143214e5a
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+using Tizen.Xamarin.Forms.Extension;
+using Xamarin.Forms;
+using Xamarin.Forms.Platform.Tizen;
+using ElmSharp;
+using Button = Xamarin.Forms.Button;
+using EFloatingButton = ElmSharp.FloatingButton;
+using EFloatingButtonPosition = ElmSharp.FloatingButtonPosition;
+using TForms = Xamarin.Forms.Platform.Tizen.Forms;
+
+[assembly: Dependency(typeof(FloatingButtonImplementation))]
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ internal class FloatingButtonImplementation : IFloatingButton, IDisposable
+ {
+ EFloatingButton _control = null;
+ FloatingButtonMovablePosition _movablePosition = FloatingButtonMovablePosition.All;
+ FloatingButtonPosition _position = FloatingButtonPosition.Right;
+ bool _isShown = true;
+ FloatingButtonItem _firstButton = null;
+ FloatingButtonItem _secondButton = null;
+ EvasObject _firstNativeButton = null;
+ EvasObject _secondNativeButton = null;
+ bool _isDisposed = false;
+
+ public FloatingButtonImplementation()
+ {
+ _control = new EFloatingButton(TForms.Context.MainWindow)
+ {
+ Mode = FloatingButtonMode.All,
+ MinimumHeight = 100,
+ MinimumWidth = 100,
+ };
+ UpdateLocation();
+ TForms.Context.MainWindow.RotationChanged += (s, e) => { UpdateLocation(); };
+ }
+
+ ~FloatingButtonImplementation()
+ {
+ Dispose();
+ }
+
+ public FloatingButtonMovablePosition MovablePosition
+ {
+ get { return _movablePosition; }
+ set
+ {
+ _movablePosition = (FloatingButtonMovablePosition)value;
+ UpdateMovablePosition();
+ }
+ }
+
+ public FloatingButtonPosition Position
+ {
+ get { return _position; }
+ }
+
+ public bool IsShown
+ {
+ get { return _isShown; }
+ }
+
+ public FloatingButtonItem FirstButton
+ {
+ get { return _firstButton; }
+ set
+ {
+ _firstButton = (FloatingButtonItem)value;
+ UpdateButton(FloatingButtonItemPosition.First);
+ }
+ }
+
+ public FloatingButtonItem SecondButton
+ {
+ get { return _secondButton; }
+ set
+ {
+ _secondButton = (FloatingButtonItem)value;
+ UpdateButton(FloatingButtonItemPosition.Second);
+ }
+ }
+
+ public void SetPosition(FloatingButtonPosition position, bool animated)
+ {
+ if (_movablePosition != FloatingButtonMovablePosition.None)
+ {
+ _position = (FloatingButtonPosition)position;
+ UpdatePosition(animated);
+ }
+ }
+
+ public void Show()
+ {
+ _isShown = true;
+ _control.Show();
+ }
+
+ public void Hide()
+ {
+ _isShown = false;
+ _control.Hide();
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_isDisposed)
+ return;
+
+ if (_firstNativeButton != null)
+ {
+ _firstNativeButton?.Unrealize();
+ _firstNativeButton = null;
+ }
+
+ if (_secondNativeButton != null)
+ {
+ _secondNativeButton?.Unrealize();
+ _secondNativeButton = null;
+ }
+
+ if (_control != null)
+ {
+ _control?.Unrealize();
+ _control = null;
+ }
+
+ _isDisposed = true;
+ }
+
+ void UpdateLocation()
+ {
+ var window = TForms.Context.MainWindow;
+ var size = window.ScreenSize;
+ if (window.Rotation == 0)
+ {
+ _control.Resize(size.Width, size.Height);
+ var h = (int)(size.Height * 0.8);
+ _control.Move(0, h);
+ }
+ else
+ {
+ _control.Resize(size.Height, size.Width);
+ var h = (int)(size.Width * 0.8);
+ _control.Move(0, h);
+ }
+ _control.Show();
+ }
+
+ void UpdateMovablePosition()
+ {
+ if (MovablePosition == FloatingButtonMovablePosition.None)
+ _control.MovementBlock = true;
+ else
+ {
+ _control.MovementBlock = false;
+ _control.Mode = (FloatingButtonMode)MovablePosition;
+ }
+ }
+
+ void UpdatePosition(bool animated)
+ {
+ if (MovablePosition != FloatingButtonMovablePosition.None)
+ _control.SetPosition((EFloatingButtonPosition)Position, animated);
+ }
+
+ void UpdateButton(FloatingButtonItemPosition position)
+ {
+ switch (position)
+ {
+ case FloatingButtonItemPosition.First:
+ _firstNativeButton?.Unrealize();
+ _firstNativeButton = GetNativeButton(FirstButton);
+ _control.SetPartContent("button1", _firstNativeButton, true);
+ break;
+
+ case FloatingButtonItemPosition.Second:
+ _secondNativeButton?.Unrealize();
+ _secondNativeButton = GetNativeButton(SecondButton);
+ _control.SetPartContent("button2", _secondNativeButton, true);
+ break;
+ }
+ }
+
+ EvasObject GetNativeButton(FloatingButtonItem item)
+ {
+ if (item == null) return null;
+ Button button = new Button();
+ if (item.Icon != null)
+ button.Image = item.Icon;
+ button.Clicked += (s, e) => { item.OnClicked(); };
+ EvasObject nativeView = Platform.GetOrCreateRenderer(button).NativeView;
+ return nativeView;
+ }
+
+ enum FloatingButtonItemPosition
+ {
+ First,
+ Second,
+ }
+ }
+}
\ No newline at end of file
<Compile Include="Cells\MultilineCellRenderer.cs" />\r
<Compile Include="Cells\TypeCellRenderer.cs" />\r
<Compile Include="LongTapGestureHandler.cs" />\r
+ <Compile Include="FloatingButtonImplementation.cs" />\r
<Compile Include="RadioButtonRenderer.cs" />\r
<Compile Include="GridViewRenderer.cs" />\r
<Compile Include="TizenExtension.cs" />\r
<_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
<AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
</PropertyGroup>\r
-</Project>
+</Project>\r
--- /dev/null
+using System;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ /// <summary>
+ /// The FloatingButton class
+ /// This is only supported for mobile profiles.
+ /// </summary>
+ /// <example>
+ /// <code>
+ /// FloatingButton floatingButton = new FloatingButton
+ /// {
+ /// MovablePosition = FloatingButtonMovablePosition.All,
+ /// };
+ ///
+ /// FloatingButtonItem item = new FloatingButtonItem();
+ /// item.Icon = new FileImageSource { File = "Icon.png" };
+ /// item.Clicked += (s,e) => { ... };
+ /// floatingButton.FirstButton = item;
+ ///
+ /// this.Appearing += (s,e) =>
+ /// {
+ /// If (!floatingButton.IsShown)
+ /// floatingButton.Show();
+ /// }
+ /// this.Disappearing += (s,e) =>
+ /// {
+ /// If (floatingButton.IsShown)
+ /// floatingButton.Hide();
+ /// }
+ /// </code>
+ /// </example>
+ public class FloatingButton : BindableObject, IFloatingButton
+ {
+ public static readonly BindableProperty MovablePositionProperty = BindableProperty.Create(nameof(MovablePosition), typeof(FloatingButtonMovablePosition), typeof(FloatingButton), FloatingButtonMovablePosition.All);
+
+ public static readonly BindableProperty PositionProperty = BindableProperty.Create(nameof(Position), typeof(FloatingButtonPosition), typeof(FloatingButton), FloatingButtonPosition.Right);
+
+ public static readonly BindableProperty IsShownProperty = BindableProperty.Create(nameof(IsShown), typeof(bool), typeof(FloatingButton), true);
+
+ public static readonly BindableProperty FirstButtonProperty = BindableProperty.Create(nameof(FirstButton), typeof(FloatingButtonItem), typeof(FloatingButton), null);
+
+ public static readonly BindableProperty SecondButtonProperty = BindableProperty.Create(nameof(SecondButton), typeof(FloatingButtonItem), typeof(FloatingButton), null);
+
+ IFloatingButton _floatingButton = null;
+
+ /// <summary>
+ /// Gets or sets the movability state of the FloatingButton. This is a bindable property.
+ /// </summary>
+ public FloatingButtonMovablePosition MovablePosition
+ {
+ get { return (FloatingButtonMovablePosition)GetValue(MovablePositionProperty); }
+ set { SetValue(MovablePositionProperty, value); }
+ }
+
+ /// <summary>
+ /// Gets the horizontal position of the FloatingButton. This is a bindable property
+ /// </summary>
+ public FloatingButtonPosition Position
+ {
+ get { return (FloatingButtonPosition)GetValue(PositionProperty); }
+ }
+
+ /// <summary>
+ /// Gets the visible state of the FloatingButton.
+ /// </summary>
+ public bool IsShown
+ {
+ get { return (bool)GetValue(IsShownProperty); }
+ internal set { SetValue(IsShownProperty, value); }
+ }
+
+ /// <summary>
+ /// Gets and sets the internal button of the FloatingButton
+ /// </summary>
+ public FloatingButtonItem FirstButton
+ {
+ get { return (FloatingButtonItem)GetValue(FirstButtonProperty); }
+ set { SetValue(FirstButtonProperty, value); }
+ }
+
+ /// <summary>
+ /// Gets and sets the internal button of the FloatingButton
+ /// </summary>
+ public FloatingButtonItem SecondButton
+ {
+ get { return (FloatingButtonItem)GetValue(SecondButtonProperty); }
+ set { SetValue(SecondButtonProperty, value); }
+ }
+
+ /// <summary>
+ /// Sets the horizontal position of the FloatingButton.
+ /// </summary>
+ /// <param name="position"> FloatingButtonPosition value </param>
+ /// <param name="animated"> Bool value to set the animation when moving the position </param>
+ public void SetPosition(FloatingButtonPosition position, bool animated)
+ {
+ if (MovablePosition != FloatingButtonMovablePosition.None)
+ {
+ _floatingButton.SetPosition(position, animated);
+ }
+ }
+
+ /// <summary>
+ /// A method to hide the FloatingButton
+ /// </summary>
+ public void Hide()
+ {
+ IsShown = false;
+ _floatingButton.Hide();
+ }
+
+ /// <summary>
+ /// A method to show the FloatingButton
+ /// </summary>
+ public void Show()
+ {
+ IsShown = true;
+ _floatingButton.Show();
+ }
+
+ public FloatingButton()
+ {
+ if (Device.Idiom != TargetIdiom.Phone)
+ throw new Exception("FloatingButton is support only mobile profile.");
+
+ _floatingButton = DependencyService.Get<IFloatingButton>(DependencyFetchTarget.GlobalInstance);
+
+ if (_floatingButton == null)
+ throw new Exception("Object reference not set to an instance of a FloatingButton.");
+
+ SetBinding(MovablePositionProperty, new Binding(nameof(MovablePosition), mode: BindingMode.TwoWay, source: _floatingButton));
+ SetBinding(PositionProperty, new Binding(nameof(Position), mode: BindingMode.TwoWay, source: _floatingButton));
+ SetBinding(FirstButtonProperty, new Binding(nameof(FirstButton), mode: BindingMode.TwoWay, source: _floatingButton));
+ SetBinding(SecondButtonProperty, new Binding(nameof(SecondButton), mode: BindingMode.TwoWay, source: _floatingButton));
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ /// <summary>
+ /// A class for containing icons and event information
+ /// </summary>
+ public class FloatingButtonItem
+ {
+ FileImageSource _icon = null;
+
+ public FloatingButtonItem()
+ {
+ }
+
+ /// <summary>
+ /// Gets or sets the Icon of the FloatingButtonItem
+ /// </summary>
+ public FileImageSource Icon
+ {
+ get { return _icon; }
+ set { _icon = value; }
+ }
+
+ /// <summary>
+ /// Occurs when the FloatingButtonItem clicked
+ /// </summary>
+ public event EventHandler Clicked;
+
+ internal void OnClicked()
+ {
+ Clicked?.Invoke(this, EventArgs.Empty);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ /// <summary>
+ /// Enumerates values that describe the Mode of FloatingButton.
+ /// </summary>
+ public enum FloatingButtonMovablePosition
+ {
+ /// <summary>
+ /// allows all positions
+ /// </summary>
+ All,
+
+ /// <summary>
+ /// allows LEFT and RIGHT positions only
+ /// </summary>
+ LeftRightOnly,
+
+ /// <summary>
+ /// movement blocked
+ /// </summary>
+ None,
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ /// <summary>
+ /// Positions of FloatingButton where floatingbutton can be placed on
+ /// </summary>
+ public enum FloatingButtonPosition
+ {
+ /// <summary>
+ /// hides in the left, but small handler will show only
+ /// </summary>
+ LeftOut,
+
+ /// <summary>
+ /// shows all of buttons, but lies on the left
+ /// </summary>
+ Left,
+
+ /// <summary>
+ /// shows all of buttons, but lies on the center
+ /// </summary>
+ Center,
+
+ /// <summary>
+ /// shows all of buttons, but lies on the right
+ /// </summary>
+ Right,
+
+ /// <summary>
+ /// hides in the right, but small handler will show only
+ /// </summary>
+ RightOut,
+ }
+}
\ No newline at end of file
--- /dev/null
+using System;
+using Xamarin.Forms;
+using System.Windows.Input;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+ internal interface IFloatingButton
+ {
+ FloatingButtonPosition Position { get; }
+
+ FloatingButtonMovablePosition MovablePosition { get; set; }
+
+ bool IsShown { get; }
+
+ FloatingButtonItem FirstButton { get; set; }
+
+ FloatingButtonItem SecondButton { get; set; }
+
+ void SetPosition(FloatingButtonPosition position, bool animated);
+
+ void Show();
+
+ void Hide();
+ }
+}
\ No newline at end of file
<Compile Include="Cells\BaseTypeCell.cs" />\r
<Compile Include="Cells\MultilineCell.cs" />\r
<Compile Include="EnumerableExtensions.cs" />\r
+ <Compile Include="FloatingButtonItem.cs" />\r
+ <Compile Include="FloatingButtonMovablePosition.cs" />\r
+ <Compile Include="IFloatingButton.cs" />\r
+ <Compile Include="FloatingButton.cs" />\r
+ <Compile Include="FloatingButtonPosition.cs" />\r
<Compile Include="GridView.cs" />\r
<Compile Include="GridViewEnums.cs" />\r
<Compile Include="GridViewEventArgs.cs" />\r