当前位置: 首页 > article >正文

Android12 添加设置控制导航栏显示和状态栏下拉

添加key值

  • 位置: frameworks/base/core/java/android/provider/Settings.java
 /**
  * Control navigation bar enabled
  */
  @Readable
  @SuppressLint("NoSettingsProvider")
  public static final String NAVIGATIONBAR_ENABLED = "navigationbar_enabled";

  /**
   * Supoort panel bar expand
   */
   @Readable
   @SuppressLint("NoSettingsProvider")
   public static final String SUPPORT_PANELBAR_EXPAND = "support_panelbar_expand";

Setting中添加相关设置项

  • 位置:packages/apps/Settings/res/xml/display_settings.xml
  <SwitchPreference
       android:key="navigationbar_enabled"
       android:title="@string/navigationbar_enabled_title"
       settings:controller="com.android.settings.display.NavigationbarPreferenceController"/>

  <SwitchPreference
       android:key="support_panelbar_expand"
       android:title="@string/support_panelbar_expand_title"
       settings:controller="com.android.settings.display.SupportPanelbarExpandPreferenceController"/>  
  • 位置:packages/apps/Settings/res/values/strings.xml
   <string name="navigationbar_enabled_title">Show navigation bar</string>
   <string name="support_panelbar_expand_title">Allows status bar drop-down</string>
  • 位置:packages/apps/Settings/src/com/android/settings/display/NavigationbarPreferenceController.java
package com.android.settings.display;

import android.content.Context;
import android.text.TextUtils;

import androidx.preference.Preference;

import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

import android.provider.Settings;

public class NavigationbarPreferenceController extends TogglePreferenceController implements
        Preference.OnPreferenceChangeListener {

    private static final String KEY_NAVIGATIONBAR = "navigationbar_enabled";

    private Context mContext;
    private Preference mPreference;

    public NavigationbarPreferenceController(Context context) {
        super(context, KEY_NAVIGATIONBAR);
        mContext = context;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_NAVIGATIONBAR;
    }

    @Override
    public void updateState(Preference preference) {
        mPreference = preference;
        super.updateState(preference);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE/* : UNSUPPORTED_ON_DEVICE*/;
    }

    @Override
    public boolean isChecked() {
        int status = Settings.System.getInt(mContext.getContentResolver(), Settings.System.NAVIGATIONBAR_ENABLED, 0);
        return status==1;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        Settings.System.putInt(mContext.getContentResolver(), 
                Settings.System.NAVIGATIONBAR_ENABLED, isChecked ? 1:0);
        return true;
    }
}

在屏幕顶部和中间下滑都可以拉出状态栏,所以有两个地方需要修改。你也可以直接在CommandQueue.java的panelsEnabled()方法中做控制

  • 位置:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
	@Override
    public boolean onTouchEvent(MotionEvent event) {
    	// add start
        int supportExpand = Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.SUPPORT_PANELBAR_EXPAND, 0);
        if (supportExpand == 0){
            return true;
        }
        // end
        boolean barConsumedEvent = mBar.interceptTouchEvent(event);

        if (DEBUG_GESTURES) {
            if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
                EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
                        event.getActionMasked(), (int) event.getX(), (int) event.getY(),
                        barConsumedEvent ? 1 : 0);
            }
        }

        return barConsumedEvent || super.onTouchEvent(event);
    }
  • 位置:packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java
	private void dispatchTouchEvent(MotionEvent ev) {
		// add start
        int supportExpand = Settings.System.getInt(
                mLauncher.getContentResolver(), Settings.System.SUPPORT_PANELBAR_EXPAND, 0);
        if (mSystemUiProxy.isActive() && supportExpand==1) {
        // add end
            mLastAction = ev.getActionMasked();
            mSystemUiProxy.onStatusBarMotionEvent(ev);
        }
    }

导航栏显示的控制

  • frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
	// add start
	import android.content.ContentResolver;
	import android.database.ContentObserver;
	import android.provider.Settings;
	// end
	
	...
	
	// add start
	private final Object mLock = new Object();
    private SettingsObserver mSettingsObserver;
    private boolean mSupportPanelExpand;
    private boolean mShowNavigationbar;
    // end
    
    ...
	// add start
   	private final class SettingsObserver extends ContentObserver {
        public SettingsObserver(Handler handler) {
            super(handler);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            synchronized (mLock) {
                updateSettingsLocked();
                if (mShowNavigationbar){
                    createNavigationBar(null);
                } else {
                    removeNavigationBar();
                }
            }
         }
    }

    private void updateSettingsLocked() {
        final ContentResolver resolver = mContext.getContentResolver();

        mShowNavigationbar = (Settings.System.getInt(resolver,
                Settings.System.NAVIGATIONBAR_ENABLED, 0)) == 1;
    }   
    // add end
    
    // ================================================================================
    // Constructing the view
    // ================================================================================
    protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) {
        final Context context = mContext;
        updateDisplaySize(); // populates mDisplayMetrics
        updateResources();
        updateTheme();
    	...
    	// add start
    	// Register for settings changes.
        mSettingsObserver = new SettingsObserver(mHandler);
        final ContentResolver resolver = mContext.getContentResolver();
        resolver.registerContentObserver(Settings.System.getUriFor(
                Settings.System.NAVIGATIONBAR_ENABLED),
                false, mSettingsObserver);
        updateSettingsLocked();

        if (mShowNavigationbar){
            createNavigationBar(result);
        }
        // add end
    }
    
    ...
    
    protected void createNavigationBar(@Nullable RegisterStatusBarResult result) {
        mNavigationBarController.createNavigationBars(true /* includeDefaultDisplay */, result);
    }
	// add start
    protected void removeNavigationBar() {
        mNavigationBarController.removeNavigationBar();
    }
    // add end
  • 位置:frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
	// add start
    public void removeNavigationBar() {
        Display[] displays = mDisplayManager.getDisplays();
        for (Display display : displays) {
             removeNavigationBar(display.getDisplayId());
        }
    }
    // add end

配置默认值

  • 位置:frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
	private void loadSystemSettings(SQLiteDatabase db) {
        SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                    + " VALUES(?,?);");

            loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
                    R.bool.def_dim_screen);
            loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                    R.integer.def_screen_off_timeout);

			// add start
            loadBooleanSetting(stmt, Settings.System.NAVIGATIONBAR_ENABLED,
                    R.bool.def_navigationbar_enabled);
            loadBooleanSetting(stmt, Settings.System.SUPPORT_PANELBAR_EXPAND,
                    R.bool.def_support_panelbar_expand);
            // end        
            ...
    }
  • frameworks/base/packages/SettingsProvider/res/values/defaults.xml
	// add start
	<bool name="def_navigationbar_enabled">false</bool>
    <bool name="def_support_panelbar_expand">false</bool>
    // end

http://www.kler.cn/a/287471.html

相关文章:

  • OceanBase 分区表详解
  • 华为ensp实验二--mux vlan的应用
  • MYSQL_深入理解自连接_图书借阅情况(2/2)
  • Istio分布式链路监控搭建:Jaeger与Zipkin
  • 树的直径计算:算法详解与实现
  • 深入理解 C++ 二叉树
  • 【实用干货】5大自动化测试的Python框架!
  • 【千帆AppBuilder】使用Python调用基于官方的API创建图片故事的应用,一起体验下全代码模式下是怎样的效果
  • Kaggle竞赛——手写数字识别(Digit Recognizer)
  • 【第三版 系统集成项目管理工程师】第14章 收尾过程组
  • gateway的学习
  • 深度学习中Embedding的理解
  • pod进阶:
  • [M二叉树] lc199. 二叉树的右视图(dfs+自顶向下+好题)
  • 使用 SASS 编写高效 CSS
  • CentOS 7安装和配置 NFS
  • [Doc][px4][ros2][gazebo][yolov8]PX4-ROS2-Gazebo-YOLOv8
  • 数据仓库系列10:如何处理维度表中的变化类型?
  • Shell 脚本入门指南
  • 深度学习100问24:什么是语言模型
  • 基于混沌麻雀搜索算法的光伏MPPT控制MATLAB仿真
  • 文章_Linux运维_在非docker环境中编译安装docker
  • java 二级列表 stream流实现
  • 力扣经典题目之->另一颗树的子树(subRoot是否是root的子树)
  • 【STM32 Blue Pill编程】-ADC数据采样(轮询、中断和DMA模式)
  • Linux使用openssl生成ssl证书