Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Android Programming In Java Starting with an App 3rd Edition James pdf download

The document provides information about the book 'Android Programming in Java: Starting with an App, 3rd Edition' by Mike James, which serves as an introductory guide to Android programming using Android Studio. It emphasizes understanding the principles of Android development, particularly focusing on creating user interfaces, while also covering essential tools and features introduced in the latest version of Android Studio. The book is designed for those with some programming experience and aims to equip readers with the knowledge to build simple Android applications.

Uploaded by

fasadiloanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Android Programming In Java Starting with an App 3rd Edition James pdf download

The document provides information about the book 'Android Programming in Java: Starting with an App, 3rd Edition' by Mike James, which serves as an introductory guide to Android programming using Android Studio. It emphasizes understanding the principles of Android development, particularly focusing on creating user interfaces, while also covering essential tools and features introduced in the latest version of Android Studio. The book is designed for those with some programming experience and aims to equip readers with the knowledge to build simple Android applications.

Uploaded by

fasadiloanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Android Programming In Java Starting with an App

3rd Edition James pdf download

https://ebookname.com/product/android-programming-in-java-
starting-with-an-app-3rd-edition-james/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Android Programming in Kotlin Starting With An App 1st


Edition James

https://ebookname.com/product/android-programming-in-kotlin-
starting-with-an-app-1st-edition-james/

Android Game Programming For Dummies 1st Edition Derek


James

https://ebookname.com/product/android-game-programming-for-
dummies-1st-edition-derek-james/

Essential App Engine Building High Performance Java


Apps with Google App Engine 1st Edition Adriaan De
Jonge

https://ebookname.com/product/essential-app-engine-building-high-
performance-java-apps-with-google-app-engine-1st-edition-adriaan-
de-jonge/

What Have You Changed Your Mind About Today s Leading


Minds Rethink Everything First Edition John Brockman

https://ebookname.com/product/what-have-you-changed-your-mind-
about-today-s-leading-minds-rethink-everything-first-edition-
john-brockman/
Living Well in a Down Economy For Dummies 1st Edition
Tracy Barr

https://ebookname.com/product/living-well-in-a-down-economy-for-
dummies-1st-edition-tracy-barr/

Historical Dictionary of the Discovery and Exploration


of the Northwest Passage Historical Dictionaries of
Discovery and Exploration 3 1st Edition Alan Day

https://ebookname.com/product/historical-dictionary-of-the-
discovery-and-exploration-of-the-northwest-passage-historical-
dictionaries-of-discovery-and-exploration-3-1st-edition-alan-day/

Public Health Management of Disasters The Practice


Guide 3rd Edition Linda Young Landesman

https://ebookname.com/product/public-health-management-of-
disasters-the-practice-guide-3rd-edition-linda-young-landesman/

Capital Adequacy beyond Basel Banking Securities and


Insurance 1st Edition James T. Willerson Md

https://ebookname.com/product/capital-adequacy-beyond-basel-
banking-securities-and-insurance-1st-edition-james-t-willerson-
md/

Deleuze Fascism Security War Aesthetics 1st Edition


Brad Evans

https://ebookname.com/product/deleuze-fascism-security-war-
aesthetics-1st-edition-brad-evans/
Differential Display Methods and Protocols 2nd Edition
Shitao Yang

https://ebookname.com/product/differential-display-methods-and-
protocols-2nd-edition-shitao-yang/
Android Programming In Java:
Starting with an App

Using Android Studio 3

Third Edition

Mike James

I/O Press
I Programmer Library
Copyright © 2017 I/O Press
All rights reserved. This book or any portion thereof may not be reproduced
or used in any manner whatsoever without the express written permission of
the publisher except for the use of brief quotations in a book review.

Mike James Android Programming in Java: Starting with an App


3rd Edition
ISBN Paperback: 978-1871962550
First Printing, 2017
Revision 0

Published by I/O Press www.iopress.info


in association with I Programmer www.i-programmer.info

The publisher recognizes and respects all marks used by companies and
manufacturers as a means to distinguish their products. All brand names and
product names mentioned in this book are trade marks or service marks of
their respective companies and our omission of trade marks is not an attempt
to infringe on the property of others.
In particular we acknowledge that Android is a trademark of Google.

2
Preface

AndroidTM programming is an attractive proposition. There are more Android


users than any other smartphone or tablet and this makes it a potentially huge
market. Android devices are relatively cheap and this makes it suitable for
implementing smaller scale projects. Finally the tools that you need are free
to download and use and you don’t need anyone's permission to get started.
The only difficulty is that Android is a tough system to master. It is easy
enough to get started as Android Studio will build you a Hello World app in a
few minutes, but what you do next is more difficult. You can get a
surprisingly long way in Android programming by simply copying and
pasting code from other programs that roughly do what you want, but the
results are usually unreliable and disappointing. To create a good app there is
no substitute for understanding how the system works and appreciating its
strong points and its limitations.
This book aims not only to show you how common tasks are done in
Android, but to make sure that you understand why they are done in a
particular way. This means covering not just the “what” but also the “why”.
The good news is that this isn’t as difficult as you might expect because
Android does have repeating patterns and ways of doing things and once you
have seen something in action you find it generalizes to components you
haven’t encountered.
This isn’t a book full of complete examples and case studies. In fact the
examples are stripped down to their bare minimum to avoid having to present
lines of irrelevant and repetitious code and to let you see what is essential. It
also isn’t a complete treatment of everything Android. A single book that
covered every aspect of the Android system would be too large to pick up and
carry. Instead it tackles the things you need to know to write a simple app. It
focuses on creating the user interface (UI) because this is what you spend
most of your time working on even if the app in question is sophisticated. At
least 90% of the effort in creating any app goes into building and perfecting
the UI and this makes it the key place to start. In this book you will find out
how to build an app with a single Activity and a UI. If you master this level of
the art then you will find it much easier to push on into unknown territory. I
can’t promise to cover every aspect of the UI but I have tried to include
examples of all of the sorts of techniques you will encounter so that you are
familiar with the way things work in general.

3
This book is at an introductory level as far as Android development goes,
however it isn’t for the complete beginner. It is assumed that you can
program, but not necessarily in Java, which is arguably the most important of
all today’s programming languages and the original language of Android. Java
is a very standard object-oriented language and with the help of comments
that point out where it is significantly different you should find it easy to pick
up as you go along. Finally the development tool used is the latest version of
Android Studio because it doesn’t make sense not to use it or to use anything
else.
This edition has been updated to cover features introduced in Android
Studio 3. In particular, it includes the use of Java 8 and the lambda
expression which greatly simplifies event handling. As well as the latest
Android Studio it also covers ConstraintLaout 1.0.2 which includes Groups
and Barriers as well as a much improved editor.

Mike James
November 2017

This book is a revised and updated version of the series of Android


Adventures With Android Studio on the I Programmer website:
www.i-programmer.info.
There are additional articles on I Programmer that form the basis of the more
advanced books that are still in preparation. After updating and revision,
Android Adventures – Mastering Fragments will be published in print as
Android Programming: Mastering Fragments & Dialogs.
The first draft of Android Programming: Structuring a Complex App, which
goes further into threading, concurrency, life cycle and other topics crucial to
a real world app, is currently work in progress on the website.
To keep informed about forthcoming titles in the Android Programming
series visit the I/O Press website:
www.iopress.info
This is also where you will also find errata, update information to keep up
with changes in Android Studio and Android itself and, most importantly,
the code from the books. You can also provide feedback to help improve
future editions of Android Programming.

4
Table of Contents
Chapter 1
Getting Started With Android Studio 11
The Language Choice........................................................................12
What You Need to Know..................................................................12
Making a Start...................................................................................12
Your First Program............................................................................14
First Look...........................................................................................18
The IDE..............................................................................................19
Basic Project Structure......................................................................19
Anatomy of an Activity.....................................................................20
Hello Layout Designer.......................................................................21
Inspecting the XML...........................................................................26
The Java.............................................................................................26
Getting Started with the Emulator ...................................................28
Summary...........................................................................................31
Chapter 2
Activity and User Interface 33
The MainActivity..............................................................................34
Inside the Activity.............................................................................35
View and ViewGroup........................................................................36
Creating Our First UI.........................................................................37
Properties...........................................................................................41
Events................................................................................................42
Connecting the Activity to the UI.....................................................44
Finding View Objects........................................................................48
Summary ..........................................................................................50
Chapter 3
Building a Simple UI 53
What's in the Palette..........................................................................54
The Button an Example....................................................................56
Positioning – the ConstraintLayout..................................................56
Sizing.................................................................................................64
The Component Tree........................................................................66
A Simple Button Example – Baseline Alignment............................66
Orientation and Resolution..............................................................68
A First App – Simple Calculator.......................................................73
Summary...........................................................................................81

5
Chapter 4
Android Events 83
The Lambda Approach.....................................................................83
Lambda Types...................................................................................85
Using a Lambda to Create an Event handler....................................86
Closure...............................................................................................88
Event Handler Using A Class............................................................89
Using Breakpoints.............................................................................92
Alternative Ways to Handle an Event..............................................93
Implement the Interface in the Activity...........................................94
Anonymous Classes..........................................................................95
Code Folding.....................................................................................98
Which Approach Should You Use?..................................................99
Summary.........................................................................................100
Chapter 5
Basic Controls 101
Basic Input Controls........................................................................101
Button Styles and Properties..........................................................101
All Properties...................................................................................105
Text Fields.......................................................................................107
The onEditorAction Event..............................................................110
CheckBoxes.....................................................................................111
Switches and Toggle buttons..........................................................112
Radio Buttons .................................................................................113
Summary.........................................................................................115
Chapter 6
Working With Layouts 117
Understanding Layouts...................................................................117
Layout Properties............................................................................118
Width and Height............................................................................120
Units................................................................................................120
A Control is Just a Box....................................................................122
Gravity.............................................................................................123
The FrameLayout............................................................................124
LinearLayout....................................................................................126
RelativeLayout.................................................................................130
Summary.........................................................................................134

6
Chapter 7
The ConstraintLayout 135
Automatic Constraints....................................................................136
Manual Constraints.........................................................................140
Bias Constraints...............................................................................143
Chains..............................................................................................145
A Chained Keypad..........................................................................147
Guidelines........................................................................................150
Groups.............................................................................................151
Sizing...............................................................................................152
Barriers............................................................................................157
Constraint Properties......................................................................160
Troubleshooting..............................................................................160
Summary.........................................................................................162
Chapter 8
Programming The UI 163
A UI Library.....................................................................................163
The View.........................................................................................163
Using setContentView.....................................................................164
The ViewGroup...............................................................................166
Programming Layout Properties.....................................................167
The View Hierarchy........................................................................169
XML Layout.....................................................................................169
Inflation Theory..............................................................................170
Finding View objects.......................................................................171
How to Build a UI?..........................................................................172
Summary.........................................................................................173
Chapter 9
Menus – Toolbar 175
Creating a Menu Resource..............................................................175
The Menu Tree................................................................................176
Displaying a Menu..........................................................................178
Using the Toolbar............................................................................179
Creating the App Bar ......................................................................183
Where's My Toolbar?.......................................................................184
Responding to Menu Events...........................................................184
Changing Menus in Code................................................................187
Controlling the Toolbar...................................................................190
Summary.........................................................................................191

