Saturday, January 28, 2012

Windows Phone - Texture (4)

Hello


One of the most common object in Windows Phone application is bitmap.
The image element displays bitmap.

Most popular bitmap format are :

  • JPEG
  • PNG
  • GIF
Note that Silverlight supports only JPEG and PNG !!

The image class

Image is described by Image class.
Image element in XAML is decribed by <Image .../> in general <Image Source="uri"/> where source is the URI of the bitmap file.
URI is a representation of a resource on the internet or intranet.


I will demonstrate two use case regarding the resource location  :

  • Bitmap reside localy 
  • Bitmap reside on the internet

Local bitmap


Add directory to the project


Give the new directory a name -  Image.


Next add to Image directory bitmap file name LocalBitmap.jpg





A directory name Image was created at the same level as the project file and a LocalBitmap.jpg reside inside it.
The project looks now like this :



Now mark LocalBitmap.png, right click mouse, choose properties and change "Build Action" to Content and "Copy to Output Directory" to "Copy if newer".


Now after compilation this will copy LocalBitmap.jpg to the directory Image which reside on  the same directory as the xap file

Add to the MainPag.xaml the image element which point locally to the bitmap file


Run the application to get

LocalBitmap.zip


Internet Bitmap


Here the bitmap file reside somwhere on the internet.
So simple add the following image element.




Run the application and the result is :


InternetBitmap.zip

Dynamic bitmap load


The samples before handled static loading of bitmap i.e. the bitmap file path was written in the XAML and was known before the application was loaded. It was handled very well by Image.Source type ImageSource which is abstract class. If you think a little about these two samples you must admire the work done here. By simply adding a path into an Image element on the XAML you get a display of local bitmap file in one sample and a display of a bitmap file which reside on the internet (and naturally involve network API to access it) on a second sample.


When you need to do this dynamically it looks like this :

First i add two image elements to MainPage.xaml



Then i use BitmapSource which inherits ImageSource to load the bitmaps.
Bitmap loading is activated after a tap and handled by the static touch handler - this was covered in previous post (Touch of Touch (3))




Note that  LocalBitmap.jpg is added to the project  as done in LocalBitmap.zip

DynamicLoadBitmap.zip


Nathan

Wednesday, January 25, 2012

Windows Phone- Touch of Touch (3)

Hello


The screen on the phone is sensitive to touch. To be more specific it is multi touch and can detect at least four fingers simultaneously .

The emulator can mimic touch tap via mouse click.


Touch events
  • Low level interface - TouchFrameReported static event, get all touch events in the application
  • High level interface - UIElement events :

Low Level  Touch Interface

The basic class here is TouchPoint which represent a single touch point.
Touch get properties :

  • Action - enumeration of action : Up,Down,Move 
  • Position - relative to the upper left corner of a reference element 
  • Size - touch area (not usefull)
  • TouchDevice

TouchDevice has 2 get properties :
  • id - use to destiguish between fingers
  • DirectlyOver - top most element underneath the finger

The handler is registered like this :
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);

and the handler definition looks like this

 void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
             ...
        }

Note that sender is null , why ??

Important methods of TouchFrameEventArgs :

  • GetTouchPoints - return a collection of TouchPoints all over the application regardless of the reference element
  • GetPrimeryTouchPoint - return the position of the first finger touching the phone


Assignment :
Write an application using TouchFrameReported which displays the X,Y of a touch tap relative to the page and relative to the Application. The Application should have a TextBlock with text Push Me, when ever you click on it its Text is changed to "I Was Pushed" other wise it's "Push Me"

Solution - LowLevelTouch.zip

High Level  Touch Interface


The high level touch interface involves 3 UIElement events :

  • ManipulationStarted
  • ManipulationDelta  
  • ManipulationCompleted
These events translate the fingers activity into translation and scaling. It started with ManipulationStarted event followed by zero or more ManipulationDelta events and end with ManipulationCompleted event.

Source sample
The sample zip file : HighLevelTouch

Following sample demonstrate these 3 events.

