Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make camera audio optional #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
compileSdkVersion 32
buildToolsVersion '32.0.0'

defaultConfig {
applicationId "fr.inria.tyrex.senslogs"
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 32
versionCode 4
versionName "2.2"
}
Expand All @@ -28,10 +28,10 @@ repositories {
}

dependencies {
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.bignerdranch.android:recyclerview-multiselect:0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.ini4j:ini4j:0.5.1'
}
16 changes: 8 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.NFC" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".Application"
android:allowBackup="true"
Expand All @@ -35,6 +32,7 @@
<activity
android:name=".ui.MainActivity"
android:configChanges="keyboard|orientation|screenSize"
android:exported="true"
android:keepScreenOn="true"
android:label="@string/app_name"
android:screenOrientation="portrait">
Expand All @@ -46,12 +44,14 @@

<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="https"
android:host="github.com"
android:pathPrefix="/tyrex-team/senslogs" />
<data
android:host="github.com"
android:pathPrefix="/tyrex-team/senslogs"
android:scheme="https" />
</intent-filter>
</activity>

Expand All @@ -64,7 +64,7 @@
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
android:resource="@xml/provider_paths" />
</provider>
</application>

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/fr/inria/tyrex/senslogs/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class Application extends android.app.Application {
private LogsManager mLogsManager;



@Override
public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -60,12 +59,12 @@ private void cleanTmpFiles() {

deleteRecursive(getCacheDir());

if(mLogsManager == null) {
if (mLogsManager == null) {
return;
}

List<File> logFiles = new ArrayList<>();
for(Log log : mLogsManager.getLogs()) {
for (Log log : mLogsManager.getLogs()) {
logFiles.add(log.getZipFile());
}

Expand All @@ -85,7 +84,7 @@ public static void deleteRecursive(File fileOrDirectory) {
for (File child : fileOrDirectory.listFiles())
deleteRecursive(child);

if(!fileOrDirectory.delete()) {
if (!fileOrDirectory.delete()) {
android.util.Log.e(Application.LOG_TAG, "Cannot delete log file");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected File doInBackground(Input... params) {
@Override
protected void onProgressUpdate(Long... values) {
super.onProgressUpdate(values);
if(mListener != null && values.length == 1) {
if (mListener != null && values.length == 1) {
mListener.onProgress(values[0]);
}
}
Expand All @@ -73,11 +73,14 @@ protected void onPostExecute(File outputFile) {


private Listener mListener;

public void setListener(Listener listener) {
mListener = listener;
}

public interface Listener {
void onCopyFinished(File outputFile);

void onProgress(Long currentSize);
}
}
17 changes: 5 additions & 12 deletions app/src/main/java/fr/inria/tyrex/senslogs/control/LogsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void addLog(Log log) {


public void deleteLog(Log log) {
if(!log.getZipFile().delete()) {
if (!log.getZipFile().delete()) {
android.util.Log.e(Application.LOG_TAG, "Cannot delete log file");
}
mLogs.remove(log);
Expand All @@ -48,16 +48,9 @@ public void deleteLog(Log log) {
}



public File copyLogToSdCard(Context context, Log log, CopyTask.Listener listener) {

File outputDir = new File(Environment.getExternalStorageDirectory(),
context.getString(R.string.folder_logs_sd_card));

if(!outputDir.exists() && !outputDir.mkdir()) {
return null;
}

File outputDir = context.getExternalFilesDir(null);
File outputFile = new File(outputDir, log.getZipFile().getName());

CopyTask task = new CopyTask();
Expand All @@ -83,18 +76,18 @@ public void onDatasetChanged(Log log) {
private void loadLogs() {

mLogs = mDataSource.getLogs();
for(Log log : mLogs) {
for (Log log : mLogs) {
log.addListener(mDatasetChangedListener);
}

}

public void clearAll() {
Iterator<Log> iterator = mLogs.iterator();
while(iterator.hasNext()) {
while (iterator.hasNext()) {
Log log = iterator.next();
log.removeListener(mDatasetChangedListener);
if(!log.getZipFile().delete()) {
if (!log.getZipFile().delete()) {
android.util.Log.e(Application.LOG_TAG, "Cannot delete log file");
}
iterator.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import android.util.Pair;

import java.io.File;
Expand Down Expand Up @@ -297,7 +299,12 @@ public void onServiceConnected(ComponentName className,

Intent intent = new Intent(mContext, RecordActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pendingIntentFlags |= PendingIntent.FLAG_IMMUTABLE;
}
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
pendingIntentFlags);

NotificationCompat.Builder builder =
new NotificationCompat.Builder(mContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public List<Sensor> getAvailableSensors() {
return mAvailableSensorsList;
}

public List<Sensor> getSensorsToCalibrate() { return mSensorsToCalibrate;}
public List<Sensor> getSensorsToCalibrate() {
return mSensorsToCalibrate;
}

private void generateAvailableSensors(Context context) {

Expand All @@ -47,7 +49,7 @@ private void generateAvailableSensors(Context context) {
for (android.hardware.Sensor sensor : sensorManager.getSensorList(android.hardware.Sensor.TYPE_ALL)) {
AndroidSensor as = new AndroidSensor(sensor);
mAvailableSensorsList.add(as);
switch(sensor.getType()) {
switch (sensor.getType()) {
case android.hardware.Sensor.TYPE_ACCELEROMETER_UNCALIBRATED:
case android.hardware.Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
case android.hardware.Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public String toString() {
}

public Object[] toObject() {
if(level == null)
return new Object[] {latitude, longitude};
return new Object[] {latitude, longitude, level};
if (level == null)
return new Object[]{latitude, longitude};
return new Object[]{latitude, longitude, level};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.inria.tyrex.senslogs.model.log;

import android.content.Context;

import androidx.annotation.NonNull;

import org.ini4j.Wini;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -23,9 +33,23 @@ public class LogsDataSource {
private final static String PREF_FILE = "Logs";
private final static String KEY_LOGS_LIST = "logs-list";

private SharedPreferences mPreferences;
private final SharedPreferences mPreferences;
private final Gson mGson;

private static class FileSerializer implements JsonDeserializer<File>,
JsonSerializer<File> {

@Override
public File deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new File(json.getAsString());
}

@Override
public JsonElement serialize(File src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getAbsolutePath());
}
}


public LogsDataSource(Context context,
SensorsManager sensorsManager) {
Expand All @@ -34,6 +58,7 @@ public LogsDataSource(Context context,
mGson = new GsonBuilder().
registerTypeAdapter(Sensor.class,
new Sensor.Serializer(sensorsManager.getAvailableSensors())).
registerTypeAdapter(File.class, new FileSerializer()).
create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public List<Preference> getPreferences() {

for (String preferenceString : preferencesStrings) {
Preference res = mGson.fromJson(preferenceString, Preference.class);
if(res != null) preferences.add(res);
if (res != null) preferences.add(res);
}

for (Sensor sensor : mSensorsManager.getAvailableSensors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void onSensorChanged(final SensorEvent event) {
firstTimestampReached = true;
}

if(timestampFormat == null) {
if (timestampFormat == null) {
return;
}

Expand Down
Loading