7
Chapter 10
Menus – Context & Popup 193
The Context Menu..........................................................................193
Contextual Action Bar.....................................................................196
The Popup Menu.............................................................................200
Summary.........................................................................................203
Chapter 11
Resources 205
Why Use Resources?.......................................................................205
What are Resources?.......................................................................207
Drawables........................................................................................208
Values..............................................................................................211
IDs....................................................................................................212
Accessing Resources in Code – The R Object................................213
Conditional Resources....................................................................214
A Simple Localization.....................................................................218
Android Studio Translation Tools.................................................219
Summary.........................................................................................221
Chapter 12
Bitmap Graphics 223
Android Graphics............................................................................223
The Bitmap......................................................................................223
The ImageView Control..................................................................224
Canvas..............................................................................................225
A First Graphic................................................................................226
Transformations..............................................................................229
A Logical Approach to Transforms................................................232
Setting Your Own Coordinates.......................................................233
Simple Animation...........................................................................234
Timer and Threads..........................................................................236
Listing..............................................................................................241
Summary.........................................................................................243

8
Chapter 13
Life Cycle Of An Activity
Lifetime and State...........................................................................245
The Life Cycle of an App................................................................246
The Simple Approach.....................................................................247
Lifecycle Explorer...........................................................................248
Trying It Out....................................................................................249
Retaining State – the Bundle..........................................................250
Saving Additional UI Data..............................................................252
Complex UI Elements.....................................................................253
Advanced State Management.........................................................254
Summary.........................................................................................255
Chapter 14
Spinners 257
The Spinner and the Designer........................................................257
Introducing the ArrayAdapter........................................................259
Handling the Selection...................................................................261
Creating an ArrayAdapter from a Resource...................................265
Changing The List...........................................................................265
Summary.........................................................................................267
Chapter 15
Pickers 269
Working with Pickers......................................................................269
TimePicker.......................................................................................270
TimePicker in Code.........................................................................271
Updating the Time..........................................................................272
DatePicker........................................................................................273
Number Picker.................................................................................277
Multi-Digit Input.............................................................................281
Summary.........................................................................................285
Chapter 16
ListView 287
Understanding the Adapter............................................................287
Extending the ListAdapter Class....................................................288
Using the ArrayAdapter..................................................................289
Working with the Data....................................................................291
A Custom Layout.............................................................................294
A Custom ArrayAdapter.................................................................297
Reuse, Caching and General Layouts.............................................301
Custom Adapter..............................................................................304
Summary.........................................................................................306

9
Chapter 1

Getting Started With Android Studio

Android represents a big potential market. It is also the most open of the "big"
phone and tablet platforms. You can write a program for an Android and let
your friends have a copy, keep it to yourself or put it on sale in an app store.
Android phones and tablets are comparatively cheap and this makes it easier
to get started. What is even better, all the tools you need to create an Android
app are free. You don't need to pay anything to create, or distribute, your
Android apps. If you want to sell them using a well known marketplace there
may something to pay – there is a one-time fee of $25 to register for Google
Play, but you don't have to use any particular distribution method.
All that stands between you and your Android app is your imagination and
programming ability. I can't do much to improve your imagination, but I can
help with the programming side of things. If you are new to Android
programming this is the place to start.
In this book I will show you the fundamentals of Android programming. Not
the tips and tricks, but how to think about what is going on. You'll be
introduced to the general principles that will make it possible for you to
master anything that you encounter that is new in the future. It isn’t possible
to cover all of Android in one book as the subject is very large. Instead we
focus on the basics of creating a User Interface (UI) as all apps have to have
some way of interacting with a user.
There are many ways to create an Android app but Google's Android Studio is
an easy to use Android IDE – Integrated Development Environment – and it is
now the recommended way of doing the job.
Before Android Studio you had to use the Eclipse IDE and set up the SDK and
other pieces of software needed. This wasn't difficult, but Android Studio
eliminates extra steps and it makes programming Android easy. Put simply, it
is the way of the future and so worth your investment in learning it.
With the release of Android Studio Google stopped work on the Eclipse
plugin and this means that Android Studio really is the only way to develop
apps from now on.
You can get started in a few minutes and by the end of this chapter, have your
first working Android application.

