Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Monday, 11 April 2011

WP7 Tutorial - part 5: Orientation and Acceleration - X,Y,Z

Detecting gestures, orientations, and movement can be realized with the accelerometer. The accelerometer is a sensor that measures the acceleration in 3 dimensions (X, Y, and Z). If the device is not moved the accelerations measure are the gravity forces in each direction. If the device is accelerated the measured results are a combination of the acceleration and the gravity.

The accelerometer data can be accessed via the AccelerometerReadingEventArgs class. The class has values for the X, Y, and Z axis. The values are of type double and between -2 and 2 which related to acceleration "for each axis in gravitational units" - 1 is the gravitational force of the earth. See: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx and http://msdn.microsoft.com/en-us/library/ff431810(v=vs.92).aspx or on page 80ff, C. Petzold, Programming Windows Phone 7.

A typical exercise for understanding the accelerometer is to create a bubble level (a tool to measure if something is horizontal or vertical - e.g. for hanging pictures on the wall). You probably want to freshen up on arctan2 - at least I needed ;-)

See below the c# example reading out the accelerometer on a windows phone 7. You can also download the accelerometer project directory in a single ZIP-file.

using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Devices.Sensors;

// A simple example to read the accelerometer and display the values
// In order to make it work you have to add the refercerence to 
// Microsoft.Devices.Sensors to your project. To do this right-click
// in the Solution Explorer on References and than choose add Reference
// in the dialog then select Microsoft.Devices.Sensors
// Albrecht Schmidt, University of Stuttgart

// for a more comprehensive example see: 
// http://msdn.microsoft.com/en-us/library/ff431810(v=vs.92).aspx
// http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
// and page 80ff, C. Petzold, Programming Windows Phone 7

namespace Accl_X_Y_Z
{
    public partial class MainPage : PhoneApplicationPage
    {
        Accelerometer accelerometer;
    
        public MainPage()
        {
            InitializeComponent();
            // create a new instance
            accelerometer = new Accelerometer();
            // register a callback function for when values change
            accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accelerometer_ReadingChanged);
            // start the accelerometer
            accelerometer.Start();
        }

        void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
        {
            // required as from here the textBlocks cannot be accessed
            Deployment.Current.Dispatcher.BeginInvoke(() => ChangeUI(e));
        }
        
        void ChangeUI(AccelerometerReadingEventArgs e)
        {
            // show the values on the screen
            textBlock1.Text = "X: " + e.X.ToString("0.000");
            textBlock2.Text = "Y: " + e.Y.ToString("0.000");
            textBlock3.Text = "Z: " + e.Z.ToString("0.000");
        }
    }
}

WP7 Tutorial - part 4: Storing Data on the Phone

If you want to save high scores or preferences you need persistent memory on the phone. On a traditional computer you would create a file and store your information in the file; another option on a Windows PC would be store such information in the registry. For security reasons there is no API to access the file system and there is no global persistent memory across applications on a WP7.

In general there are two ways to store data: (1) in a application specific storage (isolated storage) on the phone or (2) remotely on the internet (or to use another buzzword "in the cloud").
In this example the use of the phone isolated storage API is demonstrated. It is shown how to store and retrieve name-value pairs on the phone (to people who programmed Java ME this is conceptually similar to the record store).

For more details see: http://msdn.microsoft.com/en-us/library/cc221360(v=VS.95).aspx and page 126ff, C. Petzold, Programming Windows Phone 7. It is also possible to created an isolated storage for files see: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile(v=VS.95).aspx

See below the c# example using the local storage on a windows phone 7. You can also download the IsolatedStorageSettings project directory in a single ZIP-file.

using System;
using System.Windows;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

// example of how to save to and load from the isolated application storage 
// this helps to create persistence storage within a single application
// in this example it is shown how to do it for a string 
// Albrecht Schmidt, University of Stuttgart  


// For more details see:
// http://msdn.microsoft.com/en-us/library/cc221360(v=VS.95).aspx
// page 126ff, C. Petzold, Programming Windows Phone 7

// storing files/directory structures see:
// http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile(v=VS.95).aspx

namespace PhoneStorage
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        #region Save and Load Parameters from the Application Storage
        void saveToAppStorage(String ParameterName, String ParameterValue)
        {
            // use mySettings to access the Apps Storage
            IsolatedStorageSettings mySettings = IsolatedStorageSettings.ApplicationSettings;

            // check if the paramter is already stored
            if (mySettings.Contains(ParameterName))
            {
                // if parameter exists write the new value
                mySettings[ParameterName] = ParameterValue;
            }
            else
            {
                // if parameter does not exist create it
                mySettings.Add(ParameterName, ParameterValue);
            }
        }

        String loadFromAppStorage(String ParameterName)
        {
            String returnValue = "_notSet_";
            // use mySettings to access the Apps Storage
            IsolatedStorageSettings mySettings = IsolatedStorageSettings.ApplicationSettings;

            // check if the paramter exists
            if (mySettings.Contains(ParameterName))
            {
                // if parameter exists write the new value
                mySettings.TryGetValue<String>(ParameterName, out returnValue);
                // alternatively the following statement can be used:
                // returnValue = (String)mySettings[ParameterName];
            }

            return returnValue;
        }
        #endregion

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            saveToAppStorage("myIdentifer1", "Last used @ " + System.DateTime.Now.ToString("HH:mm:ss"));
            textBox1.Text = "saved...";
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text = loadFromAppStorage("myIdentifer1");
        }

    }
}

Friday, 25 March 2011

WP7 Tutorial - part 3: Using Location

In this example the use of the location API is demonstrated. The API is a high level interface to geo location. How the location is determined (e.g. GPS, GSM cell information) is of no concern to the developer.

The basic approach is to create an instance of GeoCoordinateWatcher and register two callback functions: one for when the status changes and one for when the location changes. The program demonstrates how these call backs are set up and how from within those function the user interface is updated with the received information. If the status is changes, the program checks what the current status is, and shows this in the status line (textBlock8.Text). If the position is changed then the new position information (Position.Location.Longitude, Position.Location.Latitude) - and additional information such as Speed, Altitude, Course, Accuracy are shown.

As an exercise you can build an application that shows you how close you are to a given target. In two input fields you enter the longitude and latitude of the destination (e.g. a geo cache location). And then you can calculate the difference from the current position to the target location and visualize or sonify the distance.

There is another example (Geo coordinate watcher) how to use this API on the Microsoft msdn website. In C. Petzold's book there is also a good example, see page 91ff.

See below the c# example using geo location on a windows phone 7. You can also download the geolocation project directory in a single ZIP-file.

using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Phone.Controls;
using System.Device;
using System.Device.Location;

// the example shows the basic functionality of the location device
// you need to add in the solution explorer a reference to System.Device
// right click on References in the solution explorer, click Add Reference, and then
// System.Device
// Albrecht Schmidt, University of Stuttgart

// for a more comprehensive example see:
// http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinatewatcher.aspx
// http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
// and page 91ff, C. Petzold, Programming Windows Phone 7

namespace Geo_Location
{
public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher watcher;

// Constructor
public MainPage()
{
InitializeComponent();
}

// the initialize and start button is pressed
private void button1_Click(object sender, RoutedEventArgs e)
{
// initialize the geo watcher with defaul accuracy (battery saving)
// user GeoPositionAccuracy.High for higher accuracy
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
// set movement threhold - as distance in meters - default is 0
watcher.MovementThreshold = 10;

// add a handler that is called when position is changed more than MovementThreshold
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
// a handler for status change
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);

// Start reading location data
watcher.Start();
}

void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
// you cannot change the UI in this function -> you have to call the UI Thread
Deployment.Current.Dispatcher.BeginInvoke(() => ChangeStatusUI(e));
}

void ChangeStatusUI(GeoPositionStatusChangedEventArgs e)
{
String statusType="";
if ((e.Status) == GeoPositionStatus.Disabled)
{
statusType = "GeoPositionStatus.Disabled";
}
if ((e.Status) == GeoPositionStatus.Initializing)
{
statusType = "GeoPositionStatus.Initializing";
}
if ((e.Status) == GeoPositionStatus.NoData)
{
statusType = "GeoPositionStatus.NoData";
}
if ((e.Status) == GeoPositionStatus.Ready)
{
statusType = "GeoPositionStatus.Ready";
}
textBlock8.Text = statusType;
}

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
// you cannot change the UI in this function -> you have to call the UI Thread
Deployment.Current.Dispatcher.BeginInvoke(() => ChangeUI(e));
}

void ChangeUI(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
textBlock1.Text = "Longitute: " + e.Position.Location.Longitude;
textBlock2.Text = "Latitute: " + e.Position.Location.Latitude;
textBlock3.Text = "Speed: " + e.Position.Location.Speed;
textBlock4.Text = "Altitude: " + e.Position.Location.Altitude;
textBlock5.Text = "Course: " + e.Position.Location.Course;
textBlock6.Text = "Vertical Accuracy: " + e.Position.Location.VerticalAccuracy;
textBlock7.Text = "Horizontal Accuracy: " + e.Position.Location.HorizontalAccuracy;
textBlock8.Text = "location updated at " + System.DateTime.Now.ToString("HH:mm:ss");
}

// the stop button clicked ... stop the watcher
private void button2_Click(object sender, RoutedEventArgs e)
{
if (watcher != null) { watcher.Stop(); }
textBlock8.Text = "location reading stopped";
}
}
}

Saturday, 19 March 2011

WP7 Tutorial - part 2: Vibration

This examples shows how to activate the vibration motor / vibration actuator in the phone. The calls Microsoft.Devices.VibrateController.Default.Start and Microsoft.Devices.VibrateController.Default.Stop are used to switch the actuator on and off.
When switching the vibration on the parameter sets the duration for which it should be on. The duration is between 0 and 5 seconds. With the function TimeSpan.FromMilliseconds(duration), where duration is a number, the parameter can be set easily.

The standard API only supports to switch on and off the vibration. We experimenting with the code you can explore how to have vibrations of different intensity. To do this you have to switch on and off the vibration (e.g. 100 ms on then 50 ms off) - basically doing pulse-width modulation.

There is more information on the vibration controller on the Microsoft site.

See below the c# example for controling the vibration a windows phone 7.
You can also download the vibration project directory in a single ZIP-file.

using System;
using System.Windows;
using Microsoft.Phone.Controls;

// example of how switch on the vibration motor for a given time
// another call to switch it off
// Albrecht Schmidt, University of Stuttgart

// see:
// http://msdn.microsoft.com/en-us/library/microsoft.devices.vibratecontroller.default(v=VS.92).aspx


namespace Vibration
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
double duration;
duration = Convert.ToDouble(textBox1.Text);
if (duration > 5000)
{
duration = 5000;
}
// starts the vibrations (valid duration are between 0 and 5 seconds)
Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromMilliseconds(duration));
}

private void button2_Click(object sender, RoutedEventArgs e)
{
Microsoft.Devices.VibrateController.Default.Stop();
}
}
}

Friday, 18 March 2011

WP7 Tutorial - part 1: Phone calls and SMS

Over the next weeks I like to share some examples I have created while learning to program the Windows Phone 7 platform. The tutorial is mainly explaining some of the APIs and components I found interesting (in particular related to context-awareness and human computer interaction).

If you are really new to programming on this platform the App-Hub is probably a good place to start. There are also plenty of helpful examples on the Microsoft web page. As prerequisite for this tutorial I assume that you have successfully installed Visual Studio (Express), the windows phone development tools, and that you have managed to get your first "Hello World" written, compiled, and deployed. There is also plenty of material on youtube that helps to get started. The Programming Windows Phone 7 book by Charles Petzold (free available as PDF) is also a good starting point.

Several examples that follow in the tutorial (e.g. vibration, accelerometer) having a real phone to test the programs is highly recommended.

The Windows Phone 7 is a phone and hence I start with a program that makes use of the basic phone functionality: making a phone call and sending an SMS.

This example also highlights the approach taken in several of the APIs. Your program (a third party application) is restricted to transfers control to the phones basic functions when making a call or sending an SMS. Basically the API call opens the phone/SMS applications with the parameters you hand over. From a security point of view this is nice as an application can not send SMS or do phone calls without the user recognizing (and agreeing to) it. From a programming perspective this has disadvantages as automation of functionality (e.g. always sent an SMS when I am coming closer than 10 km to home) is not possible.

The example demonstrates how to access interactively the phone book (using the PhoneNumberChooserTask), how to initiate a phone call task (using Microsoft.Phone.Tasks.PhoneCallTask), and how to initiate a SMS task (using Microsoft.Phone.Tasks.SmsComposeTask).
The PhoneNumberChooserTask is an example of a callback - used a lot when programming for WP7. The basic concept is to register a function that is called when an event happens. In this case the event is that the number is chosen and then the function myPhoneNumberChooser_Completed is called. The nice thing with Visual Studio is that you do not have to type this (or remember the syntax) - just use the TAB-key after you typed +=

See below the c# example for sending SMS and making a phone call. You can also download the Phone/SMS project directory in a single ZIP-file.

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

// example how to invoke a phone call and an SMS from a program
// the basic approach is that you can set the phone number (and
// for SMS the message body) and then you call the phone/sms
// application
// Albrecht Schmidt, University of Stuttgart
// more on how to invoke phone tasks (photo, email, ...)
// http://msdn.microsoft.com/en-us/library/ff769543(v=vs.92).aspx

namespace Phone_Call_and_SMS
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}

