Android External Resources

Slides:



Advertisements
Similar presentations
Android Fonts Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Advertisements

Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
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
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,
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
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.
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Android Dialog Boxes AlertDialog - Toast
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Mobile Computing Lecture#12 Graphics & Animation.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
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
Android Embedded Resources Lesson16 Victor Matos Cleveland State University Notes are based on: Android Developers
Android Programming.
Android Programming - Features
Cleveland State University
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Android N Amanquah.
Adapting to Display Orientation
GUI Programming Fundamentals
Android Introduction Hello World.
2D Graphics: Part 2.
Designing Apps Using The WebView Control
Android Widgets 1 7 August 2018
Creation of an Android App By Keith Lynn
ITEC535 – Mobile Programming
HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung
Android Dialog Boxes AlertDialog - Toast
תכנות ב android אליהו חלסצ'י.
Anatomy of an Android Application
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Mobile Computing With Android ACST 4550 Android Resources
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Building User Interfaces Basic Applications
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Android Developer Fundamentals V2
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Notifications
Android Project Structure, App Resources and Event Handling
CMPE419 Mobile Application Development
User Interface Screen Elements
CMPE419 Mobile Application Development
User Interface Screen Elements
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Android External Resources 16 Android External Resources Victor Matos Cleveland State University Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © 2008-2009 CommonsWare, LLC. ISBN: 978-0-9816780-0-9 & Android Developers http://developer.android.com/index.html

Android Resources Resources and Internationalization Resources are external files (that is, non-code files) that are used by your code and compiled into your application at build time. Android supports a number of different kinds of resource files, including XML, PNG, and JPEG files. Resources are externalized from source code, and XML files are compiled into a binary, fast loading format for efficiency reasons. Strings, likewise, are compressed into a more efficient storage form. http://developer.android.com/guide/topics/resources/resources-i18n.html 2

Android Resources Using Resources The Android resource system keeps track of all non-code assets associated with an application. You use the Resources class to access your application's resources; the Resources instance associated with your application can generally be found through Context.getResources(). To use a resource, you must install it correctly in the source tree and build your application. 3

Android Resources Copy/Paste Resources You will create and store your resource files under the appropriate subdirectory under the res/ directory in your project. Resources are compiled into the final APK file. Android creates a wrapper class, called R, that you can use to refer to these resources in your code. R contains subclasses named according to the path and file name of the source file 4

16. Android – Resources Android Resources 5

16. Android – Resources Android Resources A Typical Android Application consists of Java code and additional resources merged together into a deployable .apk file 6

16. Android – Resources Resources Examples. To see a number of samples you should explore the folder: c:\Android\platforms\android-1.5\data\res\ 7

Resources More Examples. 16. Android – Resources Resources More Examples. Try to install the ApiDemos application. Explore its resource folder. Find the source code in the folder: c:\Android\platforms\android-1.6\samples\ How to install the App: File -> New -> Project -> Android Project -> Next Select "Create project form existing source" Select the ApiDemos folder (all remaining fields will be self adjusted) 8

Android Resources Java Statements for Using Resources Displaying a screen layout: setContentView(R.layout.main); setContentView(R.layout.screen2); 9

Android Resources Java Statements for Using Resources Retrieving String Resources from: res/values/… /res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hola Mundo!, ResourceDemo1!</string> <string name="app_name">ResourceDemo1</string> <string name="good_bye">Hasta luego</string> <string name="color_caption">Color:</string> <string name="color_prompt">Seleccione un Color</string> <string name="planet_caption"> <b>Planeta </b>Planeta <i>Planeta </i><u>Planeta: </u></string> <string name="planet_prompt">Seleccione un Planeta</string> </resources> String msg = this.getString(R.string.color_prompt); 10

Android Resources Java Statements for Using Resources Enhancing externalized String resources from: res/values/… /res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hola Mundo!, ResourceDemo1!</string> <string name="app_name">ResourceDemo1</string> <string name="good_bye">Hasta luego</string> <string name="color_caption">Color:</string> <string name="color_prompt">Seleccione un Color</string> <string name="planet_caption"> <b>Planeta </b>Planeta <i>Planeta </i><u>Planeta: </u></string> <string name="planet_prompt">Seleccione un Planeta</string> </resources> As in HTML a string using <b>, <i>, <u> modifiers will be rendered in: bold, italics, and, underlined modes. In our example: Planeta Planeta Planeta Planeta 11

Android Resources Java Statements for Using Resources Retrieving Array Resources from: res/values/… /res/values/arrays.xml <?xml version="1.0" encoding="utf-8"?> <string-array name="planets"> <resources> <item>Mercury</item> <item>Venus</item> <string-array name="colors"> <item>Earth</item> <item>red</item> <item>Mars</item> <item>orange</item> <item>Jupiter</item> <item>yellow</item> <item>Saturn</item> <item>green</item> <item>Uranus</item> <item>blue</item> <item>Neptune</item> <item>violet</item> <item>Pluto</item> </string-array> </resources> String myColors[] = this.getResources().getStringArray(R.array.colors); 12

Android Resources Java Statements for Using Resources Retrieving a drawable image from: res/drawable/… /res/drawable/ //same as xml layout attribute //android:src="@drawable/android_green_3d“ imageView1.setImageResource( R.drawable.android_green_3d); 13

16. Android – Resources Android Resources Example1. Using Embedded Resources (drawable, string, array). <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <TextView android:orientation="vertical" android:layout_marginTop="10dip" android:padding="10dip" android:textSize="18px" android:layout_width="fill_parent" android:text="@string/planet_caption" android:layout_height="fill_parent" android:background="@color/solid_blue" > <Spinner android:id="@+id/spinner2" <ImageView android:id="@+id/ImageView01" android:drawSelectorOnTop="true" android:layout_width="wrap_content" android:prompt="@string/planet_prompt" android:layout_height="wrap_content" </ImageView> </LinearLayout> <EditText android:id="@+id/txtColorBox" /> <?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="red">#7f00</drawable> <drawable name="blue">#770000ff</drawable> <drawable name="green">#7700ff00</drawable> <color name="solid_red">#f00</color> <color name="solid_blue">#0000ff</color> <color name="solid_green">#f0f0</color> <color name="solid_yellow">#ffffff00</color> </resources> /res/values/color.xml 14

16. Android – Resources Android Resources Example1. Using Embedded Resources (drawable, string, array). 15

16. Android – Resources Android Resources Example1. Using Embedded Resources (drawable, string, array). // using Resources (adapted from Android - ApiDemos) package cis493.resources; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageView; import android.widget.Spinner; public class ResourceDemo1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //TRY: setContentView(R.layout.screen2); ImageView imageView1 = (ImageView)findViewById(R.id.ImageView01); //similar to xml layout android:src="@drawable/android_green_3d" imageView1.setImageResource(R.drawable.android_green_3d); 16

16. Android – Resources Android Resources Example1. Using Embedded Resources (drawable, string, array). EditText txtColorBox = (EditText)findViewById(R.id.txtColorBox); String msg = this.getString(R.string.color_caption); String myColors[] = this.getResources().getStringArray(R.array.colors); for ( int i=0; i<myColors.length; i++){ msg += "\n\t" + myColors[i]; } txtColorBox.setText(msg); Spinner s2 = (Spinner) findViewById(R.id.spinner2); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.planets, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); s2.setAdapter(adapter); 17

16. Android – Resources Android Resources mmmm 18

16. Android – Resources Android Resources mmmm 19

16. Android – Resources Android Resources mmmm 20

16. Android – Resources Resources Questions ? 22 22