Homescreen Widgets Demystified Pearl AndroidTO // Oct 26, 2010.

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
Joemarie Comeros Amparo Android Development Orientation for Starters.
Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings.
Chapter 6 Jam! Implementing Audio in Android Apps.
Chapter 6: Jam! Implementing Audio in Android Apps.
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
CSS216 MOBILE PROGRAMMING Android, Chapter 10 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
1 CSCE 4013: Mobile Systems Programming Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
Android and Project Structure. Android Android OS – Built on Linux Kernel – Phones – Netbooks – Readers – Other???
Chapter 1: Voilà! Meet the Android. Smartphones –Can browse the Web –Allow you to play games –Use business applications –Check –Play music –Record.
Better reference the original webpage :
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Mobile Application Development with ANDROID Tejas Lagvankar UMBC 29 April 2009.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Introducing the Sudoku Example
UI Design Patterns & Best Practices Mike Wolfson July 22, 2010.
CS5103 Software Engineering Lecture 08 Android Development II.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Chapter 1: Voilà! Meet the Android
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Broadcast Receiver Android Club Agenda Broadcast Receiver Widget.
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 17 Creating Homescreen Widgets.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
© by Pearson Education, Inc. All Rights Reserved. 1 Introduction to Android From “Android: How to Program” By Paul Deitel and Harvey Deitel.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
Cosc 5/4730 Android App Widgets. App Widgets App Widgets are miniature application views that can be embedded in other applications (such as the Home.
Application Development for mobile Devices
Configuring Android Development Environment Nilesh Singh.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Silicon Valley Code Camp 2009 “Embellish Your Pictures” Build an Application for an Android Phone Jack Ha, Balwinder Kaur Oct 3, 2009 – 5:15PM Room CCL.
First Venture into the Android World Chapter 1 Part 2.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
Introduction to Android Programming
Cosc 4735 Nougat API 24+ additions.
Lab7 – Appendix.
CS371m - Mobile Computing Services and Broadcast Receivers
GUI Programming Fundamentals
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Android Boot Camp for Developers Using Java, 3E
MAD.
Android Widget Tutorial
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Mobile Application Development BSCS-7 Lecture # 13
Android Programming Lecture 9
CS5103 Software Engineering
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
Application Development A Tutorial Driven Course
Activities, Fragments, and Intents
Presentation transcript:

Homescreen Widgets Demystified Pearl 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 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 2)Declare AppWidgetProviderInfo object 3)Create xml layout file for widget view 4)Extend the AppWidgetProvider class 5)Update AndroidManifest.xml

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 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

AppWidgetProviderInfo 1.Create an xml folder in the res folder. 2.In the xml folder, create a new Android XML File

AppWidgetProviderInfo Because the Home screen's layout orientation (and thus, the cell sizes) can change, as a rule of thumb, you should assume the worst-case cell size of 74 pixels for the height and width of a cell. However, you must subtract 2 from the final dimension to account for any integer rounding errors that occur in the pixel count. To find your minimum width and height in density-independent pixels (dp), use this formula: (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 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

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 View s 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 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

AppWidgetProvider public class BasicWidgetProvider extends AppWidgetProvider 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 public void onUpdate( Context context, AppWidgetManager AppWidgetManager, int[] appWidgetIds) { /* update each widget that belongs to this provider individually by setting an alarm because we're setting an alarm, onUpdate is really only called when a new widget is added, or the phone restarts */ final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; setAlarm(context, appWidgetId, 30000); }

AppWidgetProvider public static void setAlarm(Context context, int appWidgetId, int updateRate) { // To prevent any ANR timeouts, // we perform the update in an intent service PendingIntent pendingIntent = createUpdatePendingIntent(context,REFRESH,appWidgetId); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); //and then have the alarm wake up the system to do updates alarms.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), updateRate, pendingIntent); }

AppWidgetProvider public static class UpdateService extends IntentService public void onHandleIntent(Intent intent) { ComponentName widget = new ComponentName( this, BasicWidgetProvider.class ); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); appWidgetManager.updateAppWidget(widget, buildUpdate(this, intent)); } private RemoteViews buildUpdate(Context context, Intent intent) { RemoteViews views = new RemoteViews( context.getPackageName(), R.layout.widget ); //update the UI here… return views; } context.startService(new Intent(context, UpdateService.class));

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

AndroidManifest.xml <meta-data android:name="android.appwidget.provider" />

THANK YOU! Pearl