kopia lustrzana https://github.com/ge0rg/aprsdroid
				
				
				
			implemented preferences
							rodzic
							
								
									717213667a
								
							
						
					
					
						commit
						5ab5ddedfb
					
				|  | @ -15,6 +15,8 @@ | ||||||
|                 <category android:name="android.intent.category.LAUNCHER" /> |                 <category android:name="android.intent.category.LAUNCHER" /> | ||||||
|             </intent-filter> |             </intent-filter> | ||||||
|         </activity> |         </activity> | ||||||
|  |         <activity android:name=".PrefsAct" | ||||||
|  | 		android:label="@string/app_name" /> | ||||||
| 	<service android:name=".AprsService"> | 	<service android:name=".AprsService"> | ||||||
| 	    <intent-filter> | 	    <intent-filter> | ||||||
| 		<action android:name="de.duenndns.aprsdroid.SERVICE" /> | 		<action android:name="de.duenndns.aprsdroid.SERVICE" /> | ||||||
|  |  | ||||||
|  | @ -1,7 +1,25 @@ | ||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <resources> | <resources> | ||||||
|  | <string name="app_name">APRSdroid</string> | ||||||
|  | <string name="firstrun">You need to configure APRSdroid first!</string> | ||||||
| <string name="singlelog">Single Shot</string> | <string name="singlelog">Single Shot</string> | ||||||
| <string name="startlog">Start Logging</string> | <string name="startlog">Start Logging</string> | ||||||
| <string name="app_name">APRSdroid</string> |  | ||||||
| <string name="stoplog">Stop Logging</string> | <string name="stoplog">Stop Logging</string> | ||||||
|  | <string name="p__ham">Amateur Radio</string> | ||||||
|  | <string name="p_callsign">Callsign</string> | ||||||
|  | <string name="p_callsign_summary">Your HAM radio callsign</string> | ||||||
|  | <string name="p_callsign_entry">Enter your callsign</string> | ||||||
|  | <string name="p_passcode">Passcode</string> | ||||||
|  | <string name="p_passcode_summary">APRS-IS validation passcode</string> | ||||||
|  | <string name="p_passcode_entry">Enter the passcode for your call</string> | ||||||
|  | <string name="p__network">Networking</string> | ||||||
|  | <string name="p_host">Server</string> | ||||||
|  | <string name="p_host_summary">APRS-IS server (port 8080) to send beacons</string> | ||||||
|  | <string name="p_host_entry">Enter the APRS-IS server hostname</string> | ||||||
|  | <string name="p_interval">Update interval</string> | ||||||
|  | <string name="p_interval_summary">Minutes between beacon transmissions</string> | ||||||
|  | <string name="p_interval_entry">Enter the update interval [min]</string> | ||||||
|  | <string name="p_distance">Update distance</string> | ||||||
|  | <string name="p_distance_summary">Kilometers before beacon transmission</string> | ||||||
|  | <string name="p_distance_entry">Enter the update distance [km]</string> | ||||||
| </resources> | </resources> | ||||||
|  |  | ||||||
|  | @ -4,15 +4,19 @@ import _root_.android.app.Activity | ||||||
| import _root_.android.content._ | import _root_.android.content._ | ||||||
| import _root_.android.location._ | import _root_.android.location._ | ||||||
| import _root_.android.os.Bundle | import _root_.android.os.Bundle | ||||||
|  | import _root_.android.preference.PreferenceManager | ||||||
| import _root_.android.util.Log | import _root_.android.util.Log | ||||||
| import _root_.android.view.View | import _root_.android.view.View | ||||||
| import _root_.android.view.View.OnClickListener | import _root_.android.view.View.OnClickListener | ||||||
| import _root_.android.widget.Button | import _root_.android.widget.Button | ||||||
| import _root_.android.widget.TextView | import _root_.android.widget.TextView | ||||||
|  | import _root_.android.widget.Toast | ||||||
| 
 | 
 | ||||||
