diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a87a048 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +barbosa&landerAPI \ No newline at end of file diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/appInsightsSettings.xml b/.idea/appInsightsSettings.xml new file mode 100644 index 0000000..371f2e2 --- /dev/null +++ b/.idea/appInsightsSettings.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..ca16a99 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..a74fffb --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.barbosalanderapi" + compileSdk = 36 + + defaultConfig { + applicationId = "com.example.barbosalanderapi" + minSdk = 24 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + + implementation("com.squareup.retrofit2:retrofit:2.11.0") + implementation("com.squareup.retrofit2:converter-gson:2.11.0") + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + // Coroutines para não travar a UI + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/barbosalanderapi/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/barbosalanderapi/ExampleInstrumentedTest.java new file mode 100644 index 0000000..5ca5bc8 --- /dev/null +++ b/app/src/androidTest/java/com/example/barbosalanderapi/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.barbosalanderapi; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.barbosalanderapi", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8322159 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/barbosalanderapi/MainActivity.java b/app/src/main/java/com/example/barbosalanderapi/MainActivity.java new file mode 100644 index 0000000..013de9e --- /dev/null +++ b/app/src/main/java/com/example/barbosalanderapi/MainActivity.java @@ -0,0 +1,218 @@ +package com.example.barbosalanderapi; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import android.os.Handler; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.barbosalanderapi.R; +import com.example.barbosalanderapi.RandomApiService; +import com.example.barbosalanderapi.RandomRequest; +import com.example.barbosalanderapi.RandomResponse; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class MainActivity extends AppCompatActivity { + + private TextView slot1, slot2, slot3, txtSaldo; + private EditText editAposta; + private Button btnSortear; + private ProgressBar progress; + + private long saldo = 100000; + private long apostaAtual = 0; + + private final String API_KEY = "ebfb7ff0-b2f6-41c8-bef3-4fba17be410c"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + slot1 = findViewById(R.id.slot1); + slot2 = findViewById(R.id.slot2); + slot3 = findViewById(R.id.slot3); + txtSaldo = findViewById(R.id.txtSaldo); + editAposta = findViewById(R.id.editAposta); + btnSortear = findViewById(R.id.btnSortear); + progress = findViewById(R.id.progress); + + atualizarSaldoUI(); + + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://api.random.org/") + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + RandomApiService service = retrofit.create(RandomApiService.class); + + btnSortear.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + girarSlots(service); + } + }); + } + + private void girarSlots(RandomApiService service) { + String inputAposta = editAposta.getText().toString(); + if (inputAposta.isEmpty()) { + Toast.makeText(this, "Insira um valor de aposta!", Toast.LENGTH_SHORT).show(); + return; + } + + apostaAtual = Long.parseLong(inputAposta); + + if (apostaAtual <= 0) { + Toast.makeText(this, "Aposta deve ser maior que 0!", Toast.LENGTH_SHORT).show(); + return; + } + + if (apostaAtual > saldo) { + Toast.makeText(this, "Saldo insuficiente!", Toast.LENGTH_SHORT).show(); + return; + } + + // Subtrai a aposta do saldo + saldo -= apostaAtual; + atualizarSaldoUI(); + + progress.setVisibility(View.VISIBLE); + btnSortear.setEnabled(false); + editAposta.setEnabled(false); + + RandomRequest request = new RandomRequest(API_KEY, 3, 1, 5); + + service.generateIntegers(request).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + progress.setVisibility(View.GONE); + btnSortear.setEnabled(true); + + if (response.isSuccessful() && response.body() != null) { + RandomResponse body = response.body(); + + if (body.result != null && body.result.random != null && body.result.random.data != null) { + int[] numeros = body.result.random.data; + + iniciarAnimacaoSlot(slot1, numeros[0], 1000, false); + iniciarAnimacaoSlot(slot2, numeros[1], 2000, false); + iniciarAnimacaoSlot(slot3, numeros[2], 3000, true); + } else if (body.error != null) { + + Log.e("API_JSON_RPC_ERROR", "Erro: " + body.error.message); + + + + usarSorteioLocal(); + } else { + usarSorteioLocal(); + } + } else { + Toast.makeText(MainActivity.this, "Erro de rede: " + response.code() + " - Usando Sorteio Local", Toast.LENGTH_SHORT).show(); + Log.e("API_HTTP_ERROR", "Código: " + response.code()); + usarSorteioLocal(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + progress.setVisibility(View.GONE); + btnSortear.setEnabled(true); + Toast.makeText(MainActivity.this, "Sem Internet - Usando Sorteio Local", Toast.LENGTH_SHORT).show(); + Log.e("API_ERRO", "Erro: " + t.getMessage()); + usarSorteioLocal(); + } + }); + } + + private void usarSorteioLocal() { + java.util.Random random = new java.util.Random(); + int[] numeros = { + random.nextInt(5) + 1, + random.nextInt(5) + 1, + random.nextInt(5) + 1 + }; + + iniciarAnimacaoSlot(slot1, numeros[0], 1000, false); + iniciarAnimacaoSlot(slot2, numeros[1], 2000, false); + iniciarAnimacaoSlot(slot3, numeros[2], 3000, true); + } + + private void iniciarAnimacaoSlot(final TextView slot, final int numeroFinal, final long tempoDeGiro, final boolean isUltimo) { + final long startTime = System.currentTimeMillis(); + final Handler handler = new Handler(); + final java.util.Random rand = new java.util.Random(); + + handler.post(new Runnable() { + @Override + public void run() { + long elapsed = System.currentTimeMillis() - startTime; + + if (elapsed < tempoDeGiro) { + slot.setText(numeroParaEmoji(rand.nextInt(5) + 1)); + + slot.setTranslationY((float) (Math.random() * 10 - 5)); + + handler.postDelayed(this, 80); + } else { + slot.setText(numeroParaEmoji(numeroFinal)); + slot.setTranslationY(0); + + slot.setScaleX(1.3f); + slot.setScaleY(1.3f); + slot.animate().scaleX(1.0f).scaleY(1.0f).setDuration(300).start(); + + if (isUltimo) { + verificarGanhador(); + btnSortear.setEnabled(true); + editAposta.setEnabled(true); + progress.setVisibility(View.GONE); + } + } + } + }); + } + + private void verificarGanhador() { + String s1 = slot1.getText().toString(); + String s2 = slot2.getText().toString(); + String s3 = slot3.getText().toString(); + + if (s1.equals(s2) && s2.equals(s3)) { + long premio = apostaAtual * 2; + saldo += premio; + Toast.makeText(MainActivity.this, "JACKPOT! 🎰💰 GANHOU " + premio + "€!", Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(MainActivity.this, "Não foi desta vez! Perdeu " + apostaAtual + "€", Toast.LENGTH_SHORT).show(); + } + atualizarSaldoUI(); + } + + private void atualizarSaldoUI() { + txtSaldo.setText("SALDO: " + String.format("%,d", saldo).replace(',', '.') + "€"); + } + + private String numeroParaEmoji(int numero) { + switch (numero) { + case 1: return "🍒"; + case 2: return "🍋"; + case 3: return "🔔"; + case 4: return "💎"; + case 5: return "7️⃣"; + default: return "❓"; + } + } +} + +//teste git \ No newline at end of file diff --git a/app/src/main/java/com/example/barbosalanderapi/RandomApiService.java b/app/src/main/java/com/example/barbosalanderapi/RandomApiService.java new file mode 100644 index 0000000..922f346 --- /dev/null +++ b/app/src/main/java/com/example/barbosalanderapi/RandomApiService.java @@ -0,0 +1,10 @@ +package com.example.barbosalanderapi; + +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.POST; + +public interface RandomApiService { + @POST("json-rpc/2/invoke") + Call generateIntegers(@Body RandomRequest request); +} diff --git a/app/src/main/java/com/example/barbosalanderapi/RandomRequest.java b/app/src/main/java/com/example/barbosalanderapi/RandomRequest.java new file mode 100644 index 0000000..5c841a0 --- /dev/null +++ b/app/src/main/java/com/example/barbosalanderapi/RandomRequest.java @@ -0,0 +1,26 @@ +package com.example.barbosalanderapi; + +public class RandomRequest { + public String jsonrpc = "2.0"; + public String method = "generateIntegers"; + public Params params; + public int id = 1; + + public RandomRequest(String apiKey, int n, int min, int max) { + this.params = new Params(apiKey, n, min, max); + } + + public static class Params { + public String apiKey; + public int n; + public int min; + public int max; + + public Params(String apiKey, int n, int min, int max) { + this.apiKey = apiKey; + this.n = n; + this.min = min; + this.max = max; + } + } +} diff --git a/app/src/main/java/com/example/barbosalanderapi/RandomResponse.java b/app/src/main/java/com/example/barbosalanderapi/RandomResponse.java new file mode 100644 index 0000000..3bdd38d --- /dev/null +++ b/app/src/main/java/com/example/barbosalanderapi/RandomResponse.java @@ -0,0 +1,19 @@ +package com.example.barbosalanderapi; + +public class RandomResponse { + public Result result; + public Error error; + + public static class Result { + public RandomData random; + } + + public static class RandomData { + public int[] data; + } + + public static class Error { + public int code; + public String message; + } +} diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..bdf2cbc --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + +