Wednesday 25 November 2015

AcidSQL Application Avaiable on Google Play Store

What is ACID ?

Database ACID (Atomicity, Consistency, Isolation, Durability) Properties


There are a set of properties that guarantee that database transactions are processed reliably, referred to as ACID (Atomicity, Consistency, Isolation, Durability).

Atomicity

Atomicity refers to the ability of a database to guarantee that either all of the tasks are performed or none of them are. Database modifications must follow an all or nothing rule. Each transaction is said to be atomic if when one part of the transaction fails, the entire transaction fails.

Consistency

The consistency property ensures that the database remains in a consistent state before the start of the transaction and after the transaction is over.

A distributed data system is either strongly consistent or has some form of weak consistency

Weak consistency is sometimes referred to as eventual consistency, the database eventually reaches a consistent state. Weak consistency systems are usually ones where data is replicated; the latest version is sitting somewhere in the cluster, older versions are still out there. Eventually all nodes will see the latest version.

Isolation

Isolation refers to the requirement that other operations cannot access or see the data in an intermediate state during a transaction. This constraint is required to maintain the performance as well as the consistency between transactions in a database.

Durability

Durability refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone. This means it will survive system failure, and that the database system has checked the integrity constraints and won't need to abort the transaction.

Durability does not imply a permanent state of the database. Another transaction may overwrite any changes made by the current transaction without hindering durability.


With the AcidSQL App you can can connect to databases, make queries, execute SQL commands
view results grpahically, show tables. edit registers, delete registers and tables, view database, specifications


AcidSQL is compatible with Microsoft SQL Server, MySQL and PostgreSQL databases.

Click on the link to download now on your Android device.

Get it on Google Play

Saturday 25 July 2015

Windows Phone Simple C# Calculator App


Windows Phone using Visual Studio Silverlight for Windows Phone

Background on .NET and C#

The .NET framework is the central concept behind Visual Studio 2010. It consists of two main elements the Common Language Runtime (CLR) in which the application is executed and the set of libraries called the .NET Framework Class Libraries which provides functional support of the code needed.  The .NET programs are written in C++ /CLI and C# i.e. any language that supports the .NET framework.
.Net is a collection of dynamically linked libraries (DLLs), these DLLs are many times already installed on Windows.

We can see from the above image a 6 is displayed as the running total.

using System;//using statement obtains one or more resources
using System.Collections.Generic;//This contains interfaces and classes that define generic collections,
using System.Linq;//provides classes and interfaces that support queries that use Language-Integrated Query 
using System.Net; //provides a simple programming interface for many of the protocols used on networks
using System.Windows;//Provides the ability to create, configure, show, and manage the lifetime of windows and dialog boxes.
using System.Windows.Controls;//Represents the base class for user interface (UI) elements 
using System.Windows.Documents;//Contains types that support XML Paper Specification (XPS) document creation
using System.Windows.Input;//Provides types to support the Windows Presentation Foundation (WPF) input system
using System.Windows.Media;//Provides types that enable integration of media, including drawings, text etc
using System.Windows.Media.Animation;//Provides types that support property animation functionality
using System.Windows.Shapes;//Provides access to a library of shapes that can be used in(XAML)
using Microsoft.Phone.Controls;//Provides controls for use in Window Phone Apps

//namespace keyword used to declare scope that contains set of related objects
namespace Lab3_Calculator_App
{   // by declaring partial class we can seperate class into multiple files
    // MainPage inherits from class PhoneApplicationPage, controls Windows Phone projects
    public partial class MainPage : PhoneApplicationPage 
    {
        const int TRUE = 1; // TRUE in constant variable set to 1
        const int FALSE = 0;// FALSE in constant variable set to 0
        static int newvalue = TRUE; // static variable is associated with class itself rather than instance of class
        static float runningTotal = 0; //running total set to default value of 0
        static char previousOp = '+'; //previous operator  always set to plus

        // Constructor to initialize component
        // public keyword means the method is visible from outside the class
        public MainPage()
        {
            //Initialize component method contains code that initialize user 
            //interface objects using property grid from form designer.
            InitializeComponent();
        } // end of main page() method
        
        //start of method button0_Click
        //object sender refers to the object the invoked the event
        //RoutedEventArgs Gets or sets a reference to the object that raised the event
        private void button0_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE) // if newvalue is first value to be pressed
            {
                textBox1.Text = "0"; // set text box string to 0
                newvalue = FALSE; // now 0 is no longer first integer
            }
            else // else add 0 to current value in the text box
            {
                textBox1.Text += "0"; // 0 is added to current value in text box
            } // end of if else statement
        } // end of button0_Click method
        
        //start of method button1_Click
        //object sender refers to the object the invoked the event
        //RoutedEventArgs Gets or sets a reference to the object that raised the event
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE) // if newvalue is first value to be pressed
            {
                textBox1.Text = "1"; // set text box string to 1
                newvalue = FALSE; // now 1 is no longer first integer
            }
            else // else add 1 to current value in the text box
            {
                textBox1.Text += "1"; // 1 is added to current value in text box
            }// end of if else statement
        }// end of method button1_Click
        
        //start of method button2_Click
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE) // if newvalue is first value to be pressed
            {
                textBox1.Text = "2"; // set text box string to 2
                newvalue = FALSE;// now 2 is no longer first integer
            }
            else // else add 2 to current value in the text box
            {
                textBox1.Text += "2"; // 2 is added to current value in text box
            }// end of if else statement
        }// end of method button2_Click
        
        //start of method button3_Click
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE) // if newvalue is first value to be pressed
            {
                textBox1.Text = "3"; // set text box string to 3
                newvalue = FALSE; // now 3 is no longer first integer
            }
            else // else add 2 to current value in the text box
            {
                textBox1.Text += "3";  // 3 is added to current value in text box
            } // end of if else statement
        }// end of method button3_Click
        
        //start of method button4_Click
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)  // if newvalue is first value to be pressed
            {
                textBox1.Text = "4"; // set text box string to 4
                newvalue = FALSE;  // now 4 is no longer first integer
            }
            else // else add 4 to current value in the text box
            {
                textBox1.Text += "4"; // 4 is added to current value in text box
            }// end of if else statement
        }// end of method button4_Click
        
        //start of method button5_Click
        private void button5_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE) // if newvalue is first value to be pressed
            {
                textBox1.Text = "5"; // set text box string to 5
                newvalue = FALSE;// now 5 is no longer first integer
            }
            else// else add 5 to current value in the text box
            {
                textBox1.Text += "5";// 5 is added to current value in text box
            }// end of if else statement
        }// end of method button5_Click
        
        //start of method button6_Click
        private void button6_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)//if newvalue is first value to be pressed
            {
                textBox1.Text = "6";//set text box string to 6
                newvalue = FALSE;// now 6 is no longer first integer
            }
            else// else add 6 to current value in the text box
            {
                textBox1.Text += "6";//6 is added to current value in text box
            }// end of if else statement
        }// end of method button6_Click

        private void button7_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)
            {
                textBox1.Text = "7";
                newvalue = FALSE;
            }
            else
            {
                textBox1.Text += "7";
            }
        }

        private void button8_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)
            {
                textBox1.Text = "8";
                newvalue = FALSE;
            }
            else
            {
                textBox1.Text += "8";
            }
        }
        

        private void button9_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)
            {
                textBox1.Text = "9";
                newvalue = FALSE;
            }
            else
            {
                textBox1.Text += "9";
            }
        }

        //start of method buttopoint_Click
        private void buttopoint_Click(object sender, RoutedEventArgs e)
        {
            if (newvalue == TRUE)//if newvalue is first value to be pressed
            {
                textBox1.Text = ".";//set text box string to point
                newvalue = FALSE;// now point is no longer first integer
            }
            else// else add point to current value in the text box
            {
                textBox1.Text += ".";//point is added to current value in text box
            }// end of if else statement
        }  // end of method buttopoint_Click
        
        //start of method plus_button_click
        //private method means it not visible from outside of the class
        private void plus_button_click(object sender, RoutedEventArgs e)
        {
            float rez1; // local variable to store result1
            rez1 = System.Convert.ToSingle(textBox1.Text);// rez1 is given converted string contained within textbox
            //method ToSingle Converts the specified string representation of a number to 
            //an equivalent single-precision floating-point number.
            //parameters passed to method ToSingle is text of textbox1
            switch(previousOp) //  switch statement to control selection of operators
            {
                case '+':
                    runningTotal = runningTotal + rez1;//current result is added to running total
                    break;//The break statement terminates the closest enclosing switch statement 
                case '-':
                    runningTotal = runningTotal - rez1;//current result is subtracted to running total
                    break;//The break statement terminates the closest enclosing switch statement 
                case '/':
                    runningTotal = runningTotal / rez1;//current result is divide to running total
                    break;//The break statement terminates the closest enclosing switch statement 
                case '*':
                    runningTotal = runningTotal * rez1;//current result is multiplied to running total
                    break;//The break statement terminates the closest enclosing switch statement 
                case '=':
                    break;//The break statement terminates the closest enclosing switch statement 
            }
            textBox1.Text = runningTotal.ToString(); // runningTotal is put on textbox but first is converted to the
                                                     // the runningTotal from float to string
            newvalue = TRUE; // new value is now true
            previousOp = '+'; // previousOp is set to plus
        }// End of method plus_button_click
         
        //start of method subtract_button_click
        private void subtract_button_click(object sender, RoutedEventArgs e)
        {
            float rez1;// local variable to store result1
            rez1 = System.Convert.ToSingle(textBox1.Text); // rez1 is given converted string contained within textbox
            //method ToSingle Converts the specified string representation of a number to an equivalent single-precision floating-point number.
            //parameters passed to method ToSingle is text of textbox1
            switch(previousOp) //  switch statement to control selection of operators
            {
                case '+':
                    runningTotal = runningTotal + rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '-':
                    runningTotal = runningTotal - rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '/':
                    runningTotal = runningTotal / rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '*':
                    runningTotal = runningTotal * rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '=':
                    break;//The break statement terminates the closest enclosing switch statement 
            }
            textBox1.Text = runningTotal.ToString();// runningTotal is put on textbox but first is converted to the
                                                     // the runningTotal from float to string
            newvalue = TRUE;// new value is now true
            previousOp = '-';// previousOp is set to minus
        }//End of method subtract_button_click
     
        //start of method divide_button_click
        private void divide_button_click(object sender, RoutedEventArgs e)
        {
            float rez1;// local variable to store result1
            rez1 = System.Convert.ToSingle(textBox1.Text);// rez1 is given converted string contained within textbox
            //method ToSingle Converts the specified string representation of a number to an equivalent single-precision floating-point number.
            //parameters passed to method ToSingle is text of textbox1
            switch(previousOp) //  switch statement to control selection of operators
            {
                case '+':
                    runningTotal = runningTotal + rez1;
                    break;
                case '-':
                    runningTotal = runningTotal - rez1;
                    break;
                case '/':
                    runningTotal = runningTotal / rez1;
                    break;
                case '*':
                    runningTotal = runningTotal * rez1;
                    break;
                case '=':
                    break;
            }
            textBox1.Text = runningTotal.ToString();// runningTotal is put on textbox but first is converted to the
                                                     // the runningTotal from float to string
            newvalue = TRUE;
            previousOp = '/';// previousOp is set to divide
        //End of method divide_button_click
        
        //start of method multiply_button_click
        private void multiply_button_click(object sender, RoutedEventArgs e)
        {
            float rez1;// local variable to store result1
            rez1 = System.Convert.ToSingle(textBox1.Text);// rez1 is given converted string contained within textbox
            //method ToSingle Converts the specified string representation of a number to 
            //an equivalent single-precision floating-point number.
            //parameters passed to method ToSingle is text of textbox1
            switch(previousOp) //  switch statement to control selection of operators
            {
                case '+':
                    runningTotal = runningTotal + rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '-':
                    runningTotal = runningTotal - rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '/':
                    runningTotal = runningTotal / rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '*':
                    runningTotal = runningTotal * rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '=':
                    break;//The break statement terminates the closest enclosing switch statement 
            }
            textBox1.Text = runningTotal.ToString();// runningTotal is put on textbox but first is converted to the
                                                     // the runningTotal from float to string
            newvalue = TRUE;
            previousOp = '*';// previousOp is set to multiply
        }// end of method multiply_button_click  

        private void equals_button_click(object sender, RoutedEventArgs e)
        {
            float rez1;// local variable to store result1
            rez1 = System.Convert.ToSingle(textBox1.Text);// rez1 is given converted string contained within textbox
            //method ToSingle Converts the specified string representation 
            //of a number to an equivalent single-precision floating-point number.
            //parameters passed to method ToSingle is text of textbox1
            switch(previousOp) //  switch statement to control selection of operators
            {
                case '+':
                    runningTotal = runningTotal + rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '-':
                    runningTotal = runningTotal - rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '/':
                    runningTotal = runningTotal / rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '*':
                    runningTotal = runningTotal * rez1;
                    break;//The break statement terminates the closest enclosing switch statement 
                case '=':
                    break;//The break statement terminates the closest enclosing switch statement 
            }
            textBox1.Text = runningTotal.ToString();// runningTotal is put on textbox but first is converted to the
                                                     // the runningTotal from float to string
            newvalue = TRUE;
            runningTotal = 0;
            previousOp = '+';
        }

        private void cancel_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text = ""; //text box is cleared when cancel is clicked
            runningTotal = 0; // running total is set 0 with screen cleared
        }

        private void Calculator_Loaded(object sender, RoutedEventArgs e)
        {

        }
    } // end of  public partial class MainPage
}// end of scope of namespace Lab3_Calculator_App 

