kopia lustrzana https://github.com/ge0rg/aprsdroid
Profile Import: direct JSON to config
rodzic
d377bdfa5f
commit
3ee13d9894
|
@ -92,6 +92,26 @@
|
|||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ProfileImportActivity" android:label="@string/profile_import_activity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="file"
|
||||
android:mimeType="*/*"
|
||||
android:host="*"
|
||||
android:pathPattern=".*\\.aprs" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="content"
|
||||
android:mimeType="*/*"
|
||||
android:host="*"
|
||||
android:pathPattern=".*\\.aprs" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".KeyfileImportActivity" android:label="@string/ssl_import_activity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
|
|
@ -384,6 +384,11 @@
|
|||
<string name="ssl_expired">Your certificate has expired!</string>
|
||||
<string name="ssl_expire_in">Your certificate will expire in %d days!</string>
|
||||
|
||||
<!-- Config import -->
|
||||
<string name="profile_import_activity">Profile import</string>
|
||||
<string name="profile_import_done">Import successful!</string>
|
||||
<string name="profile_import_error">Error importing profile: %s!</string>
|
||||
|
||||
<!-- (USB) Serial TNC settings -->
|
||||
<string name="p_serial_baudrate">Baud Rate</string>
|
||||
<string name="p_serial_baudrate_summary">Data rate of the serial port</string>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package org.aprsdroid.app
|
||||
|
||||
import android.app.Activity
|
||||
import android.content._
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.widget.{EditText, Toast}
|
||||
|
||||
import java.io.File
|
||||
import java.util.Scanner
|
||||
|
||||
import org.json._
|
||||
|
||||
import scala.collection.JavaConversions._ // for enumeration of config items
|
||||
|
||||
class ProfileImportActivity extends Activity {
|
||||
val TAG = "APRSdroid.ProfileImport"
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log.d(TAG, "created: " + getIntent())
|
||||
import_config()
|
||||
}
|
||||
|
||||
def import_config() {
|
||||
try {
|
||||
// parse stream into string, http://stackoverflow.com/a/5445161/539443
|
||||
val scanner = new Scanner(getContentResolver().openInputStream(getIntent.getData())).useDelimiter("\\A")
|
||||
val config_string = scanner.next()
|
||||
val config = new JSONObject(config_string)
|
||||
val prefsedit = PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
|
||||
val keys = config.keys()
|
||||
while (keys.hasNext()) {
|
||||
val item = keys.next().asInstanceOf[String]
|
||||
val value = config.get(item)
|
||||
Log.d(TAG, "reading: " + item + " = " + value + "/" + value.getClass())
|
||||
|
||||
// Hack: too complicated to figure out scala match rules for native types
|
||||
value.getClass().getSimpleName() match {
|
||||
case "String" => prefsedit.putString(item, config.getString(item))
|
||||
case "Boolean" => prefsedit.putBoolean(item, config.getBoolean(item))
|
||||
case "Int" => prefsedit.putInt(item, config.getInt(item))
|
||||
}
|
||||
}
|
||||
prefsedit.commit()
|
||||
Toast.makeText(this, R.string.profile_import_done, Toast.LENGTH_SHORT).show()
|
||||
} catch {
|
||||
case e : Exception =>
|
||||
Toast.makeText(this, getString(R.string.profile_import_error, e.getMessage()), Toast.LENGTH_LONG).show()
|
||||
e.printStackTrace()
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue