safepoint QRIS
This commit is contained in:
@@ -1,29 +1,18 @@
|
||||
package com.example.bdkipoc;
|
||||
|
||||
// Import SDK Sunmi
|
||||
import sunmi.paylib.SunmiPayKernel;
|
||||
import com.sunmi.pay.hardware.aidlv2.emv.EMVOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.system.BasicOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.pinpad.PinPadOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.readcard.ReadCardOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.security.SecurityOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.tax.TaxOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.etc.ETCOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.print.PrinterOptV2;
|
||||
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
@@ -32,81 +21,9 @@ import com.google.android.material.button.MaterialButton;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// SDK Variables
|
||||
private EMVOptV2 emvOptV2;
|
||||
private BasicOptV2 basicOptV2;
|
||||
private PinPadOptV2 pinPadOptV2;
|
||||
private ReadCardOptV2 readCardOptV2;
|
||||
private SecurityOptV2 securityOptV2;
|
||||
private TaxOptV2 taxOptV2;
|
||||
private ETCOptV2 etcOptV2;
|
||||
private PrinterOptV2 printerOptV2;
|
||||
private boolean connectPaySDK = false;
|
||||
|
||||
// UI Variables
|
||||
private boolean isExpanded = false; // False = showing only 9 main menus, True = showing all 15 menus
|
||||
private MaterialButton btnLainnya;
|
||||
|
||||
public void bindPaySDKService() {
|
||||
Log.d("SDK_CHECK", "Starting SDK initialization...");
|
||||
try {
|
||||
final SunmiPayKernel payKernel = SunmiPayKernel.getInstance();
|
||||
Log.d("SDK_CHECK", "SunmiPayKernel instance obtained successfully");
|
||||
|
||||
payKernel.initPaySDK(this, new SunmiPayKernel.ConnectCallback() {
|
||||
@Override
|
||||
public void onConnectPaySDK() {
|
||||
Log.d("SDK_CHECK", "✅ SDK Connected Successfully!");
|
||||
try {
|
||||
emvOptV2 = payKernel.mEMVOptV2;
|
||||
basicOptV2 = payKernel.mBasicOptV2;
|
||||
pinPadOptV2 = payKernel.mPinPadOptV2;
|
||||
readCardOptV2 = payKernel.mReadCardOptV2;
|
||||
securityOptV2 = payKernel.mSecurityOptV2;
|
||||
taxOptV2 = payKernel.mTaxOptV2;
|
||||
etcOptV2 = payKernel.mETCOptV2;
|
||||
printerOptV2 = payKernel.mPrinterOptV2;
|
||||
|
||||
// Log detail komponen
|
||||
Log.d("SDK_CHECK", "EMVOptV2: " + (emvOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "BasicOptV2: " + (basicOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "PinPadOptV2: " + (pinPadOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "ReadCardOptV2: " + (readCardOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "SecurityOptV2: " + (securityOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "TaxOptV2: " + (taxOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "ETCOptV2: " + (etcOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
Log.d("SDK_CHECK", "PrinterOptV2: " + (printerOptV2 != null ? "✅ Available" : "❌ Not Available"));
|
||||
|
||||
connectPaySDK = true;
|
||||
Toast.makeText(getApplicationContext(), "✅ Sunmi SDK Connected!", Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception e) {
|
||||
Log.e("SDK_CHECK", "❌ Error initializing SDK components: " + e.getMessage());
|
||||
Toast.makeText(getApplicationContext(), "SDK Connection Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnectPaySDK() {
|
||||
Log.w("SDK_CHECK", "❌ SDK Disconnected");
|
||||
connectPaySDK = false;
|
||||
emvOptV2 = null;
|
||||
basicOptV2 = null;
|
||||
pinPadOptV2 = null;
|
||||
readCardOptV2 = null;
|
||||
securityOptV2 = null;
|
||||
taxOptV2 = null;
|
||||
etcOptV2 = null;
|
||||
printerOptV2 = null;
|
||||
Toast.makeText(getApplicationContext(), "❌ Sunmi SDK Disconnected", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("SDK_CHECK", "❌ Critical Error - Failed to initialize SDK: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "❌ Failed to initialize Sunmi SDK: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@@ -150,9 +67,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Setup menu listeners
|
||||
setupMenuListeners();
|
||||
|
||||
// Initialize Sunmi SDK
|
||||
bindPaySDKService();
|
||||
}
|
||||
|
||||
private void setupInitialMenuState() {
|
||||
@@ -185,9 +99,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Set initial button text
|
||||
isExpanded = false;
|
||||
if (btnLainnya != null) {
|
||||
btnLainnya.setText("Lainnya");
|
||||
}
|
||||
btnLainnya.setText("Lainnya");
|
||||
}
|
||||
|
||||
private void checkTransactionCompletion() {
|
||||
@@ -245,49 +157,26 @@ public class MainActivity extends AppCompatActivity {
|
||||
CardView cardView = findViewById(cardId);
|
||||
if (cardView != null) {
|
||||
cardView.setOnClickListener(v -> {
|
||||
Log.d("MENU_CLICK", "Card clicked: " + getResources().getResourceEntryName(cardId));
|
||||
|
||||
if (cardId == R.id.card_kartu_kredit) {
|
||||
// Check SDK before navigating to payment
|
||||
if (connectPaySDK) {
|
||||
Log.d("NAVIGATION", "Navigating to PaymentActivity - Kartu Kredit");
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else {
|
||||
Toast.makeText(this, "SDK belum terhubung. Harap tunggu...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else if (cardId == R.id.card_kartu_debit) {
|
||||
if (connectPaySDK) {
|
||||
Log.d("NAVIGATION", "Navigating to PaymentActivity - Kartu Debit");
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else {
|
||||
Toast.makeText(this, "SDK belum terhubung. Harap tunggu...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else if (cardId == R.id.card_qris) {
|
||||
Log.d("NAVIGATION", "Navigating to QrisActivity");
|
||||
startActivity(new Intent(MainActivity.this, QrisActivity.class));
|
||||
} else if (cardId == R.id.card_uang_elektronik) {
|
||||
if (connectPaySDK) {
|
||||
Log.d("NAVIGATION", "Navigating to PaymentActivity - Uang Elektronik");
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else {
|
||||
Toast.makeText(this, "SDK belum terhubung. Harap tunggu...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
startActivity(new Intent(MainActivity.this, PaymentActivity.class));
|
||||
} else if (cardId == R.id.card_cetak_ulang) {
|
||||
Log.d("NAVIGATION", "Navigating to TransactionActivity");
|
||||
startActivity(new Intent(MainActivity.this, TransactionActivity.class));
|
||||
} else if (cardId == R.id.card_settlement) {
|
||||
Log.d("NAVIGATION", "Navigating to SettlementActivity");
|
||||
startActivity(new Intent(MainActivity.this, SettlementActivity.class));
|
||||
Toast.makeText(this, "Settlement - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_histori) {
|
||||
Log.d("NAVIGATION", "Navigating to HistoryActivity");
|
||||
startActivity(new Intent(MainActivity.this, HistoryActivity.class));
|
||||
Toast.makeText(this, "Histori - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_bantuan) {
|
||||
Toast.makeText(this, "Bantuan - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_info_toko) {
|
||||
Toast.makeText(this, "Info Toko - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_dummy_menu_1) {
|
||||
// Use dummy menu 1 untuk SDK test
|
||||
testSDKIntegration();
|
||||
Toast.makeText(this, "Dummy Menu 1 - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_dummy_menu_2) {
|
||||
Toast.makeText(this, "Dummy Menu 2 - Coming Soon", Toast.LENGTH_SHORT).show();
|
||||
} else if (cardId == R.id.card_dummy_menu_3) {
|
||||
@@ -317,123 +206,49 @@ public class MainActivity extends AppCompatActivity {
|
||||
};
|
||||
|
||||
// Set up "Lainnya" button click listener
|
||||
if (btnLainnya != null) {
|
||||
btnLainnya.setOnClickListener(v -> {
|
||||
Log.d("MENU_TOGGLE", "Lainnya button clicked. Current state: " + (isExpanded ? "expanded" : "collapsed"));
|
||||
isExpanded = !isExpanded;
|
||||
|
||||
if (isExpanded) {
|
||||
// Show the 6 dummy menus with animation
|
||||
for (CardView card : toggleableCards) {
|
||||
if (card != null) {
|
||||
card.setVisibility(View.VISIBLE);
|
||||
card.setAlpha(0f);
|
||||
card.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(300)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
btnLainnya.setOnClickListener(v -> {
|
||||
isExpanded = !isExpanded;
|
||||
|
||||
if (isExpanded) {
|
||||
// Show the 6 dummy menus with animation
|
||||
for (CardView card : toggleableCards) {
|
||||
if (card != null) {
|
||||
card.setVisibility(View.VISIBLE);
|
||||
card.setAlpha(0f);
|
||||
card.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(300)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
btnLainnya.setText("Tampilkan Lebih Sedikit");
|
||||
} else {
|
||||
// Hide the 6 dummy menus with animation
|
||||
for (CardView card : toggleableCards) {
|
||||
if (card != null) {
|
||||
card.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.withEndAction(() -> card.setVisibility(View.GONE))
|
||||
.start();
|
||||
}
|
||||
}
|
||||
btnLainnya.setText("Lainnya");
|
||||
}
|
||||
});
|
||||
}
|
||||
btnLainnya.setText("Tampilkan Lebih Sedikit");
|
||||
} else {
|
||||
// Hide the 6 dummy menus with animation
|
||||
for (CardView card : toggleableCards) {
|
||||
if (card != null) {
|
||||
card.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.setInterpolator(new AccelerateDecelerateInterpolator())
|
||||
.withEndAction(() -> card.setVisibility(View.GONE))
|
||||
.start();
|
||||
}
|
||||
}
|
||||
btnLainnya.setText("Lainnya");
|
||||
}
|
||||
});
|
||||
|
||||
// Set up scan dan bayar card click listener
|
||||
LinearLayout scanBayarContent = findViewById(R.id.scan_bayar_content);
|
||||
if (scanBayarContent != null) {
|
||||
scanBayarContent.setOnClickListener(v -> {
|
||||
Log.d("NAVIGATION", "Scan dan Bayar clicked - Navigating to QrisActivity");
|
||||
// Navigate to QRIS payment activity
|
||||
startActivity(new Intent(MainActivity.this, QrisActivity.class));
|
||||
});
|
||||
} else {
|
||||
Log.w("MENU_SETUP", "scan_bayar_content not found in layout");
|
||||
}
|
||||
}
|
||||
|
||||
private void testSDKIntegration() {
|
||||
StringBuilder testResult = new StringBuilder();
|
||||
testResult.append("=== SUNMI SDK INTEGRATION TEST ===\n\n");
|
||||
|
||||
// Test 1: SDK Connection Status
|
||||
testResult.append("1. SDK Connection: ");
|
||||
if (connectPaySDK) {
|
||||
testResult.append("✅ CONNECTED\n");
|
||||
} else {
|
||||
testResult.append("❌ NOT CONNECTED\n");
|
||||
}
|
||||
|
||||
// Test 2: Component Availability
|
||||
testResult.append("\n2. SDK Components:\n");
|
||||
testResult.append(" - EMVOptV2: ").append(emvOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - BasicOptV2: ").append(basicOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - PinPadOptV2: ").append(pinPadOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - ReadCardOptV2: ").append(readCardOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - SecurityOptV2: ").append(securityOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - TaxOptV2: ").append(taxOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - ETCOptV2: ").append(etcOptV2 != null ? "✅" : "❌").append("\n");
|
||||
testResult.append(" - PrinterOptV2: ").append(printerOptV2 != null ? "✅" : "❌").append("\n");
|
||||
|
||||
// Test 3: Basic Function Tests
|
||||
testResult.append("\n3. Function Tests:\n");
|
||||
|
||||
if (connectPaySDK) {
|
||||
try {
|
||||
if (basicOptV2 != null) {
|
||||
testResult.append(" - BasicOpt: ✅ Ready\n");
|
||||
}
|
||||
|
||||
if (printerOptV2 != null) {
|
||||
testResult.append(" - Printer: ✅ Ready\n");
|
||||
}
|
||||
|
||||
if (emvOptV2 != null) {
|
||||
testResult.append(" - EMV: ✅ Ready\n");
|
||||
}
|
||||
|
||||
testResult.append("\n✅ SDK Integration: SUCCESS!");
|
||||
} catch (Exception e) {
|
||||
testResult.append(" - Error: ❌ ").append(e.getMessage()).append("\n");
|
||||
testResult.append("\n❌ SDK Integration: PARTIAL");
|
||||
}
|
||||
} else {
|
||||
testResult.append(" - Cannot test: SDK not connected\n");
|
||||
testResult.append("\n❌ SDK Integration: FAILED");
|
||||
}
|
||||
|
||||
Log.d("SDK_TEST", testResult.toString());
|
||||
|
||||
// Show result in a dialog
|
||||
showSDKTestDialog(testResult.toString());
|
||||
}
|
||||
|
||||
private void showSDKTestDialog(String testResult) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Sunmi SDK Integration Test")
|
||||
.setMessage(testResult)
|
||||
.setPositiveButton("OK", null)
|
||||
.setNeutralButton("Copy to Log", (dialog, which) -> {
|
||||
Log.i("SDK_TEST_RESULT", testResult);
|
||||
Toast.makeText(this, "Test result copied to log", Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
Reference in New Issue
Block a user