package com.TestBrightness;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.TestBrightness.manager.SystemManager;
public class TestBrightness extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SystemManager.init(this);
showBrightnessSettingDialog();
}
@Override
public void onClick(View v) {
showBrightnessSettingDialog();
}
private int mOldBrightness;
private int mCurrentBrightness = 0;
private int mOldAutomatic;
private boolean mAutomaticAvailable;
/**
* Brightness value for dim backlight
*/
private static final int BRIGHTNESS_DIM = 20;
/**
* Brightness value for fully on
*/
private static final int BRIGHTNESS_ON = 255;
// Backlight range is from 0 - 255. Need to make sure that user
// doesn't set the backlight to 0 and get stuck
private static final int MINIMUM_BACKLIGHT = BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = BRIGHTNESS_ON;
private void showBrightnessSettingDialog(){
final SystemManager systemManager = SystemManager.getInstance();
final Builder builder = new AlertDialog.Builder(this);
final View view = getLayoutInflater().inflate(R.layout.brightness_view, null);
// set brightness seekbar
final SeekBar brightnessBar = (SeekBar) view.findViewById(R.id.brightness_bar);
brightnessBar.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT);
int brightness = systemManager.getScreenBrightness();
int process = brightness - MINIMUM_BACKLIGHT;
if (process<0) {
process = 0;
mOldBrightness = MINIMUM_BACKLIGHT;
mCurrentBrightness = MINIMUM_BACKLIGHT;
}else{
mOldBrightness = brightness;
mCurrentBrightness = brightness;
}
brightnessBar.setProgress(process);
// set automatic available checkbox
final CheckBox autoBrightness = (CheckBox)view.findViewById(R.id.auto_brightness);
mOldAutomatic = systemManager.getBrightnessMode();
mAutomaticAvailable = systemManager.isAutoBrightness();
autoBrightness.setChecked(mAutomaticAvailable);
if(mAutomaticAvailable){
brightnessBar.setVisibility(View.GONE);
}else{
brightnessBar.setVisibility(View.VISIBLE);
}
autoBrightness.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
mAutomaticAvailable = isChecked;
if(isChecked){
brightnessBar.setVisibility(View.GONE);
systemManager.startAutoBrightness();
//systemManager.setBrightness(MainActivity.this, systemManager.getScreenBrightness());
int process = systemManager.getScreenBrightness() - MINIMUM_BACKLIGHT;
if (process<0) {
process = 0;
}// end if
brightnessBar.setProgress(process);
}else{
brightnessBar.setVisibility(View.VISIBLE);
systemManager.stopAutoBrightness();
//systemManager.setBrightness(MainActivity.this, systemManager.getScreenBrightness());
int process = systemManager.getScreenBrightness() - MINIMUM_BACKLIGHT;
if (process<0) {
process = 0;
}// end if
brightnessBar.setProgress(process);
}
}
});
brightnessBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
}
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress,
final boolean fromUser) {
mCurrentBrightness = progress + MINIMUM_BACKLIGHT;
systemManager.setBrightness(TestBrightness.this, mCurrentBrightness);
}
});
builder.setTitle(R.string.brightness);
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(final DialogInterface dialog, final int which) {
// set brightness
if(mAutomaticAvailable){
systemManager.saveBrightness(systemManager.getScreenBrightness());
}else{
systemManager.saveBrightness(mCurrentBrightness);
}
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
// recover brightness
systemManager.setBrightness(TestBrightness.this, mOldBrightness);
systemManager.saveBrightness(mOldBrightness);
// recover automatic brightness mode
systemManager.setBrightnessMode(mOldAutomatic);
}
});
builder.show();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
App开发的教程-滑动屏幕调整屏幕亮度.zip
共40个文件
class:8个
png:7个
xml:7个
需积分: 1 0 下载量 26 浏览量
2024-07-19
16:44:01
上传
评论
收藏 128KB ZIP 举报
温馨提示
App开发的教程-滑动屏幕调整屏幕亮度,包含相关文档说明,供大家学习使用!
资源推荐
资源详情
资源评论
收起资源包目录
App开发的教程-滑动屏幕调整屏幕亮度.zip (40个子文件)
TestBrightness.zip 20KB
TestBrightness2
.classpath 280B
assets
src
cn
lkp
MainActivity.java 4KB
res
drawable-mdpi
icon.png 3KB
drawable-ldpi
icon.png 2KB
values
strings.xml 178B
layout
main.xml 383B
drawable-hdpi
icon.png 4KB
bin
TestBrightness2.apk 15KB
resources.ap_ 10KB
cn
lkp
MainActivity$1.class 2KB
R$string.class 391B
R$layout.class 358B
R$id.class 353B
R$attr.class 304B
R$drawable.class 364B
MainActivity.class 3KB
R.class 447B
classes.dex 5KB
proguard.cfg 1KB
default.properties 362B
.project 851B
AndroidManifest.xml 743B
gen
cn
lkp
R.java 728B
TestBrightness2.rar 44KB
TestBrightness
TestBrightness
.classpath 273B
assets
src
com
TestBrightness
manager
SystemManager.java 5KB
TestBrightness.java 6KB
res
drawable-mdpi
icon.png 3KB
drawable-ldpi
icon.png 2KB
values
strings.xml 299B
layout
brightness_view.xml 1KB
main.xml 536B
drawable-hdpi
btn_auto_brightness_default.png 2KB
icon.png 4KB
proguard.cfg 1KB
default.properties 362B
.project 850B
AndroidManifest.xml 756B
gen
com
TestBrightness
R.java 1KB
共 40 条
- 1
资源评论
ItKevin爱java
- 粉丝: 1370
- 资源: 350
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于javaWeb+servlet开发简单的购物车系统完整源码
- mondo rescue离线安装及系统恢复并且问题解决参考
- 学习的Python笔记,都是精华
- filmly-tv-1.3.11.1031.apk.1
- 2023-04-06-项目笔记 - 第三百一十五阶段 - 4.4.2.313全局变量的作用域-313 -2025.11.12
- SMO+PLL滑膜观测器、MARS模型参考自适应观测器simulink仿真
- MATLAB与数学实验课程 MATLAB上机实验题 综合实验.docx
- MATLAB与数学实验课程 MATLAB上机实验题 优化实验 优化模型.docx
- member&configSystem
- dbc s32k144 jkgjfdkl dgfdn
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功