Skip to content

Commit

Permalink
Merge branch 'remove_colons' of https://github.com/fat-tire/haven int…
Browse files Browse the repository at this point in the history
…o fat-tire-remove_colons
  • Loading branch information
n8fr8 committed Oct 3, 2018
2 parents fc4dc2c + 3d7f134 commit 87f3062
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/havenapp/main/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Class containing util functions which will be used multiple times throughout the app.
*/

class Utils {
public class Utils {

private static final String DATE_TIME_PATTERN = "yyyy-MM-dd_HH:mm:ss";
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd_HH-mm-ss.SSS";

static String getTimerText(long milliseconds) {
String timerText;
Expand Down Expand Up @@ -41,7 +41,7 @@ static String getTimerText(long milliseconds) {
* The default {@link Locale} is used.
*
* @param date concerned {@link Date} instance
* @return a string of the format "yyyy-MM-dd_HH:mm:ss" for the corresponding date
* @return a string of the format "yyyy-MM-dd_HH-mm-ss.SSS" for the corresponding date
*/
public static String getDateTime(Date date) {
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import android.os.Environment;
import android.util.Log;

import java.io.File;

import org.havenapp.main.PreferenceManager;
import org.havenapp.main.Utils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class AudioRecorderTask extends Thread {

Expand Down Expand Up @@ -69,7 +73,8 @@ protected AudioRecorderTask(Context context) {

File fileFolder = new File(Environment.getExternalStorageDirectory().getPath(),prefs.getDefaultMediaStoragePath());
fileFolder.mkdirs();
audioPath = new File(fileFolder,new java.util.Date().getTime() + ".m4a");
audioPath = new File(fileFolder,new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
Locale.getDefault()).format(new Date()) + ".m4a");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@
import com.google.android.cameraview.CameraView;

import org.havenapp.main.PreferenceManager;
import org.havenapp.main.Utils;
import org.havenapp.main.model.EventTrigger;
import org.havenapp.main.service.MonitorService;
import org.jcodec.api.android.AndroidSequenceEncoder;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -145,9 +148,10 @@ public CameraViewHolder(Activity context, CameraView cameraView) {
File fileImageDir = new File(Environment.getExternalStorageDirectory(), prefs.getDefaultMediaStoragePath());
fileImageDir.mkdirs();

String ts = new Date().getTime() + ".jpg";
String ts = new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
Locale.getDefault()).format(new Date());

File fileImage = new File(fileImageDir, "detected.original." + ts);
File fileImage = new File(fileImageDir, ts.concat(".detected.original.jpg"));
FileOutputStream stream = new FileOutputStream(fileImage);
rawBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

Expand Down Expand Up @@ -329,7 +333,8 @@ private synchronized boolean recordVideo() {

if (doingVideoProcessing)
return false;
String ts1 = String.valueOf(new Date().getTime());
String ts1 = new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
Locale.getDefault()).format(new Date());
File fileStoragePath = new File(Environment.getExternalStorageDirectory(),prefs.getDefaultMediaStoragePath());
fileStoragePath.mkdirs();

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/havenapp/main/service/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.Log;

import org.havenapp.main.R;
import org.havenapp.main.Utils;
import org.havenapp.main.model.Event;
import org.havenapp.main.model.EventTrigger;

Expand All @@ -14,8 +15,10 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -169,7 +172,8 @@ private void showEvent (Event event, StringBuffer page) {
for (EventTrigger eventTrigger: triggers)
{
String title = eventTrigger.getStringType(mContext);
String desc = eventTrigger.getTriggerTime().toString();
String desc = new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
Locale.getDefault()).format(eventTrigger.getTriggerTime());

page.append("<b>");
page.append(title).append("</b><br/>");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/havenapp/main/ui/EventActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import com.google.android.material.snackbar.Snackbar;

import org.havenapp.main.R;
import org.havenapp.main.Utils;
import org.havenapp.main.model.Event;
import org.havenapp.main.model.EventTrigger;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Expand Down Expand Up @@ -179,7 +182,9 @@ private String generateLog () {

for (EventTrigger eventTrigger : mEvent.getEventTriggers()) {

mEventLog.append("Event Triggered @ ").append(eventTrigger.getTriggerTime().toString()).append("\n");
mEventLog.append("Event Triggered @ ").append(
new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
Locale.getDefault()).format(eventTrigger.getTriggerTime())).append("\n");

String sType = eventTrigger.getStringType(this);

Expand Down
4 changes: 4 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@
<string name="config_storage_path">Storage Folder Path</string>
<string name="config_storage_page_hint">Where captured media is stored</string>

<!-- accepted digits for directory name - may vary for locale/platform/etc.
Skipping periods, spaces, and other special characters to keep it simple -->
<string name="path_chars">0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_/</string>

</resources>
3 changes: 2 additions & 1 deletion src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:summary="@string/config_storage_page_hint"
android:title="@string/config_storage_path"
android:defaultValue="/haven"
android:digits="@string/path_chars"
/>

<Preference
Expand Down Expand Up @@ -139,4 +140,4 @@
android:title="@string/password" />
</PreferenceCategory>

</PreferenceScreen>
</PreferenceScreen>

0 comments on commit 87f3062

Please sign in to comment.