-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Clancey/Animations
Animations
- Loading branch information
Showing
41 changed files
with
1,227 additions
and
205 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Comet.Skia; | ||
namespace Comet.Samples | ||
{ | ||
public class SkiaButtonSample : View | ||
{ | ||
[Body] | ||
View body() => new VStack | ||
{ | ||
new SKText("Hello").Color(Color.Black) | ||
.BeginAnimationSequence(repeats:true) | ||
.Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.Fuchsia); | ||
}).Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.AliceBlue); | ||
}).Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.Beige); | ||
}).Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.BlueViolet); | ||
}).Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.Lavender); | ||
}).Animate(duration:1,action:(text)=>{ | ||
text.Color(Color.Fuchsia); | ||
}).EndAnimationSequence(), | ||
//TODO: Figure out why animation doesn't work | ||
new SKButton("Hello").Background(Color.Black).Color(Color.White).Animate(x => { | ||
x.Background(Color.White).Color(Color.Black); | ||
},duration:3) | ||
}; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using Android.Animation; | ||
using Android.Content; | ||
using Android.OS; | ||
|
||
namespace Comet.Android.Services | ||
{ | ||
public class AndroidTicker : Ticker | ||
{ | ||
ValueAnimator _val; | ||
bool _systemEnabled; | ||
public AndroidTicker() | ||
{ | ||
_val = new ValueAnimator(); | ||
_val.SetIntValues(0, 100); // avoid crash | ||
_val.RepeatCount = ValueAnimator.Infinite; | ||
_val.Update += (s, e) => Fire?.Invoke(); ; | ||
CheckPowerSaveModeStatus(); | ||
} | ||
|
||
internal void CheckPowerSaveModeStatus() | ||
{ | ||
// Android disables animations when it's in power save mode | ||
// So we need to keep track of whether we're in that mode and handle animations accordingly | ||
// We can't just check ValueAnimator.AreAnimationsEnabled() because there's no event for that, and it's | ||
// only supported on API >= 26 | ||
|
||
//if (!Forms.IsLollipopOrNewer) | ||
//{ | ||
// _systemEnabled = true; | ||
// return; | ||
//} | ||
|
||
var powerManager = (PowerManager)AndroidContext.CurrentContext.GetSystemService(Context.PowerService); | ||
|
||
var powerSaveOn = powerManager.IsPowerSaveMode; | ||
|
||
// If power saver is active, then animations will not run | ||
_systemEnabled = !powerSaveOn; | ||
|
||
} | ||
|
||
public override bool IsRunning => _val.IsStarted; | ||
public override bool SystemEnabled { get => _systemEnabled; } | ||
public override void Start() | ||
{ | ||
_val?.Start(); | ||
|
||
} | ||
public override void Stop() | ||
{ | ||
ThreadHelper.FireOnMainThread(() => _val.Cancel()); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using CoreAnimation; | ||
using CoreVideo; | ||
using Foundation; | ||
|
||
namespace Comet.Mac | ||
{ | ||
public class MacTicker : Ticker | ||
{ | ||
public MacTicker() | ||
{ | ||
} | ||
CVDisplayLink link; | ||
|
||
public override bool IsRunning => link != null; | ||
public override void Start() | ||
{ | ||
if (link != null) | ||
return; | ||
link = new CVDisplayLink(); | ||
link.SetOutputCallback(DisplayLinkOutputCallback); | ||
link.Start(); | ||
|
||
} | ||
public CVReturn DisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, | ||
ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) | ||
{ | ||
Fire?.Invoke(); | ||
return CVReturn.Success; | ||
} | ||
public override void Stop() | ||
{ | ||
if (link == null) | ||
return; | ||
link?.Stop(); | ||
link?.Dispose(); | ||
link = null; | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.