Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Allow to update Entry Background (once established) #12227

Merged
merged 44 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8c8cc24
Added sample
jsuarezruiz Dec 20, 2022
0886fd9
Fix the issue
jsuarezruiz Dec 20, 2022
ee47281
Added device test
jsuarezruiz Dec 20, 2022
eef5211
Merge branch 'main' into fix-12212
jsuarezruiz Jan 10, 2023
205bfbc
Applied the same change in more controls
jsuarezruiz Jan 10, 2023
7a32756
Merge branch 'main' into fix-12212
jsuarezruiz Jan 18, 2023
28b0b4d
Merge branch 'main' into fix-12212
jsuarezruiz Jan 27, 2023
adc670d
Added more samples (12991)
jsuarezruiz Jan 30, 2023
6309b71
Update src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs
jsuarezruiz Feb 8, 2023
d6c71f4
Merge branch 'main' into fix-12212
jsuarezruiz Feb 8, 2023
58c21fc
Merge branch 'main' into fix-12212
jsuarezruiz Feb 16, 2023
838845d
Auto-format source code
Feb 16, 2023
0b6e6a0
Fix merge issue
jsuarezruiz Feb 16, 2023
cfb19b2
Merge branch 'fix-12212' of https://github.com/dotnet/maui into fix-1…
jsuarezruiz Feb 16, 2023
35ce9dd
Fixd merge issue
jsuarezruiz Feb 16, 2023
83dc6ac
Auto-format source code
Feb 16, 2023
23ae8cf
Changes based on PR feedback
jsuarezruiz Feb 16, 2023
0ded61e
Merge branch 'main' into fix-12212
jsuarezruiz Feb 20, 2023
061ff08
Merge branch 'main' into fix-12212
jsuarezruiz Feb 23, 2023
9f8e477
Merge branch 'main' into fix-12212
jsuarezruiz Mar 2, 2023
28d2e56
Remove unnecessary changes
jsuarezruiz Mar 2, 2023
b019f60
Merge branch 'main' into fix-12212
jsuarezruiz Mar 3, 2023
82322c0
Merge branch 'main' into fix-12212
jsuarezruiz Mar 9, 2023
13c2118
Added platformView and Context null check
jsuarezruiz Mar 9, 2023
722572f
Small change
jsuarezruiz Mar 9, 2023
5583fa5
Merge branch 'main' into fix-12212
jsuarezruiz Mar 13, 2023
bfa255d
Added attribute
jsuarezruiz Mar 13, 2023
f5ecb87
More changes
jsuarezruiz Mar 15, 2023
4b242b1
Apply more changes
jsuarezruiz Mar 15, 2023
c60eaea
Changes based on PR feedback
jsuarezruiz Mar 16, 2023
ec89869
Auto-format source code
Mar 16, 2023
4705950
Merge branch 'main' into fix-12212
jsuarezruiz Mar 16, 2023
e758377
Merge branch 'fix-12212' of https://github.com/dotnet/maui into fix-1…
jsuarezruiz Mar 20, 2023
32a65d3
Merge branch 'main' into fix-12212
jsuarezruiz Mar 22, 2023
c6f9fb2
Merge branch 'main' into fix-12212
jsuarezruiz Mar 23, 2023
ee58508
Merge branch 'main' into fix-12212
jsuarezruiz Mar 24, 2023
0df5f32
Merge branch 'main' into fix-12212
jsuarezruiz Mar 24, 2023
a14efc2
Merge branch 'main' into fix-12212
jsuarezruiz Mar 28, 2023
94e1ed6
Merge branch 'main' into fix-12212
jsuarezruiz Mar 29, 2023
0c47d0e
Merge branch 'main' into fix-12212
jsuarezruiz Apr 3, 2023
53a55a5
Merge branch 'main' into fix-12212
jsuarezruiz Apr 12, 2023
4359d87
Refactoring code
jsuarezruiz Apr 12, 2023
9aa987f
Merge branch 'main' into fix-12212
jsuarezruiz Apr 13, 2023
01b328e
Small refactoring
jsuarezruiz Apr 14, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
</LinearGradientBrush>
</DatePicker.Background>
</DatePicker>
<Label
Text="Background"
Style="{StaticResource Headline}" />
<DatePicker
x:Name="BackgroundDatePicker"/>
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="ClearBackgroundButton"
Text="Clear Background"
Clicked="OnClearBackgroundButtonClicked"/>
<Label
Text="Default with date"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
Expand All @@ -7,6 +10,35 @@ public partial class DatePickerPage
public DatePickerPage()
{
InitializeComponent();

UpdateDatePickerBackground();
}

void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
{
UpdateDatePickerBackground();
}

void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
{
BackgroundDatePicker.Background = null;
}

void UpdateDatePickerBackground()
{
Random rnd = new Random();
Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);

BackgroundDatePicker.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}