11
The Language Choice
With the release of Android Studio 3 you now have a choice of programming
in Java or Kotlin. The advantage of Java is that it is a well known and well
supported language. In Android Studio 3 you can also program using features
from Java 8 including lambda functions. This greatly simplifies tasks such as
event handling and, while we will examine how to do event handling in Java
without lambda functions, using them is going to be the norm.
As the entire Android library is written in Java you really can’t avoid it. The
alternative language Kotlin is very easy to use and backwards compatible
with Java. There is very little risk in using it, but it is also helpful to know
enough Java to work with existing code.
The bottom line is that while Kotlin is an easier language to use, there are
advantages in knowing and using Java.

What You Need to Know


To get the most out of this book you need to be able to program in a modern
object-oriented language. You’ll have a head start if you already know some
Java, but C++, C#, Visual Basic or anything similar are close enough in spirit
to Java for you to be able to cope. You might well need to look things up
about the specifics of particular features of Java, but most of the time it
should be obvious, or obvious with the help of a few comments.
It isn't necessary to be an expert programmer because for a lot of Android
programming you are simply using the features and facilities provided. That
is, a lot of Android programming is just a matter of following the rules.
However, if you hope to produce something unique and useful you will at
some point have to add something of your own – and here creativity and skill
are required. So you might not need to be an expert programmer to get
started, but you need to become one by the time you create your amazing app.
Fortunately practice is a good teacher and so learning to make the most of
Android Studio will actually help you learn to code.

Making a Start
I'm not going to spend a lot of time explaining how to install Android Studio
in a step-by-step way as the Android website does a good job and it is more
likely to be up-to-date. It is worth, however, going over the basic principles.
Download the Android Studio package from Android Studio Home page:
https://developer.android.com/studio/
Install Android Studio which also installs all of the Android SDK and tools
you will need.

12
Windows:
1. Launch the downloaded EXE file,
android-studio-bundle-<version>.exe.
2. Follow the setup wizard to install Android Studio.
Mac OS X:
1. Open the downloaded DMG file,
android-studio-bundle-<version>.dmg
2. Drag and drop Android Studio into the Applications folder.
Linux:
1. Unpack the downloaded ZIP file,
android-studio-bundle-<version>.tgz,
into an appropriate location for your applications.
2. To launch Android Studio, navigate to the
android-studio/bin/
directory in a terminal and execute studio.sh. You may want to add
android-studio/bin/
to your PATH environmental variable so that you can start Android
Studio from any directory.
Accept any defaults that the setup program offers you – unless you have a
good reason not to. It installs not only Android Studio, but the SDK and the

13
virtual device system that lets you test your application. In most cases
Android Studio just installs with no problem.
Now you should be able to run Android Studio. If not the most likely cause of
the problem is the JDK and so re-installation is a best first option.

Your First Program


You can opt to start Android Studio after the installation. You will probably
not get straight to Android Studio the first time it starts as it downloads
updates to itself and to the Android SDK. You just have to be patient.
When it finally gets going you will see the Android Studio welcome screen:

If you have already created some programs you might well see them listed in
Recent projects.

14
Assuming this is your first project select the option:
Start a new Android Studio project

You can ignore the details of the new project for the moment. All you have to
do is supply a name for your application - HelloWorld in this case. Make sure
you uncheck the Include Kotlin support option as you want to make use of
Java. Accept the other defaults that Android Studio has filled in for you.
When you click Next you are given the chance to pick what devices you are
targeting. Again simply accept the defaults:

