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.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
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.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Android Application Development 2013 PClassic Chris Murphy 1.
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.
CS5103 Software Engineering Lecture 08 Android Development II.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
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.
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.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
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.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Android - Broadcast Receivers
Android Boot Camp for Developers Using Java, 3E
User Interfaces: Part 1 (View Groups and Layouts).
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
First Venture into the Android World Chapter 1 Part 2.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Mobile Programming Lecture 3 Debugging. Lecture 2 Review What widget would you use to allow the user to enter o a yes/no value o a range of values from.
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
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Intoduction to Andriod studio Environment With a hello world program.
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
BUILDING A SIMPLE USER INTERFACE. In this lesson, you create a layout in XML that includes a text field and a button. In the next lesson, your app responds.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
Android apps development - Eclipse, Android SDK, and ADT plugin Introduction of.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Chapter 2: Simplify! The Android User Interface
Lab7 – Appendix.
Introduction to android
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Android – Event Handling
MAD.
Android Widgets 1 7 August 2018
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
Android Project Structure, App Resources and Event Handling
Adding Components to Activity
Building a Simple User Interface
CMPE419 Mobile Application Development
Activities and Fragments
Chapter 5 Your Second Activity.
CIS 470 Mobile App Development
Presentation transcript:

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 TechCrunch (by the developer of the SMS/MMS app Emu: The Fallacy of Andoid First

Basics Apps are composed of activities and layouts an activity is an instance of the activity class manages user interaction with a screen of info subclass it to implement app functionality may have many activities for a complex app a layout defines a set of user interface objects and their position on the screen uses XML each definition creates an object on the screen

Create the project in Eclipse: File->New->Android Application name: GeoQuiz package: edu.ithaca.android.geoquiz Target SDK: API 16: Android 4.1 (Jelly Bean) doesn’t matter as long as you’ve downloaded this in Eclipse click next

Configuring the project unclick “Create custom launcher icon” leave “Create activity” checked uncheck “Mark this project as a library” check “Create Project in Workspace” should not have to change location uncheck “Add project to working sets” click next

Configuring Project click on “Blank Activity” click next Name the activity subclass QuizActivity convention to end name with “Activity” but not required layout name will fill in automagically. Provides recommended naming style. click finish

Laying out the user interface Open the layout file in the folder res/layout named activity_quiz.xml select the “activity_quiz.xml” tab at the bottom of the middle screen of Eclipse. we will ignore the graphical layout tool for now we will use this file to create our view. should have a framelayout in the folder res/layout for fragments or partial layouts named fragment_quiz.xml we will ignore this file; we’re not going to use fragments

Default Layout (part 1) in activity_quiz.xml <FrameLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="edu.ithaca.geoquiz4.QuizActivity" tools:ignore="MergeRootFrame" />

Default Layout (part 1) in fragment_quiz.xml <RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="edu.ithaca.geoquiz4.QuizActivity$PlaceholderFragment" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" />

Default Layout (part 2) <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" />

Layout file default fragment_quiz.xml file has two widgets RelativeLayout TextView Widgets are the components of a view every widget is an instance of the View class or one of its subclasses Click the Graphical Layout tab at bottom to see how the layout looks

Layout QuizActivity requires 5 widgets: a vertical LinearLayout a TextView a horizontal LinearLayout two Buttons

Layout Overwrite all the text in activity_quiz.xml with this <LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="24dp" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> There will be errors! + sign means that you are creating the resource not just referencing it

The view hierarchy

Widget Attributes android:orientation determines whether the children appear vertically or horizontally the order in which children are defined determines the order in which they appear on screen. in vertical, first child is topmost in horizontal, first child is leftmost (unless right-to-left language)

Widget Attributes android:text tells widget what text to display not literal strings (thought they could be) instead references to string resources a string that lives in a separate XML file called the strings file allows for easy localization

String Resources every project has a default strings file named strings.xm l open the strings.xml file in res/values click on strings.xml tab at bottom remove the hello_world string, add three new strings GeoQuiz The Pacific Ocean is larger than the Atlantic Ocean. True False Correct! Incorrect! Settings keep the menu_settings or you’ll get lots of errors!

String Resources whenever you refer in any XML file in the GeoQuiz project, get “False” at runtime. save strings.xml errors in fragment_quiz.xml should go away may get warnings; can ignore. You can have multiple strings files in your project must be in res/values must have a resources root element must contain child string elements your strings will be found automagically

Creating View Objects How do XML elements become View objects? see code on next slide contains two Activity methods onCreate(Bundle) called when an instance of the activity subclass ( QuizActivity ) is created. calls method setContentView(int layoutResID) this method inflates a layout and puts it on the screen also asks the fragment manager to add the appropriate fragments each widget is instantiated as defined by its attributes you specify which layout by passing the layout’s resource ID (see later) onCreateOptionsMenu(Menu)

Creating View Objects protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); if (savedInstanceState == null) { getFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); } Delete this method; we won’t use fragments!

