Skip to content

Commit fdecc85

Browse files
author
Vignesh Ramesh
authored
Merge pull request #1 from Shalini-Ashokan/master
How to design a circular timer using the .NET MAUI Radial Gauge (SfRadialGauge)
2 parents d8c6fe2 + 242b941 commit fdecc85

36 files changed

+1124
-0
lines changed

CircularTimer/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:CircularTimer"
5+
x:Class="CircularTimer.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

CircularTimer/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CircularTimer;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}

CircularTimer/AppShell.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="CircularTimer.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:CircularTimer"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>

CircularTimer/AppShell.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CircularTimer;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}

CircularTimer/CircularTimer.csproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>CircularTimer</RootNamespace>
10+
<UseMaui>true</UseMaui>
11+
<SingleProject>true</SingleProject>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!-- Display name -->
15+
<ApplicationTitle>CircularTimer</ApplicationTitle>
16+
17+
<!-- App Identifier -->
18+
<ApplicationId>com.companyname.circulartiimer</ApplicationId>
19+
<ApplicationIdGuid>E2F0A828-FBB6-46F9-B8FE-6D7446C454FB</ApplicationIdGuid>
20+
21+
<!-- Versions -->
22+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
23+
<ApplicationVersion>1</ApplicationVersion>
24+
25+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
26+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
27+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
28+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
29+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
30+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
31+
</PropertyGroup>
32+
33+
<ItemGroup>
34+
<!-- App Icon -->
35+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
36+
37+
<!-- Splash Screen -->
38+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
39+
40+
<!-- Images -->
41+
<MauiImage Include="Resources\Images\*" />
42+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
43+
44+
<!-- Custom Fonts -->
45+
<MauiFont Include="Resources\Fonts\*" />
46+
47+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
48+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<None Remove="Resources\Fonts\Sync FontIcons.ttf" />
53+
</ItemGroup>
54+
55+
<ItemGroup>
56+
<PackageReference Include="Syncfusion.Maui.Gauges" Version="*" />
57+
</ItemGroup>
58+
59+
</Project>