void OnFocusDatePickerFocused(object sender, Microsoft.Maui.Controls.FocusEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@
</LinearGradientBrush>
</Editor.Background>
</Editor>
<Label
Text="Background"
Style="{StaticResource Headline}" />
<Editor
x:Name="BackgroundEditor"/>
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="ClearBackgroundButton"
Text="Clear Background"
Clicked="OnClearBackgroundButtonClicked"/>
<Label
Text="Keyboard Numeric"
Style="{StaticResource Headline}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
Expand All @@ -8,6 +9,8 @@ public partial class EditorPage
public EditorPage()
{
InitializeComponent();

UpdateEditorBackground();
}

void OnEditorCompleted(object sender, EventArgs e)
Expand All @@ -27,5 +30,32 @@ void OnEditorUnfocused(object sender, FocusEventArgs e)
var text = ((Editor)sender).Text;
DisplayAlert("Unfocused", text, "Ok");
}

void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
{
UpdateEditorBackground();
}

void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
{
BackgroundEditor.Background = null;
}

void UpdateEditorBackground()
{
Random rnd = new Random();
Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);

BackgroundEditor.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
xmlns:viewmodels="clr-namespace:Maui.Controls.Sample.ViewModels"
Title="Entry">
<views:BasePage.Resources>
<ResourceDictionary>

<Style x:Key="EntryVisualStatesStyle" TargetType="Entry">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Pink"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Yellow"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Red" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>

</ResourceDictionary>
</views:BasePage.Resources>
<views:BasePage.BindingContext>
<viewmodels:EntryViewModel />
</views:BasePage.BindingContext>
Expand Down Expand Up @@ -121,6 +150,24 @@
</LinearGradientBrush>
</Entry.Background>
</Entry>
<Label
Text="Background"
Style="{StaticResource Headline}" />
<Entry
x:Name="BackgroundEntry"/>
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="ClearBackgroundButton"
Text="Clear Background"
Clicked="OnClearBackgroundButtonClicked"/>
<Label
Text="Updating Background using VisualStates"
Style="{StaticResource Headline}" />
<Entry
Style="{StaticResource EntryVisualStatesStyle}" />
<Label
Text="Keyboard Numeric"
Style="{StaticResource Headline}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Microsoft.Maui.Graphics;
using Entry = Microsoft.Maui.Controls.Entry;

namespace Maui.Controls.Sample.Pages
Expand All @@ -19,9 +20,10 @@ public EntryPage()
sldCursorPosition.Maximum = entryCursor.Text.Length;
sldCursorPosition.Value = entryCursor.CursorPosition;


jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
PlatformSpecificEntry.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>()
.SetImeOptions(ImeFlags.Search);

UpdateEntryBackground();
}

void OnSlideCursorPositionValueChanged(object sender, ValueChangedEventArgs e)
Expand Down Expand Up @@ -67,5 +69,32 @@ void OnEntryUnfocused(object sender, FocusEventArgs e)
var text = ((Entry)sender).Text;
DisplayAlert("Unfocused", text, "Ok");
}

void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
{
UpdateEntryBackground();
}

void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
{
BackgroundEntry.Background = null;
}

void UpdateEntryBackground()
{
Random rnd = new Random();
Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);

BackgroundEntry.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public PickerPage()

BindingContext = this;

UpdatePickerBackground();

Loaded += (s, e) =>
{
DynamicItemsPicker.Items.Add("Item 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
</LinearGradientBrush>
</DatePicker.Background>
</TimePicker>
<Label
Text="Background"
Style="{StaticResource Headline}" />
<TimePicker
x:Name="BackgroundTimePicker"/>
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="ClearBackgroundButton"
Text="Clear Background"
Clicked="OnClearBackgroundButtonClicked"/>
<Label
Text="Default with time"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
namespace Maui.Controls.Sample.Pages
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
public partial class TimePickerPage
{
public TimePickerPage()
{
InitializeComponent();

UpdateTimePickerBackground();
}

void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
{
UpdateTimePickerBackground();
}

void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
{
BackgroundTimePicker.Background = null;
}

void UpdateTimePickerBackground()
{
Random rnd = new Random();
Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);

BackgroundTimePicker.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Graphics/PaintExtensions.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Graphics
{
public static partial class PaintExtensions
{
public static Drawable? ToDrawable(this Paint paint, Context? context)
public static Drawable? ToDrawable(this Paint? paint, Context? context)
{
if (paint is SolidPaint solidPaint)
return solidPaint.CreateDrawable(context);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Graphics/PaintExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Maui.Graphics
Expand Down
6 changes: 1 addition & 5 deletions src/Core/src/Handlers/Entry/EntryHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using Android.Content.Res;
using Android.Graphics.Drawables;
using Android.Runtime;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.AppCompat.Widget;
using AndroidX.Core.Content;
using Microsoft.Maui.Platform;
using static Android.Views.View;
using static Android.Widget.TextView;

Expand Down Expand Up @@ -56,6 +51,7 @@ protected override void ConnectHandler(AppCompatEditText platformView)
protected override void DisconnectHandler(AppCompatEditText platformView)
{
_clearButtonDrawable = null;

platformView.TextChanged -= OnTextChanged;
platformView.FocusChange -= OnFocusedChange;
platformView.Touch -= OnTouch;
Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/Platform/Android/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading