android下拉欄添加媒體音量調節

參考下拉欄的屏幕亮度調節,添加媒體音量調節。
平臺信息:
MSM8909.LA.3.1.2_AOSP
PLATFORM_VERSION=9
BUILD_ID=PKQ1.190903.001

效果圖

在這里插入圖片描述

布局文件與音量圖標

Index: frameworks/base/packages/SystemUI/res/layout/quick_settings_media_volume_dialog.xml
===================================================================
--- frameworks/base/packages/SystemUI/res/layout/quick_settings_media_volume_dialog.xml	(不存在的)
+++ frameworks/base/packages/SystemUI/res/layout/quick_settings_media_volume_dialog.xml	(版本 12429)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    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:paddingLeft="16dp"
+    android:paddingRight="16dp">
+
+    <ImageView
+        android:id="@+id/media_volume_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:layout_marginEnd="8dp"
+        android:src="@drawable/ic_media_stream"
+        android:contentDescription="@null"
+        android:visibility="visible" />
+
+    <SeekBar
+        android:id="@+id/media_volume_seekbar"
+        android:layout_width="0dp"
+        android:layout_height="48dp"
+        android:layout_gravity="center_vertical"
+        android:layout_weight="1" />
+
+</LinearLayout>
Index: frameworks/base/packages/SystemUI/res/drawable/ic_media_stream.xml
===================================================================
--- frameworks/base/packages/SystemUI/res/drawable/ic_media_stream.xml	(不存在的)
+++ frameworks/base/packages/SystemUI/res/drawable/ic_media_stream.xml	(版本 12429)
@@ -0,0 +1,25 @@
+<!--
+    Copyright (C) 2017 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0"
+        android:tint="?android:attr/colorControlNormal">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M12,3l0.01,10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55C7.79,13 6,14.79 6,17c0,2.21 1.79,4 4.01,4S14,19.21 14,17V7h4V3H12zM10.01,19c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2C12.01,18.1 11.11,19 10.01,19z"/>
+</vector>

實現

Index: frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java	(版本 12424)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java	(版本 12429)
@@ -20,10 +20,14 @@import static com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState;import android.annotation.Nullable;
+import android.content.BroadcastReceiver;import android.content.ComponentName;import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;import android.content.res.Configuration;import android.content.res.Resources;
+import android.media.AudioManager;import android.metrics.LogMaker;import android.os.Handler;import android.os.Message;
@@ -32,6 +36,8 @@import android.view.LayoutInflater;import android.view.View;import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;import com.android.internal.logging.MetricsLogger;import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -62,7 +68,7 @@protected final Context mContext;protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
-    protected final View mBrightnessView;
+    protected final View mBrightnessView, mMediaVolumeView;private final H mHandler = new H();private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);private final QSTileRevealController mQsTileRevealController;
@@ -87,6 +93,9 @@private BrightnessMirrorController mBrightnessMirrorController;private View mDivider;+    private AudioManager mAudioManager;
+    private SeekBar mMediaVolumeSeekBar;
+public QSPanel(Context context) {this(context, null);}
@@ -101,6 +110,12 @@R.layout.quick_settings_brightness_dialog, this, false);addView(mBrightnessView);+        mMediaVolumeView = LayoutInflater.from(mContext).inflate(
+            R.layout.quick_settings_media_volume_dialog, this, false);
+        addView(mMediaVolumeView);
+mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate(R.layout.qs_paged_tile_layout, this, false);mTileLayout.setListening(mListening);
@@ -123,9 +138,42 @@findViewById(R.id.brightness_icon),findViewById(R.id.brightness_slider));+        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        mMediaVolumeSeekBar = findViewById(R.id.media_volume_seekbar);
+        mMediaVolumeSeekBar.setMax(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
+        mMediaVolumeSeekBar.setProgress(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
+        mMediaVolumeSeekBar.setOnSeekBarChangeListener(mSeekListener);
+        IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION);
+        mContext.registerReceiver(mMediaVolumeReceiver, filter);
+updateResources();}+    private final OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {
+        @Override
+        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
+        }
+
+        @Override
+        public void onStartTrackingTouch(SeekBar seekBar) { }
+
+        @Override
+        public void onStopTrackingTouch(SeekBar seekBar) { }
+    };
+
+    private final BroadcastReceiver mMediaVolumeReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            int currentMediaVolumeValue = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+            mMediaVolumeSeekBar.setProgress(currentMediaVolumeValue);
+        }
+    };
+protected void addDivider() {mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false);mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(),

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/85470.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/85470.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/85470.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

VS Code 配置ROS2開發環境常見問題記錄

1、ctrlshiftp后找不到C/C: Edit configurations 安裝或重裝C插件。 參考鏈接&#xff1a; 搜索C/C: Edit configurations顯示no matching command問題https://www.cnblogs.com/hunghau/p/17195622.html 2、ROS2 API無法轉到定義 &#xff08;1&#xff09;在c_cpp_proper…

Docker Desktop搭建RocketMQ的完整教程

Docker Desktop搭建RocketMQ圖文教程 1. 準備工作 已安裝Docker Desktop&#xff08;本地安裝方法參考上一節教程&#xff09;。需部署三個組件&#xff1a;NameServer、Broker、Console&#xff08;管理界面&#xff09;。 2. 創建目錄和文件 在任意盤&#xff08;如D盤&am…

算法35天|1049. 最后一塊石頭的重量 II、 494. 目標和、 474.一和零

1049. 最后一塊石頭的重量 II 題目 思路與解法 class Solution { public:int lastStoneWeightII(vector<int>& stones) {int sum 0;for(int i0;i<stones.size();i){sum stones[i];}// 問題轉換為&#xff1a;// 先求得&#xff0c;背包容量為target時&#x…

AWS S3拒絕非https的請求訪問

問題 aws s3桶&#xff0c;安全要求必須強制使用ssl加密訪問&#xff0c;即https。需要添加一個策略拒絕所有不是https的訪問s3桶請求。 解決 在對于桶添加相關拒絕策略即可。如下&#xff1a; {"Version": "2012-10-17","Statement": [{&qu…

GitLab CVE-2025-4278 安全漏洞解決方案

本分分享極狐GitLab 補丁版本 18.0.2, 17.11.4, 17.10.8 的詳細內容。這幾個版本包含重要的缺陷和安全修復代碼&#xff0c;我們強烈建議所有私有化部署用戶應該立即升級到上述的某一個版本。對于極狐GitLab SaaS&#xff0c;技術團隊已經進行了升級&#xff0c;無需用戶采取任…

Async、await是什么?跟promise有什么區別?使用的好處是什么

Async/Await 與 Promise 的深度解析 一、基本概念 1. Promise Promise 是 ES6 引入的異步編程解決方案&#xff0c;表示一個異步操作的最終完成&#xff08;或失敗&#xff09;及其結果值。 function fetchData() {return new Promise((resolve, reject) > {setTimeout(…

MySQL數據庫中所有表的空間占用與行數統計

查看某個數據庫中所有表的空間與行數統計 SELECT TABLE_NAME AS 表名,TABLE_ROWS AS 行數,ROUND(DATA_LENGTH / 1024 / 1024, 2) AS 數據大小(MB),ROUND(INDEX_LENGTH / 1024 / 1024, 2) AS 索引大小(MB),ROUND((DATA_LENGTH INDEX_LENGTH) / 1024 / 1024, 2) AS 總占用空間(…

el-upload 點擊上傳按鈕前先判斷條件滿足再彈選擇文件框

解決思路&#xff1a; 先寫一個上傳按鈕&#xff0c;點擊上傳按鈕后判斷條件是否滿足&#xff0c;滿足則顯示上傳組件并使用ref來控制點擊事件&#xff0c;隱藏自身。 注&#xff1a;上傳成功或者上傳失敗時或者上傳前判斷條件添加不滿足return將this.isShow true 代碼部分…

django ReturnDict 如何修改內容

在Django中&#xff0c;QuerySet 對象通常用于從數據庫中檢索數據&#xff0c;并且可以被轉換為各種格式&#xff0c;例如字典。如果你想修改QuerySet返回的結果&#xff08;例如&#xff0c;將其轉換為dict&#xff09;&#xff0c;你可以在查詢執行后進行操作。這里有幾種常見…

密室出逃消消樂小游戲微信流量主小程序開源

這個密室出逃消消樂小游戲采用了微信小程序的標準目錄結構&#xff0c;包含以下核心功能&#xff1a; 游戲界面&#xff1a;6x6 的網格布局&#xff0c;隨機生成不同類型的物品 游戲邏輯&#xff1a;交換相鄰物品&#xff0c;消除三個或以上相同類型的物品 計分系統&#xff1a…

SmartMediaKit實戰經驗總結之高穩定、低延遲、強兼容

在萬物互聯與數字化加速融合的今天&#xff0c;音視頻實時通信技術正成為各行業發展的核心驅動力。從教育到工業、從安防到遠程醫療&#xff0c;毫秒級低延遲的音視頻交互體驗已成為新一代實時系統的“生命線”。而在這個領域&#xff0c;視沃科技旗下的大牛直播SDK&#xff08…

前端性能調優工具與指標

性能指標解析 核心Web指標 核心Web指標(Core Web Vitals)是Google定義的一組關鍵性能指標&#xff0c;直接影響用戶體驗和SEO排名&#xff1a; FCP (First Contentful Paint): 首次內容繪制&#xff0c;記錄頁面首次渲染任何文本、圖像、非白色畫布或SVG的時間點 優: < 1.…

LeeCode2294劃分數組使最大值為K

項目場景&#xff1a; 給你一個整數數組 nums 和一個整數 k 。你可以將 nums 劃分成一個或多個 子序列 &#xff0c;使 nums 中的每個元素都 恰好 出現在一個子序列中。 在滿足每個子序列中最大值和最小值之間的差值最多為 k 的前提下&#xff0c;返回需要劃分的 最少 子序列…

中國醫科大借iMeta影響因子躍升至33.2(中科院1區)東風,憑多組學聯合生信分析成果登刊

中國醫科大借iMeta影響因子躍升至33.2&#xff08;中科院1區&#xff09;東風&#xff0c;憑多組學聯合生信分析成果登刊 2025年6月18日&#xff0c;科睿唯安正式發布了2024年期刊的最新影響因子(發送關鍵詞 “2024JIF” 至 “生信學術縱覽”&#xff0c;即可下載完整版最新影…

百度垂搜數據管理系統彈性調度優化實踐

百度垂直搜索系統將搜索核心能力賦能阿拉丁&#xff08;百度搜索特型結果&#xff09;、垂直領域搜索、應用內搜索等場景&#xff0c;支撐了數百個檢索場景、百億級內容數據的檢索。隨著接入業務數量和數據量不斷增長&#xff0c;系統在海量數據管理與調度上遭遇新的挑戰&#…

什么是Nacos?

Nacos&#xff08;Naming and Configuration Service&#xff09;是一個由阿里巴巴開源的動態服務發現、配置管理和服務管理平臺&#xff0c;專為云原生應用設計。它是構建微服務架構的核心基礎設施之一&#xff0c;主要解決分布式系統中的服務注冊發現和動態配置管理兩大核心問…

golang excel導出時需要顯示刷新

"github.com/xuri/excelize/v2"包導出excel文件時在調用WriteTo函數前需要顯式關閉流寫入器 if err : sw.Flush(); err ! nil { return nil, err } &#xff0c;否則會造成excel文件使用excel打開時出現問題&#xff0c;但是用wps打開文件就沒有此問題 詳細代碼&…

Make RL Great Again:大語言模型時代的強化學習推理丨記深度推理模型論壇

進入2025年&#xff0c;大模型依賴Scaling Law提升性能的方式正面臨邊際遞減。一方面算力成本居高不下&#xff0c;另一方面訓練效率與推理質量難以兼顧。在這種背景下&#xff0c;模型正悄然從“模仿機器”轉向“思考引擎”。 6月7日&#xff0c;以“推理”為核心的智源大會深…

MATLAB R2025a安裝教程

軟件介紹 MATLAB 是由MathWorks公司開發的高級數值計算軟件&#xff0c;在工程計算、數據分析和算法開發領域應用廣泛&#xff0c;以下是其相關介紹&#xff1a; 功能特點 ?矩陣運算與可視化&#xff1a;提供強大的矩陣處理能力&#xff0c;內置豐富的繪圖函數&#xff0c;可快…

Flink CDC MySQL 表字段定義為 decimal 輸出亂碼問題優雅解決方式

Flink CDC MySQL 表字段定義為 decimal 輸出亂碼問題解析 代碼運行環境 Flink 1.15 + FlinkCDC 2.4.0 + jdk1.8 +springboot 2.31、原因分析 Flink CDC 底層使用 Debezium 連接器來捕獲 MySQL 的數據變更。當 MySQL 表中的字段類型為 decimal 時,Debezium 默認會將 decimal…