1

im very new with android programming, and i want to make an app in android studio, that first, it opens the camera, then, when you press take photo button (the default circle button) it waits 3 seconds, and 1 second before the photo is taken, the app turn black, and the photo is taken while the app is black. I have programmed only a camera, where you press take photo, and it takes you to the camera. I need help programming what i have said.

After you press the circle to take photo, it waits 3 seconds, then the app turns black, and it takes the photo while the app is black. Thanks.

Activity_Main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="org.intracode.comactorganizer.cameratest.cameratest.MainActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imagen"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@android:drawable/btn_star_big_off" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Foto"
        android:id="@+id/btnCaptura"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.intracode.comactorganizer.testcamera.testcamera" >
<uses-permission android:name="android.permission.CAMERA"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="org.intracode.comactorganizer.testcamera.testcamera.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity:

package org.intracode.comactorganizer.cameratest.cameratest;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnClickListener {
    Button btn;
    ImageView img;
    Intent i;
    Bitmap bmp;
    final static int cons=0;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    public void init()
    {
btn = (Button)findViewById(R.id.btnCaptura);
        btn.setOnClickListener(this);

        img=(ImageView)findViewById(R.id.imagen);

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
        }

    @Override
    public void onClick(View view) {
        int id;
        id= view.getId();
        switch (id)
        {
            case R.id.btnCaptura:
i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(i,cons);
                break;
        }
        }
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == Activity.RESULT_OK)
    {
        Bundle ext = data.getExtras();
        bmp = (Bitmap)ext.get("data");
        img.setImageBitmap(bmp);

    }
}

}

1 Answers1

0

In order to do what I think you want, which is to launch the Camera app, but allow for the user to take a picture, 3 seconds goes by and the camera screen goes black? Then you will have to actually modify the Camera itself and not launch an intent for the default camera apps.

Its best to look at this too: http://developer.android.com/guide/topics/media/camera.html#custom-camera

If you're saying you want to modify YOUR APP to turn black, and not the CAMERA, then just add:

try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }

for your 3 second wait, However make sure you don't block the main thread by using a new Thread or an alternative is to follow this post https://stackoverflow.com/a/14615606/1784299.

Then have another view on top of your layout set to black but invisible, then change it to visible.

Community
  • 1
  • 1
John Shelley
  • 2,655
  • 3
  • 27
  • 36
  • okey, and can you explain me how to implement the thread.sleep? Because im very very new on android programming – user3712543 Jun 05 '14 at 19:06