1.Session 1(概述)

1.介绍

1.嵌入式系统与软件
2.设计范式

架构设计,数据库设计,接口设计,详细设计

3.设计方法

结构化设计,面向对象设计

4.模型语言

UML,SC

5.用户电子产品设计对象

软件架构,用户接口,数据结构与存储,网络通信,安全,性能

6.课程概述

架构设计,原型设计,数据库设计,多线程编程,网络通信,文件编程,单元测试

总结

2.Session 2(架构)

1.架构设计

1.架构设计过程
  • 确定设计对象

    • 易于更换和维护
    • CTOS
    • 系统性能
    • 实现
    • 安全
    • 软件容错
    • 回滚
  • 确定系统类型

    • 交互式子系统
    • 事件驱动的子系统
    • 转型子系统
    • 对象持久性子系统
  • 应用现有或自定义(设计模式)的风格

    • N-tier architecture

    • Client-Server architecture

    • Main program and subroutine architecture

    • Event-driven system architecture

    • Pesistence framework architecture

  • 指定子系统、接口、交互行为

    • define the input and output of each subsystem
    • specify the interaction behavior between the subsystems
  • 审查架构设计

    • the review verifies that if the design satifies software requirements and design objects
    • and if the design follows the software design principles

2.软件设计原则(设计模式有涉及)

1.Design for change
  • a good design should yield a system that can adapt to change
2.Open close principle
  • the design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code
3.Separation of concerns
  • a good design means than the responsibility of different concerns should be assigned to different subsystem or objects
4.Interface segregation principle
  • clients should not be forced to implement interfaces they don't use
5.Information hiding
  • a good design should hide implementation detail from the rest of the system
6.Single responsibility principle
  • a class should have only one reason to change
7.Keep it simple and stupid
  • a good design should avoid unnecessary complexity
  • less is more
8.Hollywood principle
  • don't call us, we will call u

3.包图与UML

1.UML

Unified Modeling Language

  • UML 2.0 defines thirteen types of diagrams, three represent general types of behavior

  • Structure Diagrams

    Class Diagram, Object Diagram, Component Diagram, Composite Structure Diagram, Package Diagram, and Deployment Diagram
    
  • Behavior Diagrams

    Use Case Diagram, Activity Diagram, State Machine Diagram
    
  • Interaction Diagrams

    Sequence Diagram, Communication Diagram, Timing Diagram, Interaction Overview Diagram
    
2.Package diagram
  • package diagram shows the arrangement and organization of model elements in middle to large scale project
  • package diagram can show both structure and dependencies between sub-systems or modules

4.安卓架构

1.图片

2.HAL
  • defines a standard interface for hardware vendors to implement and allows Android to be agnostic about lower-level driver implementations
  • HAL implementations are packaged into modules (.so) file and loaded by the Android system at the appropriate time
