Android8.0中下拉状态栏里面的进度条是下面的样子:
我们需要定制成下面的样子(在原生的基础上我们还增加了自动调节亮度的功能):
这里面把代码直接贴出来了,方便大家的使用和修改。如果有什么问题可以在留言哦!
frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
///xiangzaixiansheng for UI@{
import com.android.systemui.settings.ToggleSlider;
import android.widget.CheckBox;
///}@
public QSPanel(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
setOrientation(VERTICAL);
mBrightnessView = LayoutInflater.from(context).inflate(
R.layout.quick_settings_brightness_dialog, this, false);
// addView(mBrightnessView);xiangzaixiansheng
setupTileLayout();
mPageIndicator = LayoutInflater.from(context).inflate(
R.layout.qs_page_indicator, this, false);
addView(mPageIndicator);
//移动位置xiangzaixiansheng
addView(mBrightnessView);
//}@
if (mTileLayout instanceof PagedTileLayout) {
((PagedTileLayout) mTileLayout).setPageIndicator((PageIndicator) mPageIndicator);
}
addDivider();
mFooter = new QSSecurityFooter(this, context);
addView(mFooter.getView());
updateResources();
/* mBrightnessController = new BrightnessController(getContext(),
findViewById(R.id.brightness_icon),
findViewById(R.id.brightness_slider));**/
//修改样式 xiangzaixiansheng
mBrightnessController = new BrightnessController(getContext(),
(ImageView) findViewById(R.id.brightness_icon),
(ToggleSlider) findViewById(R.id.brightness_slider),
(CheckBox) findViewById(R.id.brightness_auto));
}
frameworks/base/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
///xiangzaixiansheng for UI@{
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.CheckBox;
///}@
///xiangzaixiansheng for UI 修改值为true@{
private static final boolean SHOW_AUTOMATIC_ICON = true;
///}@
///xiangzaixiansheng for UI@{
private CheckBox mAutoBrightness;
///}@
private final Runnable mUpdateModeRunnable = new Runnable() {
@Override
public void run() {
if (mAutomaticAvailable) {
int automatic;
automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
UserHandle.USER_CURRENT);
mAutomatic = automatic != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
mHandler.obtainMessage(MSG_UPDATE_ICON, mAutomatic ? 1 : 0).sendToTarget();
} else {
mHandler.obtainMessage(MSG_SET_CHECKED, 0).sendToTarget();
mHandler.obtainMessage(MSG_UPDATE_ICON, 0 /* automatic */).sendToTarget();
}
///xiangzaixiansheng for ui @{
if (mAutoBrightness != null) {
mAutoBrightness.setChecked(Settings.System.getInt(
mContext.getContentResolver(),
SCREEN_BRIGHTNESS_MODE,
SCREEN_BRIGHTNESS_MODE_MANUAL) != SCREEN_BRIGHTNESS_MODE_MANUAL);
}
///M:}@
}
};
///xiangzaixiansheng for ui@{
public BrightnessController(Context context, ImageView icon,
ToggleSlider control, CheckBox autoBrightness) {
this(context, icon, control);
mAutoBrightness = autoBrightness;
mAutoBrightness.setChecked(Settings.System.getInt(
mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
SCREEN_BRIGHTNESS_MODE_MANUAL) != SCREEN_BRIGHTNESS_MODE_MANUAL);
mAutoBrightness.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Settings.System.putInt(mContext.getContentResolver(),
SCREEN_BRIGHTNESS_MODE,
isChecked ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC :
SCREEN_BRIGHTNESS_MODE_MANUAL);
}
});
}
///}@
public void addStateChangedCallback(BrightnessStateChangeCallback cb) {
mChangeCallbacks.add(cb);
}
frameworks/base/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml
添加下面的文字和相应的checkbox即可。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:text="@string/status_bar_settings_auto_brightness_label"
/>
<CheckBox
android:id="@+id/brightness_auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="12sp"
/>
我们还需要改变滑动亮度调节时的样式:
现在是:
做成在调节亮度时,不会启动BrightnessMirrorController
这里面我们frameworks/base/packages/SystemUI/res/layout/brightness_mirror.xml修改background的值。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:elevation="2dp">
<include layout="@layout/quick_settings_brightness_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
然后在frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java
private ViewPropertyAnimator outAnimation(ViewPropertyAnimator a) {
///xiangzaixiansheng @{
return a.alpha(1.0f)
///}@
.setDuration(TRANSITION_DURATION_OUT)
.setInterpolator(Interpolators.ALPHA_OUT)
.withEndAction(null);
}