| class APRSdroid extends Activity with LocationListener with OnClickListener { | class APRSdroid extends Activity with LocationListener with OnClickListener { | ||||||
| 	val TAG = "APRSdroid" | 	val TAG = "APRSdroid" | ||||||
| 
 | 
 | ||||||
|  | 	lazy val prefs = PreferenceManager.getDefaultSharedPreferences(this) | ||||||
|  | 
 | ||||||
| 	lazy val lat = findViewById(R.id.lat).asInstanceOf[TextView] | 	lazy val lat = findViewById(R.id.lat).asInstanceOf[TextView] | ||||||
| 	lazy val lon = findViewById(R.id.lon).asInstanceOf[TextView] | 	lazy val lon = findViewById(R.id.lon).asInstanceOf[TextView] | ||||||
| 	lazy val status = findViewById(R.id.status).asInstanceOf[TextView] | 	lazy val status = findViewById(R.id.status).asInstanceOf[TextView] | ||||||
|  | @ -40,6 +44,17 @@ class APRSdroid extends Activity with LocationListener with OnClickListener { | ||||||
| 		registerReceiver(locReceiver, new IntentFilter(AprsService.UPDATE)) | 		registerReceiver(locReceiver, new IntentFilter(AprsService.UPDATE)) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	override def onResume() { | ||||||
|  | 		super.onResume() | ||||||
|  | 		List("callsign", "passcode", "host").foreach { p => | ||||||
|  | 			if (!prefs.contains(p)) { | ||||||
|  | 				startActivity(new Intent(this, classOf[PrefsAct])); | ||||||
|  | 				Toast.makeText(this, R.string.firstrun, Toast.LENGTH_SHORT).show() | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	override def onDestroy() { | 	override def onDestroy() { | ||||||
| 		super.onDestroy() | 		super.onDestroy() | ||||||
| 		unregisterReceiver(locReceiver) | 		unregisterReceiver(locReceiver) | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ import _root_.android.app.Service | ||||||
| import _root_.android.content.{Context, Intent} | import _root_.android.content.{Context, Intent} | ||||||
| import _root_.android.location._ | import _root_.android.location._ | ||||||
| import _root_.android.os.{Bundle, IBinder} | import _root_.android.os.{Bundle, IBinder} | ||||||
|  | import _root_.android.preference.PreferenceManager | ||||||
| import _root_.android.util.Log | import _root_.android.util.Log | ||||||
| import _root_.android.widget.Toast | import _root_.android.widget.Toast | ||||||
| 
 | 
 | ||||||
|  | @ -18,8 +19,7 @@ class AprsService extends Service with LocationListener { | ||||||
| 	import AprsService._ | 	import AprsService._ | ||||||
| 	val TAG = "AprsService" | 	val TAG = "AprsService" | ||||||
| 
 | 
 | ||||||
| 	val UPDATE_TIME = 10000 // 10k ms = 10s | 	lazy val prefs = PreferenceManager.getDefaultSharedPreferences(this) | ||||||
| 	val UPDATE_DIST = 10 // 10m |  | ||||||
| 
 | 
 | ||||||
| 	lazy val locMan = getSystemService(Context.LOCATION_SERVICE).asInstanceOf[LocationManager] | 	lazy val locMan = getSystemService(Context.LOCATION_SERVICE).asInstanceOf[LocationManager] | ||||||
| 
 | 
 | ||||||
|  | @ -29,8 +29,10 @@ class AprsService extends Service with LocationListener { | ||||||
| 		showToast("Service started: " + i.getAction) | 		showToast("Service started: " + i.getAction) | ||||||
| 		i.getAction match { | 		i.getAction match { | ||||||
| 		case SERVICE => | 		case SERVICE => | ||||||
|  | 			val upd_int = prefs.getInt("interval", 10) | ||||||
|  | 			val upd_dist = prefs.getInt("distance", 10) | ||||||
| 			locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, | 			locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, | ||||||
| 				UPDATE_TIME, UPDATE_DIST, this) | 				upd_int * 60000, upd_dist * 1000, this) | ||||||
| 		case SERVICE_ONCE => | 		case SERVICE_ONCE => | ||||||
| 			stopSelf() | 			stopSelf() | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -0,0 +1,11 @@ | ||||||
|  | package de.duenndns.aprsdroid | ||||||
|  | 
 | ||||||
|  | import _root_.android.os.Bundle | ||||||
|  | import _root_.android.preference.PreferenceActivity | ||||||
|  | 
 | ||||||
|  | class PrefsAct extends PreferenceActivity { | ||||||
|  | 	override def onCreate(savedInstanceState: Bundle) { | ||||||
|  | 		super.onCreate(savedInstanceState) | ||||||
|  | 		addPreferencesFromResource(R.xml.preferences) | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Georg Lukas
						Georg Lukas