Read the pdf attached!!
Need only half of the assignment done so am attaching the required parts/brackets that need to be completed.
Need to use custom view in android.
Microsoft Word - Document1 Building a bubble level application that integrates with sensors NEED ONLY 4 BRACKETS TO BE DONE HAVE MENTIONED BELOW. In this assignment you will be required to build a bubble level (sometimes known as a spirit level) application. The idea is that this allows an android device to measure how flat, level, or vertical surfaces are. You will be required to use the sensors on the device to determine the orientation of the device and to display one of two custom views for the application. Using a flat table as the reference plane you will need the following views.: • The device is lying at on the table. It should show a circular bubble level with the bubble able to move in two dimensions. A bubble in the exact centre indicates a perfectly level surface. • The device is perpendicular to the table in either portrait or landscape. It should show a single bubble level. The bubble may only move left or right. A bubble in the exact middle indicates a surface that is either perfectly at or perfectly vertical. The score for your application will depend on: 1. How fully featured, complete, and robust your code is. Along with how well your UI is thought out 2. How well documented is your code Coding Brackets (80%) 1. Bracket 1 (10%) • Basic layout that is responsive to changes in orientation. • Basic shell of both custom views. 2. Bracket 2 (20%) • Addition of listener(s) that will collect the necessary sensor data to determine the orientation of the device. • Last 500 samples of sensor data is kept in a datastructure and maintained. 3. Bracket 3 (30%) • Working bubble level custom view for the 1D case (device in land- scape or portrait mode) that has a range of [-10, 10] degrees. • Working bubble level custom view for the 2D case that has a range of [-10, 10] in both directions. 4. Bracket 4 (40%) • UI elements that show the maximum and minimum values encountered in the last 500 samples for the 1D case. • UI elements that show the maximum and minimum values encountered in the last 500 samples for the 2D case in both directions. Android By Example, Faculty of Computing, Griffith College Dublin Android By Example Introduction: In this text I aim to give you a good introduction to the fundamentals of android programming. I will also give an introduction to things like sensors and GPS. The reason why I consider this an introductory text is because there is a vast amount of things that are possible with android devices and I could not possibly cover it all. In this text I will deal with the fundamental skills of creating and managing the android UI along with generating your own custom controls. I will also touch on things like Google Maps, customising already provided widgets, network communication etc. My style of teaching is with full code examples. If you wish you can copy paste these examples into your development environment. However, I think this is the worst way that you could use these examples. I would highly recommend writing out the examples line by line yourself. This will enable you to notice the coding patterns that appear frequently in Android development. It will also develop your muscle memory such that you will experience less cognitive load when you are building your own Android projects. Those of you who come from a Java Swing or JavaFX programming background will also find multiple aspects of Android development familiar and reassuring. Above all else I hope you enjoy this small foray into the world of Android :) My Development Environment For all of the examples in this book I am using the Eclipse IDE (Kepler 4.3 with Java 8 support) with the Android Developer Tools (ADT) plugin (version 23.0.2). The android SDK (version 23.0.2) I have installed has support for API 20 (Android KitKat 4.4 Wear) and I will be using this for the target environment. The minimum API version that these examples will run on is API 14 (Android 4.0 Ice Cream Sandwich) this was the last major change to the API and devices using a previous API I consider vastly out of date. All screenshots that you see in this text are taken from a Nexus 7 running Android 4.4.4 Differences with the first edition. The previous edition of this text I considered to be a scattershot approach there was no real organisation to the examples plus it also had some incomplete examples. I also spent far to long introducing things like string resources, colour resources etc. These have been merged and cut down to give me more space for examples that deal with networking, etc. © Barry Denby Page 1 Android By Example, Faculty of Computing, Griffith College Dublin I've also given more concrete examples with sensors as the previous edition only introducted them but never gave much use to them. I will also give more information as to where and when you should expect an application to compile. This way you will be able to see the application building before your eyes and watch how the various components of code will modify and enhance the application. © Barry Denby Page 2 Android By Example, Faculty of Computing, Griffith College Dublin Example 001: Hello world in android In this example we will use the default code that is generated for an android project by the Eclipse ADT plugin. As with any programming language or API tutorial we will start with the hello world example. You can see this in the screenshot below. I will also introduce the code and the basic structure of an android application as well. 01) Generate a new android project with a blank activity. 02) In your project navigate to res/layout/activity_main.xml and you should see the following XML code if you are using a different development environment you should put this code in that file
© Barry Denby Page 3 Android By Example, Faculty of Computing, Griffith College Dublin Explaination: • The preferred method to constructing activity layouts is to use XML layout files. While it is possible to construct layouts through Java code alone, I can tell you from experience that it is messy and is less powerful than the options that the XML versions of layouts will provide. The layout we see here is a relative layout which we will cover in a lot more detail later. It is considered one of the most versitile of layouts • All activity layouts must have a single layout as the root of the layout file. In this layout the root tags are considerd to be
and • All tags will have associated attributes that are used to change the behaviour of the control we will go through some of these attributes for the Relative layout later when we come to layouts. However we will detail some of the most important ones now ◦ The xmlns:android attribute this is a standard attribute that will appear in the root node of all layouts. It is required for layouts to work. This is the same for all layouts and mandatory in the root layout. ◦ android:layout_width, android:layout_height. This determines how much space the layout will use in terms of width and height. You may specify either match_parent or wrap_content here. match_parent specifies that the contents of this layout should take the full width (or full height for android:layout_height) of the parent layout. The root layout should always specify match_parent for both the width and height as activities in android are by default full screen. ▪ wrap_content tells the layout or view that it should take the minimum amount of space (in either width or height) to display it's contents. Textviews are normally set to wrap_content in both directions as they will not use any extra space. • If you look inside the RelativeLayout tags you will see another single tag called a TextView. Widgets in Android are called Views. The TextView simply displays a piece of non interactive text. All views are written as a single tag whereas layouts are written as a pair of tags. This is a convention used throughout android to make it easier to recognise views from layouts. ◦ if you look inside the TextView tag you will find an attribute called android:text. this sets the text that will show on the TextView. ◦ Here you will see that it is set to android:text="@string/hello_world". Android applications are split into two sections: code resources (where all your Java files are held) and non-code resources (strings, colours, images, static files etc). In fact the XML layout file you are looking at © Barry Denby Page 4 Android By Example, Faculty of Computing, Griffith College Dublin now is considered a non-code resource. ◦ the @string/ part states that we are looking for a string resource. while hello_world specifies the name of the string resource we are looking for. If you take a look in res/values/strings.xml you will see the string resource for hello_world ◦ we will go into depth on string resources soon. 03) In your project navigate to src/
/MainActivity.java and you should see the following Java code. If you are using a different development environment you should put this code in that file. package com.example.example001; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true;