Download 03-intro-android - UTEP Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Android
Chapter 1
1
Objectives
• Understand what Android is
• Learn the differences between Java and Android
Java
• Examine the Android project structure
• Build a basic application using Android Studio
• Learn about the Model-View-Controller design
2
Why Mobile Computing?
• Trends in computing industry
•
•
•
•
Mainframe/batch
Workstation/client-server
PC/Web/P2P
Mobile?
• New Knowledge Areas (KA) in CS Curricula 2013
• Joint work by ACM and IEEE-CS
• Platform-based Development (PBD), e.g., mobile, web, and
game
• Good addition to your resume?
3
Why Android?
• Android: Java-based, market dominance (87% share in 2016 Q3)
• IOS: Objective-C (13%)
Global smartphone OS market share in 2016 Q3 (from www.idc.com)
4
What Is Android?
• Mobile OS by Google
• Based on Linux kernel
• Touchscreen devices
• Direct manipulation UI
• Touch gestures (swiping,
tapping, pinching)
• Virtual keyboard
5
Evolution of Android
6
Evolution of Android (Cont.)
Which version to
support?
7
Android Programming Basics
• Java for most framework
• Java SDK + Android SDK + IDE (Android Studio or Eclipse)
• XML for configuration and resources
• Cursorless control (gestures using fingers)
• Framework concepts
•
•
•
•
•
•
Activities
Intents
Views and widgets
Asynchronous calls
Background services
…
8
Java vs. Android Java
• A large number of Java
libraries in the Android
platform
• Android SDK: Dalvik
compiler, debugger,
software libraries,
emulator
Jack on
Android Studio 2.1+
Java 8
9
Java API vs. Android API
• No Java virtual machine in the Android platform
• Specialized VM, Dalvik and ART (v 5.0)
• Java bytecode compiled again into a proprietary
bytecode, dex bytecode
• Dex bytecode <-> Java bytecode
• Dex bytecode: compact Dalvik executable format
designed for Android systems, constrained in terms of
memory and processor speed.
• Dalvik dx tool for translating java bytecode into dex
bytecode
10
Android Studio
• Official IDE for building Android applications,
including: Java editor, layout editor, Android SDK,
emulator, gradle, etc.
• Focuses exclusively on Android development and
comes bundled with the Android Software
Development Kit, SDK
• Android SDK, a set of tools and API libraries for:
• Building complete applications,
• Testing them on virtual devices, and
• Performing debugging and optimization
11
Anatomy of Android Project
• Organization of Android project
•
•
•
•
Source code
Application’s resources
Manifest settings
Build files
• All of these files eventually packaged into an apk
(distribution) file
12
13
Android Manifest File
• An AndroidManifest.xml, is required for every
Android application.
• This file uses XML code to define specific
application information.
• This information can include general applicationwide settings such as the application’s style and
launch icon.
14
AndroidManifest.xml
<manifest xmlns:android="..."
package="edu.utep.cs.cs4330.helloworld"
android:versionCode="1"
android:versionName="1.0">
<application
androd:icon="@drawable/launch_icon"
android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.categry.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="17"/>
</manifest>
15
Java Source Code
• The Java source code of an application is placed in
the java directory of the project structure.
• A main file, often named MainActivity, is a Java file
that is auto-generated when the project is first
created.
• Can include JUnit test files, local tests and
instrumented tests.
16
Drawable/mipmap Resources
• The drawable folder is located in the res directory
• res contains the application resources
• Drawable resources are image files, such as
application icons, buttons, and background textures
• Q: mipmap vs. drawable folders?
• mipmap for app/launch icons
• drawable for all others
• Q: how to refer to an XML resource such as a
drawable in Java source code?
17
Generalized Screen Size
• xlarge screens are at least 960dp x 720dp
• large screens are at least 640dp x 480dp
• normal screens are at least 470dp x 320dp
• small screens are at least 426dp x 320dp
18
Layout XML Files
• User interface screens are visually designed and
coded as XML layout files.
• The design and arrangement of the elements on
the screen are implemented using XML code in a
layout file.
• Q: Advantages and disadvantages?
• Q: How to associate an XML layout with an activity?
19
Example: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
…>
<TextView … />
<LinearLayout …
android:orientation="horizontal">
<Button …
android:id="@+id/startButton"
android:text="@string/start"
android:onClick="startClicked" />
<Button … />
</LinearLayout>
</RelativeLayout>
20
In-class: Timer App
To have a taste of Android programming by:
•
•
•
•
•
•
Defining a simple UI in XML file (activity_main.xml),
Externalizing constants in XML file (strings.xml),
Associating UI with activity (setContentView),
Retrieving views defined in XML (findViewById),
Defining control code for views (android:onClick),
Separating model code from view and control.
21
Model-View-Controller
• Android applications tend to rely on the ModelView-Controller design architecture.
• This architecture assigns one of three roles that
objects can play in an application.
View
(UI element)
update UI
notify user action
Control
update data
Model
(data)
notify change
22
Sharing Android Apps
• Android requires the application to be digitally
signed with a certificate.
• Android uses this certificate to identify the author.
• Android apps typically use self-signed certificates,
in which the app developer holds the certificate’s
private key.
23