|
@@ -13,17 +13,17 @@ import android.hardware.Camera.AutoFocusCallback;
|
|
import android.hardware.Camera.Parameters;
|
|
import android.hardware.Camera.Parameters;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
-import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
import android.view.SurfaceView;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
import android.widget.RemoteViews;
|
|
import android.widget.RemoteViews;
|
|
|
|
+import me.yoqi.flashlight.utils.DroidLED;
|
|
|
|
|
|
public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
|
|
|
|
int count = 0;
|
|
int count = 0;
|
|
- static Camera mCameraActivity;
|
|
|
|
|
|
+ static Camera mCamera;
|
|
static Button flashlight_button;
|
|
static Button flashlight_button;
|
|
Parameters params;
|
|
Parameters params;
|
|
SurfaceView preview;
|
|
SurfaceView preview;
|
|
@@ -42,8 +42,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
setWidgetTo(R.drawable.light_on);
|
|
setWidgetTo(R.drawable.light_on);
|
|
}
|
|
}
|
|
|
|
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
-
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
try {
|
|
try {
|
|
flashOffApp();
|
|
flashOffApp();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -109,7 +108,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
|
|
|
|
try {
|
|
try {
|
|
flashOffApp();
|
|
flashOffApp();
|
|
@@ -143,7 +142,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
flashlight_button.setBackgroundResource(R.drawable.light_off);
|
|
flashlight_button.setBackgroundResource(R.drawable.light_off);
|
|
setWidgetTo(R.drawable.light_off);
|
|
setWidgetTo(R.drawable.light_off);
|
|
|
|
|
|
- if (getmCameraActivity() == null) {
|
|
|
|
|
|
+ if (getmCamera() == null) {
|
|
try {
|
|
try {
|
|
mHolder.addCallback(this);
|
|
mHolder.addCallback(this);
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
@@ -152,7 +151,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
setmCameraActivity(Camera.open());
|
|
setmCameraActivity(Camera.open());
|
|
try {
|
|
try {
|
|
if (mHolder != null) {
|
|
if (mHolder != null) {
|
|
- getmCameraActivity().setPreviewDisplay(mHolder);
|
|
|
|
|
|
+ getmCamera().setPreviewDisplay(mHolder);
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -162,7 +161,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
flashOnApp();
|
|
flashOnApp();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -175,7 +174,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
}
|
|
}
|
|
|
|
|
|
private void flashOnApp() {
|
|
private void flashOnApp() {
|
|
- setParams(getmCameraActivity().getParameters());
|
|
|
|
|
|
+ setParams(getmCamera().getParameters());
|
|
|
|
|
|
List<String> flashModes = getParams().getSupportedFlashModes();
|
|
List<String> flashModes = getParams().getSupportedFlashModes();
|
|
|
|
|
|
@@ -184,13 +183,13 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
} else {
|
|
} else {
|
|
if (count == 0) {
|
|
if (count == 0) {
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_OFF);
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_OFF);
|
|
- getmCameraActivity().setParameters(getParams());
|
|
|
|
|
|
+ getmCamera().setParameters(getParams());
|
|
preview = (SurfaceView) findViewById(R.id.preview);
|
|
preview = (SurfaceView) findViewById(R.id.preview);
|
|
mHolder = preview.getHolder();
|
|
mHolder = preview.getHolder();
|
|
mHolder.addCallback(this);
|
|
mHolder.addCallback(this);
|
|
|
|
|
|
try {
|
|
try {
|
|
- getmCameraActivity().startPreview();
|
|
|
|
|
|
+ getmCamera().startPreview();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
|
@@ -205,13 +204,13 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
|
|
|
|
if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
|
|
if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_TORCH);
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_TORCH);
|
|
- getmCameraActivity().setParameters(getParams());
|
|
|
|
|
|
+ getmCamera().setParameters(getParams());
|
|
} else {
|
|
} else {
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_ON);
|
|
getParams().setFlashMode(Parameters.FLASH_MODE_ON);
|
|
|
|
|
|
- getmCameraActivity().setParameters(getParams());
|
|
|
|
|
|
+ getmCamera().setParameters(getParams());
|
|
try {
|
|
try {
|
|
- getmCameraActivity().autoFocus(new AutoFocusCallback() {
|
|
|
|
|
|
+ getmCamera().autoFocus(new AutoFocusCallback() {
|
|
public void onAutoFocus(boolean success,
|
|
public void onAutoFocus(boolean success,
|
|
Camera camera) {
|
|
Camera camera) {
|
|
count = 1;
|
|
count = 1;
|
|
@@ -306,7 +305,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
flashlight_button.setBackgroundResource(R.drawable.light_on);
|
|
flashlight_button.setBackgroundResource(R.drawable.light_on);
|
|
setWidgetTo(R.drawable.light_on);
|
|
setWidgetTo(R.drawable.light_on);
|
|
|
|
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
count = 0;
|
|
count = 0;
|
|
flashOffApp();
|
|
flashOffApp();
|
|
}
|
|
}
|
|
@@ -322,8 +321,8 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
|
|
|
|
// Turns the LED off when the button on the app is pressed.
|
|
// Turns the LED off when the button on the app is pressed.
|
|
private void flashOffApp() {
|
|
private void flashOffApp() {
|
|
- getmCameraActivity().stopPreview();
|
|
|
|
- getmCameraActivity().release();
|
|
|
|
|
|
+ getmCamera().stopPreview();
|
|
|
|
+ getmCamera().release();
|
|
setmCameraActivity(null);
|
|
setmCameraActivity(null);
|
|
MyApplication.setIsFlashOn(false);
|
|
MyApplication.setIsFlashOn(false);
|
|
}
|
|
}
|
|
@@ -367,9 +366,9 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
mHolder = holder;
|
|
mHolder = holder;
|
|
mHolder.addCallback(this);
|
|
mHolder.addCallback(this);
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
try {
|
|
try {
|
|
- getmCameraActivity().setPreviewDisplay(mHolder);
|
|
|
|
|
|
+ getmCamera().setPreviewDisplay(mHolder);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -382,9 +381,9 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
mHolder = holder;
|
|
mHolder = holder;
|
|
mHolder.addCallback(this);
|
|
mHolder.addCallback(this);
|
|
|
|
|
|
- if (getmCameraActivity() != null) {
|
|
|
|
|
|
+ if (getmCamera() != null) {
|
|
try {
|
|
try {
|
|
- getmCameraActivity().setPreviewDisplay(mHolder);
|
|
|
|
|
|
+ getmCamera().setPreviewDisplay(mHolder);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -397,13 +396,12 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {
|
|
mHolder = null;
|
|
mHolder = null;
|
|
}
|
|
}
|
|
|
|
|
|
- // Getters and setters for mCameraActivity.
|
|
|
|
- public static Camera getmCameraActivity() {
|
|
|
|
- return mCameraActivity;
|
|
|
|
|
|
+ public static Camera getmCamera() {
|
|
|
|
+ return mCamera;
|
|
}
|
|
}
|
|
|
|
|
|
public static void setmCameraActivity(Camera mCameraActivity) {
|
|
public static void setmCameraActivity(Camera mCameraActivity) {
|
|
- MainActivity.mCameraActivity = mCameraActivity;
|
|
|
|
|
|
+ MainActivity.mCamera = mCameraActivity;
|
|
}
|
|
}
|
|
|
|
|
|
// Getters and setters for params.
|
|
// Getters and setters for params.
|