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

你可能感兴趣的:(Android12,系统修改与定制,panelbar,navigationbar)