Skip to content

Commit e2cfffd

Browse files
authored
Merge branch 'main' into MultiWindowSnackbarFix
2 parents f61e837 + ffec96a commit e2cfffd

File tree

65 files changed

+1815
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1815
-1097
lines changed

samples/CommunityToolkit.Maui.Sample.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Camer
5151
EndProject
5252
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{ED5A9C0B-D270-442D-BABE-F4FF622926C8}"
5353
EndProject
54-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "..\src\CommunityToolkit.Maui.Analyzers.Benchmarks\CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}"
54+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Analyzers.Benchmarks", "..\src\CommunityToolkit.Maui.Analyzers.Benchmarks\CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}"
5555
EndProject
5656
Global
5757
GlobalSection(SolutionConfigurationPlatforms) = preSolution

samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public partial class AppShell : Shell
9393
CreateViewModelMapping<FileSaverPage, FileSaverViewModel, EssentialsGalleryPage, EssentialsGalleryViewModel>(),
9494
CreateViewModelMapping<FolderPickerPage, FolderPickerViewModel, EssentialsGalleryPage, EssentialsGalleryViewModel>(),
9595
CreateViewModelMapping<SpeechToTextPage, SpeechToTextViewModel, EssentialsGalleryPage, EssentialsGalleryViewModel>(),
96+
CreateViewModelMapping<OfflineSpeechToTextPage, OfflineSpeechToTextViewModel, EssentialsGalleryPage, EssentialsGalleryViewModel>(),
9697

9798
// Add Extensions View Models
9899
CreateViewModelMapping<ColorAnimationExtensionsPage, ColorAnimationExtensionsViewModel, ExtensionsGalleryPage, ExtensionsGalleryViewModel>(),

samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<MauiFont Include="Resources\Fonts\*" />
6666

6767
<PackageReference Include="Microsoft.Maui.Controls" Version="*" />
68-
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="*" />
6968
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="5.1.0" />
7069
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
7170
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />

samples/CommunityToolkit.Maui.Sample/MauiProgram.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static void RegisterViewsAndViewModels(in IServiceCollection services)
228228
services.AddTransientWithShellRoute<FileSaverPage, FileSaverViewModel>();
229229
services.AddTransientWithShellRoute<FolderPickerPage, FolderPickerViewModel>();
230230
services.AddTransientWithShellRoute<SpeechToTextPage, SpeechToTextViewModel>();
231+
services.AddTransientWithShellRoute<OfflineSpeechToTextPage, OfflineSpeechToTextViewModel>();
231232

232233
// Add Extensions Pages + ViewModels
233234
services.AddTransientWithShellRoute<ColorAnimationExtensionsPage, ColorAnimationExtensionsViewModel>();
@@ -279,7 +280,8 @@ static void RegisterEssentials(in IServiceCollection services)
279280
services.AddSingleton<IFileSystem>(FileSystem.Current);
280281
services.AddSingleton<IFolderPicker>(FolderPicker.Default);
281282
services.AddSingleton<IBadge>(Badge.Default);
282-
services.AddSingleton<ISpeechToText>(SpeechToText.Default);
283+
services.AddKeyedSingleton<ISpeechToText, SpeechToTextImplementation>("Online");
284+
services.AddKeyedSingleton<ISpeechToText, OfflineSpeechToTextImplementation>("Offline");
283285
services.AddSingleton<ITextToSpeech>(TextToSpeech.Default);
284286
}
285287

samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
</RadioButton>
154154

155155
</HorizontalStackLayout>
156+
157+
<Button
158+
x:Name="ModalPageButton"
159+
HorizontalOptions="Center"
160+
VerticalOptions="Center"/>
156161
</VerticalStackLayout>
157162
</ScrollView>
158163
</pages:BasePage>

samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using CommunityToolkit.Maui.Sample.ViewModels.Behaviors;
23

34
namespace CommunityToolkit.Maui.Sample.Pages.Behaviors;
45

