SlideShare a Scribd company logo
Homescreen Widgets
Demystified
Pearl Chen
@androidsNsheep
AndroidTO // Oct 26, 2010
Hi, I'm a web developer...
So many ways to create
an Android application…
but none of them
create homescreen widgets!
...and I ♥ homescreen widgets
Examples
default Donut homescreen
default Froyo homescreen
...and I ♥ homescreen widgets
Examples
Gmail Unread Count
HTC SenseUI email widget
...and I ♥ homescreen widgets
Examples
Music Players
Settings controls
Key reasons to build a widget
• At-a-glance information
– unread messages, calendar items, to do lists
• Control apps that run in the background
– Music player
• Toggle settings
– settings that affect other applications such as GPS or wifi
– Consider how the Google Voice widget can toggle between “Use for all calls”,
“Do not use for calls”, “International calls only”, and “Ask for every call”. You
might want to toggle this setting before opening the Dailer app
• “Smart” shortcuts
– Reduce something that would normally take at least 2 steps into 1
– If it simply opens another application, keep it as a regular application shortcut
(Another) key reason to build a widget
Keep users engaged with your app!
out of sight == out of mind 
Hey!
Don’t forget about me!
Designing Widgets
Widget Design Best Practices UI Guidelines
developer.android.com/guide/practices/ui_guidelines/widget_design.html
Designing Widgets
Lighter color theme
in Cupcake and Donut
Darker color theme
in Éclair and Froyo
Coding Widgets
App Widgets Framework Guide
developer.android.com/guide/topics/appwidgets/index.html
1. Download
2. Import into Eclipse
as an ‘Existing Project’
3. Run
Sample Widget Code
code.google.com/p/androidto-basicwidget/
Overview of Widget Development
1) Create a new Android project in Eclipse
without an Activity class
2) Declare AppWidgetProviderInfo object
3) Create xml layout file for widget view
4) Extend the AppWidgetProvider class
5) Update AndroidManifest.xml
Overview of Widget Development
1) Create a new Android project in Eclipse
without an Activity class
Create a new Android project
Widgets not available in
Android 1.1
No need for an Activity
unless there’s going to be
a standalone application
Overview of Widget Development
2) Declare AppWidgetProviderInfo object
AppWidgetProviderInfo
1. Create an xml folder
in the res folder.
2. In the xml folder,
create a new
Android XML File
AppWidgetProviderInfo
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis=“30000"
android:initialLayout="@layout/widget">
</appwidget-provider>
(number of cells * 74) - 2
Following this formula, you should use 72 dp for a height of one cell, 294 dp and for a width of four cells.
(number of cells * 74) - 2
Overview of Widget Development
3) Create xml layout file for widget view
XML Layout File
1. There’s already a main.xml file in the
res/layout folder so just reuse that.
XML Layout File
2. I renamed it to widget.xml so it was more descriptive.
3. Added a background and padding to the container.
4. And gave the TextView an id of current_time.
XML Layout File
5. And let’s also add a refresh button as a ImageButton
with and id of refresh.
If a widget is not an Activity, what is it?
An Activity could simply be
described as an UI screen.
If a widget is not an Activity, what is it?
An Activity could simply be
described as an UI screen.
It contains View widgets such
as LinearLayout, TextView,
and Button typically marked
up in a layout xml file.
If a widget is not an Activity, what is it?
An Activity could simply be
described as an UI screen.
It contains View widgets such
as LinearLayout, TextView,
and Button typically marked
up in a layout xml file.
e.g.
Button btn =
(Button) findViewById(R.id.my_button);
btn.setText(“Submit”);
If a widget is not an Activity, what is it?
Widgets also contain View
widgets such as LinearLayout,
TextView, and Button (but
there are limitations to what
Views you can use).
If a widget is not an Activity, what is it?
Button btn =
(Button) findViewById(R.id.my_button);
btn.setText(“Submit”);
If a widget is not an Activity, what is it?
RemoteViews
RemoteViews remoteView =
new RemoteViews(
context.getPackageName(),
R.layout.widget
);
remoteView.setTextViewText(
R.id.my_button,
“Submit”
);
If a widget is not an Activity, what is it?
The application component that
supplies the UI for a widget is a
BroadcastReceiver
RemoteViews
Overview of Widget Development
4) Extend the AppWidgetProvider class
AppWidgetProvider
public class BasicWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(
Context context,
AppWidgetManager appWidgetManager,
int[] appWidgetIds)
{
super.onUpdate(
context,
appWidgetManager,
appWidgetIds
);
//do some stuff every updatePeroidMillis!
}
}
AppWidgetProvider
void onUpdate( Context context,
AppWidgetManager appWidgetManager,
int[] appWidgetIds )
void onEnabled( Context context )
void onDeleted( Context context,
int[] appWidgetIds )
void onDisabled( Context context )
void onReceive( Context context,
Intent intent )
AppWidgetProvider
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
setAlarm(context, appWidgetId, 30000);
}
AppWidgetProvider
AppWidgetProvider
Overview of Widget Development
5) Update AndroidManifest.xml
AndroidManifest.xml
THANK YOU!
Pearl Chen
@androidsNsheep

