Android Embedded Resources Lesson16 Victor Matos Cleveland State University Notes are based on: Android Developers

Slides:



Advertisements
Similar presentations
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Advertisements

User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
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.
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.
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
Animation.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Resources. Application Resources Resources are strings, images, and other pieces of application information that are stored and maintained (externalized)
User Interfaces: Part 1 (View Groups and Layouts).
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.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
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 App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
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.
Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Http :// developer. android. com / guide / topics / fundamentals. html.
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
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
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
Mobile Applications (Android Programming)
Lab7 – Appendix.
Introduction to android
Android Mobile Application Development
Android Introduction Hello World
several communicating screens
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Further android gui programming
Android Improving Layouts HierarchyViewer & lint
CS499 – Mobile Application Development
Instructor: Mazhar Hussain
Android Introduction Hello World.
Android External Resources
MAD.
Android Widgets 1 7 August 2018
Creation of an Android App By Keith Lynn
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
ITEC535 – Mobile Programming
Politeknik Elektronika Negeri Surabaya
Mobile Application Development BSCS-7 Lecture # 3
תכנות ב android אליהו חלסצ'י.
ANDROID UI – FRAGMENTS UNIT II.
Anatomy of an Android Application
Mobile Computing With Android ACST 4550 Android Resources
Android Programming Lecture 6
CIS 470 Mobile App Development
CA16R405 - Mobile Application Development (Theory)
Introduction to Cascading Style Sheets (CSS)
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
Android SDK & App Development
Android Project Structure, App Resources and Event Handling
User Interface Screen Elements
User Interface Screen Elements
Android Sensor Programming
Presentation transcript:

Android Embedded Resources Lesson16 Victor Matos Cleveland State University Notes are based on: Android Developers Portions of this page are reproduced from work created and shared by Google and used according to termsshared by Google described in the Creative Commons 3.0 Attribution License.Creative Commons 3.0 Attribution License

2 Android Resources 2 Resources Resources are external files (images, strings, files, audio, animations, layouts, styles, xml …) which are integrated into the application at compile time for their later use at execution time. Raw resources are placed here

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

4 Android Resources 4 Copy/Paste Resources You place your resources under the appropriate /res or /assets subdirectory in your project’s workspace. 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.

5 Android Resources 5 DirectoryResource Type animator/ XML files that define property animations. anim/ XML files that define tween animations. (Property animations can also be saved in this directory, but the animator/ directory is preferred for property animations to distinguish between the two types.) color/ XML files that define a state list of colors. drawable/ Bitmap files (.png,.9.png,.jpg,.gif) or XML (shapes, animations) files that are compiled into drawable resources. 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. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename. However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager. Values/ XML files that contain simple values, such as strings, integers, and colors. For example, a element creates an R.string resource and a element creates an R.color resource. You can name the file whatever you want and place different resource types in one file. For clarity use: arrays.xml, colors.xml, dimens.xml, strings.xml, styles.xml. xml/Arbitrary XML files that can be read at runtime by calling Resources.getXML().

66 Difference between folders: /res/raw and /assets Both folders are very similar (they can store arbitrary data items). All items saved in the /res/ folder are indexed by ID. Those entries are stored in the R.java file. Indexed items can be easily retrieve using notation: R.array. [resource_name] R.attr. [resource_name] … R.id. [resource_name] … R.xml. [resource_name] public static final class raw { public static final int file2=0x7f050000; public static final int lulu_log_in=0x7f050001; } Fragment taken from R.java Note: /res/raw/file2 and /res/xml/file3 appear in R.java however file1 does not.

7 Android Resources 7 getResources().getAnimation(id); getResources().getAssets().open(fileName) getResources().getAssets().openXmlResourceParser(fileName) getResources().getColor(id) getResources().getDrawable(id) getResources().getIntArray(id) getResources().getStringArray(id) getResources().getTextArray(id) getResources().getLayout(id) getResources().getMovie(id) getResources().getString(id) getResources().getXml(id) Retrieving Resources witch code

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

9 Android Resources 9 Java Statements for Using Resources Retrieving String Resources from: res/values/strings.xml Convenient strategy for internalization/redeployment. String msg = this.getString(R.string.color_prompt); Hola Mundo!, ResourceDemo1! ResourceDemo1 Hasta luego Color: Seleccione un Color Planeta Planeta Planeta Planeta Seleccione un Planeta

10 Android Resources 10 Java Statements for Using Resources Enhancing externalized String resources from: res/values/strings.xml As in HTML a string using,, modifiers will be rendered in: bold, italics, and, underlined modes. In our example: String myColors[] = this.getResources().getStringArray(R.array.colors); Planeta Planeta Hola Mundo!, ResourceDemo1! ResourceDemo1 Hasta luego Color: Seleccione un Color Planeta Planeta Planeta Planeta Seleccione un Planeta

11 Android Resources 11 Java Statements for Using Resources Retrieving Array Resources from: res/values/arrays.xml red orange yellow green blue violet Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto String myColors[] = this.getResources().getStringArray(R.array.colors);

12 Android Resources 12 Java Statements for Using Resources Retrieving a drawable image from: res/drawable/ // same as xml layout attribute // imageView1.setImageResource( R.drawable.flowers);

13 Android Resources 13 Example1. Using Embedded Resources (drawable, string, array). <LinearLayout xmlns:android= " android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dip" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:textSize="22dp" /> <Spinner android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" /> #7f00 #770000ff #7700ff00 #f00 #0000ff #f0f0 #ffffff00 /res/values/colors.xml

14 Android Resources 14 Example1. Using Embedded Resources (drawable, string, array).

15 Android Resources 15 Example1. Using Embedded Resources (drawable, string, array). // using Resources (adapted from Android - ApiDemos) public class ResourceApp1 extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); EditText txtColorBox = (EditText) findViewById(R.id.txtColorBox); ImageView imageView1 = (ImageView) findViewById(R.id.ImageView01); // similar to xml layout imageView1.setImageResource(R.drawable.csuseal); String myColors[] = this.getResources().getStringArray(R.array.colors); String msg = this.getString(R.string.spinner_1_color); for (int i = 0; i < myColors.length; i++) { msg += "\n\t" + myColors[i]; } txtColorBox.setText(msg);

16 Android Resources 16 Example1. Using Embedded Resources (drawable, string, array). Spinner s2 = (Spinner) findViewById(R.id.spinner2); ArrayAdapter 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); }//onCreate }//class

17 Resources 17 Questions ?