I have defined the handler of ManipulationDelta  and ManipulationCompleted on UIElement PhoneApplicationPage :

and the handler for ManipulationStarted is defined for a TextBlock :


so the application issue ManipulationStarted only after tap on tbMessageArea

next i add the handlers 



Run the application to produce:


Click "Push To Start" ,start moving the mouse while it is clicked then release it. You will get all events on the TextBlock :

  • one event when you first click the TextBlock
  • few events when you moves the clicked mouse
  • one event when you released the mouse


Routed Events
Routed event is a mechanism in Silverlight which involves event,bubble and visual tree.

In particular ManipulationStarted,ManipulationDelta ,ManipulationCompleted are routed events.

This means that tapping on the TextBlock in the previous sample cause ManipulationStarted event on this element. However, this event bubble up the visual tree to the parent of the TextBlock i.e. ContentPanel Grid and further to it's father LayoutRoot, and further to it's father phoneApplicationPage. Thus all of these elements could have defined a handler for ManipulationStarted and handle also this event.

Note that e.g. ManipulationStartedEventArgs derive from RoutedEventArgs.

RoutedEventArgs important properties :



You can put Handled property to true to mark the event as handled. In general (except for AddHandler) this will eliminate the bubbling of the event up the visual tree.

Nathan

Sunday, January 22, 2012

Windows Phone- Basic Orientation , Dynamic Layout and Events (2)

Hello

Orientation 

Take the program that we did in "Introduction - First Windows Phone Application (1.2)".
Use the emulator to turn the emulator sideways e.g. 90 degree clockwise. What happened ?
The display did not cope with orientation change.


Go to MainPage.xaml and change 

SupportedOrientations="Portrait" Orientation="Portrait"
to
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"

Now turn the emulator sideways. Much better , isn't it ?

Notice that the default Orientation is Portrait. Change it to Landscape and run the application again. What happened?

Horizontal and Vertical Alignment


Both describe how a child element is position or stretched within a parent layout.
Vertical alignment has four values : Top, Bottom, Center, Stretch
Horizontal alignment has four values : Right,Left,Center,Stretch.

Source sample
Orientation.zip (Use Firefox in case of error 310)

Following xaml snippet put 9 TextBlock in 3x3 matrix




And the result looks like this


Turning the emulator sideways :





Margin
Margin is a property of an element.
Margin is type Thickness which has four properties : Left, Top, Right, Bottom (in this order)
Following is a xaml snippet which define a Grid with 2x2 matrix.
The Text box both margin is 15(Left),10(Top),15(Right),10(Bottom)



It is very easy to understand the meaning of margin viewing this. You can think of margin as thickness of the element.

Padding
Padding is a property type Thickness . Only few UIElements has this property e.g. TextBox.
For TextBox it is defined as the space between the content area and the content displayed.

It is best understood via a sample








Events
You can handle event such as Loaded,Orientation changed etc.
It can be done via the IDE or directly by changing the XAML and code behind.
I will  add handling of OrientationChanged event via the IDE :


the resulting top of MainPage.xaml


and MainPage  (MainPage.xaml.cs - code behind)


Points of notice :
  • You can add event handling by directly manipulating MainPage.xaml and MainPage.xaml.cs.
  • Notice in MainPage.xaml that the event OrientationChanged is attached a handler name PhoneApplicationPage_OrientationChanged. MainPage.xaml.cs has the definition of PhoneApplicationPage_OrientationChanged.
  • OrientationChangedEventArgs is an argument of the handle, can you imagine what info it contains  ?


Lets experiment a little with this event.
I will add TextBlock to write orientation info :
and compile.

Note that i used Name and not x:Name. What's the difference ?
x:Name can be used with anything while Name can be applied only to FrameworkElement because it has a Name property (FrameworkElement Class)

Now Look at the created file MainPage.g.cs Notice two interesting things :

  • internal System.Windows.Controls.TextBlock tbOrientationChanged; - The new TextBlock name tbOrientationChanged is declared as part of class MainPage (notice that i have added it in xaml)
  • this.tbOrientationChanged = ((System.Windows.Controls.TextBlock)
                (this.FindName("tbOrientationChanged"))); - object is accessed by the name given in xaml file



