Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Library and sample updated to v1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dminta committed Apr 29, 2017
1 parent 7e1e51a commit 94287e8
Show file tree
Hide file tree
Showing 20 changed files with 2,548 additions and 1,976 deletions.
16 changes: 16 additions & 0 deletions MaterialProgressBar.Sample/ActivityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Linq;

using Android.App;
using Android.Views;

namespace MaterialProgressBar.Sample
{
public static class ActivityExtensions
{
public static T[] BindViews<T>(this Activity activity, params int[] ids)
where T : View
{
return ids.Select(id => activity.FindViewById<T>(id)).ToArray();
}
}
}
75 changes: 75 additions & 0 deletions MaterialProgressBar.Sample/Animators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using Android.Widget;
using Android.Animation;
using Android.Views.Animations;

namespace MaterialProgressBar.Sample
{
static class Animators
{
class DeterminateCircularPrimaryProgressAnimatorListener : Java.Lang.Object, ValueAnimator.IAnimatorUpdateListener
{
ValueAnimator animator;
ProgressBar[] progressBars;

public DeterminateCircularPrimaryProgressAnimatorListener(ValueAnimator animator, ProgressBar[] progressBars)
{
this.animator = animator;
this.progressBars = progressBars;
}

public void OnAnimationUpdate(ValueAnimator animation)
{
int value = (int)animator.AnimatedValue;

foreach (var progressBar in progressBars)
{
progressBar.Progress = value;
}
}
}

public static ValueAnimator MakeDeterminateCircularPrimaryProgressAnimator(ProgressBar[] progressBars)
{
ValueAnimator animator = ValueAnimator.OfInt(0, 150);
animator.SetDuration(6000);
animator.SetInterpolator(new LinearInterpolator());
animator.RepeatCount = ValueAnimator.Infinite;

animator.AddUpdateListener(new DeterminateCircularPrimaryProgressAnimatorListener(animator, progressBars));

return animator;
}

class DeterminateCircularPrimaryAndSecondaryProgressAnimatorListener : Java.Lang.Object, ValueAnimator.IAnimatorUpdateListener
{
ValueAnimator animator;
ProgressBar[] progressBars;

public DeterminateCircularPrimaryAndSecondaryProgressAnimatorListener(ValueAnimator animator, ProgressBar[] progressBars)
{
this.animator = animator;
this.progressBars = progressBars;
}

public void OnAnimationUpdate(ValueAnimator animation)
{
int value = (int)Math.Round(1.25f * (int)animator.AnimatedValue);

foreach (var progressBar in progressBars)
{
progressBar.SecondaryProgress = value;
}
}
}

public static ValueAnimator MakeDeterminateCircularPrimaryAndSecondaryProgressAnimator(ProgressBar[] progressBars)
{
ValueAnimator animator = MakeDeterminateCircularPrimaryProgressAnimator(progressBars);

animator.AddUpdateListener(new DeterminateCircularPrimaryAndSecondaryProgressAnimatorListener(animator, progressBars));

return animator;
}
}
}
75 changes: 75 additions & 0 deletions MaterialProgressBar.Sample/DeterminateCircularSampleActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Android.Animation;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;

namespace MaterialProgressBar.Sample
{
[Activity(Label = "@string/determinate_circular_title", LaunchMode = LaunchMode.SingleTop)]
[MetaData("android.support.PARENT_ACTIVITY", Value = "MaterialProgressBarSample.MainActivity")]
public class DeterminateCircularSampleActivity : AppCompatActivity
{
ProgressBar[] mPrimaryProgressBars;
ProgressBar[] mPrimaryAndSecondaryProgressBars;

ValueAnimator mPrimaryProgressAnimator;
ValueAnimator mPrimaryAndSecondaryProgressAnimator;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.determinate_circular_sample_activity);

mPrimaryProgressBars = this.BindViews<ProgressBar>(Resource.Id.normal_progress,
Resource.Id.tinted_normal_progress,
Resource.Id.dynamic_progress,
Resource.Id.tinted_dynamic_progress);

mPrimaryAndSecondaryProgressBars = this.BindViews<ProgressBar>(Resource.Id.normal_secondary_progress,
Resource.Id.normal_background_progress,
Resource.Id.tinted_normal_secondary_progress,
Resource.Id.tinted_normal_background_progress,
Resource.Id.dynamic_secondary_progress,
Resource.Id.dynamic_background_progress,
Resource.Id.tinted_dynamic_secondary_progress,
Resource.Id.tinted_dynamic_background_progress);

SupportActionBar.SetDisplayHomeAsUpEnabled(true);

mPrimaryProgressAnimator = Animators.MakeDeterminateCircularPrimaryProgressAnimator(mPrimaryProgressBars);
mPrimaryAndSecondaryProgressAnimator = Animators.MakeDeterminateCircularPrimaryAndSecondaryProgressAnimator(mPrimaryAndSecondaryProgressBars);
}

public override void OnAttachedToWindow()
{
base.OnAttachedToWindow();

mPrimaryProgressAnimator.Start();
mPrimaryAndSecondaryProgressAnimator.Start();
}

public override void OnDetachedFromWindow()
{
base.OnDetachedFromWindow();

mPrimaryProgressAnimator.End();
mPrimaryAndSecondaryProgressAnimator.End();
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
AppUtils.NavigateUp(this);
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
}
}
43 changes: 36 additions & 7 deletions MaterialProgressBar.Sample/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
using Android.App;
using Android.Animation;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;

namespace MaterialProgressBar.Sample
{
[Activity(Label = "@string/app_name", MainLauncher = true, LaunchMode = LaunchMode.SingleTop)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
ProgressBar[] mDeterminateCircularProgressBars;
ValueAnimator mDeterminateCircularProgressAnimator;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.main_activity);
}

public override bool OnCreateOptionsMenu(IMenu menu)
mDeterminateCircularProgressBars = this.BindViews<ProgressBar>(Resource.Id.determinate_circular_large_progress,
Resource.Id.determinate_circular_progress,
Resource.Id.determinate_circular_small_progress);

mDeterminateCircularProgressAnimator = Animators.MakeDeterminateCircularPrimaryProgressAnimator(mDeterminateCircularProgressBars);
}

public override void OnAttachedToWindow()
{
base.OnAttachedToWindow();

mDeterminateCircularProgressAnimator.Start();
}

public override void OnDetachedFromWindow()
{
base.OnDetachedFromWindow();

mDeterminateCircularProgressAnimator.End();
}

public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.menu_main, menu);
return true;
Expand All @@ -29,9 +54,13 @@ public override bool OnOptionsItemSelected(IMenuItem item)
{
case Resource.Id.action_about:
StartActivity(new Intent(this, typeof(AboutActivity)));
break;
}
return base.OnOptionsItemSelected(item);
return true;
case Resource.Id.action_determinate_circular_sample:
StartActivity(new Intent(this, typeof(DeterminateCircularSampleActivity)));
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
}
}
Expand Down
Loading

0 comments on commit 94287e8

Please sign in to comment.