Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Android CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
27 changes: 10 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
plugins {
alias(libs.plugins.android.application)
id 'com.android.application'
}

android {
namespace 'de.androidcrypto.android_hce_beginner_app'
compileSdk 34
compileSdk 34 // Atualizado para Android 14

defaultConfig {
applicationId "de.androidcrypto.android_hce_beginner_app"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
minSdk 26 // Android 8.0 (compatível com maioria)
targetSdk 34 // Atualizado para Android 14 (Obrigatório)
versionCode 2
versionName "2.0"
}

buildTypes {
Expand All @@ -29,12 +27,7 @@ android {
}

dependencies {

implementation libs.appcompat
implementation libs.material
implementation libs.activity
implementation libs.constraintlayout
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
}
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
package de.androidcrypto.android_hce_beginner_app;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.nfc.cardemulation.CardEmulation;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText etTrackData;
Button btnGravar;
TextView tvStatus;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
/*
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

*/

BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
//bottomNav.setOnNavigationItemSelectedListener(navListener);
bottomNav.setOnItemSelectedListener(navListener);

// as soon as the application opens the first
// fragment should be shown to the user
// in this case it is algorithm fragment
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
// Busca os elementos do layout (que vamos criar no próximo passo)
etTrackData = findViewById(R.id.etTrackData);
btnGravar = findViewById(R.id.btnGravar);
tvStatus = findViewById(R.id.tvStatus);

// 1. Recuperar track salva anteriormente
SharedPreferences prefs = getSharedPreferences("NfcData", MODE_PRIVATE);
// Valor padrão de exemplo
String savedTrack = prefs.getString("TRACK_DATA", "00A4040007F00102030405069000");
etTrackData.setText(savedTrack);

// 2. Configura o botão de Gravar
btnGravar.setOnClickListener(view -> {
String newData = etTrackData.getText().toString().trim();
if (newData.isEmpty()) {
Toast.makeText(this, "A track não pode estar vazia!", Toast.LENGTH_SHORT).show();
return;
}

private final NavigationBarView.OnItemSelectedListener navListener = item -> {
// By using switch we can easily get
// the selected fragment
// by using there id.
Fragment selectedFragment = null;
int itemId = item.getItemId();
if (itemId == R.id.home) {
selectedFragment = new HomeFragment();
} else if (itemId == R.id.read) {
selectedFragment = new ReadFragment();
} else if (itemId == R.id.write) {
selectedFragment = new WriteFragment();
}

// It will help to replace the
// one fragment to other.
if (selectedFragment != null) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment).commit();
}
return true;
};
// Salva na memória permanente (SharedPreferences)
SharedPreferences.Editor editor = getSharedPreferences("NfcData", MODE_PRIVATE).edit();
editor.putString("TRACK_DATA", newData);
editor.apply();


}
tvStatus.setText("Track Gravada com Sucesso!\nPronto para aproximar da maquininha.");
Toast.makeText(this, "Dados NFC atualizados!", Toast.LENGTH_SHORT).show();
});

// Exibe o status inicial
tvStatus.setText("Última Track carregada. Clique em Gravar para confirmar.");
}
}
Loading