@@ -121,7 +121,7 @@ public class MainActivity extends AppCompatActivity {
121121 private static final String ACTION_USB_PERMISSION = "com.vagell.kv4pht.USB_PERMISSION" ;
122122
123123 // Radio params and related settings
124- private String activeFrequencyStr = "144 .0000" ;
124+ private String activeFrequencyStr = "0 .0000" ;
125125 private int squelch = 0 ;
126126 private String callsign = null ;
127127 private boolean stickyPTT = false ;
@@ -209,7 +209,7 @@ public void run() {
209209
210210 if (radioAudioService != null ) {
211211 radioAudioService .tuneToFreq (freq , squelch , false ); // Stay on the same freq as the now-deleted memory
212- tuneToFreqUi (freq );
212+ tuneToFreqUi (freq , false );
213213 }
214214
215215 viewModel .setCallback (null );
@@ -489,7 +489,17 @@ public void unknownLocation() {
489489 public void forceTunedToFreq (String newFreqStr ) {
490490 // This is called when RadioAudioService is changing bands, and we need
491491 // to reflect that in the UI.
492- tuneToFreqUi (newFreqStr );
492+ tuneToFreqUi (newFreqStr , true );
493+ }
494+
495+ @ Override
496+ public void forcedPttStart () { // When user pushes physical PTT.
497+ startPttUi (false );
498+ }
499+
500+ @ Override
501+ public void forcedPttEnd () { // When user releases physical PTT.
502+ endPttUi ();
493503 }
494504 };
495505
@@ -1004,32 +1014,6 @@ public void run() {
10041014 selectMemoryGroup (lastGroupSetting .value );
10051015 }
10061016
1007- if (lastMemoryId != null && !lastMemoryId .value .equals ("-1" )) {
1008- activeMemoryId = Integer .parseInt (lastMemoryId .value );
1009-
1010- if (radioAudioService != null ) {
1011- radioAudioService .setActiveMemoryId (activeMemoryId );
1012- }
1013- } else {
1014- activeMemoryId = -1 ;
1015- if (lastFreq != null ) {
1016- activeFrequencyStr = lastFreq .value ;
1017- } else {
1018- activeFrequencyStr = "144.0000" ;
1019- }
1020-
1021- if (radioAudioService != null ) {
1022- radioAudioService .setActiveMemoryId (activeMemoryId );
1023- radioAudioService .setActiveFrequencyStr (activeFrequencyStr );
1024- }
1025- }
1026-
1027- if (bandwidthSetting != null ) {
1028- if (radioAudioService != null ) {
1029- radioAudioService .setBandwidth (bandwidthSetting .value );
1030- }
1031- }
1032-
10331017 if (min2mTxFreqSetting != null ) {
10341018 int min2mTxFreq = Integer .parseInt (min2mTxFreqSetting .value );
10351019 if (radioAudioService != null ) {
@@ -1058,6 +1042,27 @@ public void run() {
10581042 }
10591043 }
10601044
1045+ if (lastMemoryId != null && !lastMemoryId .value .equals ("-1" )) {
1046+ activeMemoryId = Integer .parseInt (lastMemoryId .value );
1047+
1048+ if (radioAudioService != null ) {
1049+ radioAudioService .setActiveMemoryId (activeMemoryId );
1050+ }
1051+ } else {
1052+ activeMemoryId = -1 ;
1053+ if (lastFreq != null ) {
1054+ activeFrequencyStr = lastFreq .value ;
1055+ } else {
1056+ activeFrequencyStr = "0.0000" ; // Will force radioAudioService to use minimum freq in current band
1057+ }
1058+ }
1059+
1060+ if (bandwidthSetting != null ) {
1061+ if (radioAudioService != null ) {
1062+ radioAudioService .setBandwidth (bandwidthSetting .value );
1063+ }
1064+ }
1065+
10611066 if (micGainBoostSetting != null ) {
10621067 String micGainBoost = micGainBoostSetting .value ;
10631068 if (radioAudioService != null ) {
@@ -1076,7 +1081,7 @@ public void run() {
10761081 } else {
10771082 if (radioAudioService != null ) {
10781083 radioAudioService .tuneToFreq (activeFrequencyStr , squelch , radioAudioService .getMode () == RadioAudioService .MODE_RX );
1079- tuneToFreqUi (activeFrequencyStr );
1084+ tuneToFreqUi (activeFrequencyStr , radioAudioService . getMode () == RadioAudioService . MODE_RX );
10801085 }
10811086 }
10821087 if (radioAudioService != null ) {
@@ -1270,7 +1275,7 @@ public void onClick(View v) {
12701275 public boolean onEditorAction (TextView v , int actionId , KeyEvent event ) {
12711276 if (radioAudioService != null ) {
12721277 radioAudioService .tuneToFreq (activeFrequencyField .getText ().toString (), squelch , false );
1273- tuneToFreqUi (RadioAudioService .makeSafeHamFreq (activeFrequencyField .getText ().toString ())); // Fixes any invalid freq user may have entered.
1278+ tuneToFreqUi (RadioAudioService .makeSafeHamFreq (activeFrequencyField .getText ().toString ()), false ); // Fixes any invalid freq user may have entered.
12741279 }
12751280
12761281 hideKeyboard ();
@@ -1357,13 +1362,20 @@ private void hideKeyboard() {
13571362 * Updates the UI to represent that we've tuned to the given frequency. Does not actually
13581363 * interact with the radio (use RadioAudioService for that).
13591364 */
1360- private void tuneToFreqUi (String frequencyStr ) {
1365+ private void tuneToFreqUi (String frequencyStr , boolean wasForced ) {
13611366 final Context ctx = this ;
13621367 activeFrequencyStr = radioAudioService .validateFrequency (frequencyStr );
13631368 activeMemoryId = -1 ;
13641369
1370+ showMemoryName ("Simplex" );
1371+ showFrequency (activeFrequencyStr );
1372+
1373+ // Unhighlight all memory rows, since this is a simplex frequency.
1374+ viewModel .highlightMemory (null );
1375+ memoriesAdapter .notifyDataSetChanged ();
1376+
13651377 // Save most recent freq so we can restore it on app restart
1366- if (threadPoolExecutor == null ) {
1378+ if (threadPoolExecutor == null || wasForced ) { // wasForced means user didn't actually type in the frequency (we shouldn't save it)
13671379 return ;
13681380 }
13691381 threadPoolExecutor .execute (new Runnable () {
@@ -1391,13 +1403,6 @@ public void run() {
13911403 }
13921404 }
13931405 });
1394-
1395- showMemoryName ("Simplex" );
1396- showFrequency (activeFrequencyStr );
1397-
1398- // Unhighlight all memory rows, since this is a simplex frequency.
1399- viewModel .highlightMemory (null );
1400- memoriesAdapter .notifyDataSetChanged ();
14011406 }
14021407
14031408 /**
@@ -1452,7 +1457,6 @@ private void showFrequency(String frequency) {
14521457 runOnUiThread (new Runnable () {
14531458 @ Override
14541459 public void run () {
1455- Log .d ("DEBUG" , "showFrequency: " + frequency );
14561460 EditText activeFrequencyField = findViewById (R .id .activeFrequency );
14571461 activeFrequencyField .setText (frequency );
14581462 activeFrequencyStr = frequency ;
0 commit comments