SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
8
 Support
 Different Devices
 Anuchit Chalothorn
 anoochit@gmail.com

Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Supporting Different Languages
Android will run on many devices in many
regions. To reach the most users, your
application should handle text, audio files,
numbers, currency, and graphics in ways
appropriate to the locales where your
application will be used.
Using Resources for Localization
The default resource set must also include any
default drawables and layouts, and can include
other types of resources such as animations.
● res/drawable/
● res/layout/
● res/anim/
● res/xml/
● res/raw/
Language String
Android makes this easy with a resources
directory in each Android project. Within the
res/ directory are subdirectories for various
resource types. There are also a few default
files such as res/values/strings.xml, which
holds your string values.
Locale Directories and String Files
To add support for more languages, create
additional values directories inside res/ that
include a hyphen and the ISO country code at
the end of the directory name. eg: values-es
for Spanish, values-th for Thai, values for
English etc.
Locale : English
English (default locale), /values/strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">My Application</string>
    <string name="hello_world">Hello World!</string>
</resources>
Locale : Spanish
Spanish, /values-es/strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">Mi Aplicación</string>
    <string name="hello_world">Hola Mundo!</string>
</resources>
Locale : French
French, /values-fr/strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">Mon Application</string>
    <string name="hello_world">Bonjour le monde !</string>
</resources>
Use the String Resources
You can refer to a string resource with the
syntax R.string.<string_name>. There are a
variety of methods that accept a string resource
this way.
Use the String Resources

// Get a string resource from your app's Resources
String hello = getResources().getString(R.string.
hello_world);

// Or supply a string resource to a method that requires a
string
TextView textView = new TextView(this);
textView.setText(R.string.hello_world);
Use the String in XML
In other XML files, you can refer to a string
resource with the syntax
@string/<string_name> whenever the XML
attribute accepts a string value.
Use the String in XML

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
Workshop: Locale
Create form UI like following and make locale
string for English, Vietnamese, Japanese and
Thai.
Locale your graphic
You can use qualifiers with any resources
include graphic in drawable directory, eg :
● /drawable for English (default locale)
● /drawable-th for Thai
● /drawable-vn for Vietnamese
● /drawable-ja for Japanese
Workshop: Locale your graphic
Create a UI like following and make locale
graphic for English, Vietnamese, Japanese and
Thai.
Supporting Different Screens
Android categorizes device screens using two
general properties: size and density. You
should expect that your app will be installed on
devices with screens that range in both size
and density.
Sizes and Densities
To declare different layouts and bitmaps you'd
like to use for different screens, you must place
these alternative resources in separate
directories, similar to how you do for different
language strings.
Create Different Layouts
To optimize your user experience on different
screen sizes, you should create a unique layout
XML file for each screen size you want to
support.
Create Different Layouts
The directory named with a -<screen_size>
suffix.
● /res/layout/main.xml <-- normal
● /res/layout-land/main.xml <-- landscape
● /res/layout-large/main.xml <-- for large
● /res/layout-large-land/main.xml <-- large landscape
Create Different Bitmaps
You should always provide bitmap resources
that are properly scaled to each of the
generalized density buckets: low, medium, high
and extra-high density. This helps you achieve
good graphical quality and performance on all
screen densities.
Create Different Bitmaps
To generate these images, you should start
with your raw resource in vector format and
generate the images for each density using the
following size scale:
● xhdpi: 2.0
● hdpi: 1.5
● mdpi: 1.0 (baseline)
● ldpi: 0.75


Ref: http://developer.android.com/design/style/iconography.html
Workshop: Drawable
Make graphic resources match each screen
size.
Supporting Different Platform Versions

While the latest versions of Android often
provide great APIs for your app, you should
continue to support older versions of Android
until more devices get updated.
Specify Minimum and Target API
The AndroidManifest.xml file describes details
about your app and identifies which versions of
Android it supports. Specifically, the
minSdkVersion and targetSdkVersion with
<use-sdk element.
Specify Minimum and Target API


<manifest xmlns:android="http://schemas.android.
com/apk/res/android" ... >
    <uses-sdk android:minSdkVersion="4"
              android:targetSdkVersion="15" />
    ...
</manifest>
Check System Version at Runtime
Android provides a unique code for each
platform version in the Build constants class.
Use these codes within your app to build
conditions that ensure the code that depends
on higher API levels is executed only when
those APIs are available on the system.
Check System Version at Runtime

