AGENT Smartwatch All In One Apps Using C#


Kindly view my Youtube Video to learn AGENT Smartwatch App development using C#.

In this article we will see how to create a simple App for AGENT Smartwatch. I have selected AGENT Smart since it will support both Windows, Android and iOS mobiles and also SDK for AGENT Smartwatch was based on .NET Micro Framework. .Net Micro Framework can be used to develop embedded device applications. For more details regarding the AGENT Smartwatch check their official website http://www.agentwatches.com/ .

Prerequisites: Download athe following prerequisites and install it in your computer.

  1. Visual Studio 2015 - You can download it from

    https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs .

  2. .Net Micro frame work SDK 4.3 for VS2015 project

    https://visualstudiogallery.msdn.microsoft.com/d90dcb48-d566-4bab-8ef1-0c7927758f9e

  3. AGENT SDK

    http://www.agentwatches.com/downloads/agentsdk.exe

  4. Tiny Font Tool GUI

    http://informatix.miloush.net/microframework/Utilities/TinyFontTool.aspx

In this article we will see how to:

  1. Create and run our first AGENT Smartwatch Application.

  2. Create a Simple AGENT Smartwatch to add our custom fonts, Add Images, Draw Text and Image.

  3. Create my All in One App for AGENT Smart watch.

What is Shanu All in One App for AGENT Smart Watch?

Smartwatch makes our life more easy and comfortable. If you ask me a question, since we already have Smartphones so why we need Smartwatches, my answer would be: it’s important to use smartwatch as well smartphones in today’s busy world. For example, let’s consider we are in a meeting and at the same time we are getting some calls continously. We couldn’t check who’s calling at the moment. If suppose their is animportant and urgent call then we will be missing it by without seeing who’s calling. If consider we are using the Smartwatch, then without disturbing the meeting we can check who’s calling and if it’s an important call then we can attend it.

To make things more easy and convenient I have made All in One App using AGENT Smart watch. In my All in One App for Smartwatch I have 5 different functionalities and they are the following:

  1. Simple Text Animation.



  2. Display Date and Time.



  3. Display Today's Appointment.



  4. Display Animation for simple game.



  5. Stopwatch.


Code Part

  1. Create and run our first AGENT Smartwatch Application.

    Kindly download and install all the prerequisites need to create our first AGENT Smartwatch application using c#. After you have installed all the above prerequisites.

    Click Start, Programs, then select Visual Studio 2015- Click Visual Studio 2015

    Click New, Project, select Micro Framework from template and click Windows Application. Select your project folder and give proper name for your project. After that click Ok



    Once we have created our AGENT Smartwatch Application. We can see in Solution explorer it will contain program.cs and Resources.resx. The program.cs class file is the main file where we write all our coding to create our Apps. The program.cs will have the Main method from where the program will start executing. The Resources.resx is used to add resources like Image, Tiny Font, String, etc.


    Default Target Frame work

    The default target language will be .NET Micro Framework 4.3. When we right click our project and click on properties we can see THAT the target framework will be selected as .NET Micro Framework 4.3.
      
    Default Deployment

    Default deployment device will be selected as AGENT Emulator. When we run the program we can see the output in the AGENT Emulator.



    Program.cs

    I will recommend the following website that is a very good place for any beginner to write code with AGENT Smartwatch using C#  which was written by Matt from RougrCode.

    By default when we create the program, Program.cs will contain some set of code to display the output as “Hello World”. The Program.cs will add default Header files to run the program. Here we can see the set of default header files added.

    .Net Micro Framework will have very limited functionality than our .NET framework. So we cannot use all reference which we were using in our normal .NET framework.
    1. using System;  
    2. using Microsoft.SPOT;  
    3. using Microsoft.SPOT.Input;  
    4. using Microsoft.SPOT.Presentation;  
    5. using Microsoft.SPOT.Presentation.Controls;  
    Main Method:

    By default when we create a main method it will create a window to display the default “hello world” text:
    1. public static void Main()  
    2.         {  
    3.             Program myApplication = new Program();  
    4.   
    5.             Window mainWindow = myApplication.CreateWindow();  
    6.   
    7.             // Create the object that configures the GPIO pins to buttons.  
    8.             GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);  
    9.   
    10.             // Start the application  
    11.             myApplication.Run(mainWindow);  
    12.         }  
    In Createwindow method the default code will be added to add the Text to the window and loading the text content from the resource file. Note to see our resource string we can double click on “Resources.resx” file from the Solution Explorer. If we want we can add more string or we can change the Hello World text as we like to display different text.


    1. private Window mainWindow;  
    2.   
    3.         public Window CreateWindow()  
    4.         {  
    5.             // Create a window object and set its size to the  
    6.             // size of the display.  
    7.             mainWindow = new Window();  
    8.             mainWindow.Height = SystemMetrics.ScreenHeight;  
    9.             mainWindow.Width = SystemMetrics.ScreenWidth;  
    10.   
    11.             // Create a single text control.  
    12.             Text text = new Text();  
    13.   
    14.             text.Font = Resources.GetFont(Resources.FontResources.small);  
    15.             text.TextContent = Resources.GetString(Resources.StringResources.String1);  
    16.             text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;  
    17.             text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center;  
    18.   
    19.             // Add the text control to the window.  
    20.             mainWindow.Child = text;  
    21.   
    22.             // Connect the button handler to all of the buttons.  
    23.             mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);  
    24.   
    25.             // Set the window visibility to visible.  
    26.             mainWindow.Visibility = Visibility.Visible;  
    27.   
    28.             // Attach the button focus to the window.  
    29.             Buttons.Focus(mainWindow);  
    30.   
    31.             return mainWindow;  
    32.         }  
    Here we can see in this method after creating the main window the eventhandler will be added for the AGENT Smartwatch button click events.

    OnButtonUp Event

    This event will be raised whenever the user clicks on the buttons of the AGENT Smart watch. The AGENT Smart watch will contain 5 buttons, 3 buttons at the right and 2 buttons at the left.
    1. private void OnButtonUp(object sender, RoutedEventArgs evt)  
    2.         {  
    3.             ButtonEventArgs e = (ButtonEventArgs)evt;  
    4.   
    5.             // Print the button code to the Visual Studio output window.  
    6.             Debug.Print(e.Button.ToString());  
    7.         }  
    Run and Test our first program:

    Without writing any code we can run our first AGENT Smartwatch application to display the “Hello World” text display.



    So we are succeeded in creating our first AGENT Smart watch Application and testing it.

  2. Create a Simple AGENT Smartwatch to add our custom fonts, Add Images, Draw Text and Image.

    Follow all the above steps to create your AGENT Smartwatch application.

    We already saw that when we create our AGENT Smartwatch application it will add the default code to create a Window and display the “Hello world” text.

    Now let’s see how to Draw Text, Add Image and add Tiny font to display different font text in our AGENT Smartwatch.

    By default we will have the following header files:
    1. using System;  
    2. using Microsoft.SPOT;  
    3. using Microsoft.SPOT.Input;  
    4. using Microsoft.SPOT.Presentation;  
    5. using Microsoft.SPOT.Presentation.Controls;  
    I will be adding few more reference to the project to draw text and Image, to add colors and for using Thread
    1. using Microsoft.SPOT.Presentation.Media;  
    2. using System.Threading;  
    Next will delete all the code part except the main method. Here instead of creating the new Window I will be drawing text and Image from main method.

    So now my program.cs file will be as in the following code snippet:
    1. using System.Diagnostics;  
    2. using Microsoft.SPOT;  
    3. using Microsoft.SPOT.Presentation;  
    4. using Microsoft.SPOT.Presentation.Media;  
    5. using System.Threading;  
    6. using Microsoft.SPOT.Input;  
    7. using Microsoft.SPOT.Presentation.Controls;  
    8.   
    9. namespace test  
    10. {  
    11.     public class Program : Microsoft.SPOT.Application  
    12.     {  
    13.         public static void Main()  
    14.         {  
    15.               
    16.         }  
    17.     }  
    18. }  
    Here first we will create object for bitmap to drawtext.
    1. static Bitmap _myFace;  
    Inside the main method we will draw text to display our content. Here we can see first I will create the bitmap Image with maxwidth and max height .

    We will be adding font from the resource file. Default small font will be added in our resource file.



    Here I have used the default font to display the text. Using the DrawText I will draw the text in desired location which I have given. The Thread.Sleep() was been used to display the text continuously.
    1. public class Program : Microsoft.SPOT.Application  
    2.     {  
    3.         static Bitmap _myFace;  
    4.         public static void Main()  
    5.         {  
    6.             _myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);  
    7.             _myFace.Clear();  
    8.             Font fontS = Resources.GetFont(Resources.FontResources.small);  
    9.             _myFace.DrawText("SHANU", fontS, Color.White, 12, 10);  
    10.   
    11.             _myFace.Flush();  
    12.             Thread.Sleep(Timeout.Infinite);  
    13.   
    14.         }  
    15.     }  
    When we run the program we can see the output as in the following screenshot:



    Adding custom Fonts:

    By default we will be having only one font in our application. We can also add our Custom fonts to our application from resource. Note we need to add only tiny font. To convert our normal font to Tiny font, their is a free tool available from this link http://informatix.miloush.net/microframework/Utilities/TinyFontTool.aspx you can download and change any available fonts to Tiny font. Save the font to your folder and add the Tiny font to your resource file.



    I have converted the Tahoma Font as tiny font and saved in my folder. Now let’s see how to add the tiny font in our application.

    To add the Custom converted font double click on our resource file and click Add Existing File. Select your newly converted Tahoma Tiny Font. Click save for saving the changes.



    In your main method code create new object for font to add your new font and draw the text.
    1. public static void Main()  
    2.         {  
    3.             _myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);  
    4.             _myFace.Clear();  
    5.             Font fontS = Resources.GetFont(Resources.FontResources.small);  
    6.             _myFace.DrawText("SHANU", fontS, Color.White, 12, 10);  
    7.   
    8.             Font font = Resources.GetFont(Resources.FontResources.ThahomaFont);  
    9.             _myFace.DrawText("SHANU", font, Color.White, 12, 26);  
    10.   
    11.   
    12.             _myFace.Flush();  
    13.             Thread.Sleep(Timeout.Infinite);  
    14.   
    15.         }  
    When we run the program we can see the output as in the following screenshot:



    Adding Image and Draw Image:

    To add image double click on our resource file and click Add Existing File. Select your Image file and save it. I will be adding only GIF and JPEG images.



    In your main method code create new object for font to add your new font and draw the text. Firstly, I will create the bitmap image from the Resource file and using the Draw Image I will draw the image to the desired location. Note the last 4 points are used to crop the image and display.
    1. public class Program : Microsoft.SPOT.Application  
    2.     {  
    3.         static Bitmap _myFace;  
    4.         public static void Main()  
    5.         {  
    6.             _myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);  
    7.             _myFace.Clear();  
    8.             Font fontS = Resources.GetFont(Resources.FontResources.small);  
    9.             _myFace.DrawText("SHANU", fontS, Color.White, 12, 10);  
    10.   
    11.             Font font = Resources.GetFont(Resources.FontResources.ThahomaFont);  
    12.             _myFace.DrawText("SHANU", font, Color.White, 12, 26);  
    13.   
    14.             Bitmap myImage = new Bitmap(Resources.GetBytes(Resources.BinaryResources.shanu), Bitmap.BitmapImageType.Jpeg);  
    15.   
    16.             _myFace.DrawImage(40, 40, myImage, 0, 0, 128, 128);  
    17.   
    18.             _myFace.Flush();  
    19.             Thread.Sleep(Timeout.Infinite);  
    20.   
    21.         }  
    22.     }  
      On running the program we can see the output as in the following screenshot:



    Hope now you have more clear idea of how to develop a simple App for AGENT Smartwatch. Next we will see in detail how I have created my All in one App.

  3. How to create my All in One App for AGENT Smartwatch.

    As I have already explained in my All in One App I have created 5 different functionality in one App. They are

    • Simple Text Animation.
    • Display Date and Time.
    • Display Todays Appointment.
    • Display Animation for simple Game.
    • Stopwatch.

    We will see one by one in detail on how to create using AGENT Smartwatch application development.

    Create new project as mentioned above and I will be using the default created main window to display my name by default and on button click events I will perform all the 5 different functionalities.

    Add all header files.
    1. using System;  
    2. using System.Diagnostics;  
    3. using Microsoft.SPOT;  
    4. using Microsoft.SPOT.Presentation;  
    5. using Microsoft.SPOT.Presentation.Media;  
    6. using System.Threading;  
    7. using Microsoft.SPOT.Input;  
    8. using Microsoft.SPOT.Presentation.Controls;  
    Declare all the local variables. I will be using this variable to perform 5 different functionalities.
    1. //Main bitmap to draw all text   
    2.         static Bitmap _myFace;  
    3.         const int HEIGHT = 128;  
    4.         const int WIDTH = 128;  
    5.         static int _ButtonClickNumber = 0;  
    6.         static Timer _TiimeDispTimer;  
    7.   
    8.         //To display text Animation  
    9.         static int name1Xval = 2;  
    10.         static int name1Yval = 20;  
    11.   
    12.         static int name2Xval = Bitmap.MaxWidth;  
    13.         static int name2Yval = 70;  
    14.   
    15.         static int name3Xval = 10;  
    16.         static int name3Yval = Bitmap.MaxHeight - 10;  
    17.   
    18.   
    19.   
    20.         //Ball Draw  
    21.         static int ballXval = 50;  
    22.         static int ballYval = 90;  
    23.   
    24.         //Man Draw  
    25.         static int manfaceXval = 10;  
    26.         static int manfaceYval = 40;  
    27.   
    28.         static int leg1Xval = manfaceXval + 1;  
    29.         static int leg1Yval = manfaceYval + 30;  
    30.         static int leg1X1val = manfaceXval - 4;  
    31.         static int leg1Y1val = manfaceYval + 54;  
    32.   
    33.         static int leg2Xval = manfaceXval + 1;  
    34.         static int leg2Yval = manfaceYval + 30;  
    35.         static int leg2X1val = manfaceXval + 4;  
    36.         static int leg2Y1val = manfaceYval + 54;  
    37.   
    38.         static int goalXVal = 60;  
    39.         static int goalYVal = 8;  
    40.   
    41.         Boolean cicked = false;  
    42.         Boolean goals = false;  
    43.   
    44.         //For StopWatch  
    45.   
    46.         static int secounds = 0;  
    47.         static int Miniutes = 0;  
    48.         string secounds_str = "00";  
    49.         string Miniutes_str = "00";  
    In main method we call the CreateWindow() method to create the main window and display default text as output.
    1. public static void Main()  
    2.         {  
    3.             Program myApplication = new Program();  
    4.             _myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);  
    5.             Window mainWindow = myApplication.CreateWindow();  
    6.   
    7.             // Create the object that configures the GPIO pins to buttons.  
    8.             GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);  
    9.   
    10.             // Start the application  
    11.             myApplication.Run(mainWindow);  
    12.         }  
    13.   
    14.         private Window mainWindow;  
    In createwindow method I will create a new window and add the default text to display.
    Create new Timer with timer event to run every one second. Next create a handler to perform the AGENT Smartwatch button up events.
    1. public Window CreateWindow()  
    2.         {  
    3.             // Create a window object and set its size to the  
    4.             // size of the display.  
    5.             mainWindow = new Window();  
    6.             mainWindow.Height = SystemMetrics.ScreenHeight;  
    7.             mainWindow.Width = SystemMetrics.ScreenWidth;  
    8.   
    9.             // Create a single text control.  
    10.             Text text = new Text();  
    11.   
    12.             text.Font = Resources.GetFont(Resources.FontResources.small);  
    13.             text.TextContent = Resources.GetString(Resources.StringResources.Name1);  
    14.             text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;  
    15.             text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center;  
    16.   
    17.             // Add the text control to the window.  
    18.             mainWindow.Child = text;  
    19.   
    20.             // Connect the button handler to all of the buttons.  
    21.             mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);  
    22.   
    23.             // Set the window visibility to visible.  
    24.             mainWindow.Visibility = Visibility.Visible;  
    25.   
    26.   
    27.             TimeSpan startTime = new TimeSpan(0, 0, 0, 0, DateTime.Now.Millisecond); // start aftera Second  
    28.             TimeSpan SecondsAdd = new TimeSpan(0, 0, 0, 1, 0); // Add Secounds for Update  
    29.             _TiimeDispTimer = new Timer(UpdateTime, null, startTime, SecondsAdd); // start  Timer to Display Time  
    30.   
    31.   
    32.                                                                                   // Attach the button focus to the window.  
    33.             Buttons.Focus(mainWindow);  
    34.   
    35.             return mainWindow;  
    36.         }  
    ButtonUp Event

    As I have explained AGENT Smartwatch will contain 5 buttons .3 buttons at right and 2 buttons at left and each button will contain unique Number.

    • Right Top Watch Button – 38
    • Right Middle Watch Button – 41
    • Right Bottom Watch Button – 40
    • Left Top Watch Button – 37
    • Left Top Watch Button – 39

    In this event I will check for each button up unique number and call the desired function.
    1. private void OnButtonUp(object sender, RoutedEventArgs evt)  
    2.         {  
    3.             ButtonEventArgs e = (ButtonEventArgs)evt;  
    4.   
    5.             // Print the button code to the Visual Studio output window.  
    6.             Debug.Print(e.Button.ToString());  
    7.             if (e.Button.ToString() == "38"//Right Top Watch Button  -> To Display Names  
    8.             {  
    9.                 _ButtonClickNumber = 38;  
    10.   
    11.             }  
    12.             else if (e.Button.ToString() == "41"// right Middle Watch Button -> To Display Time  
    13.             {  
    14.                 name1Xval = 6;  
    15.                 name2Xval = Bitmap.MaxWidth - 6;  
    16.                 name3Yval = Bitmap.MaxHeight - 10;  
    17.                 _ButtonClickNumber = 41;  
    18.                 showTime();  
    19.   
    20.             }  
    21.             else if (e.Button.ToString() == "40"// Right Bottom Watch Button -> To Display  Appointment  
    22.             {  
    23.                 _ButtonClickNumber = 40;  
    24.                 showAppointment();  
    25.   
    26.             }  
    27.             else if (e.Button.ToString() == "37"// Left Top Watch Button -> To Display  Animation  
    28.             {  
    29.                 _ButtonClickNumber = 37;  
    30.   
    31.                 // To Start New Animation  
    32.                 cicked = false;  
    33.                 goals = false;  
    34.                 ballXval = 50;  
    35.                 ballYval = 90;  
    36.   
    37.                 //Man Draw  
    38.                 manfaceXval = 10;  
    39.                 manfaceYval = 40;  
    40.   
    41.                 leg1Xval = manfaceXval + 1;  
    42.                 leg1Yval = manfaceYval + 30;  
    43.                 leg1X1val = manfaceXval - 4;  
    44.                 leg1Y1val = manfaceYval + 54;  
    45.   
    46.                 leg2Xval = manfaceXval + 1;  
    47.                 leg2Yval = manfaceYval + 30;  
    48.                 leg2X1val = manfaceXval + 4;  
    49.                 leg2Y1val = manfaceYval + 54;  
    50.   
    51.                 showAnimation();  
    52.             }  
    53.             else if (e.Button.ToString() == "39"// Left Bottom Watch Button -> To Display    
    54.             {  
    55.                 _ButtonClickNumber = 39;  
    56.                   secounds = 0;  
    57.                   Miniutes = 0;  
    58.                  secounds_str = "00";  
    59.                  Miniutes_str = "00";  
    60.                 spotWatch();  
    61.             }  
    62.         }  
    In my program I will be displaying Time, Text Animation and  simple football game animation using Timer. In timer event I will check for each button up number and call the function.
    1. public void UpdateTime(object state)  
    2.         {  
    3.             if (_ButtonClickNumber == 41)  
    4.             {  
    5.                 showTime();  
    6.             }  
    7.             else if (_ButtonClickNumber == 38)  
    8.             {  
    9.                 showName();  
    10.             }  
    11.             else if(_ButtonClickNumber == 37)  
    12.             {  
    13.                 showAnimation();  
    14.             }  
    15.             else if(_ButtonClickNumber == 39)  
    16.             {  
    17.                 spotWatch();  
    18.             }  
    19.   
    20.         } 
    showName() In this method I will be displaying simple text animation.



    In this method I will be displaying simple text animation. Also, I will display the text using DrawText method and using timer I will move the text from left to right, right to left and from bottom to top.
    1. public void showName()  
    2.         {  
    3.   
    4.             _myFace.Clear();  
    5.             Font font = Resources.GetFont(Resources.FontResources.shanuName);  
    6.             _myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth, Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    7.   
    8.             _myFace.DrawText(Resources.GetString(Resources.StringResources.Name1), font, Color.White, name1Xval, name1Yval);  
    9.   
    10.             if(name1Xval<= Bitmap.MaxWidth)  
    11.             {  
    12.                 name1Xval = name1Xval + 4;  
    13.             }  
    14.             else  
    15.             {  
    16.                 name1Xval = 6;  
    17.             }  
    18.   
    19.             _myFace.DrawText(Resources.GetString(Resources.StringResources.Name2), font, Color.White, name2Xval, name2Yval);  
    20.   
    21.             if (name2Xval >= 0)  
    22.             {  
    23.                 name2Xval = name2Xval - 4;  
    24.             }  
    25.             else  
    26.             {  
    27.                 name2Xval = Bitmap.MaxWidth - 6;  
    28.             }  
    29.   
    30.             _myFace.DrawText(Resources.GetString(Resources.StringResources.Name3), font, Color.White, name3Xval, name3Yval);  
    31.   
    32.             if (name3Yval >= 0)  
    33.             {  
    34.                 name3Yval = name3Yval - 4;  
    35.             }  
    36.             else  
    37.             {  
    38.                 name3Yval = Bitmap.MaxHeight-10;  
    39.             }  
    40.   
    41.             _myFace.Flush();  
    42.         }  
    showTime()

    In this method I will be displaying Date and Time.



    In this method I will be displaying today's Date and Time. Here we can see I have added two different custom fonts to display the date and time.
    1. public void showTime()  
    2.         {             
    3.             _myFace.Clear();  
    4.             Font font = Resources.GetFont(Resources.FontResources.shanuNumber);  
    5.             Font fontS = Resources.GetFont(Resources.FontResources.shanuName);  
    6.   
    7.             _myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth, Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    8.   
    9.             _myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"), fontS, Color.White, 4, 20);  
    10.             _myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"), fontS, Color.Black, 4, 21);  
    11.             _myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"), fontS, Color.White, 4, 22);  
    12.   
    13.             _myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"), font, Color.White, 2, 70);  
    14.             _myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"), font, Color.Black, 2, 71);  
    15.             _myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"), font, Color.White, 2, 72);  
    16.             _myFace.Flush();  
    17.   
    18.         }  
    showAppointment() In this method I will display today's Plan Schedule for the user.



    In this method I will be displaying today's Appointment for the user. Firstly, I will add today's plan list in the Resource string like the following screenshot:



    The method from this resource file will display today's plan one by one using DrawText method. I will also check for the current time with Appointment time. If current time is equal to Appointment time,, then I will draw rectangle bar and line under text as to alert user to indicate the user as its time to perform the current plan.
    1. public void showAppointment()  
    2.         {  
    3.   
    4.             _myFace.Clear();  
    5.             Font fontB = Resources.GetFont(Resources.FontResources.NinaB);  
    6.             Font fonts = Resources.GetFont(Resources.FontResources.small);  
    7.             _myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth, Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    8.             _myFace.DrawText(" Today's Plan", fontB, Color.White, 6, 6);  
    9.             //_myFace.DrawText("Todays Plan ", fontB, Color.White, 40, 6);  
    10.             _myFace.DrawLine(Color.White, 1, 6, 27, 120, 27);  
    11.   
    12.             // to get the Current Hour   
    13.             string hours = "12";  
    14.             hours = (DateTime.Now.Hour % 12).ToString();  
    15.   
    16.             //To display First Appointment  
    17.             string apt1 = Resources.GetString(Resources.StringResources.Appointment1);  
    18.             string[] apt1Chk = apt1.Split(' ');  
    19.             if(apt1Chk[0]== hours)  
    20.                 {  
    21.                 _myFace.DrawRectangle(Color.White,2, 4, 36, 4, 4, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    22.                 _myFace.DrawLine(Color.White, 1, 20, 48, 70, 48);  
    23.   
    24.             }  
    25.             _myFace.DrawText(apt1, fonts, Color.White, 14, 34);  
    26.   
    27.   
    28.             //To display Second Appointment  
    29.             string apt2 = Resources.GetString(Resources.StringResources.Appointment2);  
    30.             string[] apt2Chk = apt2.Split(' ');  
    31.               
    32.   
    33.   
    34.             if (apt2Chk[0] == hours)  
    35.             {  
    36.                 _myFace.DrawRectangle(Color.White, 2, 4, 56, 4, 4, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    37.                 _myFace.DrawLine(Color.White, 1, 20, 64, 70, 64);  
    38.             }  
    39.   
    40.             _myFace.DrawText(apt2, fonts, Color.White, 14, 52);  
    41.   
    42.             //To display Third Appointment  
    43.             string apt3 = Resources.GetString(Resources.StringResources.Appointment3);  
    44.             string[] apt3Chk = apt3.Split(' ');  
    45.   
    46.   
    47.   
    48.             if (apt3Chk[0] == hours)  
    49.             {  
    50.                 _myFace.DrawRectangle(Color.White, 2, 4, 74, 4, 4, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    51.                 _myFace.DrawLine(Color.White, 1, 20, 82, 70, 82);  
    52.   
    53.             }  
    54.             _myFace.DrawText(apt3, fonts, Color.White, 14, 70);  
    55.   
    56.             //To display Fourth Appointment  
    57.             string apt4 = Resources.GetString(Resources.StringResources.Appointment4);  
    58.             string[] apt4Chk = apt4.Split(' ');  
    59.   
    60.   
    61.   
    62.             if (apt4Chk[0] == hours)  
    63.             {  
    64.                 _myFace.DrawRectangle(Color.White, 2, 4, 92, 4, 4, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    65.                 _myFace.DrawLine(Color.White, 1, 20, 102, 70, 102);  
    66.   
    67.             }  
    68.             _myFace.DrawText(apt4, fonts, Color.White, 14, 88);  
    69.   
    70.   
    71.             //To display Fifth Appointment  
    72.             string apt5 = Resources.GetString(Resources.StringResources.Appointment5);  
    73.             string[] apt5Chk = apt5.Split(' ');  
    74.   
    75.   
    76.   
    77.             if (apt5Chk[0] == hours)  
    78.             {  
    79.                 _myFace.DrawRectangle(Color.White, 2, 4, 112, 4, 4, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    80.                 _myFace.DrawLine(Color.White, 1, 20, 122, 70, 122);  
    81.   
    82.             }  
    83.             _myFace.DrawText(apt5, fonts, Color.White, 14, 108);  
    84.             _myFace.Flush();  
    85.         }  
    showAnimation()

    In this method I will be showing simple football game animation to the user.



    In this method I will be drawing simple graphics to display simple animation to draw a player moving from left to right till he reaches the Football and when he reach the ball he kicks the ball and stand in the same place. The ball will be moving slowly and reach the Goal Post. Once the ball reach the goal post I will display the text as Goal. This will be happening as routine.
    1. public void showAnimation()  
    2.         {   
    3.             _myFace.Clear();  
    4.             Font font = Resources.GetFont(Resources.FontResources.shanuNumber);  
    5.         _myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth, Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    6.   
    7.   
    8.             // Goal Point  
    9.             _myFace.DrawRectangle(Color.White, 1, goalXVal, 0, goalXVal, goalYVal, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    10.   
    11.   
    12.             // ball Draw  
    13.             _myFace.DrawEllipse(Color.White, 6, ballXval, ballYval, 2, 2, Color.White, 0, 0, Color.White, 0, 0, 0);       
    14.   
    15.             _myFace.DrawEllipse(Color.White, manfaceXval, manfaceYval, 6, 6); //Face  
    16.             _myFace.DrawLine(Color.White, 1, manfaceXval , manfaceYval +6,  manfaceXval , manfaceYval+30); // Body  
    17.   
    18.             _myFace.DrawLine(Color.White, 1, manfaceXval + 1, manfaceYval + 16, manfaceXval - 4, manfaceYval + 22); //Hand 1  
    19.             _myFace.DrawLine(Color.White, 1, manfaceXval + 1, manfaceYval + 20, manfaceXval + 4, manfaceYval + 22); //Hand 2  
    20.   
    21.   
    22.             _myFace.DrawLine(Color.White, 1, leg1Xval, leg1Yval, leg1X1val, leg1Y1val); //leg 1  
    23.             _myFace.DrawLine(Color.White, 1, leg2Xval, leg2Yval, leg2X1val, leg2Y1val); //leg 2  
    24.   
    25.             if (manfaceXval <= ballXval - 14)  
    26.             {  
    27.                 if(cicked==false)  
    28.                 {   
    29.                 manfaceXval = manfaceXval + 8;  
    30.                 leg1Xval = leg1Xval + 8;  
    31.                 leg1X1val = leg1X1val + 8;  
    32.                 leg2Xval = leg2Xval + 8;  
    33.   
    34.                 leg2X1val = leg2X1val + 8;  
    35.                 }  
    36.             }  
    37.   
    38.       
    39.             if (manfaceXval >= ballXval - 14)  
    40.             {  
    41.                 cicked = true;  
    42.             }  
    43.             if(cicked==true)  
    44.             {  
    45.                 if(ballYval>= goalYVal)  
    46.                 {   
    47.                 ballXval = ballXval + 8;  
    48.                 ballYval = ballYval - 12;  
    49.                 }  
    50.                 else  
    51.                 {  
    52.                     goals = true;  
    53.                       
    54.                 }  
    55.             }  
    56.                 if(goals==true)  
    57.             {  
    58.   
    59.                 _myFace.DrawText("Goal", font, Color.White, 40, 80);  
    60.   
    61.                 ival = ival + 1;  
    62.                 if(ival>2)  
    63.                 {  
    64.                     cicked = false;  
    65.                     goals = false;  
    66.                     ballXval = 50;  
    67.                     ballYval = 90;  
    68.   
    69.                     //Man Draw  
    70.                     manfaceXval = 10;  
    71.                     manfaceYval = 40;  
    72.   
    73.                     leg1Xval = manfaceXval + 1;  
    74.                     leg1Yval = manfaceYval + 30;  
    75.                     leg1X1val = manfaceXval - 4;  
    76.                     leg1Y1val = manfaceYval + 54;  
    77.   
    78.                     leg2Xval = manfaceXval + 1;  
    79.                     leg2Yval = manfaceYval + 30;  
    80.                     leg2X1val = manfaceXval + 4;  
    81.                     leg2Y1val = manfaceYval + 54;  
    82.                 }  
    83.             }  
    84.   
    85.             _myFace.Flush();  
    86.         }  
    spotWatch() In this method I will be showing simple stopwatch.



    In this method I will be displaying simple Stopwatch with simple text animation. In this stopwatch I will be displaying the counter value as Seconds and Minute.
    1. public void spotWatch()  
    2.         {  
    3.             _myFace.Clear();  
    4.             Font font = Resources.GetFont(Resources.FontResources.shanuNumber);  
    5.             Font fontS = Resources.GetFont(Resources.FontResources.shanuName);  
    6.   
    7.             _myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth, Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);  
    8.   
    9.             Font fonts = Resources.GetFont(Resources.FontResources.small);  
    10.   
    11.             _myFace.DrawText("StopWatch", fontS, Color.White, 14, 6);  
    12.             _myFace.DrawLine(Color.White, 1,6, 24, 120, 24);  
    13.   
    14.             _myFace.DrawText(Miniutes_str + " : " + secounds_str, font, Color.White, 12, 38);  
    15.             _myFace.DrawText(Miniutes_str + " : " + secounds_str, font, Color.White, 12, 39);  
    16.             _myFace.DrawText(Miniutes_str + " : " + secounds_str, font, Color.White, 12, 40);  
    17.   
    18.   
    19.             _myFace.DrawLine(Color.White, 1, 6, 80, 120, 80);  
    20.   
    21.             _myFace.DrawText(Resources.GetString(Resources.StringResources.Name1), fontS, Color.White, name1Xval-30, 92);  
    22.   
    23.             if (name1Xval <= Bitmap.MaxWidth)  
    24.             {  
    25.                 name1Xval = name1Xval + 16;  
    26.             }  
    27.             else  
    28.             {  
    29.                 name1Xval = 6;  
    30.             }  
    31.   
    32.             _myFace.Flush();  
    33.             if(secounds <= 59)  
    34.             {  
    35.                 secounds = secounds + 1;  
    36.                 if (secounds<=9)  
    37.                 {  
    38.                     secounds_str = "0" + secounds;  
    39.                 }  
    40.                 else  
    41.                 {  
    42.                     secounds_str = secounds.ToString();  
    43.                 }  
    44.                   
    45.             }  
    46.             else  
    47.             {  
    48.                 secounds = 0;  
    49.                 Miniutes = Miniutes + 1;  
    50.                   
    51.             }  
    52.             if (Miniutes <= 9)  
    53.             {  
    54.                 Miniutes_str = "0" + Miniutes;  
    55.             }  
    56.             else  
    57.             {  
    58.                 Miniutes_str = Miniutes.ToString();  
    59.             }  
    60.   
    61.         }  
    Hope you liked this and now you might be having more clear idea to start working with AGENT Smartwatch App development. You can find both my All in one App for AGENT Smart watch source file and another source folder for adding Image in AGENT Smartwatch.


Similar Articles