package com.net;
import com.hero.net.Tool;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
public class FlashLight extends Activity {
private Context context;
private Camera camera = null;
private Parameters parameters = null;
private boolean flag = false;
// 构造器
public FlashLight(Context context) {
this.context = context;
camera = Camera.open();
}
public boolean setFlashLight() {
parameters = camera.getParameters();
if (parameters.getFlashMode().equals("off")) {
Tool.ShowStatus(context, true, true, "FlashLight");
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
Tool.ShowStatus(context, false, true, "FlashLight");
flag = true;
} else {
Tool.ShowStatus(context, true, false, "FlashLight");
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
Tool.ShowStatus(context, false, false, "FlashLight");
flag = false;
}
return flag;
}
@Override
protected void onDestroy() {
camera.release();
super.onDestroy();
}
@Override
protected void onPause() {
if (flag) {
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
}
super.onPause();
}
@Override
protected void onPostResume() {
if (flag) {
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
}
super.onPostResume();
}
}