Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.unej.sisterfortendik.activity.wajah;
- import android.Manifest;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Matrix;
- import android.media.ExifInterface;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Environment;
- import android.provider.MediaStore;
- import android.provider.OpenableColumns;
- import android.util.Base64;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.TextView;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.app.ActivityCompat;
- import androidx.core.content.ContextCompat;
- import com.unej.sisterfortendik.R;
- import com.unej.sisterfortendik.config.session.SessionClass;
- import com.unej.sisterfortendik.config.util.EncrypDecryptManager;
- import com.unej.sisterfortendik.handler.Auth.UploadFotoFace;
- import org.apache.commons.logging.LogFactory;
- import org.json.JSONObject;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import retrofit2.http.Url;
- public class RekamWajahActivity extends AppCompatActivity {
- private static final String TAG = "REKAMWAJAH";
- ImageView imageView, im_rotate, im_flip;
- //to call our own custom cam
- TextView label;
- private final static int CAMERA_PIC_REQUEST1 = 0;
- Context con;
- Button buttonCapture, buttonSimpan, buttonHapus;
- private static final int SECOND_ACTIVITY_REQUEST_CODE = 0;
- private ProgressDialog progressDialog;
- private SessionClass sessionManager;
- private EncrypDecryptManager encrypDecryptManager;
- private AlertDialog.Builder builder;
- private JSONObject jsonObject;
- private JSONObject data;
- public String streams, foto;
- String returnString,retrurnUri, returnBitmap;
- private Bitmap bitmap;
- private String selectedImagePath;
- private File destination;
- private UploadFotoFace uploadFotoFace;
- private static final String[] CAMERA_PERMISSION = new String[]{Manifest.permission.CAMERA};
- private static final int CAMERA_REQUEST_CODE = 10;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_rekam_wajah);
- progressDialog = new ProgressDialog(this);
- sessionManager = new SessionClass(this);
- jsonObject = new JSONObject();
- encrypDecryptManager = new EncrypDecryptManager();
- uploadFotoFace = new UploadFotoFace(this);
- imageView = (ImageView) findViewById(R.id.imageView9);
- im_rotate = (ImageView) findViewById(R.id.im_rotate);
- im_flip = (ImageView) findViewById(R.id.im_flip);
- con=this;
- label = (TextView) findViewById(R.id.textViewLabelBawah);
- buttonCapture = (Button) findViewById(R.id.btn_capture_wajah);
- buttonSimpan = (Button) findViewById(R.id.btn_simpan);
- buttonHapus = (Button) findViewById(R.id.btn_hapus);
- buttonSimpan.setVisibility(View.INVISIBLE);
- buttonCapture.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (hasCameraPermission()) {
- enableCamera();
- } else {
- requestPermission();
- }
- }
- });
- im_rotate.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- imageView.setRotation(imageView.getRotation()-90F);
- }
- });
- im_flip.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- imageView.setRotationY(180);
- }
- });
- AlertDialog.Builder builder = new AlertDialog.Builder(RekamWajahActivity.this);
- builder.setMessage("Apakah Anda bersedia memberikan persetujuan untuk perekaman dan pengumpulan data wajah Anda? Data ini akan digunakan secara eksklusif untuk pengembangan sistem presensi berbasis Artificial Intelligence (AI) oleh Universitas Jember. Seluruh data Anda akan dijaga kerahasiaannya sesuai dengan ketentuan privasi yang berlaku. Pastikan bahwa wajah yang direkam adalah wajah pemilik akun.");
- builder.setTitle("Konfirmasi Pengumpulan Data Wajah");
- builder.setCancelable(false);
- builder.setPositiveButton("Syarat & Ketentuan", (DialogInterface.OnClickListener) (dialog, which) -> {
- String url = "https://siakad.unej.ac.id/term";
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- startActivity(i);
- });
- builder.setNegativeButton("Tidak", (DialogInterface.OnClickListener) (dialog, which) -> {
- finish();
- });
- builder.setNeutralButton("Ya", (DialogInterface.OnClickListener) (dialog, which) -> {
- dialog.dismiss();
- });
- AlertDialog alertDialog = builder.create();
- alertDialog.show();
- uploadFotoFace.fotoLast();
- uploadFotoFace.lastFoto();
- }
- private boolean hasCameraPermission() {
- return ContextCompat.checkSelfPermission(
- this,
- Manifest.permission.CAMERA
- ) == PackageManager.PERMISSION_GRANTED;
- }
- private void requestPermission() {
- ActivityCompat.requestPermissions(
- this,
- CAMERA_PERMISSION,
- CAMERA_REQUEST_CODE
- );
- }
- private void enableCamera() {
- Intent intent = new Intent(this, CameraActivity.class);
- startActivityForResult(intent, SECOND_ACTIVITY_REQUEST_CODE);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- try {
- // check that it is the SecondActivity with an OK result
- if (requestCode == SECOND_ACTIVITY_REQUEST_CODE) {
- if (resultCode == RESULT_OK) { // Activity.RESULT_OK
- // get String data from Intent
- //returnString = data.getStringExtra("keyName");
- retrurnUri = data.getStringExtra("uri");
- Log.e(TAG, "OWH: " +retrurnUri );
- ContentResolver contentResolver = getContentResolver();
- bitmap = MediaStore.Images.Media.getBitmap(contentResolver, Uri.parse(retrurnUri));
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- InputStream inputStream = contentResolver.openInputStream(Uri.parse(retrurnUri));
- Matrix matrix = new Matrix();
- ExifInterface exif = null;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
- exif = new ExifInterface(inputStream);
- }
- int orientation = exif.getAttributeInt(
- ExifInterface.TAG_ORIENTATION,
- ExifInterface.ORIENTATION_NORMAL);
- switch (orientation) {
- case ExifInterface.ORIENTATION_ROTATE_90:
- matrix.postRotate(90);
- break;
- case ExifInterface.ORIENTATION_ROTATE_180:
- matrix.postRotate(180);
- break;
- case ExifInterface.ORIENTATION_ROTATE_270:
- matrix.postRotate(270);
- break;
- default:
- matrix.postRotate(0);
- break;
- }
- Bitmap imgRotateResult = Bitmap.createBitmap(bitmap, 0, 0,
- bitmap.getWidth(), bitmap.getHeight(), matrix, true);
- Cursor cursor = getContentResolver().query(Uri.parse(retrurnUri), null, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
- long fileSizeInBytes = cursor.getLong(sizeIndex);
- cursor.close();
- Log.d("File Size", "Ukuran file: " + fileSizeInBytes + " bytes");
- }
- imageView.setImageBitmap(imgRotateResult);
- imgRotateResult.compress(Bitmap.CompressFormat.JPEG, 70, byteArrayOutputStream);
- byte[] byteArray = byteArrayOutputStream.toByteArray();
- String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
- String encodeImagePhoto = encoded.replace("\n", "").replace("\r", "");
- buttonSimpan.setVisibility(View.VISIBLE);
- buttonSimpan.setOnClickListener(v -> {
- uploadFotoFace.foto = encodeImagePhoto;
- uploadFotoFace.uploadFoto();
- });
- buttonCapture.setText("Foto Ulang");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment