Skip to content

Commit

Permalink
Version 0.3.2
Browse files Browse the repository at this point in the history
-------------
- [EXPERIMENTAL] Streaming
- configure each sensor manually
- configure loggers
  • Loading branch information
francescogabbrielli committed Oct 8, 2018
1 parent 267b97a commit ae0d868
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "sensor-logger"
abiFilters 'armeabi-v7a', 'arm64-v8a'
abiFilters 'armeabi-v7a'//, 'arm64-v8a'
}
}
buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/assets/defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pref_ftp_user =user
pref_ftp_pw =francesco
pref_ftp_address =192.168.1.1

# transferring by streaming (0=nothing, 1=images)
pref_streaming =0
# transferring by streaming
pref_streaming =false
pref_streaming_port =8080


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ public LogFtp(SharedPreferences prefs) {
password = prefs.getString(Util.PREF_FTP_PW, "");
}

@Override
protected OutputStream openOutputStream(String folder, String filename) throws IOException {
if (!folderCreated) {
client.makeDirectory(folder);
folderCreated = client.changeWorkingDirectory(folder);
}
return client.storeFileStream(filename);
}

/**
* Connects to the FTP server
*/
Expand All @@ -53,6 +44,15 @@ public void connect() throws IOException {
}
}

@Override
protected OutputStream openOutputStream(String folder, String filename) throws IOException {
if (!folderCreated) {
client.makeDirectory(folder);
folderCreated = client.changeWorkingDirectory(folder);
}
return client.storeFileStream(filename);
}

@Override
public void close() throws IOException {
super.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected void onPermissionDenied(String permission) {
if (Manifest.permission.CAMERA.equals(permission)) {
prefs.edit()
.putBoolean(Util.PREF_CAPTURE_CAMERA, false)
.putString(Util.PREF_STREAMING, "0").apply();
.putBoolean(Util.PREF_STREAMING, false).apply();
} else if (Manifest.permission.INTERNET.equals(permission)) {
prefs.edit().putString(Util.PREF_FTP, "0").apply();
} else if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permission)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,32 @@ public boolean onPreferenceChange(Preference preference, Object value) {
Log.d(TAG, "Preference "+preference.getKey()+" -> "+value+" ["+value.getClass()+"]");
String stringValue = value.toString();
Context ctx = preference.getContext();
int descriptionId = ctx.getResources().getIdentifier(
preference.getKey() + "_description", "string", ctx.getPackageName());
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);

if (index < 0) {
preference.setSummary(null);
} else {
listPreference.setValueIndex(index);
CharSequence val = listPreference.getEntries()[index];
int descriptionId = ctx.getResources().getIdentifier(
preference.getKey() + "_description", "string", ctx.getPackageName());
// Set the summary to reflect the new value.
preference.setSummary(descriptionId != 0
? ctx.getString(descriptionId, val)
: val);
: val
);
}

} else if(preference instanceof EditTextPreference &&
(((EditTextPreference) preference).getEditText().getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD)!=0) {

preference.setSummary(stringValue.replaceAll(".","*"));

} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
// simple string representation (plus optional description).
preference.setSummary(descriptionId!=0 ? ctx.getString(descriptionId, stringValue) : stringValue);
}
return true;
}
Expand Down Expand Up @@ -224,7 +222,7 @@ public static class StreamingPreferenceFragment extends AppCompatPreferenceFragm
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_streaming);
bindPreferenceSummaryToValue(findPreference(Util.PREF_STREAMING));
// bindPreferenceSummaryToValue(findPreference(Util.PREF_STREAMING));
bindPreferenceSummaryToValue(findPreference(Util.PREF_STREAMING_PORT));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public void run() {
if (!prefs.contains(key)) {
String val = defaults.getProperty(key);
//TODO: manage different types?
if ("TRUE".equalsIgnoreCase(val) || "FALSE".equalsIgnoreCase(val))
if ("TRUE".equalsIgnoreCase(val) || "FALSE".equalsIgnoreCase(val)) {
editor.putBoolean(key, Boolean.parseBoolean(val.toLowerCase()));
else
Log.d("Defaults", key+"="+val);
} else
editor.putString(key, val);
}
}
Expand Down Expand Up @@ -162,7 +163,11 @@ public static int getSensorMaxLength(Sensor sensor) {
}

public static int getIntPref(SharedPreferences prefs, String prefKey) {
return Integer.valueOf(prefs.getString(prefKey, "0"));
Object val = prefs.getAll().get(prefKey);
if (val instanceof Boolean)
return prefs.getBoolean(prefKey, false) ? 1 : 0;
else
return val!=null ? Integer.valueOf(val.toString()) : 0;
}

public static long getLongPref(SharedPreferences prefs, String prefKey) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
<!-- Settings -> Streaming -->
<string name="pref_streaming_header">Streaming</string>
<string name="pref_streaming_title">Enable Image Streaming</string>
<string name="pref_streaming_description">[EXPERIMENTAL] The images will be streamed over HTTP: %s</string>
<string name="pref_streaming_port_title">Start server on port</string>
<string name="pref_streaming_description">[EXPERIMENTAL] The images will be streamed over HTTP</string>
<string name="pref_streaming_port_title">Port</string>
<string name="pref_streaming_port_description">Start streaming server on port %s</string>

<!-- Settings -> Logging -->
<string name="pref_logging_header">Logging</string>
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/res/xml/pref_streaming.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<ListPreference
<SwitchPreference
android:key="pref_streaming"
android:title="@string/pref_ftp_title"
android:summary="@string/pref_ftp_description"
android:entries="@array/pref_logtarget_list_titles"
android:entryValues="@array/pref_logtarget_list_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_streaming_title"
android:summary="@string/pref_streaming_description"
/>

<EditTextPreference
android:key="pref_streaming_port"
android:dependency="pref_streaming"
android:title="@string/pref_streaming_port_title"
android:summary="@string/pref_streaming_port_description"
android:inputType="number"
/>

Expand Down

0 comments on commit ae0d868

Please sign in to comment.