Android-AppWidget desktop plugin Learning

Source: Internet
Author: User

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 ");
}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.