2013-05-30
Introduction: Learn about AppWidget.
Body: This article only shows a Simple plug-in on the desktop.
Manifest. xml configuration:
Place a receiver and configure <meta-data>
[Html]
<Cycler
Android: name = ". Test3_AppWidget"
Android: label = "Test3"
Android: icon = "@ drawable/run_boy_2"
>
<Intent-filter>
<Action android: name = "android. appwidget. action. APPWIDGET_UPDATE"/>
</Intent-filter>
<Meta-data
Android: name = "android. appwidget. provider"
Android: resource = "@ xml/test3_appwidget"/>
</Cycler>
<Cycler
Android: name = ". Test3_AppWidget"
Android: label = "Test3"
Android: icon = "@ drawable/run_boy_2"
>
<Intent-filter>
<Action android: name = "android. appwidget. action. APPWIDGET_UPDATE"/>
</Intent-filter>
<Meta-data
Android: name = "android. appwidget. provider"
Android: resource = "@ xml/test3_appwidget"/>
</Cycler>
Plug-in display Configuration:
Area size, layout, refresh, etc.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Appwidget-provider xmlns: android = "http://schemas.android.com/apk/res/android"
Android: minWidth = "72dp"
Android: minHeight = "72dp"
Android: updatePeriodMillis = "2000"
Android: initialLayout = "@ layout/test3_layout"
>
</Appwidget-provider>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Appwidget-provider xmlns: android = "http://schemas.android.com/apk/res/android"
Android: minWidth = "72dp"
Android: minHeight = "72dp"
Android: updatePeriodMillis = "2000"
Android: initialLayout = "@ layout/test3_layout"
>
</Appwidget-provider>
Plug-in layout:
FrameLayout/LinearLayout/RelativeLayout can be used. The control uses AnalogClock/Button/Chronometer/ImageButton/ProgressBar/TextView...
[Html
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "TEXT_1"
/>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "TEXT_VIEW"
/>
</LinearLayout>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "TEXT_1"
/>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "TEXT_VIEW"
/>
</LinearLayout>
AppWidgetProvider: extends Er:
Nothing is written in the Code. Expand it when necessary.
[Java]
Public class Test3_AppWidget extends AppWidgetProvider {
@ Override
Public void onDeleted (Context context, int [] appWidgetIds ){
Super. onDeleted (context, appWidgetIds );
System. out. println ("Test3_AppWidget onDeleted ");
}
@ Override
Public void onDisabled (Context context ){
Super. onDisabled (context );
System. out. println ("Test3_AppWidget onDisabled ");
}
@ Override
Public void onEnabled (Context context ){
Super. onEnabled (context );
System. out. println ("Test3_AppWidget onEnabled ");
}
@ Override
Public void onReceive (Context context, Intent intent ){
Super. onReceive (context, intent );
System. out. println ("Test3_AppWidget onReceive ");
}
@ Override
Public void onUpdate (Context context, AppWidgetManager appWidgetManager,
Int [] appWidgetIds ){
Super. onUpdate (context, appWidgetManager, appWidgetIds );
System. out. println ("Test3_AppWidget onUpdate ");
}
}
Public class Test3_AppWidget extends AppWidgetProvider {
@ Override
Public void onDeleted (Context context, int [] appWidgetIds ){
Super. onDeleted (context, appWidgetIds );
System. out. println ("Test3_AppWidget onDeleted ");
}
@ Override
Public void onDisabled (Context context ){
Super. onDisabled (context );
System. out. println ("Test3_AppWidget onDisabled ");
}
@ Override
Public void onEnabled (Context context ){
Super. onEnabled (context );
System. out. println ("Test3_AppWidget onEnabled ");
}
@ Override
Public void onReceive (Context context, Intent intent ){
Super. onReceive (context, intent );
System. out. println ("Test3_AppWidget onReceive ");
}
@ Override
Public void onUpdate (Context context, AppWidgetManager appWidgetManager,
Int [] appWidgetIds ){
Super. onUpdate (context, appWidgetManager, appWidgetIds );
System. out. println ("Test3_AppWidget onUpdate ");
}
}