// choose a phone number
private void button1_Click(object sender, RoutedEventArgs e)
{
PhoneNumberChooserTask myPhoneNumberChooser;
myPhoneNumberChooser = new PhoneNumberChooserTask();
myPhoneNumberChooser.Completed += new EventHandler&lt;PhoneNumberResult&gt;(myPhoneNumberChooser_Completed);
myPhoneNumberChooser.Show();
}

// call back after the phone number is choosen
void myPhoneNumberChooser_Completed(object sender, PhoneNumberResult e)
{
if (e.TaskResult == TaskResult.OK)
{
textBox1.Text = e.PhoneNumber.ToString();
}
}

// making a phone call (opening the sms application with presets)
private void button2_Click(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Tasks.PhoneCallTask phonecall = new Microsoft.Phone.Tasks.PhoneCallTask();
phonecall.PhoneNumber = textBox1.Text; // set phone number
phonecall.Show();
}

// sending an sms (opening the sms application with presets)
private void button3_Click(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Tasks.SmsComposeTask sms = new Microsoft.Phone.Tasks.SmsComposeTask();
sms.To = textBox1.Text; // set phone number
sms.Body = textBox2.Text; // set body
sms.Show();
}
}
}

Sunday, 12 September 2010

Mensch und Computer 2010 at the University of Duisburg-Essen

The German HCI conference Mensch und Computer 2010 started today. Under a single roof - called interactive culture - three more conferences are co-located: the German UPA track, the German E-learning conference, and a track on entertainment interfaces. The size of the conference is with about 500 people impressive and it shows that interactive computing and user experience has become a major field in Germany - in academia as well as in industry - and I am proud to have chaired the paper program for Mensch&Computer together with Jürgen Ziegler.

On Sunday we ran a number of workshops: Mobile HCI (by Enrico Rukzio), Methods and Tools in HCI (by Nicole Krämer), Web 2.0 and CSCW (by Tom Gross), and on Writing scientific papers (by Geraldine Fitzpatrick). I enjoyed myself attending two of the tutorials and I have to admit I learned interesting things :-) and got ideas for my own teaching.
The paper program starting on Monday was selective as we had 119 submissions (full and short papers) and the committee chose 41 to be presented at the conference (is about 34% acceptance rate).

A restaurant to remember (in a very positive sense): Dreigiebelhaus.

Tuesday, 15 September 2009

Thursday, 14 May 2009

Tutorials at Pervasive, HCI Library

I did a tutorial on Mobile Human Computer interaction at Pervasive 2009. The tutorial tried to give an overview of challenges of mobile HCI and was partly based on last year's tutorial day at MobileHCI2008 in Amsterdam. For the slides from last year have a look at: http://albrecht-schmidt.blogspot.com/2008/09/mobilehci-2008-tutorial.html



Listening to Marc Langheinrich's tutorial on privacy I remembered that that I still have the photos of his HCI library - and to not forget them I upload them. Marc highlighted the risk of data analysis with the AOL Stalker example (some comments about the AOL Stalker). His overall tutorial is always good to hear and has many inspring issues - even so I am not agreeing with all the conclusions ;-)


For me seeing the books my collegues use on a certain topic still works better than the amazon recommendations I get ;-) perhaps people (or we?) should work harder on using social network based product recommendation systems…

Wednesday, 1 April 2009

Ubicomp Spring School in Nottingham - prototyping user interfaces

On Tuesday and Wednesday afternoon I ran practical workshops on creating novel user interfaces complementing the tutorial on Wednesday morning. The aim of the practical was to motivate people to more fundamentally question user interface decisions that we make in our research projects.

On a very simple level an input user interface can be seen as a sensor, a transfer function or mapping, and an action in the system that is controlled. To motivate that this I showed two simple javascript programs that allowed to play with the mapping of the mouse to a movement of a button on the screen and with moving through a set of images. If you twist the mapping functions really simple tasks (like moving one button on top of the other) may get complicated. Similarly if you change the way you use the sensor (e.g. instead of moving the mouse on a surface, having several people moving a surface over the mouse) such simple tasks may become really difficult, too.

With this initial experience, a optical mouse, a lot of materials (e.g. fabrics, cardboard boxes, picture frames, toys, etc.), some tools, and 2 hours of time the groups started to create their novel interactive experience. The results created included a string puppet interface, a frog interface, a interface to the (computer) recycling, a scarf, and a close contact dancing interface (the music only plays if bodies touch and move).

The final demos of the workshop were shown before dinner. Seeing the whole set of the new interface ideas one wonders why there is so little of this happening beyond the labs in the real world and why people are happy to live with current efficient but rather boring user interfaces - especially in the home context…

