Implemented on the mobile phone, after setting a period of time (timed in seconds), it will automatically take photos, which is suitable for photographers to create a scene, then set the time, and then enter the scene.
The interface is mainly an EditText that sets the time and a Button that starts the countdown. After setting the time, click the countdown button.
<FrameLayout xmlns:andro android: android:layout_width="fill_parent" android:layout_height="fill_parent" > <SurfaceView android: android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android: android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/startTimer" android:layout_gravity="center_horizontal"/> <!-- <TextView --> <!-- android: --> <!-- android:layout_width="fill_parent" --> <!-- android:layout_height="fill_parent" --> <!-- android:layout_gravity="center_horizontal|center_vertical|center" --> <!-- android:gravity="center_horizontal|center_vertical" --> <!-- android:text="@string/conutTime" --> <!-- android:textSize="40sp" /> --> <EditText android: android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center" android:gravity="center_horizontal|center_vertical" android:text="@string/conutTime" android:textSize="80sp" android:inputType="number"/> </LinearLayout> </FrameLayout>
Add permissions to the manifest file:
<uses-permission android:name="" /> <!--The following is not required--> <uses-feature android:name="" /> <uses-feature android:name="" />
Main program:
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity implements , OnClickListener, PictureCallback { private static final String CAMERA_CONTROLL = "CAMERA_CONTROLL"; private SurfaceView imageSView; private Button startButton; // private TextView countDownTextView; private EditText countDownEditTextView; private Camera camera; private SurfaceHolder surfaceHolder; private Handler timerUpdateHandler; private boolean timerRunning = false; private int currentTimer = 10; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); imageSView = (SurfaceView) findViewById(); startButton = (Button) findViewById(); // countDownTextView = (TextView) findViewById(); countDownEditTextView = (EditText) findViewById(); /* (new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub currentTimer = (().toString()); } }); */ surfaceHolder = (); (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); (this); (this); timerUpdateHandler = new Handler(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(, menu); return true; } @Override public void onPictureTaken(byte[] data, Camera camera) { // TODO Auto-generated method stub Uri imageFileUri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI, new ContentValues()); try { OutputStream imageFileOS = getContentResolver().openOutputStream( imageFileUri); (data); (); (); } catch (Exception e) { // TODO Auto-generated catch block (this, (), Toast.LENGTH_LONG).show(); } (); } @Override public void onClick(View v) { // TODO Auto-generated method stub currentTimer = (().toString()); switch (()) { case : if (!timerRunning) { timerRunning = true; (timerUpdateTask); } break; } } private Runnable timerUpdateTask = new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (currentTimer > 1) { currentTimer--; (timerUpdateTask, 1000); } else { (null, null, null, ); timerRunning = false; currentTimer = 10; } (currentTimer + ""); } }; @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub (); } @Override public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub int cameraNums = (); (CAMERA_CONTROLL, cameraNums + ""); try { camera = (cameraNums - 1); } catch (Exception e) { (CAMERA_CONTROLL, ()); } try { (holder); parameters = (); if (().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { ("orientation", "portrait"); (90); (90); } List<String> colorEffects = (); Iterator<String> cei = (); while (()) { String currentEffect = (); if ((.EFFECT_SOLARIZE)) { parameters .setColorEffect(.EFFECT_SOLARIZE); break; } } (parameters); } catch (Exception e) { // TODO Auto-generated catch block // (); (); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub (); (); } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.