Androidseminar/android19_sunx

Download Report

Transcript Androidseminar/android19_sunx

Android Chapter 19
Resource
발표자 : 김 선필
Resource?
Resource
Resource?
External files (non-code files)
But,
Used by our code
XML files
- everything but bitmap and raw
Bitmap files
res/
- for images
RAW byte
- anything else, sound files
Resource
asset/
RAW byte
- Use the AssetManager to read the files
Resource and Asset
/res
컴파일된 자바 코드와 함께 패키징 되는 리소스를 저장
AAPT(Android Asset Packaging Tool)의해 컴파일
리소스 명세가 /gen/R.java에 자동 생성 파일에 정리
소스코드에서 R 클래스를 통해 쉽게 컴파일된 리소스에 접근
Android Asset Packaging Tool (aapt)
The aapt tool lets you create .apk files containing
the binaries and resources of Android applications.
Resource and Asset
/res
컴파일된 자바 코드와 함께 패키징 되는 리소스를 저장
AAPT(Android Asset Packaging Tool)의해 컴파일
리소스 명세가 /gen/R.java에 자동 생성 파일에 정리
소스코드에서 R 클래스를 통해 쉽게 컴파일된 리소스에 접근
/asset
static하게 패키지에 포함시킬 리소스 저장
컴파일 되지 않음
raw byte 형태로 packaging
AssertManager클래스를 이용해 바이트 스트림 형식으로 읽음
/res, /res/raw, /asset?
Where is Resource?
http://developer.android.com/guide/topics/resources/resources-i18n.html
References to Resources
How to use the resource
• Using resources in code
• Referring to resources from other resources
• Supporting Alternate Resources
for Alternate Configurations
Using resources in code
Knowing the full resource ID
R.resource_type.resource_name
or
Own app
android.R.resource_type.resource_name
Using Resource in Code
- For example
References to Resources
Use of the '@' prefix to introduce a
resource reference
@resource_type/resource_name
or
@[package:]resource_type/resource_name
References to Resources
- For example
References to Theme Attributes
Using an '?' prefix instead of '@’
the name syntax is identical to the '@’ format
?resource_type/resource_name
or
?[namespace:]resource_type/resource_name
References to Theme Attributes
- For example
Using System Resources
Many resources included with the system
are available to applications
All such resources are defined under
the class "android.R"
Using System Resources
- For example
Using System Resources
- For example
I18N and L10N
Internationalization (I18N)
- 하나의 프로그램을 처음 설계 할 때부터 여러 나라에 맞게 사용할 수
있도록 설계하고 작성하는 것
Localization(L10N)
- 한 나라에만 귀속되도록 설계되고 작성된 프로그램
Locale
- 특정 지역에서 언어와 관습에 따라 결정되는 요소
- 언어, 글자, 날짜나 시간의 양식, 통화 기호, 문자열 정렬 순서 등의 요
소가 포함
※국제화가 잘된 소프트웨어는 별도의 소
스코드 변경 없이 로케일 지정을 통해 어느
나라에서도 적절하게 사용될 수 있음
Alternate Resources
장치의 UI 언어와 하드웨어 설정에 의존해서
App이 사용할 서로 다른 리소스를 제공
Alternate Resources
Android는 각각에 대해 다양한 값을 가지는 여러
타입의 수식어를 지원
“-”(dash)로 구분
Alternate Resources
전체 리스트에서 특정 설정만 사용 가능
Alternate Resources
Qualifiers that are listed higher in the table take
precedence over those listed lower
http://developer.android.com/guide/topics
/resources/resources-i18n.html
Alternate Resources
live under the res/ folder
some guidelines on qualified resource directory names
You can specify multiple qualifiers, separated by dashes
The qualifiers must be in the order listed. For example:
• Correct : values-mcc460-nokeys/
• Incorrect : values-nokeys-mcc460/
Values are case-insensitive
• to lower case before processing
Only one value for each qualifier type is supported
Qualified directories cannot be nested
How resources are referenced in code
All resources will be referenced in code or
resource reference syntax by their simple,
undecorated names
So if a resource were :
• Chapter19/res/drawable-hdpi/icon.png
• Chapter19/res/drawable-ldpi/icon.png
• Chapter19/res/drawable-mdpi/icon.png
It would be referenced as this:
• R.drawable.icon(code)
• @drawalbe/icon(XML)
How Android finds the best matching directory
This flowchart summarizes
how Android selects
resource directories to load
How Android finds the best matching directory
The example used here assumes the following
device configuration
How Android finds the best matching directory
Step1. Eliminate resource files that contradict the
device configuration
How Android finds the best matching directory
Step2. Eliminate all the directories that do not
include a language qualifier
How Android finds the best matching directory
Step3. Eliminate resources that do not specify a
screen orientation
Tall(port), wide(land), square
PART 2
Android Supported Media Formats
http://developer.android.com/guide/appe
ndix/media-formats.html
문자열 – For example
Android에서 소스코드와 문자열을 간단한 방법으
로 분리 가능
- I18N and L10N
데이터를 지정된 형식에 맞게 넣어주는 formatting
기능
일반 문자열 – For example
문자열 포매팅 – For example
화면 표시 스타일 – For example(2)
화면 표시 스타일 – For example
스타일이 적용된 포매팅 – For example
스타일 적용 + 포매팅
1.
문자열 리소스에 들어가는 스타일 태그를 HTML 엔티티로 변환
This is <b>%1$s</b&gt
// This is <b>%1$s</b>
2.
해당 문자열 리소스를 일반적인 방법으로 참조해 읽어온다
(getString(R.string.funky_format));
3.
포매팅이 적용된 결과를 생성
String.format(getString(R.string.funky_format),
TextUtils.htmlEncode(strName));
4.
문자열에 들어 있는 스타일 태그를 되살린다
someTextView.setText(Html.fromHtml(resultFormStringFormat));
스타일이 적용된 포매팅
- For example
스타일이 적용된 포매팅
- For example
내 이름은
&lt;b&gt;%1$s&lt;/b&gt
스타일이 적용된 포매팅
- For example
References to
Resources
Image
- res/layout/main.xml
Image
- src/ResourceImg.java
Image
- For example
XML
- res/xml/words.xml
xml
- res/layout/main.xml
xml
- src/ResourceXml.java
XML
- For example
크기
You can create common dimensions to use for various
screen elements by defining dimension values in XML
1.
px :: Pixels - corresponds to actual pixels on the screen
2.
in, mm :: Inches, Millimeters - based on the physical size of the
screen
3.
pt :: Points - 1/72 of an inch based on the physical size of the
screen
4.
dp :: Device-dependent pixel – an abstract unit that is based on
the physical density of the screen, so one dp is one pixel on a
160 dpi screen
5.
sp :: Scale-independent Pixels - this is like the dp unit, but it is
also scaled by the user's font size preference
QnA
Thank You!!