3.Runtime and Libraries
  • Runtime
    • Dalvik Virtual Machine (before 5.0)
    • Execute .dex files
    • Android Runtime (ART, 5.0 and higher)
    • Execute .oat files
    • Core Libraries
    • Compile Java code to .dex file
  • Libraries(C/C++)
    • Running on top of the kernel, Android includes various C/C++ core libraries such as libc and SSL
    • A media library for playback of audio and video media
    • A surface manager to provide display management
    • Graphics libraries that include SGL and OpenGL for 2D and 3D graphics, etc.
  • Dalvik VM, Based on QEMU (before 5.0)
    • Depending on linux kernel, execute .dex file
    • .class file is object file, which needs to be linked as .dex file for running in Dalvik VM
    • Dx tool is used to linke .class file to .dex file
    • Dex is a compressed file format, being used in limited memory system
    • Multiple Dalvik instances can be running at the same time
  • ART (5.0 and higher)
    • execute .oat file
    • a private elf file owned by android
    • introduces the use of ahead-of-time (AOT) compilation by compiling entire applications into native machine code upon their installation
      • improves the overall execution efficiency and reduces power consumption
      • Once installed on a device, each Android application lives in its own security sandbox
      • The android system implements the principle of least privilege (POLP)
        • The Android operating system is a multi-user Linux system in which each application is a different user
        • By default, the system assigns each application a unique Linux user ID
        • Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications
        • By default, every application runs in its own Linux process
  • Application Framework
    • An array of managers that provide services for
      • Activity、Views、Content Providers
      • Resources、Windows, etc.
  • Applications
    • Different user applications written in Java
    • Such as
      • Contacts
      • Browser
      • Etc.
    • APK
      • Android package, Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix
      • All the code in a single .apk file is considered to be one application
      • .apk is the file that Android-powered devices use to install the application
  • Application Components
    • 1 android app = N components
    • apps can use components of other applications
    • app processes are automagically started whenever any part is needed
      • one app has N entry points, !1, and !main()
    • four types of components
      • activity, service, content provider, broadcast receiver
    • Activities
      • represents a single screen with a user interface
    • Services
      • runs in the background to perform long-running operations or to perform work for remote processes and has no a user interface
    • Content Providers
      • store and retrieve data and make it accessible to all applications
    • Broadcast Receivers
      • responds to system-wide broadcast announcements
    • Intent
      • Three of the core components of an application — activities, services, and broadcast receivers — are activated through messages, called intents
      • Intent messaging is a facility for late run-time binding between components in the same or different applications
      • intent is a passive data structure holding an abstract description of an operation to be performed
      • it contains
        • Component name
        • Action
        • Data
        • Category
        • ExtrasExtrasExtrasExtras
        • Flags
    • Android project structure
      • src package
      • gen package
      • Library
      • assets folder
      • res folder
      • drawable
      • Layout
      • project Menifest file
  • Android debugging
    • adb
    • logcat
    • ddms
    • lint
    • monkey/monkeyrunner
    • junit
    • hierarchy viewer
    • etc.

5.JavaKotlin

3.Session 3(原型)

1.Prototype Design Process
2.Tools
  • Axure RP
  • Balsamiq mockups
  • 墨刀

3.UI Design Patterns
4.Android UI Components
5.Conclusion

4.Session 4(数据库)

1.Basics

  • Database
    • used to maintain internal records, to present data to customers and clients on the Mbrld-Wide- Web, and to support many other commercial processes
  • DBMS
    • a powerful tool for creating and managing large amounts of data efficiently and allowing it to persist over long periods of time, safely
DBMS components

DBMS components

  • Design of database

    • the process of producing a detailed data model of a database
    • also be used to apply to the overall process of designing, not just the base data structures, but also the forms and queries used as part of the overall database application within the database management system (DBMS)
  • Design process

    • Determine the purpose of the database

    • Find and organize the information required

    • Divide the information into entities/tables

    • Turn information items into attributes/columns

    • Specify indetified/primary keys

    • Set up the relationships/constraints

    • Refine the design

    • Apply the normalization rules

    • The process of designing a database begins with an analysis of what information the database must hold and what are the relationships among components of that information

      Design process

    Design process

    • Database modeling
      • E-R model
      • the structure of data is represented graphically using three principal element types
      • Relational model
      • the structure of data is represented using tables and views

2.E-R Modeling

  • Entity
    • an entity may be defined as a thing capable of an independent existence that can be uniquely identified
    • represented by rectangles
  • Attribute
    • an attribute is used to describe features of entity or relationship
    • represented by ovals
  • Relationship
    • a relationship captures how entities are related to one another
    • represented by diamonds
  • Design principles
    • faithfullness
    • entity sets and their attributes should reflect reality
    • avoid redundancy
    • simplicity counts
    • Avoid introducing more elements into your design than is absolutely necessary
    • choosing the right relationship
    • picking the right kind of element
  • Mapping natural language
  • Role naming
  • Cardinality
  • Key

3.Relational Data Modeling

  • Attributes
  • Schemas
  • Tuples
  • Domains
  • From E/R Diagrams to Relational Designs
  • Discovering Keys for Relations
  • Constraints
  • Trigger & stored procedure
  • SQLite

