sistemi di elettronica digitale, sez - alessandra...
TRANSCRIPT
Sistemi di Elettronica Digitale, Sez.7
Alessandra [email protected]
Ufficio 24 Dip. Ingegneria dell’Informazione030-3715627 Lunedì 16:30-18:30
Sistemi di elettronica digitale, A. Flammini, AA2017-2018
3
FROM Mobile Phones to Smartphones
• First mobile phone 1983, camera phones late ‘90, OS late ’90
• Proprietary formats emerged to better take advantage of hardware capabilities:
• Palm OS (became Garnet OS)• RIM Blackberry OS• Java Micro Edition• Symbian OS (Sony Ericsson, Motorola, Samsung)• Windows Phone (Nokia)• iPhone iOS
• Major players now: • iOS• Android• Windows Phone (abandoned)
Sistemi di Elettronica Digitale, A. Flammini
7
INSIDE A SMARTPHONE
Samsung Galaxy S4: few big devices (cameras and other components on different boards)
Sistemi di Elettronica Digitale, A. Flammini
INSIDE A SMARTPHONE: open source projects
8Sistemi di Elettronica Digitale, A. Flammini
Not successfull, abandoned 2009
INSIDE A SMARTPHONE: Sensors
9Sistemi di Elettronica Digitale, A. Flammini
Accelerometer within the smartphone can be used to detect• human activities – walking, running, dancing or posture• vehicles collisions or vibrations• The Smartphone includes gyroscopes (orientation –yaw, pitch, roll- and their variation) and magnetometers (the strength of earth’s magnetic field)
Proximity sensor, touchscreen• during a call, if the phone is close (in touch) to the ear, the touchscreen is disabled. The touchscreen can be considered as another sensor (same for NFC)
Microphones• is a sensor for word and/or noise detection and identification, but also a sensor for acoustic pollution measurement, a sensor for traffic measurement, weapon shot detection, and so on
Cameras, luxmeter, temperature• A smartphone includes two cameras with sometimes a luxmeter for automatic flash management. The camera can be used as a heart rate detection. New possible cameras for pulsiossimeter or glucose detection
GPS, WiFi, BLE, Software sensors (e.g. fingerprint)
OPERATIVE SYSTEMS (OS)
Why a Smartphone needs an OS?• To execute several programs and applications• To manage memory and communication interfaces• To manage its HW and its SW
10Sistemi di Elettronica Digitale, A. Flammini
• 2008: T-Mobile G1 announced– SDK 1.0 released– Google sponsors first Android Developer Challenge– Android Open Source Project (Apache license)– Android Dev Phone 1 released
• 2009: New SDK release– Cupcake (SDK 1.5)
• Softkeyboard with autocomplete feature• Auto-rotation option
– Donut (SDK 1.6)• New camera features• Search features improved (Quick/Voice)
– Éclair (SDK 2.0/2.0.1/2.1)• New camera features• Multiple accounts
ANDROID: History
13Sistemi di Elettronica Digitale, A. Flammini
• 2010: Nexus One released to the public– Froyo (SDK 2.2)
• Expandable memory• USB tethering
– Gingerbread (SDK 2.3)• UI update• NFC
• 2011: New SDK release– Honeycomb (SDK 3.0/3.1/3.2) for tablets only
• New UI tablet oriented• Multi-core processor supporting
– Ice Cream Sandwich (SDK 4.0/4.0.1/4.0.2/4.0.3)• WIFI direct• Changes to the UI• Face unlock
• 2012: – Ice Cream Sandwich (SDK 4.0.4)
• Stability improvement
– Jelly Bean (SDK 4.1)• Google Now
ANDROID: History
14Sistemi di Elettronica Digitale, A. Flammini
2013:
Kit Kat (SDK 4.4)
NFC capabilities through Host
Card Emulation
Wireless printing support
Storage access framework, new framework
2014:
Lollipop (SDK 5)
Android RunTime (ART) with ahead-on-time (AOT) compilation
64-bit CPU
2015:
Marshmellow (SDK 6)
USB OTG, Access point for 5GHz
Fingerprint recognition, new functionalities for Power management
ANDROID: History
15Sistemi di Elettronica Digitale, A. Flammini
2016:
Nougat (SDK 7)
New graphic functionalities
Dual window (multi-window for tablet)
Auto-update
2017:
Oreo (SDK 8)
Floating windows
Text autofill
Notification dots
Power and memory management
NOTE: Android Wear for SmartWatch
ANDROID: History
16Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Current releases distribution
17Sistemi di Elettronica Digitale, A. Flammini
ANDROID is growing fast- More than 50% of smartphone market- More than 70% of tablet market- Not only smartphone and tablet
- Smart watch- Smart TV- IoT
18
ANDROID: main differences with IOS
Different device size (more HW manufactors)
Expandable memory
USB connection
External HW easier to product
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: ARCHITECTURE
Android is:• an OS (Linux kernel) for HW interface• A Library set to be used in APPs• A Java Virtual Machine for APPs porting and executing (all Apps are written in Java language)• A framework for APPs development• An Applications containers- general Apps (Phone)- specific Apps (FB)
Application: a Java-based program for ANDROID
19Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Linux Kernel
Android Linux Kernel has
differentiated from Linux
Kernel
From 2.6 ver to 3.8
Basic SO services
Abstraction between
hardware and software
Security
Memory management
Process management
20Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Libraries
Run in system background
Use C/C++ language
Four types of libraries
Bionic Libc, system C libraries
Function libraries, supporting multimedia, web browser, SQlite
Native servers
Hardware Abstraction Libraries
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Core Libraries
Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language
Core APIs for Java language provide a powerful, yet simple and familiar development platform
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Dalvik Virtual Machine
Android custom implementation virtual machine
Provides application portability and runtime consistency
Runs optimized file format (.dex) and Dalvik bytecode
Java .class / .jar files converted to .dex at build time
Designed for embedded environment
Supports multiple virtual machine processes per device
Each process an instance of the DVM
Highly CPU-optimized bytecode interpreter
Efficiently Using runtime memory
The Dalvik VM relies on the Linux kernel for underlying functionality (threading and low-level memory management)
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Application Framework
Simplify the reuse of components
Applications can publish their capabilities and any other application may then make use of those capabilities
Applications is a set of services and systems, include
Views system, content providers, resources manager and so on
Frameworks
Activity Manager
Notification Manager
Resource Manager
Content Providers
Views
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Applications
Contain a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, …
All yours Apps will belong to this layer
All applications are written in Java programming language
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: SDK
Software Development Kit (SDK) enables developers to
create applications for the Android platform
Sample projects source code
Custom virtual machine
Development tools:
Dalvik Debug Monitor Service (DDMS)
Android Debug Bridge (ADB)
Android Emulator
SDK emulator: allows to develop and test apps on PC
without a physical device (simulate the mobile)
SDK download link:
http://developer.android.com/sdk/index.html
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Emulator
Virtual mobile device on PC
Allows to develop and test apps on PC without a physical device (simulate interrupt)
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Traditional vs APP programming
Only one APP at a time (“multitasking”)
Only one window →Simplified UI (User Interface)
Limited system access (“sandboxing”)
Limited resources and memory
Instant APP opening and closing: application should start and quit instantaneously.
APP has her own lifecycle….
Code must apply to many kind of devices
Sistemi di Elettronica Digitale, A. Flammini
APP design first of all! Then code programming
ANDROID: APP Basic Components
An APP is made of:
Activities (Programs and related User Interface)
Services (Activities without User Interface, in background)
Intents (Messages among Activities)
Content providers
Standard interface for sharing data among Applications
Broadcast receivers
Receive notification from Android system
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: APP Basic Components
Activity:
Single screen of application, only “on screen” activity is in running state
Single App many Activities which can exchange data
Activities have a event-driven life-cycle
Activities is composed by graphic components
UI is built using a hierarchy of ViewandViewGroupobjects
View are usually UI widgets (e.g. textfield, button)
ViewGroup are invisible view containers that define how the child views are laid out (grid or list)
Android provides an XML vocabulary that corresponds to ViewandViewGroup so you can define your UI in XML using a hierarchy of UI elements
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: Widgets
Text View
Button
Toggle Button
Check Box
Radio Button
Checked Text View
Progressing Bar
Seek Bar
Quick Contact Badge
Radio Group
Rate Bar
Sistemi di Elettronica Digitale, A. Flammini
ANDROID: DESIGN
32Sistemi di Elettronica Digitale, A. Flammini
The Holy Bible URL: http://developer.android.com
• Be flexible• Optimize Layouts• Assets for all
ANDROID: INTERACTION DESIGN
34Sistemi di Elettronica Digitale, A. Flammini
• Information widgets
• Collection widgets
• Control widgets
• Hybrid widgets
You can imagine them as "at-a-glance" views of an app's most important data and functionalitythat is accessible right from the user's home screen.
ANDROID: MORE DESIGN
35Sistemi di Elettronica Digitale, A. Flammini
Swipe views allow the user to efficiently move from item to item using a simple gestureand thereby make browsing and consuming data a more fluent experience.
ANDROID: FULL SCREEN DESIGN
36Sistemi di Elettronica Digitale, A. Flammini
Some content is best experienced full screen, like videos, games, image galleries, books, and slides in a presentation. Users can be engaged more deeply with content in full screen by minimizing visual distraction from app controls and protecting users from escaping the app accidentally.
ANDROID APP BASIC: MANIFEST FILES
38Sistemi di Elettronica Digitale, A. Flammini
The manifest file provides essential information about your app to the Android system, which the system must have before it can run any of the app's code.
• It names the Java package for the application. The package name serves as a uniqueidentifier for the application.
• It describes the components of the application, which include the activities, services, broadcast receivers, and content providers that compose the application. It also namesthe classes that implement each of the components and publishes their capabilities, such as the Intent messages that they can handle. These declarations inform the Androidsystem of the components and the conditions in which they can be launched.
• It determines the processes that host the application components.• It declares the permissions that the application must have in order to access protected
parts of the API and interact with other applications. It also declares the permissionsthat others are required to have in order to interact with the application's components.
• It lists the Instrumentation classes that provide profiling and other information as the application runs. These declarations are present in the manifest only while the application is being developed and are removed before the application is published.
• It declares the minimum level of the Android API that the application requires.• It lists the libraries that the application must be linked against.
ANDROID APP BASIC: Layout after (var.2)
41Sistemi di Elettronica Digitale, A. Flammini
See tutorial for APP development in http://developer.android.com
ANDROID APP BASIC: COMPONENTS
42Sistemi di Elettronica Digitale, A. Flammini
ACTIVITIESAn activity is the entry point for interacting with the user. It represents a single screen with a user interface.
SERVICESA service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons.
BROADCAST RECEIVERSA broadcast receiver is a component that enables the system to deliver events to the appoutside of a regular user flow, allowing the app to respond to system-wide broadcast announcements.
CONTENT PROVIDERSA content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that yourapp can access.
ANDROID APP BASIC: ACTIVITY LIFE CYCLE
Activities have a event-driven life-cycle (event -> callback)
Callback When
onCreate() App creation
onStart() Activity visible
onResume() after onStart
onRestart() after onStop
onPause()another Activity called
onStop() Activity invisible
onDestroy()Before Activity destruction
43Sistemi di Elettronica Digitale, A. Flammini
ANDROID APP BASIC: USER INTERFACE
44Sistemi di Elettronica Digitale, A. Flammini
The graphical user interface for an Android app is built using a hierarchy of View and ViewGroup objects.
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent">
<EditText android:id="@+id/edit_message"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="@string/edit_message" />
<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send" />
</LinearLayout>
ANDROID APP BASIC: CALL-BACK STRUCTURE
45Sistemi di Elettronica Digitale, A. Flammini
<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send"android:onClick="sendMessage" />
public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Send button */public void sendMessage(View view) {
// Do something in response to button}
}
ANDROID APP BASIC: LEARN BY EXAMPLE
46Sistemi di Elettronica Digitale, A. Flammini
RUN EMPTY APP (EXAMPLE)- Configure your Phone to connect with Android Studio:
- Settings -> about Phone/ System Phone information- -> Click at least 6 times on serial number (or build number)
- Settings -> Developer Options -> Abil Developer Options -> Press OK- Settings -> Developer Options -> Abil USB debugging- Settings -> Developer Options -> Abil Stay awake
- Install Android Studio https://developer.android.com/studio/index.html- File -> New -> New Project- Name of Application = your name- Phone and tablet = API21: Lollipop (widely supported) (Sandroide minimum is 19)- From "Add an Activity to Mobile" select "Empty Activity"- Let names and Finish- Connect your Phone via USB (Wait for installing). - Press RUN and choose your Smartphone- You can see "Hello World"
ANDROID APP BASIC: LEARN BY EXAMPLE
47Sistemi di Elettronica Digitale, A. Flammini
MODIFY EMPTY APP (EXAMPLE)
1) OBJECTIVETo modify «Hello World» with «Hello World, baby»
Objective is to insert some java code in MainActivity.java file, in the OnCreate callback, which is executed immediately after app startup, to modify the text shown with «Hello World, baby»
ANDROID APP BASIC: LEARN BY EXAMPLE
48Sistemi di Elettronica Digitale, A. Flammini
2) ASSIGN ID TO TEXTVIEW
To modify a TextView, that is a graphical interface object, from an Activity, it is needed to assign an identifier to the TextView. This Identifier could then be used later in the Activity code to access that object.
A) Open the activity_main.xml file
B) Add android:id="@+id/mytextAs attribute in the TextView tag
In this case the chosen ID is mytext
ANDROID APP BASIC: LEARN BY EXAMPLE
49Sistemi di Elettronica Digitale, A. Flammini
3) CREATE VARIABLE OF TYPE TEXTVIEWIn Mainactivity.java file
A) Create the TextView variable with name «tv»
B) If TextView is red coloured, then place the cursor on it, press ALT+Enterand click «Import class». In this way the MainActivity file is given access to the class TextView
ANDROID APP BASIC: LEARN BY EXAMPLE
50Sistemi di Elettronica Digitale, A. Flammini
4) MODIFY TEXT WITH: «Hello World, Baby»
Always in the Mainactivity.java file
1) Assign the graphical object identified by «mytext» to the tv variable. In this way a virtual object representing the graphical one is created in the activity
2) Modify the text of the tvvirtual object with the text «Hello World, Baby»