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 11, 2025
2 parents 6fbba75 + de5e3b1 commit 868d719
Show file tree
Hide file tree
Showing 30 changed files with 1,661 additions and 475 deletions.
44 changes: 38 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,21 @@
<!-- <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>-->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>


<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />


<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature android:name="android.hardware.camera.flash" android:required="false" />



<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -59,9 +58,14 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FadCam"
android:theme="@style/Base.Theme.FadCam"
android:requestLegacyExternalStorage="true"
tools:targetApi="q">

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand All @@ -86,6 +90,24 @@
android:name=".ui.VideoPlayerActivity"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity android:name=".ui.WebViewActivity" />
<activity
android:name=".TorchToggleActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:excludeFromRecents="true"
android:noHistory="true"
android:exported="true"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateAlwaysHidden"
android:screenOrientation="portrait"
android:documentLaunchMode="never"
android:clearTaskOnLaunch="true"
android:taskAffinity=""
android:allowTaskReparenting="false">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<service
android:name=".services.RecordingService"
Expand All @@ -95,8 +117,9 @@

<service
android:name=".services.TorchService"
android:enabled="true"
android:exported="false" />
android:foregroundServiceType="camera"
android:exported="true">
</service>

<receiver
android:name=".receivers.TorchReceiver"
Expand All @@ -106,6 +129,15 @@
</intent-filter>
</receiver>

<receiver
android:name=".receivers.TorchToggleReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.fadcam.TOGGLE_TORCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>

</application>

