DOC PREVIEW
SDSU CS 696 - Android App Widgets

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 696 Emerging Web and Mobile TechnologiesSpring Semester, 2011Doc 26 Android App WidgetsApr 28, 2011Copyright ©, All rights reserved. 2011 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/opl.shtml) license defines the copyright on this document.Thursday, April 28, 2011References2App Widgets, http://developer.android.com/guide/topics/appwidgets/index.htmlIntroducing home screen widgets and the AppWidget framework, http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.htmlWidget Design Guidelines http://developer.android.com/guide/practices/ui_guidelines/widget_design.htmlThursday, April 28, 2011App Widget3Small application that can be embedded in Home screenReceive periodic updatesCurrent WeatherQuote of the DayStock PricesSample App WidgetsThursday, April 28, 2011Basic Parts4AppWidgetProviderInfo Metadata for an App Widget in XMLAppWidgetProvider class implementationJava code for the App WidgetView layoutInitial layout for the App Widget in XMLConfiguration ActivityOptionalConfigures App Widget when createdThursday, April 28, 2011Manifest Info5<receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/example_appwidget_info" /></receiver>Thursday, April 28, 2011AppWidgetProviderInfo Metadata6<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="294dp" <!-- density-independent pixels --> android:minHeight="72dp" android:updatePeriodMillis="86400000" <!-- once per day --> android:initialLayout="@layout/example_appwidget" android:configure="com.example.android.ExampleAppWidgetConfigure" ></appwidget-provider>Thursday, April 28, 2011Metadata - minWidth & minHeight7Home Screen - grid of cellsCell is 74 pixels by 74 pixelsPixel rounding error - 2 pixelsApp Widget size(number of cells * 74) - 2Thursday, April 28, 2011updatePeriodMillis8how often the App Widget framework calls update on your App WidgetUpdates of every hour or longer should not drain the batteryThursday, April 28, 2011App Widget Layout9 FrameLayout LinearLayout RelativeLayout AnalogClock Button Chronometer ImageButton ImageView ProgressBar TextViewLayouts ViewsThursday, April 28, 2011Anatomy of Widget10Thursday, April 28, 2011Landscape11Thursday, April 28, 2011App Widget Graphics12You will need graphics for your App Widgethttp://developer.android.com/guide/practices/ui_guidelines/widget_design.htmlThursday, April 28, 2011AppWidgetProvider13onUpdate(Context, AppWidgetManager, int[])The main methodCalled by App Widget manageronDeleted(Context, int[])Called every time an App Widget is deletedonEnabled(Context)Called when the App Widget is created for the first time. onDisabled(Context)Called when last App Widget is deletedonReceive(Context, Intent) All calls go here firstThursday, April 28, 2011First Example - Just Text14Thursday, April 28, 2011SampleWidget.java15public class SampleWidget extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); appWidgetManager.updateAppWidget(appWidgetIds[0], views); }}Thursday, April 28, 2011res/layout/widget.xml16<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="12dip" android:padding="10dip" android:gravity="center" android:text="Sample" /></LinearLayout>Thursday, April 28, 2011res/xml/appwidget_definition.xml17<?xml version="1.0" encoding="utf-8"?><appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="146dip" android:minHeight="72dip" android:updatePeriodMillis="86400000" android:initialLayout="@layout/widget" ></appwidget-provider>Thursday, April 28, 2011AndroidManifest.xml18<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="edu.sdsu.cs.whitney" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <receiver android:name=".SampleWidget" android:label="@string/app_name" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/appwidget_definition" /> </receiver> </application> <uses-sdk android:minSdkVersion="3" /></manifest> Thursday, April 28, 2011With Background and Multiple Widgets19Thursday, April 28, 2011SampleWidget20public class SampleWidget extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; Log.i("test", "start"); for (int id = 0; id < N; id++) { Log.i("test", "id " + id); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); views.setTextViewText(R.id.message, "Hello World " + id); appWidgetManager.updateAppWidget(appWidgetIds[id], views); } }}Thursday, April 28, 2011Layout21<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" style="@style/WidgetBackground"> <TextView android:id="@+id/message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="12dip" android:padding="10dip" android:gravity="center" android:text="Sample" style="@style/Text" /></LinearLayout>Thursday, April 28, 2011res/values/styles.xml22<?xml version="1.0" encoding="utf-8"?><resources>


View Full Document

SDSU CS 696 - Android App Widgets

Download Android App Widgets
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Android App Widgets and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Android App Widgets 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?