Ubicomp Spring School in Nottingham - Tutorial

The ubicomp spring school in Nottingham had an interesting set of lectures and practical sessions, including a talk by Turing Award winner Robin Milner on a theoretical approach to ubicomp. When I arrived on Tuesday I had the chance to see Chris Baber's tutorial on wearable computing. He provided really good examples of wearable computing and its distinct qualities (also in relation to wearable use of mobile phones). One example that captures a lot about wearable computing is an adaptive bra. The bra one example of a class of interesting future garments. The basic idea is that these garments detects the activity and changes their properties accordingly. A different example in this class is a shirt/jacket/pullover/trouser that can change its insulation properties (e.g. by storing and releasing air) according to the external temperature and the users body temperature.

My tutorial was on user interface engineering and I discussed: what is different in creating ubicomp UIs compared to traditional user interfaces. I showed some trends (including technologies as well as a new view on privacy) that open the design space for new user interfaces. Furthermore we discussed the idea about creating magical experiences in the world and the dilemma of user creativity and user needs.

There were about 100 people the spring school from around the UK - it is really exciting how much research in ubicomp (and somehow in the tradition of equator) is going on in the UK.

Tuesday, 2 September 2008

MobileHCI 2008 Tutorial

The conference on mobile human computer interaction (MobileHCI 2008) started today in Amsterdam with the tutorial and workshop day.

I am chairing the tutorials and we tried a new approach for the tutorial, having 6 sessions/chapters that all together make up an introduction to mobile HCI. After 10 years of mobile HCI it seems important to help new members of the community to quickly learn about the field. The presentations were given by experts in the field that had 1 hour each for their topics. We had unexpected high attendence (the room with 100 seats was nearly always full). Have a look at the slides:

Text input for mobile devices by Scott MacKenzie
Scott gave an overview of different input means (e.g. key-based, stylus, predictive, virtual keyboard), parameters relevant for designing and assessing mobile text input (e.g., writing speed, cognitive load) and issues related to the context of use (e.g., walking/standing).

Mobile GUIs and Mobile Visualization by Patrick Baudisch

Patrick introduced input and output options for mobile devices. He will talk about the design process, prototyping and assessment of user interfaces, trade-offs related to the design of mobile GUIs and different possible interaction styles.

Understanding Mobile User Experience by Mirjana Spasojevic
Mirjana discussed different means for studying mobile user needs and evaluating the user experience. This includes explorative studies and formal evaluations (in the lab vs. in the field), including longitudinal pilot deployments. The lecture discusses traditional HCI methods of user research and how they need to be adapted for different mobile contexts and products.

Context-Aware Communication and Interaction by Albrecht Schmidt
Albrecht gave an overview of work in context-awareness and activity recognition that is related to mobile HCI. He discussed how sharing of context in communication applications can improve the user experience. The lecture explained how perception and sensing can be used to acquire context and activity information and show examples how such information can be exploited.

Haptics, audio output and sensor input in mobile HCI by Stephen Brewster
Stephen discussed the design space for haptics, audio output as well as sensor and gesture input in mobile HCI. Furthermore he assessed resulting interaction methods and implications for the interactive experience.

Camera-based interaction and interaction with public displays by Michael Rohs
Michael introduced camera based interaction with mobile devices; this included a assessment of optical markers, 2D-barcodes and optical flow as well as techniques related to augmented reality. In this context he addressed interaction with public displays, too.

You can also download the complete tutorial including all 6 chapters in a single PDF file (16MB).

Thursday, 22 May 2008

Tutorial von Sensor to Context und Activity at Pervasive 2008

Pervasive 2007 introduced a new form of tutorials – having a number of experts talking one hour about their special topic – I was last year as participant and liked it a lot. This year Pervasive 2008 repeated this approach and I contributed a tutorial on how to get context and activity from sensors (tutorial slides in PDF).

Abstract. Intelligent environments, sensor network and smart objects are inherently connected to building systems that sense phenomena in the real world and make the perceived information available to applications. In the first part of the tutorial an overview of sensors and sensor systems commonly used in pervasive computing application is given. Additionally to the sensor properties means for connecting sensors to systems (e.g. ADC, PWM, I2C, serial line) are explained. In the second part it is discussed how to create meaningful information in the application domain. Some basic features, calculated in the time and frequency domain, are introduced to provide basic means for processing and abstraction of raw sensor data. This part is complemented by a brief overview of mechanisms and methods for relating (abstracted) sensor information to context, activity and situations. Additionally general problems that are associated with sensing context and activity will be addressed in this tutorial.