56
public partial class StatusBarBehaviorPage : BasePage<StatusBarBehaviorViewModel>
67
{
8+
const string tryStatusBarOnModalPageButtonText = "Try StatusBarBehavior on Modal Page";
9+
710
public StatusBarBehaviorPage(StatusBarBehaviorViewModel viewModel)
811
: base(viewModel)
912
{
1013
InitializeComponent();
14+
15+
ModalPageButton.Text = tryStatusBarOnModalPageButtonText;
16+
ModalPageButton.Clicked += HandleModalButtonClicked;
1117
}
1218

1319
protected override void OnNavigatedTo(NavigatedToEventArgs args)
@@ -17,4 +23,49 @@ protected override void OnNavigatedTo(NavigatedToEventArgs args)
1723
var statusBarColor = Color.FromRgba(BindingContext.RedSliderValue, BindingContext.GreenSliderValue, BindingContext.BlueSliderValue, 1.0);
1824
Core.Platform.StatusBar.SetColor(statusBarColor);
1925
}
26+
27+
static async void HandleModalButtonClicked(object? sender, EventArgs e)
28+
{
29+
var statusBarBehaviorModelPage = new StatusBarBehaviorPage(new StatusBarBehaviorViewModel());
30+
31+
// Get Modal Page Button
32+
if (!TryGetModalPageButton((Microsoft.Maui.ILayout)((ScrollView)statusBarBehaviorModelPage.Content).Content, out var modalPageButton))
33+
{
34+
throw new InvalidOperationException("Unable To Find Modal Page Button");
35+
}
36+
37+
// Change Text on Modal Page Button
38+
modalPageButton.Text = "Pop Modal Page";
39+
40+
// Modify Behavior of Modal Page Button
41+
modalPageButton.Clicked -= HandleModalButtonClicked;
42+
modalPageButton.Clicked += async (_, _) => await Shell.Current.Navigation.PopModalAsync();
43+
44+
await Shell.Current.Navigation.PushModalAsync(statusBarBehaviorModelPage);
45+
}
46+
47+
static bool TryGetModalPageButton(Microsoft.Maui.ILayout layout, [NotNullWhen(true)] out Button? button)
48+
{
49+
button = null;
50+
51+
foreach (var view in layout)
52+
{
53+
switch (view)
54+
{
55+
case Button { Text: tryStatusBarOnModalPageButtonText } modalPageButton:
56+
button = modalPageButton;
57+
return true;
58+
59+
case Microsoft.Maui.ILayout nestedLayout:
60+
if (TryGetModalPageButton(nestedLayout, out var modalPageButtonInLayout))
61+
{
62+
button = modalPageButtonInLayout;
63+
return true;
64+
}
65+
break;
66+
}
67+
}
68+
69+
return false;
70+
}
2071
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<pages:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
5+
x:Class="CommunityToolkit.Maui.Sample.Pages.Essentials.OfflineSpeechToTextPage"
6+
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Essentials"
7+
xmlns:essentials="clr-namespace:CommunityToolkit.Maui.Sample.Pages.Essentials"
8+
x:TypeArguments="vm:OfflineSpeechToTextViewModel"
9+
x:DataType="vm:OfflineSpeechToTextViewModel"
10+
Title="OfflineSpeechToText">
11+
12+
<ScrollView>
13+
<VerticalStackLayout
14+
Spacing="20"
15+
Padding="30,0">
16+
17+
<Label
18+
Text="OfflineSpeechToText allows the user to convert speech to text in real time in offline."
19+
HorizontalTextAlignment="Center"/>
20+
21+
<Label
22+
Text="State"
23+
FontAttributes="Bold"/>
24+
25+
<Label
26+
Text="{Binding State}"
27+
FontSize="18"
28+
HorizontalOptions="Center"
29+
HorizontalTextAlignment="Center"
30+
MinimumHeightRequest="100" />
31+
32+
<Label
33+
Text="Language Output"
34+
FontAttributes="Bold"/>
35+
36+
<Label
37+
Text="{Binding RecognitionText}"
38+
FontSize="18"
39+
HorizontalOptions="Center"
40+
HorizontalTextAlignment="Center"
41+
MinimumHeightRequest="100" />
42+
43+
<Border
44+
StrokeThickness="2"
45+
Stroke="#808080"
46+
StrokeShape="RoundRectangle 8,8,8,8"
47+
Padding="12">
48+
<Border.Content>
49+
<Grid RowDefinitions="*,60"
50+
ColumnDefinitions="*,*"
51+
RowSpacing="12"
52+
ColumnSpacing="12">
53+
54+
<Button
55+
Grid.Row="0"
56+
Grid.Column="0"
57+
Text="StartListenAsync"
58+
Command="{Binding StartListenCommand}"
59+
HorizontalOptions="End" />
60+
61+
<Button
62+
Grid.Row="0"
63+
Grid.Column="1"
64+
Text="StopListenAsync"
65+
Command="{Binding StopListenCommand}"
66+
HorizontalOptions="Start" />
67+
68+
<Label
69+
Grid.Row="1"
70+
Grid.ColumnSpan="2"
71+
Text="The `StartListenAsync` API starts the speech-to-text service and shares the results using `RecognitionResultUpdated` event and `RecognitionResultCompleted` event."
72+
HorizontalOptions="Center"
73+
HorizontalTextAlignment="Center"
74+
FontSize="12"/>
75+
76+
</Grid>
77+
</Border.Content>
78+
</Border>
79+
</VerticalStackLayout>
80+
</ScrollView>
81+
82+
</pages:BasePage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using CommunityToolkit.Maui.Sample.ViewModels.Essentials;
2+
3+
namespace CommunityToolkit.Maui.Sample.Pages.Essentials;
4+
5+
public partial class OfflineSpeechToTextPage : BasePage<OfflineSpeechToTextViewModel>
6+
{
7+
public OfflineSpeechToTextPage(OfflineSpeechToTextViewModel viewModel) : base(viewModel)
8+
{
9+
InitializeComponent();
10+
}
11+
}