CircularTimer/CircularTimer.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CircularTimer", "CircularTimer.csproj", "{039385B8-59DA-4314-9509-AFF552924B6F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
Release-Xml|Any CPU = Release-Xml|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{039385B8-59DA-4314-9509-AFF552924B6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{039385B8-59DA-4314-9509-AFF552924B6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{039385B8-59DA-4314-9509-AFF552924B6F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
18+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release|Any CPU.Deploy.0 = Release|Any CPU
21+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
22+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release-Xml|Any CPU.Build.0 = Release|Any CPU
23+
{039385B8-59DA-4314-9509-AFF552924B6F}.Release-Xml|Any CPU.Deploy.0 = Release|Any CPU
24+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Release-Xml|Any CPU.ActiveCfg = Release-Xml|Any CPU
29+
{CBDA6F07-84FC-4B4E-8802-297E1CC89706}.Release-Xml|Any CPU.Build.0 = Release-Xml|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
36+
EndGlobalSection
37+
EndGlobal

CircularTimer/MainPage.xaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:gauge="clr-namespace:Syncfusion.Maui.Gauges;assembly=Syncfusion.Maui.Gauges"
5+
x:Class="CircularTimer.MainPage">
6+
7+
<gauge:SfRadialGauge x:Name="timerGauge">
8+
<gauge:SfRadialGauge.Axes>
9+
<gauge:RadialAxis StartAngle="270"
10+
EndAngle="270"
11+
Maximum="60"
12+
ShowLabels="False"
13+
ShowTicks="False">
14+
<gauge:RadialAxis.Pointers>
15+
<gauge:RangePointer x:Name="range"
16+
Value="{Binding Source={x:Reference pointer},Path=Value}"
17+
EnableAnimation="True"
18+
Fill="Blue" />
19+
<gauge:ShapePointer x:Name="pointer"
20+
Value="60"
21+
EnableAnimation="True"
22+
ShapeHeight="30"
23+
ShapeWidth="30"
24+
Stroke="Blue"
25+
BorderWidth="3"
26+
ShapeType="Circle"
27+
Fill="White" />
28+
</gauge:RadialAxis.Pointers>
29+
<gauge:RadialAxis.Annotations>
30+
<gauge:GaugeAnnotation PositionFactor="0.4"
31+
DirectionValue="30"
32+
DirectionUnit="AxisValue">
33+
<gauge:GaugeAnnotation.Content>
34+
<StackLayout>
35+
<Button x:Name="play"
36+
Clicked="play_pause_Clicked"
37+
Text="&#xe737;"
38+
IsVisible="True"
39+
FontSize="Large"
40+
FontFamily="Sync FontIcons"
41+
TextColor="Blue"
42+
HeightRequest="40"
43+
WidthRequest="50"
44+
HorizontalOptions="Center"
45+
VerticalOptions="Center"
46+
BackgroundColor="Transparent"
47+
BorderWidth="0" />
48+
<Button x:Name="pause"
49+
Clicked="play_pause_Clicked"
50+
Text="&#xe769;"
51+
IsVisible="False"
52+
FontSize="Medium"
53+
FontFamily="Sync FontIcons"
54+
TextColor="Blue"
55+
HeightRequest="40"
56+
WidthRequest="50"
57+
HorizontalOptions="Center"
58+
VerticalOptions="Center"
59+
BackgroundColor="Transparent"
60+
BorderWidth="0" />
61+
</StackLayout>
62+
</gauge:GaugeAnnotation.Content>
63+
</gauge:GaugeAnnotation>
64+
<gauge:GaugeAnnotation PositionFactor="0.1"
65+
DirectionValue="0"
66+
DirectionUnit="AxisValue">
67+
<gauge:GaugeAnnotation.Content>
68+
<Label x:Name="timer"
69+
Text="01:00"
70+
FontSize="80"
71+
TextColor="Blue" />
72+
</gauge:GaugeAnnotation.Content>
73+
</gauge:GaugeAnnotation>
74+
</gauge:RadialAxis.Annotations>
75+
</gauge:RadialAxis>
76+
</gauge:SfRadialGauge.Axes>
77+
</gauge:SfRadialGauge>
78+
</ContentPage>

CircularTimer/MainPage.xaml.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace CircularTimer;
2+
3+
public partial class MainPage : ContentPage
4+
{
5+
bool isCircularTimerOn = false;
6+
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
private void play_pause_Clicked(object sender, EventArgs e)
13+
{
14+
isCircularTimerOn = !isCircularTimerOn;
15+
if (isCircularTimerOn)
16+
{
17+
play.IsVisible = false;
18+
pause.IsVisible = true;
19+
}
20+
21+
Dispatcher.StartTimer(TimeSpan.FromSeconds(1), () =>
22+
{
23+
if (!isCircularTimerOn)
24+
{
25+
play.IsVisible = true;
26+
pause.IsVisible = false;
27+
return false;
28+
}
29+
30+
Dispatcher.DispatchAsync(() =>
31+
{
32+
pointer.Value -= 1;
33+
if (pointer.Value == -1)
34+
{
35+
isCircularTimerOn = false;
36+
pointer.Value = 60;
37+
timer.Text = "01:00";
38+
}
39+
else
40+
{
41+
timer.Text = pointer.Value.ToString("00:00");
42+
}
43+
});
44+
45+
return true;
46+
});
47+
}
48+
}

CircularTimer/MauiProgram.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.Maui.Core.Hosting;
2+
3+
namespace CircularTimer;
4+
5+
public static class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder
11+
.UseMauiApp<App>()
12+
.ConfigureSyncfusionCore()
13+
.ConfigureFonts(fonts =>
14+
{
15+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
16+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
17+
fonts.AddFont("Sync FontIcons.ttf", "Sync FontIcons");
18+
});
19+
20+
return builder.Build();
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

0 commit comments

Comments
 (0)