Android development: Uses delay to draw background labels (such as coordinate system and rectangular boxes) on the welcome interface and camera preview)

Source: Internet
Author: User

Many applications open the welcome interface for about 0.5 seconds, and then jump to the main interface, are implemented by latency. Bytes. Now I want to automatically preview the application as soon as I open it and draw a cross sign. That is, the preview is implemented by the button listener, and the preview is performed in the surfacecreated function. Define a surfacecallback class in mainactivity. As follows:

private final class SurfaceCallback implements Callback{        public void surfaceCreated(SurfaceHolder holder) {            try{                camera = Camera.open();                Camera.Parameters parameters = camera.getParameters();                parameters.setPreviewSize(960, 540); 
Parameters. setpreviewframerate (5); parameters. setpicturesize (1280,960); parameters. setjpegquality (80); camera. setparameters (parameters); camera. setpreviewdisplay (holder); camera. startpreview (); //} catch (exception e) {e. printstacktrace ();} new handler (). postdelayed (New runnable () {public void run () {// todo auto-generated method stub/* Cross */mdraw. setvisibility (view. visible); mdraw. drawline (); }}, 2000);} public void surfacechanged (surfaceholder holder, int format, int width, int height) {} public void surfacedestroyed (surfaceholder holder) {If (camera! = NULL) {Camera. Release (); camera = NULL ;}}}

The cross function is very simple. There are only two sentences.

Mdraw. setvisibility (view. Visible );
Mdraw. drawline ();

But these two statements are put in public void surfacecreated (surfaceholder holder ){...} The camera. startpreview () in this function is not found, because it seems that the top layer cannot be drawn before the underlying surfaceview preview screen is normal. Isn't it possible to draw at the same time in a thread ??? We can only say that the reason is unknown, so we can only use the delay.

New handler (). postdelayed (New runnable (){

Public void run (){
// Todo auto-generated method stub

/* Cross */
Mdraw. setvisibility (view. Visible );
Mdraw. drawline ();

}

},2000 );

The run () function is the task to be done after the delay is reached.

If you want to implement a boot welcome interface, you can write the following code in the run () function:

Intent intent = new intent (beginactivity. This, mainactivity. Class );

Beginactivity. This. startactivity (intent );

Beginactivity. Finish ();

 

Thanks to joim and Brother Gao for their guidance. Joim's code is awesome! Bytes. Android learning welcome to group: 248217350

 

Post note: It is better to add this code to the oncreate function! Added to the end of start preview, which is equal to an extended wait time!

Related Article

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.