15
Most of the time you will want to create apps that run on a version of Android
that captures the biggest market, but if this isn't a concern then it can be
better to select a more recent Android version.
The next page lets you select a template for your project. In this case change
the selection to Basic Activity. This gives you some additional generated code
which makes it easier to create an app that looks right. Every Android
application consists of at least one Activity and this template generates a
project with a single Activity ready for you to customize:

On the next page you can assign custom names for the various components of
your project that the template generates. For a real project you would assign
names that were meaningful, but in this case you can accept the defaults:

16
Finally you can click the Finish button and wait as Android Studio creates all
the files you need. Even a simple Android project has lots of files so again it
all takes time.

17
First Look
When everything is ready you will see Android Studio for the first time.
As long as everything has worked you should eventually, it takes about three
minutes or more, be presented with a view of your new project starting off in
the Designer. Click the Design tab to see the initial user interface:

Problems?
If you get any error messages then the chances are that your project hasn't
finished being processed. Wait a little while longer for the activity to stop. If
you look at the status line at the bottom of the window you will see a message
saying “Gradle Build Finished” when Android Studio has finished with your
new project.
If you still have problems it is worth trying the File,Invalidate Caches/Restart
command. This usually works for "Missing styles" and similar errors.

18
The IDE
Although there looks like a lot to master in the Android Studio user interface,
most of it you will only visit occasionally. The key things to notice are that
moving from left to right you have:
● The Project window
● The tool Palette and the Component Tree window
● The Designer or Layout Editor
● The Attributes window
Most of the time you will be using the Project window and the Attributes
window. You will also see different editors depending on what sort of file
you have selected. In this case you have by default a layout file,
content_main.xml, selected and hence you have a layout editor in the middle
of the screen.
Before we go into layout, which is one of the main topics of this book, it is
important that you know a little about the file structure of a project so that
you can navigate to its different parts.

Basic Project Structure


When the project has finished building all of the files created can be viewed
by opening the Projects tab. The main thing to notice is that there are a great
many folders and files:

It seems almost unbelievable that the simplest Android app you can create
involves so many files.

19
Don't panic. Most of the files that have been created are auto-generated and
most of the time you don't need to know anything about them, let alone open
or edit them. In fact, opening and editing auto-generated files really isn't a
good idea.
So let's focus on the files that matter to us.
For our simple program there are only two important files. One of them
determines the behavior of the Activity:
MainActivity.java
The other determines the visual appearance, or View, of the app:
content_main.xml
You can set which Activity is the one that the system starts, but by default it
is the single activity that you created and named when you set up the project.
You can change the default names but for the moment leave them as they are.
The java directory is, from your point of view, where most of the construction
of your app occurs so make sure you know where it is. The res directory is
where you store all of the resources, layouts, bitmaps, etc, that your app
needs.
So while things look complicated at the moment the only two project files
that matter to you, and your project, are MainActivity.java in the java folder
and content_main.xml in the res folder.
The two other folders in the java folder are concerned with creating tests for
your program. This is not something that we need to worry about when first
starting to write Android apps.

Anatomy of an Activity
An Android app is made up of one or more Activity classes.
You can think of an Activity as being something like a web page complete
with HTML to determine what displays and JavaScript to determine what it
does.
In the case of an Activity the layout is determined by the XML file in resource
(res) folder, this is often called the View, and the behavior is determined by
the code in the java folder.
The XML can be thought of as a markup language much like HTML or XAML.
It defines an initial layout for the screen when the app first runs. It is possible
to generate new layout components at runtime from the Java file. In fact, if
you really want to, you can dispense with the XML file and generate
everything from code, but as you will discover the XML markup approach is
much the best way to do the job because of the availability of the Designer.

20
So to be 100% clear in a Java project:
● The java file contains the code that makes your app behave in
particular ways.
● The .xml layout file contains a definition of the initial UI, the View, of
your app.

Hello Layout Designer


