一般android的解锁界面 滑环只有2个方向 怎么增加多个方向多个功能呢.
在 frameworks\base\policy\src\com\android\internal\policy\impl\LockScreen.java
onTrigger里做如下修改:
public void onTrigger(View v, int target) {
if (target == 0) { // 0 = unlock/portrait, 1 = unlock/landscape
mCallback.goToUnlockScreen();
}
else if(target == 1)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else if(target == 2)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.email", "com.android.email.activity.Welcome"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else if(target == 3)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else if (target == 4) { // 2 = alt/portrait, 3 = alt/landscape
if (!mCameraDisabled) {
// Start the Camera (Gallery)
// Intent intent = new Intent();
// intent.setComponent(new ComponentName("com.android.gallery3d", "com.android.gallery3d.app.Gallery"));
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// mContext.startActivity(intent);
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
}
else if(target == 5)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.gallery3d", "com.android.gallery3d.app.Gallery"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else if(target == 6)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.music", "com.android.music.MusicBrowserActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else if(target == 7)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.vending", "com.android.vending.AssetBrowserActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
mCallback.goToUnlockScreen();
}
else {
toggleRingMode();
mUnlockWidgetMethods.updateResources();
mCallback.pokeWakelock();
}
}
八个方向对应八个功能
在 frameworks\base\core\res\res\values\arrays.xml里
<array name="lockscreen_targets_with_camera">
<item>@drawable/ic_lockscreen_unlock</item>
<item>@drawable/ic_lockscreen_browser</item>
<item>@drawable/ic_lockscreen_email</item>
<item>@drawable/ic_lockscreen_maps</item>
<item>@drawable/ic_lockscreen_camera</item>
<item>@drawable/ic_lockscreen_gallery3d</item>
<item>@drawable/ic_lockscreen_music</item>
<item>@drawable/ic_lockscreen_playstore</item>
</array>
各个方向的图标配置
frameworks\base\core\res\res\values-sw600dp-land\arrays.xml里
这样就可以实现功能