package com.jit.video
import android.app.Activity
import android.content.ContentResolver
import android.provider.Settings
import android.view.WindowManager
import android.widget.Toast
import android.provider.Settings.System
public class LightnessController {
// 判断是否开启了自动亮度调节
public static boolean isAutoBrightness(Activity act) {
boolean automicBrightness = false
ContentResolver aContentResolver = act.getContentResolver()
try {
automicBrightness = Settings.System.getInt(aContentResolver,
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
} catch (Exception e) {
Toast.makeText(act, "无法获取亮度", Toast.LENGTH_SHORT).show()
}
return automicBrightness
}
// 改变亮度
public static void setLightness(Activity act, int value) {
try {
System.putInt(act.getContentResolver(), System.SCREEN_BRIGHTNESS, value)
WindowManager.LayoutParams lp = act.getWindow().getAttributes()
lp.screenBrightness = (value <= 0 ? 1 : value) / 255f
act.getWindow().setAttributes(lp)
} catch (Exception e) {
Toast.makeText(act, "无法改变亮度", Toast.LENGTH_SHORT).show()
}
}
// 获取亮度
public static int getLightness(Activity act) {
return System.getInt(act.getContentResolver(), System.SCREEN_BRIGHTNESS, -1)
}
// 停止自动亮度调节
public static void stopAutoBrightness(Activity activity) {
Settings.System.putInt(activity.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL)
}
// 开启亮度自动调节
public static void startAutoBrightness(Activity activity) {
Settings.System.putInt(activity.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC)
}
}
private AudioManager mAudioManager;
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
private void volumeDown(float delatY) {
int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int current = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int down = (int) (delatY / height * max * 3);
int volume = Math.max(current - down, 0);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
int transformatVolume = volume * 100 / max;
volumnController.show(transformatVolume);
}
private void volumeUp(float delatY) {
int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int current = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int up = (int) ((delatY / height) * max * 3);
int volume = Math.min(current + up, max);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
int transformatVolume = volume * 100 / max;
volumnController.show(transformatVolume);
}
package com.jit.video;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
public class VolumnController {
private Toast t;
private VolumnView tv;
private Context context;
public VolumnController(Context context) {
this.context = context;
}
public void show(float progress) {
if (t == null) {
t = new Toast(context);
View layout = LayoutInflater.from(context).inflate(R.layout.vv, null);
tv = (VolumnView) layout.findViewById(R.id.volumnView);
t.setView(layout);
t.setGravity(Gravity.BOTTOM, 0, 100);
t.setDuration(Toast.LENGTH_SHORT);
}
tv.setProgress(progress);
t.show();
}
}
package com.jit.video;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
/**
* 仿小米声音调节环形进度条
*/
public class VolumnView extends View {
float r1 = 0;
float r2 = 0;
float r3 = 0;
float w1 = 15;
float w2 = 30;
Paint paint;
float progress = 0;
Bitmap bitmap;
RectF oval;
public VolumnView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
public VolumnView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public VolumnView(Context context) {
super(context);
init(context);
}
void init(Context context) {
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Style.STROKE);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ling);
}
@Override
protected void onDraw(Canvas canvas) {
float cx = getMeasuredWidth() / 2;
float cy = getMeasuredHeight() / 2;
r1 = cx - w1 / 2;
r2 = cx - w1 / 2 - w2 / 2;
r3 = cx - w1 / 2 - w2;
paint.setStrokeWidth(w1);
paint.setColor(Color.parseColor("#454547"));
canvas.drawCircle(cx, cy, r1, paint);
paint.setColor(Color.parseColor("#747476"));
paint.setStrokeWidth(w2);
canvas.drawCircle(cx, cy, r2, paint);
paint.setColor(Color.parseColor("#464648"));
paint.setStyle(Style.FILL);
canvas.drawCircle(cx, cy, r3, paint);
canvas.drawBitmap(bitmap, cx - bitmap.getWidth() / 2,
cx - bitmap.getHeight() / 2, paint);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(0);
paint.setTextSize(40);
float textWidth = paint.measureText("铃声");
canvas.drawText("铃声", cx - textWidth / 2, cx + bitmap.getHeight() / 2
+ 40, paint);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(w2);
paint.setColor(Color.WHITE);
if (oval == null) {
oval = new RectF(cx - r2, cy - r2, cx + r2, cy + r2);
}
canvas.drawArc(oval, 270, 360 * progress / 100, false, paint);
super.onDraw(canvas);
}
/**
* 设置进度
*
* @param progress
* 范围(0-100)
*/
public void setProgress(float progress) {
this.progress = progress;
if (this.progress >= 100)
this.progress = 100;
if (this.progress <= 0)
this.progress = 0;
postInvalidate();
}
}