Now i will change the handler :

Run the application and rotate the emulator. You will see something like this :



OrientationChangedEvent.zip  (Use Firefox in case of error 310)




Nathan

Introduction - First Windows Phone Application (1.2)


Hello

use "Silverlight for Windows Phone" template and create a new "Windows Phone Application" project via Visual Studio 2010 and name it "SilverlightHelloPhone" which is also the namespace

Application Zipped (use Firefox in case of error)

WMAppManifest.xml

  • Title attribute- the name of the application as  presented to the use
ApplicationIcon.png - icon of the application

App.xaml.cs - code behind
  • All silverlight application has an App class which inherit Application. It handles tasks like startup \ shutdown 
  • Note that it is partial class, its definition continued in App.xaml 
  • App class create one object type PhoneApplicationFrame  (only one object can exist). This frame is 480x800 pixels and occupy the entire display of the phone. It behaves somewhat like web browser by navigating to an object type MainPage which inherits PhoneApplicationPage.  PhoneApplicationFrame can have many instances type  PhoneApplicationPage but can host only one at a time

 App.xaml - XAML file

  • used for resources which are used by the application : brushes,color,...
  • Note that this XAML notation implied that class App derive from Application (root element) and thus continued definition of class SilverlightHelloPhoneApp from App.xaml.cs
  • xmlns means XML namespace
  • http://schemas.microsoft.com/winfx/2006/xaml/presentation - standard Silverlight namespace use to locate e.g. Application class
  • http://schemas.microsoft.com/winfx/2006/xaml/presentation - namespace related to the XAML. x is used in x:Class 
App.g.cs -another partial definition of App class generated file . reside under obj directory


MainPage.xaml - XAML file

    • definition of class MainPage
    •  x:Class="SilverlightHelloPhone.MainPage - definition of the class, inherit PhoneApplicationPage
    • next four xmlns are the same as in App.xaml
    •  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - d stand for designer. 
    • xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc stand for markup compatibility 
    • mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" - ignore  DesignWidth and  DesignHeight during compilation. (why is it needed ?)
    •  FontFamily,FontSize,Foreground : relate to the whole of the page
    • SupportedOrientations : orientation supported by the page
    •  shell:SystemTray.IsVisible="True" - enable view of  the status bar at the top of the phone 
    • The body of MainPage.xaml is a visual tree of elements : Grid,StackPanel,TextBlock -  All of them are Silverlight classes with markup representation . Play with remarking of these elements and see the change of the page in the designer . 

     MainPage.xaml.cs - code behind
    • definition of class MainPage 

    MainPage.g.cs - another partial definition of  MainPage class generated file . reside under obj directory

    Our application looks visually as follolws :

    • PhoneApplicationFrame
    • PhoneApplicationPage
    • Grid name  LayoutRoot
    •  StackPanel name TitlePanel
    • TextBlock name ApplicationTitle
    • TextBlock name PageTitle 

    • Grid name ContentPanel 

    Remarks

    • Notice that i have used the word element. In Silverlight it has two meanings :
    • It's an XML term used to indicate item delimited by start tag and end tag
    • It's a visual object e.g. TextBox 


    Exercise

    • Add a TextBlock with "Hello" inside the content Grid. Do it twice, once by drag drop textBlock and once by editing the xaml file. make sure it is centered
    • Change the content of ApplicationTitle and PageTitle

    Color Themes


    • it is possible to change theme by going from the phone Start, click the right arrow on the top, Setting , then choose theme. it is possible to choose Background between Dark\Light and Accent color between 10 colors - Colors list





    • this will result as follows

    Points and Pixels

    • All dimensions in Silverlight are in pixels. e.g. font size of 36 means 36 pixels


    XAP

    • Under bin\Debug reside SilverlightHelloPhone.xap which is the file used for phone deployment.
    • Rename to .zip and you will be able to unzip it and see it's content (it has not exe file, why?) :




    Nathan

    Introduction - Hello Windows Phone 7 (1.1)

    Hello

    Software

    • Supports two known technologies : 
    • Silverlight
    • XAML
    • RIA (Rich Internet Application)
    • XNA
    • High performance  2D\3D  games 
    • C#\VB only
    • Cloud Ready :
    • Location aware
    •  Maps


    • Written application may be uploaded to the marketplace. This require registration and certification. Microsoft check that the uploaded application meets it's standards in terms of reliability,efficiency etc.


    Hardware Chassis

    • Unlike Android, Windows Phone has minimal hardware spec relating to the phone device.
    • The front of the phone consist of multi touch display and 3 buttons (left to right) :
    • Back - can be used by  application  like in browser. Cause  application termination if used from the application front page
    • Start - take the user to the start screen of the phone. Can not be used by application
    • Search - search by the operating system



    • Screen size is 480x800 pixels . Expected in the future also 320x480
    • Screens are required to respond to at least four simultaneously touch points
    • Hardware keyboard is optional - on screen keyboard exist (SIP)

    Sensors and devices

    • Windows Phone device is required to support sensors :
    • Wi-Fi : Wireless connection
    • Camera :  at least 5 Mega pixel
    • Accelerometer :  acceleration detector , detect orientation and sharp movement
    • Location : A GPS is used for position location
    • Vibration : provide vibration of the phone
    • FM radio
    • Push Notification : web service update only when notification actually happened (no polling)

    Nathan

    Wednesday, January 18, 2012

    Windows Phone Emulator

    Hello

    Emulator :


    The toolbar displayed alongside the Windows Phone emulator offers the following controls, listed in order from top to bottom:
    • Close - Terminates the Windows Phone emulator.
    • Minimize - Minimizes the Windows Phone emulator to the Windows taskbar.
    • Rotate Left - Rotates the Windows Phone emulator display 90 degrees counterclockwise.
    • Rotate Right - Rotates the Windows Phone emulator display 90 degrees clockwise.
    • Resize - Toggles the Windows Phone emulator display between reduced and full size.
    • Zoom - Invokes the Zoom dialog box to resize the emulator.
    • Additional Tools - Accelometer, Location, Screen shot


    Links



    Nathan

    Sunday, January 15, 2012

    Windows Phone - Application Platform Overview

    Hello

    http://msdn.microsoft.com/en-us/library/ff402531(v=VS.92).aspx

    Points of interest :

    • Architecture :
    • Runtimes : 
    • Silverlight, XNA (games), Windows Phone Framework , Common Base Class Library
    • Windows Phone Framework : Sensor, Radio, Camera, Notification, Browser
    •   Quick migration of application developed on Silverlight\XNA to Windows Phone
    • Tools :  Visual studio, Expression blend, Phone emulator, XNA Games, ...
    • Cloud Services : Notifications, Location, Feeds, Social,  Maps, Windows Azure , .... 
    • Portal Services : Marketplace, Publishing, Update,....


    Nathan

    Thursday, January 12, 2012

    Monday, January 2, 2012

    10 Top Best Android Apps you must have

    Hello

    Some interesting facts on Android popularity :

    • Android is proved to be mostly used Mobile Phones in the world with over 44% of the market share
    • There are over 2.5 million Android Apps available currently
    And the best apps :
    1. Google Voice
    2. Advanced Task Killer
    3. Dropbox
    4. Evernote
    5. DroidAnalytics
    6. Documents To Go
    7. Astro File Manager
    8. Lookout
    9. RockPlayer Lite
    10. AnyPost


    source : http://www.linkedin.com/news?viewArticle=&articleID=834847619&gid=76373&type=member&item=78485033&articleURL=http%3A%2F%2Fwww%2Egadgetcage%2Ecom%2Ftop-best-android-apps-must-have%2F24455%2F&urlhash=CWqZ&goback=%2Egde_76373_member_78485033

    Nathan