Skip to content

Commit 99e90e4

Browse files
committed
auto start
1 parent 5a302bc commit 99e90e4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app/src/main/java/com/jvdegithub/aiscatcher/MainActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
public class MainActivity<binding> extends AppCompatActivity implements AisCatcherJava.AisCallback, DeviceManager.DeviceCallback {
6868

6969
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
70+
private boolean firstRun = true;
7071

7172
private LogBook logbook;
7273
private LocationHelper locationHelper;
@@ -200,6 +201,17 @@ private void onWeb () {
200201
startActivity(browserIntent);
201202
}
202203

204+
protected void AutoStart() {
205+
if(!Settings.getAutoStart(this)) return;
206+
if(DeviceManager.getDeviceType() != DeviceManager.DeviceType.RTLSDR &&
207+
DeviceManager.getDeviceType() != DeviceManager.DeviceType.AIRSPY &&
208+
DeviceManager.getDeviceType() != DeviceManager.DeviceType.AIRSPYHF)
209+
return;
210+
211+
if (!AisService.isRunning(getApplicationContext())) {
212+
onPlayStop();
213+
}
214+
}
203215
protected void onResume () {
204216

205217
super.onResume();
@@ -210,6 +222,11 @@ protected void onResume () {
210222
} else {
211223
updateUIwithStop();
212224
}
225+
226+
if(firstRun) {
227+
firstRun = false;
228+
AutoStart();
229+
}
213230
}
214231

215232
@Override

app/src/main/java/com/jvdegithub/aiscatcher/Settings.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ static void setDefault(Context context) {
5959

6060
preferences.edit().putString("sSHARINGKEY", "").commit();
6161
preferences.edit().putBoolean("sSHARING", false).commit();
62+
preferences.edit().putBoolean("sAUTOSTART", false).commit();
6263

6364
preferences.edit().putBoolean("w1SWITCH", false).commit();
6465
preferences.edit().putString("w1PORT", "8100").commit();
6566

66-
6767
preferences.edit().putString("oCGF_WIDE", "Default").commit();
6868
preferences.edit().putString("oMODEL_TYPE", "Default").commit();
6969
preferences.edit().putBoolean("oFP_DS", false).commit();
@@ -299,6 +299,12 @@ static public int getCGFSetting(Context context)
299299
return 1;
300300
}
301301

302+
static public boolean getAutoStart(Context context)
303+
{
304+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
305+
return preferences.getBoolean("sAUTOSTART",false);
306+
}
307+
302308
static public boolean getFixedPointDownsampling(Context context)
303309
{
304310
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

app/src/main/res/xml/preferences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
android:defaultValue="False"
2626
android:title="Force Dark Mode"/>
2727

28+
<SwitchPreferenceCompat
29+
android:key="sAUTOSTART"
30+
android:summary="Auto Start when USB device is available"
31+
android:defaultValue="False"
32+
android:title="Auto Start"/>
33+
2834
</PreferenceCategory>
2935

3036
<PreferenceCategory

0 commit comments

Comments
 (0)