Skip to content

Commit ec5d7cf

Browse files
committed
update the bright display and strobo icons + misc adjustments
1 parent 167c26d commit ec5d7cf

File tree

14 files changed

+20
-5
lines changed

14 files changed

+20
-5
lines changed

app/src/main/java/com/simplemobiletools/flashlight/MarshmallowCamera.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.hardware.camera2.CameraAccessException;
66
import android.hardware.camera2.CameraManager;
77
import android.os.Build;
8+
import android.os.Handler;
89
import android.util.Log;
910

1011
import com.squareup.otto.Bus;
@@ -14,9 +15,11 @@ class MarshmallowCamera {
1415

1516
private CameraManager manager;
1617
private String cameraId;
18+
private Context mContext;
1719

1820
@TargetApi(Build.VERSION_CODES.M)
1921
MarshmallowCamera(Context context) {
22+
mContext = context;
2023
manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
2124
try {
2225
final String[] list = manager.getCameraIdList();
@@ -31,7 +34,14 @@ void toggleMarshmallowFlashlight(final Bus bus, boolean enable) {
3134
manager.setTorchMode(cameraId, enable);
3235
} catch (CameraAccessException e) {
3336
Log.e(TAG, "toggle marshmallow flashlight " + e.getMessage());
34-
bus.post(new Events.CameraUnavailable());
37+
38+
Runnable mainRunnable = new Runnable() {
39+
@Override
40+
public void run() {
41+
bus.post(new Events.CameraUnavailable());
42+
}
43+
};
44+
new Handler(mContext.getMainLooper()).post(mainRunnable);
3545
}
3646
}
3747
}

app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public boolean toggleStroboscope() {
6767
return true;
6868
}
6969

70-
private void stopStroboscope() {
70+
public void stopStroboscope() {
7171
mShouldStroboscopeStop = true;
7272
}
7373

@@ -221,7 +221,7 @@ public void run() {
221221

222222
if (mCamera != null) {
223223
mCamera.setParameters(torchOff);
224-
if (!mShouldEnableFlashlight) {
224+
if (!mShouldEnableFlashlight || mIsMarshmallow) {
225225
mCamera.release();
226226
mCamera = null;
227227
}

app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ private void toggleStroboscope() {
118118
if (isCameraPermissionGranted()) {
119119
if (mCameraImpl.toggleStroboscope()) {
120120
mStroboscopeBar.setVisibility(mStroboscopeBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
121+
changeIconColor(mStroboscopeBar.getVisibility() == View.VISIBLE ? R.color.colorPrimary : R.color.translucent_white, mStroboscopeBtn);
121122
}
122123
} else {
123124
final String[] permissions = {Manifest.permission.CAMERA};
@@ -156,7 +157,10 @@ protected void onResume() {
156157

157158
mBrightDisplayBtn.setVisibility(mConfig.getBrightDisplay() ? View.VISIBLE : View.GONE);
158159
mStroboscopeBtn.setVisibility(mConfig.getStroboscope() ? View.VISIBLE : View.GONE);
159-
mStroboscopeBar.setVisibility(View.INVISIBLE);
160+
if (!mConfig.getStroboscope()) {
161+
mCameraImpl.stopStroboscope();
162+
mStroboscopeBar.setVisibility(View.INVISIBLE);
163+
}
160164
}
161165

162166
@Override
@@ -193,6 +197,7 @@ public void stateChangedEvent(Events.StateChanged event) {
193197
}
194198

195199
public void enableFlashlight() {
200+
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
196201
changeIconColor(R.color.colorPrimary, mToggleBtn);
197202
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
198203
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
3232
android:layout_marginTop="@dimen/buttons_margin"
33-
android:background="@mipmap/bright_display"
33+
android:background="@mipmap/stroboscope"
3434
android:padding="@dimen/activity_margin"/>
3535

3636
<SeekBar
91 Bytes
Loading
1.34 KB
Loading
266 Bytes
Loading
1.01 KB
Loading
89 Bytes
Loading
1.72 KB
Loading

0 commit comments

Comments
 (0)