diff --git a/.gitignore b/.gitignore index 56cc642..c70b517 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ # Java class files *.class +.idea/** +.idea/ + # Generated files bin/ gen/ diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..babf321 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/ListeningActivity.java b/app/src/main/java/ch/mathieubroillet/jarvis/android/ListeningActivity.java index 3da7d67..8224249 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/ListeningActivity.java +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/ListeningActivity.java @@ -3,6 +3,8 @@ package ch.mathieubroillet.jarvis.android; import android.app.KeyguardManager; import android.content.Context; import android.os.Bundle; +import android.view.WindowManager; + import androidx.appcompat.app.AppCompatActivity; public class ListeningActivity extends AppCompatActivity { @@ -14,10 +16,17 @@ public class ListeningActivity extends AppCompatActivity { // used for turning on the screen and show the activity setShowWhenLocked(true); setTurnScreenOn(true); + KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); if (keyguardManager != null) keyguardManager.requestDismissKeyguard(this, null); + + // full screen + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + + setContentView(R.layout.activity_listening); } diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/Main.java b/app/src/main/java/ch/mathieubroillet/jarvis/android/Main.java index 70f7e19..69602d7 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/Main.java +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/Main.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.widget.Toast; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; @@ -13,15 +14,12 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; public class Main extends AppCompatActivity { - private boolean hasPermissions() { - return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED && - ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW) == PackageManager.PERMISSION_GRANTED; + return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED; } private void requestPermissions() { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 0); - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, 0); + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.SYSTEM_ALERT_WINDOW}, 0); } private void startService() { @@ -44,9 +42,11 @@ public class Main extends AppCompatActivity { setContentView(R.layout.activity_main); if (!hasPermissions()) { - requestPermissions(); - } + Toast.makeText(this, "No pemerssions, accept all permissions and restart app.", Toast.LENGTH_SHORT).show(); - startService(); + requestPermissions(); + } else { + startService(); + } } } diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/PorcupineService.java b/app/src/main/java/ch/mathieubroillet/jarvis/android/PorcupineService.java index 68c0af3..c9094d3 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/PorcupineService.java +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/PorcupineService.java @@ -36,13 +36,12 @@ public class PorcupineService extends Service { getApplicationContext(), (keywordIndex) -> { - - Intent dialogIntent = new Intent(getBaseContext(), ListeningActivity.class); + Intent dialogIntent = new Intent(this, ListeningActivity.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(dialogIntent); - Toast.makeText(this, "Jarvis detecté", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "Wake-word detected!", Toast.LENGTH_SHORT).show(); }); porcupineManager.start(); } catch (PorcupineException e) {