Android Fundamentals and Components Kris Secor Mobile Application Development.

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
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.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android: Layouts David Meredith
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android Development: Application Layout Richard S. Stansbury 2015.
Introducing the Sudoku Example
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Modify Android Objects Using.
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
CS5103 Software Engineering Lecture 08 Android Development II.
PROG Mobile Java Application Development PROG Mobile Java Application Development Developing Android Apps: Components & Layout.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
Mobile Programming Lecture 6
CS378 - Mobile Computing Intents.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Overview of Android Application Development
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
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
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Building User Interfaces Basic Applications
Lecture 2: Android Concepts
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.
Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Lab7 – Appendix.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Lecture 2: Android Concepts
Android Application Development 1 6 May 2018
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Mobile Application Development BSCS-7 Lecture # 8
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Korea Software HRD Center
Introduction to Android
Mobile Programmming Dr. Mohsin Ali Memon.
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Android Fundamentals and Components Kris Secor Mobile Application Development

 1. Activities  2. Services  3. Broadcast Receivers  4. Content Providers Mobile Application Development

 Activity is the basic building block of every visible android application.  It provides the means to render a GUI.  Every screen in an application is an activity by itself.  We can call each visible component as an activity in android.  Though more than one activities work together to present an application sequence, each activity is an independent entity. Mobile Application Development

 Service is another building block of android applications which does not provide any UI.  It is a program that can run in the background for an indefinite period.  That means if we want to do a long operation (example: download data from internet), then we need to create an Android service for this purpose. Mobile Application Development

 Started Service (Unbounded)  This type of service is created and called by Android Activities. There is no 2 way communication between Android Activity and Service. The Activity just started the service and does not care about the status of the service. The Service will finish it’s work and automatically stops when finish it’s job.  Bound Service (Bounded)  This type of Android Service is for 2 way communication. Suppose an Android Activity has started a bound service, then Activity can be notified the status by the service. Mobile Application Development

 Broadcast receivers can receive or respond to any broadcast announcements  Eg:when a new message comes to your inbox, this information will be broadcast to all applications. If any application wants to do something with the new message, then it can receive the broadcasted message details (Like: sender’s number, content etc.) and process accordingly. Mobile Application Development

 Content Providers are a separate league of components that expose a specific set of data to applications.  If you want to search a contact in your contact database (Like: name, number etc), then you can use Content Provider for this purpose. You can say Content provider is the pointer in your application to a specific data base from other application. Mobile Application Development

 C.R.U.D. Mobile Application Development

 We need to see how the aforementioned component communicate which is why we need to know intents and intent filters. Mobile Application Development

 Intents are messages that are passed between components.  They are not API’s  1. API calls are synchronous while intent- based invocation is asynchronous (mostly)  2. API calls are bound at compile time while intent-based calls are run-time bound (mostly) Mobile Application Development

 In simple word, the core android components of an application — activities, services, and broadcast receivers — are activated through messages, called intents.  For example an activity can send an intent to the Android system which starts another activity. So Intent is just a way to send message in android. Mobile Application Development

 Implicit intents specify the action which should be performed by other components or applications.  For Example: If you want to open an URL in a web browser from your application code, Then following code tells the Android system to view a webpage. Typically the web browser is registered to this Intent but other components could also register themselves to this intent. That means if you have installed web browsers like IE, Mozilla Firfox and Google Chrome, then all browsers might be registered to the intent (Intent.ACTION_VIEW) to show a web page as per you request.  Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("  startActivity(i);  If only one component (our web browser in this example) is found, Android starts this component directly. If several components are identified by the Android system, the user will get an selection dialog and can decide which component should be used for that Intent. Mobile Application Development

 Explicit intents explicitly define the exact component which should be called by the Android system, by using the Java class as identifier.  The following code shows how to create an explicit intent and send it to the Android system. That means Android system will directly execute your intent request as you requested. Explicit intents are typically used within an application as the classes in an application are controlled by the application developer. If you want to open an Android Activity from another activity, then below is the code using intent. Also you can send some data to that activity if required.  Intent i = new Intent(this, ActivityTwo.class);  i.putExtra("First Value", "This First Value for ActivityTwo");  i.putExtra("Second Value", "This Second Value ActivityTwo"); Mobile Application Development

 To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters. Each filter describes a capability of the component, a set of intents that the component is willing to receive.  Eg:A note saving application might have two filters — one for starting up with a specific note that the user can view or edit, and another for starting with a new, blank note that the user can fill in and save. Mobile Application Development

 Basically IntentFilters are defined in the AndroidManifest.xml file.  For a BroadcastReceiver it is possible to define in coding.  IntentFilters are defined by its category, action and data filters. It can also contain additional metadata. If a component does not define an Intent filter, then it can only be called by explicit Intents. Mobile Application Development

 You have two ways you can create the interface(s) of your Application. 1. Code = write code using SDK with classes like LinearLayout, TextView, …… 2. XML = create XML files in res/Layout (i.e. main.xml) that contain Android XML view tags like, etc.

Lets look at this option first

 Generally, I would say if it is possible, doing XML would be better as it means a decoupling of design from Java code.  You can have both in your system….  Lets discuss this first.

 Layouts defined with XML located in res/layout

 res/layout/main.xml = contains layout for interface <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /> The above will create an interface in vertical (versus portrait) mode that fills the parent Both in width wraps and content as necessary.

 it's a tree of XML elements, ◦ Inspired by web authoring ◦ Build up UI quickly  each node is the name of a View class (example is just one View element). ◦ Create your own View ---extends ◦ Each node can have multiple attributes ◦ Look to API for details

 ◦ xmlns:android XML namespace declaration that tells the Android tools that you are going to refer to common attributes defined in the Android namespace. The outermost tag in every Android layout file must have this attribute. ◦ android:layout_width This attribute defines how much of the available width on the screen this View should consume. As it's the only View so you want it to take up the entire screen, which is what a value of "fill_parent" means. android:layout_height This is just like android:layout_width, except that it refers to available screen height. ◦ android:text This sets the text that the TextView should display. In this example, you use a string resource instead of a hard-coded string value. The hello string is defined in the res/values/strings.xml file.

 Visual creation of XML file  Create New->Other->Android->XML file- ◦ Select for layout type ◦ Play with it…. drag and drop

 Visual creation of XML file  Create New->Other->Android->XML file- ◦ Select for layout type ◦ Play with it…. drag and drop

 I dragged and dropped an EditText view and a Button. Below I show you the corresponding code. res/layout/main2.xml <AbsoluteLayout xmlns:android=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">

Besides drag and drop you can edit the xml file directly. Lets discuss some of the Android XML Interface related tags

Control structure of interface

 Determines how the layout is structured.  Some Tags  LinearLayout  A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). You can also specify gravity, which specifies the alignment of all the child elements by calling setGravity() or specify that specific children grow to fill up any remaining space in the layout by setting the weight member of LinearLayout.LayoutParams. The default orientation is horizontal.setOrientation()setGravity() LinearLayout.LayoutParams  AbsoluteLayout  A layout that lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.  RelativeLayout  FrameLayout  TableLayout

 Visual creation of XML file  XML Attributes Attribute Name Related Method Description android:baselineAligned setBaselineAligned(boolean) When set to false, prevents the layout from aligning its children's baselines. android:baselineAlignedChildIndex setBaselineAlignedChildIndex(int) When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView). android:gravity setGravity(int) Specifies how to place the content of an object, both on the x- and y-axis, within the object itself. android:measureWithLargestChild When set to true, all children with a weight will be considered having the minimum size of the largest child. android:orientation setOrientation(int) Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. android:weightSum Defines the maximum weight sum. android:baselineAligned setBaselineAligned(boolean)android:baselineAlignedChildIndex setBaselineAlignedChildIndex(int)android:gravitysetGravity(int)android:measureWithLargestChildandroid:orientationsetOrientation(int)android:weightSum

Control structure of interface, but commonly a sub-area

 A view that shows items in a vertically scrolling list. Attributes  android:divider Drawable or color to draw between list items. android:divider  android:dividerHeight Height of the divider. android:dividerHeight  android:entries Reference to an array resource that will populate the ListView. android:entries  android:footerDividersEnabled When set to false, the ListView will not draw the divider before each footer view. android:footerDividersEnabled  android:headerDividersEnabled When set to false, the ListView will not draw the divider after each header view. android:headerDividersEnabled

 A view that shows items in a center- locked, horizontally scrolling list.  The default values for the Gallery assume you will be using Theme_galleryItemBackground as the background for each View given to the Gallery from the Adapter. If you are not doing this, you may need to adjust some Gallery properties, such as the spacing. Theme_galleryItemBackground Attributes  android:animationDuration setAnimationDuration(int) Sets how long a transition animation should run (in milliseconds) when layout has changed. android:animationDurationsetAnimationDuration(int)  android:gravity setGravity(int) Specifies how to place the content of an object, both on the x- and y-axis, within the object itself. android:gravitysetGravity(int)  android:spacing setSpacing(int) android:spacingsetSpacing(int)  android:unselectedAlpha setUnselectedAlpha(float) Sets the alpha on the items that are not selected. android:unselectedAlphasetUnselectedAlpha(float)

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery gallery = (Gallery) findViewById(R.id.gallery); gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show(); } }); }

Making the elements of your GUI

 An Activity can contain views and ViewGroups.  android.view.View.* = base class for all Views. ◦ example sub-classes include: TextView, ImageView, etc.  android.view.ViewGroup = Layout for views it contains, subclasses include ◦ android.widget.LinearLayout ◦ android.widget.AbsoluteLayout ◦ android.widget.TableLayout ◦ android.widget.RelativeLayout ◦ android.widget.FrameLayout ◦ android.widget.ScrollLayout

 arranges by single column or row.  child views can be arranged vertically or horizontally. <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Text View android:layout_width=“fill_parent” android:layout_height=“wrap_content”

 You can set either in XML or with set*() methods.  i.e. Xml android:orientation=“vertical” code (ll is LinearLayout instance) ll.setOrientation(VERTICAL);

AttributeDescription layout_widthspecifies width of View or ViewGroup layout_heightspecifies height layout_marginTopextra space on top layout_marginBottomextra space on bottom side layout_marginLeftextra space on left side layout_marginRightextra space on right side layout_gravityhow child views are positioned layout_weighthow much extra space in layout should be allocated to View (only when in LinearLayout or TableView) layout_xx-coordinate layout_yy-coordinate