4.SQLite and ContentProvider Programming

  • SQLiteOpenHelper

    • An abstract class, being used to create a helper object to create, open, and/or manage a database
  • SQLiteDatabase

    • A class exposes methods to manage a SQLite database
    • Database names must be unique within an application, not across all applications
    • You can execute SQLite queries using the SQLiteDatabase query() methods, which accept various query parameters
    • Every SQLite query will return a Cursor that points to all the rows found by the query
    • You can also use the SQLiteDatabase delete()/update() methods to manage your data in database
  • ContentProvider

    • ContentResolver

      • You can use the ContentResolver's methods to interact with whatever content providers you're interested in
      • There's just a single instance of each type of ContentProvider
      • But it can communicate with multiple ContentResolver objects in different applications and processes
    • Data model

      • Content providers expose their data as a simple table on a database model
      • Every record includes a numeric _ID field that uniquely identifies the record within the table
      • A query returns a Cursor object that can move from record to record and column to column to read the contents of each field
  • URIs

    • Each content provider exposes a public URI (wrapped as a Uri object) that uniquely identifies its data set
    • All URIs for providers begin with the string "content://”
Content URI

Content URI

  • Querying a Content Provider
    • The URI that identifies the provider
    • The names of the data fields you want to receive
    • The data types for those fields
    • If you're querying a particular record, you also need the ID for that record
  • Creating a Content Provider
    • Set up a system for storing the data
    • Extend the ContentProvider class to provide access to the data
    • Declare the content provider in the manifest file for your application (AndroidManifest.xml)

5.Conclusions

5.Session 5(编程)

1.Structured & OO Programming

2.Programming for Performance

  • Process VS Thread

  • Two Rules

    • Do not access the Android UI toolkit from outside the UI thread
    • Do not block the UI thread
  • ANR (Application Not Responding)

  • If you have operations to perform that are not instantaneous, you should do them in separate threads ("background" or "worker" threads) in Android

    • You can use View.post(Runnable) method to access UI compoment outside UI thread
    • Or use handler, looper, message queue to deliver messages between UI thread and worker thread
  • Message Queue

  • Looper

  • Handler

    • A Handler allows you to send and

    process Message and Runnable objects associated with a thread's MessageQueue

    • When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it
  • AsyncTask

    • In android, AsyncTask allows you to perform asynchronous work on your user interface
    • To use it, you must subclass AsyncTask and implement the doInBackground() callback method, which runs in a pool of background threads
    • It handles result in callback method onPostExecute (Result result)
    • Rules
      • The AsyncTask class must be loaded on the UI thread
      • The task instance must be created on the UI thread
      • execute(Params...) must be invoked on the UI thread
      • Do not call onPreExecute(), onPostExecute(Result), doInBackgro und(Params...),onProgressUpdate(Progress...) manually
      • The task can be executed only once
  • IPC

    • Android offers a mechanism for interprocess communication (IPC) using remote procedure calls (RPCs)
    • And provides all the code to perform these IPC transactions
    • To perform IPC, your application must bind to a service
  • The Service Lifecycle

    The Service Lifecycle

    • Creating a Started Service or Creating a Bound Service
  • Broadcast Receivers

    • A broadcast receiver is a component that responds to system-wide broadcast announcements
    • A broadcast receiver is implemented as a subclass of BroadcastReceiver
    • There are two major classes of broadcasts that can be received
    • Normal broadcasts
    • Ordered broadcasts
    • Receiver Lifecycle
      • A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent)
      • Permissions
        • Access permissions can be enforced by either the sender or receiver of an Intent
        • when sending, you supply a non-null permission to sendBroadcast(Intent intent, String permission)
        • when receiving, you supply a non-null permission to registerReceiver(BroadcastReceiver br, IntentFilter filter, String permission, android.os.Handler handler)
  • EventBus

    • open source (by greenrobot)

    • simplifying the communication between components

    • decouples event senders and receivers

    • performs well with Activities, Fragments, and background threads

    • avoids complex and error-prone dependencies and life cycle issues

    • substitute for Intent, Handler/Message Queque, Broadcast etc.

      EventBus

    EventBus

3.File Programming

  • Stream I/O

  • Stream I/O operations involve three steps

  • Byte-Based I/O & Byte Streams

  • Character-Based I/O & Character Streams

  • File I/O

    Stream I/O

    Stream I/O

  • Using the External Storage

  • SharedPreferences

    • The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types
      • Modifications to the preferences must go through an SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to storage
      • use SharedPreferences methods such as getBoolean() and getString()
        • Map, Set, boolean, int, long, float, String
    • To get a SharedPreferences object for your application, use one of two methods
      • getSharedPreferences()
        • Use this if you need multiple preferences files identified by name, which you specify with the first parameter
      • getPreferences()
        • Use this if you need only one preferences file for your Activity
    • To write values
      • Call edit() to get a SharedPreferences.Editor
      • Add values with methods such as putBoolean() and putString()
      • Commit the new values with commit()

4.Network Programming

  • The Internet is all about connecting machines together

  • Sockets provide the communication mechanism between two computers

    • The socket is primarily a concept used in the Transport Layer of the Internet model
    • Java's socket model is derived from BSD (UNIX) sockets
  • Java's socket model

    • Local socket address=IP+port

    • Remote socket address=IP+port

    • Protocol (TCP/UDP)

      • TCP: for reliable communication between two applications, used in client/server model
      • UDP: a connection-less protocol that allows for packets of data to be transmitted between applications
      Checking the network status

      Communicating with socket

      Using HttpURLConnection to access web service

      Using HttpURLConnection to access web service

      Using HttpClient to access web service

      Using HttpClient to access web service

5.Multi-media Programming

  • OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware
  • Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL) , specifically, the OpenGL ES API
  • Android supports OpenGL both through its framework API and the Native Development Kit (NDK)
  • There are two foundational classes in the Android framework that let you create and manipulate graphics with the OpenGL ES API
    • GLSurfaceView
    • GLSurfaceView.Renderer
  • View Animation
  • Tween Animation
    • The XML file must have a single root element: either an , , , , or element that holds a group (or groups) of other animation elements
    • - A container that holds other animation elements (, , , ) or other elements
    • - A fade-in or fade-out animation
    • - A resizing animation
    • - A vertical and/or horizontal motion
    • - A rotation animation - Interpolators An interpolator is an animation modifier defined in XML that affects the rate of change in an animation
  • Frame animation
  • Property Animation
  • ValueAnimator
  • ObjectAnimator
  • Drawable Animation

6.Conclusions

6.Session 6(测试)

1.Basics

Types of testing

Types of testing

2.Unit Testing

  • Test Runner
    • is an executable program that runs tests implemented using an xUnit framework and reports the test results
  • Test Case
    • is the most elemental class. All unit tests are inherited from here
  • Test Suite
    • is a set of tests that all share the same fixture
  • Assertions
    • is a function or macro that verifies the behavior (or the state) of the unit under test
  • Test Fixture
    • is all the things that must be in place in order to run a test and expect a particular outcome
    • four phases of a test in xUnit
      • Set up -- Setting up the test fixture
      • Exercise -- Interact with the system under test
      • Verify -- Determine whether the expected outcome has been obtained
      • Tear down -- Tear down the test fixture to return to the original state

3.Monkey Runner

  • The monkeyrunner tool provides an API for writing programs that control an Android device or emulator from outside of Android code
  • With monkeyrunner, you can write a Python program that
    • installs an Android application or test package
    • runs an application or test package
    • sends keystrokes to an application
    • takes screenshots of an user interface and stores screenshots on the workstation
  • The monkeyrunner tool provides
    • Multiple device control
    • Functional testing
    • Regression testing
    • Extensible automation
  • The monkeyrunner tool uses Jython, a implementation of Python that uses the Java programming language

4.Test Case Design

  • Typical Test Case Parameters
  • Conventional Black-Box Testing
  • Equivalence Partitioning
  • Boundary Value Analysis
  • Decision Table
  • Use case-based testing
  • Conventional White-box Testing
    • control flow testing
    • data flow testing
    • branch testing
    • statement coverage
    • decision coverage
    • prime path testing
    • path testing

5.Conclusions