CodeByte

Write your code smartly

Monthly Archives: June 2012

Using Camera in Windows Phone

Here i will tell you how to invoke Camera in Windows phone application. Its as simple as you can use a camera in your cell phone.

So now add a button any where in your Windows Phone application from toolbox and double click it to get the click event handler or find the click event from its properties windows show in previous posts.

Please add the following namespace on top of your CS file or code file

using Microsoft.Phone.Tasks;

Add following code on the click event of the button.

private void button1_Click(object sender, RoutedEventArgs e)
{
   CameraCaptureTask cmt = new CameraCaptureTask();
   cmt.Completed += new EventHandler<PhotoResult>(cmt_Completed);
   cmt.Show();
}

The Camera will be launched after clicking button with a dummy Black object moving around a white screen. by pressing the Capture button you can capture the image. You can Play with the image captured in your application like displaying it on image control.

Put the below code in Camera photo result event

void cmt_Completed(object sender, PhotoResult e)
{
   //throw new NotImplementedException();
   BitmapImage bi = new BitmapImage();
   bi.SetSource(e.ChosenPhoto);
   image1.Source = bi;
}

Enjoy Happy Coding !

Simple Calculator in Windows Phone

In previous post I explained the simple process of getting started guide with Windows Phone development and how to configure it in your development PC. In this post I will show how to create a simple calculator with addition property ( you can alter by your self with its operator -, *, /). The new project with simple Windows phone page, drop 2 text boxes from toolbar on left and a button. Now click on a text box and on the right bottom you will see a property window, find the property “TEXT” and remove the word text box written in front of it. Do this for other as well. Now change the button “Content” property to “Add”.

If you want to create text boxes and button through code then use the following code sample and place it inside the second grid tag.

<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”10,43,0,0″ Name=”textBox1″ Text=”” VerticalAlignment=”Top” Width=”460″ Grid.Row=”1″ />

<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”10,125,0,0″ Name=”textBox2″ Text=”” VerticalAlignment=”Top” Width=”460″ Grid.Row=”1″ />
<Button Content=”Add” Grid.Row=”1″ Height=”72″ HorizontalAlignment=”Left” Margin=”152,209,0,0″ Name=”button1″ VerticalAlignment=”Top” Width=”160″ />

Here how now design view XAML code  looks like

<Grid x:Name=”LayoutRoot” Background=”Transparent”>
<Grid.RowDefinitions>
<RowDefinition Height=”Auto”/>
<RowDefinition Height=”*”/>
</Grid.RowDefinitions>

<!–TitlePanel contains the name of the application and page title–>
<StackPanel x:Name=”TitlePanel” Grid.Row=”0″ Margin=”12,17,0,28″>
<TextBlock x:Name=”ApplicationTitle” Text=”MY APPLICATION” Style=”{StaticResource PhoneTextNormalStyle}”/>
<TextBlock x:Name=”PageTitle” Text=”page name” Margin=”9,-7,0,0″ Style=”{StaticResource PhoneTextTitle1Style}”/>
</StackPanel>

<!–ContentPanel – place additional content here–>
<Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″></Grid>
<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”10,43,0,0″ Name=”textBox1″ Text=”” VerticalAlignment=”Top” Width=”460″ Grid.Row=”1″ />
<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”10,125,0,0″ Name=”textBox2″ Text=”” VerticalAlignment=”Top” Width=”460″ Grid.Row=”1″ />
<Button Content=”Add” Grid.Row=”1″ Height=”72″ HorizontalAlignment=”Left” Margin=”152,209,0,0″ Name=”button1″ VerticalAlignment=”Top” Width=”160″ />
</Grid>


Now select the Button and go back to the property window, here you will see two tabs on the top of this window i.e “Properties” and “Events“. Click on the events tab and find out the “Click”. Double click on the event this will take you to the code file named as MainPage.xaml.cs and into the click event of the button. Here now you code the following :

private void button1_Click(object sender, RoutedEventArgs e)
{
   int a,b;
   long c;
   a = Convert.ToInt16(textBox1.Text);
   b = Convert.ToInt16(textBox2.Text);
   c = a + b;
   MessageBox.Show(c.ToString());
}

