Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvariyath committed Jan 7, 2025
2 parents 21e4142 + e92a350 commit 6fbba75
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 3 deletions.
166 changes: 166 additions & 0 deletions app/src/main/java/com/fadcam/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.fadcam;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Log {
private static File logFile;

private static final String TAG = "Log";

private static Context context;

private static Uri fileUri;

public static void init(Context context)
{
Log.context = context;

createHtmlFile(context, "debug.html");
}

private static String getCurrentTimeStamp() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
return simpleDateFormat.format(new Date());
}

public static void d(String tag, String message) {
String logMessage = "<font color=\"34495e\">" + getCurrentTimeStamp() + " INFO: [" + tag + "]" + message + "</font>";
appendHtmlToFile(logMessage);
}

public static void w(String tag, String message) {
String logMessage = "<font color=\"f1c40f\">" + getCurrentTimeStamp() + " WARNING: [" + tag + "]" + message + "</font>";
appendHtmlToFile(logMessage);
}

public static void e(String tag, Object... objects) {
StringBuilder message = new StringBuilder();
for(Object object: objects)
{
if(object instanceof String)
{
message.append(object);
}
else if(object instanceof Exception)
{
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
((Exception) object).printStackTrace(printWriter);
String stackTrace = stringWriter.toString();
message.append(stackTrace);
}
}

String logMessage = "<font color=\"e74c3c\">" + getCurrentTimeStamp() + " ERROR: [" + tag + "]" + message + "</font>";
appendHtmlToFile(logMessage);
}

public static Uri createHtmlFile(Context context, String fileName) {
try {
Uri existingFileUri = checkIfFileExists(context, fileName);

if (existingFileUri != null) {
return existingFileUri;
}

ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "text/html");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/FadCam");

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
fileUri = context.getContentResolver().insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues);
} else {
fileUri = Uri.parse("file://" + context.getExternalFilesDir(null).getPath() + "/Download/" + fileName);
}
} catch (Exception e) {
e.printStackTrace();
}

return null;
}

public static void appendHtmlToFile(String htmlContent) {
OutputStream outputStream = null;

try {
outputStream = context.getContentResolver().openOutputStream(fileUri, "wa");
if (outputStream != null) {
outputStream.write(htmlContent.getBytes());
outputStream.write(("</br>").getBytes());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

private static Uri checkIfFileExists(Context context, String fileName) {
Uri uri = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
uri = MediaStore.Downloads.EXTERNAL_CONTENT_URI;
} else {
String downloadsPath = context.getExternalFilesDir(null).getPath() + "/Download";
File downloadsDir = new File(downloadsPath);

if (!downloadsDir.exists()) {
boolean dirCreated = downloadsDir.mkdirs();
if (!dirCreated) {
return null;
}
}

File file = new File(downloadsDir, fileName);
uri = Uri.fromFile(file);
}

String[] projection = {MediaStore.MediaColumns._ID};
String selection = MediaStore.MediaColumns.DISPLAY_NAME + "=?";
String[] selectionArgs = new String[]{fileName};

Cursor cursor = null;
try {
ContentResolver resolver = context.getContentResolver();
cursor = resolver.query(uri, projection, selection, selectionArgs, null);

if (cursor != null && cursor.moveToFirst()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID));
return ContentUris.withAppendedId(uri, id);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}

return null;
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/fadcam/services/RecordingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.os.IBinder;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.Range;
import android.view.Surface;
import android.widget.Toast;
Expand All @@ -38,6 +37,7 @@
import com.arthenica.ffmpegkit.ReturnCode;
import com.fadcam.CameraType;
import com.fadcam.Constants;
import com.fadcam.Log;
import com.fadcam.MainActivity;
import com.fadcam.R;
import com.fadcam.RecordingState;
Expand Down Expand Up @@ -105,6 +105,8 @@ public boolean isPaused() {
public void onCreate() {
super.onCreate();

Log.init(getApplicationContext());

locationHelper = new LocationHelper(getApplicationContext());

createNotificationChannel();
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/fadcam/ui/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import android.text.Html;
import android.text.Spanned;
import android.text.format.Formatter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
Expand All @@ -59,6 +58,7 @@

import com.fadcam.CameraType;
import com.fadcam.Constants;
import com.fadcam.Log;
import com.fadcam.R;
import com.fadcam.services.RecordingService;
import com.fadcam.RecordingState;
Expand Down Expand Up @@ -356,6 +356,8 @@ private void resetTimers() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Log.init(requireContext());

Log.d(TAG, "HomeFragment created.");

// Request essential permissions on every launch
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/fadcam/ui/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.os.Bundle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Log;
import android.util.Size;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -32,6 +31,7 @@

import com.fadcam.CameraType;
import com.fadcam.Constants;
import com.fadcam.Log;
import com.fadcam.MainActivity;
import com.fadcam.R;
import com.fadcam.SharedPreferencesManager;
Expand Down Expand Up @@ -101,6 +101,7 @@ private void updateButtonAppearance(MaterialButton button, boolean isSelected) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.init(requireContext());
locationHelper = new LocationHelper(requireContext());
sharedPreferencesManager = SharedPreferencesManager.getInstance(requireContext());
initializeCamcorderProfiles();
Expand Down Expand Up @@ -861,6 +862,8 @@ private List<CamcorderProfile> getCamcorderProfiles(CameraType cameraType) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, quality);
if(profile != null) {
profiles.add(profile);

Log.d("SettingsFragment", cameraType + ": " + profile.videoFrameWidth + "x" + profile.videoFrameHeight + " (FPS: " + profile.videoFrameRate + ")");
}
}
}
Expand Down

0 comments on commit 6fbba75

Please sign in to comment.