<phone:PhoneApplicationPage 
    x:Class="Lab3_Calculator_App.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" Name="Calculator" Loaded="Calculator_Loaded" d:DesignHeight="768" d:DesignWidth="480">
    <phone:PhoneApplicationPage.BorderBrush>
        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
            <GradientStop Color="Black" Offset="0" />
            <GradientStop Color="#FFFF7C7C" Offset="1" />
        </LinearGradientBrush>
    </phone:PhoneApplicationPage.BorderBrush>
    <!--LayoutRoot is the root grid where all page content is placed-->
    <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="Calculator" Style="{StaticResource PhoneTextNormalStyle}" TextAlignment="Center" Foreground="White" TextWrapping="NoWrap" OpacityMask="#FF77E8CC" FontFamily="Segoe WP SemiLight" FontWeight="Normal" FontSize="24" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,133,12,0">
            <Button Content="1" Height="75" HorizontalAlignment="Left" Margin="12,79,0,0" Name="button1" VerticalAlignment="Top" Width="113" Foreground="WhiteSmoke" BorderBrush="#FFF8F8F8" Click="button1_Click" OpacityMask="#FFE10606" BorderThickness="4">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFCFF74" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="2" Height="75" HorizontalAlignment="Left" Margin="131,79,0,0" Name="button2" VerticalAlignment="Top" Width="111" Click="button2_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF77" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="3" Height="75" HorizontalAlignment="Left" Margin="242,78,0,0" Name="button3" VerticalAlignment="Top" Width="114" Click="button3_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFCFC27" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="4" Height="75" HorizontalAlignment="Left" Margin="12,176,0,0" Name="button4" VerticalAlignment="Top" Width="113" Click="button4_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF2F" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="5" Height="75" HorizontalAlignment="Left" Margin="131,176,0,0" Name="button5" VerticalAlignment="Top" Width="111" Click="button5_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF58" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="6" Height="75" HorizontalAlignment="Left" Margin="242,175,0,0" Name="button6" VerticalAlignment="Top" Width="114" Click="button6_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF08" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="9" Height="75" HorizontalAlignment="Left" Margin="242,267,0,0" Name="button7" VerticalAlignment="Top" Width="114" Click="button9_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF33" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="7" Height="75" HorizontalAlignment="Left" Margin="12,268,0,0" Name="button8" VerticalAlignment="Top" Width="113" Click="button7_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFE6FF00" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="8" Height="75" HorizontalAlignment="Left" Margin="131,268,0,0" Name="button9" VerticalAlignment="Top" Width="111" Click="button8_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFE54E" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="." Height="75" HorizontalAlignment="Left" Margin="131,369,0,0" Name="button10" VerticalAlignment="Top" Width="111" Click="buttopoint_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF27" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="C" Height="74" Margin="345,369,0,0" Name="button11" VerticalAlignment="Top" Click="cancel_Click" HorizontalAlignment="Left" Width="111">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF17" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="0" Height="75" HorizontalAlignment="Left" Margin="12,369,0,0" Name="button12" VerticalAlignment="Top" Width="116" Click="button0_Click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="Yellow" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="+" Height="75" HorizontalAlignment="Left" Margin="346,78,0,0" Name="button13" VerticalAlignment="Top" Width="110" Click="plus_button_click" BorderBrush="White" Foreground="White">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFEFEF00" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="-" Height="75" HorizontalAlignment="Left" Margin="346,175,0,0" Name="button14" VerticalAlignment="Top" Width="110" Click="subtract_button_click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF22" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="*" Height="75" HorizontalAlignment="Left" Margin="345,0,0,216" Name="button15" VerticalAlignment="Bottom" Width="111" Click="multiply_button_click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF12" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="/" Height="75" HorizontalAlignment="Left" Margin="242,368,0,0" Name="button16" VerticalAlignment="Top" Width="114" Click="divide_button_click">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFFFF2F" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button Content="=" Height="78" HorizontalAlignment="Center" Margin="12,449,207,0" Name="button17" VerticalAlignment="Top" Width="237" Click="equals_button_click" BorderThickness="3" FontSize="28" FontWeight="Thin" FontStyle="Normal" FontStretch="SemiCondensed" Foreground="White" HorizontalContentAlignment="Center">
                <Button.Background>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Black" Offset="0" />
                        <GradientStop Color="#FFFAFF00" Offset="1" />
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Grid.Background>
                <ImageBrush ImageSource="/Lab3_Calculator_App;component/Images/Bliss_Clean_by_mtspknwildcat.jpg" />
            </Grid.Background>
        </Grid>
        <TextBox Height="149" HorizontalAlignment="Left" Margin="0,55,0,0" Name="textBox1" Text="0" VerticalAlignment="Top" Width="468" BorderBrush="#BFFFFFFF" TextAlignment="Right" FontSize="40" TextChanged="textBox1_TextChanged" Grid.RowSpan="2" OpacityMask="#FFFF1717" AllowDrop="False">
            <TextBox.CaretBrush>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="#FFFF8383" Offset="1" />
                </LinearGradientBrush>
            </TextBox.CaretBrush>
            <TextBox.Background>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="#FF96FFFF" Offset="1" />
                </LinearGradientBrush>
            </TextBox.Background>
        </TextBox>
    </Grid>
 
    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage> 
 
 
You can download entire project in link below:
 
https://github.com/JunSoftware109/Mobile-Applications/tree/master/Windows%20Phone%20Apps/Lab3_Calculator_App 

Thursday 25 June 2015

Dr Hearing Open Source Project

Disclaimer: the following post contains extracts from my final year thesis and may not be re-used in any form or fashion without my permission, thank you for reading..









Project DHOSP - What is DHOSP?
Dr Hearing Open Source Project was my final year project which was designed to identify hearing impairments in adults. The project was completed but lacked a production quality standard for publication, so apart of my project scope was to bring the project to my fellow colleagues and developers so that we may develop the best Android application for identifying hearing deficiencies.

So what is a hearing test?

A hearing test provides a methodology to diagnose an individual’s hearing impairment or deficiencies. ISO 8253-1:2010 is an international standard for PTA (Pure Tone Audiometry). This standard specifies procedures and requirements for PTA air conduction and bone conduction. Pure tone audiometry is the measurement of an individual’s hearing across a range of test frequencies using a standardized test method that specifies the procedure for determining the threshold, the range of test frequencies and presentation levels, and the way thresholds are presented in a graphical manner and including the symbols user to depict objects. We use PTA to evaluate possible hearing losses and to determine the type of hearing loss that an individual may have.



Hearing loss can be defined as the amount a person’s hearing level changes as a result of some adverse influence. This means that some structure or function of the ear that is crucial to hearing has been damaged.


