热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

[Android开发]Android音量及屏幕亮度调节

屏幕亮度调节/***滑动改变亮度*



屏幕亮度调节

/**
* 滑动改变亮度
* @param percent
*/
private void onBrightnessSlide(float percent) {
if (mBrightness <0) { // mBrightness是当前屏幕的亮度
mBrightness = getWindow().getAttributes().screenBrightness;
if (mBrightness <= 0.00f)
mBrightness = 0.50f;
if (mBrightness <0.01f)
mBrightness = 0.01f;
// 显示
mOperationBg.setImageResource(R.drawable.video_brightness_bg);
mVolumeBrightnessLayout.setVisibility(View.VISIBLE);
}
WindowManager.LayoutParams lpa = getWindow().getAttributes();
lpa.screenBrightness = mBrightness + percent;
if (lpa.screenBrightness > 1.0f)
lpa.screenBrightness = 1.0f;
else if (lpa.screenBrightness <0.01f)
lpa.screenBrightness = 0.01f;
getWindow().setAttributes(lpa);
ViewGroup.LayoutParams lp = mOperationPercent.getLayoutParams(); //这部分是改变图片上面的当前亮度的进度的
lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);
mOperationPercent.setLayoutParams(lp);
}

音量调节

/**
* 音量调节
*/
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private AudioManager mAudioManager;
private int currentVolume;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
// 最大音量
int maxVolume = mAudioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
Log.i(TAG, "最大音量:" + maxVolume);
currentVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
Log.i(TAG, "当前音量:" + currentVolume);
}
public void up(View view) {
// 音量增大
// AudioManager.STREAM_SYSTEM
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FX_FOCUS_NAVIGATION_UP);
currentVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
Log.i(TAG, "当前音量:" + currentVolume);
}
public void down(View view) {
// 音量减小
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP);
currentVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
Log.i(TAG, "当前音量:" + currentVolume);
}
}


推荐阅读
author-avatar
跑不快的码
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有