Mobile Programming Mid-Term

Ace your homework & exams now with Quizwiz!

If you have an image that you want to use in your Android app

,but the file type is not .png, open the image in Microsoft Paint or a similar type of program. You can convert the file type by saving the image as a .png file.

When the user taps an application icon on his or her Android phone or tablet,

,the Main.java code is read by the phone processor

Simplifying User Input

The onscreen keyboard is called a soft keyboard, which is positioned at the bottom of the screen over the application window.

Formatting Numbers

Java includes a class called DecimalFormat that provides patterns for formattingnumbersforoutputon the Android Code Syntax DecimalFormat currency = new DecimalFormat("$###,###.##");

Open Handset Alliance

an open-source business alliance of 80 firms that develop standards for mobile device

preferred unit of measurement

often sp, which stands for scaled-independent pixels.

Package Explorer

on the left side of the Eclipse program window contains the Hello Android World application folders

Linear layout

organizes layout components in a vertical column or horizontal row

The entry point of the Activity class is the onCreate( ) event handler,

which is called a method

File contains the Main class that opens the main.xml screen,

which you designed for the app's user interface

The Android SDK includes three types of button controls:

Button, ToggleButton, and ImageButton

Android Market

Programs written for the Android platform are sold and deployed through an online store

select TextView in the

Form Widgets list

The user interface is in a subfolder of the res folder named

layout.

A Button control is a commonly used

object in a graphical user interface

Coding an onCreate Method

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }

You can create a layout and

then add widgets to the layout

String Array is part of the String table,

which is best to use for text displayed in the application because it can easily be changed without changing code

After you create an application,

you can run it in the Android emulator to test the application and make sure it runs correctly

the default user interface for main.xml

Linear layout

The String table can also be used for localization.

Localization is the use of the String table to change text based on the user's preferred language.

Arithmetic

Order of Operations Highest to Lowest Precedence Description ( ) Parentheses ++ -- Left to right * / % Left to right + - Left to right

Android user interface designers typically use another layout called a

Relative layout

Resolution

Resolution Dots per Inch (dpi) Size (px) ldpi (low-density screen) 120 36 × 36 mdpi (medium-density screen) 160 48 × 48 hdpi (high-density screen) 240 72 × 72 xhdpi (extra high-density screen)* 320 96 × 96 When you publish an app to the Android Market, you must provide a 512 × 512 pixel, high-resolution application icon in the developer console as you upload your program. This icon is displayed in the Android Market to provide a description of the app and does not replace your launcher icon. Vector-based graphics are best to use for icon design because the images can be scaled without the loss of detail and are easily resized.

hdpi

Resources for high-density screens High-density graphicshave 240 dotsper inch

ldpi

Resources for low-density screens Low-density graphics have 120 dots per inch

mdpi

Resources for medium-density screens Medium-density graphics have 160 dots per inch

sp reasoning:

The reason for using this unit of measurement is that if a user has set up an Android phone to display a large font size for more clarity and easier visibility, the font in the app will be scaled to meet the user's size preference

Using the String table

The string items that are displayed in the Spinner control cannot be typed directly in the Properties pane, but instead are created in a values string array in the res/values folder.

Setting the Hint Property for the Text Field

These guidelines can be included in the Hint property of the Text Field control. A hint is a short description of a field that is visible as light-colored text (also called a watermark) inside a Text Field control.

GetSelectedItem( ) Method

To obtain the text name of the concert group that was selected by the user in the Spinner control, you use a method named GetSelectedItem( ).

Pascal case

Using an uppercase letter to begin a Java class name and starting each new word with an uppercase letter

Creating a Button Event Handler

When the user reacts, the app initiates an event, which executes code in an event handler, which is a part of the program coded to respond to the specific event. Code Syntax Button b=(Button)findViewById(R.id.btnRecipe);

Technically, a widget is

a View object that functions as an interface for interaction with the mobile user

layout

a container that can hold as many widgets as needed.

file named strings.xml

