https://www.cnblogs.com/joy99/p/6269946.html
一.android5.1 源码
1.1.ANDROID5.1frameworksasepackagesSystemUIsrccomandroidsystemuistatusbarphoneQSTileHost.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.1frameworksasepackagesSystemUI esvaluesconfig.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>