FlashlightMine is an Android application that allows users to toggle their device flashlight using a button or by shaking the device. The app provides a simple and interactive UI for this purpose.
- Flashlight Control: Turn the flashlight ON/OFF with a button.
- Shake Detection: Shake your device to toggle the flashlight.
- Dynamic UI:
- Changes the background color and light bulb icon based on flashlight status.
- Updates the status bar color dynamically.
- Applies dynamic tint to UI elements for better visual feedback.
- Snackbar Notifications: Inform users about additional functionalities (e.g., shake detection).
![]() |
![]() |
- Android Studio installed on your computer.
- A device with a flashlight and accelerometer sensor (or an emulator with simulated hardware).
-
Clone this repository:
git clone https://github.com/samyak2403/FlashLightmine.git
-
Open the project in Android Studio.
-
Build and run the project on a compatible Android device or emulator.
The primary activity handles the following:
-
Flashlight Control:
- Toggles the flashlight using the
CameraManager
API. - Updates the UI to reflect the flashlight status.
- Toggles the flashlight using the
-
Shake Listener:
- Uses the accelerometer sensor to detect device shakes.
- Toggles the flashlight if a shake is detected above the threshold (2.5 G).
-
Dynamic UI Updates:
- Changes background color and status dynamically.
- Updates the tint of decorative ellipses based on flashlight state.
toggleFlashlight()
: Toggles the flashlight and updates the UI.setupShakeListener()
: Registers a sensor listener to detect shakes.setEllipsesTint(isFlashlightOn: Boolean)
: Updates the tint of UI ellipses.
This app uses the following Android libraries:
- Material Components for Snackbar and UI design.
- Camera2 API for flashlight control.
Add the following permissions in your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
- Launch the app.
- Tap the ON/OFF button to toggle the flashlight.
- Shake your device to toggle the flashlight dynamically.
- Add customization for shake sensitivity.
- Include more dynamic animations for better user interaction.
This project is licensed under the MIT License - see the LICENSE file for details.