Wednesday, August 10, 2016

BLE.CHP8.Android Programming


  • Benifit of BLE 
    • Cheat hardware and Rich Interfaces
    • Phone as a gateway
      • in conjunction with other apps or APIs
  • Getting Start
    • Get the Hardware
      • Android version at least 4.4
        • include updated and more stable version of the BLE protocol stack
      • Supports BLE  device
    • Get the Software
      • Eclipse Android Development Tools (ADT)
      • Bluetooth Application Accelerator
    • Configure the Hardware
      • Enable Developer mode 
        • Enable USB debugging , and Stay awake options
    • Start a New Project
      • import BT Apllication Accelerators's Android files into the project
      • Open Eclipse ADT select File/Import, navigate to the directory that contains the Application Accelerator
      • select the Android /BLEDemo folder ....
  • Initializing the BLE Library
  • Connecting to a Remote Device
  • Communicating with a Remote Device

Wednesday, August 3, 2016

CHP3_Multiple Activities and Intents


  • Multiple activities
    • Most of the Apps have more than one activities.
  • Intent
    • Let Activities talk to each others
    • Across the apps boundary , interact with other apps in the same device.

============================================================================================================================================

Activity def what user can do (just one thing) ! 

Steps to build the App
  1. app structure
  2. build project
  3. update layout
    1. <Button>
    2. android : onClick ="onSendMessage"
    3. android : text = "@string/send"/>
  4. update strings.xml
    1. <string name = "send">Send Message</string>
  5. New method for activity
    1. public void onSendMessage (View view) {  }
  6. The 2nd Activity and layout
    1. File > New > Activity / Blank Activity / ReceiveMessageActivity ; activity_receive_message > finish
  7. AndroidManifest.xml
  8. Intent
    1. import android.content.Intent
    2. Intent intent = new Intent (this , ReceiveMessageActivity.class);
    3. startActivity(intent);
  9. Sending Text to the 2nd Intent
    1. Layout
      1. <TextView> ID
      2. Delete hello world
    2. Activity
      1. putExtra()
        1. intent.putExtra("message",value);
          1. message => name of the string
          2. overloaded
          3. value => can be different types
      2. getIntent();
        1. String string = intent.getStringExtra("message");
        2. int intNum = intent.getIntExtra("name,default_value");
  10. Specific action's intent

============================================================================================================================================
  • New GUI components 
    • Spinner
    • EditText
      • can edit text column
      • can input text
      • inherit from Android View (Class)
    • TextView
    • Button
  • String Resources
    • strings.xml
  • Responsive Web Design
    • em as unit
============================================================================================================================================

  • AndroidManifest.xml
    • app/src/main
    • include app significant info
      • what activity include in the app (MAIN , LAUNCHER)
      • which libraries and declaration(declare activity exist in application element)we've  used 
      • package name
      • default app icon
      • app theme
      • security permissions....
    • if you're not using Android Studio IDE , you've to build it yourself.
  • Intent
    • Build Intent => Intent intent = new Intent (this , Target.class)
      • mail address (sender , receiver)
    • Launch Intent Activity => startActivity(intent)
    • Not Found => ActivityNotFoundException
============================================================================================================================================

  • Why 2 activities rather than 1 activity handle all of the stuff
    • coz the back button
    • the order issue

============================================================================================================================================

  • Changing App , sending messages to others
    • How does Android App works ?
      • Android App , is combined by multiple Activities and other components
    • activity1 > intent > Android (check) > intent >  activity2 (even though in other app) 
  • How do we know which apps on the device?
    • "action" can solve all the problem
============================================================================================================================================
  • Explicit intent
    • directly tell Android what class
  • Implicit intent.
    • which activity let Android decide
============================================================================================================================================

establish specific action's intent 
  • Intent intent -= new Intent (action)
    • action
      • Intent.ACTION_DIAL
      • Intent.ACTION_WEB_SEARCH
      • Intent.ACTION_SEND
        • extra message adding
          • intent.setType("text/plain")
          • intent.putExtra(Intent.EXTRA_TEXT , messageText) ;
          • intent.putExtra(Intent.EXTRA_SUBJECT, subject);

============================================================================================================================================

" intent filter " tell Android which activity can handle the action

  • Intent resolution
    • explicit intent
      • it's easy 
    • implicit intent
      • Android
        • app > AndroidManifest.xml > check intent filter to accomplish the work
  • Intent filter
      • indicate what  components can receive what types of intent 
    • action
      • what activity can do ?
    • category
      • provide activity extra informations
        • main entry pt or not ?

for implicit intent
  • android.intent.category.DEFAULT
  • intent filter
    • compare to app > AndroidManifest.xml
      • action
      • MIME

