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.
- Loading branch information
Showing
7 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupImplementation.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,143 @@ | ||
/* | ||
* Copyright (c) 2020 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 Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Tizen; | ||
using XForms = Xamarin.Forms.Forms; | ||
|
||
[assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.ContentPopupImplementation))] | ||
|
||
namespace Tizen.Wearable.CircularUI.Forms.Renderer | ||
{ | ||
public class ContentPopupImplementation : IContentPopup, IDisposable | ||
{ | ||
View _content; | ||
ElmSharp.Popup _popUp; | ||
bool _isDisposed; | ||
|
||
public event EventHandler BackButtonPressed; | ||
|
||
public ContentPopupImplementation() | ||
{ | ||
_popUp = new ElmSharp.Popup(XForms.NativeParent); | ||
_popUp.Style = "circle"; | ||
|
||
_popUp.BackButtonPressed += BackButtonPressedHandler; | ||
_popUp.Dismissed += OnDismissed; | ||
} | ||
|
||
~ContentPopupImplementation() | ||
{ | ||
Dispose(false); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_isDisposed) | ||
return; | ||
|
||
if (disposing) | ||
{ | ||
if (Content != null) | ||
Content = null; | ||
|
||
if (_popUp != null) | ||
{ | ||
_popUp.BackButtonPressed -= BackButtonPressedHandler; | ||
_popUp.Dismissed -= OnDismissed; | ||
_popUp.Unrealize(); | ||
_popUp = null; | ||
} | ||
} | ||
|
||
_isDisposed = true; | ||
} | ||
|
||
public View Content | ||
{ | ||
get | ||
{ | ||
return _content; | ||
} | ||
set | ||
{ | ||
_content = value; | ||
UpdateContent(); | ||
} | ||
} | ||
|
||
void BackButtonPressedHandler(object sender, EventArgs e) | ||
{ | ||
BackButtonPressed?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
void UpdateContent() | ||
{ | ||
if (!XForms.IsInitialized) | ||
{ | ||
Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized"); | ||
return; | ||
} | ||
|
||
if (Content != null) | ||
{ | ||
var renderer = Platform.GetOrCreateRenderer(Content); | ||
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
var native = renderer.NativeView; | ||
var sizeRequest = Content.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel(); | ||
native.MinimumHeight = sizeRequest.Height; | ||
_popUp.SetContent(native, false); | ||
} | ||
else | ||
{ | ||
if (Content != null) | ||
Content = null; | ||
_popUp.SetContent(null, false); | ||
} | ||
} | ||
|
||
public void Show() | ||
{ | ||
if (!XForms.IsInitialized) | ||
{ | ||
throw new InvalidOperationException("When the Application's Platform is not initialized, it can not show the Dialog."); | ||
} | ||
|
||
if (_popUp != null) | ||
{ | ||
_popUp.Show(); | ||
} | ||
} | ||
|
||
public void Dismiss() | ||
{ | ||
_popUp.Hide(); | ||
_popUp.Dismiss(); | ||
} | ||
|
||
void OnDismissed(object sender, EventArgs e) | ||
{ | ||
Dispose(); | ||
} | ||
} | ||
} |
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,88 @@ | ||
/* | ||
* Copyright (c) 2020 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 Xamarin.Forms; | ||
|
||
namespace Tizen.Wearable.CircularUI.Forms | ||
{ | ||
/// <summary> | ||
/// The ContentPopup is a Popup, which allows you to customize the View to be displayed. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public class ContentPopup : BindableObject | ||
{ | ||
/// <summary> | ||
/// BindableProperty. Identifies the content bindable property. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPopup), null); | ||
|
||
IContentPopup _popUp; | ||
|
||
/// <summary> | ||
/// Occurs when the device's back button is pressed. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public event EventHandler BackButtonPressed; | ||
|
||
/// <summary> | ||
/// Creates and initializes a new instance of the ContentPopup class. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public ContentPopup() | ||
{ | ||
_popUp = DependencyService.Get<IContentPopup>(DependencyFetchTarget.NewInstance); | ||
if (_popUp == null) | ||
throw new InvalidOperationException("Object reference not set to an instance of a Popup."); | ||
|
||
_popUp.BackButtonPressed += (s, e) => | ||
{ | ||
BackButtonPressed?.Invoke(this, EventArgs.Empty); | ||
}; | ||
|
||
SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _popUp)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets content view of the Popup. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public View Content | ||
{ | ||
get { return (View)GetValue(ContentProperty); } | ||
set { SetValue(ContentProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// Shows the ContentPopup. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public void Show() | ||
{ | ||
_popUp.Show(); | ||
} | ||
|
||
/// <summary> | ||
/// Dismisses the ContentPopup. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public void Dismiss(object result = null) | ||
{ | ||
_popUp.Dismiss(); | ||
} | ||
} | ||
} |
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,52 @@ | ||
/* | ||
* Copyright (c) 2020 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 Xamarin.Forms; | ||
|
||
namespace Tizen.Wearable.CircularUI.Forms | ||
{ | ||
/// <summary> | ||
/// The IContentPopup is an interface to describe confirmation pop-up which has content area | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
internal interface IContentPopup | ||
{ | ||
/// <summary> | ||
/// Occurs when the Back button is pressed. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
event EventHandler BackButtonPressed; | ||
|
||
/// <summary> | ||
/// Gets or sets content view of the Popup. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
View Content { get; set; } | ||
|
||
/// <summary> | ||
/// Shows the Popup | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
void Show(); | ||
|
||
/// <summary> | ||
/// Dismisses the Popup | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
void Dismiss(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs
100755 → 100644
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
43 changes: 43 additions & 0 deletions
43
test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.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,43 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
x:Class="WearableUIGallery.TC.TCContentPopupTest" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:WearableUIGallery" | ||
xmlns:w="clr-namespace:Tizen.Wearable.CircularUI.Forms;assembly=Tizen.Wearable.CircularUI.Forms" | ||
w:CircleSurfaceEffectBehavior.RotaryFocusObject="{x:Reference myscroller}"> | ||
<ContentPage.Behaviors> | ||
<w:CircleSurfaceEffectBehavior/> | ||
</ContentPage.Behaviors> | ||
<ContentPage.Content> | ||
<w:CircleScrollView x:Name="myscroller" Orientation="Vertical"> | ||
<StackLayout Padding="0,50,0,50"> | ||
<Label | ||
x:Name="label1" | ||
HorizontalOptions="CenterAndExpand" | ||
Text="ContentPopup test" | ||
VerticalOptions="Start" /> | ||
<Button | ||
AutomationId="dismisstest1" | ||
x:Name="button1" | ||
Clicked="OnContentPopupDismissBackKeyClicked" | ||
FontSize="Small" | ||
HeightRequest="50" | ||
HorizontalOptions="Center" | ||
Text="Dismiss test 1" | ||
VerticalOptions="CenterAndExpand" | ||
WidthRequest="300" /> | ||
<Button | ||
AutomationId="dismisstest2" | ||
x:Name="button2" | ||
Clicked="OnContentPopupDismissButtonClicked" | ||
FontSize="Small" | ||
HeightRequest="50" | ||
HorizontalOptions="Center" | ||
Text="Dismiss test 2" | ||
VerticalOptions="CenterAndExpand" | ||
WidthRequest="300" /> | ||
</StackLayout> | ||
</w:CircleScrollView> | ||
</ContentPage.Content> | ||
</ContentPage> |
Oops, something went wrong.