private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use
ActionBar APIs
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.
HONEYCOMB)
   {
         ActionBar actionBar = getActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
   }
}
Use Platform Styles and Themes
Android provides user experience themes that
give apps the look and feel of the underlying
operating system. These themes can be
applied to your app within the manifest file.
Platform Styles and Themes
To make your activity look like a dialog box:


<activity android:theme="@android:style/Theme.Dialog">
Platform Styles and Themes
To make your activity have a transparent
background:To make your activity have a
transparent background:

<activity
      android:theme="@android:style/Theme.Translucent">
Platform Styles and Themes
To apply your own custom theme defined in
/res/values/styles.xml:


<activity android:theme="@style/CustomTheme">
Platform Styles and Themes
To apply a theme to your entire app (all
activities), add the android:theme attribute to
the <application> element:

<application android:theme="@style/CustomTheme">
End

Contenu connexe

Tendances

Screen orientations in android
Screen orientations in androidScreen orientations in android
Screen orientations in androidmanjakannar
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screensAbhijeet Dutta
 
Designing for Android - Anjan Shrestha
Designing for Android - Anjan ShresthaDesigning for Android - Anjan Shrestha
Designing for Android - Anjan ShresthaMobileNepal
 
UX and UI Designing for all android screen
UX and UI Designing for all android screenUX and UI Designing for all android screen
UX and UI Designing for all android screenArnold Saputra
 
Lec5 interactive multimedia tools
Lec5 interactive multimedia toolsLec5 interactive multimedia tools
Lec5 interactive multimedia toolsShona Hira
 
Lec5 interactive multimedia tools
Lec5 interactive multimedia toolsLec5 interactive multimedia tools
Lec5 interactive multimedia toolsDom Mike
 
High DPI for desktop applications
High DPI for desktop applicationsHigh DPI for desktop applications
High DPI for desktop applicationsKirill Grouchnikov
 
Cloud-based Render With Auteurist
Cloud-based Render With AuteuristCloud-based Render With Auteurist
Cloud-based Render With Auteuristgareth-axum
 
Graphics!!!!!!!
Graphics!!!!!!!Graphics!!!!!!!
Graphics!!!!!!!chibbii
 
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能Unity Technologies Japan K.K.
 

Tendances (11)

Screen orientations in android
Screen orientations in androidScreen orientations in android
Screen orientations in android
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screens
 
Open graphics
Open graphicsOpen graphics
Open graphics
 
Designing for Android - Anjan Shrestha
Designing for Android - Anjan ShresthaDesigning for Android - Anjan Shrestha
Designing for Android - Anjan Shrestha
 
UX and UI Designing for all android screen
UX and UI Designing for all android screenUX and UI Designing for all android screen
UX and UI Designing for all android screen
 
Lec5 interactive multimedia tools
Lec5 interactive multimedia toolsLec5 interactive multimedia tools
Lec5 interactive multimedia tools
 
Lec5 interactive multimedia tools
Lec5 interactive multimedia toolsLec5 interactive multimedia tools
Lec5 interactive multimedia tools
 
High DPI for desktop applications
High DPI for desktop applicationsHigh DPI for desktop applications
High DPI for desktop applications
 
Cloud-based Render With Auteurist
Cloud-based Render With AuteuristCloud-based Render With Auteurist
Cloud-based Render With Auteurist
 
Graphics!!!!!!!
Graphics!!!!!!!Graphics!!!!!!!
Graphics!!!!!!!
 
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能
【Unite 2017 Tokyo】Unity UI最適化ガイド 〜ベストプラクティスと新機能
 

Similaire à Android App Development 08 : Support Multiple Devices

Android App Development - 03 Resources
Android App Development - 03 ResourcesAndroid App Development - 03 Resources
Android App Development - 03 ResourcesDiego Grancini
 
03 android application structure
03 android application structure03 android application structure
03 android application structureSokngim Sa
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Android Resources.docx
Android Resources.docxAndroid Resources.docx
Android Resources.docxKNANTHINIMCA
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibilityaspnet123
 
Localization and Shared Preferences in android
Localization and Shared Preferences in androidLocalization and Shared Preferences in android
Localization and Shared Preferences in androidAly Arman
 
Windows phone 8 session 6
Windows phone 8 session 6Windows phone 8 session 6
Windows phone 8 session 6hitesh chothani
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldTarunsingh198
 
