Download - Androidify workshop
![Page 1: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/1.jpg)
Androidify Yourself!
![Page 2: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/2.jpg)
Alexey Buzdin
Aleksey Nikolaenko
@AlexeyBuzdin
@echoAlexey
![Page 3: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/3.jpg)
Google Developers Group
• Place to discuss, learn, and share passion for technology
• Focused on developer culture & technical content
• Free as beer
![Page 4: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/4.jpg)
![Page 5: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/5.jpg)
Today’s agenda
• Setup environment
• Introduction to Android
• Android application development
• GDG Raffle
http://goo.gl/HIYmeC
![Page 6: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/6.jpg)
Android Studio
• IntelliJ IDEA based
• Gradle build support
• Comes with Android SDK
• Layout editor with preview
and much more…
![Page 7: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/7.jpg)
Android platform
• Android is a Linux-based operating system and a software stack designed for touchscreen mobile devices
![Page 8: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/8.jpg)
Android Anatomy
![Page 9: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/9.jpg)
Android Runtime
• On Android you develop in Java
• ... but Android does not run Java Bytecode !
![Page 10: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/10.jpg)
Android Runtime
• Custom Virtual Machine. Why?
Constraints
Designed for 64M RAMNo swapPhone tech v. DesktopCPU specific
Oracle JVM problems
Memory HogSlow startupIP licensing restrictions
![Page 11: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/11.jpg)
Anatomy of Android application
• AndroidManifest
• Activities
• Fragments
• Intents
• Services
• Content providers
• Broadcast receivers
![Page 12: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/12.jpg)
Android Manifest
• general configuration for your application
• contains all component definitions of your appication
![Page 13: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/13.jpg)
Activity
• An activity represents a single screen with a user interface
• An activity is implemented as a subclass of Activity
![Page 14: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/14.jpg)
Fragment
• A Fragment represents a behavior or a portion of user interface in an Activity
• Affected by lifecycle of Activity
• subclass of Fragment
![Page 15: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/15.jpg)
Intent
Intent is used to invoke different components:
• Start a service
• Launch an activity
• Display a web page
• Broadcast a message
![Page 16: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/16.jpg)
Service
• Background process that performs long-running operations or remote processes
• No user interface for service
• A service is implemented as a subclass of Service
• Service can be local (accessed within application) or remote (scope of device)
![Page 17: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/17.jpg)
Content providers
• Content providers are used to share data between applications
• Can store data in SQLite, Web and other storages and perform CRUD operations with Content providers
• subclass of ContentProvider
![Page 18: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/18.jpg)
Broadcast receiver
• Component that responds to system-wide broadcast announcements (e.g.. Screen is turns on-off, SMS received,
• Broadcast delivered as Intent
• Don’t have user interface
• Subclass of BroadcastReceiver
![Page 19: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/19.jpg)
Android UI fundamentals
![Page 20: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/20.jpg)
Android UI fundamentals
Screen size• actual physical size, measured
as the screen's diagonal• 2.55”, 3.2”, 4.0”, 10.1”, ...Android groups into four generalized sizes: • Small• Normal• Large• Xlarge
![Page 21: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/21.jpg)
Android UI fundamentals
Screen density• quantity of pixels within a physical area of the
screen (dots per inch, dpi). • "low" density screen has fewer pixels• Android groups actual screen densities into four
generalized densities: • Low (ldpi, 120) • Medium (mdpi, 160)• High (hdpi, 240)• Extra high (xhdpi, 320)
![Page 22: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/22.jpg)
Android UI fundamentals
Density-independent pixel (dp)• virtual pixel unit to express layout dimensions or
position in a density-independent way• equivalent to one physical pixel on a 160 dpi screen • px = dp * (dpi / 160)• system transparently handles any scaling of the dp
units
![Page 23: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/23.jpg)
Android UI fundamentals
Best practices
• Do not use hard-coded pixel values in your application code
• Use size and density-specific resources
• Use wrap_content, match_parent, or the dp unit for layout dimensions
• Test Your Application on Multiple Screens
![Page 24: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/24.jpg)
Android resources
![Page 25: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/25.jpg)
Resources
Android supports the externalization of resources
• strings, colors, images, themes, menus, layouts
• system resources
Why?
• easier to maintain, update, and manage
• easier to define alternative resource values for internationalization and to support variations in hardware
![Page 26: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/26.jpg)
res/ & R
res/• Generated by ADT Wizard• Each resource type is stored in a
different subfolderR.java• Resources from /res are „indexed“ by
ADT or aapt tool• Enables to reference resources in
code
![Page 27: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/27.jpg)
Default v. Alternative Resources
• For any type of resource, we can specify default and multiple alternative resources
• Default resources are used regardless of the device configuration when no alternative resources match the current configuration
• Alternative resources are designed for use with a specific configuration
![Page 28: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/28.jpg)
How to specify Alternative Resources
• Create a new directory in res/
• res/<resources_name>-<config_qualifier>
• <config_qualifier> specifies a configuration for which these resources are to be used
• Save your alternative resources in new directory and name it as the default resource files
![Page 29: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/29.jpg)
Resource types
• Layouts• Simple values
– Strings– Plurals– Colors– Dimensions– Styles– String or integer arraysStored within XML files in the res/values folder
![Page 30: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/30.jpg)
Resource types
Styles and Themes• Let your applications
maintain a consistent look and feel by enabling you to specify the attribute values used by Views
• The most common use of is to store the colors and fonts for an application
![Page 31: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/31.jpg)
Building User Interfaces
![Page 32: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/32.jpg)
View
View• base class for all visual interface
elements controls, widgets• an object that draws something on the
screen that the user can interact withView Group • extends View class• an object that holds other Views
View group is an invisible container that organizes child views, while the child views draw some part of the UI
![Page 33: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/33.jpg)
Android Layouts
• A layout defines the visual structure for a user interface, such as the UI for an activity or app widget.
• Can be defined in XML or programmatically during runtime.
• XML layouts stored in res/layout folder and are qualified as resource
![Page 34: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/34.jpg)
Layout
Advantages of declaring UI in XML• Separation of the presentation from the code that
controls its behavior• modify UI without having to modify source code• create XML layouts for different screen
orientations, different device screen sizes, and different languages
• Easier to visualize the structure of your UI• Easier to design/debug UI• Visualizer tool (ADT)
![Page 35: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/35.jpg)
Layout example
ViewGroup
View
![Page 36: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/36.jpg)
Layout types
LinearLayout• Aligns all children in a single
direction - vertically or horizontally• All children are stacked one after
the other• Layout weight (android:
layout_weight) assigns an "importance" value to a view in terms of how much space is should occupy on the screen
![Page 37: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/37.jpg)
LinearLayout
![Page 38: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/38.jpg)
Layout types
RelativeLayout• view group that displays child
views in relative positions• can eliminate nested view
groups and keep your layout hierarchy flat, that improves performance
• specify the location of child objects relative to each other (child A to the left of child B) or to the parent
![Page 39: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/39.jpg)
Layout Parameters
Layout Parameters (layout_something)• parent view group defines layout parameters for
each child view (including the child view group)• child element must define LayoutParams that are
appropriate for its parent
![Page 40: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/40.jpg)
Basic widget toolbox
![Page 41: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/41.jpg)
Questions & Answers
![Page 43: Androidify workshop](https://reader034.vdocuments.us/reader034/viewer/2022042814/555802cfd8b42a200d8b532c/html5/thumbnails/43.jpg)