Created
December 11, 2014 18:55
-
-
Save Redth/2a5acaa57f0a44a73a21 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using Android.Support.Wearable.Watchface; | |
using Android.App; | |
using Android.Runtime; | |
namespace WatchFace | |
{ | |
public class MyWatchFaceService : CanvasWatchFaceService | |
{ | |
public override CanvasWatchFaceService.Engine OnCreateEngine () | |
{ | |
return new MyWatchFaceEngine (this); | |
} | |
public class MyWatchFaceEngine : CanvasWatchFaceService.Engine | |
{ | |
public MyWatchFaceEngine (CanvasWatchFaceService svc) : base(svc) | |
{ | |
Service = svc.JavaCast<Service> (); | |
} | |
public Service Service { get; private set; } | |
Android.Graphics.Paint hoursPaint; | |
public override void OnCreate (Android.Views.ISurfaceHolder surfaceHolder) | |
{ | |
var b = new WatchFaceStyle.Builder (Service) | |
.SetCardPeekMode (WatchFaceStyle.PeekModeShort) | |
.SetBackgroundVisibility (WatchFaceStyle.BackgroundVisibilityInterruptive) | |
.SetShowSystemUiTime (false) | |
.Build (); | |
SetWatchFaceStyle(b); | |
hoursPaint = new Android.Graphics.Paint (); | |
hoursPaint.Color = Android.Graphics.Color.White; | |
hoursPaint.TextSize = 48f; | |
} | |
public override void OnPropertiesChanged (Android.OS.Bundle props) | |
{ | |
} | |
public override void OnTimeTick () | |
{ | |
Invalidate (); | |
} | |
public override void OnAmbientModeChanged (bool ambient) | |
{ | |
} | |
public override void OnVisibilityChanged (bool visible) | |
{ | |
} | |
public override void OnDraw (Android.Graphics.Canvas canvas, Android.Graphics.Rect frame) | |
{ | |
var str = DateTime.Now.ToString ("h:mm:ss tt"); | |
canvas.DrawText (str, (float)(frame.Left + 50), (float)(frame.Top + 50), hoursPaint); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment