launcher修改--获取widget信息(图片,文字等)(源码追踪)

  次阅读 来源:互联网(转载协议) 2015-10-03 10:39 我要评论(0)

在launcher中,长按屏幕,图挂了,我们在代码里面找一下:

首先,找到onLongClick(View v)方法,然后在这个方法中,有如下代码

if (mWorkspace.allowLongPress()) {

if (cellInfo.cell == null) {

if (cellInfo.valid) {

// User long pressed on empty space

mWorkspace.setAllowLongPress(false);

showAddDialog(cellInfo);

}

} else {

if (!(cellInfo.cell instanceof Folder)) {

// User long pressed on an item

mWorkspace.startDrag(cellInfo);

}

}

}

然后,继续追踪showAddDialog()方法:

private void showAddDialog(CellLayout.CellInfo cellInfo) {

mAddItemCellInfo = cellInfo;

mWaitingForResult = true;

showDialog(DIALOG_CREATE_SHORTCUT);

}

继 续找showDialog,没什么发现,showDialog()方法是该类父类Activity()方法,携带参数 DIALOG_CREATE_SHORTCUT,但是它最后是调用的Launcher.java的onCreateDialog(int id)这个方法:

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case DIALOG_CREATE_SHORTCUT:

return new CreateShortcut().createDialog();

在这里,使用了CreateShortcut.createDialog()方法,在源代码的2708行:

private class CreateShortcut implements DialogInterface.OnClickListener,

DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, DialogInterface.OnShowListener { private AddAdapter mAdapter; Dialog createDialog() { mWaitingForResult = true; mAdapter = new AddAdapter(Launcher.this); final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); builder.setTitle(getString(R.string.menu_item_add_item)); builder.setAdapter(mAdapter, this); builder.setInverseBackgroundForced(true); AlertDialog dialog = builder.create(); dialog.setOnCancelListener(this); dialog.setOnDismissListener(this); dialog.setOnShowListener(this); return dialog; } public void onCancel(DialogInterface dialog) { mWaitingForResult = false; cleanup(); } public void onDismiss(DialogInterface dialog) { mWorkspace.unlock(); } private void cleanup() { mWorkspace.unlock(); dismissDialog(DIALOG_CREATE_SHORTCUT); } /** * Handle the action clicked in the "Add to home" dialog. */ public void onClick(DialogInterface dialog, int which) { Resources res = getResources(); cleanup(); switch (which) { case AddAdapter.ITEM_SHORTCUT: { // Insert extra item to handle picking application pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut); break; } case AddAdapter.ITEM_APPWIDGET: { int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // add the search widget ArrayList<AppWidgetProviderInfo> customInfo = new ArrayList<AppWidgetProviderInfo>(); AppWidgetProviderInfo info = new AppWidgetProviderInfo(); info.provider = new ComponentName(getPackageName(), "XXX.YYY"); info.label = getString(R.string.group_search); info.icon = R.drawable.ic_search_widget; customInfo.add(info); pickIntent.putParcelableArrayListExtra( AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo); ArrayList<Bundle> customExtras = new ArrayList<Bundle>(); Bundle b = new Bundle(); b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET); customExtras.add(b); pickIntent.putParcelableArrayListExtra( AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras); // start the pick activity startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); break; } case AddAdapter.ITEM_LIVE_FOLDER: { // Insert extra item to handle inserting folder Bundle bundle = new Bundle(); ArrayList<String> shortcutNames = new ArrayList<String>(); shortcutNames.add(res.getString(R.string.group_folder)); bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, R.drawable.ic_launcher_folder)); bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_live_folder)); pickIntent.putExtras(bundle); startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); break; } case AddAdapter.ITEM_WALLPAPER: { startWallpaper(); break; } case AddAdapter.ITEM_ANYCUT: { Intent anycutIntent=new Intent(); anycutIntent.setClass(Launcher.this, CustomShirtcutActivity.class); startActivityForResult(anycutIntent, REQUEST_PICK_ANYCUT); break; } } } public void onShow(DialogInterface dialog) { mWorkspace.lock(); } }

本站部分文章来源于网络以及网友投稿,本站只负责对文章进行整理、排版、编辑,是出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。如果您有什么意见或建议,请联系QQ28-1688-302!

人工智能实验室
相关文章相关文章
  • Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平

    Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平

  • 2018深圳国际人工智能展览会 2018 shenzhen International Artif

    2018深圳国际人工智能展览会 2018 shenzhen International Artif

  • teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

    teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

  • Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛

    Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛

网友点评网友点评
阅读推荐阅读推荐

据外媒报道,STEER打造了首款完全自动驾驶停车技术,旨在使常规车辆转变为无人驾驶车辆。STEER的首款技术应用是4级自动驾驶及网络安全停车...

近日,美国软性机器抓手制造商 Soft Robotics 宣布,获得 2000 万美元的融资,本轮投资者包括 Scale Venture Partners,Calibrate Ventures...

据外媒报道,加州车管局发布了《2017自动驾驶脱离报告(California Autonomous Vehicle Disengagement Reports)》,其中谈及了脱离的具体...

用人机语音交互,来解决智能家居适老的问题;通过家庭门禁与安防套件、空气净化套件、可燃气体与有害气体监控套件等相互联动,在不同生活情...