Skip to content

Commit 50deaf9

Browse files
authored
Merge pull request #43 from sh123/aprs
Basic APRS messaging without acknowledgement
2 parents e478e30 + 52a78cc commit 50deaf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1420
-74
lines changed

codec2talkie/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<activity
4747
android:name=".storage.log.LogItemActivity"
4848
android:configChanges="orientation|screenSize" />
49+
<activity
50+
android:name=".storage.message.group.MessageGroupActivity"
51+
android:configChanges="orientation|screenSize" />
52+
<activity
53+
android:name=".storage.message.MessageItemActivity"
54+
android:configChanges="orientation|screenSize" />
4955
<activity
5056
android:name=".MainActivity"
5157
android:configChanges="orientation|screenSize">

codec2talkie/src/main/java/com/radio/codec2talkie/MainActivity.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.radio.codec2talkie.recorder.RecorderActivity;
5959
import com.radio.codec2talkie.settings.PreferenceKeys;
6060
import com.radio.codec2talkie.settings.SettingsActivity;
61+
import com.radio.codec2talkie.storage.message.group.MessageGroupActivity;
6162
import com.radio.codec2talkie.tools.AudioTools;
6263
import com.radio.codec2talkie.tools.RadioTools;
6364
import com.radio.codec2talkie.transport.TransportFactory;
@@ -68,7 +69,7 @@
6869
import java.util.List;
6970
import java.util.Locale;
7071

