This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android Material] Linear Progress Indicator #5079
Merged
mattleibow
merged 1 commit into
xamarin:mattleibow/material-slider
from
paymicro:fix-gh5008
Feb 7, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
102 changes: 102 additions & 0 deletions
102
Xamarin.Forms.Controls/GalleryPages/MaterialProgressBarGallery.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,102 @@ | ||
namespace Xamarin.Forms.Controls | ||
{ | ||
public class MaterialProgressBarGallery : ContentPage | ||
{ | ||
public MaterialProgressBarGallery() | ||
{ | ||
Visual = VisualMarker.Material; | ||
|
||
var progressBar = new ProgressBar(); | ||
|
||
Slider[] ColorSlider = | ||
{ | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5) | ||
}; | ||
Slider[] BackColorSlider = | ||
{ | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5), | ||
new Slider(0, 1, 0.5) | ||
}; | ||
|
||
var actions = new Grid() | ||
{ | ||
ColumnDefinitions = | ||
{ | ||
new ColumnDefinition { Width = 10 }, | ||
new ColumnDefinition { Width = GridLength.Star }, | ||
new ColumnDefinition { Width = 30 }, | ||
new ColumnDefinition { Width = 10 }, | ||
new ColumnDefinition { Width = GridLength.Star }, | ||
new ColumnDefinition { Width = 30 }, | ||
} | ||
}; | ||
|
||
actions.AddChild(new Label { Text = "Primary color" }, 0, 0, 3); | ||
for (int i = 0; i < ColorSlider.Length; i++) | ||
{ | ||
var valueLabel = new Label(); | ||
ColorSlider[i].ValueChanged += (_, e) => | ||
{ | ||
progressBar.ProgressColor = Color.FromRgba(ColorSlider[0].Value, ColorSlider[1].Value, ColorSlider[2].Value, ColorSlider[3].Value); | ||
valueLabel.Text = ((int)(e.NewValue * 255)).ToString(); | ||
}; | ||
actions.AddChild(new Label { Text = GetColorLetter(i) }, 0, i + 1); | ||
actions.AddChild(ColorSlider[i], 1, i + 1); | ||
actions.AddChild(valueLabel, 2, i + 1); | ||
} | ||
|
||
actions.AddChild(new Label { Text = "Background color" }, 3, 0, 3); | ||
for (int i = 0; i < BackColorSlider.Length; i++) | ||
{ | ||
var valueLabel = new Label(); | ||
BackColorSlider[i].ValueChanged += (_, e) => | ||
{ | ||
progressBar.BackgroundColor = Color.FromRgba(BackColorSlider[0].Value, BackColorSlider[1].Value, BackColorSlider[2].Value, BackColorSlider[3].Value); | ||
valueLabel.Text = ((int)(e.NewValue * 255)).ToString(); | ||
}; | ||
actions.AddChild(new Label { Text = GetColorLetter(i) }, 3, i + 1); | ||
actions.AddChild(BackColorSlider[i], 4, i + 1); | ||
actions.AddChild(valueLabel, 5, i + 1); | ||
} | ||
|
||
var valueSlider = new Slider(0, 1, progressBar.Progress); | ||
valueSlider.ValueChanged += (_, e) => progressBar.Progress = e.NewValue; | ||
actions.AddChild(new Label { Text = "Value" }, 0, 5, 6); | ||
actions.AddChild(valueSlider, 0, 6, 6); | ||
|
||
var heightSlider = new Slider(0, 100, 4); | ||
heightSlider.ValueChanged += (_, e) => progressBar.HeightRequest = e.NewValue; | ||
actions.AddChild(new Label { Text = "HeightRequest" }, 0, 7, 6); | ||
actions.AddChild(heightSlider, 0, 8, 6); | ||
|
||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
actions, | ||
progressBar | ||
} | ||
}; | ||
} | ||
|
||
string GetColorLetter(int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return "R"; | ||
case 1: | ||
return "G"; | ||
case 2: | ||
return "B"; | ||
default: | ||
return "A"; | ||
} | ||
} | ||
} | ||
} |
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
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
35 changes: 35 additions & 0 deletions
35
Xamarin.Forms.Platform.Android/Resources/drawable/MaterialProgressBar.xml
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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
From original drawable https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/res/drawable/progress_horizontal_material.xml | ||
with removed rounded corners. | ||
paymicro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:id="@android:id/background" | ||
android:gravity="center_vertical|fill_horizontal"> | ||
<shape android:shape="rectangle" | ||
android:tint="#000"> | ||
<corners android:radius="0dp" /> | ||
<solid android:color="#000" /> | ||
</shape> | ||
</item> | ||
<item android:id="@android:id/secondaryProgress" | ||
android:gravity="center_vertical|fill_horizontal"> | ||
<scale android:scaleWidth="100%"> | ||
<shape android:shape="rectangle" | ||
android:tint="#000"> | ||
<corners android:radius="0dp" /> | ||
<solid android:color="#000" /> | ||
</shape> | ||
</scale> | ||
</item> | ||
<item android:id="@android:id/progress" | ||
android:gravity="center_vertical|fill_horizontal"> | ||
<scale android:scaleWidth="100%"> | ||
<shape android:shape="rectangle" | ||
android:tint="#000"> | ||
<corners android:radius="0dp" /> | ||
<solid android:color="#000" /> | ||
</shape> | ||
</scale> | ||
</item> | ||
</layer-list> |
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 |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
|
||
<!-- Material Progress Bars --> | ||
<style name="XamarinFormsMaterialProgressBarHorizontal" parent="Widget.AppCompat.ProgressBar.Horizontal"> | ||
<item name="android:indeterminateOnly">false</item> | ||
<item name="android:progressDrawable">@drawable/MaterialProgressBar</item> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you opt to use the base control and a custom drawing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just got reminded by Shane, Google has a HARD set for 4dp. Of course, this is absolutely not true for iOS, but hey, why follow your own guides. |
||
</style> | ||
<style name="XamarinFormsMaterialProgressBarCircular" parent="Widget.AppCompat.ProgressBar"> | ||
<item name="android:background">@drawable/MaterialActivityIndicatorBackground</item> | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this constant should be moved to the
MaterialColors
type (as the rest of the values like this are there)