package
com.example.sns;
import
java.io.File;
import
java.io.FileInputStream;
import
java.io.FileNotFoundException;
import
java.io.FileOutputStream;
import
java.io.IOException;
import
java.io.InputStream;
import
java.nio.channels.FileChannel;
import
java.util.ArrayList;
import
android.annotation.SuppressLint;
import
android.app.Activity;
import
android.content.Intent;
import
android.content.res.Resources;
import
android.database.Cursor;
import
android.graphics.Bitmap;
import
android.graphics.BitmapFactory;
import
android.net.Uri;
import
android.os.Bundle;
import
android.os.Environment;
import
android.provider.MediaStore;
import
android.util.Log;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.ImageView;
import
android.widget.Toast;
@SuppressLint
(
"InlinedApi"
)
public
class
insert
extends
Activity {
public
static
final
int
REQUEST_CODE_CAMERA =
0
;
public
static
final
int
REQUEST_CODE_CROP =
1
;
ImageView imgView;
Uri u;
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.insert);
Button insertButton = (Button)findViewById(R.id.mirt);
Button cancel = (Button)findViewById(R.id.cancel);
Button cameraButton = (Button)findViewById(R.id.insertcamera);
imgView=(ImageView)findViewById(R.id.insertImage);
final
EditText et = (EditText) findViewById(R.id.irttext);
cameraButton.setOnClickListener(
new
OnClickListener(){
public
void
onClick(View v){
Intent intent =
new
Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(
"crop"
,
"true"
);
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
u = Uri.fromFile(
new
File(Environment.DIRECTORY_PICTURES,
"myFile.jpg"
));
intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
}
});
insertButton.setOnClickListener(
new
OnClickListener(){
public
void
onClick(View v){
Intent resultIntent =
new
Intent();
resultIntent.putExtra(
"name"
, et.getText().toString());
setResult(
1
, resultIntent);
finish();
}
});
cancel.setOnClickListener(
new
OnClickListener(){
public
void
onClick(View v){
finish();
}
});
}
protected
void
onActivityResult(
int
requestCode,
int
resultCode, Intent data){
if
(resultCode==RESULT_OK){
if
(requestCode==REQUEST_CODE_CAMERA){
InputStream is =
null
;
try
{
is =
this
.getContentResolver().openInputStream(u);
}
catch
(FileNotFoundException e){
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeStream(is);
imgView.setImageBitmap(bmp);
Log.i(
"Inside"
,
"REQUEST_CODE_CAMERA"
);
}
}
}
}