-
Introduction
A big part of this module is about programming!
You will have to demonstrate programming skills in relation to building an Android App for a device such as a Smartphone.
Programming Activities
- Android Application Structure
- Basic Graphical Components
- Laying out the Components in an Application
Algorithms and Data Structures
Location Services
- Android
- Android is the target platform
- Support for development is provided via specific API’s
- Applications are run on an “Emulator”
- Android Studio
- Android Studio is a special tool called an Integrated Development Environment (IDE)
- Android Studio provides wizards to take the “drudgery” out of developing applications
- Download Android Studio using the link below or using steps shown on the getting started workbook provided at the footnote.
Android Resources
You can download android studio using this link: 🔗 http://developer.android.com/index.html
-
What is Android?
According to the Android Developer Guide “Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.”
Target Platform
The target platform for your work will be a “mobile phone” sized device. So think “SmartPhone”
Android Developer Tools
- Android also provides a set of tools for the developer which includes a
- compiler
- debugger
- device emulator
- Java Virtual machine (The Dalvik Virtual machine)
- Set of additional tools (dk,aapt etc.)
Android Guides
- See the handouts entitled
- “Android Development – Guide 1 The Basic Overall Picture of an Android Application”
- “Android Development – Guide 2 Listeners, Event Handling and Debugging”
- Programming Techniques
- Object Oriented Programming
- Event Driven Programming
- Android Project
- Android uses XML to describe the layout of the visual components
- You write the XML directly by hand
- Use a “designer” to create the appearance and let the “designer” create the XML on your behalf
- Code is written in Java
Graphical User Interface
o create graphical user interface, you will need xml code and java code. XML code will be used for positioning/layout of the specified design using XML and use the graphical layout viewer in Android to view the layout as you create it. The main.xml is used to describe the initial layout of the interface for the application.
In addition to this, you still need to “link” the components to the Java code that you will be producing. So to do this, you will need to write Java code to “get” the objects created in xml.
Click on the Code tab to explore xml code and java code.
-
Using Colour
- Colour is a very useful and often needed feature in any application. You can change the colour of various parts of your application at:
- Design Time
- Run Time
Changing Background Colour
The following line of code is used to change background colour of the android visual device.
android:background=“color/LemonChiffon”
Changing Background Colour
There are a number of different ways that a background or a text colour can be set. You can do so by using an rgb colour for example by embedding the following line of code in your java code.
mainView.setBackGroundColor(Color.rgb(200,0,0));
Colour transparency could be achieved by adding additional value when using an rgb colour code as can be seen in the following example.
mainView.setBackGroundColor(Color.argb(0,200,0,0);
A hexadecimal value could also be used to specify the rgb values as shown of the example code below.
mainView.setBackGroundColor(Color.parseColor(“#ffffff”));
Colour
There be some occasions where it is useful to use predefined colours in a resource file. For example XML resource files for the W3C schools defined colours and the X11 defined colours. A resource definition of a colour could be used to achieve this, for example:
mainView.setBackgroundColor(getResources().getColor(R.color.silver,this));
-
Changing Text attributes
There are many ways in which changing text attributes could be achieved. First is by using Android studio or in java code.
For example, by using the following code you could change text colour.
android:textColor=“color/Black”
As for text size the following code could be amended
android:textSize=“25sp”
For changing Text Style, the following line of code could be used.
android:textStyle=“bold|italic”
Text size Units
- The units for the size of the text can be specified in a number of ways:
- sp (scaled pixels),
- px (pixels),
- dp (density-independent pixels),
- in (inches),
- mm (millimeters).
However, the best practice is to use the sp unit so the size can scale depending on user settings.
Text Colour in Java
You can make use of setTextColour function to change the colour of the text in a component in the same way that you used setBackGroundColor.
TextView caption could also be used for changing text colour in Java by making use of setTextColor code, example:
caption = (TextView)findViewById(R.id.topCaption) caption.setTextColor(Color.BLACK);
Fonts
- Android devices are usually equipped with 3 standard fonts. The fonts identified in the bullet list are optimised for use in mobile devices.
- Droid Sans (sans | normal)
- Droid Sans Mono (monospace)
- Droid Sans Serif (serif)
Firstly you will need to specify the font that you want to use with a particular component by means of the android:typeface attribute in an appropriate XML file example:
android:typeface=”sans”
Then you would set Fonts attributes like:
TextView tbox1 = (TextView)findViewById(R.id.textBox1); tbox1.setTypeface(“sans”);
-
Basic Graphical Components
TextView
Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however, the basic class is configured to not allow editing; see EditText for a subclass that configures the text view for editing.
EditText
EditText is a thin veneer over TextView that configures itself to be editable.
Button
Represents a push-button widget. Push-buttons can be pressed, or clicked, by the user to perform an action.
What’s next
Looking ahead to week 2, you should make sure that you read the third paper “Interacting with 21st Century Computers”. This will be needed for the Tutorial. You should also be thinking through how the material covered in the lectures can be applied to assignment that you have been tasked with.