package eee.photossinhro;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static android.media.tv.TvTrackInfo.TYPE_VIDEO;
public class PhotosActivity extends AppCompatActivity {
String id; //идентификатор аккаунта
private Context cntcur;
static final int REQUEST_PICTURE_CAPTURE = 1;
private ImageView image;
private String pictureFilePath;
private File getPictureFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String pictureFile = "photossinhro" + timeStamp;
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(pictureFile, ".jpg", storageDir);
pictureFilePath = image.getAbsolutePath();
Log.i("Info", "--путь:"+pictureFilePath);
return image;
}
private void sendTakePictureIntent() {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra( MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(cameraIntent, REQUEST_PICTURE_CAPTURE);
File pictureFile = null;
try {
pictureFile = getPictureFile();
} catch (IOException ex) {
Toast.makeText(this, "Photo file can't be created, please try again", Toast.LENGTH_SHORT).show();
return;
}
if (pictureFile != null) {
Uri photoURI = FileProvider.getUriForFile(this, "eee.photossinhro.fileprovider", pictureFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(cameraIntent, REQUEST_PICTURE_CAPTURE);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photos);
id = getIntent().getExtras().getString("id");
Log.i("Info","--мы в новой активности! ID="+id);
cntcur=this;
// нажата кнопка "сделать фото"
Button button = (Button) findViewById(R.id.CreatePhotos);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Info", "--нажата кнопка сделать фото");
if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
sendTakePictureIntent();
}
}
});
}
}