Exemplo n.º 1
0
            /// <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);
                }
            }
Exemplo n.º 3
0
        public void Draw(Canvas canvas, MotoRect rect)
        {
            string time = WatchfaceUtility.ConvertToDateTime(Calendar).ToString("HH:mm");

            int unit = Scale.Unit(rect);

            // HH:mm

            //paint.TextSize = 50;
            paint.TextSize = unit * 5f;
            float width = paint.MeasureText(time);

            //canvas.DrawText(time,
            //    (rect.Width - width) / 2, 80, paint);
            canvas.DrawText(time,
                            (rect.Width - width) / 2, unit * 8f, paint);
        }
Exemplo n.º 4
0
        public void Draw(Canvas canvas, MotoRect rect)
        {
            DateTime datetime   = WatchfaceUtility.ConvertToDateTime(Calendar);
            string   date       = "";
            Rect     textRect   = new Rect();
            int      dateHeight = 0;

            int unit = Scale.Unit(rect);

            // d
            //paint.TextSize = 28;
            paint.TextSize = unit * 2.8f;
            date           = datetime.ToString("dd", ci);
            paint.GetTextBounds(date, 0, date.Length, textRect);
            dateHeight = textRect.Height();
            canvas.DrawText(date,
                            (rect.Width / 4.0f * 3.5f) - (textRect.Width() / 2.0f),
                            (rect.Height + textRect.Height()) / 2.0f, paint);

            // ddd
            //paint.TextSize = 16;
            paint.TextSize = unit * 1.6f;
            date           = datetime.ToString("ddd", ci).ToUpper();
            paint.GetTextBounds(date, 0, date.Length, textRect);
            //canvas.DrawText(date,
            //    (rect.Width / 4.0f * 3.5f) - (textRect.Width() / 2.0f),
            //    (rect.Height + textRect.Height()) / 2.0f - dateHeight - 10, paint);
            canvas.DrawText(date,
                            (rect.Width / 4.0f * 3.5f) - (textRect.Width() / 2.0f),
                            (rect.Height + textRect.Height()) / 2.0f - dateHeight - unit, paint);

            // MMM
            //paint.TextSize = 16;
            paint.TextSize = unit * 1.6f;
            date           = datetime.ToString("MMM", ci).ToUpper();
            paint.GetTextBounds(date, 0, date.Length, textRect);
            canvas.DrawText(date,
                            (rect.Width / 4.0f * 3.5f) - (textRect.Width() / 2.0f),
                            (rect.Height + textRect.Height()) / 2.0f + dateHeight + textRect.Height(), 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);
                }

                // Draws the text of the current time.
                canvas.DrawText(
                    WatchfaceUtility.ConvertToDateTime(nowTime).ToString(isAmbient ? "HH:mm" : "HH:mm:ss"),
                    digitalTimeText.XOffset, digitalTimeText.YOffset, digitalTimeText.Paint
                    );
            }
            /// <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);
                }

                canvas.DrawText(
                    WatchfaceUtility.ConvertToDateTime(nowTime).ToString(isAmbient ? "HH:mm" : "HH:mm:ss"),
                    digitalTimeText.XOffset, digitalTimeText.YOffset, digitalTimeText.Paint
                    );
            }
Exemplo n.º 7
0
 private Color GetColor(AccentColor accentColor) => WatchfaceUtility.ConvertARGBToColor(GetColor(GetColorResource(accentColor)));
Exemplo n.º 8
0
        // Scaled 用 Bitmap
        //private Bitmap backgroundScaledBitmap;
        //private Bitmap backgroundScaledAmbient;

        public WatchBackground(CanvasWatchFaceService owner)
        {
            // 背景色の作成
            backColor = new Color(
                WatchfaceUtility.ConvertARGBToColor(
                    ContextCompat.GetColor(owner, Resource.Color.background)));

            // 背景用 Paint の作成
            backgroundPaint = new Paint()
            {
                // 背景色を設定
                Color = backColor,
                // Scaled された画像をなめらかにする
                FilterBitmap = true
            };

            #region 'Resources.GetDrawable(int)' は旧形式です('deprecated')

            //// リソースから月齢画像を読み込みます
            //var backgroundDrawableFullMoon = owner.Resources.GetDrawable(Resource.Drawable.FullMoon);
            //var backgroundDrawableF7N = owner.Resources.GetDrawable(Resource.Drawable.F7N);
            //var backgroundDrawableF6N = owner.Resources.GetDrawable(Resource.Drawable.F6N);
            //var backgroundDrawableF5N = owner.Resources.GetDrawable(Resource.Drawable.F5N);
            //var backgroundDrawableF4N = owner.Resources.GetDrawable(Resource.Drawable.F4N);
            //var backgroundDrawableF3N = owner.Resources.GetDrawable(Resource.Drawable.F3N);
            //var backgroundDrawableF2N = owner.Resources.GetDrawable(Resource.Drawable.F2N);
            //var backgroundDrawableF1N = owner.Resources.GetDrawable(Resource.Drawable.F1N);
            //var backgroundDrawableNewMoon = owner.Resources.GetDrawable(Resource.Drawable.NewMoon);
            //var backgroundDrawableN1F = owner.Resources.GetDrawable(Resource.Drawable.N1F);
            //var backgroundDrawableN2F = owner.Resources.GetDrawable(Resource.Drawable.N2F);
            //var backgroundDrawableN3F = owner.Resources.GetDrawable(Resource.Drawable.N3F);
            //var backgroundDrawableN4F = owner.Resources.GetDrawable(Resource.Drawable.N4F);
            //var backgroundDrawableN5F = owner.Resources.GetDrawable(Resource.Drawable.N5F);
            //var backgroundDrawableN6F = owner.Resources.GetDrawable(Resource.Drawable.N6F);
            //var backgroundDrawableN7F = owner.Resources.GetDrawable(Resource.Drawable.N7F);
            //var backgroundDrawableDevilSummoner = owner.Resources.GetDrawable(Resource.Drawable.DevilSummoner);
            //var backgroundDrawableDx2 = owner.Resources.GetDrawable(Resource.Drawable.Dx2);
            ////var backgroundDrawableAmbient = owner.Resources.GetDrawable(Resource.Drawable.Ambient);    //

            //// 月齢画像を Bitmap に変換
            //backgroundFullMoon = (backgroundDrawableFullMoon as BitmapDrawable).Bitmap;
            //backgroundF7N = (backgroundDrawableF7N as BitmapDrawable).Bitmap;
            //backgroundF6N = (backgroundDrawableF6N as BitmapDrawable).Bitmap;
            //backgroundF5N = (backgroundDrawableF5N as BitmapDrawable).Bitmap;
            //backgroundF4N = (backgroundDrawableF4N as BitmapDrawable).Bitmap;
            //backgroundF3N = (backgroundDrawableF3N as BitmapDrawable).Bitmap;
            //backgroundF2N = (backgroundDrawableF2N as BitmapDrawable).Bitmap;
            //backgroundF1N = (backgroundDrawableF1N as BitmapDrawable).Bitmap;
            //backgroundNewMoon = (backgroundDrawableNewMoon as BitmapDrawable).Bitmap;
            //backgroundN1F = (backgroundDrawableN1F as BitmapDrawable).Bitmap;
            //backgroundN2F = (backgroundDrawableN2F as BitmapDrawable).Bitmap;
            //backgroundN3F = (backgroundDrawableN3F as BitmapDrawable).Bitmap;
            //backgroundN4F = (backgroundDrawableN4F as BitmapDrawable).Bitmap;
            //backgroundN5F = (backgroundDrawableN5F as BitmapDrawable).Bitmap;
            //backgroundN6F = (backgroundDrawableN6F as BitmapDrawable).Bitmap;
            //backgroundN7F = (backgroundDrawableN7F as BitmapDrawable).Bitmap;
            //backgroundDevilSummoner = (backgroundDrawableDevilSummoner as BitmapDrawable).Bitmap;
            //backgroundDx2 = (backgroundDrawableDx2 as BitmapDrawable).Bitmap;
            ////backgroundAmbient = (backgroundDrawableAmbient as BitmapDrawable).Bitmap;

            #endregion

            #region Resource から Bitmap を読み込み、Rescale 前の状態で変数にセット

            backgroundFullMoon = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.FullMoon, null)
                as BitmapDrawable).Bitmap;
            backgroundF7N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F7N, null)
                as BitmapDrawable).Bitmap;
            backgroundF6N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F6N, null)
                as BitmapDrawable).Bitmap;
            backgroundF5N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F5N, null)
                as BitmapDrawable).Bitmap;
            backgroundF4N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F4N, null)
                as BitmapDrawable).Bitmap;
            backgroundF3N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F3N, null)
                as BitmapDrawable).Bitmap;
            backgroundF2N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F2N, null)
                as BitmapDrawable).Bitmap;
            backgroundF1N = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.F1N, null)
                as BitmapDrawable).Bitmap;
            backgroundNewMoon = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.NewMoon, null)
                as BitmapDrawable).Bitmap;
            backgroundN1F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N1F, null)
                as BitmapDrawable).Bitmap;
            backgroundN2F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N2F, null)
                as BitmapDrawable).Bitmap;
            backgroundN3F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N3F, null)
                as BitmapDrawable).Bitmap;
            backgroundN4F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N4F, null)
                as BitmapDrawable).Bitmap;
            backgroundN5F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N5F, null)
                as BitmapDrawable).Bitmap;
            backgroundN6F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N6F, null)
                as BitmapDrawable).Bitmap;
            backgroundN7F = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.N7F, null)
                as BitmapDrawable).Bitmap;
            backgroundDevilSummoner = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.DevilSummoner, null)
                as BitmapDrawable).Bitmap;
            backgroundDx2 = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.Dx2, null)
                as BitmapDrawable).Bitmap;
            backgroundAmbient = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.Ambient, null)
                as BitmapDrawable).Bitmap;
            backgroundTetregrammaton = (
                ResourcesCompat.GetDrawable(owner.Resources, Resource.Drawable.TETREGRAMMATON, null)
                as BitmapDrawable).Bitmap;

            #endregion
        }
Exemplo n.º 9
0
            /// <summary>
            ///		<see cref="MyWatchFaceEngine"/>のインスタンスが生成された時に実行します。
            /// </summary>
            /// <param name="holder">ディスプレイ表面を表すオブジェクト</param>
            public override void OnCreate(ISurfaceHolder holder)
            {
                // TODO : ここでは主に、以下の処理を行います。
                // ・リソースから画像の読み込み
                // ・Paintなどのグラフィックスオブジェクトを生成
                // ・時刻を格納するオブジェクトの作成
                // ・システムのUI(インジケーターやOK Googleの表示など)の設定

                // システムのUIの配置方法を設定します。
                SetWatchFaceStyle(
                    new WatchFaceStyle.Builder(owner)
                    #region ウォッチフェイスのスタイルの設定

                    // ユーザーからのタップイベントを有効にするかどうか設定します。
                    //   true  : 有効
                    //   false : 無効(デフォルト)
                    //.SetAcceptsTapEvents( true )

                    // 通知が来た時の通知カードの高さを設定します。
                    //   WatchFaceStyle.PeekModeShort    : 通知カードをウィンドウの下部に小さく表示します。(デフォルト)
                    //   WatchFaceStyle.PeekModeVariable : 通知カードをウィンドウの全面に表示します。
                    .SetCardPeekMode(WatchFaceStyle.PeekModeShort)

                    // 通知カードの背景の表示方法を設定します。
                    //   WatchFaceStyle.BackgroundVisibilityInterruptive : 電話の着信など一部の通知のみ、背景を用事します。(デフォルト)
                    //   WatchFaceStyle.BackgroundVisibilityPersistent   : 通知カードの種類にかかわらず、その背景を常に表示します。
                    .SetBackgroundVisibility(WatchFaceStyle.BackgroundVisibilityInterruptive)

                    // アンビエントモード時に通知カードを表示するかどうかを設定します。
                    //   WatchFaceStyle.AmbientPeekModeVisible : 通知カードを表示します。(デフォルト)
                    //   WatchFaceStyle.AmbientPeekModeHidden  : 通知カードを表示しません。
                    //.SetAmbientPeekMode( WatchFaceStyle.AmbientPeekModeHidden )

                    // システムUIのデジタル時計を表示するするかどうかを設定します。(使用している例として、デフォルトで用意されている「シンプル」があります。)
                    //   true  : 表示
                    //   false : 非表示(デフォルト)
                    .SetShowSystemUiTime(false)

                    // ステータスアイコンなどに背景を付けるかどうかを設定します。
                    //   デフォルト                               : ステータスアイコンなどに背景を表示しません。
                    //   WatchFaceStyle.ProtectStatusBar        : ステータスアイコンに背景を表示します。
                    //   WatchFaceStyle.ProtectHotwordIndicator : 「OK Google」に背景を表示します。
                    //   WatchFaceStyle.ProtectWholeScreen      : ウォッチフェイスの背景を少し暗めにします。
                    // ※パラメーターは論理和で組み合わせることができます。
                    //.SetViewProtectionMode( WatchFaceStyle.ProtectStatusBar | WatchFaceStyle.ProtectHotwordIndicator )

                    // 通知カードを透明にするかどうかを設定します。
                    //   WatchFaceStyle.PeekOpacityModeOpaque      : 不透明(デフォルト)
                    //   WatchFaceStyle.PeekOpacityModeTranslucent : 透明
                    //.SetPeekOpacityMode( WatchFaceStyle.PeekOpacityModeTranslucent )

                    // ステータスアイコンや「OK Google」の位置を設定します。
                    //   GravityFlags.Top | GravityFlags.Left   : 左上(角形のデフォルト)
                    //   GravityFlags.Top | GravityFlags.Center : 上部の中央(丸形のデフォルト)
                    // 注 : GravityFlagsは列挙体なので、int型にキャストします。
                    //.SetStatusBarGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )
                    //.SetHotwordIndicatorGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )

                    #endregion
                    // 設定したスタイル情報をビルドします。このメソッドは最後に呼び出します。
                    .Build()
                    );
                // ベースクラスのOnCreateメソッドを実行します。
                base.OnCreate(holder);

                #region 最新のAndroid SDKにおける、Android.Content.Res.Resources.GetColorメソッドについて

                /*
                 *      Android.Content.Res.Resources.GetColorメソッドは、Android SDK Level 23以降で非推奨(Deprecated)となっています。
                 *      代わりの方法として、Android.Support.V4.Content.ContextCompat.GetColorメソッドを使用します。
                 *
                 *      [CanvasWatchFaceServiceオブジェクト].Resources.GetColor( Resource.Color.[リソース名] );
                 *      ↓
                 *      ContextCompat.GetColor( [CanvasWatchFaceServiceオブジェクト], Resource.Color.[リソース名] );
                 *      ※CanvasWatchFaceServiceクラスはContextクラスを継承しています。
                 *
                 *      なお、ContextCompat.GetColorの戻り値はColor型でなく、ARGB値を格納したint型となります。
                 *      Chronoir_net.Chronica.WatchfaceExtension.WatchfaceUtility.ConvertARGBToColor( int )メソッドで、Color型に変換することができます。
                 */
                #endregion

                var resources = owner.Resources;

                // 背景用のグラフィックスオブジェクトを生成します。
                backgroundPaint = new Paint();
                // リソースから背景色を読み込みます。
                backgroundPaint.Color = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.background));

                // 時針用のPaintグラフィックスオブジェクトを生成します。
                var hourHandPaint = new Paint();
                hourHandPaint.Color = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_hands));
                // 時針の幅を設定します。
                hourHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.hour_hand_stroke);
                // アンチエイリアスを有効にします。
                hourHandPaint.AntiAlias = true;
                // 線端の形は丸形を指定します。
                hourHandPaint.StrokeCap = Paint.Cap.Round;
                // 時針オブジェクトを初期化します。
                hourHand = new HourAnalogHandStroke(hourHandPaint);

                // 分針用のPaintグラフィックスオブジェクトを生成します。
                var minuteHandPaint = new Paint();
                minuteHandPaint.Color       = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_hands));
                minuteHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.minute_hand_stroke);
                minuteHandPaint.AntiAlias   = true;
                minuteHandPaint.StrokeCap   = Paint.Cap.Round;
                minuteHand = new MinuteAnalogHandStroke(minuteHandPaint);

                // 秒針用のPaintグラフィックスオブジェクトを生成します。
                var secondHandPaint = new Paint();
                secondHandPaint.Color       = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_sec_hand));
                secondHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.second_hand_stroke);
                secondHandPaint.AntiAlias   = true;
                secondHandPaint.StrokeCap   = Paint.Cap.Round;
                secondHand = new SecondAnalogHandStroke(secondHandPaint);

                // 時刻を格納するオブジェクトを生成します。
                // Time ( Android )
                //nowTime = new Time();
                // Calendar ( Java )
                nowTime = Java.Util.Calendar.GetInstance(Java.Util.TimeZone.Default);
                // DateTime ( C# )
                // DateTime構造体は値型なので、オブジェクトの生成はは不要です。
            }
Exemplo n.º 10
0
            /// <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

                // OnTapCommand & 画像の Scaled 用に画面サイズを取得
                motoRect.SetBounds(bounds);
                // Moto 360 1st 以外の端末やと 1 回走る
                if (motoRect.IsSizeChanged)
                {
                    watchBackground.Rescale(motoRect);
                    //watchGraph.Rescale(motoRect);
                    //watchReminder.Rescale(motoRect);
                    watchList.Rescale(motoRect);
                    watchNotify.Rescale(motoRect);
                }

                // 月齢計算
                moon.Now =
                    WatchfaceUtility.ConvertToDateTime(nowTime);

                //canvas.DrawColor(Color.Black);
                //watchBackground.IsInAmbient = IsInAmbientMode;
                //watchHands.IsAmbient = isAmbient;
                watchHands.Calendar = nowTime;
                watchTime.Calendar  = nowTime;
                watchDate.Calendar  = nowTime;
                //watchReminder.Calendar = nowTime;
                watchList.Calendar = nowTime;

                // 背景を描画します。
                // アンビエントモードであるかどうか判別します。
                if (IsInAmbientMode)
                {
                    // アンビエントモードの時は、黒色で塗りつぶします。
                    //canvas.DrawColor(Color.Black);
                    //watchBackground.DrawInAmbient(canvas, motoRect);

                    if (watchBackground.IsListMode)
                    {
                        watchBackground.DrawTetregrammaton(canvas, motoRect);
                        // リストモードの場合は上部に時間を表示
                        //watchTime.Draw(canvas, motoRect);
                    }
                    else
                    {
                        watchBackground.DrawInAmbient(canvas, motoRect);
                        // 時針、分針の線だけ表示する
                        watchHands.DrawHands(canvas, motoRect);
                    }
                }
                else
                {
                    // そうでない時は、背景画像を描画します。

                    // 背景描画
                    watchBackground.MoonAge = moon.Age;
                    watchBackground.Draw(canvas, motoRect);

                    // リマインダ
                    //if (!watchBackground.IsListMode)
                    //{
                    //    watchReminder.LastFullMoon = moon.LastFullMoon;
                    //    watchReminder.Draw(canvas, motoRect);
                    //}

                    #region next fullmoon graph

                    //watchGraph.LastFullMoon = moon.LastFullMoon;
                    //watchGraph.MoonAge = moon.Age;
                    //watchGraph.Draw(canvas, motoRect);
                    watchList.LastFullMoon = moon.LastFullMoon;
                    watchList.MoonAge      = moon.Age;
                    watchList.Draw(canvas, motoRect);

                    #endregion

                    #region 日付 右側 ddd d MMM

                    // 満月の時は描かへんいうんもありかな
                    if (watchBackground.FaceStyle == FaceStyles.Logo ||
                        moon.Age != MoonAges.Full ||
                        watchList.IsListMode)
                    {
                        watchDate.Draw(canvas, motoRect);
                    }

                    #endregion

                    #region メッセージ表示

                    watchNotify.Draw(canvas, motoRect);

                    #endregion

                    // 時針、分針、秒針
                    if (watchBackground.IsListMode)
                    {
                        // リストモードの場合は上部に時間を表示
                        watchTime.Draw(canvas, motoRect);
                        // 秒針だけ表示する
                        watchHands.DrawSec(canvas, motoRect);
                    }
                    else
                    {
                        // 月齢・ロゴ描画時
                        watchHands.DrawBorder(canvas, motoRect);
                        watchHands.DrawHands(canvas, motoRect);
                        watchHands.DrawSec(canvas, motoRect);
                    }
                }

                #region メッセージ

                if (moon.During5minMessage)
                {
                    watchNotify.Message = Messages.Before5min;
                    watchNotify.Visible = true;
                }
                else if (moon.During1minMessage)
                {
                    watchNotify.Message = Messages.Before1min;
                    watchNotify.Visible = true;
                }
                else if (moon.DuringEndedMessage)
                {
                    watchNotify.Message = Messages.Ended;
                    watchNotify.Visible = true;
                }
                else if (!watchNotify.IsCharSelecting)
                {
                    watchNotify.Visible = false;
                }

                #endregion

                #region バイブレーション

                if (moon.IsBefore5min)
                {
                    Xamarin.Essentials.Platform.Vibrator.Vibrate(300);
                }
                else if (moon.IsBefore1min)
                {
                    Xamarin.Essentials.Platform.Vibrator.Vibrate(500);
                }
                else if (moon.IsFullmoonEnded)
                {
                    Xamarin.Essentials.Platform.Vibrator.Vibrate(100);
                }

                #endregion
            }
Exemplo n.º 11
0
            /// <summary>
            ///		<see cref="MyWatchFaceEngine"/>のインスタンスが生成された時に実行します。
            /// </summary>
            /// <param name="holder">ディスプレイ表面を表すオブジェクト</param>
            public override void OnCreate(ISurfaceHolder holder)
            {
                // TODO : ここでは主に、以下の処理を行います。
                // ・リソースから画像の読み込み
                // ・Paintなどのグラフィックスオブジェクトを生成
                // ・時刻を格納するオブジェクトの作成
                // ・システムのUI(インジケーターやOK Googleの表示など)の設定

                // システムのUIの配置方法を設定します。
                SetWatchFaceStyle(
                    new WatchFaceStyle.Builder(owner)
                    #region ウォッチフェイスのスタイルの設定

                    // ユーザーからのタップイベントを有効にするかどうか設定します。
                    //   true  : 有効
                    //   false : 無効(デフォルト)
                    .SetAcceptsTapEvents(true)

                    // 通知が来た時の通知カードの高さを設定します。
                    //   WatchFaceStyle.PeekModeShort    : 通知カードをウィンドウの下部に小さく表示します。(デフォルト)
                    //   WatchFaceStyle.PeekModeVariable : 通知カードをウィンドウの全面に表示します。
                    .SetCardPeekMode(WatchFaceStyle.PeekModeShort)

                    // 通知カードの背景の表示方法を設定します。
                    //   WatchFaceStyle.BackgroundVisibilityInterruptive : 電話の着信など一部の通知のみ、背景を用事します。(デフォルト)
                    //   WatchFaceStyle.BackgroundVisibilityPersistent   : 通知カードの種類にかかわらず、その背景を常に表示します。
                    .SetBackgroundVisibility(WatchFaceStyle.BackgroundVisibilityInterruptive)

                    // アンビエントモード時に通知カードを表示するかどうかを設定します。
                    //   WatchFaceStyle.AmbientPeekModeVisible : 通知カードを表示します。(デフォルト)
                    //   WatchFaceStyle.AmbientPeekModeHidden  : 通知カードを表示しません。
                    //.SetAmbientPeekMode( WatchFaceStyle.AmbientPeekModeHidden )

                    // システムUIのデジタル時計を表示するするかどうかを設定します。(使用している例として、デフォルトで用意されている「シンプル」があります。)
                    //   true  : 表示
                    //   false : 非表示(デフォルト)
                    .SetShowSystemUiTime(false)

                    // ステータスアイコンなどに背景を付けるかどうかを設定します。
                    //   デフォルト                               : ステータスアイコンなどに背景を表示しません。
                    //   WatchFaceStyle.ProtectStatusBar        : ステータスアイコンに背景を表示します。
                    //   WatchFaceStyle.ProtectHotwordIndicator : 「OK Google」に背景を表示します。
                    //   WatchFaceStyle.ProtectWholeScreen      : ウォッチフェイスの背景を少し暗めにします。
                    // ※パラメーターは論理和で組み合わせることができます。
                    //.SetViewProtectionMode( WatchFaceStyle.ProtectStatusBar | WatchFaceStyle.ProtectHotwordIndicator )

                    // 通知カードを透明にするかどうかを設定します。
                    //   WatchFaceStyle.PeekOpacityModeOpaque      : 不透明(デフォルト)
                    //   WatchFaceStyle.PeekOpacityModeTranslucent : 透明
                    //.SetPeekOpacityMode( WatchFaceStyle.PeekOpacityModeTranslucent )

                    // ステータスアイコンや「OK Google」の位置を設定します。
                    //   GravityFlags.Top | GravityFlags.Left   : 左上(角形のデフォルト)
                    //   GravityFlags.Top | GravityFlags.Center : 上部の中央(丸形のデフォルト)
                    // 注 : GravityFlagsは列挙体なので、int型にキャストします。
                    //.SetStatusBarGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )
                    //.SetHotwordIndicatorGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )

                    #endregion
                    // 設定したスタイル情報をビルドします。このメソッドは最後に呼び出します。
                    .Build()
                    );
                // ベースクラスのOnCreateメソッドを実行します。
                base.OnCreate(holder);

                #region 最新のAndroid SDKにおける、Android.Content.Res.Resources.GetColorメソッドについて

                /*
                 *                      Android.Content.Res.Resources.GetColorメソッドは、Android SDK Level 23以降で非推奨(Deprecated)となっています。
                 *                      代わりの方法として、Android.Support.V4.Content.ContextCompat.GetColorメソッドを使用します。
                 *
                 *                      [CanvasWatchFaceServiceオブジェクト].Resources.GetColor( Resource.Color.[リソース名] );
                 *                      ↓
                 *                      ContextCompat.GetColor( [CanvasWatchFaceServiceオブジェクト], Resource.Color.[リソース名] );
                 *                      ※CanvasWatchFaceServiceクラスはContextクラスを継承しています。
                 *
                 *                      なお、ContextCompat.GetColorの戻り値はColor型でなく、ARGB値を格納したint型となります。
                 *                      Chronoir_net.Chronica.WatchfaceExtension.WatchfaceUtility.ConvertARGBToColor( int )メソッドで、Color型に変換することができます。
                 */
                #endregion

                // 時刻を格納するオブジェクトを生成します。
                // Time ( Android )
                //nowTime = new Time();
                // Calendar ( Java )
                nowTime = Java.Util.Calendar.GetInstance(Java.Util.TimeZone.Default);
                // DateTime ( C# )
                // DateTime構造体は値型なので、オブジェクトの生成はは不要です。

                // 画面サイズ準備(OnDraw で更新)
                // とりあえず Moto 360 1st gen に設定
                motoRect = new MotoRect(0, 0, 320, 320)
                {
                    IsMoto360 = true
                };

                // 背景
                watchBackground = new WatchBackground(owner);
                watchBackground.Rescale(motoRect);
                watchBackground.FaceStyle = FaceStyles.Moon;
                // グラフ
                //watchGraph = new WatchGraph();
                //watchGraph.Rescale(motoRect);
                // リマインダ
                //watchReminder = new WatchReminder();
                //watchReminder.Rescale(motoRect);
                // リスト | グラフ & リマインダ
                watchList = new WatchList();
                watchList.Rescale(motoRect);
                watchList.IsListMode = false;
                watchList.FaceStyle  = FaceStyles.Moon;
                // 時針、分針、秒針
                watchHands = new WatchHands(owner);
                // 日時
                watchDate = new WatchDate();
                watchTime = new WatchTime();
                // 月齢判定
                moon = new MoonAge();
                moon.Initialize(
                    WatchfaceUtility.ConvertToDateTime(nowTime));
                // メッセージ
                watchNotify = new WatchNotify(owner);
                watchNotify.Rescale(motoRect);
            }
Exemplo n.º 12
0
        void DrawReminder(Canvas canvas, MotoRect rect)
        {
            DateTime now       = WatchfaceUtility.ConvertToDateTime(Calendar);
            int      totalMins = (int)NextFullMoon.Subtract(now).TotalMinutes;

            if (totalMins > 40 | totalMins < 0)
            {
                return;
            }

            reminderPath.Reset();

            //float startAngle = (45 - min) * 6;
            //float sweepAngle = min * 6;

            int nowMin  = now.Minute;
            int nextMin = NextFullMoon.Minute;

            float startAngle = 0f;
            float sweepAngle = 0f;

            if (nowMin < 15 & nextMin <= 15)
            {
                startAngle = 270f + nowMin * 6f;
                sweepAngle = (nextMin - nowMin) * 6f;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);
            }
            else if (nowMin < 15)
            {
                startAngle = 270f + nowMin * 6f;
                sweepAngle = 360f - startAngle;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);

                startAngle = 0f;
                sweepAngle = (nextMin - 15) * 6f;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);
            }
            else if (nextMin <= 15)
            {
                startAngle = (nowMin - 15) * 6f;
                sweepAngle = 270f - startAngle;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);

                startAngle = 270f;
                sweepAngle = nextMin * 6f;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);
            }
            else if (nextMin < nowMin)
            {
                startAngle = (nowMin - 15) * 6f;
                sweepAngle = 360f - startAngle;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);

                startAngle = 0f;
                sweepAngle = (nextMin - 15) * 6f;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);
            }
            else
            {
                startAngle = (nowMin - 15) * 6f;
                sweepAngle = (nextMin - nowMin) * 6f;

                reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);
            }

            //float startAngle = (nextMin * 6f) + 15f;
            //float sweepAngle = totalMins * 6;

            //reminderPath.AddArc(reminderRectF, startAngle, sweepAngle);

            canvas.DrawPath(reminderPath, reminderPaint);
        }
            /// <summary>
            ///		Invoked when a <see cref="MyWatchFaceEngine"/> object is created.
            /// </summary>
            /// <param name="holder">Object representing display surface</param>
            public override void OnCreate(ISurfaceHolder holder)
            {
                // TODO: Here, mainly perform the following processing.
                // * Loads images from resources
                // * Generates graphics objects such as Paint etc.
                // * Generates an object that stores time
                // * Sets the system UI (status icon, notification card and "Ok Google" etc.)

                // Sets the display method of the system UI.
                SetWatchFaceStyle(
                    new WatchFaceStyle.Builder(owner)
                    #region Setting watch face style

                    // Sets whether to enable tap event from user.
                    //   true  : Enabled
                    //   false : Disabled(default)
                    //.SetAcceptsTapEvents( true )

                    // Sets the height of the notification card when receiving the notification.
                    //   WatchFaceStyle.PeekModeShort    : Displays the notification card small at the bottom of the window.(default)
                    //   WatchFaceStyle.PeekModeVariable : Displays the notification card on the front of the window.
                    .SetCardPeekMode(WatchFaceStyle.PeekModeShort)

                    // Sets the display method of the notification card background.
                    //   WatchFaceStyle.BackgroundVisibilityInterruptive : Displays the notification card's background, only when some important notification such as incoming calls.(default)
                    //   WatchFaceStyle.BackgroundVisibilityPersistent   : Displays the notification card's background regardless of the notification type.
                    .SetBackgroundVisibility(WatchFaceStyle.BackgroundVisibilityInterruptive)

                    // Sets whether or not to display notification cards in ambient mode.
                    //   WatchFaceStyle.AmbientPeekModeVisible : Visible(default)
                    //   WatchFaceStyle.AmbientPeekModeHidden  : Hidden
                    //.SetAmbientPeekMode( WatchFaceStyle.AmbientPeekModeHidden )

                    // Sets whether to display the digital clock of the system UI. (As an example of use, there is "Simple" which is provided by default.)
                    //   true  : Visible
                    //   false : Hidden(default)
                    .SetShowSystemUiTime(false)

                    // Sets whether to add a background to the status icon etc.
                    //   Default                                : Nothing
                    //   WatchFaceStyle.ProtectStatusBar        : Displays the background on the status icon.
                    //   WatchFaceStyle.ProtectHotwordIndicator : Displays the background on the "OK Google".
                    //   WatchFaceStyle.ProtectWholeScreen      : Makes the background of the watch face a little darker.
                    // Note: Parameters can be combined by logical OR.
                    //.SetViewProtectionMode( WatchFaceStyle.ProtectStatusBar | WatchFaceStyle.ProtectHotwordIndicator )

                    // Sets whether the notification card is transparent.
                    //   WatchFaceStyle.PeekOpacityModeOpaque      : Opacity(default)
                    //   WatchFaceStyle.PeekOpacityModeTranslucent : Transparent
                    //.SetPeekOpacityMode( WatchFaceStyle.PeekOpacityModeTranslucent )

                    // Sets the status icon and "OK Google" position.
                    //   GravityFlags.Top | GravityFlags.Left   : Left-Top(Square form's default)
                    //   GravityFlags.Top | GravityFlags.Center : Center-Top(Round form's default)
                    // Note: Parameters can be combined by logical OR.
                    // Note: Casts GravityFlags's value to int type, because it is an enumeration.
                    //.SetStatusBarGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )
                    //.SetHotwordIndicatorGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )

                    #endregion
                    // Builds the set style information. This method is called last.
                    .Build()
                    );

                base.OnCreate(holder);

                #region About method that getting color values from resources in the latest Android SDK

                /*
                 *      Android.Content.Res.Resources.GetColor method is deprecated as Android SDK Level 23 or later.
                 *      As an alternative, use the Android.Support.V4.Content.ContextCompat.GetColor method.
                 *
                 *      [CanvasWatchFaceService object].Resources.GetColor( Resource.Color.[Resource name] );
                 *      ↓
                 *      ContextCompat.GetColor( [CanvasWatchFaceService object], Resource.Color.[Resource name] );
                 *
                 *      Note: CanvasWatchFaceService class inherits Context class.
                 *
                 *      However, the return value of ContextCompat.GetColor method, because it is not a color type
                 *      but an int type storing an ARGB value, cannot be directly set to [Paint object].Color.
                 *      -> Using the Chronoir_net.Chronica.WatchfaceExtension.WatchfaceUtility.ConvertARGBToColor( int ) method,
                 *         can convert the integer value storing the ARGB value to Color type.
                 */
                #endregion

                var resources = owner.Resources;

                // Creates a graphics object for the background.
                backgroundPaint = new Paint();
                // Reads background color from resource.
                backgroundPaint.Color = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.background));

                // Creates a graphics object for the hour hand.
                var hourHandPaint = new Paint();
                hourHandPaint.Color = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_hands));
                // Sets the hour hand width.
                hourHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.hour_hand_stroke);
                // Enable anti-aliasing.
                hourHandPaint.AntiAlias = true;
                // Specifies the shape of the line end in a round shape.
                hourHandPaint.StrokeCap = Paint.Cap.Round;
                // Creates the hour hand object.
                hourHand = new HourAnalogHandStroke(hourHandPaint);

                // Creates a graphics object for the minute hand.
                var minuteHandPaint = new Paint();
                minuteHandPaint.Color       = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_hands));
                minuteHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.minute_hand_stroke);
                minuteHandPaint.AntiAlias   = true;
                minuteHandPaint.StrokeCap   = Paint.Cap.Round;
                minuteHand = new MinuteAnalogHandStroke(minuteHandPaint);

                // Creates a graphics object for the second hand.
                var secondHandPaint = new Paint();
                secondHandPaint.Color       = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner, Resource.Color.analog_sec_hand));
                secondHandPaint.StrokeWidth = resources.GetDimension(Resource.Dimension.second_hand_stroke);
                secondHandPaint.AntiAlias   = true;
                secondHandPaint.StrokeCap   = Paint.Cap.Round;
                secondHand = new SecondAnalogHandStroke(secondHandPaint);

                // Creates an object that stores time.
                // Time ( Android )
                //nowTime = new Time();
                // Calendar ( Java )
                nowTime = Java.Util.Calendar.GetInstance(Java.Util.TimeZone.Default);
                // DateTime ( C# )
                // This object need not create, because DateTime structure is value type.
            }
Exemplo n.º 14
0
            /// <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

                bool isSizeChanged = bounds.Width() != width || bounds.Height() != height;

                if (isSizeChanged)
                {
                    width  = bounds.Width();
                    height = bounds.Height();

                    if (backgroundBitmap == null || backgroundBitmap.IsRecycled ||
                        backgroundBitmapForTick == null || backgroundBitmapForTick.IsRecycled ||
                        backgroundBitmapForDate == null || backgroundBitmapForDate.IsRecycled ||
                        backgroundBitmapForBattery == null || backgroundBitmapForBattery.IsRecycled ||
                        backgroundBitmapForBattCharge == null || backgroundBitmapForBattCharge.IsRecycled)
                    {
                        backgroundBitmap              = CreateScaledBitmapFromCanvas(Resource.Drawable.bangasaasagi, width, height);
                        backgroundBitmapForTick       = CreateScaledBitmapFromCanvas(Resource.Drawable.bangasatick, width, height);
                        backgroundBitmapForDate       = CreateScaledBitmapFromCanvas(Resource.Drawable.bangasadate, width, height);
                        backgroundBitmapForBattery    = CreateScaledBitmapFromCanvas(Resource.Drawable.bangasabatt, width, height);
                        backgroundBitmapForBattCharge = CreateScaledBitmapFromCanvas(Resource.Drawable.bangasabattcharge, width, height);
                    }

                    int longSize = Math.Max(canvas.Width, canvas.Height);
                    backgroundLeft = (width - longSize) / 2f;
                    backgroundTop  = (height - longSize) / 2f;
                    scale          = longSize / DisignedSize;
                    hourLeft       = 350f * scale + backgroundLeft;
                    hourTop        = 125f * scale + backgroundTop;
                    minuteLeft     = 350f * scale + backgroundLeft;
                    minuteTop      = backgroundTop;
                    secondLeft     = 350f * scale + backgroundLeft;
                    secondTop      = backgroundTop;
                    if (hourHand == null || hourHand.IsRecycled ||
                        minuteHand == null || minuteHand.IsRecycled ||
                        secondHand == null || secondHand.IsRecycled)
                    {
                        hourHand   = CreateScaledBitmapByScale(Resource.Drawable.bangasahourhand, scale);
                        minuteHand = CreateScaledBitmapByScale(Resource.Drawable.bangasaminhand, scale);
                        secondHand = CreateScaledBitmapByScale(Resource.Drawable.bangasasechand, scale);
                    }
                }

                // 中心のXY座標を求めます。
                float centerX = bounds.Width() / 2.0f;
                float centerY = bounds.Height() / 2.0f;

                canvas.DrawColor(Color.Black);

                canvas.DrawBitmap(backgroundBitmapForTick, 0, 0, null);
                if (!IsInAmbientMode)
                {
                    canvas.DrawBitmap(backgroundBitmap, 0, 0, null);
                    canvas.DrawBitmap(backgroundBitmapForBattery, 0, 0, null);
                    if (isCharging)
                    {
                        canvas.DrawBitmap(backgroundBitmapForBattCharge, 0, 0, null);
                    }
                }
                canvas.DrawBitmap(backgroundBitmapForDate, 0, 0, null);

                if (!IsInAmbientMode)
                {
                    canvas.DrawText(batteryValue, centerX / 2f - centerX / 8f, centerY + centerY / 120f, textPaintForBatt);
                }
                canvas.DrawText(nowTime.Day.ToString(), centerX * 3f / 2f + centerX / 8f, centerY + centerY / 40f, textPaintForDate);
                canvas.DrawText(nowTime.ToString("ddd"), centerX * 3f / 2f + centerX / 8f, centerY + centerY / 10f, textPaintForDayOfWeek);

                float secRot       = nowTime.Second / 30f * ( float )Math.PI;
                int   minutes      = nowTime.Minute;
                float minRot       = minutes / 30f * ( float )Math.PI;
                float hrRot        = ((nowTime.Hour + (minutes / 60f)) / 6f) * ( float )Math.PI;
                float hourRotate   = (nowTime.Hour + nowTime.Minute / 60f) * 30f;
                float minuteRotate = nowTime.Minute * 6f;
                float secondRotate = nowTime.Second * 6f;

                matrix.SetTranslate(hourLeft, hourTop);
                matrix.PostRotate(hourRotate, centerX, centerY);
                canvas.DrawBitmap(hourHand, matrix, bitmapPaint);

                matrix.SetTranslate(minuteLeft, minuteTop);
                matrix.PostRotate(minuteRotate, centerX, centerY);
                canvas.DrawBitmap(minuteHand, matrix, bitmapPaint);

                if (!IsInAmbientMode)
                {
                    matrix.SetTranslate(secondLeft, secondTop);
                    matrix.PostRotate(secondRotate, centerX, centerY);
                    canvas.DrawBitmap(secondHand, matrix, bitmapPaint);
                }
            }
Exemplo n.º 15
0
            /// <summary>
            ///		<see cref="MyWatchFaceEngine"/>のインスタンスが生成された時に実行します。
            /// </summary>
            /// <param name="holder">ディスプレイ表面を表すオブジェクト</param>
            public override void OnCreate(ISurfaceHolder holder)
            {
                // TODO : ここでは主に、以下の処理を行います。
                // ・リソースから画像の読み込み
                // ・Paintなどのグラフィックスオブジェクトを生成
                // ・時刻を格納するオブジェクトの作成
                // ・システムのUI(インジケーターやOK Googleの表示など)の設定

                // システムのUIの配置方法を設定します。
                SetWatchFaceStyle(
                    new WatchFaceStyle.Builder(owner)
                    #region ウォッチフェイスのスタイルの設定

                    // ユーザーからのタップイベントを有効にするかどうか設定します。
                    //   true  : 有効
                    //   false : 無効(デフォルト)
                    //.SetAcceptsTapEvents( true )

                    // 通知が来た時の通知カードの高さを設定します。
                    //   WatchFaceStyle.PeekModeShort    : 通知カードをウィンドウの下部に小さく表示します。(デフォルト)
                    //   WatchFaceStyle.PeekModeVariable : 通知カードをウィンドウの全面に表示します。
                    // 注: Android Wear 2.0では、この設定は使用されません。
                    .SetCardPeekMode(WatchFaceStyle.PeekModeShort)

                    // 通知カードの背景の表示方法を設定します。
                    //   WatchFaceStyle.BackgroundVisibilityInterruptive : 電話の着信など一部の通知のみ、背景を用事します。(デフォルト)
                    //   WatchFaceStyle.BackgroundVisibilityPersistent   : 通知カードの種類にかかわらず、その背景を常に表示します。
                    // 注: Android Wear 2.0では、この設定は使用されません。
                    .SetBackgroundVisibility(WatchFaceStyle.BackgroundVisibilityInterruptive)

                    // アンビエントモード時に通知カードを表示するかどうかを設定します。
                    //   WatchFaceStyle.AmbientPeekModeVisible : 通知カードを表示します。(デフォルト)
                    //   WatchFaceStyle.AmbientPeekModeHidden  : 通知カードを表示しません。
                    // 注: Android Wear 2.0では、この設定は使用されません。
                    //.SetAmbientPeekMode( WatchFaceStyle.AmbientPeekModeHidden )

                    // システムUIのデジタル時計を表示するするかどうかを設定します。(使用している例として、デフォルトで用意されている「シンプル」があります。)
                    //   true  : 表示
                    //   false : 非表示(デフォルト)
                    .SetShowSystemUiTime(false)

                    // ステータスアイコンなどに背景を付けるかどうかを設定します。
                    //   デフォルト                               : ステータスアイコンなどに背景を表示しません。
                    //   WatchFaceStyle.ProtectStatusBar        : ステータスアイコンに背景を表示します。
                    //   WatchFaceStyle.ProtectHotwordIndicator : 「OK Google」に背景を表示します。
                    //   WatchFaceStyle.ProtectWholeScreen      : ウォッチフェイスの背景を少し暗めにします。
                    // ※パラメーターは論理和で組み合わせることができます。
                    //.SetViewProtectionMode( WatchFaceStyle.ProtectStatusBar | WatchFaceStyle.ProtectHotwordIndicator )

                    // 通知カードを透明にするかどうかを設定します。
                    //   WatchFaceStyle.PeekOpacityModeOpaque      : 不透明(デフォルト)
                    //   WatchFaceStyle.PeekOpacityModeTranslucent : 透明
                    // 注: Android Wear 2.0では、この設定は使用されません。
                    //.SetPeekOpacityMode( WatchFaceStyle.PeekOpacityModeTranslucent )

                    // ステータスアイコンや「OK Google」の位置を設定します。
                    //   GravityFlags.Top | GravityFlags.Left   : 左上(角形のデフォルト)
                    //   GravityFlags.Top | GravityFlags.Center : 上部の中央(丸形のデフォルト)
                    // 注 : GravityFlagsは列挙体なので、int型にキャストします。
                    //.SetStatusBarGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )
                    //.SetHotwordIndicatorGravity( ( int )( GravityFlags.Top | GravityFlags.Center ) )

                    #endregion
                    // 設定したスタイル情報をビルドします。このメソッドは最後に呼び出します。
                    .Build()
                    );
                // ベースクラスのOnCreateメソッドを実行します。
                base.OnCreate(holder);

                #region 最新のAndroid SDKにおける、Android.Content.Res.Resources.GetColorメソッドについて

                /*
                 *      Android.Content.Res.Resources.GetColorメソッドは、Android SDK Level 23以降で非推奨(Deprecated)となっています。
                 *      代わりの方法として、Android.Support.V4.Content.ContextCompat.GetColorメソッドを使用します。
                 *
                 *      [CanvasWatchFaceServiceオブジェクト].Resources.GetColor( Resource.Color.[リソース名] );
                 *      ↓
                 *      ContextCompat.GetColor( [CanvasWatchFaceServiceオブジェクト], Resource.Color.[リソース名] );
                 *      ※CanvasWatchFaceServiceクラスはContextクラスを継承しています。
                 *
                 *      なお、ContextCompat.GetColorの戻り値はColor型でなく、ARGB値を格納したint型となります。
                 *      Chronoir_net.Chronica.WatchfaceExtension.WatchfaceUtility.ConvertARGBToColor( int )メソッドで、Color型に変換することができます。
                 */
                #endregion

                var resources = owner.Resources;

                // 日付、バッテリー残量のフォントを設定します。
                textPaintForDate = new Paint {
                    TextSize = TypedValue.ApplyDimension(
                        ComplexUnitType.Dip,
                        resources.GetDimension(Resource.Dimension.text_date_font),
                        owner.Resources.DisplayMetrics
                        ),
                    AntiAlias = true,
                    Color     = Color.White,
                    // 中央ぞろえ
                    TextAlign = Paint.Align.Center
                };
                textPaintForDayOfWeek = new Paint(textPaintForDate)
                {
                    TextSize = TypedValue.ApplyDimension(
                        ComplexUnitType.Dip,
                        resources.GetDimension(Resource.Dimension.text_day_of_week_font),
                        owner.Resources.DisplayMetrics
                        )
                };
                textPaintForBatt = new Paint(textPaintForDate)
                {
                    TextSize = TypedValue.ApplyDimension(
                        ComplexUnitType.Dip,
                        resources.GetDimension(Resource.Dimension.text_batt_font),
                        owner.Resources.DisplayMetrics
                        )
                };

                // 背景用のグラフィックスオブジェクトを生成します。
                bitmapPaint = new Paint {
                    Color        = WatchfaceUtility.ConvertARGBToColor(ContextCompat.GetColor(owner.BaseContext, Resource.Color.background)),
                    FilterBitmap = true
                };

                matrix = new Matrix();

                // 時刻を格納するオブジェクトを生成します。
                // Time ( Android )
                //nowTime = new Time();
                // Calendar ( Java )
                //nowTime = Java.Util.Calendar.GetInstance( Java.Util.TimeZone.Default );
                // DateTime ( C# )
                // DateTime構造体は値型なので、オブジェクトの生成はは不要です。
            }
