Mobile Application Development BSCS-7 Lecture # 3

Slides:



Advertisements
Similar presentations
Programming with Android: Activities and Intents
Advertisements

App Customization. Introduction  Not all Android apps look the same  i.e. the default bland black and white look  Most have custom looks like  Background.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
Intents.
Intents and Intent Filters.  Intents are data structures that specify  Operations to be performed  Events that have occurred  Broadcast by one component.
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,
Mobile Application Development
Mobile Programming Pertemuan 6 Presented by Mulyono Poltek NSC Surabaya.
8/16/2015alicewebmaster1 Create contents with the new Content Management System (Drupal): Workflow for page editors.
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
Basic Android Tutorial USF’s Association for Computing Machinery.
Mobile Application Development using Android Lecture 2.
CS378 - Mobile Computing Intents.
CHAPTER 4 LINKS Creating links between pages Linking to other sites links.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Resources. Application Resources Resources are strings, images, and other pieces of application information that are stored and maintained (externalized)
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Silicon Valley Code Camp 2009 “Embellish Your Pictures” Build an Application for an Android Phone Jack Ha, Balwinder Kaur Oct 3, 2009 – 5:15PM Room CCL.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Lecture 2: Android Concepts
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Editing a Twitter search. Viewing search results in a browser.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project.
Android Embedded Resources Lesson16 Victor Matos Cleveland State University Notes are based on: Android Developers
Chapter 2: Simplify! The Android User Interface
Mobile Applications (Android Programming)
Introduction to android
Android Mobile Application Development
Mobile Applications (Android Programming)
Android Mobile Application Development
Lecture 2: Android Concepts
Android 01: Fundamentals
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
Instructor: Mazhar Hussain
Lecture 3 agenda A tour of Android studio features
Inserting and Working with Images
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
MAD.
Activities and Intents
Creation of an Android App By Keith Lynn
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Anatomy of an Android Application
Android SDK & App Development
Software Engineering for Internet Applications
CS371m - Mobile Computing Intents.
CS323 Android Getting Started
Android Programming Lecture 5
CMPE419 Mobile Application Development
Application Development A Tutorial Driven Course
CA16R405 - Mobile Application Development (Theory)
Activities and Intents
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
HNDIT2417 Mobile Application Development
Activities and Intents
Emerging Platform#3 Android & Programming an App
Android Project Structure, App Resources and Event Handling
It is used to Start an Activity Start a Service Deliver a Broadcast
Introduction to Android
Lecture 2: Android Concepts
Android Development Tools
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

Mobile Application Development BSCS-7 Lecture # 3 by Tanzila Kehkashan

Application Components – Resources Static content that your code uses, such as bitmaps, colors, layout definitions, user interface strings, animation instructions, and more are included in Resources. Maintained separately in various sub-directories under res/ directory of project. Organizing Resources Directory Resource Type Location anim/ XML files that define property animations. saved in res/anim/ folder and accessed from R.anim class. color/ XML files that define a state list of colors. saved in res/color/ and accessed from R.color class. drawable/ Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state lists, shapes, animation drawable. saved in res/drawable/ and accessed from R.drawable class. layout/ XML files that define a user interface layout. saved in res/layout/ and accessed from R.layout class. menu/ XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu. saved in res/menu/ and accessed from R.menu class. by Tanzila Kehkashan

Application Components – Resources Directory Resource Type raw/ Arbitrary files to save in their raw form. You need to call Resources.openRawResource() with the resource ID, which is R.raw.filename to open such raw files. values/ XML files that contain simple values, such as strings, integers, and colors. For example, here are some filename conventions for resources you can create in this directory −arrays.xml for resource arrays, and accessed from the R.array class. integers.xml for resource integers, and accessed from the R.integer class. bools.xml for resource boolean, and accessed from the R.bool class. colors.xml for color values, and accessed from the R.color class. dimens.xml for dimension values, and accessed from the R.dimen class. strings.xml for string values, and accessed from the R.string class. styles.xml for styles, and accessed from the R.style class. xml/ Arbitrary XML files that can be read at runtime by calling Resources.getXML(). You can save various configuration files here which will be used at run time. Alternative Resources Provided to support specific device configurations. At runtime, Android detects tcurrent device configuration and loads appropriate resources for application. by Tanzila Kehkashan

Application Components – Resources Alternative Resources To create new Resource File -> New -> Android Resource File / Android Resource Directory OR Create a new directory in res/ named in the form <resources_name>-<config_qualifier> Here resources_name will be any of the resources, like layout, drawable etc. qualifier will specify an individual configuration for which these resources are to be used. (Check official documentation for a complete list of qualifiers for different type of resources.) Save respective alternative resources in this new directory. Resource files must be named exactly the same as the default resource files, but these files will have content specific to the alternative. For example though image file name will be same but for high resolution screen, its resolution will be high. Figure 1. Two different devices, each using the default layout (the app provides no alternative layouts). Figure 2. Two different devices, each using a different layout provided for different screen sizes. by Tanzila Kehkashan

Application Components – Resources During your application development you will need to access defined resources either in your code, or in your layout XML files. Accessing Resources in Code When your Android application is compiled, a R class gets generated, which contains resource IDs for all the resources available in your res/ directory. You can use R class to access that resource using sub-directory and resource name or directly resource ID. Example To access res/drawable/myimage.png and set an ImageView you will use following code: First line of code make use of R.id.myimageview to get ImageView defined with id myimageview in a Layout file. Second line of code makes use of R.drawable.myimage to get an image with name myimage available in drawable sub-directory under /res. ImageView imageView = (ImageView) findViewById(R.id.myimageview); imageView.setImageResource(R.drawable.myimage); by Tanzila Kehkashan

Application Components – Resources Accessing Resources in XML Consider the following resource XML res/values/strings.xml file that includes a color resource and a string resource. Now you can use these resources in the following layout file to set the text color and text string as follows: Create Varying Density Resources with Android Asset Studio http://romannurik.github.io/AndroidAssetStudio/ <?xml version="1.0" encoding="utf-8"?> <resources> <color name="opaque_red">#f00</color> <string name=“strHello">Hello BSCS!</string> </resources> <?xml version="1.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@color/opaque_red" android:text="@string/strHello" /> by Tanzila Kehkashan

Application Components – Intents Intent is an abstract concept or data structure for some operation that should be performed in the Android OS. Often used to launch external applications with intent to do something, such as make a phone call, display a web page, or map an address. Can be used with startActivity() to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService( Intent, ServiceConnection, int) to communicate with a background Service. Provides a facility for performing late runtime binding between code in different applications. Most significant use is in launching of activities, where it can be thought of as glue between activities. Intent Object An Intent generally has two pieces of information associated with it; What the intent is (as in make a phone call), (Action) What data does the intent need (such as a phone number) to perform the intention. (Data) by Tanzila Kehkashan

Intents – Types of Intents Explicit Intent Used to launch a specific app component, such as a particular activity or service in your app. Implicit Intent Specifies an action that can invoke any app on the device able to perform the action. // Explicit Intent by specifying its class name Intent i = new Intent(FirstActivity.this, SecondAcitivity.class); // Starts TargetActivity startActivity(i); Intent read1=new Intent(); read1.setAction(android.content.Intent.ACTION_VIEW); read1.setData(ContactsContract.Contacts.CONTENT_URI); startActivity(read1); by Tanzila Kehkashan

Intent Fields – Action Action is a String representing desired operation Some Standard Activity Actions android.intent.action.ACTION_DIAL – Dial a number android.intent.action.ACTION_EDIT – Display data to edit android.intent.action.ACTION_SYNC – Synchronize device data with server android.intent.action.ACTION_MAIN – Start as initial activity of app android.intent.action.CALL – Perform a call to someone specified by the data android.intent.action.WEB_SEARCH – Perform a web search android.intent.action.SENDTO – Send a message to someone specified by the data Action in an Intent object can be set by the setAction() method and read by getAction() Setting the Intent Action Intent newInt = newIntent(Intent.ACTION_DIAL); //Or Intent newInt = new Intent(); newInt.setAction(Intent.ACTION_DIAL); by Tanzila Kehkashan

