Android系统App Widgets英文资料外文翻译文献.docx

上传人:b****1 文档编号:2858125 上传时间:2023-05-04 格式:DOCX 页数:11 大小:37.49KB
下载 相关 举报
Android系统App Widgets英文资料外文翻译文献.docx_第1页
第1页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第2页
第2页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第3页
第3页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第4页
第4页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第5页
第5页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第6页
第6页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第7页
第7页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第8页
第8页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第9页
第9页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第10页
第10页 / 共11页
Android系统App Widgets英文资料外文翻译文献.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Android系统App Widgets英文资料外文翻译文献.docx

《Android系统App Widgets英文资料外文翻译文献.docx》由会员分享,可在线阅读,更多相关《Android系统App Widgets英文资料外文翻译文献.docx(11页珍藏版)》请在冰点文库上搜索。

Android系统App Widgets英文资料外文翻译文献.docx

Android系统AppWidgets英文资料外文翻译文献

Android系统AppWidgets英文资料外文翻译文献

AppWidgets

AppWidgetsareminiatureapplicationviewsthatcanbeembeddedinotherapplications(suchastheHomescreen)andreceiveperiodicupdates.TheseviewsarereferredtoasWidgetsintheuserinterface,andyoucanpublishonewithanAppWidgetprovider.AnapplicationcomponentthatisabletoholdotherAppWidgetsiscalledanAppWidgethost.ThescreenshotbelowshowstheMusicAppWidget.

 

ThisdocumentdescribeshowtopublishanAppWidgetusinganAppWidgetprovider.

TheBasics

TocreateanAppWidget,youneedthefollowing:

AppWidgetProviderInfoobject

DescribesthemetadataforanAppWidget,suchastheAppWidget'slayout,updatefrequency,andtheAppWidgetProviderclass.ThisshouldbedefinedinXML.

AppWidgetProviderclassimplementation

DefinesthebasicmethodsthatallowyoutoprogrammaticallyinterfacewiththeAppWidget,basedonbroadcastevents.Throughit,youwillreceivebroadcastswhentheAppWidgetisupdated,enabled,disabledanddeleted.

Viewlayout

DefinestheinitiallayoutfortheAppWidget,definedinXML.

Additionally,youcanimplementanAppWidgetconfigurationActivity.ThisisanoptionalActivitythatlauncheswhentheuseraddsyourAppWidgetandallowshimorhertomodifyAppWidgetsettingsatcreate-time.

Thefollowingsectionsdescribehowtosetupeachofthesecomponents.

DeclaringanAppWidgetintheManifest

First,declaretheAppWidgetProviderclassinyourapplication'sAndroidManifest.xmlfile.Forexample:

name="ExampleAppWidgetProvider">

name="android.appwidget.action.APPWIDGET_UPDATE"/>

name="android.appwidget.provider"

android:

resource="@xml/example_appwidget_info"/>

Theelementrequirestheandroid:

nameattribute,whichspecifiestheAppWidgetProviderusedbytheAppWidget.

Theelementmustincludeanelementwiththeandroid:

nameattribute.ThisattributespecifiesthattheAppWidgetProvideracceptstheACTION_APPWIDGET_UPDATEbroadcast.Thisistheonlybroadcastthatyoumustexplicitlydeclare.TheAppWidgetManagerautomaticallysendsallotherAppWidgetbroadcaststotheAppWidgetProviderasnecessary.

TheelementspecifiestheAppWidgetProviderInforesourceandrequiresthefollowingattributes:

•android:

name-Specifiesthemetadataname.Useandroid.appwidget.providertoidentifythedataastheAppWidgetProviderInfodescriptor.

•android:

resource-SpecifiestheAppWidgetProviderInforesourcelocation.

AddingtheAppWidgetProviderInfoMetadata

TheAppWidgetProviderInfodefinestheessentialqualitiesofanAppWidget,suchasitsminimumlayoutdimensions,itsinitiallayoutresource,howoftentoupdatetheAppWidget,and(optionally)aconfigurationActivitytolaunchatcreate-time.DefinetheAppWidgetProviderInfoobjectinanXMLresourceusingasingleelementandsaveitintheproject'sres/xml/folder.

Forexample:

android="

android:

minWidth="294dp"

--density-independentpixels-->

android:

minHeight="72dp"

android:

updatePeriodMillis="86400000"

--onceperday-->

android:

initialLayout="@layout/example_appwidget"

android:

configure="com.example.android.ExampleAppWidgetConfigure">

Here'sasummaryoftheattributes:

•ThevaluesfortheminWidthandminHeightattributesspecifytheminimumarearequiredbytheAppWidget'slayout.

ThedefaultHomescreenpositionsAppWidgetsinitswindowbasedonagridofcellsthathaveadefinedheightandwidth.IfthevaluesforanAppWidget'sminimumwidthorheightdon'tmatchthedimensionsofthecells,thentheAppWidgetdimensionsrounduptothenearestcellsize.(SeetheAppWidgetDesignGuidelinesformoreinformationontheHomescreencellsizes.)

BecausetheHomescreen'slayoutorientation(andthus,thecellsizes)canchange,asaruleofthumb,youshouldassumetheworst-casecellsizeof74pixelsfortheheightandwidthofacell.However,youmustsubtract2fromthefinaldimensiontoaccountforanyintegerroundingerrorsthatoccurinthepixelcount.Tofindyourminimumwidthandheightindensity-independentpixels(dp),usethisformula:

(numberofcells*74)–2

Followingthisformula,youshoulduse72dpforaheightofonecell,294dpandforawidthoffourcells.

•TheupdatePeriodMillisattributedefineshowoftentheAppWidgetframeworkshouldrequestanupdatefromtheAppWidgetProviderbycallingtheonUpdate()method.Theactualupdateisnotguaranteedtooccurexactlyontimewiththisvalueandwesuggestupdatingasinfrequentlyaspossible—perhapsnomorethanonceanhourtoconservethebattery.Youmightalsoallowtheusertoadjustthefrequencyinaconfiguration—somepeoplemightwantastocktickertoupdateevery15minutes,ormaybeonlyfourtimesaday.

Note:

Ifthedeviceisasleepwhenitistimeforanupdate(asdefinedbyupdatePeriodMillis),thenthedevicewillwakeupinordertoperformtheupdate.Ifyoudon'tupdatemorethanonceperhour,thisprobablywon'tcausesignificantproblemsforthebatterylife.If,however,youneedtoupdatemorefrequentlyand/oryoudonotneedtoupdatewhilethedeviceisasleep,thenyoucaninsteadperformupdatesbasedonanalarmthatwillnotwakethedevice.Todoso,setanalarmwithanIntentthatyourAppWidgetProviderreceives,usingtheAlarmManager.SetthealarmtypetoeitherELAPSED_REALTIMEorRTC,whichwillonlydeliverthealarmwhenthedeviceisawake.ThensetupdatePeriodMillistozero("0").

•TheinitialLayoutattributepointstothelayoutresourcethatdefinestheAppWidgetlayout.

•TheconfigureattributedefinestheActivitytolaunchwhentheuseraddstheAppWidget,inorderforhimorhertoconfigureAppWidgetproperties.Thisisoptional(readCreatinganAppWidgetConfigurationActivitybelow).

SeetheAppWidgetProviderInfoclassformoreinformationontheattributesacceptedbytheelement.

CreatingtheAppWidgetLayout

YoumustdefineaninitiallayoutforyourAppWidgetinXMLandsaveitintheproject'sres/layout/directory.YoucandesignyourAppWidgetusingtheViewobjectslistedbelow,butbeforeyoubegindesigningyourAppWidget,pleasereadandunderstandtheAppWidgetDesignGuidelines.

CreatingtheAppWidgetlayoutissimpleifyou'refamiliarwithDeclaringLayoutinXML.However,youmustbeawarethatAppWidgetlayoutsarebasedonRemoteViews,whichdonotsupporteverykindoflayoutorviewwidget.

ARemoteViewsobject(and,consequently,anAppWidget)cansupportthefollowinglayoutclasses:

•FrameLayout

•LinearLayout

•RelativeLayout

Andthefollowingwidgetclasses:

•AnalogClock

•Button

•Chronometer

•ImageButton

•ImageView

•ProgressBar

•TextView

Descendantsoftheseclassesarenotsupported.

UsingtheAppWidgetProviderClass

YoumustdeclareyourAppWidgetProviderclassimplementationasabroadcastreceiverusingtheelementintheAndroidManifest(seeDeclaringanAppWidgetintheManifestabove).

TheAppWidgetProviderclassextendsBroadcastReceiverasaconvenienceclasstohandletheAppWidgetbroadcasts.TheAppWidgetProviderreceivesonlytheeventbroadcaststhatarerelevanttotheAppWidget,suchaswhentheAppWidgetisupdated,deleted,enabled,anddisabled.Whenthesebroadcasteventsoccur,theAppWidgetProviderreceivesthefollowingmethodcalls:

onUpdate(Context,AppWidgetManager,int[])

ThisiscalledtoupdatetheAppWidgetatintervalsdefinedbytheupdatePeriodMillisattributeintheAppWidgetProviderInfo(seeAddingtheAppWidgetProviderInfoMetadataabove).ThismethodisalsocalledwhentheuseraddstheAppWidget,soitshouldperformtheessentialsetup,suchasdefineeventhandlersforViewsandstartatemporaryService,ifnecessary.However,ifyouhavedeclaredaconfigurationActivity,thismethodisnotcalledwhentheuseraddstheAppWidget,butiscalledforthesubsequentupdates.ItistheresponsibilityoftheconfigurationActivitytoperformthefirstupdatewhenconfigurationisdone.(SeeCreatinganAppWidgetConfigurationActivitybelow.)

onDeleted(Context,int[])

ThisiscalledeverytimeanAppWidgetisdeletedfromtheAppWidgethost.

onEnabled(Context)

ThisiscalledwhenaninstancetheAppWidgetiscreatedforthefirsttime.Forexample,iftheuseraddstwoinstancesofyourAppWidget,thisisonlycalledthefirsttime.IfyouneedtoopenanewdatabaseorperformothersetupthatonlyneedstooccuronceforallAppWidgetinstances,thenthisisagoodplacetodoit.

onDisabled(Context)

ThisiscalledwhenthelastinstanceofyourAppWidgetisdeletedfromtheAppWidgethost.ThisiswhereyoushouldcleanupanyworkdoneinonEnabled(Context),suchasdeleteatemporarydatabase.

onReceive(Context,Intent)

Thisiscalledforeverybroadcastandbeforeeachoftheabovecallbackmethods.Younormallydon'tneedtoimplementthismethodbecausethedefaultAppWidgetProviderimplementationfiltersallAppWidgetbroadcastsandcallstheabovemethodsasappropriate.

Note:

InAndroid1.5,thereisaknownissueinwhichtheonDeleted()methodwillnotbecalledwhenitshouldbe.Toworkaroundthisissue,youcanimplementonReceive()asdescribedinthisGroupposttoreceivetheonDeleted()callback.

ThemostimportantAppWidgetProvidercallbackisonUpdated()becauseitiscalledwheneachAppWidgetisaddedtoahost(unlessyouuseaconfigurationActivity).IfyourAppWidgetacceptsanyuserinteraction

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2