Resources. Application Resources Resources are strings, images, and other pieces of application information that are stored and maintained (externalized)

Slides:



Advertisements
Similar presentations
Programming with Android: Application Resources Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Advertisements

CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
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: Application Resources Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
More Java: Encapsulation, Getters, Setters, Anonymous Class 1 CS300.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Programming with Android: Application Resources Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
Android Development for Different Screens and Devices Rohit Ghatol.
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
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.
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.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Chapter 2: Simplify! The Android User Interface
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.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
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
User Interfaces: Part 1 (View Groups and Layouts).
Configuring Android Development Environment Nilesh Singh.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Creating an Example Android App in Android Studio Activity lifecycle & UI Resources.
UI Design and Development +Roman Nurik +Nick Butcher.
UI Design and Development +Roman Nurik +Nick Butcher.
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
MOBILE COMPUTING D10K-7D02 MC03: Introduction to Android Programming Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
1 Mobile Computing Handling Different Display Sizes Copyright 2015 by Janson Industries.
© 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.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
Resources & Android Manifest Калин Кадиев Astea Solutions AD.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
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.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
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
Introduction to Android Chapter 1 1. Objectives Understand what Android is Learn the differences between Java and Android Java Examine the Android project.
Presenter Sudhanshu Gupta
Chapter 2: Simplify! The Android User Interface
Mobile Applications (Android Programming)
Android Mobile Application Development
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
Instructor: Mazhar Hussain
2D Graphics: Part 2.
MAD.
Mobile Application Development BSCS-7 Lecture # 3
Anatomy of an Android Application
Mobile Computing With Android ACST 4550 Android Resources
Android Programming Lecture 3
Android Layout Basics Topics
CMPE419 Mobile Application Development
Emerging Platform#3 Android & Programming an App
Android Project Structure, App Resources and Event Handling
Introduction to Android
Korea Software HRD Center
Presentation transcript:

Resources

Application Resources Resources are strings, images, and other pieces of application information that are stored and maintained (externalized) independently from the code. Externalizing resources also allows you to provide alternative resources that support different locales (languages/countries) and different device configurations (e.g., screen sizes/orientation). Resources are organized in a project’s res/ directory, using various sub-directories that group resources by type and configuration. Slide 2©SoftMoore Consulting

File Hierarchy for a Simple Project app/src/main java/ edu/citadel/android/hello/MainActivity.java res/ drawable/ drawable-hdpi drawable-mdpi drawable-xhdpi drawable-xxhdpi layout/ activity_main.xml values/ colors.xml dimens.xml strings.xml styles.xml values-w820dp/ AndroidManifest.xml Slide 3©SoftMoore Consulting

Alternative Resources For any type of resource, you can specify default and multiple alternative resources for your application: –default resources: used regardless of the device configuration or when there are no alternative resources that match the current configuration. –alternative resources: for use with a specific configuration. To specify that a group of resources are for a specific configuration, append an appropriate configuration qualifier to the directory name. Example/ –default UI layout is saved in the res/layout/ directory –alternate UI layout for landscape orientation is saved in the res/layout-land/ directory Slide 4©SoftMoore Consulting

Example: Alternative Resources Slide 5©SoftMoore Consulting Figure 1. Two different devices, both using default resources. Figure 2. Two different devices, one using alternative resources.

Resource Directories (subdirectories of res/ ) anim/ – XML files that define tween animations color/ – XML files that define a state list of colors (e.g., button state can be pressed, focused, or neither) drawable/ – Bitmap files (.png,.9.png,.jpg,.gif ) or XML files that are compiled into drawable resource subtypes layout/ – XML files that define a user interface layout menu/ – XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu raw/ – Arbitrary files to save in their raw form Slide 6©SoftMoore Consulting

Resource Directories (subdirectories of res/ – continued) values/ – XML files that contain simple values, such as strings, integers, and colors. Examples include –arrays.xml for resource arrays –colors.xml for color values –dimens.xml for dimension values –strings.xml for string values –styles.xml for styles xml/ – Arbitrary XML files that can be read at runtime Slide 7©SoftMoore Consulting

Specifying Configuration-Specific Alternatives Create a new directory in res/ named in the form -. – is the directory name of the corresponding default resources. – is a name that specifies an individual configuration for which these resources are to be used. You can append more than one. Separate each one with a dash. Save the respective alternative resources in this new directory. The resource files must be named exactly the same as the default resource files. Slide 8©SoftMoore Consulting

Example: Specifying Configuration-Specific Alternatives res/ drawable/ icon.png background.png drawable-hdpi/ icon.png background.png Slide 9©SoftMoore Consulting

Configuration Qualifier Names for Alternative Resource Directories MCC and MNC – mobile country code/mobile network code (e.g., to include country-specific legal resources) Language or both language and region – e.g., en, fr, en-rUS, fr-rFR, fr-rCA, etc. Screen size – small, normal, large, xlarge (e.g., tablets) Screen orientation – port, land Screen pixel density (dpi) – ldpi, mdpi, hdpi, xhdpi, nodpi Keyboard availability – keysexposed, keyshidden, keyssoft Platform version (API Level) – e.g., v3, v4, v7, etc. Slide 10©SoftMoore Consulting

String Resources A string is a simple resource that is referenced using the value provided in the name attribute. Example (file strings.xml in directory res/values ) Hello Android Hello, Android! Settings Slide 11©SoftMoore Consulting

Escaping Apostrophes and Quotes An apostrophes or a quote in a string resource must either be escaped (e.g., using “ \ ”) or else the whole string must be enclosed in the other type of quote. Examples "This'll work" This\'ll also work This doesn't work Slide 12©SoftMoore Consulting

Accessing Resources When your application is compiled, the Android Asset Packaging Tool ( aapt ) generates class R, which contains resource IDs for all the resources in your res/ directory. For each type of resource, there is an R subclass (for example, R.drawable for all drawable resources) and for each resource of that type, there is a static integer (for example, R.drawable.icon ). This integer is the resource ID that you can use to retrieve your resource. There are two ways you can access a resource: –In code: Use a static integer from a sub-class of your R class (e.g., R.string.hello ) –In XML: Use a special XML syntax that also corresponds to the resource ID defined in your R class ) Slide 13©SoftMoore Consulting

Example: Accessing Resources Accessing resources within code ImageView imageView = (ImageView) findViewById(R.id.myimageview); imageView.setImageResource(R.drawable.myimage); String submit = getString(R.string.submit); Accessing Resources from XML <Button android:layout_width="match_parent" android:layout_height="wrap_content" /> Slide 14©SoftMoore Consulting

String Array Resources In addition to simple strings, it is possible to declare an array of strings as a resource. Example (in res/strings.xml ) Mercury Venus Earth Mars Accessing the string array within the Java code Resources res = getResources();getResources() String[] planets = res.getStringArray(R.array.planets_array);getStringArray Slide 15©SoftMoore Consulting

Relevant Links Application Resources Providing Resources Localizing with Resources String Resources How to Localize an Android Application Slide 16©SoftMoore Consulting