public void exter_shutter_trigger() {
    try {
      shutter_trigger.prepare();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    shutter_trigger.start();
  }
        public void onShutter() {
          // TODO Auto-generated method stub

          AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
          mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);

          try {
            player.prepare();
          } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }

          player.start();
        }
  public void exter_shutter_trigger_sec(double s) throws InterruptedException {
    try {

      shutter_trigger.prepare();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    int x = (int) ((s * 1000.0) / 100.0);
    for (int i = 0; i < x; i++) {
      // activity:message_inf(i,"第%03d張拍攝完成");
      shutter_trigger.start();

      while (shutter_trigger.isPlaying()) Thread.sleep(1);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    // System.loadLibrary("luajava-1.1");

    // 設定橫向螢幕
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    L = LuaStateFactory.newLuaState();
    L.pushJavaObject(this);
    L.setGlobal("activity");

    res = getResources();
    conf = res.getConfiguration();

    conf.locale = Locale.TAIWAN;
    res.updateConfiguration(conf, null);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    appobject = this.getApplicationContext();

    surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    ////////////////////////////////////////////////////////////////////////////////////////////

    /*bitmap2 = BitmapFactory.decodeResource(  getResources()    , R.raw.line  );

          surfaceView2 = (SurfaceView)findViewById(R.id.surface_level );
          surfaceHolder2 = surfaceView2.getHolder();

          SurfaceHolder.Callback  level_callback  = new SurfaceHolder.Callback()
          {

    	public void surfaceChanged(SurfaceHolder holder, int format,
    			int width, int height) {
    		//需要
    		 on_level_change(new float[3]);
    	}

    	public void surfaceCreated(SurfaceHolder holder) {
    	}

    	public void surfaceDestroyed(SurfaceHolder holder) {
    	}

          };

    surfaceHolder2.addCallback(  level_callback  );
          surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  */

    //////////////////////////////////////////////////////////////////////////////////////////

    /*  sensormanager = (SensorManager) getSystemService(SENSOR_SERVICE);
         sensors =  sensormanager.getSensorList(Sensor.TYPE_ORIENTATION);

         SensorEventListener sl =new SensorEventListener ()
         {
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    	//不需要
    }
    public void onSensorChanged(SensorEvent event) {
    	 on_level_change(event.values);
    }

         };
         sensormanager.registerListener  (   sl   ,  sensors.get(0) ,  SensorManager.SENSOR_DELAY_GAME  );
         */

    /////////////////////////////////////////////////////////////////////

    Button run_script = (Button) this.findViewById(R.id.run_script);
    run_script.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (lua_file == "") {
              print_screen(res.getString(R.string.file_load_no));
              return;
            }

            File f = new File("/sdcard/ez_Lua_Script_Camera/lua_scripts/" + lua_file);
            if (f.exists() == false) {
              print_screen(res.getString(R.string.file_load_fail));
              return;
            }
            ((TextView) findViewById(R.id.lua_file_screen)).setText(lua_file);
            all_pics = 0;
            ((TextView) findViewById(R.id.shutter_times_screen)).setText("拍攝張數 : 00000");
            (new lua_run()).start();
          }
        });

    Button about = (Button) this.findViewById(R.id.about);
    about.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            Intent i =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://dl.dropbox.com/u/61164954/homepage/ez_LSC/index.htm"));
            startActivity(i);
          }
        });

    Button audio_c = (Button) this.findViewById(R.id.audio);
    audio_c.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == false) {
              print_screen(res.getString(R.string.audio_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.audio);
              keepa.setText(cs);
              is_audio = true;
              (new audio()).start();
            } else {
              arecorder.stop();
              is_audio = false;
              print_screen(res.getString(R.string.audio_rec_end));
              CharSequence xcs = res.getString(R.string.audio_rec);
              Button keepax = (Button) findViewById(R.id.audio);
              keepax.setText(xcs);
              camera.startPreview();
            }
          }
        });

    Button movie = (Button) this.findViewById(R.id.movie);
    movie.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == false) {
              print_screen(res.getString(R.string.video_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.movie);
              keepa.setText(cs);
              parameters.setFocusMode("continuous-video");
              camera.setParameters(parameters);
              is_video = true;
              (new video()).start();
            } else {
              recorder.stop();
              is_video = false;
              print_screen(res.getString(R.string.video_rec_end));
              CharSequence xcs = res.getString(R.string.video_rec);
              Button keepax = (Button) findViewById(R.id.movie);
              keepax.setText(xcs);
              camera.lock();
              camera.release();
              camera = Camera.open();
              parameters = camera.getParameters();
              parameters.setPreviewSize(640, 480);
              parameters.setPreviewFrameRate(30);
              parameters.setJpegQuality(100);
              parameters.setFocusMode("continuous-video");
              parameters.setPictureSize(2048, 1536);
              camera.setParameters(parameters);
              try {
                camera.setPreviewDisplay(surfaceHolder);
              } catch (IOException e) {
              }
              camera.startPreview();
            }
          }
        });

    Button lua = (Button) this.findViewById(R.id.lua);
    lua.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }
            show_choose_Dialog();
          }
        });

    test_caller();
    load_config();

    try {
      player.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/shuttersound.ogg");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      shutter_trigger.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/trigger.wav");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }