Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science.

Similar presentations


Presentation on theme: "Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science."— Presentation transcript:

1 Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science

2 Introduction  The “Secret Encoder” Program >Encodes text entered, based on a simple keyword  Will allow us to explore the issues of mobile development >User Input >Output Display >Use of the Menu Buttons >Program termination

3 Encoder Program  Screen contains three areas: >Encryption key entry >Secret message entry >Output display entry  When the code button is pressed the key is applied to the message to produce the result  The encryption is performed using XOR, so that it is reversible Key: mykeytext In: password Out: xwbqegg231 Code

4 Starting Development  Initially I am going to write the program for a Smartphone  Then we will convert the code over and build a Pocket PC version  You will see that the conversion is not difficult and centres around the user interface  Finally we can use the encoder in a workspace that targets both devices

5 Encoder Project  First we have to add the data entry components for the program  The Visual Studio Toolbox holds only the components which are available for the Smartphone display  We are going to use Label and TextBox components

6 Encoder Form  I have added four Label and two TextBox components onto the form  They have been given sensible names and aligned correctly

7 Test Layout  When the program runs the layout is somewhat different  This is a limitation of Visual Studio 2003  Visual Studio 2005 gives a full preview

8 Field Traversal  The Smartphone application begins running with the most recently added TextBox selected first  Moving “forwards” through the fields actually moves towards the “oldest” TextBox  This is not what the user will want  You should add the lowest TextBox first >Or make use of the tool to change the field order

9 Smartphone Tab Order  The Smartphone Tab order dialogue, selected from the View menu allows you to re-arrange the tab order of the fields on the form

10 Correct Tabs  The order on the right is the one required  Note that although the labels are not selected by the tab operation, they appear on the order dialogue

11 Data Entry  The present program will run, and the user can move between the two entry boxes and type text into either  We now need a way of triggering the encode action

12 Adding Menu Keys  Not all forms may have menu keys  You can edit them by selecting the MainMenu item at the bottom of the form designer

13 Menu Keys  Once you have added the keys to the form you can type menu selections onto them by clicking on the “Type Here” item

14 Adding the Encode Selection  The Encode selection can be added by typing the option name over the button  Note that I have the option to type above the selection to create multi-option menus

15 Smartphone Menu  The menu key is displayed as shown  We now need to bind an event to the key press to perform our encode action

16 Binding to Menu Actions  It is very easy to bind to a key event  In the form designer, double click on the menu item  If there is no event hander for that item, one is created and you are taken to it in the source file

17 Encode Action  I have created a method to perform the encode action  I could have placed this code inside the event hander itself, but it is more flexible to create a method to do the job: private void doEncode () { outputTextLabel.Text = encode ( inTextBox.Text, keyTextBox.Text ) ; }  This calls an encode method which actually performs the translation of the text itself

18 Testing the program  The initial version of the encode method simply returns the original text  This allows me to test the program and ensure that it works correctly

19 The Encode method private string encode ( string input, string key ) { char [] keyChars = key.ToCharArray(); int keypos = 0 ; System.Text.StringBuilder result = new System.Text.StringBuilder(); foreach ( char ch in input ) { int cval = ch - 32; int pval = keyChars[keypos] - 32; result.Append((char)((cval ^ pval) + 32)); keypos++; if ( keypos == key.Length ) keypos = 0 ; } return result.ToString() ; }

20 Secret Encoder  The encryption works, but it is a very weak method  Note that the space in the input reveals the key character at that position  I leave it to you to create a better one!

21 Exiting the program  At the moment there is no way to exit the program on the Smartphone device  We can stop it with Visual Studio, but the user will not be able to do that  It is very easy to add an exit menu option

22 Stopping an Application  We can use the standard application termination method to stop the program: private void menuItem2_Click(object sender, System.EventArgs e) { Application.Exit(); }  This frees off any resources and exits the program cleanly  Note that the Windows CE guidelines aren’t keen on you stopping your programs (but I do it anyway)

23 TextBox Key Entry  You may wish to not show the password when you are using the program  As with standard Windows Forms, the TextBox component can be set to allow password entry

24 Debugging  The program can be debugged in exactly the same manner as any other Visual Studio application  Any exceptions which are thrown are trapped and you are given the option to debug

25 Running on the PC  The application will run on a standard PC  Note how the behaviour of the menu has been adapted for a Windows Form  It is often useful to be able to run programs on a PC to test them >Particularly if they make use of file input/output

26 Labels and Bugs  There is a bug in this program; some characters are interpreted by the label display component as controls for access keys (even though these have no meaning for Samrtphone!)  The key of “cheese” gives the output as shown

27 TextBox Replacement  Using a TextBox set to read only allows the correct text to be displayed  The read only property of the text box is used to prevent the user changing it

28 Pocket PC Version  The Pocket PC version is very similar  Just about all of the Smartphone code can be transferred directly over to Pocket PC  The only issue is that of user input using buttons

29 Sample Project 01 Smartphone Encoder  If you run the program you will find that you can enter and encode text using a key that you supply  If the encoded text is entered it is converted back into the original

30 Sample Project 02 Pocket PC Encoder  The Pocket PC version is virtually identical to the Smartphone one  The only change is the use of a button to receive the encode command

31 Developing the Application  You may wish to further develop this application  Suggested enhancements include >Improved encoding method >Separate encode/decode methods (perhaps using public and private keys)

32 Sample Project 03  This project combines a Smartphone and a Pocket PC version of the encoder in a single Visual Studio workspace  They all share the same encoder behaviour  Note the references to the Encoder resource

33 More Mobile Fun  If you want to make use of remote resources you should take a look at Web Services  A sample web service is based at MoreThanOneCanPlay.com  Details are on the delegate CD


Download ppt "Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science."

Similar presentations


Ads by Google