Skip to content

Commit

Permalink
interaction is back :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Maucourt committed Sep 19, 2020
1 parent 789b0c9 commit ccee042
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "net.sylvek.itracing2"
minSdkVersion 26
targetSdkVersion 29
versionCode 77
versionName "2.5.2"
versionCode 78
versionName "2.5.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
41 changes: 0 additions & 41 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,5 @@
<activity android:name=".preferences.PreferencesActivity" android:label="@string/preferences"
android:parentActivityName=".devices.DevicesActivity"/>
<service android:name=".BluetoothLEService"/>
<receiver android:name=".receivers.LinkBackground">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".receivers.CapturePosition">
<intent-filter>
<action android:name="net.sylvek.itracing2.action.CAPTURE_POSITION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".receivers.CustomAction">
<intent-filter>
<action android:name="net.sylvek.itracing2.action.CUSTOM_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".receivers.ToggleVibratePhone">
<intent-filter>
<action android:name="net.sylvek.itracing2.action.STOP_VIBRATE_PHONE"/>
<action android:name="net.sylvek.itracing2.action.START_VIBRATE_PHONE"/>
<action android:name="net.sylvek.itracing2.action.TOGGLE_VIBRATE_PHONE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".receivers.ToggleRingPhone">
<intent-filter>
<action android:name="net.sylvek.itracing2.action.TOGGLE_RING_PHONE"/>
<action android:name="net.sylvek.itracing2.action.STOP_RING_PHONE"/>
<action android:name="net.sylvek.itracing2.action.START_RING_PHONE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".receivers.ImmediateAlert">
<intent-filter>
<action android:name="net.sylvek.itracing2.action.IMMEDIATE_ALERT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="itag" />
</intent-filter>
</receiver>
</application>
</manifest>
52 changes: 51 additions & 1 deletion app/src/main/java/net/sylvek/itracing2/BluetoothLEService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.Service;
import android.bluetooth.*;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.os.Binder;
import android.os.Build;
Expand All @@ -19,6 +20,12 @@
import net.sylvek.itracing2.database.Devices;
import net.sylvek.itracing2.database.Events;
import net.sylvek.itracing2.devices.DevicesActivity;
import net.sylvek.itracing2.receivers.CapturePosition;
import net.sylvek.itracing2.receivers.CustomAction;
import net.sylvek.itracing2.receivers.ImmediateAlert;
import net.sylvek.itracing2.receivers.LinkBackground;
import net.sylvek.itracing2.receivers.ToggleRingPhone;
import net.sylvek.itracing2.receivers.ToggleVibratePhone;

import java.util.HashMap;
import java.util.UUID;
Expand Down Expand Up @@ -280,6 +287,7 @@ public IBinder onBind(Intent intent) {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.registerReceivers();
this.setForegroundEnabled(Preferences.isForegroundEnabled(this));
this.connect();

Expand All @@ -291,6 +299,48 @@ public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}

private void registerReceivers() {
IntentFilter f1 = new IntentFilter();
f1.addAction("net.sylvek.itracing2.action.CAPTURE_POSITION");
f1.addCategory("android.intent.category.DEFAULT");
registerReceiver(new CapturePosition(), f1);
Log.d(TAG, "CapturePosition() - registered with: " + f1);

IntentFilter f2 = new IntentFilter();
f2.addAction("net.sylvek.itracing2.action.CUSTOM_ACTION");
f2.addCategory("android.intent.category.DEFAULT");
registerReceiver(new CustomAction(), f2);
Log.d(TAG, "CustomAction() - registered with: " + f2);

IntentFilter f3 = new IntentFilter();
f3.addAction("net.sylvek.itracing2.action.STOP_VIBRATE_PHONE");
f3.addAction("net.sylvek.itracing2.action.START_VIBRATE_PHONE");
f3.addAction("net.sylvek.itracing2.action.TOGGLE_VIBRATE_PHONE");
f3.addCategory("android.intent.category.DEFAULT");
registerReceiver(new ToggleVibratePhone(), f3);
Log.d(TAG, "ToggleVibratePhone() - registered with: " + f3);

IntentFilter f4 = new IntentFilter();
f4.addAction("net.sylvek.itracing2.action.TOGGLE_RING_PHONE");
f4.addAction("net.sylvek.itracing2.action.STOP_RING_PHONE");
f4.addAction("net.sylvek.itracing2.action.START_RING_PHONE");
f4.addCategory("android.intent.category.DEFAULT");
registerReceiver(new ToggleRingPhone(), f4);
Log.d(TAG, "ToggleRingPhone() - registered with: " + f4);

IntentFilter f5 = new IntentFilter();
f5.addAction("net.sylvek.itracing2.action.IMMEDIATE_ALERT");
f5.addCategory("android.intent.category.DEFAULT");
registerReceiver(new ImmediateAlert(), f5);
Log.d(TAG, "ImmediateAlert() - registered with: " + f5);

IntentFilter f6 = new IntentFilter();
f6.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
f6.addCategory("android.intent.category.DEFAULT");
registerReceiver(new LinkBackground(), f6);
Log.d(TAG, "LinkBackground() - registered with: " + f6);
}

public void setForegroundEnabled(boolean enabled) {
if (enabled) {
final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Expand All @@ -310,7 +360,7 @@ public void setForegroundEnabled(boolean enabled) {
}

private String getNotificationChannel(NotificationManager notificationManager) {
String channelId = "channelid";
String channelId = "channel-itracing2";
String channelName = getResources().getString(R.string.app_name);
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onCreate(Bundle savedInstanceState)
showDevices();

if (!isMyServiceRunning(BluetoothLEService.class)) {
startService(new Intent(this, BluetoothLEService.class));
startForegroundService(new Intent(this, BluetoothLEService.class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void onReceive(Context context, Intent intent) {
final Intent mapIntent = getMapIntent(position);

final Notification notification = new Notification.Builder(context)
.setChannelId("channel-itracing2")
.setContentText(context.getString(R.string.display_last_position))
.setContentTitle(context.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_launcher)
Expand Down

0 comments on commit ccee042

Please sign in to comment.