Android系统App Widgets英文资料外文翻译文献Word文档下载推荐.docx

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

Android系统App Widgets英文资料外文翻译文献Word文档下载推荐.docx

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

Android系统App Widgets英文资料外文翻译文献Word文档下载推荐.docx

Viewlayout

DefinestheinitiallayoutfortheAppWidget,definedinXML.

Additionally,youcanimplementanAppWidgetconfigurationActivity.ThisisanoptionalActivitythatlauncheswhentheuseraddsyourAppWidgetandallowshimorhertomodifyAppWidgetsettingsatcreate-time.

Thefollowingsectionsdescribehowtosetupeachofthesecomponents.

DeclaringanAppWidgetintheManifest

First,declaretheAppWidgetProviderclassinyourapplication'

sAndroidManifest.xmlfile.Forexample:

<

receiverandroid:

name="

ExampleAppWidgetProvider"

>

<

intent-filter>

actionandroid:

android.appwidget.action.APPWIDGET_UPDATE"

/>

/intent-filter>

meta-dataandroid:

android.appwidget.provider"

android:

resource="

@xml/example_appwidget_info"

/receiver>

The<

receiver>

elementrequirestheandroid:

nameattribute,whichspecifiestheAppWidgetProviderusedbytheAppWidget.

elementmustincludean<

action>

elementwiththeandroid:

nameattribute.ThisattributespecifiesthattheAppWidgetProvideracceptstheACTION_APPWIDGET_UPDATEbroadcast.Thisistheonlybroadcastthatyoumustexplicitlydeclare.TheAppWidgetManagerautomaticallysendsallotherAppWidgetbroadcaststotheAppWidgetProviderasnecessary.

meta-data>

elementspecifiestheAppWidgetProviderInforesourceandrequiresthefollowingattributes:

•android:

name-Specifiesthemetadataname.Useandroid.appwidget.providertoidentifythedataastheAppWidgetProviderInfodescriptor.

resource-SpecifiestheAppWidgetProviderInforesourcelocation.

AddingtheAppWidgetProviderInfoMetadata

TheAppWidgetProviderInfodefinestheessentialqualitiesofanAppWidget,suchasitsminimumlayoutdimensions,itsinitiallayoutresource,howoftentoupdatetheAppWidget,and(optionally)aconfigurationActivitytolaunchatcreate-time.DefinetheAppWidgetProviderInfoobjectinanXMLresourceusingasingle<

appwidget-provider>

elementandsaveitintheproject'

sres/xml/folder.

Forexample:

appwidget-providerxmlns:

android="

minWidth="

294dp"

!

--density-independentpixels-->

minHeight="

72dp"

updatePeriodMillis="

86400000"

--onceperday-->

initialLayout="

@layout/example_appwidget"

configure="

com.example.android.ExampleAppWidgetConfigure"

/appwidget-provider>

Here'

sasummaryofthe<

attributes:

•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).

SeetheAppWidgetProviderInfoclassformoreinformationontheattributesacceptedbythe<

element.

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

YoumustdeclareyourAppWidgetProviderclassimplementationasabroadcastreceiverusingthe<

elementintheAndroidManifest(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.

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

ThemostimportantAppWidgetProvidercallbackisonUpdated()becauseitiscalledwheneachAppWidgetisaddedtoahost(unlessyouuseaconfigurationActivity).IfyourAppWidgetacceptsanyuserinteraction

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

当前位置:首页 > 幼儿教育 > 育儿理论经验

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

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