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);
}
}
}