diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b22036c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,53 @@
+### BEGIN_SECTION(julioromano)
+## julioromano specific additions.
+
+# Mac OS X specifics
+*~
+.DS_Store
+
+# Idea project files
+.idea
+*.iml
+
+keystore.properties
+*.jks
+
+### END_SECTION(julioromano)
+
+### BEGIN_SECTION(github)
+## https://github.com/github/gitignore/blob/master/Android.gitignore
+
+# Built application files
+*.apk
+*.ap_
+
+# Files for the Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+### END_SECTION(github)
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..c283539
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,72 @@
+apply plugin: 'com.android.application'
+//apply plugin: 'io.fabric'
+
+def keystorePropertiesFile = rootProject.file("app/keystore.properties")
+def keystoreProperties = new Properties()
+keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
+
+android {
+
+ compileSdkVersion 25
+ buildToolsVersion "25.0.2"
+
+ defaultConfig {
+ applicationId "net.kjulio.torch"
+ versionCode 106
+ versionName "1.0.6"
+ targetSdkVersion 25
+ minSdkVersion 10
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ }
+
+ applicationVariants.all { variant ->
+ variant.resValue "string", "versionName", variant.versionName
+ }
+
+ signingConfigs {
+ release {
+ keyAlias keystoreProperties['keyAlias']
+ keyPassword keystoreProperties['keyPassword']
+ storeFile file(keystoreProperties['storeFile'])
+ storePassword keystoreProperties['storePassword']
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled true
+ shrinkResources true
+ signingConfig signingConfigs.release
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ // Always show the result of every unit test, even if it passes.
+ testOptions.unitTests.all {
+ testLogging {
+ events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
+ }
+ }
+
+ dataBinding {
+ enabled true
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+}
+
+dependencies {
+ String daggerVersion = '2.9'
+
+ compile 'com.android.support:design:25.2.0'
+ compile 'com.jakewharton.timber:timber:4.5.1'
+ compile "com.google.dagger:dagger:$daggerVersion"
+ provided "com.google.dagger:dagger-compiler:$daggerVersion"
+ provided 'javax.annotation:javax.annotation-api:1.3'
+
+ testCompile 'junit:junit:4.12'
+ testCompile 'org.hamcrest:hamcrest-core:1.3'
+ testCompile 'org.mockito:mockito-core:2.7.13'
+}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..bcbc602
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,28 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Users/julionb/Library/Android/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
+
+-dontobfuscate
+-dontwarn dagger.producers.monitoring.internal.**
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..3bfc840
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/net/kjulio/torch/app/AndroidModule.java b/app/src/main/java/net/kjulio/torch/app/AndroidModule.java
new file mode 100644
index 0000000..8ee5ed5
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/app/AndroidModule.java
@@ -0,0 +1,34 @@
+package net.kjulio.torch.app;
+
+import android.app.Application;
+import android.content.Context;
+
+import javax.inject.Singleton;
+
+import dagger.Module;
+import dagger.Provides;
+
+@Module
+public class AndroidModule {
+
+ private final Application application;
+ private final Context context;
+
+ public AndroidModule(Application application) {
+ this.application = application;
+ this.context = application.getApplicationContext();
+ }
+
+ @Provides
+ @Singleton
+ Context provideContext() {
+ return context;
+ }
+
+ @Provides
+ @Singleton
+ Application provideApplication() {
+ return application;
+ }
+
+}
diff --git a/app/src/main/java/net/kjulio/torch/app/App.java b/app/src/main/java/net/kjulio/torch/app/App.java
new file mode 100644
index 0000000..01266b5
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/app/App.java
@@ -0,0 +1,79 @@
+package net.kjulio.torch.app;
+
+import android.app.Application;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.support.v4.app.NotificationCompat;
+
+import net.kjulio.torch.R;
+import net.kjulio.torch.timber.TimberInitializer;
+import net.kjulio.torch.ui.main.MainActivity;
+
+import javax.inject.Inject;
+
+public class App extends Application {
+
+ @Inject
+ TimberInitializer timberInitializer;
+
+ private AppComponent appComponent;
+
+ // Global app visibility flag: true if app is really going to background instead of just switching activities
+ private boolean notify = true;
+
+ // Notification stuff
+ private NotificationManager notificationManager;
+ private NotificationCompat.Builder notificationBuilder;
+
+ public void onCreate() {
+ super.onCreate();
+ appComponent = DaggerAppComponent.builder()
+ .androidModule(new AndroidModule(this))
+ .build();
+ appComponent.inject(this);
+
+ // Init Intents for notification
+ Intent NotificationIntent = new Intent(this, MainActivity.class);
+ PendingIntent NotificationPendingIntent = PendingIntent.getActivity(this, 0, NotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Init resources local var for notification text
+ Resources res = getResources();
+
+ // Init notification
+ notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationBuilder = new NotificationCompat.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(res.getString(R.string.notif_title))
+ .setContentText(res.getString(R.string.notif_text))
+ .setContentIntent(NotificationPendingIntent)
+ .setAutoCancel(true) // Hide the notification after its selected
+ .setOngoing(true); // Set notification as ongoing so it can't be cleared
+ }
+
+ public AppComponent getAppComponent() {
+ return appComponent;
+ }
+
+ public boolean isNotify() {
+ return notify;
+ }
+
+ public void setNotify(boolean Notify) {
+ notify = Notify;
+ }
+
+ // Raise notification if Notify flag is enabled
+ public void sendNotif() {
+ if (notify) {
+ notificationManager.notify(0, notificationBuilder.build());
+ }
+ }
+
+ // Cancels existing notification, if any
+ public void clearNotif() {
+ notificationManager.cancel(0);
+ }
+}
diff --git a/app/src/main/java/net/kjulio/torch/app/AppComponent.java b/app/src/main/java/net/kjulio/torch/app/AppComponent.java
new file mode 100644
index 0000000..4ea92d8
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/app/AppComponent.java
@@ -0,0 +1,14 @@
+package net.kjulio.torch.app;
+
+
+import javax.inject.Singleton;
+
+import dagger.Component;
+
+@Singleton
+@Component(modules = {AndroidModule.class})
+public interface AppComponent {
+
+ void inject(App app);
+
+}
diff --git a/app/src/main/java/net/kjulio/torch/timber/TimberInitializer.java b/app/src/main/java/net/kjulio/torch/timber/TimberInitializer.java
new file mode 100644
index 0000000..c9a3341
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/timber/TimberInitializer.java
@@ -0,0 +1,19 @@
+package net.kjulio.torch.timber;
+
+import net.kjulio.torch.BuildConfig;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import timber.log.Timber;
+
+@Singleton
+public class TimberInitializer {
+
+ @Inject
+ TimberInitializer() {
+ if (BuildConfig.DEBUG) {
+ Timber.plant(new Timber.DebugTree());
+ }
+ }
+}
diff --git a/app/src/main/java/net/kjulio/torch/torch/TorchFragment.java b/app/src/main/java/net/kjulio/torch/torch/TorchFragment.java
new file mode 100644
index 0000000..3216308
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/torch/TorchFragment.java
@@ -0,0 +1,13 @@
+package net.kjulio.torch.torch;
+
+import android.support.v4.app.Fragment;
+
+public abstract class TorchFragment extends Fragment {
+
+ public static final String TORCH_FRAGMENT_TAG = "torchFragmentTag";
+
+ public abstract void on();
+
+ public abstract void off();
+
+}
diff --git a/app/src/main/java/net/kjulio/torch/torch/TorchFragmentFactory.java b/app/src/main/java/net/kjulio/torch/torch/TorchFragmentFactory.java
new file mode 100644
index 0000000..458414d
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/torch/TorchFragmentFactory.java
@@ -0,0 +1,37 @@
+package net.kjulio.torch.torch;
+
+import android.content.Context;
+
+import net.kjulio.torch.torch.camera1.Camera1TorchFragment;
+import net.kjulio.torch.torch.mock.MockTorchFragment;
+import net.kjulio.torch.utils.Utils;
+
+public class TorchFragmentFactory {
+
+ private final Context context;
+
+ public TorchFragmentFactory(Context context) {
+ this.context = context;
+ }
+
+ public TorchFragment create() {
+ return create(false);
+ }
+
+ public TorchFragment create(boolean mock) {
+ if (mock || !Utils.deviceHasCamera(context)) {
+ return new MockTorchFragment();
+ } else {
+ // TODO: Uncomment when support for different camera APIs is ready.
+ // if (Build.VERSION.SDK_INT < 21) {
+ // return new Camera1TorchFragment();
+ // } else if (Build.VERSION.SDK_INT < 23) {
+ // return new Camera2TorchFragment();
+ // } else {
+ // return new FlashlightTorchFragment();
+ // }
+ return new Camera1TorchFragment();
+ }
+ }
+
+}
diff --git a/app/src/main/java/net/kjulio/torch/torch/camera1/Camera1TorchFragment.java b/app/src/main/java/net/kjulio/torch/torch/camera1/Camera1TorchFragment.java
new file mode 100644
index 0000000..8e9760c
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/torch/camera1/Camera1TorchFragment.java
@@ -0,0 +1,123 @@
+package net.kjulio.torch.torch.camera1;
+
+import android.hardware.Camera;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.SurfaceHolder;
+import android.view.View;
+import android.view.ViewGroup;
+
+import net.kjulio.torch.databinding.FragmentTorchCamera1Binding;
+import net.kjulio.torch.torch.TorchFragment;
+
+import java.io.IOException;
+
+import timber.log.Timber;
+
+public class Camera1TorchFragment extends TorchFragment {
+
+ private final MySurfaceHolderCallback mySurfaceHolderCallback = new MySurfaceHolderCallback();
+ private final Camera.AutoFocusCallback autoFocusCallback = new Camera.AutoFocusCallback() {
+ @Override
+ public void onAutoFocus(boolean success, Camera camera) {}
+ };
+
+ private Camera camera;
+ private SurfaceHolder surfaceHolder;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ FragmentTorchCamera1Binding binding =
+ FragmentTorchCamera1Binding.inflate(inflater, container, false);
+
+ // Init Camera resources
+ surfaceHolder = binding.surfaceView.getHolder();
+ surfaceHolder.addCallback(mySurfaceHolderCallback);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
+ surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+ }
+
+ return binding.getRoot();
+ }
+
+ @Override
+ public void on() {
+ switchOn();
+ }
+
+ @Override
+ public void off() {
+ switchOff();
+ }
+
+ private void switchOn() {
+ try {
+ camera = Camera.open(); // attempt to get a Camera instance
+ } catch (Exception e) {
+ Timber.e(e, "Can't open camera, maybe it's in use or not available.");
+ }
+
+ // If we don't recall this here then camera won't work after
+ // resuming from sleep
+ mySurfaceHolderCallback.surfaceCreated(surfaceHolder);
+
+ Camera.Parameters parameters = camera.getParameters();
+ // Hacked torch switch on logic for devices which do not support FLASH_MODE_TOCH (e.g. Galaxy Ace)
+ if (!parameters.getSupportedFlashModes().contains(Camera.Parameters.FLASH_MODE_TORCH)) {
+ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
+ camera.setParameters(parameters);
+ camera.autoFocus(autoFocusCallback);
+ camera.startPreview();
+ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
+ camera.setParameters(parameters);
+ } else {
+ // Standard logic for device with support for FLASH_MODE_TORCH
+ // Some phones don't preserve parameters state after stopPreview(),
+ // we gotta set them each time here!
+ parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
+ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
+ camera.setParameters(parameters);
+ camera.startPreview();
+ }
+ }
+
+ private void switchOff() {
+ if (camera != null) {
+ Camera.Parameters parameters = camera.getParameters();
+ // Some phones don't turn off flash upon stopPreview(), we gotta do
+ // it manually here!
+ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
+ camera.setParameters(parameters);
+ camera.stopPreview();
+ // Release camera resource
+ camera.release();
+ camera = null;
+ }
+ }
+
+ class MySurfaceHolderCallback implements SurfaceHolder.Callback {
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ // HACK: since we want to open the camera handle only when actually turning on
+ // the light (to avoid occupying the camera handle when the light is off) we
+ // need to surround this try/catch block with an "if guard" to avoid calling
+ // setPreviewDisplay() with a still empty camera handle (which would crash)
+ if (camera != null) {
+ try {
+ camera.setPreviewDisplay(surfaceHolder);
+ } catch (IOException e) {
+ Timber.e(e, "Error setting camera preview.");
+ }
+ }
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {}
+ }
+}
diff --git a/app/src/main/java/net/kjulio/torch/torch/mock/MockTorchFragment.java b/app/src/main/java/net/kjulio/torch/torch/mock/MockTorchFragment.java
new file mode 100644
index 0000000..6f7559a
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/torch/mock/MockTorchFragment.java
@@ -0,0 +1,27 @@
+package net.kjulio.torch.torch.mock;
+
+import net.kjulio.torch.R;
+import net.kjulio.torch.torch.TorchFragment;
+import net.kjulio.torch.utils.Utils;
+
+import timber.log.Timber;
+
+public class MockTorchFragment extends TorchFragment {
+
+ @Override
+ public void on() {
+ showWarningMessage();
+ Timber.d("Torch on");
+ }
+
+ @Override
+ public void off() {
+ showWarningMessage();
+ Timber.d("Torch off");
+ }
+
+ private void showWarningMessage() {
+ Utils.snackbar(getActivity().findViewById(R.id.coordinator), getString(R.string.warning_no_flash));
+ }
+
+}
diff --git a/app/src/main/java/net/kjulio/torch/ui/main/MainActivity.java b/app/src/main/java/net/kjulio/torch/ui/main/MainActivity.java
new file mode 100644
index 0000000..4e42778
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/ui/main/MainActivity.java
@@ -0,0 +1,189 @@
+package net.kjulio.torch.ui.main;
+
+import android.Manifest;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.databinding.DataBindingUtil;
+import android.databinding.ObservableBoolean;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AppCompatActivity;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.WindowManager;
+
+import net.kjulio.torch.R;
+import net.kjulio.torch.app.App;
+import net.kjulio.torch.databinding.ActivityMainBinding;
+import net.kjulio.torch.torch.TorchFragment;
+import net.kjulio.torch.torch.TorchFragmentFactory;
+import net.kjulio.torch.ui.settings.SettingsActivity;
+
+import timber.log.Timber;
+
+public class MainActivity extends AppCompatActivity {
+
+ public final ObservableBoolean torchButton = new ObservableBoolean();
+
+ private static final int PERMISSIONS_REQUEST_CAMERA = 243;
+
+ private TorchFragment torchFragment;
+ private SharedPreferences sharedPreferences;
+ private boolean lastInvocation;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
+ binding.setActivity(this);
+ sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ FragmentManager fm = getSupportFragmentManager();
+ if (savedInstanceState == null) {
+ torchFragment = new TorchFragmentFactory(this).create();
+ fm.beginTransaction()
+ .replace(R.id.frameLayout, torchFragment, TorchFragment.TORCH_FRAGMENT_TAG)
+ .commit();
+ } else {
+ torchFragment = (TorchFragment) fm.findFragmentByTag(TorchFragment.TORCH_FRAGMENT_TAG);
+ }
+
+ // Sets button state according to preferences (or true if no preference found)
+ String s = sharedPreferences.getString("pref_startup_state", "last");
+ switch (s) {
+ case "last":
+ torchButton.set(sharedPreferences.getBoolean("mTorchButton", true));
+ break;
+ case "off":
+ torchButton.set(false);
+ break;
+ case "on":
+ torchButton.set(true);
+ break;
+ }
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+
+ // Enable notification
+ ((App) getApplication()).setNotify(true);
+
+ // Cancels existing notification, if any
+ ((App) getApplication()).clearNotif();
+
+ // Set correct display stays on state
+ if (sharedPreferences.getBoolean("pref_nosleep", true)) {
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ } else {
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+
+ if (torchButton.get()) {
+ torch(true);
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ // Save preferences
+ sharedPreferences.edit()
+ .putBoolean("mTorchButton", torchButton.get())
+ .apply();
+
+ // Raise notification if pref_background is true and torch is actually on
+ if (sharedPreferences.getBoolean("pref_background", true) &&
+ sharedPreferences.getBoolean("mTorchButton", true)) {
+ ((App) getApplication()).sendNotif();
+ } else {
+ torch(false);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // Cancels existing notification, if any
+ ((App) getApplication()).clearNotif();
+ torch(false);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.activity_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.menu_settings:
+ // Disable notification as we're staying in the app
+ ((App) getApplication()).setNotify(false);
+ startActivity(new Intent(this, SettingsActivity.class));
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ public void onClickTorchButton() {
+ torch(torchButton.get());
+ }
+
+ private void torch(boolean enable) {
+ lastInvocation = enable;
+ if (hasCameraPermission()) {
+ if (enable) {
+ torchFragment.on();
+ } else {
+ torchFragment.off();
+ }
+ } else {
+ requestCameraPermission();
+ }
+ }
+
+ private void requestCameraPermission() {
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
+ PERMISSIONS_REQUEST_CAMERA);
+ }
+
+ private boolean hasCameraPermission() {
+ return (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
+ == PackageManager.PERMISSION_GRANTED);
+ }
+
+ private void onCameraPermissionGranted() {
+ torch(lastInvocation);
+ }
+
+ private void onCameraPermissionDenied() {
+ requestCameraPermission();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ switch (requestCode) {
+ case PERMISSIONS_REQUEST_CAMERA: {
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ Timber.d("Permission granted");
+ onCameraPermissionGranted();
+ } else {
+ Timber.e("Permission denied");
+ onCameraPermissionDenied();
+ }
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/net/kjulio/torch/ui/settings/SettingsActivity.java b/app/src/main/java/net/kjulio/torch/ui/settings/SettingsActivity.java
new file mode 100644
index 0000000..14c0614
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/ui/settings/SettingsActivity.java
@@ -0,0 +1,38 @@
+package net.kjulio.torch.ui.settings;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+
+import net.kjulio.torch.R;
+import net.kjulio.torch.app.App;
+
+public class SettingsActivity extends PreferenceActivity {
+
+ private SharedPreferences sharedPreferences;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.settings);
+ sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ // Enable notification
+ ((App) getApplication()).setNotify(true);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ // Raise notification if pref_background is true and torch is actually on
+ if (sharedPreferences.getBoolean("pref_background", true) &&
+ sharedPreferences.getBoolean("mTorchButton", true)) {
+ ((App) getApplication()).sendNotif();
+ }
+ }
+}
diff --git a/app/src/main/java/net/kjulio/torch/utils/Utils.java b/app/src/main/java/net/kjulio/torch/utils/Utils.java
new file mode 100644
index 0000000..661d381
--- /dev/null
+++ b/app/src/main/java/net/kjulio/torch/utils/Utils.java
@@ -0,0 +1,23 @@
+package net.kjulio.torch.utils;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.support.design.widget.Snackbar;
+import android.view.View;
+import android.widget.Toast;
+
+public class Utils {
+
+ public static boolean deviceHasCamera(Context context) {
+ return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
+ }
+
+ public static void toast(Context context, String text) {
+ Toast.makeText(context, text, Toast.LENGTH_LONG).show();
+ }
+
+ public static void snackbar(View v, String text) {
+ Snackbar.make(v, text, Snackbar.LENGTH_LONG).show();
+ }
+
+}
diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..703cd80
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-ldpi/ic_launcher.png b/app/src/main/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 0000000..0440e7a
Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..ec4fcdc
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..5638cbc
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable/togglebutton.png b/app/src/main/res/drawable/togglebutton.png
new file mode 100644
index 0000000..1339ecc
Binary files /dev/null and b/app/src/main/res/drawable/togglebutton.png differ
diff --git a/app/src/main/res/drawable/togglebutton_background.xml b/app/src/main/res/drawable/togglebutton_background.xml
new file mode 100644
index 0000000..8b2b2d8
--- /dev/null
+++ b/app/src/main/res/drawable/togglebutton_background.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/togglebutton_check.png b/app/src/main/res/drawable/togglebutton_check.png
new file mode 100644
index 0000000..449ceed
Binary files /dev/null and b/app/src/main/res/drawable/togglebutton_check.png differ
diff --git a/app/src/main/res/drawable/togglebutton_check_press.png b/app/src/main/res/drawable/togglebutton_check_press.png
new file mode 100644
index 0000000..ab22bf5
Binary files /dev/null and b/app/src/main/res/drawable/togglebutton_check_press.png differ
diff --git a/app/src/main/res/drawable/togglebutton_press.png b/app/src/main/res/drawable/togglebutton_press.png
new file mode 100644
index 0000000..b9a22bc
Binary files /dev/null and b/app/src/main/res/drawable/togglebutton_press.png differ
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..bb75453
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_torch_camera1.xml b/app/src/main/res/layout/fragment_torch_camera1.xml
new file mode 100644
index 0000000..4bdea9e
--- /dev/null
+++ b/app/src/main/res/layout/fragment_torch_camera1.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/activity_main.xml b/app/src/main/res/menu/activity_main.xml
new file mode 100644
index 0000000..9e518ca
--- /dev/null
+++ b/app/src/main/res/menu/activity_main.xml
@@ -0,0 +1,9 @@
+
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..0969862
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #000000
+ #FFFFFF
+ #666666
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..90a2c1d
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,35 @@
+
+
+ Torch
+ Settings
+ Torch
+ Settings
+ Version
+
+
+ - Last
+ - Off
+ - On
+
+
+ - last
+ - off
+ - on
+
+
+ Author\'s website
+ https://kjulio.net/
+ Startup state
+ State of the torch at application launch
+ last
+ Keep display on while using the torch
+ Run in background
+ Torch stays on when pressing the home button or when switching apps
+ Prevent display from sleeping
+ Torch by kJulio version
+ Torch
+ Tap to return to torch
+ About
+ Settings
+ Couldn\'t detect any camera flash, Torch won\'t work.
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..f2fce15
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml
new file mode 100644
index 0000000..35edace
--- /dev/null
+++ b/app/src/main/res/xml/settings.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..1279911
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,29 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+apply plugin: 'com.github.ben-manes.versions'
+
+buildscript {
+ repositories {
+ jcenter()
+ maven { url 'https://maven.fabric.io/public' }
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.github.ben-manes:gradle-versions-plugin:0.14.0'
+ classpath 'io.fabric.tools:gradle:1.22.1'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+ maven { url 'https://maven.fabric.io/public' }
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..aac7c9b
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,17 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..13372ae
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..8469c94
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Dec 28 10:00:20 PST 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..9d82f78
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..e7b4def
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':app'