a default file that is part of every Android application and contains commonly used strings for an application

guide

a green dashed vertical line that appears when a control is dragged to the emulator window

string

a series of alphanumeric characters that can include spaces.

method

a set of Java statements that can be included inside a Java class.

widget

a single element such as a TextView, Button, or CheckBox control, and is also called an object

import statement

a way of making more Java functions available to your specific program

Spinner control

a widget similar to a drop-down list for selecting a single item from a fixed listing The Spinner control displays a prompt with a list of strings called items in a pop-up window without taking up multiple lines on the initial display.

Layout view

allows you to preview how the controls will appear on various screens and orientations, and the XML view shows you the XML definition of the resource

The syntax needed for an OnClickListener method that listens for the Button control is shown in the following Code Syntax:

b.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub } });

Android phone platform

built on a free operating system primarily created by a company called Android, Inc.

prompt

can be used to display instructions at the top of the Spinner control, can also be stored in strings.xml.

onCreate method

is where you initialize the Activity

XML method is preferred

it allows you to design the user interface of an application without needing to write large amounts of code

Android emulator

lets you design, develop, prototype, and test Android applications without using a physical device

Activity

one of the core components of an Android application, is the point at which the application makes contact with your users An Activity is an important component of the life cycle of an Android app.

Relative layout

organizes layout components in relation to each other. This provides more flexibility in positioning controls than Linear layouts.

GetSelectedItem( )

returns the text label of the currently selected Spinner item Code Syntax groupChoice = group.getSelectedItem().toString(); A method named GetSelectedIndex( ) can be used with a Spinner control to determine if the user selected the first, second, or subsequent choice. For example, if GetSelectedIndex( ) is equal to the integer 0, the user selected the first choice.

The Java code necessary to display the content of a specific screen is called

setContentView Code Syntax setContentView(R.layout.main); R.layout.main represents the user interface of main.xml layout - The R represents the term Resource as the layout folder resides in the res folder.

When an application has more than one Activity

the Android Manifest file must have an intent to navigate among multiple activities.

By default,

the Linear layout places each control directly below the previous control to form a vertical column

The Package Explorer on the left side of the Eclipse program window contains

the folders for an Android project

In the Package Explorer in the left pane of the Eclipse program window,

the res (resource) folder contains three subfolders whose names start with drawable.