Now on top you can see a Play button in green color press that, you will see a emulator booting OS, This is because Emulators are designed with the same configuration as the original phones thats why you must meet the requirements of it. Now your application will run and the layout you designed will be displayed. Provide the values in text boxes and press add, you will see the answer in the message box. if not please go through it again.

Understanding the Event Code

  
int a,b;
long c;


We have declared to Integer variables a and b to collect text box values in them and a long integer variable to collect their Sum.

   a = Convert.ToInt16(textBox1.Text);
   b = Convert.ToInt16(textBox2.Text);


We have to convert the textbox values to integer because the addition operator is performed on numbers and textbox values are of TEXT type or Strings.

   c = a + b;
   MessageBox.Show(c.ToString());


add the values of a and b and place the answer in c. Now displaying the answer c in a message box we have to again convert the c (which has a numeric answer) to String as Message Box is a class which only displays Strings.

Hope you got simple way to work with this post if any queries then leave a comment below.

Create Windows Phone Application

Windows Phone applications are created using C# language on .NET platform 4.0 or above. Simply you must have Visual Studio 2010 service pack 1 installed on your system, if not you can find it fromHere. This down loader will install Windows Phone SDK along with Visual Studio Express limited for Windows phone development. Along with the SDK the Emulator for testing your apps live will also be installed for which you required at-least 2 GB memory. Once you have configured all the setup you are ready to build your first Windows Phone application.

Open Visual Studio Express for Windows Phone and click > File from the menu. Then new Project > Silverlight for Windows Phone .

Now here you can select different type of controls offered by Windows Phone, it includes Panorama, Pivot and simple application. Here how it looks like.

Give the name and location and then press OK. You will see this design view of your first application.

here you can see 2 blocks divided, one is the phone showing the Windows phone and second on the right side is the Silver light code (XAML) generated when you make changes on the phone design by dragging controls from toolbar to the phone. Toolbar is on the left side having common controls . Using these controls you can develop a Windows Phone application. In further posts i will be telling you how you can create a working simple app using XAML and C# code so stay tune and queries you can post comments below.

Happy Coding !

This slideshow requires JavaScript.

Adding Google Analytics to your Website

Google Inc. provides us with its free tool “Google Analytics” which can help you keep your application under monitor and see the web traffic on hourly, daily, weekly and monthly basis. Google analytic provides lots of attributes which can never be imagine which includes language data, browser data, Mobile OS and PC OS separate traffic details. It also provides Total visits to the website including average time spent per user, unique visits, returning users and much more. The image below will show you the interface.

Follow these simple steps to apply monitoring feature in your own website.

1. You must have a Google mail account. (if not Sign Up here.)

2. Once you have an account simply open the following link : Google Analytics

3. Click Sign In and provide your credentials.

4. You have to again click on the Sign Up button on the right side but it will just ask you for the name of the account you want to create to track your website here is the image :

5. After that give any account name, URL of your website, country time zone and accept Google Analytics Terms and Services and click create account.

6. After this your Account ID is created in a format “UA-xxxxxxxx-1”. Also at the last of this page you will find the java script code for your tracking.

7. Copy that code and paste it inside the head tag before its closing </head>.

8. You are ready to track your website.

9. There are Mobile platforms SDK available which you can integrate with your Mobile platform to track your Mobile applications.

Policy-Based Security Management in MANETs

Abstract:

It’s a fact that internationally, Mobile Ad-hoc networks are gaining lot of progress and adaptation rate is increasing because of the fast growing rate of business. Data communication is the major thing every one look to acquire while interacting with each other so whenever wireless devices get together can make up a network for instantly changing information.  The wireless devices are not fixed at their places and having some other issues to handle during this network life. As MANETs are the open networks can be formed using two or more mobile devices therefore, it raises the challenge of network management. These mobile devices can easily run out of batteries and location can change any time. Also during these open network communications security issues can also rise like eavesdropping, spoofing and denial-of-service attacks. Therefore, it is the main challenge to trust the communicated node before changing information. Policies based network management is normally used in fixed environment of networks so it is another challenge to implement policies based network management is MANETs considering the security issues.