Resources and resource IDS resource: a piece of your app that is not code images, audio files, XML files resources live in a subdirectory of the res directory activity_quiz.xml lives in res/layout/ strings file lives in res/values/

Resources and resource IDS resource: can see by opening the file R.java it’s in the gen/edu.ithaca.android.geoquiz directory the edu.ithaca.android.geoquiz name depends on what you named your package. this file is generated by the build process won’t be there until you build! you should see a value similar to public static final int activity_quiz=0x7f030000;

Resources To access a resource in code use its resourceID resource for our layout is R.layout.activity_quiz Android generates resource IDs for entire layouts and each string but not individual widgets to generate a resourceID for a widget must include an android:id attribute in the widget’s definition For each button add the attribute: or the + sign means to create the id

Wiring up widgets Can access buttons via their resource IDs Add the bold lines to QuizActivity: public class QuizActivity extends Activity { private Button mTrueButton; private Button protected void onCreate(Bundle savedInstanceState) { these will cause errors: the Button type needs to be imported! see next slide! the m prefix is an android convention

Wiring up widgets To fix the import error can organize your imports To organize press: Command+Shift+O on mac Ctrl+Shift+Oon windows/linux this will put in the necessary imports

Wiring up widgets To wire up buttons: get references to the inflated View objects set listeners on those objects to respond to user actions

Get ref to widgets Can get a reference to an inflated widget by calling: public View findViewById(int id) this method accepts a resource ID of a widget it returns a View object Add to QuizActivity.java see next slide

Get ref to widgets protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); mTrueButton = (Button)findViewById(R.id.true_button); mFalseButton = (Button)findViewById(R.id.false_button); return true; }

Setting Listeners Android apps are event driven When app is waiting for a specific event it is listening for that event A listener is an object that implements a listener interface for that event. listener interfaces are provided by Android for most events

Setting Listeners Our app: want to listen for a mouse click Must implement the View.OnClickListener interface

Setting Listeners protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); mTrueButton = (Button)findViewById(R.id.true_button); mTrueButton.setOnClickListener(new View.OnClickListener() public void onClick(View v) { // TODO Auto-generated method stub } }); mFalseButton = (Button)findViewById(R.id.false_button); return true; } We’ll fill this in shortly!

Anonymous Classes The listener on the last slide is an anonymous inner class Most listeners in Android use this technique The anonymous inner class implements the OnClickListener interface. means it must implement the interface methods in this case, there is only one: OnClick(View) Must set a similar class for the false button (next slide)

Setting Listeners // mTrueButton code is still here, I just took it out to save room mFalseButton = (Button)findViewById(R.id.false_button); mFalseButton.setOnClickListener(new View.OnClickListener() public void onClick(View v) { // TODO Auto-generated method stub } }); return true; } We’ll fill this in shortly!

Toasts A pop-up message in Android is called a toast A toast is a short message that informs the user of something but does not require any input or action. We’ll make toasts that announce whether the user answered correctly or not.

Toasts To make a toast call the following method from the Toast class: public static toast Toast makeText(Context context, int resId, int duration) The Context parameter is typically an instance of an Activity class. The second parameter is the resource ID of the string that the Toast will display needs the Context to find and use the string’s resource ID Third parameter is one of two Toast constants that specify how long the toast should be visible

Toasts After you make a Toast, use Toast.show() to get it on the screen. see next slide

Making Toasts for mTrueButton handler: public void onClick(View v) { Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show(); } QuizActivity.this indicates the correct context Cannot just say “this” because we’re inside an anonymous class!

Making Toasts for mFalseButton handler: public void onClick(View v) { Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show(); }

Run right click on name and choose Run As->Android Application To run on device, on a Mac just connect device via USB. on Windows may need to install the abd (Android Debug Bridge). may have to download from your device manufacturer’s website must set device up (see next slide).

Setting up device Step 1 Must set up device to accept applications that are not from Google Play if device is running Android 4.1 or earlier, go to Settings  Applications. Make sure Unknown sources is checked. if device is running Android 4.2 or later, go to Settings  Security. Make sure Unknown sources is checked.

Setting up device Step 2 Must enable USB debugging in the device. Android 4.0 and earlier: Settings  Applications  Development and enable USB debugging Android 4.1 or later. Must enable developer options. Go to Settings  About Tablet/phone and press Build Number 7 times. Return to Settings see Developer Options and enable USB Debugging.

Debugging To see what’s happening on the device or the emulator, see the LogCat window at the bottom of Eclipse (next to the console window). If it’s not showing go to Window  Show View  Other Expand Android and double-click on LogCat