XML(Extensible Markup Language

used to assist in the layout of the Android emulator

To design a user interface for an Android app, you can create a layout,

which is a container that displays widgets such as TextView, Button, and CheckBox controls, also called objects.

instantiate

you create an instance of the object by defining one particular variation of the object within a class, giving it a name, and locating it in the memory of the computer Each class needs its own copy of an object.

When you import the Button type as an Android widget,

you make the classes from the Android Button package available throughout the application. An import statement is automatically placed at the top of the Java code.

Java

an object-oriented programming language

ImageView control

can display an icon or a graphic such as a picture file or shape on the Android screen

Text size property

can use various units of measurement

Text property

changes the text written within the control

To view the opening icon called the launcher icon on the home screen,

click the application listing icon at the bottom of the emulator when an application begins to execute

Before you can insert the ImageView control in the emulator window

you must place the appropriate picture file in the resources folder

Android supports three types of graphic formats

.png (preferred), .jpg (acceptable), and .gif (discouraged).

The startActivity( ) method creates an intent to start another Activity such as to start the recipe Activity class. A context in Android coding means that any time you request that program to launch another Activity, a context is sent to the Android system to show which initiating Activity class is making the request.

Code Syntax startActivity(new Intent(Main.this, Recipe.class));

Coding the Spinner Control

Code Syntax final Spinner group = (Spinner) findViewById(R.id.txtGroup);

Adding the Button, TextView, and ImageView Controls

Code Syntax final TextView result = ((TextView) findViewById (R.id.txtResult));

SetText( ) Method

Earlier in the Android project, the method GetText( ) extracted the text from the Text Field control. In an opposite manner, the method SetText( ) displays text in a TextView control. SetText( ) accepts a string of data for display Code Syntax result.setText("Total Cost for " + groupChoice + " is "+ currency.format(totalCost));

After the Button property is referenced in Main.java, an OnClickListener( ) method is necessary to detect when the user taps an onscreen button.

Event listeners wait for user interaction, which is when the user taps the button to view the recipe in the case of the chapter project.

In 2005

Google obtained Android, Inc., to start a venture in the mobile phone market

To convert a string into a numerical data type, a Parse class is needed to convert strings to a number data type.

Integer Integer.parseInt( ) Float Float.parseFloat( ) Double Double.parseDouble( ) Long Long.parseLong( ) Code Syntax numberOfTickets = Integer.parseInt(tickets.getText().toString());

Coding a Theme in the Android Manifest File

Code Syntax android:theme="@android:style/Theme.Black.NoTitleBar"

gen folder

contains Java files that are automatically generated

A final variable can only be initialized once and any attempt to reassign the value results in a compile error when the application is executed.

Code Syntax final EditText tickets=(EditText) findViewById(R.id.txtTickets);

Android 4.0 Library

contains a single file, android.jar

Android.jar

contains all the class libraries needed to build an Android application for this version

Program development life cycle

1. Gather and analyze the program requirements—The developer must obtain the information that identifies the program requirements and then document these requirements. 2. Design the user interface—After the developer understands the program requirements, the next step is to design the user interface. The user interface provides the framework for the processing that occurs within the program. 3. Design the program processing objects—An Android app consists of one or more processing objects that perform the tasks required in the program. The developer must determine what processing objects are required, and then determine the requirements of each object. 4. Code the program—After the processing object has been designed, the object must be implemented in program code. Program code consists of the instructions written using XML and Java code that ultimately can be executed. 5. Test the program—As the program is being coded, and after the coding is completed, the developer should test the program code to ensure it is executing properly.

When an OnClickListener is placed in the code window, Java creates an onClick auto-generated stub.

A stub is a piece of code that actually serves as a placeholder to declare itself, and it has just enough code to link to the rest of the program.

Coding the EditText Class for the Text Field

A variable is used in a Java program to contain data that changes during the execution of the program

Adding a Spinner Control with String Array Entries

After entering the items in an array, the Spinner property called Entries connects the String Array to the Spinner control for display in the application. The Spinner control is located in the Form Widgets category.

Layout margin top

All Palette controls such as TextView and Image View can use a property

smartphone

An average data plan for a mobile device

AndroidManifest.xml file

contains all the information about the application that Android needs to run

res folder

contains all the resources, such as images, music, and video files, that your application may need.

The Relative layout allows

controls to be placed anywhere, but the green dashed line centers each control perfectly

GetText( ) Method

convert the values in the assigned variables to the correct data type for calculation purposes

Android User Interface Layout editor

displays form widgets that you place on the user interface using the drag-and-drop method

object-oriented programming language

encourages good software engineering practices such as code reuse

Linearlayouts are common for

forms that display controls in a single row or column

assets folder

holds any asset files that are accessed through classic file manipulation

Android creates a Drawable resource for any of these files when you save them

in the res/drawable folder

src folder

includes the Java code source files for the project

object

is a specific, concrete instance of a class. When you create an object, you instantiate it.

theme

is a style applied to an Activity or an entire application.

Android Manifest file

is necessary in every Android application and must have the filename AndroidManifest.xml. The Android Manifest file provides all the essential information to the Android device, such as the name of your Java application, a listing of each Activity, any permissions needed to access other Android functions such as the use of the Internet, and the minimum level of the Android API

class

is simply a blueprint or a template for creating objects by defining its properties. In object oriented terminology, a class describes a group of objects that establishes an introduction to each object's properties.


Related study sets

Salam! neu A1-A2 - Lektion 1 (Vokabeln)

View Set

Social Psychology Chapter 5-Stereotypes,Prejudice, and discrimination Terms.

View Set

Topik 7: Metafizik(Konsep Insan 2)

View Set