Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project.

Similar presentations


Presentation on theme: "CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project."— Presentation transcript:

1 CHAPTER 1 part 1 Introduction

2 Chapter objectives: Understand Android 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

3 1.1Android Platforms Introduced in 2008 2016 Android applications include – fluid animations, – sophisticated multitasking menus – voice interactions Current version as of Sept 2016 is Android 7 Nougat – Not on many devices yet – Previous version was Android 6 Marshmellow

4 Table 1-1 shows the evolution of Android

5

6

7 1.2 Java vs. Android Java A large number of Java libraries are available in the Android platform The SDK includes – a debugger, – software libraries, and – an emulator for an Android device

8 differences between the Java API and the Android API Java is run in a virtual machine (VM) – There is no Java virtual machine in the Android platform – Instead uses a specialized virtual machine called Dalvik Compiling apps – Java compiled into bytecode by the Java compiler, – Java bytecode compiled again into a Dalvik bytecode – uses the Dalvik dx tool Dalvik bytecode – not Java bytecode – is a compact executable format designed for Android systems

9

10 1.3 Android Studio IDE Android Studio is the official IDE for building Android applications – Can also develop on Eclipse; we won’t Developed by Google, Only for Android development comes bundled with the Android Software Development Kit, SDK The SDK provides – developer tools and – API libraries for building complete applications, – testing them on virtual devices, and – performing debugging and optimization

11 1.4 The Basics of App Design The process for building an application

12 Creating a project Starting a project – File -> New -> New Project – Must specify the minimum SDK. More devices vs more features – Choose template Creates a type of activity Note that the book asks for a different type of activity (Blank) that you may see (Basic) Do not choose “Empty”; this does not have a layout – Name the activity

13 Creating a project There are default activity and layout names – You can change to whatever you want – The tutorials use the default Do not use a fragment yet. Click finish May run into various problems – Filesystem case-sensitivity problem (easy to fix) – Missing styles on layout (fix automatically) – Failed to find toolbarStyle can ignore

14 1.5 The Anatomy of an Android Project A project built in Android Studio, will be structured similar to Figure 1-6 Project structure is organized by source code, the application’s resources, manifest settings, and build files All of these files are eventually packaged into an apk file, which represents the final app

15 Java Editor Layout Editor Android SDK Android SDK Archive AVD Gradle

16 1.5.1 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 application-wide settings such as the application’s style and launch icon.

17 1.5.1 Android Manifest File Supplies system attributes used with Android apps The package you created

18 1.5.1 Android Manifest File Sets the icon that will appear on the home screen to be an image that is in the mipmap folder Sets the background Only one application node An application can have many actvities but only one main activitiy

19 1.5.1 Android Manifest File <uses-feature android:name=“android.hardware.Camera”/> andoid:required=“true” /> <uses-permission android:name=“android.permission.Camera”/> <uses-permission android:name=“android.permission.WRITE_EXTERNAL_S TORAGE”/> The device must have a camera Can also set hardware requirements and require permissions (location services, SMS, access to external storage, etc.) App will request permission to use camera App will request permission to use external storage.

20 1.5.2 Java Source Code and Activity class files The Java source code of an application is placed in the java directory A main file is auto-generated when the project is first built: MainActivity or MyActivity, Name varies, depending on the Android Studio version Controls behavior of app when it first loads

21 1.5.2 Java Source Code and Activity class files An activity class corresponds to a single action that the user can perform Apps have one or more activities – Must have exactly one main activity Each activity is represented by a user interface called a layout Activities defined by two files: – Java class determines behavior – Layout determines visual representation

22 1.5.3 Resources All application resources are located in the res directory This directory contains subdirectories – drawable All drawable resources (images) – layout Defines the placement of visual objects including buttons, text, and images on the canvas that represents the activity. XML. – menu Defines the application menu bar. We’ll discuss this later. – mipmap The mipmap folders are only for placing your app/launcher icons (which are shown on the homescreen). – values Contains literal strings, colors, etc. that are referenced in the application

23 1.5.3 Drawable 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 – There is a default launch icon ic_launcher.png Recommend PNG format, non-interlaced, 24- bits. Do not have to be web-safe.

24 Android runs on a variety of devices. low-density small screens to high-density large screens dp = density-independent pixel Virtual pixel unit that is equivalent to one physical pixel on a 160-dpi screen. Conversion of dp to screen pixels (px): px = dp X (dpi/160) E.g., on a 240-dpi screen 1 dp = 1.5 px

25 generalized screen sizes: 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 Developers often include 3-5 bit-mapped versions of an image for different generalized density buckets: low, medium, high, extra-high.

26 images Creating images – Start with raw resource in vector format – Generate images for each density using scale: xxhdpi:3.0 xhdpi:2.0 hdpi:1.5 mdpi:1.0 (baseline) – Android automatically chooses correct sized image e.g., a 300x300 image for xxhdpi device must be 200x200 for xhdpi, 150x150 for hdpi and 100x100 for mdpi

27 1.5.4 Layout XML files User interface screens are visually designed and coded as XML layout files Layout is managed by an activity Layouts can be arranged to account for different screen sizes (see chapter 2) Files are stored in the directory res/layout

28 1.5.4 Layout XML files

29 Value Resources Value resources: strings, colors, dimensions, styles Stored in res/values directory Implemented in XML Act as constants that can be used in the Java code. Value resources organized by type – strings.xml – colors.xml

30 Gradle Scripts Grade scripts are build files Stored in Gradle Scripts directory Set things like the minimum API level, target SDK version. – If SDK version different than API level app will run on the min API level device but source code must only use APIs from that level. Build system can generate multiple apk files with different build configurations so that different versions of app can be built.


Download ppt "CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project."

Similar presentations


Ads by Google