安卓11 SysteUI添加按钮以及下拉状态栏的色温调节按钮

最近客户想要做一个台灯产品,需要实现 串口调节台灯功能 ,其中包括
亮度调节
色温调节
开关
三个功能
话不多说,贴代码

diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
old mode 100644
new mode 100755
index 17f92ee..71fefa0
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -790,5 +790,8 @@</intent-filter></receiver>+        <service android:name=".junjie.MySerialPortService"
+            android:exported="true"/>
+</application></manifest>
diff --git a/packages/SystemUI/res/drawable/ic_qs_td_button.xml b/packages/SystemUI/res/drawable/ic_qs_td_button.xml
new file mode 100755
index 0000000..8a81bc2
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_td_button.xml
@@ -0,0 +1,18 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"^M
+    android:width="108dp"^M
+    android:height="108dp"^M
+    android:viewportWidth="1024"^M
+    android:viewportHeight="1024">^M
+  <path^M
+      android:fillColor="#FFFFFFFF"^M
+      android:pathData="M4.3,603.5a1.7,1.7 0,0 0,0 -3.4,1.7 1.7,0 0,0 0,3.4zM904.9,560.7a19.9,19.9 0,0 1,-14.9 -6.7l-315.2,-356.5a19.9,19.9 0,1 1,29.9 -26.4l315.2,356.5a19.9,19.9 0,0 1,-14.9 33.1zM684.2,882.9a19.9,19.9 0,0 1,-14.3 -33.8l216.2,-222a19.9,19.9 0,0 1,28.5 27.8l-216.2,222a19.9,19.9 0,0 1,-14.3 6z"/>^M
+  <path^M
+      android:fillColor="#FFFFFFFF"^M
+      android:pathData="M545.9,235.2a19.9,19.9 0,0 1,-13.7 -34.4l60.3,-56.7a60.3,60.3 0,0 0,-82.5 -87.8l-60.3,56.7a19.9,19.9 0,0 1,-27.3 -29l60.3,-56.7a100.1,100.1 0,0 1,137.2 145.9l-60.3,56.7a19.9,19.9 0,0 1,-13.7 5.4z"/>^M
+  <path^M
+      android:fillColor="#FFFFFFFF"^M
+      android:pathData="M482.2,478.3h-0.6a19.9,19.9 0,0 1,-13.9 -6.3L174.9,160.4a19.9,19.9 0,0 1,0.9 -28.2,233.7 233.7,0 0,1 320.1,340.6 19.9,19.9 0,0 1,-13.6 5.4zM218.3,148.4l264.1,281.1a193.9,193.9 0,0 0,-264.1 -281.1zM1001.5,1024h-725.1a19.9,19.9 0,0 1,-19.9 -19.9c0,-88.8 72.3,-161.1 161.1,-161.1h442.9c88.8,0 161.1,72.3 161.1,161.1a19.9,19.9 0,0 1,-19.9 19.9zM297.8,984.2h682a121.8,121.8 0,0 0,-119.5 -101.3h-442.9a121.8,121.8 0,0 0,-119.5 101.3zM926.9,666.5a72.3,72.3 0,1 1,72.3 -72.3,72.4 72.4,0 0,1 -72.3,72.3zM926.9,561.8a32.5,32.5 0,1 0,32.5 32.5,32.5 32.5,0 0,0 -32.5,-32.5z"/>^M
+  <path^M
+      android:fillColor="#FFFFFFFF"^M
+      android:pathData="M321.7,428.5a101.1,101.1 0,0 1,-52.5 -187.6,19.9 19.9,0 1,1 20.7,34.1 61.3,61.3 0,1 0,82.6 86.6,19.9 19.9,0 1,1 33,22.3 101.1,101.1 0,0 1,-83.9 44.6z"/>^M
+</vector>^M
diff --git a/packages/SystemUI/res/layout/brightness_mirror.xml b/packages/SystemUI/res/layout/brightness_mirror.xml
old mode 100644
new mode 100755
index e3440b5..288947e
--- a/packages/SystemUI/res/layout/brightness_mirror.xml
+++ b/packages/SystemUI/res/layout/brightness_mirror.xml
@@ -18,7 +18,7 @@xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/brightness_mirror"android:layout_width="@dimen/qs_panel_width"
-    android:layout_height="@dimen/brightness_mirror_height"
+    android:layout_height="@dimen/brightness_mirror_height1"android:layout_gravity="@integer/notification_panel_layout_gravity"android:visibility="invisible"><FrameLayout
diff --git a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml
old mode 100644
new mode 100755
index 12127f5..039f633
--- a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml
+++ b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml
@@ -17,17 +17,69 @@xmlns:systemui="http://schemas.android.com/apk/res-auto"android:layout_height="wrap_content"android:layout_width="match_parent"
-    android:layout_gravity="center_vertical"
+    android:orientation="vertical"style="@style/BrightnessDialogContainer">+<com.android.systemui.settings.ToggleSliderViewandroid:id="@+id/brightness_slider"
-        android:layout_width="0dp"
-        android:layout_height="48dp"
-        android:layout_gravity="center_vertical"
-        android:layout_weight="1"
+        android:layout_width="match_parent"
+        android:layout_height="40dp"android:contentDescription="@string/accessibility_brightness"android:importantForAccessibility="no"
-        systemui:text="@string/status_bar_settings_auto_brightness_label" />
+        systemui:text="@string/status_bar_settings_auto_brightness_label"
+        android:visibility="gone"/>
+    <!--liujunjie add -->
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="40dp"
+        android:orientation="horizontal">
+        <SeekBar
+            android:layout_width="0dp"
+            android:layout_weight="5"
+            android:layout_height="40dp"
+            android:id="@+id/seekbar3" />
+        <TextView
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:text="@string/str1"
+            android:gravity="center"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="40dp"
+        android:orientation="horizontal">
+        <SeekBar
+            android:layout_width="0dp"
+            android:layout_weight="5"
+            android:layout_height="40dp"
+            android:id="@+id/seekbar1" />
+        <TextView
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:text="@string/str2"
+            android:gravity="center"/>
+    </LinearLayout>
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="40dp"
+        android:orientation="horizontal">
+        <SeekBar
+            android:layout_width="0dp"
+            android:layout_weight="5"
+            android:layout_height="40dp"
+            android:id="@+id/seekbar2" />
+        <TextView
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:text="@string/str3"
+            android:gravity="center"/>
+    </LinearLayout>
+    <!--liujunjie add end -->
+</LinearLayout>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index a60b9d0..6a864e08 100755
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -20,6 +20,10 @@<resources xmlns:android="http://schemas.android.com/apk/res/android"xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"><string name="app_label" msgid="4811759950673118541">"系统界面"</string>
+    <string name="str1" msgid="4811759950673118544">"屏幕亮度"</string>
+    <string name="str2" msgid="4811759950673118545">"台灯亮度"</string>
+    <string name="str3" msgid="4811759950673118547">"台灯色温"</string>
+    <string name="quick_settings_dtbutton_unlocked_label" msgid="4811759950673118542">"台灯"</string><string name="status_bar_clear_all_button" msgid="2491321682873657397">"清除"</string><string name="status_bar_no_notifications_title" msgid="7812479124981107507">"无通知"</string><string name="status_bar_ongoing_events_title" msgid="3986169317496615446">"正在进行的"</string>
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
old mode 100644
new mode 100755
index fcd47d4..6a32d03
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -106,7 +106,7 @@<!-- The default tiles to display in QuickSettings --><string name="quick_settings_tiles_default" translatable="false">
-        wifi,bt,dnd,flashlight,rotation,battery,cell,airplane,cast,screenrecord
+        wifi,bt,tdbutton,airplane</string><!-- The minimum number of tiles to display in QuickSettings -->
@@ -114,7 +114,7 @@<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" --><string name="quick_settings_tiles_stock" translatable="false">
-        wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night,screenrecord,reverse
+        wifi,cell,tdbutton,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night,screenrecord,reverse</string><!-- The tiles to display in QuickSettings -->
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
old mode 100644
new mode 100755
index f002a27..ae0fcca
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -426,6 +426,7 @@<dimen name="notification_panel_width">@dimen/match_parent</dimen><dimen name="brightness_mirror_height">48dp</dimen>
+    <dimen name="brightness_mirror_height1">80dp</dimen><!-- The width of the panel that holds the quick settings. --><dimen name="qs_panel_width">@dimen/notification_panel_width</dimen>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 7f2fbba..e65bdb2 100755
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -19,6 +19,11 @@<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"><!-- Name of the status bar as seen in the applications info settings page. [CHAR LIMIT=12] --><string name="app_label">System UI</string>
+    <string name="str1" >Screen brightness</string>
+    <string name="str2" >Lamp brightness</string>
+    <string name="str3" >Lamp color temperature</string>
+    <!--台灯-->
+    <string name="quick_settings_dtbutton_unlocked_label">DeskLamp</string><!-- The text for the button in the notification window-shade that clearsall of the currently visible notifications. [CHAR LIMIT=10]-->
diff --git a/packages/SystemUI/src/com/android/systemui/junjie/MySerialPortService.java b/packages/SystemUI/src/com/android/systemui/junjie/MySerialPortService.java
new file mode 100755
index 0000000..0df1efb
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/junjie/MySerialPortService.java
@@ -0,0 +1,204 @@
+package com.android.systemui.junjie;
+
+import android.app.Service;
+import android.content.Intent;
+import android.hardware.SerialPort;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class MySerialPortService extends Service {
+
+    public static final String port = "/dev/ttyS9";
+    private SerialPort serialPort;
+    private ParcelFileDescriptor parcelFileDescriptor;
+    private ByteBuffer dates = ByteBuffer.allocate(10);
+    public static final String TAG = "MySerialPortService";
+    private FileOutputStream mFileOutputStream;
+    private final IBinder mBinder = new MyBinder();
+
+    public void setStatusChange(StatusChange statusChange) {
+        this.statusChange = statusChange;
+    }
+
+    private StatusChange statusChange;
+
+    public MySerialPortService() {
+
+    }
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        Log.d(TAG, "启动service");
+        thread.start();
+
+    }
+
+    public byte[] getRealData(byte[] src){
+        byte[] res = new byte[src.length+1];
+        byte checkSum = 0x0 & 0xff;
+        for (int i = 0; i < src.length; i++) {
+            byte ui = src[i];
+            checkSum +=(ui&0xff);
+            res[i] = src[i];
+        }
+        checkSum = (byte) (checkSum%0x100);
+        res[src.length] = checkSum;
+        Log.d(TAG, "getRealData: checkSun" +checkSum);
+        return res;
+    }
+
+    /**
+     * 打开灯
+     * */
+    public void setPortOff() {
+        Log.d(TAG, "onReceive: 串口关闭");
+        byte[] setui = new byte[]{0x55,(byte) 0xaa,0x1,0x3,0x1,0x0} ;
+        Log.d(TAG, "setPortOff==" + mFileOutputStream);
+        setCommd(setui);
+
+    }
+    /**
+     * 关闭灯
+     * */
+    public void setPortON() {
+        byte[] setui = new byte[]{0x55,(byte) 0xaa,0x1,0x3,0x1,0x1};
+               Log.d(TAG, "setPortON==" + mFileOutputStream);
+        setCommd(setui);
+    }
+    /**
+     * 配置色温
+     */
+    public void  setColorTemperature(int value){
+        //setPortON();
+        byte[] setui = new byte[]{0x55,(byte) 0xaa,0x1,0x5,0x1, (byte) (value&0xff)};
+        setCommd(setui);
+        Log.d(TAG, "setColorTemperature: "+value);
+
+
+    }
+
+    /**
+     * 配置亮度
+     */
+    public void  setBrightness(int value){
+        //setPortON();
+        byte[] setui = new byte[]{0x55,(byte) 0xaa,0x1,0x4,0x1, (byte) (value&0xff)};
+        setCommd(setui);
+        Log.d(TAG, "setColorTemperature: "+value);
+       // queryState();
+    }
+
+    /**
+     * 查询状态
+     * */
+    public void queryState(){
+        byte[] setui = new byte[]{0x55,(byte) 0xaa,0x1,0x1,0x0} ;
+        setCommd(setui);
+
+
+    }
+
+    private void setCommd(byte[] su){
+        try {
+            if (mFileOutputStream != null) {
+                mFileOutputStream.write(getRealData(su));
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+
+
+
+    private final Thread thread = new Thread(new Runnable() {
+        @Override
+        public void run() {
+            serialPort = new SerialPort(port);
+            try {
+                parcelFileDescriptor = ParcelFileDescriptor.open(new File(port), ParcelFileDescriptor.MODE_READ_WRITE);
+                serialPort.open(parcelFileDescriptor, 9600);
+                mFileOutputStream = new FileOutputStream(parcelFileDescriptor.getFileDescriptor());
+                Log.d(TAG,"main Thread start "+mFileOutputStream);
+                writeThread.start();
+                while (true) {
+                    Log.d(TAG, "run: 读取线程阻塞:");
+                    int read = serialPort.read(dates);
+                    readDate();
+                }
+
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+
+        }
+    });
+
+    private final Thread writeThread = new Thread(new Runnable() {
+        @Override
+        public void run() {
+            Log.d(TAG,"writeThread start "+mFileOutputStream);
+            if (mFileOutputStream != null){
+                //setColorTemperature(10);
+                //queryState();
+            }
+        }
+    });
+
+    private void readDate() {
+        byte[] by = dates.array();
+        /*for (byte b:
+             by) {
+            Log.d(TAG, "readDate: sts:"+b);
+        }*/
+        if (statusChange != null && by[3] == 0x2){
+            Log.d(TAG, "readDate: 读取数据 命令字段:"+by[3]+", 数据长度:"+by[4] +"开关状态:"+by[5]+" ,亮度值:"+by[6]+" ,色温值 :"+by[7]);
+            statusChange.dateSet(by[5]==1,by[6],by[7]);
+        }
+    }
+
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        // TODO: Return the communication channel to the service.
+        return mBinder;
+    }
+    public class MyBinder extends Binder {
+        public MySerialPortService getService() {
+            return MySerialPortService.this;
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        try {
+            mFileOutputStream.close();
+            serialPort.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+
+        return super.onStartCommand(intent, START_STICKY, startId);
+    }
+
+    public interface StatusChange{
+        void dateSet(boolean status,int br,int color);
+    }
+
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index a87a13c..3ce1e82 100755
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -46,6 +46,7 @@ import com.android.systemui.Dumpable;import com.android.systemui.R;import com.android.systemui.broadcast.BroadcastDispatcher;import com.android.systemui.dump.DumpManager;
+import com.android.systemui.junjie.MySerialPortService;import com.android.systemui.media.MediaHierarchyManager;import com.android.systemui.media.MediaHost;import com.android.systemui.plugins.qs.DetailAdapter;
@@ -63,6 +64,7 @@ import com.android.systemui.tuner.TunerService;import com.android.systemui.tuner.TunerService.Tunable;import com.android.systemui.util.animation.DisappearParameters;+import java.io.FileDescriptor;import java.io.PrintWriter;import java.util.ArrayList;
@@ -82,6 +84,14 @@ import android.content.IntentFilter;import android.content.BroadcastReceiver;import android.util.Log;+import android.widget.Button;
+import android.widget.SeekBar;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.database.ContentObserver;
+import android.provider.Settings;
+
+/** View that represents the quick settings tile panel (when expanded/pulled down). **/public class QSPanel extends LinearLayout implements Tunable, Callback, BrightnessMirrorListener,Dumpable {
@@ -160,6 +170,205 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightneprivate int mMediaTotalBottomMargin;private int mFooterMarginStartHorizontal;private Consumer<Boolean> mMediaVisibilityChangedListener;
+    // liujunjie add
+
+    private static MySerialPortService mySerialPortService;
+    private SeekBar seekBar1,seekBar2,seekBar3;
+    private static boolean isOn;
+    private int br;
+    private int color;
+    public static StatusChange statusChange2;
+
+    private final  MySerialPortService.StatusChange statusChange = new MySerialPortService.StatusChange() {
+        @Override
+        public void dateSet(boolean status, int br1, int color1) {
+
+            br = br1;
+            color = color1;
+            seekBar1.setProgress(br1);
+            seekBar2.setProgress(color1);
+            if (isOn != status){
+                statusChange2.statusChange(status);
+            }
+            isOn = status;
+            //updateSeekStatus();
+
+
+        }
+    };
+    private void updateSeekStatus(){
+        if (isOn){
+            if (seekBar1.getVisibility() != View.VISIBLE){
+                seekBar1.setVisibility(View.VISIBLE);
+                seekBar2.setVisibility(View.VISIBLE);
+            }
+
+        }else {
+            if (seekBar1.getVisibility() != View.GONE){
+                seekBar1.setVisibility(View.GONE);
+                seekBar2.setVisibility(View.GONE);
+            }
+
+            }
+
+
+    }
+
+    public static void setStatusChange(QSPanel.StatusChange statusChange) {
+        statusChange2 = statusChange;
+    }
+
+    public interface StatusChange {
+        void statusChange(boolean status);
+    }
+
+    class BrightnessObserver extends ContentObserver {
+        private Context mContext;
+
+        public BrightnessObserver(Context context) {
+            super(null);
+            mContext = context;
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            super.onChange(selfChange);
+            if (!isMeTouch){
+
+                int brightness = Settings.System.getInt(
+                        mContext.getContentResolver(),
+                        Settings.System.SCREEN_BRIGHTNESS,
+                        0
+                );
+                handleBrightnessChange(brightness);
+
+            }
+
+
+
+        }
+        private void handleBrightnessChange(int brightness) {
+            int st = Math.round((float) brightness /255 * 100);
+            if (seekBar3 != null){
+                seekBar3.setProgress(st);
+            }
+        }
+    }
+    boolean isMeTouch = false;
+    private void junjieInit() {
+        Intent intent = new Intent(mContext, MySerialPortService.class);
+        mContext.bindService(intent,mConnection, Context.BIND_AUTO_CREATE);
+        seekBar1 = mBrightnessView.findViewById(R.id.seekbar1);
+        seekBar2 = mBrightnessView.findViewById(R.id.seekbar2);
+        seekBar3 = mBrightnessView.findViewById(R.id.seekbar3); // 屏幕亮度
+        seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (mySerialPortService != null && fromUser  && progress != 0){
+                    mySerialPortService.setBrightness(progress);
+                }
+
+            }
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+
+            }
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+
+            }
+        });
+        seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (mySerialPortService != null && fromUser){
+                    mySerialPortService.setColorTemperature(progress);
+                }
+
+            }
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+
+            }
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+
+            }
+        });
+
+        seekBar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (isMeTouch){
+                    int st = Math.round((float) progress /100 * 255);
+                    Settings.System.putInt(getContext().getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,st);
+                }
+
+            }
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+                isMeTouch = true;
+
+            }
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+                isMeTouch = false;
+
+            }
+        });
+        initStatus();
+        int sy = Settings.System.getInt(getContext().getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,0);
+        seekBar3.setProgress(sy);
+    }
+
+    private void initStatus() {
+        BrightnessObserver brightnessObserver = new BrightnessObserver(getContext());
+        getContext().getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS),
+                true,
+                brightnessObserver
+        );
+
+    }
+
+    public static void liujunjieClick() {
+        if (mySerialPortService != null){
+            if (isOn){
+                mySerialPortService.setPortOff();
+
+            }else {
+                mySerialPortService.setPortON();
+            }
+            isOn = !isOn;
+        }
+    }
+
+    public static boolean getDTStatus() {
+       return isOn;
+    }
+
+    private final ServiceConnection mConnection = new ServiceConnection() {
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            MySerialPortService.MyBinder binder = (MySerialPortService.MyBinder) service;
+            mySerialPortService = binder.getService();
+            mySerialPortService.setStatusChange(statusChange);
+            mySerialPortService.queryState();
+
+        }
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            mySerialPortService = null;
+
+        }
+    };
+@@ -234,6 +443,8 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, BrightneaddView(mHorizontalLinearLayout, lp);initMediaHostState();
+            //junjieInit(); // liujunjie add
+            android.util.Log.d("liujunjie","========== 1111 junjieInit  ========");}addSecurityFooter();if (mRegularTileLayout instanceof PagedTileLayout) {
@@ -261,6 +472,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, BrightneaddView(mBrightnessView);mBrightnessController = new BrightnessController(getContext(),findViewById(R.id.brightness_slider), mBroadcastDispatcher);
+        junjieInit();}protected QSTileLayout createRegularTileLayout() {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
index f9bd43d..e235fb7 100755
--- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
@@ -41,6 +41,7 @@ import com.android.systemui.qs.tiles.NfcTile;import com.android.systemui.qs.tiles.NightDisplayTile;import com.android.systemui.qs.tiles.RotationLockTile;import com.android.systemui.qs.tiles.ScreenRecordTile;
+import com.android.systemui.qs.tiles.TDButtonTile;import com.android.systemui.qs.tiles.UiModeNightTile;import com.android.systemui.qs.tiles.UserTile;import com.android.systemui.qs.tiles.WifiTile;
@@ -83,6 +84,8 @@ public class QSFactoryImpl implements QSFactory {private final Lazy<QSHost> mQsHostLazy;+    private final Provider<TDButtonTile> mTDButtonTileProvider;
+@Injectpublic QSFactoryImpl(Lazy<QSHost> qsHostLazy,Provider<WifiTile> wifiTileProvider,
@@ -105,7 +108,9 @@ public class QSFactoryImpl implements QSFactory {Provider<GarbageMonitor.MemoryTile> memoryTileProvider,Provider<UiModeNightTile> uiModeNightTileProvider,Provider<ScreenRecordTile> screenRecordTileProvider,
-                       Provider<EyeHealthTile> eyeHealthTileProvider) {
+                       Provider<EyeHealthTile> eyeHealthTileProvider,
+                       Provider<TDButtonTile> tDButtonTileProvider
+            ) {mQsHostLazy = qsHostLazy;mWifiTileProvider = wifiTileProvider;mBluetoothTileProvider = bluetoothTileProvider;
@@ -128,6 +133,7 @@ public class QSFactoryImpl implements QSFactory {mUiModeNightTileProvider = uiModeNightTileProvider;mScreenRecordTileProvider = screenRecordTileProvider;mEyeHealthTileProvider=eyeHealthTileProvider;
+        mTDButtonTileProvider = tDButtonTileProvider;}public QSTile createTile(String tileSpec) {
@@ -180,6 +186,8 @@ public class QSFactoryImpl implements QSFactory {return mUiModeNightTileProvider.get();case "screenrecord":return mScreenRecordTileProvider.get();
+            case "tdbutton":
+                return mTDButtonTileProvider.get();}diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/TDButtonTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/TDButtonTile.java
new file mode 100755
index 0000000..76581e3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/TDButtonTile.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles;
+
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.provider.Settings;
+import android.service.quicksettings.Tile;
+import android.widget.Switch;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.systemui.R;
+import com.android.systemui.plugins.qs.QSTile.BooleanState;
+import com.android.systemui.qs.QSHost;
+import com.android.systemui.qs.QSPanel;
+import com.android.systemui.qs.tileimpl.QSTileImpl;
+
+import javax.inject.Inject;
+
+/** Quick settings tile: Rotation **/
+public class TDButtonTile extends QSTileImpl<BooleanState> {
+
+    private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_td_button);
+
+    @Inject
+    public TDButtonTile(QSHost host) {
+        super(host);
+        QSPanel.setStatusChange(new QSPanel.StatusChange(){
+            @Override
+            public void statusChange(boolean status){
+
+                refreshState();
+
+            }
+
+        });
+    }
+
+    @Override
+    public BooleanState newTileState() {
+        return new BooleanState();
+    }
+
+
+    @Override
+    protected void handleClick() {
+        final boolean newState = !mState.value;
+        QSPanel.liujunjieClick();
+        refreshState(newState);
+    }
+
+
+    @Override
+    public CharSequence getTileLabel() {
+        return getState().label;
+    }
+
+    @Override
+    protected void handleUpdateState(BooleanState state, Object arg) {
+
+        state.value = QSPanel.getDTStatus();
+        state.label = mContext.getString(R.string.quick_settings_dtbutton_unlocked_label);
+        state.icon = mIcon;
+        //tate.contentDescription = getAccessibilityString(rotationLocked);
+        //state.expandedAccessibilityClassName = Switch.class.getName();
+        state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return 0;
+    }
+
+
+    @Override
+    protected void handleSetListening(boolean listening) {
+
+
+    }
+
+    @Override
+    public Intent getLongClickIntent() {
+        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
+        homeIntent.addCategory(Intent.CATEGORY_HOME);xieuy
+        homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        return homeIntent;
+    }
+
+}

协议链接

链接:https://pan.baidu.com/s/1kOmVpb5fEKO9FAkN4JsnhA?pwd=s56b 
提取码:s56b 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/501466.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

服务器等保测评日志策略配置

操作系统日志 /var/log/message 系统启动后的信息和错误日志&#xff0c;是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关的日志信息 /var/log/maillog 与邮件相关的日志信息 /var/log/cron 与定时任务相关的日志信息 /var/log/spooler 与UUCP和news设备相关的…

Flutter-插件 scroll-to-index 实现 listView 滚动到指定索引位置

scroll-to-index 简介 scroll_to_index 是一个 Flutter 插件&#xff0c;用于通过索引滚动到 ListView 中的某个特定项。这个库对复杂滚动需求&#xff08;如动态高度的列表项&#xff09;非常实用&#xff0c;因为它会自动计算需要滚动的目标位置。 使用 安装插件 flutte…

我用AI学Android Jetpack Compose之开篇

最近突发奇想&#xff0c;想学一下Jetpack Compose&#xff0c;打算用Ai学&#xff0c;学最新的技术应该要到官网学&#xff0c;不过Compose已经出来一段时间了&#xff0c;Ai肯定学过了&#xff0c;用Ai来学&#xff0c;应该问题不大&#xff0c;学习过程记录下来&#xff0c;…

PHP框架+gatewayworker实现在线1对1聊天--发送消息(6)

文章目录 发送消息原理说明发送功能实现html部分javascript代码PHP代码 发送消息原理说明 接下来我们发送聊天的文本信息。点击发送按钮的时候&#xff0c;会自动将文本框里的内容发送出去。过程是我们将信息发送到服务器&#xff0c;服务器再转发给对方。文本框的id为msgcont…

网络安全 | 信息安全管理体系(ISMS)认证与实施

网络安全 | 信息安全管理体系&#xff08;ISMS&#xff09;认证与实施 一、前言二、信息安全管理体系&#xff08;ISMS&#xff09;概述2.1 ISMS 的定义与内涵2.2 ISMS 的核心标准 ——ISO/IEC 27001 三、信息安全管理体系&#xff08;ISMS&#xff09;认证3.1 认证的意义与价值…

服务器数据恢复—服务器硬盘亮黄灯的数据恢复案例

服务器硬盘指示灯闪烁黄灯是一种警示&#xff0c;意味着服务器硬盘出现故障即将下线。发现这种情况建议及时更换硬盘。 一旦服务器上有大量数据频繁读写&#xff0c;硬盘指示灯会快速闪烁。服务器上某个硬盘的指示灯只有黄灯亮着&#xff0c;而其他颜色的灯没有亮的话&#xff…

AfuseKt1.4.4 | 刮削视频播放器,支持阿里云盘和自动海报墙

AfuseKt是一款功能强大的安卓端在线视频播放器&#xff0c;广泛兼容多种平台如阿里云盘、Alist、WebDAV、Emby、Jellyfin等&#xff0c;同时也支持本地存储视频文件的播放。其特色功能包括自动抓取影片信息生成海报墙展示&#xff0c;充分利用设备硬件进行高清视频流畅播放&…

数字孪生:物联+数据打造洞察世界新视角

引言&#xff1a;数字孪生是物理系统向信息空间映射的关键技术&#xff0c;通过传感器、数据分析、物联网&#xff0c;实现实时模拟和控制。新一代信息技术支撑数字孪生的广泛应用&#xff0c;使其在工业、城市、交通、医疗、水利等多领域实现虚拟与现实融合&#xff0c;促进经…

“AI智慧教学系统:开启个性化教育新时代

大家好&#xff0c;我是老王&#xff0c;一个在产品圈摸爬滚打多年的资深产品经理。今天&#xff0c;我想和大家聊聊一个最近特别火的概念——AI智慧教学系统。这东西听起来好像很高大上&#xff0c;但其实和我们每个人都息息相关&#xff0c;因为它关系到我们下一代的教育。 一…

【开源项目】数字孪生立交~东湖高新区互通式立交数字孪生可视化项目——开源工程及源码

飞渡科技数字孪生立交管理平台&#xff0c;依托国产自研数字孪生引擎&#xff0c;融合地理空间数据、倾斜摄影、人工智能及物联网IOT等多种技术&#xff0c;实现对立交的安全监测以及养护管理。 基于GIS技术&#xff0c;呈现立交的空间区位分布。 将交通流量数据以云图形式呈现…

树莓派 Pico RP2040 教程点灯 双核编程案例

双核点亮不同的 LED 示例&#xff0c;引脚分别是GP0跟GP1。 #include "pico/stdlib.h" #include "pico/multicore.h"#define LED1 0 // 核心 0 控制的 LED 引脚 #define LED2 1 // 核心 1 控制的 LED 引脚// the setup function runs once when you press …

ASA第六天笔记

Botnet Traffic Filter简介 1.僵死网络流量过滤特性是一个基于名誉的机制&#xff0c;用于阻止流量源自于或者去往已知的感染主机。 2.僵死网络流量过滤比较每一个连接中的源和目的IP地址。 动态SensorBase数据库&#xff0c;被Cisco动态更新。静态数据库&#xff0c;需要手动…

网关的主要作用

在网络安全领域&#xff0c;网关扮演着举足轻重的角色&#xff0c;它不仅是网络间的桥梁&#xff0c;更是安全防线的守护者。以下是网关在网络安全中的几个关键作用&#xff1a; 1. 防火墙功能&#xff1a;网关常常集成了防火墙技术&#xff0c;能够对进出网络的数据包进行严格…

【模型】Qwen2-VL 服务端UI

1. 前言 最近在测试VLM模型&#xff0c;发现官方的网页demo&#xff0c;代码中视频与图片分辨率可能由于高并发设置的很小&#xff0c;导致达不到预期效果&#xff0c;于是自己研究了一下&#xff0c;搞了一个简单的前端部署&#xff0c;自己在服务器部署了下UI界面&#xff0…

leetcode题目(3)

目录 1.加一 2.二进制求和 3.x的平方根 4.爬楼梯 5.颜色分类 6.二叉树的中序遍历 1.加一 https://leetcode.cn/problems/plus-one/ class Solution { public:vector<int> plusOne(vector<int>& digits) {int n digits.size();for(int i n -1;i>0;-…

数据库知识汇总2

一. 范式 定义&#xff1a;范式是符合某一种级别的关系模式的集合。 关系数据库中的关系必须满足一定的要求。满足不同程度要求的为不同范式&#xff1b; 一个低一级范式的关系模式&#xff0c;通过模式分解&#xff08;schema decomposition&#xff09;可以转换为若干个高一…

Eplan 布局图中的宏/设备/安装板比例缩放

在Eplan的布局图&#xff0c;有时要放大或缩小宏或设备&#xff0c;有两种办法 1.选中宏/设备/安装板等&#xff0c;在 编辑--图形中选择比例缩放即可&#xff0c;但这种方式会造成尺寸标注与实际长度不符&#xff0c;需要手动修改尺寸标注值。 2.修改页面的比例&#xff0c;在…

zookeeper+kafka

一、zookeeper 1.概述 zoo: 开源的分布式框架协调服务 zookeeper的工作机制&#xff1a;基于观察者模式设计的分布式结构&#xff0c;负责存储和管理架构当中的元信息&#xff0c;架构当中的应用接受观察者的监控&#xff0c;一旦数据有变化&#xff0c;通知对应的zookeeper&a…

Java项目实战II基于微信小程序的家庭大厨(开发文档+数据库+源码)

目录 一、前言 二、技术介绍 三、系统实现 四、核心代码 五、源码获取 全栈码农以及毕业设计实战开发&#xff0c;CSDN平台Java领域新星创作者&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。 一、前言 在快节奏的生活中&#xff0c;家庭聚餐成为了连接亲情…

Ungoogled Chromium127 编译指南 MacOS 篇(一)- 项目介绍

1. 引言 在当今互联网时代&#xff0c;浏览器不仅是我们访问网络的窗口&#xff0c;更是保护个人隐私的重要工具。然而&#xff0c;主流浏览器普遍存在数据收集和隐私问题。大多数用户可能并不知道&#xff0c;当我们使用 Chrome 浏览器时&#xff0c;会有大量的个人数据被收集…