Intent Fields – Data Data to view on a map Data associated with the Intent Formatted as a Uniform Resource Identifier (URI) Examples Data to view on a map Uri.parse(“geo:0,0? q=1600+Pennsylvania+Ave+Washington+DC”); Number to dial in phone dialer Uri.parse(“tel:+3007001001”); The setData() method specifies data only as a URI and The URI is read by getData(). Setting Intent Data Intent newInt = new Intent (Intent.ACTION_DIAL, Uri.parse("tel:+3007001001")); Or Intent newInt = new Intent(Intent.ACTION_DIAL); newInt.setData(Uri.parse("tel:+3007001001")); by Tanzila Kehkashan

Intent Fields – Category Additional information about the components that can handle the intent. addCategory() method places a category in an Intent object removeCategory() deletes a category previously added getCategories() gets the set of all categories currently in the object. Examples Sr.No Categories Description 1 CATEGORY_APP_BROWSER Used with ACTION_MAIN to launch the browser application. 2 CATEGORY_APP_CALCULATOR Used with ACTION_MAIN to launch the calculator application. 3 CATEGORY_APP_CALENDAR Used with ACTION_MAIN to launch the calendar application. 4 CATEGORY_APP_CONTACTS Used with ACTION_MAIN to launch the contacts application. 5 CATEGORY_APP_EMAIL Used with ACTION_MAIN to launch the email application. 6 CATEGORY_APP_GALLERY Used with ACTION_MAIN to launch the gallery application. 7 CATEGORY_APP_MAPS Used with ACTION_MAIN to launch the maps application. 8 CATEGORY_APP_MARKET This activity allows user to browse and download new applications. 9 CATEGORY_APP_MESSAGING Used with ACTION_MAIN to launch the messaging application. 10 CATEGORY_APP_MUSIC Used with ACTION_MAIN to launch the music application. by Tanzila Kehkashan

Intent – Intent Fields image/*, image/png, image/jpeg Type Specifies the MIME type of the Intent Data Examples image/*, image/png, image/jpeg text/html, text/plain If unspecified, Android will infer the type Setting the Type Intent.setType(String type); Or Intent.setDataAndType(Uri data, String type); Component The component that should receive this intent Use this when there’s exactly one component that should receive the Intent Setting the Component Intent newInt = new Intent (); and one of following: setComponent(), setClass(), or setClassName() by Tanzila Kehkashan

Intent – Intent Fields Extra Extra is additional information associated with Intent Setting the Extra Several forms depending on data type putExtra(String name, String value); putExtra(String name, float[] value); Flag Specify how Intent should be handled Examples FLAG_ACTIVITY_NO_HISTORY Don’t put this Activity in the History stack FLAG_DEBUG_LOG_RESOLUTION Print extra logging information when this Intent is processed Setting Intent Flag Intent newInt = new Intent(Intent.ACTION_SEND); newInt.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {“uolidol@uol.cs.edu.pk”, “ceo@uol.edu.pk”, “ceo@pmhouse.gov”, “ceo@musician.org”}); Intent newInt = new Intent(Intent.ACTION_SEND); newInt.setFlags( Intent.FLAG_ACTIVITY_NO_HISTORY); by Tanzila Kehkashan

Intent – Starting Activity with Intent startActivity(Intent intent); startActivityForResult(Intent intent, …); Target Activity Above are methods to start activity. But Android has to figure out which activity has to start. There are two ways android does it. Explicit Activation Explicitly name the target activity when you created the intent, android will just start it up by setting intents component. Implicit Activation You didn’t provide target activity and android implicitly determine it based on intent used and based on properties of activities that you have installed on your device. by Tanzila Kehkashan

Application Components – Intent Explicit Activation by Tanzila Kehkashan

by Tanzila Kehkashan