需要仿照ios时钟界面,android系统中实现,首先分析android系统应用DeskClock
分析方法,首先分析AndroidManifest文件
分析AosDeskClock AndroidManifest.xml文件
<application android:label=”@string/app_label”
android:icon=”@mipmap/ic_launcher_alarmclock”
android:requiredForAllUsers=”true”
android:supportsRtl=”true”>
application层级 设置了label icon supportsRtl
以及 android:requiredForAllUsers=”true”——此句意义不明确
<activity android:name=”DeskClock”
android:label=”@string/app_label”
android:theme=”@style/DeskClock”
android:icon=”@mipmap/ic_launcher_alarmclock”
android:launchMode=”singleTask”
android:screenOrientation=”portrait”
android:windowSoftInputMode=”adjustNothing”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
第一个activity name DeskClock 桌面时钟,与整个application有相同的label,theme 主题风格,应该是设置字体颜色等,icon图标,activity的launchmode singletask,screenOrientation,竖直方向,windowsoftinputmode,此属性用来协调虚拟键盘弹出的显示情况,此属性有待研究
还适配了一个intent-filter action category已经给出,应该是用于外部启动这个activity
<activity-alias android:name=”DockClock”
android:targetActivity=”DeskClock”
android:label=”@string/app_label”
android:theme=”@style/DeskClock”
android:icon=”@mipmap/ic_launcher_alarmclock”
android:launchMode=”singleTask”
android:enabled=”@bool/config_dockAppEnabled”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.DESK_DOCK” />
</intent-filter>
</activity-alias>
一个activity-alias层级 activity-alias通过指定targetActivity来决定入口相连接的activity,给该程序更改一个不同的label和icon,两个图标进入同一个activity
<activity android:name=”SettingsActivity”
android:label=”@string/settings”
android:theme=”@style/Theme.Settings”
android:taskAffinity=””
android:excludeFromRecents=”true”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>
第二个activity name SettingsActivity 有一个label,theme,taskAffinity空, android:excludeFromRecents控制在不在recent列表中显示。true时不显示;false显示,默认。运行如下activity后,不会显示在recent列表中。依然有意个intent-filter
<activity android:name=”AgoldSetAlarmAcitivity”
android:label=”@string/settings”
android:theme=”@style/SettingsTheme”
android:taskAffinity=””
android:excludeFromRecents=”true”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>
第三个activity, name AgoldSetAlarmActivity,有一个lable,theme,taskAffinity为空,依然不显示在最近列表中,适配一个filter 其中只含有一个action
<activity android:name=”.worldclock.CitiesActivity”
android:label=”@string/cities_activity_title”
android:theme=”@style/CitiesTheme”
android:taskAffinity=””
android:excludeFromRecents=”true”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>
第四个activity 名称 .worldclock.CitiesActivity 有一个lable,theme,taskAffinity为空,依然不显示在最近列表中,适配一个filter 其中只含有一个action
<activity android:name=”.alarms.AlarmActivity”
android:taskAffinity=””
android:excludeFromRecents=”true”
android:theme=”@style/AlarmAlertFullScreenTheme”
android:windowSoftInputMode=”stateAlwaysHidden”
android:showOnLockScreen=”true”
android:configChanges=”orientation|screenSize|keyboardHidden|keyboard|navigation”/>
第五个activity name .alarms.AlarmActivity ,android:showOnLockScreen=”true”根据这个基本可以判断是闹钟显示界面, android:configChanges,定义属性时会去重新调用各个activity的各个生命周期
<activity android:name=”ScreensaverActivity”
android:excludeFromRecents=”true”
android:taskAffinity=””
android:theme=”@style/ScreensaverActivityTheme”
android:configChanges=”orientation|screenSize|keyboardHidden|keyboard” />
第六个activity name ScreensaverActivity 通过名称判断是一个截屏activity,设置了configChanges,
<activity android:name=”HandleApiCalls”
android:theme=”@android:style/Theme.NoDisplay”
android:excludeFromRecents=”true”
android:permission=”com.android.alarm.permission.SET_ALARM”>
<intent-filter>
<action android:name=”android.intent.action.SET_ALARM” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
<intent-filter>
<action android:name=”android.intent.action.SHOW_ALARMS” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
<intent-filter>
<action android:name=”android.intent.action.SET_TIMER” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
</activity>
第七个activity name HandleApiCalls,此activity设置了三个intent-filter,此activity待查看具体作用
<activity-alias android:name=”HandleSetAlarm”
android:targetActivity=”.HandleApiCalls”
android:exported=”true”>
</activity-alias>
第七个activitys的alias
<!– Settings activity for screensaver –>
<activity android:name=”.ScreensaverSettingsActivity”
android:label=”@string/screensaver_settings”
android:theme=”@android:style/Theme.Holo.Light”
android:taskAffinity=””
android:excludeFromRecents=”true”
android:exported=”true”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>
第八个activity name .ScreensaverSettingsActivity android:exported 代表是否支持其它应用调用当前组件。默认值:如果包含有intent-filter 默认值为true; 没有intent-filter默认值为false。
<!– This activity is basically like the TimerFragment in DeskClock
but only during lock screen
so that is only has the fired timers –>
<activity android:name=”com.android.deskclock.timer.TimerAlertFullScreen”
android:excludeFromRecents=”true”
android:theme=”@style/AlarmAlertFullScreenTheme”
android:launchMode=”singleInstance”
android:showOnLockScreen=”true”
android:taskAffinity=””
android:configChanges=”orientation|screenSize|keyboardHidden|keyboard|navigation”/>
第九个activity name com.android.deskclock.timer.TimerAlertFullScreen 这个activity就像是时钟里面的timerFragement 但是仅仅在锁屏上出现
<receiver android:name=”.alarms.AlarmStateManager”
android:exported=”false”>
</receiver>
第一个receiver
<receiver android:name=”.PackageDataClearedReceiver”
android:exported=”false”>
<intent-filter>
<action android:name=”com.mediatek.intent.action.SETTINGS_PACKAGE_DATA_CLEARED” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
<intent-filter>
<action android:name=”android.intent.action.LOCALE_CHANGED” />
</intent-filter>
</receiver>
第二个receiver
<receiver android:name=”AlarmInitReceiver”>
<intent-filter>
<action android:name=”android.intent.action.BOOT_COMPLETED” />
<action android:name=”android.intent.action.TIME_SET” />
<action android:name=”android.intent.action.TIMEZONE_CHANGED” />
<action android:name=”android.intent.action.LOCALE_CHANGED” />
</intent-filter>
<intent-filter android:priority=”100″>
<action android:name=”android.intent.action.ACTION_BOOT_IPO” />
</intent-filter>
</receiver>
第三个receiver
<receiver android:name=”com.android.alarmclock.AnalogAppWidgetProvider” android:label=”@string/analog_gadget”
android:icon=”@mipmap/ic_launcher_alarmclock”>
<intent-filter>
<action android:name=”android.appwidget.action.APPWIDGET_UPDATE” />
</intent-filter>
<meta-data android:name=”android.appwidget.oldName” android:value=”com.android.deskclock.AnalogAppWidgetProvider” />
<meta-data android:name=”android.appwidget.provider” android:resource=”@xml/analog_appwidget” />
</receiver>
第四个receiver
<receiver android:name=”com.android.alarmclock.DigitalAppWidgetProvider” android:label=”@string/digital_gadget”
android:icon=”@mipmap/ic_launcher_alarmclock”>
<intent-filter>
<action android:name=”android.appwidget.action.APPWIDGET_UPDATE” />
<action android:name=”com.android.deskclock.ON_QUARTER_HOUR” />
<action android:name=”android.intent.action.DATE_CHANGED” />
<action android:name=”android.intent.action.TIMEZONE_CHANGED” />
<action android:name=”android.intent.action.SCREEN_ON” />
<action android:name=”android.intent.action.TIME_SET” />
<action android:name=”android.intent.action.LOCALE_CHANGED” />
<action android:name=”android.intent.action.ALARM_CHANGED” />
<action android:name=”android.app.action.NEXT_ALARM_CLOCK_CHANGED” />
<action android:name=”com.android.deskclock.worldclock.update” />
</intent-filter>
<meta-data android:name=”android.appwidget.provider” android:resource=”@xml/digital_appwidget” />
</receiver>
第五个receiver
<receiver android:name=”com.android.alarmclock.DigitalWidgetViewsFactory”
android:exported=”false” />
第六个receiver
<receiver android:name=”com.android.deskclock.timer.TimerReceiver”
android:exported=”false”>
<intent-filter>
<action android:name=”start_timer” />
<action android:name=”delete_timer” />
<action android:name=”times_up” />
<action android:name=”timer_stop” />
<action android:name=”timer_reset” />
<action android:name=”timer_done” />
<action android:name=”timer_update” />
<action android:name=”notif_in_use_show” />
<action android:name=”notif_in_use_cancel” />
<action android:name=”notif_times_up_stop” />
<action android:name=”notif_times_up_plus_one” />
<action android:name=”notif_times_up_show” />
<action android:name=”notif_times_up_cancel” />
<action android:name=”android.intent.action.ACTION_PRE_SHUTDOWN” />
</intent-filter>
</receiver>
第七个receiver
<service android:name=”.alarms.AlarmService”>
<intent-filter>
<action android:name=”com.android.deskclock.START_ALARM” />
</intent-filter>
</service>
第一个service 目测是闹钟服务
<service android:name=”com.android.alarmclock.DigitalAppWidgetService”
android:permission=”android.permission.BIND_REMOTEVIEWS”
android:exported=”false” />
第二个service 数字时钟控件服务
<!– Dream (screensaver) implementation –>
<service android:name=”Screensaver”
android:exported=”true”
android:label=”@string/app_label”
android:permission=”android.permission.BIND_DREAM_SERVICE”>
<intent-filter>
<action android:name=”android.service.dreams.DreamService” />
<action android:name=”android.app.action.NEXT_ALARM_CLOCK_CHANGED” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
<meta-data
android:name=”android.service.dream”
android:resource=”@xml/dream_info” />
</service>
第三个services name Screensaver
<service android:name=”TimerRingService”
android:exported=”false”
android:description=”@string/timer_ring_service_desc”>
<intent-filter>
<action android:name=”com.android.deskclock.TIMER_ALERT” />
</intent-filter>
</service>
第四个services 计时器响铃服务
<service android:name=”com.android.deskclock.stopwatch.StopwatchService”
android:exported=”false”
android:description=”@string/stopwatch_service_desc”>
<intent-filter>
<action android:name=”start_stopwatch” />
<action android:name=”lap_stopwatch” />
<action android:name=”stop_stopwatch” />
<action android:name=”reset_stopwatch” />
<action android:name=”share_stopwatch” />
</intent-filter>
</service>
第五个services 秒表
<provider android:name=”.provider.ClockProvider”
android:authorities=”com.android.deskclock”
android:exported=”false” />
第一个provider
整个AndroidManifest.xml文件中,含有9个activity,7个receiver,5个service,1个provider, 将这些组件去逐步了解deskclock
分析过程中,遇到了很多xml不同层级属性问题,有些甚至都无法百度到相关信息,感受到Google的重要性。