Prevent-Screen-Off


Source link: https://github.com/kevalpatel2106/Prevent-Screen-Off

Prevent-Screen-Off

Featured in:

What is this library for?

  • Ideally, when you user is looking at the screen, your application should not turn the screen off. This is huge deal for the blogging, messaging applications because those applications displays textual content to the user. Reading those textual content takes more time to the user. While reading that content (let say anu article) if the screen turns off, because of the screen timeout that is frustrating to the user.
  • This library provides smart handling of the screen on-off. This library prevents screen from turning off if your user is looking at the screen might reading some textual content on the screen. As soon as the user stop looking at the screen it will allow phone screen to turn off.

How this library works?

  • This library users Google Play Services Mobile Vision API to track users eye using the front camera of the device.
  • Library will start tracking user eyes as soon as activity comes into the foreground. If the user is looking at the screen this will prevent screen from turning off.
  • When library detects that the user is not looking at the screen, this will turn off the screen after some time and stop eye tracking the preserve the battery.

How to use this library???

Gradle dependency:

Add these lines to your build.gradle file to start integration.

dependency{

  compile 'com.kevalpatel2106:prevent-screen-off:1.1' 
}
 
  • This library automatically adds android.permission.CAMERA and android.permission.WAKE_LOCK permission in your applications AndroidManifest.xml file.

Initialize in your activity:

  • First you need to inherit AnalyserActivity in the activity which you want to controll screen on/off automatically. The library will synchronise with your activity lifecycle and start and stop eye tracking based on your activity state
  • Implement ScreenListener to receive the callbacks from the library.
public class MainActivity extends AnalyserActivity

//Inherit AnalyseActivity to automatically manage activity callback.

implements ScreenListner {

 //Implement the listener to get the callbacks 
  • Handle the callbacks and errors received from ScreenListener.
public void onScreenMonitoringStart() {

  //This callback will receive when eye tracking algorithm is intilized. 
}
  @Override public void onScreenMonitoringStop() {

 //This callback will receive when eye tracking algorithm is stopped. 
}
  @Override public void onErrorOccurred(int errorCode) {

  switch (errorCode) {

case Errors.UNDEFINED:

//Error is not defined.

  //Library won't control the screen on/off anymore.

 break;

case Errors.CAMERA_PERMISSION_NOT_AVAILABLE:

  //Camera permission is not available ask for the runtime camera permission

 break;

case Errors.FRONT_CAMERA_NOT_AVAILABLE:

//Device does not have the front camera.

  //So, this library won't control the screen on/off.

 break;

case Errors.LOW_LIGHT:

  //Low light in the surrounding environment so that eye tracking cannot work.

  //Library won't control the screen on/off anymore.

  break;

case Errors.PLAY_SERVICE_NOT_AVAILABLE:

//This device doesn't have the play services installed.

 // The SDK will display the error dialog it self. This will stop the eye tracker and will not

 // prevent screen off automatically.

 break;
  
}
 
}
 

That's it. You are ready to test.

Where to use this library:

  • Tracking user's eye using device camera consumes more battery. So, it is advisable that you don't integrate automatic screen controll in every screen of you application.
  • You can integrate this features in your application activity, which has more textual content to read. e.g. chat conversation activity in messaging app or activity that displays full article in your blogging application. (This list can be extend for may other users. Let me know if you have more ideas.)

Demo

  • You can download the sample apk from here.

Contribute:

Simple 3 step to contribute into this repo:

  1. Fork the project.
  2. Make required changes and commit.
  3. Generate pull request. Mention all the required description regarding changes you made.

Questions?

Hit me on

License

Copyright 2017 Keval Patel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

droitatedDB is a lightweight framework, which frees you from the burden of dealing with the Android SQLite database directly if you don't want to but lets you access it directly if you need to.

With an annotation based approach you are able to get a database up and running in no time. Simply annotate your data classes and let droitatedDB do the work.

Force clear delaying & no longer needed Gradle tasks.

A more elegant and easy way to build an multifunctional adapter for ListView or RecyclerView in Android.

An imitation of the clock in Google I/O 2016. Almost all of the animations and images in it are made by the SVG, so this library may be a wonderful material to learn the SVG's usage in Android.

"Recovery" can help you to automatically handle application crash in runtime.

An interesting pop-view animation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes