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

PDF
Chapt 04 user interaction
PPTX
Android Widget
PDF
Android appwidget
PPTX
Android Tutorials - Powering with Selection Widget
PDF
Android Basic Components
PDF
04 user interfaces
PDF
Android ui menu
PDF
Android activities & views
Chapt 04 user interaction
Android Widget
Android appwidget
Android Tutorials - Powering with Selection Widget
Android Basic Components
04 user interfaces
Android ui menu
Android activities & views

What's hot (10)

PDF
The battle between the states (all about flutter stateless & stateful widgets...
PPTX
08.1. Android How to Use Intent (explicit)
PPT
Android Button
PPTX
Activities, Fragments, and Events
PDF
Android App Development 03 : Widget &amp; UI
PDF
Introduction to fragments in android
DOC
Day 4: Activity lifecycle
PPT
android menus
PDF
A comprehensive guide on developing responsive and common react filter component
The battle between the states (all about flutter stateless & stateful widgets...
08.1. Android How to Use Intent (explicit)
Android Button
Activities, Fragments, and Events
Android App Development 03 : Widget &amp; UI
Introduction to fragments in android
Day 4: Activity lifecycle
android menus
A comprehensive guide on developing responsive and common react filter component
Ad

Similar to Android Homescreen Widgets Demystified (20)

PDF
Android how to hellowidget
PDF
Android howto hellowidget
PDF
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
PDF
Invading the home screen
ODP
Home Screen Widgets
PPTX
App widget
PDF
Android Deep Dive
PDF
(ATS6-DEV07) Building widgets for ELN home page
PDF
Introducing Honeycomb
PPTX
Introduction to android
ODP
Android App Development - 13 Broadcast receivers and app widgets
PPT
WRT Widgets Masterclass - OverTheAir
PDF
Porting experience - by Golden Gekko
PDF
Vodafone 360 - Porting Experience
PDF
Designing a High Quality User Experience for Widgets
PPTX
Introduction to Android for Quality Engineers
PDF
Androidify workshop
PDF
Adv android 1-0-cc
PDF
Android Development...The 20,000-Foot View
PDF
Flutter Roadshow 2024 - Homescreen Widgets - Rohan Joshi.pdf
Android how to hellowidget
Android howto hellowidget
Dicoding Developer Coaching #21: Android | Cara Membuat Widget di Aplikasi An...
Invading the home screen
Home Screen Widgets
App widget
Android Deep Dive
(ATS6-DEV07) Building widgets for ELN home page
Introducing Honeycomb
Introduction to android
Android App Development - 13 Broadcast receivers and app widgets
WRT Widgets Masterclass - OverTheAir
Porting experience - by Golden Gekko
Vodafone 360 - Porting Experience
Designing a High Quality User Experience for Widgets
Introduction to Android for Quality Engineers
Androidify workshop
Adv android 1-0-cc
Android Development...The 20,000-Foot View
Flutter Roadshow 2024 - Homescreen Widgets - Rohan Joshi.pdf
Ad

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

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