0

I want to create a strobe effect,make the flashlight blink.Below is my code,right now what i have achieve is to make it flash but only once,that's why i need to help me make it flash for a great deal of time.

public class Strobe extends Activity {

    Camera cam;
    private static final String TAG = null;
    private Handler mHander = new Handler();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        strobe();       
    }

    private void turnOnLight(){
        for(int x = 0; x == 10; x++);{ //although for does exist does nothing and that is in all for i have put around my program,don't know why
            Log.d("tagname","runs 10 times  a");

        cam = Camera.open();
        Parameters params = cam.getParameters();
        params.setFlashMode(Parameters.FLASH_MODE_TORCH);
        cam.setParameters(params);
        cam.startPreview();
        cam.autoFocus(new AutoFocusCallback(){
            public void onAutoFocus(boolean success, Camera camera) {
            }

        });
        }
    }

    private void turnOffLight(){
        for(int x = 0; x == 10; x++);{ 

        cam.stopPreview();
        cam.release();
        Log.d("tagname","runs 10 times  b");

        }
    }

    private void strobe(){
        for(int x = 0; x == 10; x++);{ 
        Thread timer = new Thread(){
            public void run(){


                turnOnLight();
                try{
                    Thread.sleep(300);

                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                turnOffLight();
                Log.d("tagname","runs 10 times  c");


            };      
          };timer.start();
        };

    }

    };
We're All Mad Here
  • 1,544
  • 3
  • 18
  • 46

2 Answers2

0

Have you considered the fact that the syntax for your for loops is all wrong? For staryers, you are using == where you probably want to use <, and you put a semicolon after the for statement where there shouldn't be one. Review the proper syntax for a for loop and try to rewrite your code.

Nathan Walters
  • 4,116
  • 4
  • 23
  • 37
0
int n=10000;
while(n-->0)
{

int n=100000;
while(n-->0) 
{
turnOnLight();
try{
      Thread.sleep(300);
   }catch(InterruptedException e)
{
      e.printStackTrace();`enter code here`
}
turnOffLight();
Log.d("tagname","runs 10 times  c");
}

}
xinghui
  • 22
  • 3