Skip to content

Commit

Permalink
Implement low-light whitening effect(closes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf104a committed Mar 30, 2024
1 parent 83aa7e4 commit 100866f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/com/polar/mirror/LowLightController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.camera.core.Preview;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

/**
* Implements logic of controlling low-light mode
* Implements low-light mode
*/
public class LowLightController {
private final Activity mActivity;
private float lastBrightness = 1;
public boolean isLowLightModeEnabled = false;
private FloatingActionButton mLowLightModeButton;
private final FloatingActionButton mLowLightModeButton;
private final ImageView mLowLightOverlay;
private static final String TAG = "LowLightController";
private static final int WHITENING_VALUE = 128;


LowLightController(Activity activity, FloatingActionButton lowLightModeButton){
LowLightController(Activity activity, FloatingActionButton lowLightModeButton,
ImageView lowLightOverlay){
mActivity = activity;
mLowLightModeButton = lowLightModeButton;
mLowLightOverlay = lowLightOverlay;
}

private void enableLowLightMode(){
Expand All @@ -39,6 +44,8 @@ private void enableLowLightMode(){
mActivity.getWindow().setAttributes(layout);
//Set image on FAB
mLowLightModeButton.setImageResource(R.drawable.flashlight_off);
//Enable whitening overlay
mLowLightOverlay.setVisibility(View.VISIBLE);
}

private void disableLowLightMode(){
Expand All @@ -48,6 +55,8 @@ private void disableLowLightMode(){
mActivity.getWindow().setAttributes(layout);
//Set image on FAB
mLowLightModeButton.setImageResource(R.drawable.flashlight_on);
//Disable whitening overlay
mLowLightOverlay.setVisibility(View.GONE);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/polar/mirror/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ protected void onCreate(Bundle savedInstanceState) {
//Get low-light FAB
FloatingActionButton lowLightModeButton = findViewById(R.id.low_light_button);

//Get low-light overlay
ImageView lowLightOverlay = findViewById(R.id.low_light_overlay_view);

//Start camera
try {
startCamera();
mLowLightController = new LowLightController(this, lowLightModeButton);
mLowLightController = new LowLightController(this, lowLightModeButton,
lowLightOverlay);
} catch (ExecutionException | InterruptedException e) {
final String toastText = getString(R.string.can_not_start_camera);
Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
android:scaleType="centerCrop"
android:contentDescription="@string/stop_view_desc" />

<ImageView
android:id="@+id/low_light_overlay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="@color/white"
android:alpha="0.3"
android:visibility="gone"
android:contentDescription="@string/low_light_mode_overlay" />

<View
android:id="@+id/overlay_view"
android:layout_width="match_parent"
Expand All @@ -30,6 +40,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />


<include layout="@layout/action_panel" />

</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<string name="tap_to_show_actions">Kliknij gdziekolwiek, aby wyświetlić menu akcji</string>
<string name="can_not_start_camera">Brak dostępu do kamery</string>
<string name="no_camera_permissions">Dostęp do kamery nie został przyznany. Użyj aplikacji Ustawienia, aby pryznać dostęp</string>
<string name="low_light">Tryb ciemonści</string>
<string name="low_light">Tryb ciemności</string>
<string name="low_light_mode_overlay">Overlay trybu ciemności</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="can_not_start_camera">Не вдалося отримати доступ до камери</string>
<string name="no_camera_permissions">Доступ до камери не надано. Скористуйтесь застосунком Налаштування, аби надати доступ вручну</string>
<string name="low_light">Режим пітьми</string>
<string name="low_light_mode_overlay">Оверлей режим пітьми</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="can_not_start_camera">Can not access camera</string>
<string name="no_camera_permissions">Camera permissions was not granted. Use Settings app to grant it.</string>
<string name="low_light">Dark mode</string>
<string name="low_light_mode_overlay">Low light mode overlay</string>
</resources>

0 comments on commit 100866f

Please sign in to comment.