Android style resource and other resources types-chapter12
Android style resource and other resources types-chapter12Android style resource and other resources types-chapter12
Android style resource and other resources types-chapter12Dr. Ramkumar Lakshminarayanan
 
Consistent UI Across Android Devices
Consistent UI Across Android DevicesConsistent UI Across Android Devices
Consistent UI Across Android DevicesIrene Duke
 
Application fundamentals
Application fundamentalsApplication fundamentals
Application fundamentalsmaamir farooq
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...Christopher Miller
 

Similaire à Android App Development 08 : Support Multiple Devices (20)

Android App Development - 03 Resources
Android App Development - 03 ResourcesAndroid App Development - 03 Resources
Android App Development - 03 Resources
 
03 android application structure
03 android application structure03 android application structure
03 android application structure
 
Android resource
Android resourceAndroid resource
Android resource
 
Android Resources.docx
Android Resources.docxAndroid Resources.docx
Android Resources.docx
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibility
 
Localization and Shared Preferences in android
Localization and Shared Preferences in androidLocalization and Shared Preferences in android
Localization and Shared Preferences in android
 
Windows phone 8 session 6
Windows phone 8 session 6Windows phone 8 session 6
Windows phone 8 session 6
 
Android resources in android-chapter9
Android resources in android-chapter9Android resources in android-chapter9
Android resources in android-chapter9
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello world
 
Android dev tips
Android dev tipsAndroid dev tips
Android dev tips
 
Android style resource and other resources types-chapter12
Android style resource and other resources types-chapter12Android style resource and other resources types-chapter12
Android style resource and other resources types-chapter12
 
Android momobxl
Android momobxlAndroid momobxl
Android momobxl
 
Consistent UI Across Android Devices
Consistent UI Across Android DevicesConsistent UI Across Android Devices
Consistent UI Across Android Devices
 
Visual studio
Visual studioVisual studio
Visual studio
 
Multi Screen Hell
Multi Screen HellMulti Screen Hell
Multi Screen Hell
 
Application fundamentals
Application fundamentalsApplication fundamentals
Application fundamentals
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Chapter 9 - Resources System
Chapter 9 - Resources SystemChapter 9 - Resources System
Chapter 9 - Resources System
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...
MVP Virtual Conference - Americas 2015 - Cross platform localization for mobi...
 

Plus de Anuchit Chalothorn (20)

Flutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARUFlutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARU
 
Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020
 
13 web service integration
13 web service integration13 web service integration
13 web service integration
 
09 material design
09 material design09 material design
09 material design
 
07 intent
07 intent07 intent
07 intent
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
 
04 layout design and basic widget
04 layout design and basic widget04 layout design and basic widget
04 layout design and basic widget
 
03 activity life cycle
03 activity life cycle03 activity life cycle
03 activity life cycle
 
02 create your first app
02 create your first app02 create your first app
02 create your first app
 
01 introduction
01 introduction 01 introduction
01 introduction
 
Material Theme
Material ThemeMaterial Theme
Material Theme
 
00 Android Wear Setup Emulator
00 Android Wear Setup Emulator00 Android Wear Setup Emulator
00 Android Wear Setup Emulator
 
MongoDB Replication Cluster
MongoDB Replication ClusterMongoDB Replication Cluster
MongoDB Replication Cluster
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
IT Automation with Puppet Enterprise
IT Automation with Puppet EnterpriseIT Automation with Puppet Enterprise
IT Automation with Puppet Enterprise
 
