本文主要是介绍Android frameworks 开发总结之八,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Quick Settings增加一項
XXX device要求在quick settings中增加一項touch panel.
-
在/frameworks/base/packages/SystemUI/res/values/config.xml文件中的quick_settings_tiles_default string 中增加touch panel。並在String resource文件中增加顯示的title
<!-- The default tiles to display in QuickSettings --><string name="quick_settings_tiles_default" translatable="false">wifi,bt,dnd,touchpanel,flashlight,rotation,battery,cell,airplane,cast</string>
-
在frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles 下增加TouchPanelTile.java文件.
package com.android.systemui.qs.tiles;import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.os.SystemProperties;import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.qs.QSHost;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.plugins.qs.QSTile.BooleanState;import javax.inject.Inject;/**/** Quick settings tile: Touch Panel **/
public class TouchPanelTile extends QSTileImpl<BooleanState> {private static final String PERSIST_KEY_PROP_TOUCH_MODE = "persist.sys.touch_mode";private static final int TOUCH_MODE_PROPERTY_FINGER = 0;private static final int TOUCH_MODE_PROPERTY_STYLUS = 1;private static final int TOUCH_MODE_PROPERTY_GLOVE = 2;private static final String TOUCH_MODE_FINGER = "finger";private static final String TOUCH_MODE_STYLUS = "stylus";private static final String TOUCH_MODE_GLOVE = "glove";private int mTouchPanelMode = 0;private QSHost qsHost;private boolean isHandleClick = false;@Injectpublic TouchPanelTile(QSHost host) {super(host);qsHost = host;}@Overridepublic BooleanState newTileState() {return new BooleanState();}@Overrideprotected void handleClick() {mTouchPanelMode ++; //在quick setting中點擊時調用if(mTouchPanelMode > TOUCH_MODE_PROPERTY_GLOVE){mTouchPanelMode = TOUCH_MODE_PROPERTY_FINGER;}updateTouchMode(mTouchPanelMode);isHandleClick = true;refreshState();Log.i("WKS1","TouchPanelTile -> handleClick: mTouchPanelMode = " + mTouchPanelMode);}@Overrideprotected void handleUpdateState(BooleanState state, Object arg) { //下拉quick setting時調用if (isHandleClick) {…..} else {try {String mode = SystemProperties.get(PERSIST_KEY_PROP_TOUCH_MODE);……//state.labe 設置顯示titlestate.label = mContext.getString(R.string.quick_settings_touch_panel_stylus);}Log.i("WKS1", "TouchPanelTile -> handleUpdateState: mode = " + mode);} catch (NumberFormatException e) {Log.e(TAG, "could not get touch mode", e);}}isHandleClick = false;state.icon = ResourceIcon.get(R.drawable.ic_qs_bluetooth_on);Log.i("WKS1","TouchPanelTile -> handleUpdateState: state.value = " + state.value);Log.i("WKS1","TouchPanelTile -> handleUpdateState: mTouchPanelMode = " + mTouchPanelMode);}@Overridepublic int getMetricsCategory() {return MetricsEvent.QS_TOUCHPANEL;}@Overridepublic Intent getLongClickIntent() { //長按顯示界面return new Intent(Settings.ACTION_DISPLAY_SETTINGS);}...@Overridepublic CharSequence getTileLabel() {if (mTouchPanelMode == TOUCH_MODE_PROPERTY_FINGER) {return mContext.getString(R.string.quick_settings_touch_panel_finger);} else if (mTouchPanelMode == TOUCH_MODE_PROPERTY_GLOVE) {return mContext.getString(R.string.quick_settings_touch_panel_glove);} else {return mContext.getString(R.string.quick_settings_touch_panel_stylus);}}private void updateTouchMode(int mode){//SystemUI 中使用SystemProperties.set提示設置失敗,使用settings數據監聽方式 Settings.System.putInt(qsHost.getContext().getContentResolver(),Settings.System.TOUCH_PANEL_MODE,mode);}
}
-
在frameworks/base/proto/src/metrics_constants/metrics_constants.proto 文件中增加 MetricsEvent.QS_TOUCHPANEL
// OPEN: QS Touch Panel tile shown// ACTION: QS Touch Panel tile tapped// SUBTYPE: 0 is off, 1 is finger, 2 is glove, 3 is stylus// CATEGORY: QUICK_SETTINGSQS_TOUCHPANEL = 1751;
-
在frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java 文件中實現
@@ -46,6 +46,7 @@ import com.android.systemui.qs.tiles.UserTile;import com.android.systemui.qs.tiles.WifiTile;import com.android.systemui.qs.tiles.WorkModeTile;import com.android.systemui.util.leak.GarbageMonitor;
+import com.android.systemui.qs.tiles.TouchPanelTile;import javax.inject.Inject;import javax.inject.Provider;
@@ -75,6 +76,7 @@ public class QSFactoryImpl implements QSFactory {private final Provider<NfcTile> mNfcTileProvider;private final Provider<GarbageMonitor.MemoryTile> mMemoryTileProvider;private final Provider<UiModeNightTile> mUiModeNightTileProvider;
+ private final Provider<TouchPanelTile> mTouchPanelProvider;private QSTileHost mHost;@@ -97,7 +99,8 @@ public class QSFactoryImpl implements QSFactory {Provider<NightDisplayTile> nightDisplayTileProvider,Provider<NfcTile> nfcTileProvider,Provider<GarbageMonitor.MemoryTile> memoryTileProvider,
- Provider<UiModeNightTile> uiModeNightTileProvider) {
+ Provider<UiModeNightTile> uiModeNightTileProvider,
+ Provider<TouchPanelTile> TouchPanelTileProvider) {mWifiTileProvider = wifiTileProvider;mBluetoothTileProvider = bluetoothTileProvider;mCellularTileProvider = cellularTileProvider;
@@ -117,6 +120,7 @@ public class QSFactoryImpl implements QSFactory {mNfcTileProvider = nfcTileProvider;mMemoryTileProvider = memoryTileProvider;mUiModeNightTileProvider = uiModeNightTileProvider;
+ mTouchPanelProvider = TouchPanelTileProvider;}public void setHost(QSTileHost host) {
@@ -170,6 +174,8 @@ public class QSFactoryImpl implements QSFactory {return mNfcTileProvider.get();case "dark":return mUiModeNightTileProvider.get();
+ case "touchpanel":
+ return mTouchPanelProvider.get();}
这篇关于Android frameworks 开发总结之八的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!