samples/CommunityToolkit.Maui.Sample/Pages/Essentials/SpeechToTextPage.xaml

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
SelectedItem="{Binding CurrentLocale}"
3232
ItemDisplayBinding="{Binding ., Converter={StaticResource PickerLocaleDisplayConverter}}"/>
3333

34+
<Label
35+
Text="State"
36+
FontAttributes="Bold"/>
37+
38+
<Label
39+
Text="{Binding State}"
40+
FontSize="18"
41+
HorizontalOptions="Center"
42+
HorizontalTextAlignment="Center"
43+
MinimumHeightRequest="100" />
44+
3445
<Label
3546
Text="Language Output"
3647
FontAttributes="Bold"/>
@@ -47,44 +58,6 @@
4758
Command="{Binding PlayCommand}"
4859
HorizontalOptions="Center" />
4960

50-
<Border
51-
StrokeThickness="2"
52-
Stroke="#808080"
53-
StrokeShape="RoundRectangle 8,8,8,8"
54-
Padding="12">
55-
<Border.Content>
56-
57-
<Grid RowDefinitions="*,60"
58-
ColumnDefinitions="*,*"
59-
RowSpacing="12"
60-
ColumnSpacing="12">
61-
62-
<Button
63-
Grid.Row="0"
64-
Grid.Column="0"
65-
Text="ListenAsync"
66-
Command="{Binding ListenCommand}"
67-
HorizontalOptions="End" />
68-
69-
<Button
70-
Grid.Row="0"
71-
Grid.Column="1"
72-
Text="Cancel Token"
73-
Command="{Binding ListenCancelCommand}"
74-
HorizontalOptions="Start" />
75-
76-
<Label
77-
Grid.Row="1"
78-
Grid.ColumnSpan="2"
79-
Text="The `ListenAsync` API allows you to await the final speech recognition results using async/await. `ListenAsync` is cancelled via CancellationToken."
80-
HorizontalOptions="Center"
81-
HorizontalTextAlignment="Center"
82-
FontSize="12"/>
83-
84-
</Grid>
85-
</Border.Content>
86-
</Border>
87-
8861
<Border
8962
StrokeThickness="2"
9063
Stroke="#808080"

samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
<service android:name="communityToolkit.maui.media.services" android:stopWithTask="true" android:exported="false" android:enabled="true"
99
android:foregroundServiceType="mediaPlayback">
10-
<intent-filter>
11-
<action android:name="android.intent.action.MEDIA_BUTTON"/>
12-
</intent-filter>
1310
<intent-filter>
1411
<action android:name="androidx.media3.session.MediaSessionService"/>
1512
</intent-filter>

0 commit comments

Comments
 (0)