赞
踩
public class SetUpActivity extends AppCompatActivity {
private TextView btnReturnTrend; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_set_up); if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); getWindow().setNavigationBarColor(Color.TRANSPARENT); getWindow().setStatusBarColor(Color.TRANSPARENT); } btnReturnTrend = findViewById(R.id.btnReturn); btnReturnTrend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(SetUpActivity.this,MainActivity.class)); finish(); } }); SeekBar seekBar = findViewById(R.id.seekBar); // 进度条绑定最大亮度,255是最大亮度 seekBar.setMax(255); // 取得当前亮度 int normal = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); // 进度条绑定当前亮度 seekBar.setProgress(normal); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //判断是否可以写入数据到系统 if (!Settings.System.canWrite(SetUpActivity.this)) { /* Intent i = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); i.setData(Uri.parse("package:" + SetUpActivity.this.getPackageName())); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); SetUpActivity.this.startActivity(i);*/ Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); } else { //处理逻辑 // 取得当前进度 int tmpInt = seekBar.getProgress(); // 当进度小于80时,设置成80,防止太黑看不见的后果。 if (tmpInt < 80) { tmpInt = 80; } // 根据当前进度改变亮度 Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, tmpInt); tmpInt = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, -1); WindowManager.LayoutParams wl = getWindow().getAttributes(); float tmpFloat = (float) tmpInt / 255; if (tmpFloat > 0 && tmpFloat <= 1) { wl.screenBrightness = tmpFloat; } getWindow().setAttributes(wl); } } } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub } }); }
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。