menambahkan modal
This commit is contained in:
parent
a7fa40d60a
commit
810964b4be
@ -2,8 +2,10 @@ package com.example.bdkipoc;
|
|||||||
|
|
||||||
import android.animation.AnimatorSet;
|
import android.animation.AnimatorSet;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -17,6 +19,7 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -34,6 +37,9 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
private TextView btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btn000;
|
private TextView btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btn000;
|
||||||
private ImageView btnDelete;
|
private ImageView btnDelete;
|
||||||
|
|
||||||
|
// Modal components
|
||||||
|
private Dialog paymentModal;
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
private StringBuilder currentAmount = new StringBuilder();
|
private StringBuilder currentAmount = new StringBuilder();
|
||||||
private static final int MAX_AMOUNT_LENGTH = 12;
|
private static final int MAX_AMOUNT_LENGTH = 12;
|
||||||
@ -53,7 +59,7 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
initializeViews();
|
initializeViews();
|
||||||
setupClickListeners();
|
setupClickListeners();
|
||||||
setupInitialStates();
|
setupInitialStates();
|
||||||
// REMOVED: addAnimations() - No more card sliding animation
|
setupModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusBarColor() {
|
private void setStatusBarColor() {
|
||||||
@ -93,6 +99,37 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
btnDelete = findViewById(R.id.btnDelete);
|
btnDelete = findViewById(R.id.btnDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupModal() {
|
||||||
|
// Create modal dialog
|
||||||
|
paymentModal = new Dialog(this);
|
||||||
|
paymentModal.setContentView(R.layout.modal_layout);
|
||||||
|
|
||||||
|
// Remove background dimming - make it fully transparent
|
||||||
|
if (paymentModal.getWindow() != null) {
|
||||||
|
paymentModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup modal listeners
|
||||||
|
setupModalListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupModalListeners() {
|
||||||
|
// Make modal non-cancelable by touching outside
|
||||||
|
paymentModal.setCanceledOnTouchOutside(false);
|
||||||
|
|
||||||
|
// Auto dismiss after 3 seconds (simulate card processing)
|
||||||
|
Handler modalHandler = new Handler(Looper.getMainLooper());
|
||||||
|
paymentModal.setOnShowListener(dialog -> {
|
||||||
|
modalHandler.postDelayed(() -> {
|
||||||
|
if (paymentModal.isShowing()) {
|
||||||
|
dismissModal();
|
||||||
|
// Simulate successful card processing
|
||||||
|
processCardPayment();
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void setupClickListeners() {
|
private void setupClickListeners() {
|
||||||
// Back navigation - entire LinearLayout is clickable
|
// Back navigation - entire LinearLayout is clickable
|
||||||
backNavigation.setOnClickListener(v -> {
|
backNavigation.setOnClickListener(v -> {
|
||||||
@ -131,11 +168,11 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
deleteLastDigit();
|
deleteLastDigit();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Confirm button
|
// Confirm button - NOW SHOWS MODAL INSTEAD OF DIRECT PAYMENT
|
||||||
confirmButton.setOnClickListener(v -> {
|
confirmButton.setOnClickListener(v -> {
|
||||||
if (confirmButton.isEnabled()) {
|
if (confirmButton.isEnabled()) {
|
||||||
addButtonClickAnimation(v);
|
addButtonClickAnimation(v);
|
||||||
handleConfirmPayment();
|
showPaymentModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -163,8 +200,6 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
editTextAmount.setCursorVisible(false);
|
editTextAmount.setCursorVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVED: addAnimations() method - No card sliding animation on startup
|
|
||||||
|
|
||||||
private void addDigit(String digit) {
|
private void addDigit(String digit) {
|
||||||
// Validate input length
|
// Validate input length
|
||||||
if (currentAmount.length() >= MAX_AMOUNT_LENGTH) {
|
if (currentAmount.length() >= MAX_AMOUNT_LENGTH) {
|
||||||
@ -256,7 +291,8 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleConfirmPayment() {
|
// NEW METHOD: Show payment modal instead of direct payment processing
|
||||||
|
private void showPaymentModal() {
|
||||||
String amount = currentAmount.toString();
|
String amount = currentAmount.toString();
|
||||||
|
|
||||||
if (TextUtils.isEmpty(amount) || amount.equals("0")) {
|
if (TextUtils.isEmpty(amount) || amount.equals("0")) {
|
||||||
@ -279,6 +315,71 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show modal with animation
|
||||||
|
showModalWithAnimation();
|
||||||
|
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
showToast("Format jumlah tidak valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showModalWithAnimation() {
|
||||||
|
paymentModal.show();
|
||||||
|
|
||||||
|
// Add slide-up animation
|
||||||
|
View modalView = paymentModal.findViewById(android.R.id.content);
|
||||||
|
if (modalView != null) {
|
||||||
|
ObjectAnimator slideUp = ObjectAnimator.ofFloat(modalView, "translationY", 300f, 0f);
|
||||||
|
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(modalView, "alpha", 0f, 1f);
|
||||||
|
|
||||||
|
AnimatorSet animatorSet = new AnimatorSet();
|
||||||
|
animatorSet.playTogether(slideUp, fadeIn);
|
||||||
|
animatorSet.setDuration(300);
|
||||||
|
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||||
|
animatorSet.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissModal() {
|
||||||
|
if (paymentModal != null && paymentModal.isShowing()) {
|
||||||
|
// Add slide-down animation before dismissing
|
||||||
|
View modalView = paymentModal.findViewById(android.R.id.content);
|
||||||
|
if (modalView != null) {
|
||||||
|
ObjectAnimator slideDown = ObjectAnimator.ofFloat(modalView, "translationY", 0f, 300f);
|
||||||
|
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(modalView, "alpha", 1f, 0f);
|
||||||
|
|
||||||
|
AnimatorSet animatorSet = new AnimatorSet();
|
||||||
|
animatorSet.playTogether(slideDown, fadeOut);
|
||||||
|
animatorSet.setDuration(200);
|
||||||
|
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||||
|
|
||||||
|
animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(android.animation.Animator animation) {
|
||||||
|
paymentModal.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
animatorSet.start();
|
||||||
|
} else {
|
||||||
|
paymentModal.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processModalConfirmation() {
|
||||||
|
// This method is no longer needed since modal auto-dismisses
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processCardPayment() {
|
||||||
|
String amount = currentAmount.toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
long amountValue = Long.parseLong(amount);
|
||||||
|
|
||||||
|
// Show processing with card payment
|
||||||
|
showToast("Memproses pembayaran dengan kartu...");
|
||||||
|
|
||||||
// Process payment
|
// Process payment
|
||||||
processPayment(amountValue);
|
processPayment(amountValue);
|
||||||
|
|
||||||
@ -350,8 +451,13 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
// Check if modal is showing, dismiss it first
|
||||||
|
if (paymentModal != null && paymentModal.isShowing()) {
|
||||||
|
dismissModal();
|
||||||
|
} else {
|
||||||
navigateBack();
|
navigateBack();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
@ -359,6 +465,11 @@ public class PaymentActivity extends AppCompatActivity {
|
|||||||
if (animationHandler != null) {
|
if (animationHandler != null) {
|
||||||
animationHandler.removeCallbacksAndMessages(null);
|
animationHandler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up modal
|
||||||
|
if (paymentModal != null && paymentModal.isShowing()) {
|
||||||
|
paymentModal.dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public methods for testing
|
// Public methods for testing
|
||||||
|
BIN
app/src/main/res/drawable/ic_card_insert.png
Normal file
BIN
app/src/main/res/drawable/ic_card_insert.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
43
app/src/main/res/layout/modal_layout.xml
Normal file
43
app/src/main/res/layout/modal_layout.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- res/layout/modal_layout.xml -->
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="32dp"
|
||||||
|
app:cardCornerRadius="16dp"
|
||||||
|
app:cardElevation="8dp"
|
||||||
|
app:cardBackgroundColor="#FFFFFF">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="32dp"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<!-- Card Icon -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="80dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:src="@drawable/ic_card_insert"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:adjustViewBounds="true"/>
|
||||||
|
|
||||||
|
<!-- Main Text -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Silakan Tempelkan / Gesekkan / Masukkan Kartu ke Perangkat"
|
||||||
|
android:textColor="#333333"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="normal"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:lineSpacingExtra="4dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
Loading…
x
Reference in New Issue
Block a user