There are three main forms of hearing loss; Sensor neural affecting the cochlea, Conductive hearing loss affecting the ear canal and mixed hearing loss which is a combination of both sensor neural and conductive hearing loss.


The World Health Organization (WHO) defines “disabling hearing impairment in adults as a permanent unaided hearing threshold level (average for frequencies 0.5, 1, 2, 4 kHz) for the better ear of 41 dB or greater (WHO, 2001).2 In children under 15 years of age, disabling hearing impairment is defined as permanent unaided hearing threshold level (average for frequencies 0.5, 1, 2, 4 kHz) for the better ear of 31 dB or greater.”


The auditory pathway includes the external ear, the middle ear and the inner ear, followed by the auditory nerve ending up in the auditory centres in the auditory cortex.




· The external ear consists of the pinna, ear canal and eardrum. Sound travels down the ear canal, through the eardrum and causing it to move or vibrate.


· The middle ear is a space behind the eardrum that contains three small bones called ossicles. This string of tiny bones is connected to the eardrum at one end and to the oval window at the other end which connects to the inner ear. Vibrations from the eardrum cause the ossicles to vibrate which, in turn, creates movement of the fluid in the inner ear.


· Movement of the fluid in the inner ear, or cochlea, causes changes in hair cells. This movement of the hair cells sends electric signals from the inner ear up the auditory nerve to the brain.


