安卓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.mzph.cn/pingmian/66035.shtml

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

相关文章

node.js下载、安装、设置国内镜像源(永久)(Windows11)

目录 node-v20.18.0-x64 工具下载安装设置国内镜像源&#xff08;永久&#xff09; node-v20.18.0-x64 工具 系统&#xff1a;Windows 11 下载 官网https://nodejs.org/zh-cn/download/package-manager 版本我是跟着老师选的node-v20.18.0-x64如图选择 Windows、x64、v2…

如何轻松安全地销售旧 Android 手机

众所周知&#xff0c;手机不断更新换代。当您想要的手机终于到货时&#xff0c;您可能迫不及待地将旧 Android 手机更新为最新手机。在此之前&#xff0c;你们中的一些人可能会考虑以最多的钱卖掉旧的Android手机。 但永远不要冲动地卖掉你的旧 Android 手机&#xff01;为了安…

欧科云链研究院:ChatGPT 眼中的 Web3

编辑&#xff5c;OKG Research 转眼间&#xff0c;2024年已经进入尾声&#xff0c;Web3 行业经历了热闹非凡的一年。今年注定也是属于AI的重要一年&#xff0c;OKG Research 决定拉上 ChatGPT 这位“最懂归纳的AI拍档”&#xff0c;尝试把一整年的研究内容浓缩成精华。我们一共…

【从零开始入门unity游戏开发之——unity篇04】unity6基础入门——场景窗口(Scene)和层级窗口(Hierarchy)介绍

文章目录 场景窗口&#xff08;Scene&#xff09;和层级窗口&#xff08;Hierarchy&#xff09;一、层级窗口&#xff08;Hierarchy&#xff09;1、添加新的对象&#xff08;物体&#xff09;2、Hierarchy层级窗口快捷键3、搜索 二、Scene场景窗口1、工具栏控制台2、操作物体位…

Mac中配置vscode(第一期:python开发)

1、终端中安装 xcode-select --install #mac的终端中安装该开发工具 xcode-select -p #显示当前 Xcode 命令行工具的安装路径注意&#xff1a;xcode-select --install是在 macOS 上安装命令行开发工具(Command Line Tools)的关键命令。安装的主要组件包括&#xff1a;C/C 编…

快速将索尼手机联系人导出为 HTML 文件

我想将 Sony Xperia 手机上的联系人导出到计算机上进行备份&#xff0c;并在需要时进行编辑。这可以做到吗&#xff1f;如何做到&#xff1f;作为助手我需要下载什么工具吗&#xff1f; 当您的 Android 手机上存储了如此多的重要联系人&#xff0c;而您又不想丢失它们时&#…

学习threejs,导入AWD格式的模型

&#x1f468;‍⚕️ 主页&#xff1a; gis分享者 &#x1f468;‍⚕️ 感谢各位大佬 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍⚕️ 收录于专栏&#xff1a;threejs gis工程师 文章目录 一、&#x1f340;前言1.1 ☘️THREE.AWDLoader AWD模型加…

【OAA 】面向对象分析:从概念到实践

&#x1f525;个人主页&#xff1a; 中草药 &#x1f525;专栏&#xff1a;【Java】登神长阶 史诗般的Java成神之路 我们都知道Java是一门面向对象的开发语言&#xff0c;在软件开发的广袤天地中&#xff0c;面向对象分析&#xff08;Object-Oriented Analysis&#xff0c;简称…

jvm结构介绍

JVM结构概述 Java虚拟机&#xff08;JVM&#xff09;是Java程序的运行环境&#xff0c;它负责将Java字节码转换为机器码并执行。JVM的结构主要包括类加载子系统、运行时数据区、执行引擎、本地接口以及垃圾收集器。 1. 类加载子系统&#xff08;Class Loader Subsystem&#xf…

Nginx常用配置之详解(Detailed Explanation of Common Nginx Configurations)

Nginx常用配置详解(图文全面总结) Nginx Nginx 是一款轻量级的高性能 HTTP、 和反向代理服务器。 Nginx&#xff0c;被广泛用于负载均衡、静态文件服务、和代理.........等。 Nginx&#xff0c;以高并发、低内存占用、和高可用性著称&#xff0c;大部分的大厂以及公司都在使…

Win11+WLS Ubuntu 鸿蒙开发环境搭建(二)

参考文章 penHarmony南向开发笔记&#xff08;一&#xff09;开发环境搭建 OpenHarmony&#xff08;鸿蒙南向开发&#xff09;——标准系统移植指南&#xff08;一&#xff09; OpenHarmony&#xff08;鸿蒙南向开发&#xff09;——小型系统芯片移植指南&#xff08;二&…

ubuntu 使用s3fs配置自动挂载对象存储

一、环境准备 1.有访问对象存储权限的AKSK 2.服务器、对象存储 二、实施步骤 sudo apt update sudo apt install s3fs echo "AK:SK" >/home/ubuntu/.passwd-s3fs ---位置自定义 chmod 600 /home/ubuntu/.passwd-s3fs ---权限必须要有 mkdir /data sudo s3fs …

聚铭网络受邀参加2024年南京市信息技术应用创新产业供需对接会

近日&#xff0c;备受瞩目的2024年南京市信息技术应用创新产业供需对接会&#xff08;‘宁工品推’信创、商用密码专场&#xff09;”在中国&#xff08;南京&#xff09;软件谷云密城圆满举办。聚铭网络作为信创领域的杰出代表厂商&#xff0c;受邀出席本次大会&#xff0c;为…

关于 AWTK 和 Weston 在旋转屏幕时的资源消耗问题

关于 AWTK 和 Weston 在旋转屏幕时的资源消耗问题&#xff0c;首先需要理解这两者旋转的本质区别及其资源开销。 AWTK的屏幕旋转&#xff1a; AWTK旋转的实现方式&#xff1a; AWTK 是一个用户界面工具包&#xff0c;它通过图形渲染系统处理所有控件和窗口的旋转。当你使用 w…

RS485方向自动控制电路分享

我们都知道RS485是半双工通信&#xff0c;所以在传输的时候需要有使能信号&#xff0c;标明是发送还是接收信号&#xff0c;很多时候就简单的用一个IO口控制就好了&#xff0c;但是有一些低成本紧凑型的MCU上&#xff0c;一个IO口也是很珍贵的&#xff0c;因此&#xff0c;如果…

UE5材质节点Frac/Fmod

Frac取小数 Fmod取余数 转场效果 TimeMultiplyFrac很常用 Timesin / Timecos 制作闪烁效果

图神经网络_GNN从入门到入门

文章目录 0 提出背景1 网络结构2 GNN算法2.1 算法描述2.2 举个栗子 3 GNN本质4 应用领域5 代码案例5.1 PyG的下载5.2 常用数据集介绍5.3 one demo 0 提出背景 经典的深度神经网络适用于 欧几里得数据&#xff08;Euclidean data&#xff09;&#xff0c;比如我们常常用卷积神经…

CDGA数据治理工程师-学习笔记

目录 第一章 数据管理 组织管理数据的目标&#xff1a; 数据管理的原则&#xff1a; 数据生命周期&#xff1a; 数据管理战略的组成应包括&#xff1a; 第二章 数据伦理 目标 数据伦理活动 数据处理伦理问题 贝尔蒙特 数据伦理准则 违背伦理进行数据处理的风险 建立…

AWS K8s 部署架构

Amazon Web Services&#xff08;AWS&#xff09;提供了一种简化的Kubernetes&#xff08;K8s&#xff09;部署架构&#xff0c;使得在云环境中管理和扩展容器化应用变得更加容易。这个架构的核心是AWS EKS&#xff08;Elastic Kubernetes Service&#xff09;&#xff0c;它是…

计算机网络 (16)数字链路层的几个共同问题

一、封装成帧 封装成帧是数据链路层的一个基本问题。数据链路层把网络层交下来的数据构成帧发送到链路上&#xff0c;以及把接收到的帧中的数据取出并上交给网络层。封装成帧就是在一段数据的前后分别添加首部和尾部&#xff0c;构成了一个帧。接收端在收到物理层上交的比特流后…