</manifest>
9 changes: 7 additions & 2 deletions app/src/main/java/com/fadcam/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ public abstract class Constants {
public static final String PREF_VIDEO_FRAME_RATE = "video_frame_rate";
public static final String PREF_CAMERA_SELECTION = "camera_selection";
public static final String PREF_IS_PREVIEW_ENABLED = "isPreviewEnabled";
public static final String PREF_BOTH_TORCHES_ENABLED = "both_torches_enabled";
public static final String PREF_SELECTED_TORCH_SOURCE = "selected_torch_source";
public static final String PREF_BOTH_TORCHES_ENABLED = "pref_both_torches_enabled";
public static final String PREF_SELECTED_TORCH_SOURCE = "pref_selected_torch_source";
public static final String PREF_TORCH_STATE = "pref_torch_state";
public static final String PREF_LOCATION_DATA = "location_data";
public static final String PREF_DEBUG_DATA = "debug_data";
public static final String PREF_WATERMARK_OPTION = "watermark_option";
public static final String PREF_VIDEO_CODEC = "video_codec";
public static final String PREF_APP_THEME = "app_theme";

public static final String BROADCAST_ON_RECORDING_STARTED = "ON_RECORDING_STARTED";
public static final String BROADCAST_ON_RECORDING_RESUMED = "ON_RECORDING_RESUMED";
Expand All @@ -26,6 +29,7 @@ public abstract class Constants {
public static final String BROADCAST_ON_RECORDING_STATE_CALLBACK = "ON_RECORDING_STATE_CALLBACK";
public static final String BROADCAST_ON_TORCH_STATE_CHANGED = "ON_TORCH_STATE_CHANGED";
public static final String BROADCAST_ON_TORCH_STATE_REQUEST = "ON_TORCH_STATE_REQUEST";
public static final String BROADCAST_CAMERA_ERROR = "CAMERA_ACCESS_ERROR";

public static final String INTENT_ACTION_STOP_RECORDING = "ACTION_STOP_RECORDING";
public static final String INTENT_ACTION_CHANGE_SURFACE = "ACTION_CHANGE_SURFACE";
Expand All @@ -37,6 +41,7 @@ public abstract class Constants {
public static final String INTENT_EXTRA_RECORDING_STATE = "RECORDING_STATE";
public static final String INTENT_EXTRA_RECORDING_START_TIME = "RECORDING_START_TIME";
public static final String INTENT_EXTRA_TORCH_STATE = "TORCH_STATE";
public static final String INTENT_EXTRA_TORCH_STATE_CHANGED = "TORCH_STATE_CHANGED";

public static final String RECORDING_DIRECTORY = "FadCam";
public static final String RECORDING_FILE_EXTENSION = "mp4";
Expand Down
34 changes: 30 additions & 4 deletions app/src/main/java/com/fadcam/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,26 @@ public class Log {

private static Uri fileUri;

private static boolean isDebugEnabled = false;

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

// Check SharedPreferences for debug setting
SharedPreferencesManager sharedPreferencesManager = SharedPreferencesManager.getInstance(context);
isDebugEnabled = sharedPreferencesManager.isDebugLoggingEnabled();

if (isDebugEnabled) {
createHtmlFile(context, "debug.html");
}
}

createHtmlFile(context, "debug.html");
public static void setDebugEnabled(boolean enabled) {
isDebugEnabled = enabled;
if (enabled) {
createHtmlFile(context, "debug.html");
}
}

private static String getCurrentTimeStamp() {
Expand All @@ -42,16 +57,22 @@ private static String getCurrentTimeStamp() {
}

public static void d(String tag, String message) {
if (!isDebugEnabled) return;

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

public static void w(String tag, String message) {
if (!isDebugEnabled) return;

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

public static void e(String tag, Object... objects) {
if (!isDebugEnabled) return;

StringBuilder message = new StringBuilder();
for(Object object: objects)
{
Expand All @@ -75,21 +96,24 @@ else if(object instanceof Exception)

public static Uri createHtmlFile(Context context, String fileName) {
try {
Uri existingFileUri = checkIfFileExists(context, fileName);
// Use a static filename for debug log
String debugFileName = "FADCAM_debug.html";

Uri existingFileUri = checkIfFileExists(context, debugFileName);

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

ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, debugFileName);
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);
fileUri = Uri.parse("file://" + context.getExternalFilesDir(null).getPath() + "/Download/" + debugFileName);
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -99,6 +123,8 @@ public static Uri createHtmlFile(Context context, String fileName) {
}

public static void appendHtmlToFile(String htmlContent) {
if (!isDebugEnabled) return;

OutputStream outputStream = null;

try {
Expand Down
49 changes: 47 additions & 2 deletions app/src/main/java/com/fadcam/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.fadcam;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.viewpager2.widget.ViewPager2;
Expand All @@ -14,6 +20,7 @@
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.io.File;
import java.util.Collections;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {
Expand All @@ -25,14 +32,29 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Apply saved theme on startup
SharedPreferencesManager sharedPreferencesManager = SharedPreferencesManager.getInstance(this);
String savedTheme = sharedPreferencesManager.sharedPreferences.getString(Constants.PREF_APP_THEME, "Dark Mode");

Log.d("MainActivity", "Saved theme: " + savedTheme);

// Always force dark mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

// Only set AMOLED theme if explicitly selected
if ("AMOLED Black".equals(savedTheme)) {
Log.d("MainActivity", "Setting AMOLED theme");
getTheme().applyStyle(R.style.Theme_FadCam_Amoled, true);
} else {
Log.d("MainActivity", "Using default dark theme");
}

// Load and apply the saved language preference before anything else
SharedPreferences prefs = getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE);
String savedLanguageCode = prefs.getString(Constants.LANGUAGE_KEY, Locale.getDefault().getLanguage());

applyLanguage(savedLanguageCode); // Apply the language preference

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); //force dark theme even on light themed devices

// Check if current locale is Pashto
if (getResources().getConfiguration().locale.getLanguage().equals("ps")) {
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
Expand Down Expand Up @@ -88,6 +110,29 @@ public void onPageSelected(int position) {
File osmdroidTileCache = new File(osmdroidBasePath, "tiles");
org.osmdroid.config.Configuration.getInstance().setOsmdroidBasePath(osmdroidBasePath);
org.osmdroid.config.Configuration.getInstance().setOsmdroidTileCache(osmdroidTileCache);

// Add dynamic shortcut for torch
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
createDynamicShortcuts();
}
}

@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void createDynamicShortcuts() {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

// Torch Toggle Shortcut
Intent torchIntent = new Intent(this, TorchToggleActivity.class);
torchIntent.setAction(Intent.ACTION_VIEW);

ShortcutInfo torchShortcut = new ShortcutInfo.Builder(this, "torch_toggle")
.setShortLabel(getString(R.string.torch_shortcut_short_label))
.setLongLabel(getString(R.string.torch_shortcut_long_label))
.setIcon(Icon.createWithResource(this, R.drawable.ic_flashlight_on))
.setIntent(torchIntent)
.build();

shortcutManager.setDynamicShortcuts(Collections.singletonList(torchShortcut));
}

public void applyLanguage(String languageCode) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/fadcam/SharedPreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public boolean isLocalisationEnabled() {
return sharedPreferences.getBoolean(Constants.PREF_LOCATION_DATA, false);
}

public boolean isDebugLoggingEnabled() {
return sharedPreferences.getBoolean(Constants.PREF_DEBUG_DATA, false);
}

public String getWatermarkOption() {
return sharedPreferences.getString(Constants.PREF_WATERMARK_OPTION, Constants.DEFAULT_WATERMARK_OPTION);
}
Expand Down
76 changes: 76 additions & 0 deletions app/src/main/java/com/fadcam/TorchToggleActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.fadcam;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import com.fadcam.services.TorchService;

public class TorchToggleActivity extends Activity {
private static final String TAG = "TorchToggleActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Prevent the activity from being visible or interactive
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

// Prevent app from coming to foreground
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Log.d(TAG, "TorchToggleActivity onCreate called");
Log.d(TAG, "Intent: " + getIntent());

try {
// Create an intent for TorchService
Intent torchIntent = new Intent(this, TorchService.class);
torchIntent.setAction(Constants.INTENT_ACTION_TOGGLE_TORCH);

// Log service start attempt
Log.d(TAG, "Attempting to start TorchService");

// Start service based on Android version
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.d(TAG, "Starting foreground service");
startForegroundService(torchIntent);
} else {
Log.d(TAG, "Starting service");
startService(torchIntent);
}

// Log success
Log.d(TAG, "TorchService started successfully");
} catch (Exception e) {
// Log any errors
Log.e(TAG, "Error starting TorchService", e);
}

// Always finish the activity immediately
finish();

// Prevent any animation
overridePendingTransition(0, 0);
}

@Override
protected void onStop() {
super.onStop();
// Ensure the activity is completely hidden
finish();
}

@Override
protected void onPause() {
super.onPause();
// Prevent app from coming to foreground
moveTaskToBack(true);
}
}
Loading

0 comments on commit 868d719

Please sign in to comment.