Using PhoneGap Command Line
Using PhoneGap Command LineUsing PhoneGap Command Line
Using PhoneGap Command Line
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Android App Development 08 : Support Multiple Devices

  • 1. 8 Support Different Devices Anuchit Chalothorn anoochit@gmail.com Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Supporting Different Languages Android will run on many devices in many regions. To reach the most users, your application should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your application will be used.
  • 3. Using Resources for Localization The default resource set must also include any default drawables and layouts, and can include other types of resources such as animations. ● res/drawable/ ● res/layout/ ● res/anim/ ● res/xml/ ● res/raw/
  • 4. Language String Android makes this easy with a resources directory in each Android project. Within the res/ directory are subdirectories for various resource types. There are also a few default files such as res/values/strings.xml, which holds your string values.
  • 5. Locale Directories and String Files To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. eg: values-es for Spanish, values-th for Thai, values for English etc.
  • 6. Locale : English English (default locale), /values/strings.xml : <?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">My Application</string> <string name="hello_world">Hello World!</string> </resources>
  • 7. Locale : Spanish Spanish, /values-es/strings.xml : <?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">Mi Aplicación</string> <string name="hello_world">Hola Mundo!</string> </resources>
  • 8. Locale : French French, /values-fr/strings.xml : <?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">Mon Application</string> <string name="hello_world">Bonjour le monde !</string> </resources>
  • 9. Use the String Resources You can refer to a string resource with the syntax R.string.<string_name>. There are a variety of methods that accept a string resource this way.
  • 10. Use the String Resources // Get a string resource from your app's Resources String hello = getResources().getString(R.string. hello_world); // Or supply a string resource to a method that requires a string TextView textView = new TextView(this); textView.setText(R.string.hello_world);
  • 11. Use the String in XML In other XML files, you can refer to a string resource with the syntax @string/<string_name> whenever the XML attribute accepts a string value.
  • 12. Use the String in XML <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" />
  • 13. Workshop: Locale Create form UI like following and make locale string for English, Vietnamese, Japanese and Thai.
  • 14.
  • 15. Locale your graphic You can use qualifiers with any resources include graphic in drawable directory, eg : ● /drawable for English (default locale) ● /drawable-th for Thai ● /drawable-vn for Vietnamese ● /drawable-ja for Japanese
  • 16. Workshop: Locale your graphic Create a UI like following and make locale graphic for English, Vietnamese, Japanese and Thai.
  • 17.
  • 18. Supporting Different Screens Android categorizes device screens using two general properties: size and density. You should expect that your app will be installed on devices with screens that range in both size and density.
  • 19. Sizes and Densities To declare different layouts and bitmaps you'd like to use for different screens, you must place these alternative resources in separate directories, similar to how you do for different language strings.
  • 20. Create Different Layouts To optimize your user experience on different screen sizes, you should create a unique layout XML file for each screen size you want to support.
  • 21. Create Different Layouts The directory named with a -<screen_size> suffix. ● /res/layout/main.xml <-- normal ● /res/layout-land/main.xml <-- landscape ● /res/layout-large/main.xml <-- for large ● /res/layout-large-land/main.xml <-- large landscape
  • 22. Create Different Bitmaps You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low, medium, high and extra-high density. This helps you achieve good graphical quality and performance on all screen densities.
  • 23. Create Different Bitmaps To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale: ● xhdpi: 2.0 ● hdpi: 1.5 ● mdpi: 1.0 (baseline) ● ldpi: 0.75 Ref: http://developer.android.com/design/style/iconography.html
  • 24. Workshop: Drawable Make graphic resources match each screen size.
  • 25.
  • 26. Supporting Different Platform Versions While the latest versions of Android often provide great APIs for your app, you should continue to support older versions of Android until more devices get updated.
  • 27. Specify Minimum and Target API The AndroidManifest.xml file describes details about your app and identifies which versions of Android it supports. Specifically, the minSdkVersion and targetSdkVersion with <use-sdk element.
  • 28. Specify Minimum and Target API <manifest xmlns:android="http://schemas.android. com/apk/res/android" ... > <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" /> ... </manifest>
  • 29. Check System Version at Runtime Android provides a unique code for each platform version in the Build constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.
  • 30. Check System Version at Runtime private void setUpActionBar() { // Make sure we're running on Honeycomb or higher to use ActionBar APIs if (Build.VERSION.SDK_INT >= Build.VERSION_CODES. HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } }
  • 31. Use Platform Styles and Themes Android provides user experience themes that give apps the look and feel of the underlying operating system. These themes can be applied to your app within the manifest file.
  • 32. Platform Styles and Themes To make your activity look like a dialog box: <activity android:theme="@android:style/Theme.Dialog">
  • 33. Platform Styles and Themes To make your activity have a transparent background:To make your activity have a transparent background: <activity android:theme="@android:style/Theme.Translucent">
  • 34. Platform Styles and Themes To apply your own custom theme defined in /res/values/styles.xml: <activity android:theme="@style/CustomTheme">
  • 35. Platform Styles and Themes To apply a theme to your entire app (all activities), add the android:theme attribute to the <application> element: <application android:theme="@style/CustomTheme">
  • 36. End