欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android中 视频屏幕左半部分上下滑动改变亮度右半部分上下滑动改变声音

程序员文章站 2024-03-05 21:25:31
说明: 实现功能: (1)屏幕右半部分上滑,声音变大,下滑,声音变小 屏幕左半部分上滑,亮度变大,下滑,亮度变小 (2)如果亮度>1或者小于0.2时,手机震动...

说明:

实现功能:

(1)屏幕右半部分上滑,声音变大,下滑,声音变小 屏幕左半部分上滑,亮度变大,下滑,亮度变小

(2)如果亮度>1或者小于0.2时,手机震动

private float starty;//记录手指按下时的y坐标
private float startx;//记录手指按下时的y坐标
private int downvol;//记录手指按下时的音量
private vibrator vibrator;//手机震动器
//不要忘记震动权限<uses-permission android:name="android.permission.vibrate" />
/*
* 设置屏幕亮度 lp = 0 全暗 ,lp= -1,根据系统设置, lp = 1; 最亮
*/
public void setbrightness(float brightness) {
windowmanager.layoutparams lp = getwindow().getattributes();
// if (lp.screenbrightness <= 0.1) {
// return;
// }
lp.screenbrightness = lp.screenbrightness + brightness / 255.0f;
if (lp.screenbrightness > 1) {
lp.screenbrightness = 1;
vibrator = (vibrator) getsystemservice(vibrator_service);
long[] pattern = { 10, 200 }; // off/on/off/on... 关闭10秒震动200毫秒,不停切换
vibrator.vibrate(pattern, -1);
} else if (lp.screenbrightness < 0.2) {
lp.screenbrightness = (float) 0.2;
vibrator = (vibrator) getsystemservice(vibrator_service);
long[] pattern = { 10, 200 }; // off/on/off/on...
vibrator.vibrate(pattern, -1);
}
getwindow().setattributes(lp);
}
@override
public boolean ontouchevent(motionevent event) {
//把事件传递给手势识别器(注:对事件只进行了解析处理,没有拦截,解析成手势识别的单击、双击、长按)
detector.ontouchevent(event);
switch (event.getaction()) {
case motionevent.action_down :
starty=event.gety();
startx=event.getx();
downvol=audiomanager.getstreamvolume(audiomanager.stream_music);
handler.removemessages(hide_control);
break;
case motionevent.action_move :
float endy=event.gety();
float distancey=starty-endy;
if(startx>screenwidth/2){
//屏幕右半部分上滑,声音变大,下滑,声音变小
int touchrang=math.min(screenwidth,screenheight);
//int curvol= (int) (downvol+(distance/screenheight)*maxvolume);
int curvol= (int) (downvol+(distancey/touchrang)*maxvolume);//考虑到横竖屏切换的问题
int volume=math.min(math.max(0,curvol),maxvolume);
updatevolume(volume);
}else{
//屏幕左半部分上滑,亮度变大,下滑,亮度变小
final double fling_min_distance = 0.5;
final double fling_min_velocity = 0.5;
if (distancey > fling_min_distance && math.abs(distancey) > fling_min_velocity) {
setbrightness(20);
}
if (distancey < fling_min_distance
&& math.abs(distancey) > fling_min_velocity) {
setbrightness(-20);
}
}
break;
case motionevent.action_up :
handler.sendemptymessagedelayed(hide_control,5000);
break;
}
return super.ontouchevent(event);
}

以上所述是小编给大家介绍的android中 视频屏幕左半部分上下滑动改变亮度右半部分上下滑动改变声音 ,希望对大家有所帮助