介绍
因之前客户需求将settings加密了但一些WiFi还有热点的功能开启还可以通过长按settings的入口添加,客户想要长按settings什么快捷方式也不弹。
这里我们分析Launcher3的SystemShortcutFactory.java可以看出长按图标时的弹框加载是在getEnabledShortcuts此方法中,那么我只要找出settings对应的viewID跳过即可不弹框
路径:packages/apps/Launcher3/src/com/android/launcher3/popup/SystemShortcutFactory.java
此处打log抓到settings的id为5
public @NonNull List<SystemShortcut> getEnabledShortcuts(Launcher launcher, ItemInfo info) {
List<SystemShortcut> systemShortcuts = new ArrayList<>();
for (SystemShortcut systemShortcut : mAllShortcuts) {
//*/soda water.20230917 Screen Settings long press the screen
if(info.getViewId()==5){
Log.d("soda water","systemShortcut = "+systemShortcut.toString());
continue;
}
//*/
if (systemShortcut.getOnClickListener(launcher, info) != null) {
systemShortcuts.add(systemShortcut);
}
}
return systemShortcuts;
}
上面的代码执行完我们长按拖动图标时会发现图标加载出现了问题应该是拖拽后没刷新,我们接着看PopupContainerWithArrow里的populateAndShow,我们在其中限制快捷方式长度为零的执行下reorderAndShow即可
路径:packages/apps/Launcher3/src/com/android/launcher3/popup/PopupContainerWithArrow.java
上面将id为5的都跳过添加列表了 所以当找到列表为0的就是我们要屏蔽的 并且加上箭头标志否则长按后文本会消失
@TargetApi(Build.VERSION_CODES.P)
protected void populateAndShow(final BubbleTextView originalIcon, int shortcutCount,
final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) {
mNumNotifications = notificationKeys.size();
mOriginalIcon = originalIcon;
//*/soda water.20230917 Screen Settings long press the screen
if(systemShortcuts.size() == 0){
int viewsToFlip = getChildCount();
reorderAndShow(viewsToFlip);
return;
}
//*/
// Add views
if (mNumNotifications > 0) {
// Add notification entries
View.inflate(getContext(), R.layout.notification_content, this);
mNotificationItemView = new NotificationItemView(this);
if (mNumNotifications == 1) {
mNotificationItemView.removeFooter();
}
updateNotificationHeader();
}