update the bright display and strobo icons + misc adjustments
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.hardware.camera2.CameraAccessException;
|
import android.hardware.camera2.CameraAccessException;
|
||||||
import android.hardware.camera2.CameraManager;
|
import android.hardware.camera2.CameraManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
@ -14,9 +15,11 @@ class MarshmallowCamera {
|
|||||||
|
|
||||||
private CameraManager manager;
|
private CameraManager manager;
|
||||||
private String cameraId;
|
private String cameraId;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
MarshmallowCamera(Context context) {
|
MarshmallowCamera(Context context) {
|
||||||
|
mContext = context;
|
||||||
manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
||||||
try {
|
try {
|
||||||
final String[] list = manager.getCameraIdList();
|
final String[] list = manager.getCameraIdList();
|
||||||
@ -31,7 +34,14 @@ class MarshmallowCamera {
|
|||||||
manager.setTorchMode(cameraId, enable);
|
manager.setTorchMode(cameraId, enable);
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
Log.e(TAG, "toggle marshmallow flashlight " + e.getMessage());
|
Log.e(TAG, "toggle marshmallow flashlight " + e.getMessage());
|
||||||
|
|
||||||
|
Runnable mainRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
bus.post(new Events.CameraUnavailable());
|
bus.post(new Events.CameraUnavailable());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
new Handler(mContext.getMainLooper()).post(mainRunnable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class MyCameraImpl {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopStroboscope() {
|
public void stopStroboscope() {
|
||||||
mShouldStroboscopeStop = true;
|
mShouldStroboscopeStop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ public class MyCameraImpl {
|
|||||||
|
|
||||||
if (mCamera != null) {
|
if (mCamera != null) {
|
||||||
mCamera.setParameters(torchOff);
|
mCamera.setParameters(torchOff);
|
||||||
if (!mShouldEnableFlashlight) {
|
if (!mShouldEnableFlashlight || mIsMarshmallow) {
|
||||||
mCamera.release();
|
mCamera.release();
|
||||||
mCamera = null;
|
mCamera = null;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@ public class MainActivity extends SimpleActivity {
|
|||||||
if (isCameraPermissionGranted()) {
|
if (isCameraPermissionGranted()) {
|
||||||
if (mCameraImpl.toggleStroboscope()) {
|
if (mCameraImpl.toggleStroboscope()) {
|
||||||
mStroboscopeBar.setVisibility(mStroboscopeBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
|
mStroboscopeBar.setVisibility(mStroboscopeBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
|
||||||
|
changeIconColor(mStroboscopeBar.getVisibility() == View.VISIBLE ? R.color.colorPrimary : R.color.translucent_white, mStroboscopeBtn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final String[] permissions = {Manifest.permission.CAMERA};
|
final String[] permissions = {Manifest.permission.CAMERA};
|
||||||
@ -156,8 +157,11 @@ public class MainActivity extends SimpleActivity {
|
|||||||
|
|
||||||
mBrightDisplayBtn.setVisibility(mConfig.getBrightDisplay() ? View.VISIBLE : View.GONE);
|
mBrightDisplayBtn.setVisibility(mConfig.getBrightDisplay() ? View.VISIBLE : View.GONE);
|
||||||
mStroboscopeBtn.setVisibility(mConfig.getStroboscope() ? View.VISIBLE : View.GONE);
|
mStroboscopeBtn.setVisibility(mConfig.getStroboscope() ? View.VISIBLE : View.GONE);
|
||||||
|
if (!mConfig.getStroboscope()) {
|
||||||
|
mCameraImpl.stopStroboscope();
|
||||||
mStroboscopeBar.setVisibility(View.INVISIBLE);
|
mStroboscopeBar.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
@ -193,6 +197,7 @@ public class MainActivity extends SimpleActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
|
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
|
||||||
changeIconColor(R.color.colorPrimary, mToggleBtn);
|
changeIconColor(R.color.colorPrimary, mToggleBtn);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/buttons_margin"
|
android:layout_marginTop="@dimen/buttons_margin"
|
||||||
android:background="@mipmap/bright_display"
|
android:background="@mipmap/stroboscope"
|
||||||
android:padding="@dimen/activity_margin"/>
|
android:padding="@dimen/activity_margin"/>
|
||||||
|
|
||||||
<SeekBar
|
<SeekBar
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/mipmap-hdpi/stroboscope.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 717 B After Width: | Height: | Size: 983 B |
BIN
app/src/main/res/mipmap-mdpi/stroboscope.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/stroboscope.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/stroboscope.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/stroboscope.png
Normal file
After Width: | Height: | Size: 4.6 KiB |