1. android 4.0增加解锁目标
1.1资源文件
framework/base/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml或者keyguard_screen_tab_unlock_land.xml
//关键view
<com.android.internal.widget.multiwaveview.MultiWaveView
android:id="@+id/unlock_widget" //id
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:targetDrawables="@array/lockscreen_targets_with_camera" <!-- 解锁目标数组 -->
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera" <!-- 描述-->
android:directionDescriptions="@array/lockscreen_direction_descriptions" <!-- 位置描述 -->
android:handleDrawable="@drawable/ic_lockscreen_handle" <!--中间解锁hanlder -->
android:waveDrawable="@drawable/ic_lockscreen_outerring" <!-- 绘制椭圆范围 -->
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
android:snapMargin="@dimen/multiwaveview_snap_margin"
android:hitRadius="@dimen/multiwaveview_hit_radius"
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right" <!-- 未解锁产生的波澜 -->
android:horizontalOffset="0dip"
android:verticalOffset="60dip"
android:feedbackCount="3" //多少次波澜
android:vibrationDuration="20" //触觉反馈,震动.0表示不震动
/>
//解锁目标资源集合,以逆时针方向显示在椭圆解锁边缘上。
framework/base/core/res/res/ values-sw600dp-land/arrays.xml
默认采用的是lockscreen_targets_with_camera,lockscreen_target_descriptions_with_camera是资源描述
<array name="lockscreen_targets_with_camera">
<item>@drawable/ic_lockscreen_unlock</item> //这个是0,到时对应MultiWaveViewMethods.onTrigger的 int target参数,用于解锁后的跳转的程序
<item>@null</item> //1
<item>@drawable/ic_lockscreen_camera</item> // 2
<item>@null</item> // 3
</array>
<array name="lockscreen_target_descriptions_with_camera">
<item>@string/description_target_unlock</item>
<item>@null</item>
<item>@string/description_target_camera</item>
<item>@null</item>
</array>
1.1 主要java文件
LockScreen.java的构造函数初始化布局,加载解锁相关信息(图片解锁,波澜解锁方式)
LockScreen(Context context, Configuration configuration, LockPatternUtils lockPatternUtils,
KeyguardUpdateMonitor updateMonitor,
KeyguardScreenCallback callback) {
//判断横竖屏
if (mCreationOrientation != Configuration.ORIENTATION_LANDSCAPE) {
inflater.inflate(R.layout.keyguard_screen_tab_unlock, this, true);
} else {
inflater.inflate(R.layout.keyguard_screen_tab_unlock_land, this, true);
}
mUnlockWidget = findViewById(R.id.unlock_widget); //实际获取的是一个com.android.internal.widget.multiwaveview.MultiWaveView
//2.3的滑动解锁
if (mUnlockWidget instanceof SlidingTab) {
SlidingTab slidingTabView = (SlidingTab) mUnlockWidget;
slidingTabView.setHoldAfterTrigger(true, false);
slidingTabView.setLeftHintText(R.string.lockscreen_unlock_label);
slidingTabView.setLeftTabResources(
R.drawable.ic_jog_dial_unlock,
R.drawable.jog_tab_target_green,
R.drawable.jog_tab_bar_left_unlock,
R.drawable.jog_tab_left_unlock);
SlidingTabMethods slidingTabMethods = new SlidingTabMethods(slidingTabView);
slidingTabView.setOnTriggerListener(slidingTabMethods);
mUnlockWidgetMethods = slidingTabMethods;
}
//波纹解锁
else if (mUnlockWidget instanceof WaveView) {
WaveView waveView = (WaveView) mUnlockWidget;
WaveViewMethods waveViewMethods = new WaveViewMethods(waveView);
waveView.setOnTriggerListener(waveViewMethods);
mUnlockWidgetMethods = waveViewMethods;
}
// 4.0 默认解锁
else if (mUnlockWidget instanceof MultiWaveView) {
MultiWaveView multiWaveView = (MultiWaveView) mUnlockWidget;
MultiWaveViewMethods multiWaveViewMethods = new MultiWaveViewMethods(multiWaveView);
multiWaveView.setOnTriggerListener(multiWaveViewMethods);
mUnlockWidgetMethods = multiWaveViewMethods;
} else {
throw new IllegalStateException("Unrecognized unlock widget: " + mUnlockWidget);
}
mUnlockWidgetMethods.updateResources(); //更新资源,这个是一个多态提醒,实际对象是MultiWaveViewMethods,那么应该调用的是MultiWaveViewMethods的updateResources方法
}
1.2
MultiWaveViewMethods重点是两个方法
updateResources更新解锁目标资源
onTrigger解锁成功后的处理
1.1资源文件
framework/base/core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml或者keyguard_screen_tab_unlock_land.xml
//关键view
<com.android.internal.widget.multiwaveview.MultiWaveView
android:id="@+id/unlock_widget" //id
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:targetDrawables="@array/lockscreen_targets_with_camera" <!-- 解锁目标数组 -->
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera" <!-- 描述-->
android:directionDescriptions="@array/lockscreen_direction_descriptions" <!-- 位置描述 -->
android:handleDrawable="@drawable/ic_lockscreen_handle" <!--中间解锁hanlder -->
android:waveDrawable="@drawable/ic_lockscreen_outerring" <!-- 绘制椭圆范围 -->
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
android:snapMargin="@dimen/multiwaveview_snap_margin"
android:hitRadius="@dimen/multiwaveview_hit_radius"
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right" <!-- 未解锁产生的波澜 -->
android:horizontalOffset="0dip"
android:verticalOffset="60dip"
android:feedbackCount="3" //多少次波澜
android:vibrationDuration="20" //触觉反馈,震动.0表示不震动
/>
//解锁目标资源集合,以逆时针方向显示在椭圆解锁边缘上。
framework/base/core/res/res/ values-sw600dp-land/arrays.xml
默认采用的是lockscreen_targets_with_camera,lockscreen_target_descriptions_with_camera是资源描述
<array name="lockscreen_targets_with_camera">
<item>@drawable/ic_lockscreen_unlock</item> //这个是0,到时对应MultiWaveViewMethods.onTrigger的 int target参数,用于解锁后的跳转的程序
<item>@null</item> //1
<item>@drawable/ic_lockscreen_camera</item> // 2
<item>@null</item> // 3
</array>
<array name="lockscreen_target_descriptions_with_camera">
<item>@string/description_target_unlock</item>
<item>@null</item>
<item>@string/description_target_camera</item>
<item>@null</item>
</array>
1.1 主要java文件
LockScreen.java的构造函数初始化布局,加载解锁相关信息(图片解锁,波澜解锁方式)
LockScreen(Context context, Configuration configuration, LockPatternUtils lockPatternUtils,
KeyguardUpdateMonitor updateMonitor,
KeyguardScreenCallback callback) {
//判断横竖屏
if (mCreationOrientation != Configuration.ORIENTATION_LANDSCAPE) {
inflater.inflate(R.layout.keyguard_screen_tab_unlock, this, true);
} else {
inflater.inflate(R.layout.keyguard_screen_tab_unlock_land, this, true);
}
mUnlockWidget = findViewById(R.id.unlock_widget); //实际获取的是一个com.android.internal.widget.multiwaveview.MultiWaveView
//2.3的滑动解锁
if (mUnlockWidget instanceof SlidingTab) {
SlidingTab slidingTabView = (SlidingTab) mUnlockWidget;
slidingTabView.setHoldAfterTrigger(true, false);
slidingTabView.setLeftHintText(R.string.lockscreen_unlock_label);
slidingTabView.setLeftTabResources(
R.drawable.ic_jog_dial_unlock,
R.drawable.jog_tab_target_green,
R.drawable.jog_tab_bar_left_unlock,
R.drawable.jog_tab_left_unlock);
SlidingTabMethods slidingTabMethods = new SlidingTabMethods(slidingTabView);
slidingTabView.setOnTriggerListener(slidingTabMethods);
mUnlockWidgetMethods = slidingTabMethods;
}
//波纹解锁
else if (mUnlockWidget instanceof WaveView) {
WaveView waveView = (WaveView) mUnlockWidget;
WaveViewMethods waveViewMethods = new WaveViewMethods(waveView);
waveView.setOnTriggerListener(waveViewMethods);
mUnlockWidgetMethods = waveViewMethods;
}
// 4.0 默认解锁
else if (mUnlockWidget instanceof MultiWaveView) {
MultiWaveView multiWaveView = (MultiWaveView) mUnlockWidget;
MultiWaveViewMethods multiWaveViewMethods = new MultiWaveViewMethods(multiWaveView);
multiWaveView.setOnTriggerListener(multiWaveViewMethods);
mUnlockWidgetMethods = multiWaveViewMethods;
} else {
throw new IllegalStateException("Unrecognized unlock widget: " + mUnlockWidget);
}
mUnlockWidgetMethods.updateResources(); //更新资源,这个是一个多态提醒,实际对象是MultiWaveViewMethods,那么应该调用的是MultiWaveViewMethods的updateResources方法
}
1.2
MultiWaveViewMethods重点是两个方法
updateResources更新解锁目标资源
onTrigger解锁成功后的处理