Exemplo n.º 16
0
        public WatchHands(CanvasWatchFaceService owner)
        {
            var resources = owner.Resources;

            // 時針用のPaintグラフィックスオブジェクトを生成します。
            hourHandPaint = new Paint
            {
                // 時針の色を設定します
                Color =
                    WatchfaceUtility.ConvertARGBToColor(
                        ContextCompat.GetColor(owner, Resource.Color.analog_hands)),
                // 時針の幅を設定します。
                StrokeWidth = resources.GetDimension(Resource.Dimension.hour_hand_stroke),
                // アンチエイリアスを有効にします。
                AntiAlias = true,
                // 線端の形は丸形を指定します。
                StrokeCap = Paint.Cap.Round
            };

            // 時針の縁を準備します
            hourHandBackPaint = new Paint
            {
                Color       = Color.Black,
                StrokeWidth = hourHandPaint.StrokeWidth + 3,
                AntiAlias   = hourHandPaint.AntiAlias,
                StrokeCap   = hourHandPaint.StrokeCap
            };

            // 分針用のPaintグラフィックスオブジェクトを生成します。
            minuteHandPaint = new Paint
            {
                Color       = hourHandPaint.Color,
                StrokeWidth = resources.GetDimension(Resource.Dimension.minute_hand_stroke),
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Round
            };

            // 分針の縁を準備します
            minuteHandBackPaint = new Paint
            {
                Color       = hourHandBackPaint.Color,
                StrokeWidth = minuteHandPaint.StrokeWidth + 3,
                AntiAlias   = minuteHandPaint.AntiAlias,
                StrokeCap   = minuteHandPaint.StrokeCap
            };

            // 秒針用のPaintグラフィックスオブジェクトを生成します。
            secondHandPaint = new Paint
            {
                Color =
                    WatchfaceUtility.ConvertARGBToColor(
                        ContextCompat.GetColor(owner, Resource.Color.analog_second_hand)),
                StrokeWidth = resources.GetDimension(Resource.Dimension.second_hand_stroke),
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Round
            };

            // 秒針の縁を準備します
            secondHandBackPaint = new Paint
            {
                Color       = Color.Black,
                StrokeWidth = secondHandPaint.StrokeWidth + 2,
                AntiAlias   = secondHandPaint.AntiAlias,
                StrokeCap   = secondHandPaint.StrokeCap
            };
        }