Let's take a look at the two files that have been generated for our initial Hello
World application, beginning with the XML layout. Double click on the
content_main.xml file in the Project tab and the file will open (if it isn't
already open). If it is already open you can also select its tab displayed just
above the editor area. You can select any file that is open for editing by
selecting its tab.
You can work with the XML directly to define where all the buttons and text
go, and later you will learn how to edit it when things go wrong or to fine
tune it. However, Android Studio provides you with a very nice interactive
Layout Editor, which throughout this book is referred to as the Designer and
this is worth using.
As you become more experienced the idea of switching between a design
view and an XML view will become second nature. Think of the interactive
editor as a very easy way of generating the XML that otherwise would take
you ages to get right. If you look at the bottom left you will see two tabs –
Design and Text:

You can switch between editing the XML as text, and editing it in the drag-
and-drop designer simply by clicking on the tab. If you now click on the tab
the window will display the Designer, but be patient the first time you do this
it might take a few moments.

21
The Designer looks a little too much to take in when you first see it but you
will quickly get used to it. On the left is a Palette of all of the components or
controls - buttons, text, checkboxes and so on - that you can place on the
design surface:

In the middle is the design surface and this defaults to the screen size and
appearance of the Nexus 5. You can select other devices to work with.

22
There are, in fact, two views of the layout that you can use, the design and the
blueprint. By default you are shown the design view but you can display
either view using the menu at the top left of the design area.

You can display both views together, but in most cases available screen area
is the main issue and showing just one is the best option. The design view
shows you the layout as a close approximation to how it will appear on a real
device. The blueprint view doesn’t try to render the UI realistically but it does
provide you will more layout information to help you position and size
elements. Use whichever you are most happy with.

23
On the left, below the Palette, you have the Component Tree which shows
you the structure of your layout, that is how different UI components are
contained inside others. It shows you the structure of the XML file in an
easier to use form. You can use the Component Tree as an easy way of to
select individual UI components by clicking on their names. You can also
drag-and-drop UI components onto the Component Tree to position them
accurately within the hierarchy.
On the right you have the Attributes window that can be used to set the
properties, such as width, height, color and so on of any component in the
layout. If you have used any drag-and-drop designer then this will seem
familiar and if you have struggled with detailed layout using a markup
language, be it HTML, XAML or XML, you will appreciate how easy the
Designer makes building and testing a UI.
In the case of our sample program the only component is a single TextView
already containing the text "Hello World". A TextView is the standard
component to use when all we want to do is to display some static text.

24
You can modify the greeting text if you want to. Select the TextView
component either on the Nexus image or in the Component Tree and use the
Attributes window to find its Text property. Change this to read "Hello
Android World!":

Use the text field without the spanner icon. The properties with the spanner
icon next to them are used to set values that only show in the Designer. In
this case the text field without the spanner icon is the one that controls what
appears in your app at runtime.
You can use the Designer to create any UI you care to and you really don't
have to get involved in the XML that corresponds to the layout – unless things
go wrong or you need to do something so sophisticated that the Designer
doesn't support it.

25
Random documents with unrelated
content Scribd suggests to you:
*** END OF THE PROJECT GUTENBERG EBOOK PRENTICE HUGH
***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you


derive from the use of Project Gutenberg™ works
calculated using the method you already use to calculate
your applicable taxes. The fee is owed to the owner of the
Project Gutenberg™ trademark, but he has agreed to
donate royalties under this paragraph to the Project
Gutenberg Literary Archive Foundation. Royalty payments
must be paid within 60 days following each date on which
you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly
marked as such and sent to the Project Gutenberg Literary
Archive Foundation at the address specified in Section 4,
“Information about donations to the Project Gutenberg
Literary Archive Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of
receipt that s/he does not agree to the terms of the full
Project Gutenberg™ License. You must require such a user
to return or destroy all copies of the works possessed in a
physical medium and discontinue all use of and all access to
other copies of Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full


refund of any money paid for a work or a replacement
copy, if a defect in the electronic work is discovered and
reported to you within 90 days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like