Quick Settings增加一項

XXX device要求在quick settings中增加一項touch panel.

<!-- The default tiles to display in QuickSettings --&gt;
    <string name="quick_settings_tiles_default" translatable="false"&gt;
        wifi,bt,dnd,touchpanel,flashlight,rotation,battery,cell,airplane,cast
    </string&gt;
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&gt; {
    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;
    @Inject
    public TouchPanelTile(QSHost host) {
        super(host);
        qsHost = host;
    }

    @Override
    public BooleanState newTileState() {
        return new BooleanState();
    }

    @Override
    protected 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);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) { //下拉quick setting時調用
        if (isHandleClick) {
            …..
        } else {
            try {
                String mode = SystemProperties.get(PERSIST_KEY_PROP_TOUCH_MODE);
                ……
                    //state.labe 設置顯示title
                    state.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);
    }

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.QS_TOUCHPANEL;
    }

    @Override
    public Intent getLongClickIntent() { //長按顯示界面
        return new Intent(Settings.ACTION_DISPLAY_SETTINGS);
    }

  ...
    @Override
    public 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);
    }
}
// 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_SETTINGS
    QS_TOUCHPANEL = 1751;
@@ -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();
         }

原文地址:https://blog.csdn.net/Leif_dong/article/details/134597364

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_#ID#.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注