/// <summary> /// ウォッチフェイスの描画時に実行されます。 /// </summary> /// <param name="canvas">ウォッチフェイスに描画するためのキャンバスオブジェクト</param> /// <param name="bounds">画面のサイズを格納するオブジェクト</param> public override void OnDraw(Canvas canvas, Rect bounds) { // TODO : 現在時刻を取得し、ウォッチフェイスを描画する処理を入れます。 // 現在時刻にセットします。 // Time ( Android ) //nowTime.SetToNow(); // Calendar ( Java ) nowTime = Java.Util.Calendar.GetInstance(nowTime.TimeZone); // DateTime ( C# ) //nowTime = DateTime.Now; #if DEBUG if (Log.IsLoggable(logTag, LogPriority.Info)) { Log.Info(logTag, $"{nameof( OnDraw )}: Now time = {WatchfaceUtility.ConvertToDateTime( nowTime ):yyyy/MM/dd HH:mm:ss K}"); } #endif // 背景を描画します。 // アンビエントモードであるかどうか判別します。 if (IsInAmbientMode) { // アンビエントモードの時は、黒色で塗りつぶします。 canvas.DrawColor(Color.Black); } else { // そうでない時は、背景画像を描画します。 canvas.DrawRect(0, 0, canvas.Width, canvas.Height, backgroundPaint); } // 中心のXY座標を求めます。 float centerX = bounds.Width() / 2.0f; float centerY = bounds.Height() / 2.0f; // 針の長さを求めます。 secondHand.Length = centerX - 20; minuteHand.Length = centerX - 40; hourHand.Length = centerX - 80; // 時針を描画します。 hourHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + hourHand.X, centerY + hourHand.Y, hourHand.Paint); // 分針を描画します。 minuteHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + minuteHand.X, centerY + minuteHand.Y, minuteHand.Paint); // アンビエントモードでないかどうかを判別します。 if (!IsInAmbientMode) { // 分針を描画します。 secondHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + secondHand.X, centerY + secondHand.Y, secondHand.Paint); } }
/// <summary> /// Invoke when drawing a watch face. /// </summary> /// <param name="canvas"><see cref="Canvas"/> object for drawing on the watch face</param> /// <param name="bounds">Object storing the screen size</param> public override void OnDraw(Canvas canvas, Rect bounds) { // TODO: Writes here, process of acquiring the current time and drawing the watch face. // Gets current time. // Time ( Android ) //nowTime.SetToNow(); // Calendar ( Java ) nowTime = Java.Util.Calendar.GetInstance(nowTime.TimeZone); // DateTime ( C# ) //nowTime = DateTime.Now; #if DEBUG if (Log.IsLoggable(logTag, LogPriority.Info)) { Log.Info(logTag, $"{nameof( OnDraw )}: Now time = {WatchfaceUtility.ConvertToDateTime( nowTime ):yyyy/MM/dd HH:mm:ss K}"); } #endif // Draws the background. // Determines whether in ambient mode. if (IsInAmbientMode) { // In ambient mode, fills with black color. canvas.DrawColor(Color.Black); } else { // Otherwise, draws the background graphics. canvas.DrawRect(0, 0, canvas.Width, canvas.Height, backgroundPaint); } // Calculates the center XY coordinates. float centerX = bounds.Width() / 2.0f; float centerY = bounds.Height() / 2.0f; // Calculates the length of the hands. secondHand.Length = centerX - 20; minuteHand.Length = centerX - 40; hourHand.Length = centerX - 80; // Draws the hour hand. hourHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + hourHand.X, centerY + hourHand.Y, hourHand.Paint); // Draws the minute hand. minuteHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + minuteHand.X, centerY + minuteHand.Y, minuteHand.Paint); // Determines whether in ambient mode. if (!IsInAmbientMode) { // In ambient mode, draws the second hand. secondHand.SetTime(nowTime); canvas.DrawLine(centerX, centerY, centerX + secondHand.X, centerY + secondHand.Y, secondHand.Paint); } }