What is an Audiogram?



An audiogram plots decibel (dB) values on the Y-Axis. If a loss of hearing is present then the graph will have higher points with increased dB signal where the person is having difficulty hearing the tone. The more severe the hearing loss the more the dB values on the graph will going downwards. On the X-Axis we have the plotting of the frequency pure tones in hertz (Hz). An Audiogram usually plots sound on the left lowest 125Hz and increasing to 8000 KHz.

Purpose of the Project
The purpose of this project was to develop an application that would help identify common hearing impairment by using an audiogram which would picture how a person hears. The audiogram is used to describe the hearing of a person across different frequencies. It can be used as a tool to determine amount of damage done or determine the cause.

Goal of the Project
The goal of the project was to develop and application to determine hearing impairments in adults.

Motivation
An easy and simple application that will allow users to quickly do hearing tests for an assessment, where they get results by reading the audiogram.

Considerations
The problem of hearing impairment is an increasing problem across most populations of the world and is something that people should be aware of and by taking hearing tests they can be made more aware of their own level of hearing and how to best keep it healthy. In the EU it is estimated that more than 55 million people are having hearing impairments and the costs in the EU is estimated to 160 billion Euros per year. According to a study, a mild hearing loss costs 2000 euros per individual each year, a moderate costs 6,600 and severe 11,000 euros.

From the above studies we can see that it is a problem that needs to be carefully analyzed and more research needs to be done.

Measurement
The advantage brought to users through this application is that it provides free and quick self-test ability. Where-as many Android applications or web applications require connection to the internet using databases, this current project does all processing locally on the users device.






System Implementation


Android Activities
An activity represents a single screen that the user sees on the device. An application usually consists of multiple activities. Activities are the most observable part of the application. In Android, you can be looking at an activity of one application, but shortly after you could start another activity in a completely separate application. For example, if you are in the Calendar application and you decide to call a friend, you would be launching the activity to bring up the phone application in the Calendar application.


Android life-cycle
Activity can be expensive on the device CPU and RAM. It can sometime involve creating a new Linux process, allocating memory for all the new objects, inflating the objects from XML layouts, and setting up the screen. In Android the activity life cycle is managed by the Activity Manager.

Activity Manager is responsible for creating, destroying, and managing activities. For example, when the user starts an application for the first time, the Activity Manager will create its activity and put it onto the screen. Later, when the user switches screens, the Activity Manager will move that previous activity to a holding place. This way, if the user wants to go back to an older activity, it can be started more quickly. Older activities that the user hasn’t used in a while will be destroyed in order to free more space for the currently active one. This mechanism is designed to help improve the speed of the user interface and thus improve the overall user experience.

Programming for Android is conceptually different than programming for some other environments. In Android, you find yourself responding more to certain changes in the state of your application rather than driving that change yourself. It is a managed, container-based environment similar to programming for Java applets or servlets. So, when it comes to an activity life cycle, you don’t get to say what state the activity is in, but you have plenty of opportunity to say what happens during the transitions from state to state. The figure below shows the states that an activity can go through.



Managing the lifecycle of activities by implementing call-back methods is crucial to developing a strong application. The lifecycle of an activity is directly affected by its association with other activities,

Call-back methods are essentially in the three states as follows:

1. Resumed

The activity is in the foreground of the screen and has user focus.

2. Paused

Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity partially transparent,

3. Stopped

The activity is completely hidden by another activity. Figure 26 Diagram of how the methods are called for each button



Each button has as onClick() method which the is specified in the XML file. Once button is clicked, an intent object is created which takes instance of current class and class to be launched. Intents provide the ability to bind classes together which helps us to launch them along.

Another important aspect to activities is declaring them in the Android Manifest because if not declared the application will crash with an exception error. In the Manifest we use an activity tag and pass in location of class in the project package




Implementing Frequency Generator
Generating the pure tone requires the use of basic sine wave. In the Frequency Generator class we create an array of generated sound samples and pass it into the AudioTrack.write function. This function takes data to the audio sink for playback in streaming mode. The byte class is used as it wraps primitive value byte in an object. The encoding scheme is PCM 16 bits per sample. Pulse code modulation encodes an audio waveform in the time domain. The frequency and sample rate measures how many samples are plated each second. We use getChannelConfiguration which return the configured channel configuration



The encoding plays an important role as the byte array is in played in form of audio. The audio track write method takes in three parameters one is the byte array this is the audio data, second is the offset bit and last is the size of the bytes.

We create an object of type short which is a 16-bit signed two’s complement integer. The short class wraps a value of primitive type in an object

Configuring the sample rate 44,100 gives the highest quality sound. We test each pure tone and compare if it sounds is as good.




Implementing Audiogram with Android plot library
In order to render the audiogram we require a comprehensive library to create our audiogram. There are two most popular open source libraries available, both were tried and tested, these included AndroidPlot and GraphView.



After testing both GraphView and AndroidPlot, the latter was more useful as it contained helpful examples and its source code was more understandable. To implement AndroidPlot within the project first we have to include it within the project build path.



The main audiogram is implemented into the HearingTestActivity class. This class contains a method to render XYPlot which we associate with out XYPlot which we declared in our audiogram XML file. We create a reference object of type XYPlot this contains information for the plot XY axis and colour of background. This XYPlot class further inherits from XYSeries, XYSeriesFormatter and XYSeriesRenderer. These are all interfaces or abstract classes which provide impartial or no implementation.




Implementing Fragments
Fragments in android can be described as an activity within an activity. Fragments were chosen as a way to combine multiple activities was required which had different classes acting on single screen view. In the design two fragments were added to one layout view that is the HearingTestActivity. In order to implement this, first a layout view was created for the playtone_fragment this is where the user controls the testing options. The other fragment is then of the audiogram which only draws a XYPlot using the Android plot library. The two fragments are then combined into one layout, the reason for doing this is that we can separate the logic of both classes to their own respected layouts and that once we embed them as fragments, the code is less coupled and not totally dependent on other methods .

The implementation of the fragments was one of the trickiest aspects of the project as it took me a long time to implement. There many of ways to implement fragments a there is no best solution so it was trial and error to discover which method worked best. The method that worked for me was where we had fragments tags declared in the hearing test layout and have a class tag defined and also a tools tag for each fragment. The tools tag defines which layout is rendered and is very important.


To complete the implementation of fragments we create two classes for each xml file. These two classes contain an onCreateView method which inflates the layout into the hearingtest_view.xml activity. The inflater instantiates a layout XML file into the View object. The inflation uses XML file at build time. Last thing to make sure is to include the android-support-v4.jar file in the project build path.



Become a member of Team DHOSP

Link to the project repository : https://github.com/JunSoftware109/AndroidProjectHearing

If you would like to be an official contributor contact me at junmalik109@gmail.com.
I will then have a chat with you and welcome you to the team.

Thanks for reading and goodbye for now!