71-
public class MainActivity extends AppCompatActivity {
72+
public class MainActivity extends AppCompatActivity implements ServiceConnection {
7273

7374
private static final String TAG = MainActivity.class.getSimpleName();
7475

@@ -358,6 +359,13 @@ protected void startSettingsActivity() {
358359
_settingsActivityLauncher.launch(new Intent(this, SettingsActivity.class));
359360
}
360361

362+
private final ActivityResultLauncher<Intent> _messagesActivityLauncher = registerForActivityResult(
363+
new ActivityResultContracts.StartActivityForResult(), result -> {});
364+
365+
protected void startMessagesActivity() {
366+
_messagesActivityLauncher.launch(new Intent(this, MessageGroupActivity.class));
367+
}
368+
361369
protected boolean requestPermissions() {
362370
List<String> permissionsToRequest = new LinkedList<>();
363371
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -382,13 +390,13 @@ protected boolean requestPermissions() {
382390
}
383391

384392
private void bindAppService() {
385-
if (!bindService(new Intent(this, AppService.class), _appServiceConnection, Context.BIND_AUTO_CREATE)) {
393+
if (!bindService(new Intent(this, AppService.class), this, Context.BIND_AUTO_CREATE)) {
386394
Log.e(TAG, "Service does not exists or no access");
387395
}
388396
}
389397

390398
private void unbindAppService() {
391-
unbindService(_appServiceConnection);
399+
unbindService(this);
392400
}
393401

394402
private void startAppService(TransportFactory.TransportType transportType) {
@@ -552,7 +560,7 @@ else if (itemId == R.id.start_tracking) {
552560
return true;
553561
}
554562
else if (itemId == R.id.messages) {
555-
Toast.makeText(getBaseContext(), "Not implemented", Toast.LENGTH_SHORT).show();
563+
startMessagesActivity();
556564
return true;
557565
}
558566
else if (itemId == R.id.aprs_log) {
@@ -661,24 +669,21 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
661669
}
662670
}
663671

664-
private final ServiceConnection _appServiceConnection = new ServiceConnection() {
665-
666-
@Override
667-
public void onServiceConnected(ComponentName className, IBinder service) {
668-
Log.i(TAG, "Connected to app service");
669-
_appService = ((AppService.AppServiceBinder)service).getService();
670-
if (AppService.isRunning) {
671-
_textConnInfo.setText(_appService.getTransportName());
672-
updateMenuItemsAndStatusText();
673-
}
672+
@Override
673+
public void onServiceConnected(ComponentName className, IBinder service) {
674+
Log.i(TAG, "Connected to app service");
675+
_appService = ((AppService.AppServiceBinder)service).getService();
676+
if (AppService.isRunning) {
677+
_textConnInfo.setText(_appService.getTransportName());
678+
updateMenuItemsAndStatusText();
674679
}
680+
}
675681

676-
@Override
677-
public void onServiceDisconnected(ComponentName className) {
678-
Log.i(TAG, "Disconnected from app service");
679-
_appService = null;
680-
}
681-
};
682+
@Override
683+
public void onServiceDisconnected(ComponentName className) {
684+
Log.i(TAG, "Disconnected from app service");
685+
_appService = null;
686+
}
682687

683688
private final Handler onAppServiceStateChanged = new Handler(Looper.getMainLooper()) {
684689
@Override
@@ -726,9 +731,11 @@ public void handleMessage(Message msg) {
726731
case EV_RECEIVING:
727732
_btnPtt.setText(R.string.main_status_rx);
728733
break;
734+
case EV_TEXT_MESSAGE_RECEIVED:
729735
case EV_DATA_RECEIVED:
730736
if (msg.obj != null) {
731-
_textStatus.setText((String) msg.obj);
737+
String note = (String)msg.obj;
738+
_textStatus.setText(note.split(":")[0]);
732739
}
733740
_btnPtt.setText(R.string.main_status_data_received);
734741
break;

codec2talkie/src/main/java/com/radio/codec2talkie/app/AppMessage.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ public enum AppMessage {
66
EV_CONNECTED(1),
77
EV_LISTENING(2),
88
EV_TRANSMITTED_VOICE(3),
9-
EV_TRANSMITTED_DATA(4),
10-
EV_RECEIVING(5),
11-
EV_VOICE_RECEIVED(6),
12-
EV_DATA_RECEIVED(7),
13-
EV_RX_LEVEL(8),
14-
EV_TX_LEVEL(9),
15-
EV_RX_ERROR(10),
16-
EV_TX_ERROR(11),
17-
EV_RX_RADIO_LEVEL(12),
18-
EV_STARTED_TRACKING(13),
19-
EV_STOPPED_TRACKING(14),
9+
EV_TEXT_MESSAGE_TRANSMITTED(4),
10+
EV_TRANSMITTED_DATA(5),
11+
EV_RECEIVING(6),
12+
EV_VOICE_RECEIVED(7),
13+
EV_TEXT_MESSAGE_RECEIVED(8),
14+
EV_DATA_RECEIVED(9),
15+
EV_RX_LEVEL(10),
16+
EV_TX_LEVEL(11),
17+
EV_RX_ERROR(12),
18+
EV_TX_ERROR(13),
19+
EV_RX_RADIO_LEVEL(14),
20+
EV_STARTED_TRACKING(15),
21+
EV_STOPPED_TRACKING(16),
2022
// commands
21-
CMD_SEND_LOCATION_TO_TNC(15),
22-
CMD_PROCESS(16),
23-
CMD_QUIT(17),
24-
CMD_START_TRACKING(18),
25-
CMD_STOP_TRACKING(19),
26-
CMD_SEND_SINGLE_TRACKING(20);
23+
CMD_SEND_LOCATION_TO_TNC(17),
24+
CMD_PROCESS(18),
25+
CMD_QUIT(19),
26+
CMD_START_TRACKING(20),
27+
CMD_STOP_TRACKING(21),
28+
CMD_SEND_SINGLE_TRACKING(22),
29+
CMD_SEND_MESSAGE(23);
2730

2831
private final int _value;
2932

codec2talkie/src/main/java/com/radio/codec2talkie/app/AppService.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
import com.radio.codec2talkie.MainActivity;
3232
import com.radio.codec2talkie.R;
33+
import com.radio.codec2talkie.protocol.message.TextMessage;
3334
import com.radio.codec2talkie.settings.PreferenceKeys;
35+
import com.radio.codec2talkie.storage.message.MessageItemActivity;
3436
import com.radio.codec2talkie.tracker.Tracker;
3537
import com.radio.codec2talkie.tracker.TrackerFactory;
3638
import com.radio.codec2talkie.transport.TransportFactory;
@@ -46,12 +48,13 @@ public class AppService extends Service {
4648

4749
private final int SERVICE_NOTIFICATION_ID = 1;
4850
private final int VOICE_NOTIFICATION_ID = 2;
51+
private final int MESSAGE_NOTIFICATION_ID = 3;
4952

5053
private AppWorker _appWorker;
5154
private Messenger _callbackMessenger;
5255
private Tracker _tracker;
5356
private NotificationManager _notificationManager;
54-
PowerManager.WakeLock _serviceWakeLock;
57+
private PowerManager.WakeLock _serviceWakeLock;
5558

5659
private boolean _voiceNotificationsEnabled = false;
5760

@@ -99,6 +102,11 @@ public void stopTracking() {
99102
_onProcess.sendMessage(msg);
100103
}
101104

105+
public void sendTextMessage(TextMessage textMessage) {
106+
if (_appWorker != null)
107+
_appWorker.sendTextMessage(textMessage);
108+
}
109+
102110
public boolean isTracking() {
103111
if (_tracker == null) return false;
104112
return _tracker.isTracking();
@@ -155,7 +163,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
155163
transportType = (TransportFactory.TransportType) extras.get("transportType");
156164
startAppWorker(transportType);
157165

158-
Notification notification = buildNotification(getString(R.string.app_service_notif_text_ptt_ready), R.drawable.ic_app_action);
166+
Notification notification = buildServiceNotification(getString(R.string.app_service_notif_text_ptt_ready), R.drawable.ic_app_action);
159167
startForeground(SERVICE_NOTIFICATION_ID, notification);
160168
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
161169

@@ -214,6 +222,9 @@ public void handleMessage(Message msg) {
214222
case EV_VOICE_RECEIVED:
215223
showVoiceNotification(R.string.app_notifications_voice_title, R.string.app_notifications_voice_summary);
216224
break;
225+
case EV_TEXT_MESSAGE_RECEIVED:
226+
showMessageNotification(R.string.app_notifications_text_title, (String)msg.obj);
227+
break;
217228
case EV_LISTENING:
218229
hideVoiceNotification();
219230
break;
@@ -245,7 +256,7 @@ public void handleMessage(Message msg) {
245256

246257
private void showServiceNotification(int resId, int iconResId) {
247258
String text = getString(resId);
248-
_notificationManager.notify(SERVICE_NOTIFICATION_ID, buildNotification(text, iconResId));
259+
_notificationManager.notify(SERVICE_NOTIFICATION_ID, buildServiceNotification(text, iconResId));
249260
}
250261

251262
private void showVoiceNotification(int titleResId, int textResId) {
@@ -255,6 +266,12 @@ private void showVoiceNotification(int titleResId, int textResId) {
255266
_notificationManager.notify(VOICE_NOTIFICATION_ID, buildFullScreenNotification(title, text));
256267
}
257268

269+
private void showMessageNotification(int titleResId, String note) {
270+
if (!MessageItemActivity.isPaused || !_voiceNotificationsEnabled) return;
271+
String title = getString(titleResId);
272+
_notificationManager.notify(MESSAGE_NOTIFICATION_ID, buildMessageNotification(title, note));
273+
}
274+
258275
private void hideVoiceNotification() {
259276
if (!_voiceNotificationsEnabled) return;
260277
_notificationManager.cancel(VOICE_NOTIFICATION_ID);
@@ -269,7 +286,7 @@ private String createNotificationChannel(String channelId, String channelName, i
269286
return channelId;
270287
}
271288

272-
private Notification buildNotification(String text, int iconResId) {
289+
private Notification buildServiceNotification(String text, int iconResId) {
273290
String channelId = "";
274291
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
275292
channelId = createNotificationChannel("alpha", "Service", NotificationManager.IMPORTANCE_LOW);
@@ -312,4 +329,31 @@ private Notification buildFullScreenNotification(String title, String text) {
312329
.setAutoCancel(true)
313330
.build();
314331
}
332+
333+
private Notification buildMessageNotification(String title, String text) {
334+
String channelId = "";
335+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
336+
channelId = createNotificationChannel("gamma", "Message", NotificationManager.IMPORTANCE_HIGH);
337+
338+
// extract group name from the note
339+
String[] srcDstText = text.split(": ");
340+
String groupName = srcDstText[0].split("→")[1];
341+
342+
Intent notificationIntent = new Intent(this, MessageItemActivity.class);
343+
notificationIntent.putExtra("groupName", groupName);
344+
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
345+
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
346+
notificationIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
347+
348+
return new NotificationCompat.Builder(this, channelId)
349+
.setContentTitle(title)
350+
.setContentText(text)
351+
.setSmallIcon(R.drawable.ic_app_action)
352+
.setChannelId(channelId)
353+
.setPriority(NotificationCompat.PRIORITY_HIGH)
354+
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
355+
.setContentIntent(pendingIntent)
356+
.setAutoCancel(true)
357+
.build();
358+
}
315359
}

0 commit comments

Comments
 (0)