CHAPTER 1 Part 2 Android Programming. Chapter objectives: Understand how to create a simple Android project Understand how to create a manifest file Understand.

Slides:



Advertisements
Similar presentations
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Advertisements

All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Android Development (Basics)
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Better reference the original webpage :
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Chapter 3 Navigating a Project Goals & Objectives 1.Get familiar with the navigation of the project. How is everything structured? What settings can you.
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Chapter 5 Creating User Interfaces GOALS and OBJECTIVES Begin our application by creating our user interface. More than one way to create a user interface.
IE 411/511: Visual Programming for Industrial Applications
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
Basic Android Tutorial USF’s Association for Computing Machinery.
DUE Hello World on the Android Platform.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Android Boot Camp for Developers Using Java, 3E
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
Creating an Example Android App in Android Studio Activity lifecycle & UI Resources.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
ANDROID APPLICATION DEVELOPMENT. ANDROID DEVELOPMENT DEVELOPER.ANDROID.COM/INDEX.HTML THE OFFICIAL SITE FOR ANDROID DEVELOPERS. PROVIDES THE ANDROID SDK.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Intoduction to Andriod studio Environment With a hello world program.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project.
Introduction to Android Chapter 1 1. Objectives Understand what Android is Learn the differences between Java and Android Java Examine the Android project.
Dive Into® Visual Basic 2010 Express
Chapter 2: Simplify! The Android User Interface
Lab7 – Appendix.
Introduction to android
Lab7 – Advanced.
Open Handset Alliance.
Mobile Application Development BSCS-7 Lecture # 2
GUI Programming Fundamentals
Android – Event Handling
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Chapter 2 – Introduction to the Visual Studio .NET IDE
MAD.
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Visual programming Chapter 1: Introduction
Android SDK & App Development
CS323 Android Getting Started
Chapter 2 – Introduction to the Visual Studio .NET IDE
CIS 470 Mobile App Development
Welcome to E-Prime E-Prime refers to the Experimenter’s Prime (best) development studio for the creation of computerized behavioral research. E-Prime is.
Android Developer Fundamentals V2 Lesson 1
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
HNDIT2417 Mobile Application Development
Android Programming Tutorial
CIS 470 Mobile App Development
Android Application Development
Android Project Structure, App Resources and Event Handling
Mobile Programming Dr. Mohsin Ali Memon.
Mobile Programmming Dr. Mohsin Ali Memon.
Cosc 4730 An Introduction.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

CHAPTER 1 Part 2 Android Programming

Chapter objectives: Understand how to create a simple Android project Understand how to create a manifest file Understand how to import resources Understand how to run an app on an Android device Prerequisite: must know Java!

Tutorial 1 Need resources from the book /

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 (Empty) choose “Empty” – Name the activity

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

Tutorial 1: Hello Goodbye app Add and Edit Resources – Text values, graphic files, data values, color def Hello Goodbye app – Drawables: 3 graphic files (background image, button image, graphic image) May have to copy the launch icon in also! – String values: “hello”, “goodbye” – Color values: color for “hello” text and “goodbye” text.

Resources Image file names must be lowercase Drawable need different pixel densities (see previous pptx slides) Different folders for different densities – If a folder is not present, Android will create it when you add image – If it won’t create the folder, you can create it yourself. – See next slide.

Resources Different folders for different densities – If a folder is not present, Android will create it when you add image – If it won’t create the folder, you can create it yourself. – App/src/main/res/drawable-xxhdpi – do this in Android studio; could also do in finder – For xxhdpi image should be in folder “drawable-xxhdpi” at the same level as the “drawable” folder – If you do this correctly, you should see the structure shown in figure 1-25 – You can paste the xxhdpi background.png into both the xxhdpi folder and the xhdpi folder.

Resources

Other Resources The tutorial will have you create strings in the res/values/strings.xml file You will create a color in the res/values/color.xml file but must create the file first. #B530BD

Constructing the Interface Layout files in XML There is a default layout created when the project is created The tutorial uses the file activity_main.xml Two modes: – Design (visual). Similar to Java Swing – Text. XML.

Interface What to do if your interface won’t render: choose a different version of the API

Interface Construction Canvas – the screen Palette – elements that can be dragged to the canvas Android Version – that is used to render the interface Device – each device has it’s own look and feel Orientation – portrait or landscape or UI Mode such as TV AppTheme – configuration theme, e.g., all balck, full screen with no title

Interface Construction Outline– the hierarchical list of visual elements placed on the layout file. Root is a “container”; will explore these later. Properties – each visual object has a collection of context-sensitive properties that can be set, e.g., color, width, etc. Mode Tabs – can build interface via text or visually

Building the Interface Note that you might have a CustomView – this layout might have a line in the XML like – You should open the layout “content_main” This will have a RelativeLayout may have to edit the content_main.xml, e.g., to delete the “hello world!” text or to add text. – Instructions in the tutorial will still work

