small changes

This commit is contained in:
Mathieu B 2021-08-13 22:31:21 +02:00
parent 852d3ddaac
commit 717b07bc02
5 changed files with 39 additions and 11 deletions

3
.gitignore vendored
View File

@ -10,6 +10,9 @@
# Java class files # Java class files
*.class *.class
.idea/**
.idea/
# Generated files # Generated files
bin/ bin/
gen/ gen/

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="9d45e847" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2021-08-13T20:01:53.677679Z" />
</component>
</project>

View File

@ -3,6 +3,8 @@ package ch.mathieubroillet.jarvis.android;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class ListeningActivity extends 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 // used for turning on the screen and show the activity
setShowWhenLocked(true); setShowWhenLocked(true);
setTurnScreenOn(true); setTurnScreenOn(true);
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) if (keyguardManager != null)
keyguardManager.requestDismissKeyguard(this, null); keyguardManager.requestDismissKeyguard(this, null);
// full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_listening); setContentView(R.layout.activity_listening);
} }

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -13,15 +14,12 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
public class Main extends AppCompatActivity { public class Main extends AppCompatActivity {
private boolean hasPermissions() { private boolean hasPermissions() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED && return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW) == PackageManager.PERMISSION_GRANTED;
} }
private void requestPermissions() { private void requestPermissions() {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 0); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.SYSTEM_ALERT_WINDOW}, 0);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, 0);
} }
private void startService() { private void startService() {
@ -44,9 +42,11 @@ public class Main extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
if (!hasPermissions()) { if (!hasPermissions()) {
requestPermissions(); Toast.makeText(this, "No pemerssions, accept all permissions and restart app.", Toast.LENGTH_SHORT).show();
}
startService(); requestPermissions();
} else {
startService();
}
} }
} }

View File

@ -36,13 +36,12 @@ public class PorcupineService extends Service {
getApplicationContext(), getApplicationContext(),
(keywordIndex) -> { (keywordIndex) -> {
Intent dialogIntent = new Intent(this, ListeningActivity.class);
Intent dialogIntent = new Intent(getBaseContext(), ListeningActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent); startActivity(dialogIntent);
Toast.makeText(this, "Jarvis detecté", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Wake-word detected!", Toast.LENGTH_SHORT).show();
}); });
porcupineManager.start(); porcupineManager.start();
} catch (PorcupineException e) { } catch (PorcupineException e) {