To access full paper please subscribe for free and send your email to get the paper.

ji_jibran1990@hotmail.com

 

Microsoft Kinect

Kinect is a product of Microsoft which is used to sense the body movement of the humans. Kinect is majorly used with the Microsoft’s gaming console known as XBOX where you can play games by live action. Xbox is connected to kinect and kinect using its camera detects the points of the skeleton of the human body and performs respective actions on the gaming screen.

Kinect helps users to interact to display devices such as gaming consoles or PC without any touch or physical interactions. That leads to know about NUI (Natural User Interaction) which means to interact with the system without touching in fact using sensors to perform actions. RGB camera is integrated in Kinect to detect the scene. Not only this Kinect also detects the voice and perform actions what are assigned to that voice. Yes, Kinect is now widely used for programming different software which are useful in daily life of different people.

Kinect had a processor inside itself which makes the processing faster than the normal web cam of the computer systems.

Following is the image representing the kinect device description.

3D depth sensor is used distinguish the distance of the objects in the scene detected by the RGB camera and result in a image defining the scene in a gray scale mode (by default). Closer the object darker the color.

Define CSS class and CSS ID

To define a class in CSS the format used is : put a (dot) first followed by any name you want to put for a class.

.textcolor {
  color: #FFF;
}

can be used like this in a paragraph tag for instance

  <p class="textcolor"> This is CSS class <p>

The result will be the text written inside paragraph tag will have white foreground or text color.

Now defining a CSS class ID, put # symbol followed by a desired name of class ID

#contentsection {
  height: 767px;
  width: 1003px;
  margin: auto;
  padding: 0px;
  background-position:center center;
}

using it like this for instance

  <div id="contentsection"></div>

It will create a div section on the page with defined properties in the Class ID.

Now what is the difference between these two types of classes which works almost same.

The main difference between these two types of CSS declaration is that class ID can be used only once as it is just as unique identifier for a person which can only be a one person with one ID. But class can be used multiple times in your body of the page. So class is used when you want to apply that css style to a item which will be used many times but if one time then you can use ID. Also when calling class ID in a tag you must specify it by calling its ID property like this

  <div id="contentsection">

but when calling a class we use class property

  <p class="textcolor">

Hyper Text Transfer Protocol

HTTP is a foundation of communication on internet considering a client-server model. It is used to transfer or exchange hypertext by building network using links called hyperlinks.

Client may be a browser and the website can be a server. The client request through a message using HTTP to the server which uses HTML and provides a response in the form of status of the request and it can be a content with a message or data.

A HTTP client sends a request by building a TCP connection and HTTP waits for a request, after receiving the request a response from the server is made to the client by which the request-response clock starts which make up a HTTP session. Unless a clock of request-response is not stopped a session is alive else it is killed.

A response can be a HTML web page which is displayed on the client browser.

Domain Name Servers

DNS is a system which is used by the computers and devices using internet to assign the IP addresses to the domain names. The Internet is based on the IP addresses therefore it requires that a domain name must me translated into IP address so it is easily located.

DNS works like a phone book as it assigns a IP address to a domain name so that computer can communicate to the domain selected. But unlike phone book it updates it self without effecting the end user.

When a system is connected to home network (ISP) it sends the information to router which assigns the network address which also includes the DNS information so that it can acknowledge when to translate the domain name to IP address.

It is easy to remember the alphabetical names of the domain such as http://www.example.com rather than the IP address such as  70.42.251.42.

You can avoid the look up process performed by the browser when you put in a domain name e.g http://www.google.com  (try it) by directly providing the IP address of that domain.

DNS translates these domain names using a huge database also assigning the time allocated for the domain name  hence there are multiple addresses are assigned to a single domain name.

File Transfer Protocol

FTP is used to transfer files and web pages to server over a TCP based network such as internet. FTP is used to upload and download files from the server to the simple client development machine. It has separate controls and connections using user name and password authentication to connect to server and upload and download files.

There are some FTPs which allows to enter the server without authentication of any username and password valid, therefore might verify for the email address but it makes un-secure way of connecting to the server.

Design a site like this with WordPress.com
Get started