system ui 升级更改的一些基础配置

 

设置  systemUI

 

  1. 设置虚拟键颜色 成#FAFAFA效果

  frameworks/base / core/java/com/android/internal/policy/PhoneWindow.java

 private void resetLightNavigationbar(View view,TypedArray a) {
   ......
   mNavigationBarColor = Color.argb(255, 250, 250, 250);
   .....

}

 brightness_bar设置

手电筒照明 level设置

打开蓝牙状态栏显示蓝牙图标 PhoneStatusBarPolicy.java

关闭飞行模式, 打开 流量和 wifi 开关

响铃/振动/静音 3种状态切换

修改 tile的跳转应用和 图标文字

  //title 的配置

 frameworks/base / packages/SystemUI/extApp/res/values/config.xml

<string name="quick_settings_tiles_default" translatable="false">   <string>

<string name="quick_settings_tiles_stock" translatable="false">   <string>

  ---- 亮度条

 修改UI布局和参数

  frameworks/base / packages/SystemUI/res/layout/brightness_mirror.xml

  frameworks/base / packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml

  frameworks/base / packages/SystemUI/res/layout/status_bar_toggle_slider.xml

  frameworks/base / packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java

//更新图标

private void updateIcon(boolean automatic) {

}

 

 手电筒----

  /frameworks/base / packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java

 private FlashlightDetailAdapter() {
      mSlider = null;
      mWarningTextView = null;

      //滑动seekbar监听
      torchLevelChangedListener = new OnSeekBarChangeListener() {
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
              if (fromUser) {
                   if (mWarningTextView != null) {
                         if (progress == 4) {
                                mWarningTextView.setVisibility(View.VISIBLE);
                         } else {
                                mWarningTextView.setVisibility(View.GONE);
                         }

       Log.d(TAG,"torchLevel:"+ progress);
       mFlashlightController.setFlashlightLevel(progress, true);

}

//更新
public void updateDetailView(final boolean state) {
   int level = mFlashlightController.getFlashlightLevel();
    if (mSlider != null) {
                        mSlider.setProgress(level);

}

/frameworks/base / packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightController.

java

    void setFlashlightLevel(int level, boolean toSettings);
    int  getFlashlightLevel();

  frameworks/base / packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightControllerImpl.java

 private int mFlashlightLevel;
    public static final String KEY_FLASH_LEVEL = "Flashlight_brightness_level";

    private FlashlightBrightnessObserver mFlashlightBrightnessObserver = null;
    private class FlashlightBrightnessObserver extends ContentObserver {
        public FlashlightBrightnessObserver() {
            super(mHandler);
            mContext.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(KEY_FLASH_LEVEL),
                    false, this, -1);
            onChange(true);
        }

        public void onChange(boolean selfChange) {
            //mFlashlightLevel = convertToFlashlightLevel(Settings.System.getIntForUser(mContext.getContentResolver(), KEY_FLASH_LEVEL, -1, UserHandle.USER_CURRENT));
            mFlashlightLevel = Settings.System.getIntForUser(mContext.getContentResolver(), KEY_FLASH_LEVEL, 0, UserHandle.USER_CURRENT);
            Log.d(TAG, "FlashlightBrightnessObserver onReceive : " + mFlashlightLevel);
        }
    }
   
    //根据 value设置手电筒照亮等级
    public String convertToFlashlightLevel(int settingValue) {
        String level = "20";
        switch (settingValue) {
            case 0:
                level = "20";
                break;
            case 1:
                level = "40";
                break;
            case 2:
                level = "60";
                break;
            case 3:
                level = "80";
                break;
            case 4:
                level = "100";
                break;
        }
        return level;
    }

    public int getFlashlightLevel() {
        return mFlashlightLevel;
    }

    public void setFlashlightLevel(int level, boolean toSettings) {
        String progress = convertToFlashlightLevel(level);
        Log.d(TAG,"setFlashlight  Level:"+level+",progress:"+ progress );
        //写入led节点
        SysUIUtils.updateFlashLightBright(progress);
        if(toSettings) {
            Settings.System.putIntForUser(mContext.getContentResolver(), KEY_FLASH_LEVEL, level, UserHandle.USER_CURRENT);
        }
    }

-------------------声音模式 ----------------------------------

frameworks/base / packages/SystemUI/extApp/src/com/android/systemui/tiles/MuteTile.java

public class MuteTile extends QSTileImpl<QSTile.BooleanState> {

   @Override
    protected void handleClick() {
        LogUtils.d(TAG, "handleClick mRingMode: " + mRingerMode);
        int modeRecord = mModeRecord.getValue();

        //更改点击事件切换的顺序
        if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
            mRingerMode =  AudioManager.RINGER_MODE_NORMAL;
        } else if (modeRecord == AudioManager.RINGER_MODE_VIBRATE) {
            mRingerMode = AudioManager.RINGER_MODE_SILENT;
        } else if (modeRecord == AudioManager.RINGER_MODE_NORMAL) {
            mRingerMode = AudioManager.RINGER_MODE_VIBRATE;
        }
        //设置声音模式
        mModeRecord.setValue(mRingerMode);
        mController = Dependency.get(VolumeDialogController.class);
        mController.setRingerMode(mRingerMode, false);
        //mAudioManager.setRingerModeInternal(mRingerMode);
        refreshState(Integer.valueOf(mRingerMode));
    }


 @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        LogUtils.d(TAG, "handleUpdateState mRingerMode: " + mRingerMode);

       //state.label = mContext.getString(R.string.mute);
       //state.icon = ResourceIcon.get(R.drawable.wos_ic_qs_mute);
       // if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
       //    state.contentDescription = state.label;
       //     state.state = Tile.STATE_ACTIVE;
       //  } else {
       //      state.contentDescription = state.label;
       // state.state = Tile.STATE_INACTIVE;

        state.value = true;
        state.icon = getMuteIcon();
        state.label = getMuteLable();
        state.state = Tile.STATE_ACTIVE;
        if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
            state.contentDescription = state.label;
        }else if(mRingerMode == AudioManager.RINGER_MODE_VIBRATE){
            state.contentDescription = state.label;
        }else if(mRingerMode == AudioManager.RINGER_MODE_NORMAL){
            state.contentDescription = state.label;
        }
    }
  //修改显示lable
  public String getMuteLable() {
        if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
            return mContext.getString(R.string.mute);
        } else if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
            return mContext.getString(R.string.vibrate);
        } else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
            return mContext.getString(R.string.sound);
        } else {
            return "";
        }
    }
   //修改icon
    public Icon getMuteIcon() {
        if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
            return ResourceIcon.get(R.drawable.wos_ic_qs_mute);
        } else if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
            return ResourceIcon.get(R.drawable.wos_ic_qs_mute_shake);
        } else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
            return ResourceIcon.get(R.drawable.wos_ic_qs_mute_ring);
        } else {
            return ResourceIcon.get(R.drawable.wos_ic_qs_mute_ring);
        }
    }
}

------------------ 飞行模式-----------------------

/frameworks/base / packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java

protected void handleUpdateState(BooleanState state, Object arg) {

   ............
   ............

   //req关闭 飞行模式时,打开wifi ,mobile data
  if(SystemUIFeature.SUPPORT_2.1){
            boolean airplaneModeEnabled = state.value;
            if(!airplaneModeEnabled){

                //enable wifi

                NetworkController mController = Dependency.get(NetworkController.class);
                mController.setWifiEnabled(true);

                //enable mobile data
                DataUsageController mDataController = 
                mController.getMobileDataController();

                mDataController.setMobileDataEnabled(true);
            }
        }

}

 ---------打开蓝牙,显示图标------

  /frameworks/base / packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

rivate final void updateBluetooth() {
        int iconId = R.drawable.stat_sys_data_bluetooth;
        String contentDescription =
                mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
        boolean bluetoothVisible = false;
        if (mBluetooth != null) {
         //enable
        +     bluetoothVisible = mBluetooth.isBluetoothEnabled();
            if (mBluetooth.isBluetoothConnected()) {
                iconId = R.drawable.stat_sys_data_bluetooth_connected;
                contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);

         -     bluetoothVisible = mBluetooth.isBluetoothEnabled();

            }
        }
        
        mIconController.setIcon(mSlotBluetooth, iconId, contentDescription);
        //visibile
        mIconController.setIconVisibility(mSlotBluetooth, bluetoothVisible);
    }

  ---------------网络设置跳转 --------------------

frameworks/base / packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java   

 static Intent getCellularSettingIntent() {
        if (SystemUIFeature.SUPPORT_ROM ) {
            return new Intent().setComponent(new 
          ComponentName("com.qualcomm.qti.networksetting",
                    "com.qualcomm.qti.networksetting.MobileNetworkSettings"));
        } else {
            return new Intent(Settings.ACTION_DATA_USAGE_SETTINGS);
        }
    }

 

/frameworks/base / packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java

 @Override
 public CharSequence getTileLabel() {
        return SystemUIFeature.SUPPORT_ROM  ? mContext.getString(R.string.quick_settings_disturb_label)
                : mContext.getString(R.string.quick_settings_dnd_label);
    }


 @Override
  protected void handleUpdateState(BooleanState state, Object arg) {

        ....
        state.value = newValue;
        state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        state.slash.isSlashed = !state.value;
        state.label = getTileLabel();
        state.secondaryLabel = TextUtils.emptyIfNull(ZenModeConfig.getDescription(mContext,
                zen != Global.ZEN_MODE_OFF, mController.getConfig(), false));

        //update icon

      state.icon =SystemUIFeature.SUPPORT_ROM  ?ResourceIcon.get(R.drawable.ic_qs_disturb):

                 ResourceIcon.get(R.drawable.ic_mi_qs_disturb);;
   }


 @Override
 public View createDetailView(Context context, View convertView, ViewGroup parent) {

           if (convertView == null) {
              mZenPanel.init(mController);
              mZenPanel.addOnAttachStateChangeListener(this);
              mZenPanel.setCallback(mZenModePanelCallback);

              //update icon
              mZenPanel.setEmptyState(R.drawable.ic_qs_disturb, R.string.dnd_is_off);
            }
      }

 

 

 

上一篇:Android 自定义进度条


下一篇:Android P 音频焦点管理