This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new ContentButton * Change Renderer inheritance and fix typo * Restructure ContentButton and ContentButtonRenderer * Fix layout issue * Remove OnLayoutUpdate method * Fix typo
- Loading branch information
Showing
7 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentButtonRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved | ||
* | ||
* Licensed under the Flora License, Version 1.1 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://floralicense.org/license/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using Tizen.Wearable.CircularUI.Forms; | ||
using Tizen.Wearable.CircularUI.Forms.Renderer; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Tizen; | ||
using Xamarin.Forms.Platform.Tizen.Native; | ||
using XForms = Xamarin.Forms.Forms; | ||
using XFLayout = Xamarin.Forms.Layout; | ||
using EButton = ElmSharp.Button; | ||
using EColor = ElmSharp.Color; | ||
using System.ComponentModel; | ||
|
||
[assembly: ExportRenderer(typeof(ContentButton), typeof(ContentButtonRenderer))] | ||
|
||
namespace Tizen.Wearable.CircularUI.Forms.Renderer | ||
{ | ||
public class ContentButtonRenderer : LayoutRenderer | ||
{ | ||
EButton _button; | ||
|
||
ContentButton Button => Element as ContentButton; | ||
|
||
protected override void OnElementChanged(ElementChangedEventArgs<XFLayout> e) | ||
{ | ||
base.OnElementChanged(e); | ||
Initialize(); | ||
} | ||
|
||
void Initialize() | ||
{ | ||
if (_button == null) | ||
{ | ||
_button = new EButton(XForms.NativeParent); | ||
_button.BackgroundColor = EColor.Transparent; | ||
_button.SetPartColor("effect", EColor.Transparent); | ||
_button.SetPartColor("effect_pressed", EColor.Transparent); | ||
_button.Show(); | ||
|
||
_button.Pressed += OnPressed; | ||
_button.Released += OnReleased; | ||
_button.Clicked += OnClicked; | ||
|
||
Control.PackEnd(_button); | ||
} | ||
} | ||
|
||
protected override void UpdateLayout() | ||
{ | ||
base.UpdateLayout(); | ||
|
||
_button.Geometry = Control.Geometry; | ||
_button.RaiseTop(); | ||
} | ||
|
||
void OnPressed(object sender, EventArgs args) | ||
{ | ||
Button?.SendPressed(); | ||
} | ||
|
||
void OnReleased(object sender, EventArgs args) | ||
{ | ||
Button?.SendReleased(); | ||
} | ||
|
||
void OnClicked(object sender, EventArgs args) | ||
{ | ||
Button?.SendClicked(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved | ||
* | ||
* Licensed under the Flora License, Version 1.1 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://floralicense.org/license/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Windows.Input; | ||
using Xamarin.Forms; | ||
|
||
namespace Tizen.Wearable.CircularUI.Forms | ||
{ | ||
/// <summary> | ||
/// The ContentButton is a Button, which allows you to customize the View to be displayed. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public class ContentButton : ContentView, IButtonController | ||
{ | ||
/// <summary> | ||
/// BindableProperty. Identifies the Command bindable property. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ContentButton), null, | ||
propertyChanging: OnCommandChanging, propertyChanged: OnCommandChanged); | ||
|
||
/// <summary> | ||
/// BindableProperty. Identifies the CommandParameter bindable property. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(ContentButton), null, | ||
propertyChanged: (bindable, oldvalue, newvalue) => CommandCanExcuteChanged(bindable, EventArgs.Empty)); | ||
|
||
/// <summary> | ||
/// Gets or sets command that is executed when the button is clicked. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public ICommand Command | ||
{ | ||
get => (ICommand)GetValue(CommandProperty); | ||
set => SetValue(CommandProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets command paramter that is executed when the button is clicked. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public object CommandParameter | ||
{ | ||
get => GetValue(CommandParameterProperty); | ||
set => SetValue(CommandParameterProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when the button is clicked. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public event EventHandler Clicked; | ||
|
||
/// <summary> | ||
/// Occurs when the button is pressed. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public event EventHandler Pressed; | ||
|
||
/// <summary> | ||
/// Occurs when the button is released. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public event EventHandler Released; | ||
|
||
bool IsEnabledCore | ||
{ | ||
set => SetValueCore(IsEnabledProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// For internal use. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public void SendClicked() | ||
{ | ||
if (IsEnabled) | ||
{ | ||
Command?.Execute(CommandParameter); | ||
Clicked?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// For internal use. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public void SendPressed() | ||
{ | ||
if (IsEnabled) | ||
{ | ||
Pressed?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// For internal use. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public void SendReleased() | ||
{ | ||
if (IsEnabled) | ||
{ | ||
Released?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
|
||
protected override void OnBindingContextChanged() | ||
{ | ||
base.OnBindingContextChanged(); | ||
|
||
View content = Content; | ||
if (content != null) | ||
{ | ||
SetInheritedBindingContext(content, BindingContext); | ||
} | ||
} | ||
|
||
static void OnCommandChanged(BindableObject bindable, object oldCommand, object newCommand) | ||
{ | ||
ContentButton button = (ContentButton)bindable; | ||
if (newCommand is ICommand command) | ||
{ | ||
command.CanExecuteChanged += button.OnCommandCanExecuteChanged; | ||
} | ||
CommandChanged(button); | ||
} | ||
|
||
static void CommandChanged(ContentButton button) | ||
{ | ||
if(button.Command != null) | ||
{ | ||
CommandCanExcuteChanged(button, EventArgs.Empty); | ||
} | ||
else | ||
{ | ||
button.IsEnabledCore = true; | ||
} | ||
} | ||
|
||
static void OnCommandChanging(BindableObject bindable, object oldCommand, object newCommand) | ||
{ | ||
ContentButton button = (ContentButton)bindable; | ||
if (oldCommand != null) | ||
{ | ||
(oldCommand as ICommand).CanExecuteChanged -= button.OnCommandCanExecuteChanged; | ||
} | ||
} | ||
|
||
static void CommandCanExcuteChanged(object sender, EventArgs e) | ||
{ | ||
var button = (ContentButton)sender; | ||
if (button.Command != null) | ||
{ | ||
button.IsEnabledCore = button.Command.CanExecute(button.CommandParameter); | ||
} | ||
} | ||
|
||
void OnCommandCanExecuteChanged(object sender, EventArgs e) | ||
{ | ||
ContentButton button = (ContentButton)sender; | ||
if (button.Command != null) | ||
{ | ||
button.IsEnabledCore = button.Command.CanExecute(button.CommandParameter); | ||
} | ||
} | ||
} | ||
} |
Binary file added
BIN
+3.7 KB
test/WearableUIGallery/WearableUIGallery.Tizen.Wearable/res/button_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.29 KB
test/WearableUIGallery/WearableUIGallery.Tizen.Wearable/res/button_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions
29
test/WearableUIGallery/WearableUIGallery/TC/TCContentButton.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:w="clr-namespace:Tizen.Wearable.CircularUI.Forms;assembly=Tizen.Wearable.CircularUI.Forms" | ||
xmlns:tizen="clr-namespace:Xamarin.Forms.PlatformConfiguration.TizenSpecific;assembly=Xamarin.Forms.Core" | ||
x:Class="WearableUIGallery.TC.ContentButtonTestPage"> | ||
<ContentPage.Content> | ||
<StackLayout VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="CenterAndExpand"> | ||
<Label x:Name="label" | ||
HorizontalOptions="CenterAndExpand" | ||
HorizontalTextAlignment="Center" | ||
Text="Test"/> | ||
<w:ContentButton x:Name="button" | ||
Clicked="OnButtonClicked" | ||
Pressed="OnButtonPressed" | ||
Released="OnButtonReleased" | ||
Command="{Binding ClickCommand}"> | ||
<w:ContentButton.Content> | ||
<AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> | ||
<Image x:Name="buttonBg" Source="button_bg.png" Opacity="0.25" Aspect="AspectFill" tizen:Image.BlendColor="Transparent" AbsoluteLayout.LayoutBounds=".5,.5,89,66" AbsoluteLayout.LayoutFlags="PositionProportional" /> | ||
<Image x:Name="buttonBorder" Source="button_border.png" Aspect="AspectFill" tizen:Image.BlendColor="DarkGreen" AbsoluteLayout.LayoutBounds=".5,.5,89,66" AbsoluteLayout.LayoutFlags="PositionProportional" /> | ||
<Image x:Name="buttonIcon" Source="home.png" tizen:Image.BlendColor="DarkGreen" AbsoluteLayout.LayoutBounds=".5,.5,36,36" AbsoluteLayout.LayoutFlags="PositionProportional" /> | ||
</AbsoluteLayout> | ||
</w:ContentButton.Content> | ||
</w:ContentButton> | ||
</StackLayout> | ||
</ContentPage.Content> | ||
</ContentPage> |
38 changes: 38 additions & 0 deletions
38
test/WearableUIGallery/WearableUIGallery/TC/TCContentButton.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Windows.Input; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace WearableUIGallery.TC | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class ContentButtonTestPage : ContentPage | ||
{ | ||
public ContentButtonTestPage() | ||
{ | ||
InitializeComponent(); | ||
|
||
ClickCommand = new Command(execute: () => | ||
{ | ||
label.Text = "clicked"; | ||
}); | ||
} | ||
|
||
public ICommand ClickCommand { get; private set; } | ||
|
||
private void OnButtonClicked(object sender, EventArgs e) | ||
{ | ||
Console.WriteLine($"ContentButton clicked event is invoked!!"); | ||
} | ||
|
||
private void OnButtonPressed(object sender, EventArgs e) | ||
{ | ||
Xamarin.Forms.PlatformConfiguration.TizenSpecific.Image.SetBlendColor(buttonBg, Color.Gray); | ||
} | ||
|
||
private void OnButtonReleased(object sender, EventArgs e) | ||
{ | ||
Xamarin.Forms.PlatformConfiguration.TizenSpecific.Image.SetBlendColor(buttonBg, Color.Transparent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters