Android---Eye-protection and high-compatibility flashlight implementation

Source: Internet
Author: User

The program has two functions, one is the eye lamp, the second is the flashlight, but the flashlight compatibility solution is to add abnormal control, to avoid a variety of abnormal occupation can not start the flashlight.
The main program interface, no landscaping, only to achieve basic functions.

Part of the code:
Protective Eye Mask Main code

private void CreateView () {Mwindowmanager = (WindowManager) getapplication (). Getsystemservice(Context. WINDOW_service);Wmparams = new WindowManager. Layoutparams();Phone window. It is used for telephone interactions (especially inbound).        It is placed above all applications, under the status bar. Wmparams. Type= WindowManager. Layoutparams. TYPE_phone;Set the picture format, the effect is transparent background wmparams. Format= PixelFormat. RGBA_8888;Set the floating window to be non-focusable (operations that enable operation of other visible windows except floating windows) Wmparams. Flags= WindowManager. Layoutparams. FLAG_not_touch_modal | WindowManager. Layoutparams. FLAG_not_focusable | WindowManager. Layoutparams. FLAG_not_touchable;Adjust the hover window to display the docking position to the left of the pinned Wmparams. Gravity= Gravity. Left| Gravity. TOP;Wmparams. x=0;Wmparams. Y=0;Setting the hover window length-width data wmparams. Width= WindowManager. Layoutparams. MATCH_parent;Wmparams. Height= WindowManager. Layoutparams. MATCH_parent;v = new MyView (Getapplicationcontext ());Mwindowmanager. AddView(V, Wmparams);}

Flashlight Main Code

    /** * Turn the flashlight on or off * *    PrivateView.onclicklistener Flash =NewView.onclicklistener () {@Override         Public void OnClick(View v) {//First to determine if there is a flash            if(!getpackagemanager (). Hassystemfeature (Packagemanager.feature_camera_flash)) {Toast.maketext (mainactivity). This,"The current device does not have a flashing light", Toast.length_long). Show ();return; }if(flashstate)                {Close (); Btnstartflash.settext ("Turn on the flashlight"); }Else if(!flashstate)                {open (); Btnstartflash.settext ("Turn off the flashlight"); }        }    };Private void Initflashmode() {Try{camera = Camera.open (); Camera.setpreviewtexture (NewSurfacetexture (0)); }Catch(IOException e)            {Close (); }if(Camera! =NULL) {parameters = Camera.getparameters ();            Previousflashmode = Parameters.getflashmode (); }if(Previousflashmode = =NULL) {Previousflashmode = Camera.Parameters.FLASH_MODE_OFF; }        }//Turn off the camera        Private void Close() {if(camera!=NULL) {Parameters.setflashmode (Previousflashmode);                Camera.setparameters (parameters);                Camera.release (); Camera =NULL; Flashstate =false; }        }//Open camera        Private void Open(){if(camera==NULL) {Initflashmode (); }if(camera!=NULL) {Parameters.setflashmode (Camera.Parameters.FLASH_MODE_TORCH);                Camera.setparameters (parameters);                Camera.startpreview (); Flashstate =true; }        }

Complete code can contact me [email protected]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android---Eye-protection and high-compatibility flashlight implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.