04 calculator

Upload: jojo-cansino

Post on 14-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 04 Calculator

    1/18

    Programming with Android:Calculator Example

    Luca Bedogni Marco Di FeliceDipartimento di Informatica: Scienza e Ingegneria

    Universit di Bologna

  • 7/30/2019 04 Calculator

    2/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: Outline

    Today:

    How to build a Calculator? Define the layout of the application

    Create an application that uses this layout

    Add some sort of intelligence to the application

    Test it

  • 7/30/2019 04 Calculator

    3/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout

    Define the buttons, labels, cells and so on

    Place them on the screenPay attention: Android powered phones are very

    different in terms of resolutions

    Try not to stick with absolute values/positioning (

    will see this later)

  • 7/30/2019 04 Calculator

    4/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

  • 7/30/2019 04 Calculator

    5/18Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

  • 7/30/2019 04 Calculator

    6/18Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

    Operator

  • 7/30/2019 04 Calculator

    7/18Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

    Operator

    Second Ope

  • 7/30/2019 04 Calculator

    8/18Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

    Operator

    Second Ope

    Result

  • 7/30/2019 04 Calculator

    9/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

    Operator

    Second Ope

    Result

    Operator

  • 7/30/2019 04 Calculator

    10/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout definition

    First Operand

    Operator

    Second Ope

    Result

    Operator

  • 7/30/2019 04 Calculator

    11/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: logic definition

    Whenever a user selects a operand cell, a keybo

    will pop upPressing an operator button will switch the focus

    one operand to another (except for =)

    We want to deal with float numbers

  • 7/30/2019 04 Calculator

    12/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: events

    We want to be warned when a user touches

    something on the screen Every time this happens, we will react with a set of ac

    The MVC pattern is relaxed that way (pros and cons)

    We do not want the result to be focusable

  • 7/30/2019 04 Calculator

    13/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout building

    We will use a set of layouts

    Layouts are grouped together following a hierarcWhy not absolute positioning?

  • 7/30/2019 04 Calculator

    14/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout building

    We will use a set of layouts

    Layouts are grouped together following a hierarcWhy not absolute positioning?

    Android has a wide range of devices

    Wide range of resolution

    Wide range of capabilities

  • 7/30/2019 04 Calculator

    15/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: layout building

    We will use a set of layouts

    Layouts are grouped together following a hierarcWhy not absolute positioning?

    Android has a wide range of devices

    Wide range of resolution

    Wide range of capabilities

    Need to build dynamic applications that

    performs different depending on the device

    they're running in.

  • 7/30/2019 04 Calculator

    16/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: hierarchy viewer

  • 7/30/2019 04 Calculator

    17/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: Recap

    Define a Layout

    Pay Attention to devices heterogeneityFeatures

    Keyboard should pop up when needed

    Should not pop up on the result

    Switch from one cell to another when pressingoperand

    React to Events

  • 7/30/2019 04 Calculator

    18/18

    Luca Bedogni, Marco Di Felice- Programming with Android Calculator Example

    Calculator: start

    Let's start developing the calculato