Changing Background Your resource dialog box may look like this! This is the “drawable drawer”

Building the Interface Note: use the resources (string, color) as described in the tutorial in your Java code. – Do NOT enter text directly, even though this works!

Sizing Elements Sizes of GUI components and text can be specified in dp or sp Notation dp: density-independent pixel – 1 dp = 1 pixel on a 160-dpi screen. – On a 240-dpi screen each dp pixel is scaled by a factor of 240/160 – The sp = scale independent pixel. – Scaled like dp but use the user’s preferred size (as specified in settings)

Where Code Goes Apps can have several screens – Each screen is coded separately – A screen is called an “activity” Every screen has two files associated with them: – A java file that contains code – A XML file that describes the look (components, background, etc.) of the page

Adding Code Will code the MainActivity class – The MainActivity.java class is created with the project – Represents the main Java class that will be executed when the app is launched. – This class is a subset of the Activity class Inherits method callbacks when activity is created, paused, stopped, resumed, destroyed

Adding Code Two objectives – Inflate the user interface layout – Control and respond to the UI elements

Class Variables public class MainActivity extends AppCompatActivity { private TextView greetingTextView; private boolean isHello; private void initializeGreeting(){ isHello = true; }

Inflating onCreate() – Callback method, called when activity is created – Used to initialize the actviity, e.g., set up user interface, initialize state

onCreate() protected void onCreate(Bundle savedInstanceState) { // Task 1 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Task 2 greetingTextView = (TextView) findViewById(R.id.textView); // Task 3 initializeGreeting(); // Task 4 Button exclaimBtn = (Button) findViewById(R.id.button); exclaimBtn.setOnClickListener(toggleGreeting); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // ATTENTION: This was auto-generated to implement the App Indexing API. // See for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); } Initialize the app, associate this code with It’s layout. These are always done. Task 2: get a pointer to the text box. Task 3: set the value of the global variable “isHello”

Accessing Resources Can refer to resources with the constant “R”, e.g., R.id.textView // refers to the resource with // id of “textView” Recall that the text box in the interface had name “textView” in the strings.xml file: <TextView …more stuff

onCreate() protected void onCreate(Bundle savedInstanceState) { // Task 1 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Task 2 greetingTextView = (TextView) findViewById(R.id.textView); // Task 3 initializeGreeting(); // Task 4 Button exclaimBtn = (Button) findViewById(R.id.button); exclaimBtn.setOnClickListener(toggleGreeting); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // ATTENTION: This was auto-generated to implement the App Indexing API. // See for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); } This is the listener. The actual variable “toggleGreeting” is an instance of a View.OnClickListener

Adding Code Registering an onClick listener: – We need to associate code with a click on the button – Do this by “registering” a “listener” method to the “onClick” event for the button: Button exclaimBtn = (Button) findViewById(R.id.button); exclaimBtn.setOnClickListener(toggleGreeting); This is the name of the method (defined by us in this class) that will be called when the event happens

Adding Code This is the event handler (a method that is called when the event is triggered). – Uses an inner class, i.e., a class that is defined “on the fly” in the code. private final View.OnClickListener toggleGreeting = new View.onClickListener(){ public void onClick(View btn){ // Task: construct the toggle greeting if (isHello){ isHello = false; greetingTextView.setText(R.string.goodbye); } else { isHello = true; greetingTextView.setText(R.string.hello); } } }; This variable will hold an instance of an OnClicListener class that is defined here

Adding Code new View.onClickListener(){ public void onClick(View btn){ // Task: construct the toggle greeting if (isHello){ isHello = false; greetingTextView.setText(R.string.goodbye); } else { isHello = true; greetingTextView.setText(R.string.hello); } } }; Creates an instance of the class View.onClickListener The class has no variables and one method: onClick(View btn) One class variable is tested: isHello greetingTextView points to the text box. We set its value using a resource from string.xml

building Uses scripts in the Gradle Scripts directory – Build.gradle – Provides locations of the app’s manifest, source, resources, assets. – The Android Asset Packaging Tool (aapt) collects all XML files and compiles into a java file: R.java – R.java provides reference to resources – Java compiler produces.class files – The dex tool compiles.class to Dalvik bytecode – Apkbuilder tool packages.dex, resources, etc. to.apk

Running on a device Build->Rebuild Project – Compiled then packaged into.apk – Includes.dex files (Dalvik byte code), binary version of manifest, resources, etc. – App must be signed In debug mode Android Studio signs for you To release you need a private key

Running on a device Can use any Android device – Must configure the device for development use – See textbook – Note that developer options may not be visible on your device Settings->about tablet/phone and press “Build” 7 times – When developer options are visible, toggle to enable Connect to your computer via USB

running Plug in device Run->Run ‘app’ Choose device to run on Note that a device has to have developer mode enabled. Go to settings  About phone and tap the Build number 7 times