All Projects → nisrulz → lantern

nisrulz / lantern

Licence: Apache-2.0 license
[Android Library] Handling device flash as torch for Android.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to lantern

Amber
Amber-ify LED torch.
Stars: ✭ 26 (-67.9%)
Mutual labels:  torch, flashlight
BetterDummy
Unlock your displays on your Mac! Smooth scaling, HiDPI unlock, XDR/HDR extra brightness upscale, DDC, brightness and dimming, dummy displays, PIP and lots more!
Stars: ✭ 9,601 (+11753.09%)
Mutual labels:  display, screen
Mons
POSIX Shell script to quickly manage monitors on X
Stars: ✭ 457 (+464.2%)
Mutual labels:  display, screen
Nocturnal
A Dimness and Night Shift menu bar app for macOS 🌙
Stars: ✭ 199 (+145.68%)
Mutual labels:  display, screen
choco-screen-resolution
Sets the screen resolution on Windows virtual machines (VMs)
Stars: ✭ 24 (-70.37%)
Mutual labels:  display, screen
Evdi
Extensible Virtual Display Interface
Stars: ✭ 384 (+374.07%)
Mutual labels:  display, screen
Caffeine Ng
☕ Tray bar application able to temporarily inhibits the screensaver and sleep mode.
Stars: ✭ 72 (-11.11%)
Mutual labels:  display, screen
Esp32 epaper example
Full featured ePaper library for ESP32 with demo application
Stars: ✭ 147 (+81.48%)
Mutual labels:  display
Liveov7670
A step-by-step guide to building the circuit for this project:
Stars: ✭ 143 (+76.54%)
Mutual labels:  display
Easydeviceinfo
📱 [Android Library] Get device information in a super easy way.
Stars: ✭ 1,698 (+1996.3%)
Mutual labels:  display
Nvapiwrapper
NvAPIWrapper is a .Net wrapper for NVIDIA public API, capable of managing all aspects of a display setup using NVIDIA GPUs
Stars: ✭ 105 (+29.63%)
Mutual labels:  display
Rpi Display
2.8" TFT-Display with Touchpanel for all Raspberry Pi Models
Stars: ✭ 151 (+86.42%)
Mutual labels:  display
Core Layout
Flexbox & CSS-style Layout in Swift.
Stars: ✭ 215 (+165.43%)
Mutual labels:  display
graftr
graftr: an interactive shell to view and edit PyTorch checkpoints.
Stars: ✭ 89 (+9.88%)
Mutual labels:  torch
wluma
Automatic brightness adjustment based on screen contents and ALS
Stars: ✭ 290 (+258.02%)
Mutual labels:  screen
Heliosdisplaymanagement
An open source display profile management program for Windows with support for NVIDIA Surround
Stars: ✭ 181 (+123.46%)
Mutual labels:  display
Jxpopupview
一个轻量级的自定义视图弹出框架
Stars: ✭ 117 (+44.44%)
Mutual labels:  display
Lcd Image Converter
Tool to create bitmaps and fonts for embedded applications, v.2
Stars: ✭ 176 (+117.28%)
Mutual labels:  display
Sprat-type
Display typeface
Stars: ✭ 58 (-28.4%)
Mutual labels:  display
Lunar
Intelligent adaptive brightness for your external monitors
Stars: ✭ 2,712 (+3248.15%)
Mutual labels:  display

Lantern 

Android library handling flashlight for camera and camera2 api. Added support for handling display/screen light.

Built with ❤︎ by Nishant Srivastava and contributors


Including in your project

Lantern is available in the Jcenter, so getting it as simple as adding it as a dependency

implementation "com.github.nisrulz:lantern:{latest version}"

where {latest version} corresponds to published version in Download

Usage

Lantern uses a fluent api. You can enable/disable feature by calling the right method on the Lantern object. Use what you need!

  1. Declare permissions in your app's AndroidManifest.xml file

    <!-- Permissions : Allows access to flashlight -->
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    
    <!-- Permissions : Allows access to change system settings for handling screen states -->
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
  2. Init code.

    private Lantern lantern = new Lantern(this)
                                // Check and request for system permission, used for handling screen states
                                .checkAndRequestSystemPermission()
                                // OPTIONAL: Setup Lantern to observe the lifecycle of the activity/fragment, handles auto-calling cleanup() method
                                .observeLifecycle(this);
    
    // Init Lantern's torch feature by calling `initTorch()`, which also check if camera permission is granted + camera feature exists
    // In case permission is not granted, request for the permission and retry by calling `initTorch()` method
    // NOTE: In case camera feature/hardware does not exist, `initTorch()` will return `false` and Lantern will not have
    // torch functionality but only screen based features
    if (!lantern.initTorch()) {
        // Request camera permission if it is not granted
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CODE);
    }
    
    
    // Handle the runtime permission
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    
        if (requestCode == REQUEST_CODE) {
            // Retry initializing the Lantern's torch feature
            if (!lantern.initTorch()) {
                // Camera Permission Denied! Do something.
            }
        }
    }
  3. Cleanup

    If you are not observing the lifecyle of the activity/fragment via observeLifecycle(this) method, then you need to call cleanup() method in onDestroy() of the Activity.

    @Override
    protected void onDestroy() {
        lantern.cleanup();
        super.onDestroy();
    }
  4. Manage states via

    • Turn On

      lantern
          // Enable always on display
          .alwaysOnDisplay(true)
          // Set screen to full bright
          .fullBrightDisplay(true)
          // Or set screen to Auto Bright
          .autoBright(true)
          // Enable torch via flash
          .enableTorchMode(true)
          // Enable pulsating torch
          .pulse(true)
          // Set the delay for between each pulse
          .withDelay(1, TimeUnit.SECONDS);
    • Turn Off

      lantern
          // Disable always on display
          .alwaysOnDisplay(false)
          // Unset full bright screen state
          .fullBrightDisplay(false)
          // Or unset screen from Auto Bright
          .autoBright(false)
          // Disable torch via flash
          .enableTorchMode(false)
          // Disable pulsating torch
          .pulse(false);

Pull Requests

I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:

  1. Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (Reformat code) on Mac (not sure for Windows) with Android Studio defaults. This project uses a modified version of Grandcentrix's code style, so please use the same when editing this project.
  2. If its a feature, bugfix, or anything please only change code to what you specify.
  3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
  4. Pull requests must be made against develop branch. Any other branch (unless specified by the maintainers) will get rejected.
  5. Check for existing issues first, before filing an issue.
  6. Have fun!

License

Licensed under the Apache License, Version 2.0, click here for the full license.

Author & support

This project was created by Nishant Srivastava but hopefully developed and maintained by many others. See the the list of contributors here.

If you appreciate my work, consider buying me a cup of to keep me recharged 🤘

  • PayPal
  • Bitcoin Address: 13PjuJcfVW2Ad81fawqwLtku4bZLv1AxCL

Donation to the project is always welcome which helps to maintain and keep my open source projects up to date!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].