Professional Documents
Culture Documents
faceapp;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.concurrent.Executor;
//import android.hardware.biometrics.BiometricPrompt;
int amtval = 0;
String amt_bal = "";
String amt_add = "";
String userid = "";
String transamt = "";
EditText et1,et2;
int auth_check = 0;
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_biomodactivivty);
filreaddata1();
biometricLoginButton = findViewById(R.id.biometric_login);
biometricLoginButton.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int
after) {
@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {
@Override
public void afterTextChanged(Editable s) {
if (biometricLoginButton.getText().toString().contains("TRANSACTION
SUCCESSUL"))
{
int x =
Integer.parseInt(String.valueOf(et1.getText().toString())) +
Integer.parseInt(String.valueOf(et2.getText().toString()));
Toast.makeText(getApplicationContext(),"Total :"+
x ,Toast.LENGTH_LONG ).show();
writenewbal(String.valueOf(x));
movetobalview();
}
}
});
initbiomteric();
// checkbio();
biometricLoginButton.setOnClickListener(view -> {
biometricPrompt.authenticate(promptInfo);
// checkbio();
});
}
// biometricPrompt.authenticate(promptInfo);
if (auth_check == 1) {
// Toast.makeText(getApplicationContext(), " ALL SUCCECSS !!! ",
Toast.LENGTH_LONG).show();
biometricLoginButton.setText("TRANSACTION SUCCESSUL ! ");
}
}
auth_check = 1;
checkbio();
// reducebal();
}
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence
errString) {
super.onAuthenticationError(errorCode, errString);
auth_check = 3;
Toast.makeText(getApplicationContext(), errString,
Toast.LENGTH_LONG).show();
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
auth_check = 2;
Toast.makeText(getApplicationContext(), "FAILED",
Toast.LENGTH_LONG).show();
}
});
promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Touch id required")
.setDescription("Touch the touch id sensor")
.setNegativeButtonText("Exit")
.setConfirmationRequired(true)
.build();
if (amtval >= 0) {
try {
File file = new File(getFilesDir(), "amtbalance.txt");
FileOutputStream fileOutputStream = new FileOutputStream(file);
bufferedWriter.write(String.valueOf(amtval));
Toast.makeText(this, " Amount Deducted " + amtval,
Toast.LENGTH_SHORT).show();
bufferedWriter.flush();
bufferedWriter.close();
outputStreamWriter.close();
fileOutputStream.close();
} catch (FileNotFoundException ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG);
} catch (IOException ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG);
} catch (Exception ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, " Sorry Insufficient Balance " + amtval,
Toast.LENGTH_SHORT).show();
}
movetobalview();
if (fileInputStream != null) {
// et1.setText(amt_bal);
}
// Toast.makeText(getApplicationContext(), " Outside : " + amt_bal,
Toast.LENGTH_LONG).show();
if (fileInputStream1 != null) {
// et2.setText(amt_add);
}
// Toast.makeText(getApplicationContext(), " Outside : " + amt_add,
Toast.LENGTH_LONG).show();
bufferedWriter.flush();
bufferedWriter.close();
outputStreamWriter.close();
fileOutputStream.close();
}
catch (FileNotFoundException ex) {
Toast.makeText(getApplicationContext(), ex.toString(),
Toast.LENGTH_LONG).show();
} catch (IOException ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
Toast.makeText(this,ex.toString(),Toast.LENGTH_LONG).show();
}
finally {
Toast.makeText(getApplicationContext(), " New Balance " + x ,
Toast.LENGTH_SHORT).show();
}
}
}