Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
}
#else
handlersCollection.AddHandler<TimePicker, TimePickerHandler>();
#endif
#if ANDROID
if (RuntimeFeature.IsMaterial3Enabled)
{
handlersCollection.AddHandler<ProgressBar, ProgressBarHandler2>();
}
else
{
handlersCollection.AddHandler<ProgressBar, ProgressBarHandler>();
}
#else
handlersCollection.AddHandler<ProgressBar, ProgressBarHandler>();
#endif
handlersCollection.AddHandler<Application, ApplicationHandler>();
handlersCollection.AddHandler<BoxView, BoxViewHandler>();
Expand All @@ -137,7 +149,6 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
handlersCollection.AddHandler<Entry, EntryHandler>();
handlersCollection.AddHandler<GraphicsView, GraphicsViewHandler>();
handlersCollection.AddHandler<Layout, LayoutHandler>();
handlersCollection.AddHandler<ProgressBar, ProgressBarHandler>();
handlersCollection.AddHandler<ScrollView, ScrollViewHandler>();
handlersCollection.AddHandler<SearchBar, SearchBarHandler>();
handlersCollection.AddHandler<Slider, SliderHandler>();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Material3 ProgressBar tests reuse the existing ProgressBar Feature Matrix HostApp page.
// The native Android view differs (LinearProgressIndicator vs ProgressBar), so these tests
// produce separate screenshot baselines under the Material3 category.
#if ANDROID
using System;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests;

public class Material3ProgressBarFeatureTests : _GalleryUITest
{
public override string GalleryPageName => "ProgressBar Feature Matrix";

public Material3ProgressBarFeatureTests(TestDevice device)
: base(device)
{
}

[Test, Order(1)]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_ProgressToMethod_VerifyVisualState()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("ProgressToEntry");
App.ClearText("ProgressToEntry");
App.EnterText("ProgressToEntry", "0.90");
App.PressEnter();
App.WaitForElement("ProgressToButton");
App.Tap("ProgressToButton");
Task.Delay(1000).Wait();
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}

[Test]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_SetProgressOutOfRange()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("ProgressEntry");
App.ClearText("ProgressEntry");
App.EnterText("ProgressEntry", "1.44");
App.PressEnter();
App.WaitForElement("ProgressBarControl");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}

[Test]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_SetProgressNegativeValue()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("ProgressEntry");
App.ClearText("ProgressEntry");
App.EnterText("ProgressEntry", "-0.44");
App.PressEnter();
App.WaitForElement("ProgressBarControl");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}

[Test]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_SetProgressColorAndBackgroundColor_VerifyVisualState()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("ProgressEntry");
App.ClearText("ProgressEntry");
App.EnterText("ProgressEntry", "0.60");
App.PressEnter();
App.WaitForElement("ProgressColorRedButton");
App.Tap("ProgressColorRedButton");
App.WaitForElement("BackgroundColorLightBlueButton");
App.Tap("BackgroundColorLightBlueButton");
App.WaitForElement("ProgressBarControl");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}

[Test]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_ChangeFlowDirection_RTL_VerifyLabel()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("FlowDirectionRTL");
App.Tap("FlowDirectionRTL");
App.WaitForElement("ProgressBarControl");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}

[Test]
[Category(UITestCategories.Material3)]
public void Material3ProgressBar_ToggleShadow_VerifyVisualState()
{
App.WaitForElement("ResetButton");
App.Tap("ResetButton");
App.WaitForElement("ShadowTrueRadio");
App.Tap("ShadowTrueRadio");
App.WaitForElement("ProgressBarControl");
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}
}
#endif
16 changes: 16 additions & 0 deletions src/Core/src/Handlers/ProgressBar/ProgressBarHandler2.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Google.Android.Material.ProgressIndicator;

namespace Microsoft.Maui.Handlers;

// TODO: Material3 - make it public in .net 11
internal class ProgressBarHandler2 : ProgressBarHandler
{
protected override LinearProgressIndicator CreatePlatformView()
{
return new LinearProgressIndicator(MauiMaterialContextThemeWrapper.Create(Context))
{
Indeterminate = false,
Max = ProgressBarExtensions.Maximum
};
}
}
34 changes: 34 additions & 0 deletions src/Core/src/Platform/Android/ProgressBarExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Android.Content.Res;
using Google.Android.Material.ProgressIndicator;
using Microsoft.Maui.Graphics;
using AProgressBar = Android.Widget.ProgressBar;

Expand All @@ -14,6 +15,18 @@ public static void UpdateProgress(this AProgressBar platformProgressBar, IProgre
}

public static void UpdateProgressColor(this AProgressBar platformProgressBar, IProgress progress)
{
if (platformProgressBar is LinearProgressIndicator materialProgressBar)
{
materialProgressBar.UpdateLinearProgressIndicatorColor(progress);
}
else
{
platformProgressBar.UpdateProgressBarColor(progress);
}
}

static void UpdateProgressBarColor(this AProgressBar platformProgressBar, IProgress progress)
{
Color color = progress.ProgressColor;

Expand All @@ -27,9 +40,30 @@ public static void UpdateProgressColor(this AProgressBar platformProgressBar, IP
var tintList = ColorStateList.ValueOf(color.ToPlatform());

if (platformProgressBar.Indeterminate)
{
platformProgressBar.IndeterminateTintList = tintList;
}
else
{
platformProgressBar.ProgressTintList = tintList;
}
}
}

static void UpdateLinearProgressIndicatorColor(this LinearProgressIndicator materialProgressBar, IProgress progress)
{
Color color = progress.ProgressColor;

if (color is null)
{
// Reset to theme default by passing empty array - Material3's setIndicatorColor()
// automatically resolves this to theme's colorPrimary when length == 0
materialProgressBar.SetIndicatorColor([]);
}
else
{
var colorArray = new int[] { color.ToPlatform() };
materialProgressBar.SetIndicatorColor(colorArray);
}
}
}
Expand Down
Loading