============================================================================================================================================

run app on reality device
  1. USB debugging
    1. Developer options
    2. Settings > About Phone > Click build number *7 times
    3. Windows > install USB driver (http://developer.android.com/tools/extras/oem-usb.htmo)
    4. USB cable to connect to your PC (allow to use USB debug) RSA key
  2. createChooser()
============================================================================================================================================

Quick Recap

  • Task
    • >=2 activities get together
  • <EditText>
    • Edit text ,input text 
    • inherit from Android View
  • Android Studio > File > New... > Activity (for new activity)
  • AndroidManifest.xml
  • intent
    • a tool let Android elements can talk to each others
  • explicit intent
    • Intent intent = new Intent(this , Target.class);
  • start activity
    • startActivity(intent) 
    • ActivityNotFoundException
  • add more info to intent
    • putExtra()
  • get intent to launch activity
    • getIntent()
  • get relative info about intent
    • get*Extra()
      • getStringExtra()
      • getIntExtra()
  • activity action
    • describe what act activity can do 
      • eg  . sending message
        • Intent.ACTION_SEND
  • implicit intent
    • Intent intent = new Intent (action);
    • need to have DEFAULT category
  • setType()
    • to describe intent dataType
  • Intent Resolution
    • compare intent content to intent filter in app AnroidManifest.xml
      • components name
      • action
      • data type
      • category
  • createChooser()
    • overwrite default Android activity  select window
      • add new topic
      • no default 
      • if no activity it will show mssage
  • getString(R.string.stringname) to get string resource value

Monday, August 1, 2016

CHP2_Interactive App


Goals
  • make activity and layout like bros
  • let your app do something to  response  the user

Project One _ Adviser
  • GUI components for layout
    • spinner
    • button
    • textfield
  • strings.xml
  • activity
  • java class

============================================================================================================================================

Steps

  1. build the project => basic layout and activity
  2. refresh layout => put on all the GUI components you'd like to have
  3. connect layout to the activity => appearance and the brain
  4. java class => the logic of the  code  


============================================================================================================================================

  • Design Editor
    • Palette
      • GUI components toolbox
        • Widgets
  • Text Editor
    • <TextView
      • ID

Both Design and Text Editor were extends by Android View Class
  • android : id
  • android :text
  • android : layout_width
  • android : layout_height

============================================================================================================================================
  • Spinner => dropdown menu
    • spinner add values => res (noncode assets) ; eg , graph , string
    • strings.xml
      • single string
      • string array
    • make spinner reference to string -array
  • GUI elements => eg . button. textfield . spinner has similar properties , coz they are same "View class"
  • write dead into text property or using strings.xml  handle static text 
    • make you easily transfer to different languages. 
    • uniform one place for modify your text
    • app/src/main/res/values/strings.xml

============================================================================================================================================


Quick Recap

  • All of the GUI components are Android View class's subclass.
  • <string-array name ="array">  =>strings.xml
      • <item>string1</item>
      • ...
    • </string-array>
  • "@array/array_name" => Layout
  • android : onClick = "clickMethod" => Layout
  • public void clickMethod(View view) { }  =>Activity
  • R.java ,for reference
  • findViewById() get view reference
  • setText()
  • getSelectedItem()
  • File -> New ... -> Java Class

CHP1_Android Overview


  • Android base on Linux , Open source platform
  • Google support
  • Java  + XML 
  • apply on varies of  phone pad .....
============================================================================================================================================
  • What is it look like ?
    • App GUI
      • Layout
        • XML
          • buttons , labels, text .... GUI elements
  • How does it works ?
    • Working content
      • Activity
        • Java class 
          • (which layout connect to ?)
          • (how does the app response?)
  • Extra sources
    • graphics ,audios , application data


All of what we talking is  a bunch of specific  menu's files => package when we build

============================================================================================================================================
  • Android platform
    • Android core applications (Java)
      • Contacts ,Calendar,Maps,Browser
    • Applications framework (Java)
      • These are called "API" which can be read and save to control the application's "looking " & "behavior"
        • Activity Manager
        • Window Manager
        • Content Providers
        • View System
        • Package Manager
        • Telephony Manager
        • Resource Manager
        • Location Manager
        • Notification Manager
    • Libraries (C++ /C)
      • Surface Manager
      • OpenGL |ES
      • SGL
      • SSL
      • Free Type
      • WebKit
      • libc
      • SQLite
      • Media Framework
    • Android Runtime (Jave build : core libraries)
    • Linux Kernel
      • driver , safety protect , memory management ....
        • Display Driver
        • Camera Driver
        • WiFi Driver
        • Keypad Driver
        • Flash Memory Driver
        • Audio Drivers
        • Binder(LPC) Driver
        • Power Management
============================================================================================================================================

IDE _Android Studio (Java format  to Android format)

  • No .class  & .jar = >Yes Android Unique format in order to acc and save the power
  • special edition of "IntelliJ IDEA"
    • compiler
    • read and save Android SDK's tools and libraries
    • templetes
    • package and execute the app
  • Grandle (build tool)
    • command line
    • text editor
  • Android Studio  = Gandle + other tools  +  GUI
Android SDK
  • Android Software Development Kit (Libraries and tools) for each edition of Android
    • SDK platform
    • SDK tool (Debug  and Testing ...)
    • App Examples
    • Google Play Billing
    • Desciption File (API file)
    • Android support
JDK
  • Java Development Kit
JRE
  • Java Runtime Environment

============================================================================================================================================

Start to build your first App

  1. create your new project
  2. projext configure
    1. Application name => the name in Google Play
    2. Company domain
    3. Package name => combine with application name and company domain
      1. to identify your app by Android device
      2. manage different edition's app
      3. always the same after build
  3. API level
    1. Minimum SDK 
      1. Android Edition
        1. version number
        2. codename (may include few editions)
  4. create Activity and Layout
  5. activity configure
    1. Activity name (Java)
    2. Layout name (XML)
    3. Title
    4. menu resource name




  • Activity => What is the action ?
    • def one thing that user can do 
  • Layout => What does the GUI look like ?
    • how does the GUI elements arrange
============================================================================================================================================
  1. Start App
  2. create Activity
  3. Activity point to Layout
  4. Activity tell Android to display layout on the screen
  5. user act with layout 
  6. activity response to this act by code
  7. activity refresh the screen
============================================================================================================================================

Table of Content

  • explorer
    • java & XML (activity & layout)
    • Android  .java files
    • res
      • icon
      • style
    • Android libraries
      • app compatibility
      • minimize SDK
    • config
  • grandle
    • compile and arrange your app
    • app
      • build
        • R.java
      • src
        • main
          • java
            • MainActivity.java
          • res
            • layout
              • activity_main.xml
            • values
              • strings.xml
            • AndroidManifest.xml

============================================================================================================================================


Carry out

  • Entity device
  • Android SDK , Emulator 
    • one or more Android virtual device
      • QEMU
        • similar as VirtualBox  or VMWare
    • steps
      • open AVD Manager
      • create a virtual device
      • select hardware
      • select system image
        • Android edition
        • CPU (ARM , x86)
        • API level
      • verify configuration
    • Run app
      • launch emulator
        • java original code 
          • compile to bytecode
            • build up APK (include java.file  + libraries + res)
              • APK upload to AVD and be installed
                • AVD active app's activities
                  • start from "MainnActivity.java"
                    • activity point to "activity_main.xml"
                      • activity let screen show the layout
                        • monitor by console
APK
  • Android application package
  • aka . Android application 's JAR or ZIP files


Java => bytecode => APK

Android is not operating on "Java VM "
but on "ART " or the older version "Dalvik"

  1. you wrote the java code
  2. compile to .class file
  3. assemble the .class files to DEX format single file (smaller and more efficiency bytecode)
  4. ART execute DEX code
ART
  • translte the DEX bytecode to more suitable code on Android device
    • faster and less power consumption
JVM
  • waste lots of memory resources
    • each app run its own process

============================================================================================================================================

Modify App


  • Activity tell app what to do ? how to response the user ? MainActivity.java
  • Layout show how the app look like , appearance?  activity_main.xml
    • app/src/main/res/layout
      • code editor (Text)
        • =>elements...more later on 
          • <RelativeLayout>
            • relative position show the arrangement
          • <TextView>
            • show the text
            • string.xml
              • @android : text = "@string/hello_world"
      • design editor (Design)
string.xml
  • save the string name / value resource file
    • layout and activity can use name to inquire the correspond string  
  • for international concern
    • varies of different languages
  • app/src/main/res/values/strings.xml
    • <resources>
    • include , simple values , color , string
  • app/src/main/res/values_fr

<string name = "string_name">string_value</string>
"@string/string_name"

============================================================================================================================================

Quick Recap

  • Android Edition 
    • version number + API level + version code
  • Android Studio
    • special edition IntelliJ IDEA + Android SDK + grandle
  • Android app
    • activity + layout + res
  • layout
    • RelativeLayout
    • TextView
  • activity
  • strings.xml
  • AndroidManifest.xml
  • AVD
  • APK
    • Android app .JVR include app's ( bytecode + libraries + res )
  • ART
    • Android runtime
      • independent process