More Related Content

What's hot

The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...
Katy Slemon
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
Oum Saokosal
 
Android Button
Android ButtonAndroid Button
Android Button
bhavin joshi
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
Henry Osborne
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAnuchit Chalothorn
 
20101127
2010112720101127
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
Katy Slemon
 

What's hot (10)

The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...The battle between the states (all about flutter stateless & stateful widgets...
The battle between the states (all about flutter stateless & stateful widgets...
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Android Button
Android ButtonAndroid Button
Android Button
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UI
 
20101127
2010112720101127
20101127
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
android menus
android menusandroid menus
android menus
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
 

Similar to Android Homescreen Widgets Demystified

Get an Android tutorial for beginners
Get an Android tutorial for beginnersGet an Android tutorial for beginners
Get an Android tutorial for beginners
JavaTpoint.Com
 
Learning Android Part 2/6
Learning Android Part 2/6Learning Android Part 2/6
Learning Android Part 2/6
Girish Bellalcheru
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
Mobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’sMobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’s
Adam Wilson
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
Siva Kumar reddy Vasipally
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
guest213e237
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
Amit Saxena
 
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
DicodingEvent
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Shrijan Tiwari
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intents
Vitali Pekelis
 
Android App development III
Android App development IIIAndroid App development III
Android App development III
Thenraja Vettivelraj
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
Vivek Bhusal
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Android session 2
Android session 2Android session 2
Android session 2
Ahesanali Suthar
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
Monir Zzaman
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
Chandrakant Divate
 
Gadgets Windows
Gadgets WindowsGadgets Windows
Gadgets Windows
sahibsahib
 

Similar to Android Homescreen Widgets Demystified (20)

Get an Android tutorial for beginners
Get an Android tutorial for beginnersGet an Android tutorial for beginners
Get an Android tutorial for beginners
 
Learning Android Part 2/6
Learning Android Part 2/6Learning Android Part 2/6
Learning Android Part 2/6
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Mobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’sMobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’s
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
 
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intents
 
Android App development III
Android App development IIIAndroid App development III
Android App development III
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Android session 2
Android session 2Android session 2
Android session 2
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Gadgets Windows
Gadgets WindowsGadgets Windows
Gadgets Windows
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Android Homescreen Widgets Demystified

  • 2. Hi, I'm a web developer... So many ways to create an Android application… but none of them create homescreen widgets!
  • 3. ...and I ♥ homescreen widgets Examples default Donut homescreen default Froyo homescreen
  • 4. ...and I ♥ homescreen widgets Examples Gmail Unread Count HTC SenseUI email widget
  • 5. ...and I ♥ homescreen widgets Examples Music Players Settings controls
  • 6. Key reasons to build a widget • At-a-glance information – unread messages, calendar items, to do lists • Control apps that run in the background – Music player • Toggle settings – settings that affect other applications such as GPS or wifi – Consider how the Google Voice widget can toggle between “Use for all calls”, “Do not use for calls”, “International calls only”, and “Ask for every call”. You might want to toggle this setting before opening the Dailer app • “Smart” shortcuts – Reduce something that would normally take at least 2 steps into 1 – If it simply opens another application, keep it as a regular application shortcut
  • 7. (Another) key reason to build a widget Keep users engaged with your app! out of sight == out of mind  Hey! Don’t forget about me!
  • 8. Designing Widgets Widget Design Best Practices UI Guidelines developer.android.com/guide/practices/ui_guidelines/widget_design.html
  • 9. Designing Widgets Lighter color theme in Cupcake and Donut Darker color theme in Éclair and Froyo
  • 10. Coding Widgets App Widgets Framework Guide developer.android.com/guide/topics/appwidgets/index.html
  • 11. 1. Download 2. Import into Eclipse as an ‘Existing Project’ 3. Run Sample Widget Code code.google.com/p/androidto-basicwidget/
  • 12. Overview of Widget Development 1) Create a new Android project in Eclipse without an Activity class 2) Declare AppWidgetProviderInfo object 3) Create xml layout file for widget view 4) Extend the AppWidgetProvider class 5) Update AndroidManifest.xml
  • 13. Overview of Widget Development 1) Create a new Android project in Eclipse without an Activity class
  • 14. Create a new Android project Widgets not available in Android 1.1 No need for an Activity unless there’s going to be a standalone application
  • 15. Overview of Widget Development 2) Declare AppWidgetProviderInfo object
  • 16. AppWidgetProviderInfo 1. Create an xml folder in the res folder. 2. In the xml folder, create a new Android XML File
  • 18. Overview of Widget Development 3) Create xml layout file for widget view
  • 19. XML Layout File 1. There’s already a main.xml file in the res/layout folder so just reuse that.
  • 20. XML Layout File 2. I renamed it to widget.xml so it was more descriptive. 3. Added a background and padding to the container. 4. And gave the TextView an id of current_time.
  • 21. XML Layout File 5. And let’s also add a refresh button as a ImageButton with and id of refresh.
  • 22. If a widget is not an Activity, what is it? An Activity could simply be described as an UI screen.
  • 23. If a widget is not an Activity, what is it? An Activity could simply be described as an UI screen. It contains View widgets such as LinearLayout, TextView, and Button typically marked up in a layout xml file.
  • 24. If a widget is not an Activity, what is it? An Activity could simply be described as an UI screen. It contains View widgets such as LinearLayout, TextView, and Button typically marked up in a layout xml file. e.g. Button btn = (Button) findViewById(R.id.my_button); btn.setText(“Submit”);
  • 25. If a widget is not an Activity, what is it? Widgets also contain View widgets such as LinearLayout, TextView, and Button (but there are limitations to what Views you can use).
  • 26. If a widget is not an Activity, what is it? Button btn = (Button) findViewById(R.id.my_button); btn.setText(“Submit”);
  • 27. If a widget is not an Activity, what is it? RemoteViews RemoteViews remoteView = new RemoteViews( context.getPackageName(), R.layout.widget ); remoteView.setTextViewText( R.id.my_button, “Submit” );
  • 28. If a widget is not an Activity, what is it? The application component that supplies the UI for a widget is a BroadcastReceiver RemoteViews
  • 29. Overview of Widget Development 4) Extend the AppWidgetProvider class
  • 30. AppWidgetProvider public class BasicWidgetProvider extends AppWidgetProvider { @Override public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate( context, appWidgetManager, appWidgetIds ); //do some stuff every updatePeroidMillis! } }
  • 31. AppWidgetProvider void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds ) void onEnabled( Context context ) void onDeleted( Context context, int[] appWidgetIds ) void onDisabled( Context context ) void onReceive( Context context, Intent intent )
  • 32. AppWidgetProvider final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; setAlarm(context, appWidgetId, 30000); }
  • 35. Overview of Widget Development 5) Update AndroidManifest.xml