Android5.1 Android7.1 下拉快捷设置面板添加快捷开关、根据型号显示不同配置、quick settings中去掉不需要的图标
https://www.cnblogs.com/joy99/p/6269946.html
一.android5.1 源码
1.1.ANDROID5.1\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\QSTileHost.java
private List<String> loadTileSpecs() { final Resources res = mContext.getResources(); final String defaultTileList = res.getString(R.string.quick_settings_tiles_default); String tileList = Secure.getStringForUser(mContext.getContentResolver(), TILES_SETTING, mUserTracker.getCurrentUserId()); if (tileList == null) { tileList = res.getString(R.string.quick_settings_tiles); if (DEBUG) Log.d(TAG, "Loaded tile specs from config: " + tileList); } else { if (DEBUG) Log.d(TAG, "Loaded tile specs from setting: " + tileList); } final ArrayList<String> tiles = new ArrayList<String>(); boolean addedDefault = false; for (String tile : tileList.split(",")) { tile = tile.trim(); if (tile.isEmpty()) continue; if (tile.equals("default")) { if (!addedDefault) { tiles.addAll(Arrays.asList(defaultTileList.split(","))); addedDefault = true; } } else { tiles.add(tile); } } return tiles; }
1.2.ANDROID5.1\frameworks\base\packages\SystemUI\res\values\config.xml
创建快捷开关时需要按照参数配置文件config.xml来加载快捷开关信息
(1) QSTileHost类在构造函数里调用recreateTiles() 方法; (2) 在recreateTiles() 方法里loadTileSpecs(); (3) loadTileSpecs() 方法里通过mContext.getResources().getString(R.string.quick_settings _tiles_default) 从config.xml中加载快捷开关规 格”quick_settings_tiles_default” 这个配置项便确定了默认情况下快速设定面板上显示哪些开关以及开关的显示顺序; (4) 接下来创建快捷开关createTile() ,通过从config.xml文件中获取的配置信息实例化每个快捷开关; (5) 最后将创建的快捷开关保存在成员变量mTiles列表里,通过调用QSTileHost.getTiles() 可以获取到所有的快捷开关。
二.根据wifi_chip来加载config.xml
private String getWifiNameString(String path) { String defString = "AP6181"; try { @SuppressWarnings("resource") BufferedReader reader = new BufferedReader(new FileReader(path)); defString = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return defString; } private List<String> loadTileSpecs() { String wifiName = getWifiNameString("/data/wifi_chip"); final Resources res = mContext.getResources(); final String defaultTileList; final String defaultTileList_bt; if (TelephonyManager.getDefault().getPhoneCount() > 1) { defaultTileList = res.getString(R.string.quick_settings_tiles_default_dualsim); defaultTileList_bt = res.getString(R.string.quick_settings_tiles_default_bt_dualsim); } else { defaultTileList = res.getString(R.string.quick_settings_tiles_default); defaultTileList_bt = res.getString(R.string.quick_settings_tiles_default_bt); } String tileList = Secure.getStringForUser(mContext.getContentResolver(), TILES_SETTING, mUserTracker.getCurrentUserId()); if (tileList == null) { tileList = res.getString(R.string.quick_settings_tiles); if (DEBUG) Log.d(TAG, "Loaded tile specs from config: " + tileList); } else { if (DEBUG) Log.d(TAG, "Loaded tile specs from setting: " + tileList); } final ArrayList<String> tiles = new ArrayList<String>(); boolean addedDefault = false; for (String tile : tileList.split(",")) { tile = tile.trim(); if (tile.isEmpty()) continue; if (tile.equals("default")) { if (!addedDefault) { if(wifiName.contains("AP6181") || wifiName.contains("RTL8189FS") || wifiName.contains("RTL8189ES")|| wifiName.contains("RTL8188EU")/*SystemProperties.get("ro.rk.bt_enable", "true").equals("false")*/) tiles.addAll(Arrays.asList(defaultTileList.split(","))); else tiles.addAll(Arrays.asList(defaultTileList_bt.split(","))); addedDefault = true; } } else { tiles.add(tile); } } return tiles; }
config.xml
<!-- The default tiles to display in QuickSettings --> <string name="quick_settings_tiles_default_bt" translatable="false"> wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,hotspot </string> <!-- The default tiles to display in QuickSettings --> <string name="quick_settings_tiles_default" translatable="false"> wifi,inversion,dnd,rotation,location,cast,hotspot </string>
wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,hotspot 分配对应着quick settings中的:wifi开关、bluetooth开关、inversion、cell-sim卡、飞行模式、转屏锁、手电筒、位置信息、cast-wifi屏幕投射、wifi热点
三.隐藏下来快捷设置
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@@ -101,7 +101,7 @@ public class PhoneStatusBarView extends PanelBar { @Override public PanelView selectPanelForTouch(MotionEvent touch) { - final float x = touch.getX(); + /*final float x = touch.getX(); if(mAppBarPanel != null) LOGD("selectPanelForTouch enable="+mAppBarPanel.panelViewEnabled()); if(mAppBarPanel != null && mAppBarPanel.panelViewEnabled()){ @@ -112,7 +112,8 @@ public class PhoneStatusBarView extends PanelBar { // No double swiping. If either panel is open, nothing else can be pulled down. return mNotificationPanel.getExpandedHeight() > 0 ? null - : mNotificationPanel; + : mNotificationPanel;*/ + return null; }
四.Android7.1 下拉快捷设置面板添加快捷开关
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -497,7 +497,7 @@ public class NotificationPanelView extends PanelView implements @Override public void resetViews() { mIsLaunchTransitionFinished = false; - mBlockTouches = false; + mBlockTouches = true; mUnlockIconActive = false; if (!mLaunchingAffordance) { mAfforanceHelper.reset(false);