├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ ├── GPL_v2_0.xml │ └── profiles_settings.xml ├── dictionaries │ └── anselm94.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── android_arch_core_common_1_0_0_jar.xml │ ├── android_arch_lifecycle_common_1_0_0_jar.xml │ ├── android_arch_lifecycle_runtime_1_0_0.xml │ ├── com_android_support_animated_vector_drawable_26_1_0.xml │ ├── com_android_support_appcompat_v7_26_1_0.xml │ ├── com_android_support_design_26_1_0.xml │ ├── com_android_support_recyclerview_v7_26_1_0.xml │ ├── com_android_support_support_annotations_26_1_0_jar.xml │ ├── com_android_support_support_compat_26_1_0.xml │ ├── com_android_support_support_core_ui_26_1_0.xml │ ├── com_android_support_support_core_utils_26_1_0.xml │ ├── com_android_support_support_fragment_26_1_0.xml │ ├── com_android_support_support_media_compat_26_1_0.xml │ ├── com_android_support_support_v4_26_1_0.xml │ ├── com_android_support_support_vector_drawable_26_1_0.xml │ ├── com_android_support_transition_26_1_0.xml │ ├── junit_junit_4_12_jar.xml │ └── org_hamcrest_hamcrest_core_1_3_jar.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE.txt ├── README.md ├── Torchie-Android.iml ├── app ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── aidl │ └── com │ │ └── android │ │ └── vending │ │ └── billing │ │ └── IInAppBillingService.aidl │ ├── java │ └── in │ │ └── blogspot │ │ └── anselmbros │ │ └── torchie │ │ ├── TorchieApp.java │ │ ├── main │ │ ├── ScreenState.java │ │ ├── TorchieManager.java │ │ ├── TorchieManagerListener.java │ │ └── manager │ │ │ ├── DeviceManager.java │ │ │ ├── DeviceManagerListener.java │ │ │ ├── TorchManager.java │ │ │ ├── VolumeKeyManager.java │ │ │ ├── WakeLockManager.java │ │ │ ├── device │ │ │ ├── Device.java │ │ │ ├── DeviceListener.java │ │ │ ├── input │ │ │ │ ├── InputDevice.java │ │ │ │ ├── InputDeviceListener.java │ │ │ │ ├── event │ │ │ │ │ └── VolumeKeyEvent.java │ │ │ │ ├── key │ │ │ │ │ └── volume │ │ │ │ │ │ ├── VolumeKeyDevice.java │ │ │ │ │ │ ├── nativve │ │ │ │ │ │ └── VolumeKeyNative.java │ │ │ │ │ │ └── rocker │ │ │ │ │ │ └── VolumeKeyRocker.java │ │ │ │ └── proximity │ │ │ │ │ └── ProximitySensor.java │ │ │ └── output │ │ │ │ ├── OutputDevice.java │ │ │ │ ├── OutputDeviceListener.java │ │ │ │ ├── torch │ │ │ │ ├── Torch.java │ │ │ │ ├── flashlight │ │ │ │ │ ├── Flashlight.java │ │ │ │ │ ├── Flashlight1.java │ │ │ │ │ └── Flashlight2.java │ │ │ │ └── screenlight │ │ │ │ │ └── Screenlight.java │ │ │ │ └── vibrator │ │ │ │ └── Vibrator.java │ │ │ ├── timer │ │ │ ├── CountTimer.java │ │ │ └── CountTimerListener.java │ │ │ └── wakelock │ │ │ └── WakeLock.java │ │ ├── receiver │ │ ├── BootReadyReceiver.java │ │ └── RockerReceiver.java │ │ ├── service │ │ └── TorchieQuick.java │ │ ├── ui │ │ ├── activity │ │ │ ├── MainActivity.java │ │ │ ├── ScreenflashActivity.java │ │ │ └── SettingsActivity.java │ │ ├── fragment │ │ │ ├── SettingsFragment.java │ │ │ └── dialog │ │ │ │ ├── AboutDialog.java │ │ │ │ ├── DonateDialog.java │ │ │ │ ├── DonateFailDialog.java │ │ │ │ ├── DonateSuccessDialog.java │ │ │ │ ├── PermissionDialog.java │ │ │ │ └── WelcomeDialog.java │ │ ├── helper │ │ │ └── DonateDialogListener.java │ │ └── widget │ │ │ └── settings │ │ │ ├── CheckBoxDialogPreference.java │ │ │ └── TimeoutListPreference.java │ │ └── utils │ │ ├── Constants.java │ │ ├── IabUtils │ │ ├── IabBroadcastReceiver.java │ │ ├── IabException.java │ │ ├── IabHelper.java │ │ ├── IabResult.java │ │ ├── Inventory.java │ │ ├── Purchase.java │ │ ├── Security.java │ │ └── SkuDetails.java │ │ ├── LogUtils.java │ │ ├── NotificationUtils.java │ │ └── SettingsUtils.java │ └── res │ ├── drawable-v21 │ └── but_ripple.xml │ ├── drawable │ ├── but_ripple.xml │ ├── ic_donate.png │ ├── ic_logo_mono.png │ ├── sw_flash.xml │ ├── sw_flash_off.xml │ ├── sw_flash_on.xml │ └── torchie_head_norm.png │ ├── layout │ ├── activity_main.xml │ ├── activity_screenflash.xml │ ├── activity_settings.xml │ ├── dialog_about.xml │ ├── dialog_donate.xml │ ├── dialog_donate_failure.xml │ ├── dialog_donate_success.xml │ ├── dialog_permission.xml │ ├── dialog_welcome.xml │ ├── fragment_settings.xml │ ├── layout_list_item.xml │ └── pref_widget_checkbox.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-af │ └── strings.xml │ ├── values-bg │ └── strings.xml │ ├── values-cs │ └── strings.xml │ ├── values-de │ └── strings.xml │ ├── values-es │ └── strings.xml │ ├── values-et │ └── strings.xml │ ├── values-fa │ └── strings.xml │ ├── values-fr │ └── strings.xml │ ├── values-hr │ └── strings.xml │ ├── values-hu │ └── strings.xml │ ├── values-in │ └── strings.xml │ ├── values-it │ └── strings.xml │ ├── values-ja │ └── strings.xml │ ├── values-ka │ └── strings.xml │ ├── values-ko │ └── strings.xml │ ├── values-lt │ └── strings.xml │ ├── values-mn │ └── strings.xml │ ├── values-pl │ └── strings.xml │ ├── values-pt │ └── strings.xml │ ├── values-ro │ └── strings.xml │ ├── values-ru │ └── strings.xml │ ├── values-sq │ └── strings.xml │ ├── values-sr │ └── strings.xml │ ├── values-sv │ └── strings.xml │ ├── values-ta │ └── strings.xml │ ├── values-tr │ └── strings.xml │ ├── values-w820dp │ └── dimens.xml │ ├── values-zh-rCN │ └── strings.xml │ ├── values-zh │ └── strings.xml │ ├── values │ ├── arrays.xml │ ├── colors.xml │ ├── dimens.xml │ ├── preferences_default.xml │ ├── strings.xml │ ├── styles.xml │ └── translators_list.xml │ └── xml │ ├── accessibility_service_config.xml │ └── preferences.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── keystore.properties ├── projectFilesBackup └── .idea │ └── workspace.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | .idea/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | #App unit-testing files 36 | test/ 37 | androidTest/ 38 | 39 | # Android Studio specific 40 | .idea/workspaces.xml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | 44 | #Torchie Specific 45 | keystore.properties -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/GPL_v2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/dictionaries/anselm94.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | merbin 5 | paypal 6 | torchie 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_core_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_runtime_1_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_animated_vector_drawable_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_appcompat_v7_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_design_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_recyclerview_v7_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_annotations_26_1_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_compat_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_ui_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_utils_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_fragment_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_media_compat_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_v4_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_vector_drawable_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_transition_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/junit_junit_4_12_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_core_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Torchie][Torchie-logo] Torchie - Volume Button Flash 2 | ============================================================= 3 | Turn on/off flashlight/LED/torch/Screenlight on Android smartphones running Android 4.0.3 or later just by using Volume Buttons together anytime! It works in screen on, lock screen and screen off (when enabled from settings). It feels like a handy conventional battery operated torch with physical hardware button access. It's tiny, small and runs silently as SERVICE. Absolutely *no root* required! 4 | 5 | 6 | Get it on Google Play 7 | 8 | Get it on F-Droid 9 | 10 | 11 | ### Official Website 12 | 13 | 14 | 15 | *** 16 | 17 | 18 | ## Wiki 19 | [Torchie Wiki](https://github.com/anselm94/Torchie-Android/wiki) 20 | 21 | 22 | *** 23 | 24 | 25 | ## Follow 26 | * [Like Torchie](https://facebook.com/torchieapp) on **Facebook** 27 | * [Follow Torchie](https://plus.google.com/111668132285982978436) via **Google+** 28 | 29 | 30 | ## Participate 31 | * [Join Torchie Beta Community](https://plus.google.com/communities/114100054385968340083) on Google+ 32 | 33 | 34 | ## Translate 35 | You are free to translate (if not before in a particular language) or make suggestions/corrections in translations. [Read more](https://github.com/anselm94/Torchie-Android/tree/dev/app/src/main/res) 36 | 37 | 38 | *** 39 | 40 | 41 | ## Developed by 42 | Merbin J Anselm & Rebin J Anselm - [Anselm & Anselm](http:anselmbros.blogspot.in) 43 | 44 | 45 | ## License 46 | [GNU General Public License v2](https://github.com/anselm94/Torchie-Android/blob/dev/LICENSE.txt) 47 | ``` 48 | Copyright (C) 2016 Merbin J Anselm 49 | 50 | This program is free software; you can redistribute it and/or modify 51 | it under the terms of the GNU General Public License as published by 52 | the Free Software Foundation; either version 2 of the License, or 53 | (at your option) any later version. 54 | 55 | This program is distributed in the hope that it will be useful, 56 | but WITHOUT ANY WARRANTY; without even the implied warranty of 57 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 58 | GNU General Public License for more details. 59 | 60 | You should have received a copy of the GNU General Public License along 61 | with this program; if not, write to the Free Software Foundation, Inc., 62 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 63 | ``` 64 | 65 | [Torchie-Logo]: https://lh3.googleusercontent.com/P7Ezb0agm_YOPB4U9tQ4gQ6Bp4qLly8qFgW-akLmss0gx9s_0NZ56wo5zdjK4o59Wow=w100 "Torchie" 66 | -------------------------------------------------------------------------------- /Torchie-Android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/anselm94/tools/android/android-sdk-linux/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class com.android.vending.billing.** 20 | #-keep public class * extends android.support.v7.preference.Preference 21 | 22 | -keepattributes *Annotation* 23 | -keepclassmembers class ** { 24 | @org.greenrobot.eventbus.Subscribe ; 25 | } 26 | -keep enum org.greenrobot.eventbus.ThreadMode { *; } 27 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/TorchieApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie; 20 | 21 | import android.app.Application; 22 | 23 | /** 24 | * Created by Merbin J Anselm on 02-Feb-17. 25 | */ 26 | 27 | public class TorchieApp extends Application { 28 | @Override 29 | public void onCreate() { 30 | super.onCreate(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/ScreenState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 19-Feb-17. 23 | */ 24 | 25 | public enum ScreenState { 26 | SCREEN_OFF, //SCREEN_OFF 27 | SCREEN_LOCK, //SCREEN_LOCK 28 | SCREEN_ON //SCREEN_UNLOCK 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/TorchieManagerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 14-Feb-17. 23 | */ 24 | 25 | public interface TorchieManagerListener { 26 | void onError(String error); 27 | 28 | void onTorchStatusChanged(boolean status); 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/DeviceManagerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 14-Feb-17. 23 | */ 24 | 25 | public interface DeviceManagerListener { 26 | void onTorchStatusChanged(boolean status); 27 | 28 | void onKeyActionPerformed(); 29 | 30 | void onProximityChanged(boolean status); 31 | 32 | void onError(String error); 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/VolumeKeyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2016 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | package in.blogspot.anselmbros.torchie.main.manager; 38 | 39 | import android.content.Context; 40 | import android.os.Build; 41 | 42 | import in.blogspot.anselmbros.torchie.main.manager.device.input.InputDeviceListener; 43 | import in.blogspot.anselmbros.torchie.main.manager.device.input.event.VolumeKeyEvent; 44 | import in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.VolumeKeyDevice; 45 | import in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.nativve.VolumeKeyNative; 46 | import in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.rocker.VolumeKeyRocker; 47 | 48 | /** 49 | * Created by Merbin J Anselm on 06-Feb-17. 50 | */ 51 | 52 | class VolumeKeyManager { 53 | 54 | private static VolumeKeyManager mInstance; 55 | 56 | private VolumeKeyDevice volumeKeyDevice; 57 | private Context mContext; 58 | 59 | private boolean isEnabled; 60 | private InputDeviceListener mListener; 61 | 62 | private VolumeKeyManager(Context context, String volumeKeyType, boolean enable) { 63 | this.isEnabled = enable; 64 | this.mContext = context; 65 | this.setType(volumeKeyType); 66 | } 67 | 68 | public static VolumeKeyManager getInstance(Context context, String volumeKeyType, boolean enable) { 69 | if (mInstance == null) { 70 | mInstance = new VolumeKeyManager(context, volumeKeyType, enable); 71 | } 72 | return mInstance; 73 | } 74 | 75 | public void setEnabled(boolean enable) { 76 | this.isEnabled = enable; 77 | if (this.volumeKeyDevice != null) { 78 | this.volumeKeyDevice.setEnabled(this.isEnabled); 79 | } 80 | } 81 | 82 | public void setType(String volumeKeyType) { 83 | volumeKeyType = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) ? volumeKeyType : VolumeKeyRocker.TYPE; 84 | if (this.volumeKeyDevice != null && VolumeKeyDevice.TYPE.equals(volumeKeyType)) { 85 | return; 86 | } 87 | this.volumeKeyDevice = null; 88 | if (volumeKeyType.equals(VolumeKeyNative.TYPE)) { 89 | this.volumeKeyDevice = new VolumeKeyNative(this.mContext); 90 | this.volumeKeyDevice.setListener(this.mListener); 91 | } else if (volumeKeyType.equals(VolumeKeyRocker.TYPE)) { 92 | this.volumeKeyDevice = new VolumeKeyRocker(this.mContext); 93 | this.volumeKeyDevice.setListener(this.mListener); 94 | } 95 | this.volumeKeyDevice.setEnabled(this.isEnabled); 96 | } 97 | 98 | public boolean setVolumeKeyEvent(VolumeKeyEvent keyEvent) { 99 | return this.volumeKeyDevice.setInputEvent(keyEvent); 100 | } 101 | 102 | public void setListener(InputDeviceListener listener) { 103 | this.mListener = listener; 104 | if (this.volumeKeyDevice != null) { 105 | this.volumeKeyDevice.setListener(this.mListener); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/WakeLockManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2017 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | /* 38 | * Copyright (C) 2016 Merbin J Anselm 39 | * 40 | * This program is free software; you can redistribute it and/or modify 41 | * it under the terms of the GNU General Public License as published by 42 | * the Free Software Foundation; either version 2 of the License, or 43 | * (at your option) any later version. 44 | * 45 | * This program is distributed in the hope that it will be useful, 46 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 47 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 48 | * GNU General Public License for more details. 49 | * 50 | * You should have received a copy of the GNU General Public License along 51 | * with this program; if not, write to the Free Software Foundation, Inc., 52 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 53 | */ 54 | 55 | package in.blogspot.anselmbros.torchie.main.manager; 56 | 57 | import android.content.Context; 58 | import android.util.Log; 59 | 60 | import androidx.media.VolumeProviderCompat; 61 | 62 | import in.blogspot.anselmbros.torchie.main.manager.wakelock.WakeLock; 63 | 64 | /** 65 | * Created by Merbin J Anselm on 05-Feb-17. 66 | */ 67 | 68 | public class WakeLockManager { 69 | 70 | private static WakeLockManager mInstance; 71 | private WakeLock wakeLock; 72 | private boolean isEnabled; 73 | private boolean isHeldOnDemand; 74 | 75 | private WakeLockManager() { 76 | this.isEnabled = true; 77 | this.isHeldOnDemand = false; 78 | } 79 | 80 | public static WakeLockManager getInstance() { 81 | if (mInstance == null) { 82 | mInstance = new WakeLockManager(); 83 | } 84 | return mInstance; 85 | } 86 | 87 | public void acquire(Context context, VolumeProviderCompat volumeProvider) { 88 | if (this.wakeLock == null) { 89 | this.wakeLock = new WakeLock(); 90 | } 91 | this.wakeLock.setEnabled(this.isEnabled); 92 | this.wakeLock.acquire(context, volumeProvider); 93 | Log.e("Torchie Wakelock", String.valueOf(this.wakeLock.isHeld())); 94 | } 95 | 96 | public void setHeldOnDemand() { 97 | this.isHeldOnDemand = true; 98 | } 99 | 100 | public boolean isHeldOnDemand() { 101 | return this.isHeldOnDemand; 102 | } 103 | 104 | public void release() { 105 | if (this.wakeLock != null) { 106 | this.wakeLock.release(); 107 | this.isHeldOnDemand = false; 108 | Log.e("Torchie Wakelock", String.valueOf(this.wakeLock.isHeld())); 109 | } 110 | this.wakeLock = null; 111 | } 112 | 113 | public boolean isHeld() { 114 | return this.wakeLock != null && this.wakeLock.isHeld(); 115 | } 116 | 117 | public void setEnabled(boolean enabled) { 118 | this.isEnabled = enabled; 119 | if (this.wakeLock != null) { 120 | this.wakeLock.setEnabled(this.isEnabled); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/Device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.utils.Constants; 24 | 25 | /** 26 | * Created by Merbin J Anselm on 04-Feb-17. 27 | */ 28 | 29 | public abstract class Device { 30 | 31 | public static final String TYPE = Constants.ID_DEVICE; 32 | 33 | protected final Context mContext; 34 | protected String deviceType; 35 | protected boolean isEnabled; 36 | 37 | public Device(Context context) { 38 | this.mContext = context; 39 | this.deviceType = TYPE; 40 | isEnabled = false; 41 | } 42 | 43 | public final String getDeviceType() { 44 | return this.deviceType; 45 | } 46 | 47 | 48 | public boolean isEnabled() { 49 | return isEnabled; 50 | } 51 | 52 | public void setEnabled(boolean enabled) { 53 | isEnabled = enabled; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/DeviceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 04-Feb-17. 23 | */ 24 | 25 | public interface DeviceListener { 26 | void onError(String error); 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/InputDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2016 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | package in.blogspot.anselmbros.torchie.main.manager.device.input; 38 | 39 | import android.content.Context; 40 | import android.view.InputEvent; 41 | 42 | import in.blogspot.anselmbros.torchie.main.manager.device.Device; 43 | import in.blogspot.anselmbros.torchie.utils.Constants; 44 | 45 | /** 46 | * Created by Merbin J Anselm on 04-Feb-17. 47 | */ 48 | 49 | public abstract class InputDevice extends Device { 50 | public static final String TYPE = Constants.ID_DEVICE_INPUT; 51 | public final static int INP_LOW = 0; 52 | public final static int INP_HIGH = 1; 53 | public final static int INP_TRIGGER = 2; 54 | private InputDeviceListener mListener; 55 | 56 | public InputDevice(Context context) { 57 | super(context); 58 | this.deviceType = TYPE; 59 | } 60 | 61 | public final void setListener(InputDeviceListener listener) { 62 | this.mListener = listener; 63 | } 64 | 65 | public final boolean setInputEvent(InputEvent event) { 66 | if (this.isEnabled) { 67 | return this.setEvent(event); 68 | } 69 | return false; 70 | } 71 | 72 | protected abstract boolean setEvent(InputEvent event); 73 | 74 | public abstract void getStatusRequest(); 75 | 76 | protected final void updateCurrentSignal(int signal) { 77 | if (this.mListener != null) { 78 | this.mListener.onValueChanged(this.deviceType, signal); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/InputDeviceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.input; 20 | 21 | import in.blogspot.anselmbros.torchie.main.manager.device.DeviceListener; 22 | 23 | /** 24 | * Created by Merbin J Anselm on 04-Feb-17. 25 | */ 26 | 27 | public interface InputDeviceListener extends DeviceListener { 28 | void onValueChanged(String deviceType, int eventConstant); 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/key/volume/VolumeKeyDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.main.manager.device.input.InputDevice; 24 | import in.blogspot.anselmbros.torchie.utils.Constants; 25 | 26 | /** 27 | * Created by Merbin J Anselm on 05-Feb-17. 28 | */ 29 | 30 | public abstract class VolumeKeyDevice extends InputDevice { 31 | public static final String TYPE = Constants.ID_DEVICE_INPUT_VOLUMEKEY; 32 | 33 | public static final int MODE_VOLUME_COMBO = 0; 34 | 35 | private int mMode; 36 | 37 | public VolumeKeyDevice(Context context) { 38 | super(context); 39 | this.mMode = MODE_VOLUME_COMBO; 40 | this.deviceType = TYPE; 41 | } 42 | 43 | public final int getMode() { 44 | return this.mMode; 45 | } 46 | 47 | public final void setMode(int mode) { 48 | this.mMode = mode; 49 | } 50 | 51 | @Override 52 | public void getStatusRequest() { 53 | this.isActionModePerformed(); 54 | } 55 | 56 | protected final boolean isActionModePerformed() { 57 | switch (this.mMode) { 58 | case MODE_VOLUME_COMBO: 59 | return this.isKeyComboPerformed(); 60 | default: 61 | return this.isKeyComboPerformed(); 62 | } 63 | } 64 | 65 | protected abstract boolean isKeyComboPerformed(); 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/key/volume/nativve/VolumeKeyNative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2016 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | package in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.nativve; 38 | 39 | import android.content.Context; 40 | import android.view.InputEvent; 41 | import android.view.KeyEvent; 42 | 43 | import in.blogspot.anselmbros.torchie.main.manager.device.input.event.VolumeKeyEvent; 44 | import in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.VolumeKeyDevice; 45 | import in.blogspot.anselmbros.torchie.utils.Constants; 46 | 47 | /** 48 | * Created by Merbin J Anselm on 04-Feb-17. 49 | */ 50 | 51 | public class VolumeKeyNative extends VolumeKeyDevice { 52 | public static final String TYPE = Constants.ID_DEVICE_INPUT_VOLUMEKEY_NATIVE; 53 | 54 | private boolean volumeDownPressed; 55 | private boolean volumeUpPressed; 56 | 57 | public VolumeKeyNative(Context context) { 58 | super(context); 59 | this.deviceType = TYPE; 60 | volumeDownPressed = false; 61 | volumeUpPressed = false; 62 | } 63 | 64 | @Override 65 | public boolean setEvent(InputEvent event) { 66 | VolumeKeyEvent volumeKeyEvent = (VolumeKeyEvent) event; 67 | if (volumeKeyEvent.getVolumeKeyEventType() == VolumeKeyEvent.VOLUME_KEY_EVENT_NATIVE && volumeKeyEvent.isVolumeKeyEvent()) { 68 | if (volumeKeyEvent.getAction() == KeyEvent.ACTION_DOWN) { 69 | if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { 70 | volumeDownPressed = true; 71 | } else if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { 72 | volumeUpPressed = true; 73 | } 74 | } else if (volumeKeyEvent.getAction() == KeyEvent.ACTION_UP) { 75 | if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { 76 | volumeDownPressed = false; 77 | } else if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { 78 | volumeUpPressed = false; 79 | } 80 | } 81 | return this.isActionModePerformed(); 82 | } 83 | return false; 84 | } 85 | 86 | 87 | protected boolean isKeyComboPerformed() { 88 | boolean keyComboPerformed = volumeDownPressed && volumeUpPressed; 89 | if (keyComboPerformed) { 90 | this.updateCurrentSignal(INP_TRIGGER); 91 | } 92 | return keyComboPerformed; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/key/volume/rocker/VolumeKeyRocker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2017 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | /* 38 | * Copyright (C) 2016 Merbin J Anselm 39 | * 40 | * This program is free software; you can redistribute it and/or modify 41 | * it under the terms of the GNU General Public License as published by 42 | * the Free Software Foundation; either version 2 of the License, or 43 | * (at your option) any later version. 44 | * 45 | * This program is distributed in the hope that it will be useful, 46 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 47 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 48 | * GNU General Public License for more details. 49 | * 50 | * You should have received a copy of the GNU General Public License along 51 | * with this program; if not, write to the Free Software Foundation, Inc., 52 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 53 | */ 54 | 55 | package in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.rocker; 56 | 57 | import android.content.Context; 58 | import android.view.InputEvent; 59 | 60 | import in.blogspot.anselmbros.torchie.main.manager.device.input.event.VolumeKeyEvent; 61 | import in.blogspot.anselmbros.torchie.main.manager.device.input.key.volume.VolumeKeyDevice; 62 | import in.blogspot.anselmbros.torchie.utils.Constants; 63 | 64 | /** 65 | * Created by Merbin J Anselm on 04-Feb-17. 66 | */ 67 | 68 | public class VolumeKeyRocker extends VolumeKeyDevice { 69 | public static final String TYPE = Constants.ID_DEVICE_INPUT_VOLUMEKEY_ROCKER; 70 | 71 | private final static int MAX_BUFFER_SIZE = 6; 72 | private int[] buffer; 73 | private int current_ptr; 74 | 75 | public VolumeKeyRocker(Context context) { 76 | super(context); 77 | this.deviceType = TYPE; 78 | buffer = new int[MAX_BUFFER_SIZE]; 79 | } 80 | 81 | @Override 82 | public boolean setEvent(InputEvent event) { 83 | VolumeKeyEvent volumeKeyEvent = (VolumeKeyEvent) event; 84 | if (volumeKeyEvent.getVolumeKeyEventType() == VolumeKeyEvent.VOLUME_KEY_EVENT_ROCKER && volumeKeyEvent.isVolumeKeyEvent()) { 85 | buffer[current_ptr] = volumeKeyEvent.getCurrentValue(); 86 | current_ptr++; 87 | if (current_ptr == MAX_BUFFER_SIZE) { 88 | current_ptr = 0; 89 | } 90 | return this.isActionModePerformed(); 91 | } 92 | return false; 93 | } 94 | 95 | @Override 96 | protected boolean isKeyComboPerformed() { 97 | boolean keyComboPerformed = false; 98 | for (int i = 0; i < current_ptr; i++) { 99 | if (i > 0) { 100 | int a = buffer[i], b = buffer[i - 1]; 101 | if ((a == -1 && b == 1) || (a == 1 && b == -1)) { 102 | this.clearBuffer(); 103 | keyComboPerformed = true; 104 | } 105 | } 106 | } 107 | if (keyComboPerformed) { 108 | this.updateCurrentSignal(INP_TRIGGER); 109 | } 110 | return keyComboPerformed; 111 | } 112 | 113 | private void clearBuffer() { 114 | buffer = new int[MAX_BUFFER_SIZE]; 115 | current_ptr = 0; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/input/proximity/ProximitySensor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.input.proximity; 20 | 21 | import android.content.Context; 22 | import android.hardware.Sensor; 23 | import android.hardware.SensorEvent; 24 | import android.hardware.SensorEventListener; 25 | import android.hardware.SensorManager; 26 | import android.view.InputEvent; 27 | 28 | import in.blogspot.anselmbros.torchie.main.manager.device.input.InputDevice; 29 | import in.blogspot.anselmbros.torchie.main.manager.timer.CountTimer; 30 | import in.blogspot.anselmbros.torchie.main.manager.timer.CountTimerListener; 31 | import in.blogspot.anselmbros.torchie.utils.Constants; 32 | 33 | import static android.content.Context.SENSOR_SERVICE; 34 | 35 | /** 36 | * Created by Merbin J Anselm on 04-Feb-17. 37 | */ 38 | 39 | public class ProximitySensor extends InputDevice implements SensorEventListener, CountTimerListener { 40 | public static final String TYPE = Constants.ID_DEVICE_INPUT_PROXIMITY; 41 | private static ProximitySensor mInstance; 42 | private CountTimer mCountTimer; 43 | 44 | private int signal; 45 | 46 | private ProximitySensor(Context context) { 47 | super(context); 48 | this.deviceType = TYPE; 49 | } 50 | 51 | public static ProximitySensor getInstance(Context context) { 52 | if (mInstance == null) { 53 | mInstance = new ProximitySensor(context); 54 | } 55 | return mInstance; 56 | } 57 | 58 | @Override 59 | protected boolean setEvent(InputEvent event) { 60 | return false; 61 | } 62 | 63 | @Override 64 | public void getStatusRequest() { 65 | final SensorManager mSensorManager = (SensorManager) this.mContext.getSystemService(SENSOR_SERVICE); 66 | final Sensor proximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); 67 | mSensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_FASTEST); 68 | } 69 | 70 | @Override 71 | public void onSensorChanged(SensorEvent event) { 72 | signal = (event.values[0] == 0) ? INP_HIGH : INP_LOW; 73 | if (signal == INP_HIGH) { 74 | if (mCountTimer != null) { 75 | mCountTimer.cancel(); 76 | } 77 | final SensorManager mSensorManager = (SensorManager) this.mContext.getSystemService(SENSOR_SERVICE); 78 | mSensorManager.unregisterListener(this); 79 | this.updateCurrentSignal(signal); 80 | } else { 81 | mCountTimer = new CountTimer("ProximitySensorResponse", 0.3f, this); 82 | mCountTimer.start(); 83 | } 84 | } 85 | 86 | @Override 87 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 88 | 89 | } 90 | 91 | @Override 92 | public void onCountEnd(String id) { 93 | final SensorManager mSensorManager = (SensorManager) this.mContext.getSystemService(SENSOR_SERVICE); 94 | mSensorManager.unregisterListener(this); 95 | this.updateCurrentSignal(signal); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/OutputDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.main.manager.device.Device; 24 | import in.blogspot.anselmbros.torchie.utils.Constants; 25 | 26 | /** 27 | * Created by Merbin J Anselm on 04-Feb-17. 28 | */ 29 | 30 | public abstract class OutputDevice extends Device { 31 | 32 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT; 33 | 34 | private boolean mStatus; 35 | private OutputDeviceListener mListener; 36 | 37 | public OutputDevice(Context context) { 38 | super(context); 39 | this.deviceType = TYPE; 40 | this.mStatus = false; 41 | } 42 | 43 | protected abstract void turnOn(); 44 | 45 | protected abstract void turnOff(); 46 | 47 | public final void start(boolean status) { 48 | if (this.isEnabled) { 49 | if (status && !this.mStatus) 50 | this.turnOn(); 51 | else if (!status && this.mStatus) 52 | this.turnOff(); 53 | } 54 | } 55 | 56 | public final void toggle() { 57 | this.start(!this.mStatus); 58 | } 59 | 60 | public final boolean getStatus() { 61 | return this.mStatus; 62 | } 63 | 64 | public final void setListener(OutputDeviceListener listener) { 65 | this.mListener = listener; 66 | } 67 | 68 | protected final void updateStatus(boolean status) { 69 | this.mStatus = status; 70 | if (this.mListener != null) { 71 | this.mListener.onStatusChanged(this.deviceType, status); 72 | } 73 | } 74 | 75 | protected final void updateError(String error) { 76 | if (this.mListener != null) { 77 | this.mListener.onError(error); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/OutputDeviceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output; 20 | 21 | import in.blogspot.anselmbros.torchie.main.manager.device.DeviceListener; 22 | 23 | /** 24 | * Created by Merbin J Anselm on 04-Feb-17. 25 | */ 26 | 27 | public interface OutputDeviceListener extends DeviceListener { 28 | void onStatusChanged(String deviceType, boolean status); 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/torch/Torch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.torch; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.main.manager.device.output.OutputDevice; 24 | import in.blogspot.anselmbros.torchie.utils.Constants; 25 | 26 | /** 27 | * Created by Merbin J Anselm on 05-Feb-17. 28 | */ 29 | 30 | public abstract class Torch extends OutputDevice { 31 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_TORCH; 32 | 33 | public Torch(Context context) { 34 | super(context); 35 | this.deviceType = TYPE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/torch/flashlight/Flashlight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.torch.flashlight; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.main.manager.device.output.torch.Torch; 24 | import in.blogspot.anselmbros.torchie.utils.Constants; 25 | 26 | /** 27 | * Created by Merbin J Anselm on 06-Feb-17. 28 | */ 29 | 30 | public abstract class Flashlight extends Torch { 31 | 32 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_TORCH_FLASH; 33 | 34 | public Flashlight(Context context) { 35 | super(context); 36 | this.deviceType = TYPE; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/torch/flashlight/Flashlight1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.torch.flashlight; 20 | 21 | import android.content.Context; 22 | import android.graphics.SurfaceTexture; 23 | import android.hardware.Camera; 24 | 25 | import java.io.IOException; 26 | import java.util.List; 27 | 28 | import in.blogspot.anselmbros.torchie.R; 29 | import in.blogspot.anselmbros.torchie.utils.Constants; 30 | 31 | /** 32 | * Created by Merbin J Anselm on 04-Feb-17. 33 | */ 34 | 35 | public class Flashlight1 extends Flashlight { 36 | 37 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_TORCH_FLASH_LEGACY; 38 | 39 | private Camera mCamera; 40 | private boolean flashSupported; 41 | 42 | public Flashlight1(Context context) { 43 | super(context); 44 | this.flashSupported = false; 45 | this.deviceType = TYPE; 46 | } 47 | 48 | @Override 49 | protected void turnOn() { 50 | if (this.ready() && !this.getStatus()) { 51 | try { 52 | this.mCamera.setPreviewTexture(new SurfaceTexture(0));//Thanks to http://github.com/bleeding182/minimalist-flashlight 53 | this.mCamera.startPreview(); 54 | // this.mCamera.autoFocus(null); //Causing error in Oxygen OS 2.2.0 (based on Android 5.1.1) marked by Piotr Zaborowski 55 | this.updateStatus(true); 56 | } catch (IOException previewUnavailable) { 57 | this.updateError(this.mContext.getResources().getString(R.string.camera_error)); 58 | if (this.mCamera != null) { 59 | try { 60 | this.mCamera.release(); 61 | this.mCamera = null; 62 | } catch (Exception ex) { 63 | } 64 | } 65 | } 66 | } 67 | //TODO: Make it run in AsyncTask 68 | } 69 | 70 | @Override 71 | protected void turnOff() { 72 | if (this.getStatus() && this.mCamera != null) { 73 | this.mCamera.stopPreview(); 74 | this.mCamera.release(); 75 | this.mCamera = null; 76 | this.updateStatus(false); 77 | } 78 | } 79 | 80 | private boolean ready() { 81 | if (this.mCamera == null) { 82 | try { 83 | this.mCamera = Camera.open(); 84 | } catch (RuntimeException cameraNotFound) { 85 | this.updateError(this.mContext.getResources().getString(R.string.camera_busy)); 86 | return false; 87 | } 88 | } 89 | Camera.Parameters mCameraParameters = this.mCamera.getParameters(); 90 | List supportedFlashModes = mCameraParameters.getSupportedFlashModes(); 91 | if (supportedFlashModes != null) { 92 | if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) { 93 | this.flashSupported = true; 94 | mCameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); 95 | } else if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_ON)) { 96 | this.flashSupported = true; 97 | mCameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON); 98 | } 99 | } 100 | if (this.flashSupported) { 101 | try { 102 | mCamera.setParameters(mCameraParameters); 103 | } catch (RuntimeException FeatureUnsupported) { 104 | this.updateError(this.mContext.getResources().getString(R.string.torch_unsupported)); 105 | return false; 106 | } 107 | } 108 | return true; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/torch/flashlight/Flashlight2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.torch.flashlight; 20 | 21 | import android.annotation.TargetApi; 22 | import android.content.Context; 23 | import android.hardware.camera2.CameraAccessException; 24 | import android.hardware.camera2.CameraCharacteristics; 25 | import android.hardware.camera2.CameraManager; 26 | 27 | import in.blogspot.anselmbros.torchie.R; 28 | import in.blogspot.anselmbros.torchie.utils.Constants; 29 | 30 | /** 31 | * Created by Merbin J Anselm on 04-Feb-17. 32 | */ 33 | 34 | @TargetApi(23) 35 | public class Flashlight2 extends Flashlight { 36 | 37 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_TORCH_FLASH_NEW; 38 | 39 | private String[] mCameraIDList; 40 | private boolean flashSupported; 41 | 42 | public Flashlight2(Context context) { 43 | super(context); 44 | flashSupported = false; 45 | this.deviceType = TYPE; 46 | } 47 | 48 | @Override 49 | protected void turnOn() { 50 | if (!this.getStatus()) { 51 | CameraManager mCameraManager = (CameraManager) this.mContext.getSystemService(Context.CAMERA_SERVICE); 52 | try { 53 | this.mCameraIDList = mCameraManager.getCameraIdList(); 54 | } catch (CameraAccessException e) { 55 | this.updateError(this.mContext.getResources().getString(R.string.camera_error)); 56 | return; 57 | } 58 | try { 59 | CameraCharacteristics mCameraParameters = mCameraManager.getCameraCharacteristics(this.mCameraIDList[0]); 60 | this.flashSupported = mCameraParameters.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); 61 | } catch (Exception e) { 62 | this.updateError(this.mContext.getResources().getString(R.string.torch_unsupported)); 63 | return; 64 | } 65 | if (this.flashSupported) { 66 | try { 67 | mCameraManager.setTorchMode(this.mCameraIDList[0], true); 68 | this.updateStatus(true); 69 | } catch (CameraAccessException e) { 70 | this.updateError(this.mContext.getResources().getString(R.string.camera_busy)); 71 | } 72 | } 73 | } 74 | } 75 | 76 | @Override 77 | protected void turnOff() { 78 | if (this.getStatus()) { 79 | if (this.mCameraIDList != null && this.flashSupported) { 80 | CameraManager mCameraManager = (CameraManager) this.mContext.getSystemService(Context.CAMERA_SERVICE); 81 | try { 82 | mCameraManager.setTorchMode(mCameraIDList[0], false); 83 | } catch (CameraAccessException e) { 84 | this.updateError(this.mContext.getResources().getString(R.string.torch_unsupported)); 85 | return; 86 | } 87 | this.updateStatus(false); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/torch/screenlight/Screenlight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.torch.screenlight; 20 | 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.content.IntentFilter; 25 | 26 | import in.blogspot.anselmbros.torchie.main.manager.device.output.torch.Torch; 27 | import in.blogspot.anselmbros.torchie.ui.activity.ScreenflashActivity; 28 | import in.blogspot.anselmbros.torchie.utils.Constants; 29 | 30 | /** 31 | * Created by Merbin J Anselm on 04-Feb-17. 32 | */ 33 | 34 | public class Screenlight extends Torch { 35 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_TORCH_SCREEN; 36 | public final static String CLOSE_ACTIVITY_IDENTIFIER = "in.blogspot.anselmbros.torchie.CLOSE_ACTIVITY"; 37 | 38 | private ScreenlightOffReceiver screenlightOffReceiver; 39 | 40 | public Screenlight(Context context) { 41 | super(context); 42 | this.deviceType = TYPE; 43 | } 44 | 45 | @Override 46 | protected void turnOn() { 47 | Intent intent = new Intent(this.mContext, ScreenflashActivity.class); 48 | intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 49 | intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 50 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 51 | this.mContext.startActivity(intent); 52 | this.updateStatus(true); 53 | } 54 | 55 | @Override 56 | protected void turnOff() { 57 | this.mContext.sendBroadcast(new Intent(CLOSE_ACTIVITY_IDENTIFIER)); 58 | screenlightOffReceiver = new ScreenlightOffReceiver(); 59 | this.mContext.registerReceiver(screenlightOffReceiver, new IntentFilter(this.deviceType)); 60 | } 61 | 62 | public class ScreenlightOffReceiver extends BroadcastReceiver { 63 | @Override 64 | public void onReceive(Context context, Intent intent) { 65 | updateStatus(false); 66 | if (intent.getAction().equals(deviceType)) { 67 | mContext.unregisterReceiver(screenlightOffReceiver); 68 | screenlightOffReceiver = null; 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/device/output/vibrator/Vibrator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.device.output.vibrator; 20 | 21 | import android.content.Context; 22 | 23 | import in.blogspot.anselmbros.torchie.R; 24 | import in.blogspot.anselmbros.torchie.main.manager.device.output.OutputDevice; 25 | import in.blogspot.anselmbros.torchie.utils.Constants; 26 | 27 | /** 28 | * Created by Merbin J Anselm on 05-Feb-17. 29 | */ 30 | 31 | public class Vibrator extends OutputDevice { 32 | public static final String TYPE = Constants.ID_DEVICE_OUTPUT_VIBRATOR; 33 | 34 | public final long duration; 35 | 36 | public Vibrator(Context context) { 37 | super(context); 38 | this.deviceType = TYPE; 39 | this.duration = context.getResources().getInteger(R.integer.pref_default_vibration_duration); 40 | } 41 | 42 | @Override 43 | protected void turnOn() { 44 | final android.os.Vibrator vibrator = (android.os.Vibrator) this.mContext.getSystemService(Context.VIBRATOR_SERVICE); 45 | vibrator.vibrate(duration); 46 | } 47 | 48 | @Override 49 | protected void turnOff() { 50 | final android.os.Vibrator vibrator = (android.os.Vibrator) this.mContext.getSystemService(Context.VIBRATOR_SERVICE); 51 | vibrator.cancel(); 52 | } 53 | 54 | public void vibrate() { 55 | this.turnOn(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/timer/CountTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.timer; 20 | 21 | import android.os.CountDownTimer; 22 | 23 | /** 24 | * Created by Merbin J Anselm on 10-Feb-17. 25 | */ 26 | 27 | public class CountTimer extends CountDownTimer { 28 | 29 | private CountTimerListener mListener; 30 | private String id; 31 | 32 | public CountTimer(String id, double seconds, CountTimerListener listener) { 33 | super((long) (seconds * 1000), (long) (seconds * 1000)); 34 | this.id = id; 35 | this.mListener = listener; 36 | } 37 | 38 | @Override 39 | public void onTick(long millisUntilFinished) { 40 | 41 | } 42 | 43 | @Override 44 | public void onFinish() { 45 | if (this.mListener != null) { 46 | this.mListener.onCountEnd(this.id); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/main/manager/timer/CountTimerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.main.manager.timer; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 10-Feb-17. 23 | */ 24 | 25 | public interface CountTimerListener { 26 | void onCountEnd(String id); 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/receiver/BootReadyReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.receiver; 20 | 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | 25 | import in.blogspot.anselmbros.torchie.R; 26 | import in.blogspot.anselmbros.torchie.service.TorchieQuick; 27 | import in.blogspot.anselmbros.torchie.utils.NotificationUtils; 28 | 29 | /** 30 | * Created by anselm94 on 21/4/16. 31 | */ 32 | public class BootReadyReceiver extends BroadcastReceiver { 33 | @Override 34 | public void onReceive(Context context, Intent intent) { 35 | if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { 36 | if (TorchieQuick.getInstance() == null) { 37 | NotificationUtils.sendNotification(context, String.format(context.getResources().getString(R.string.notify_title)), String.format(context.getResources().getString(R.string.notify_text))); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/receiver/RockerReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2017 Merbin J Anselm 21 | * 22 | * This program is free software; you can redistribute it and/or modify 23 | * it under the terms of the GNU General Public License as published by 24 | * the Free Software Foundation; either version 2 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This program is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU General Public License along 33 | * with this program; if not, write to the Free Software Foundation, Inc., 34 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35 | */ 36 | 37 | package in.blogspot.anselmbros.torchie.receiver; 38 | 39 | import android.content.BroadcastReceiver; 40 | import android.content.Context; 41 | import android.content.Intent; 42 | import android.view.KeyEvent; 43 | 44 | import in.blogspot.anselmbros.torchie.service.TorchieQuick; 45 | 46 | public class RockerReceiver extends BroadcastReceiver { 47 | @Override 48 | public void onReceive(Context context, Intent intent) { 49 | if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { 50 | final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 51 | if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) { 52 | switch (event.getKeyCode()) { 53 | case KeyEvent.KEYCODE_VOLUME_UP: 54 | if (this.isTorchieQuickServiceRunning()) { 55 | TorchieQuick.getInstance().setVolumeValues(1); 56 | } 57 | break; 58 | case KeyEvent.KEYCODE_VOLUME_DOWN: 59 | if (this.isTorchieQuickServiceRunning()) { 60 | TorchieQuick.getInstance().setVolumeValues(-1); 61 | } 62 | break; 63 | default: 64 | if (this.isTorchieQuickServiceRunning()) { 65 | TorchieQuick.getInstance().setVolumeValues(0); 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | private boolean isTorchieQuickServiceRunning() { 73 | return TorchieQuick.getInstance() != null; 74 | } 75 | } -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/activity/ScreenflashActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.activity; 20 | 21 | import android.app.Activity; 22 | import android.content.BroadcastReceiver; 23 | import android.content.Context; 24 | import android.content.Intent; 25 | import android.content.IntentFilter; 26 | import android.os.Bundle; 27 | import android.view.Window; 28 | import android.view.WindowManager; 29 | 30 | import in.blogspot.anselmbros.torchie.R; 31 | 32 | import static in.blogspot.anselmbros.torchie.main.manager.device.output.torch.screenlight.Screenlight.CLOSE_ACTIVITY_IDENTIFIER; 33 | 34 | public class ScreenflashActivity extends Activity { 35 | 36 | CloseActivityReceiver closeActivityReceiver; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | 41 | requestWindowFeature(Window.FEATURE_NO_TITLE); 42 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | 43 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 44 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | 45 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 46 | 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_screenflash); 49 | 50 | setScreenBrightness(1f); 51 | 52 | closeActivityReceiver = new CloseActivityReceiver(); 53 | registerReceiver(closeActivityReceiver, new IntentFilter(CLOSE_ACTIVITY_IDENTIFIER)); 54 | } 55 | 56 | @Override 57 | protected void onPause() { 58 | overridePendingTransition(0, 0); //Disable exit animation 59 | super.onPause(); 60 | } 61 | 62 | @Override 63 | protected void onDestroy() { 64 | unregisterReceiver(closeActivityReceiver); 65 | super.onDestroy(); 66 | } 67 | 68 | private void setScreenBrightness(float value) { 69 | WindowManager.LayoutParams lp = getWindow().getAttributes(); 70 | lp.screenBrightness = value; // 0f - no backlight ... 1f - full backlight 71 | getWindow().setAttributes(lp); 72 | } 73 | 74 | public class CloseActivityReceiver extends BroadcastReceiver { 75 | @Override 76 | public void onReceive(Context context, Intent intent) { 77 | if (intent.getAction().equals(CLOSE_ACTIVITY_IDENTIFIER)) { 78 | finish(); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/activity/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.activity; 20 | 21 | import android.os.Bundle; 22 | import androidx.appcompat.app.AppCompatActivity; 23 | import androidx.appcompat.widget.Toolbar; 24 | 25 | import in.blogspot.anselmbros.torchie.R; 26 | 27 | public class SettingsActivity extends AppCompatActivity { 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_settings); 33 | Toolbar tb = (Toolbar) findViewById(R.id.toolbar_settings); 34 | setSupportActionBar(tb); 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/fragment/dialog/AboutDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.fragment.dialog; 20 | 21 | import android.app.DialogFragment; 22 | import android.content.Intent; 23 | import android.net.Uri; 24 | import android.os.Bundle; 25 | import android.text.method.LinkMovementMethod; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.view.Window; 30 | import android.widget.TextView; 31 | 32 | import in.blogspot.anselmbros.torchie.R; 33 | import in.blogspot.anselmbros.torchie.utils.Constants; 34 | 35 | /** 36 | * Created by anselm94 on 8/12/15. 37 | */ 38 | public class AboutDialog extends DialogFragment implements View.OnClickListener { 39 | 40 | View rootView; 41 | TextView tvAboutNote, tvAboutAnselm, tvVisitSite, tvFacebook, tvTranslatorNote, tvNotice; 42 | 43 | String notice; 44 | 45 | public AboutDialog() { 46 | 47 | } 48 | 49 | @Override 50 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 51 | rootView = inflater.inflate(R.layout.dialog_about, container, false); 52 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 53 | 54 | tvAboutNote = (TextView) rootView.findViewById(R.id.tv_about_note); 55 | tvAboutAnselm = (TextView) rootView.findViewById(R.id.tv_about_anselm); 56 | tvVisitSite = (TextView) rootView.findViewById(R.id.tv_visit_site); 57 | tvFacebook = (TextView) rootView.findViewById(R.id.tv_facebook); 58 | tvTranslatorNote = (TextView) rootView.findViewById(R.id.tv_translator_note); 59 | tvNotice = (TextView) rootView.findViewById(R.id.tv_notice); 60 | 61 | tvAboutNote.setMovementMethod(LinkMovementMethod.getInstance()); 62 | tvTranslatorNote.setMovementMethod(LinkMovementMethod.getInstance()); 63 | tvAboutAnselm.setOnClickListener(this); 64 | tvVisitSite.setOnClickListener(this); 65 | tvFacebook.setOnClickListener(this); 66 | tvNotice.setMovementMethod(LinkMovementMethod.getInstance()); 67 | 68 | try { 69 | notice = String.format(getActivity().getResources().getString(R.string.notice), getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName); 70 | tvNotice.setText(notice); 71 | } catch (Exception e) { 72 | notice = getActivity().getResources().getString(R.string.notice); 73 | tvNotice.setText(notice); 74 | } 75 | 76 | return rootView; 77 | } 78 | 79 | @Override 80 | public void onClick(View v) { 81 | Intent intent = new Intent(Intent.ACTION_VIEW); 82 | if (v == tvAboutAnselm) { 83 | intent.setData(Uri.parse(Constants.ABOUTANSELM_URI)); 84 | } else if (v == tvVisitSite) { 85 | intent.setData(Uri.parse(Constants.WEB_URI)); 86 | } else if (v == tvFacebook) { 87 | intent.setData(Uri.parse(Constants.FACEBOOK_URI)); 88 | } 89 | startActivity(intent); 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/fragment/dialog/DonateFailDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.fragment.dialog; 20 | 21 | import android.app.DialogFragment; 22 | import android.content.Intent; 23 | import android.net.Uri; 24 | import android.os.Bundle; 25 | import android.os.Handler; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.view.Window; 30 | import android.widget.Button; 31 | 32 | import in.blogspot.anselmbros.torchie.R; 33 | import in.blogspot.anselmbros.torchie.utils.Constants; 34 | 35 | /** 36 | * Created by anselm94 on 9/12/15. 37 | */ 38 | public class DonateFailDialog extends DialogFragment implements View.OnClickListener { 39 | 40 | View rootView; 41 | Button butDismiss, butProceed; 42 | 43 | public DonateFailDialog() { 44 | } 45 | 46 | @Override 47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 48 | rootView = inflater.inflate(R.layout.dialog_donate_failure, container, false); 49 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 50 | 51 | butDismiss = (Button) rootView.findViewById(R.id.but_error_dismiss); 52 | butProceed = (Button) rootView.findViewById(R.id.but_proceed_paypal); 53 | 54 | butDismiss.setOnClickListener(this); 55 | butProceed.setOnClickListener(this); 56 | 57 | return rootView; 58 | } 59 | 60 | @Override 61 | public void onClick(View v) { 62 | if (v == butDismiss) { 63 | Handler mHandler = new Handler(); 64 | mHandler.postDelayed(new Runnable() { 65 | 66 | @Override 67 | public void run() { 68 | dismiss(); 69 | } 70 | 71 | }, 350L); 72 | } else if (v == butProceed) { 73 | Handler mHandler = new Handler(); 74 | mHandler.postDelayed(new Runnable() { 75 | 76 | @Override 77 | public void run() { 78 | Intent intent = new Intent(Intent.ACTION_VIEW); 79 | intent.setData(Uri.parse(Constants.WEB_DONATE_URI)); 80 | startActivity(intent); 81 | dismiss(); 82 | } 83 | 84 | }, 350L); 85 | 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/fragment/dialog/DonateSuccessDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.fragment.dialog; 20 | 21 | import android.app.DialogFragment; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.os.Handler; 25 | import android.view.LayoutInflater; 26 | import android.view.View; 27 | import android.view.ViewGroup; 28 | import android.view.Window; 29 | import android.widget.Button; 30 | 31 | import in.blogspot.anselmbros.torchie.R; 32 | import in.blogspot.anselmbros.torchie.utils.Constants; 33 | 34 | /** 35 | * Created by anselm94 on 9/12/15. 36 | */ 37 | public class DonateSuccessDialog extends DialogFragment implements View.OnClickListener { 38 | 39 | View rootView; 40 | Button butDismiss; 41 | Button butShare; 42 | 43 | public DonateSuccessDialog() { 44 | } 45 | 46 | @Override 47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 48 | rootView = inflater.inflate(R.layout.dialog_donate_success, container, false); 49 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 50 | 51 | butDismiss = (Button) rootView.findViewById(R.id.but_thanks_dismiss); 52 | butShare = (Button) rootView.findViewById(R.id.but_thanks_share); 53 | 54 | butDismiss.setOnClickListener(this); 55 | butShare.setOnClickListener(this); 56 | 57 | return rootView; 58 | } 59 | 60 | @Override 61 | public void onClick(View v) { 62 | 63 | if (v == butDismiss) { 64 | Handler mHandler = new Handler(); 65 | mHandler.postDelayed(new Runnable() { 66 | 67 | @Override 68 | public void run() { 69 | dismiss(); 70 | } 71 | 72 | }, 350L); 73 | } else if (v == butShare) { 74 | Handler mHandler = new Handler(); 75 | mHandler.postDelayed(new Runnable() { 76 | 77 | @Override 78 | public void run() { 79 | Intent int_tell = new Intent(Intent.ACTION_SEND); 80 | int_tell.setType("text/plain"); 81 | int_tell.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_info) + Constants.PLAY_URI); 82 | startActivity(Intent.createChooser(int_tell, getResources().getString(R.string.share_via))); 83 | dismiss(); 84 | } 85 | 86 | }, 350L); 87 | 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/fragment/dialog/PermissionDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.fragment.dialog; 20 | 21 | import android.app.DialogFragment; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.os.Handler; 25 | import android.text.method.LinkMovementMethod; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.view.Window; 30 | import android.widget.TextView; 31 | 32 | import in.blogspot.anselmbros.torchie.R; 33 | 34 | /** 35 | * Created by anselm94 on 8/12/15. 36 | */ 37 | public class PermissionDialog extends DialogFragment implements View.OnClickListener { 38 | 39 | View rootView; 40 | TextView tvPermissionNote, tvPermissionEnable, tvPermissionLater, tvPermissionDetailed; 41 | 42 | public PermissionDialog() { 43 | } 44 | 45 | @Override 46 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 47 | rootView = inflater.inflate(R.layout.dialog_permission, container, false); 48 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 49 | tvPermissionNote = (TextView) rootView.findViewById(R.id.tv_permission_note); 50 | tvPermissionEnable = (TextView) rootView.findViewById(R.id.tv_permission_enable); 51 | tvPermissionLater = (TextView) rootView.findViewById(R.id.tv_permission_later); 52 | tvPermissionDetailed = (TextView) rootView.findViewById(R.id.tv_permission_detail); 53 | 54 | tvPermissionDetailed.setMovementMethod(LinkMovementMethod.getInstance()); 55 | tvPermissionNote.setMovementMethod(LinkMovementMethod.getInstance()); 56 | tvPermissionEnable.setOnClickListener(this); 57 | tvPermissionLater.setOnClickListener(this); 58 | return rootView; 59 | } 60 | 61 | @Override 62 | public void onClick(View v) { 63 | if (v == tvPermissionEnable) { 64 | Handler mHandler = new Handler(); 65 | mHandler.postDelayed(new Runnable() { 66 | 67 | @Override 68 | public void run() { 69 | openAccessibilitySettings(); 70 | dismiss(); 71 | } 72 | 73 | }, 350L); 74 | 75 | } else if (v == tvPermissionLater) { 76 | Handler mHandler = new Handler(); 77 | mHandler.postDelayed(new Runnable() { 78 | 79 | @Override 80 | public void run() { 81 | dismiss(); 82 | } 83 | 84 | }, 350L); 85 | } 86 | } 87 | 88 | private void openAccessibilitySettings() { 89 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 90 | startActivity(intent); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/fragment/dialog/WelcomeDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.fragment.dialog; 20 | 21 | import android.app.DialogFragment; 22 | import android.os.Bundle; 23 | import android.os.Handler; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.view.Window; 28 | import android.widget.Button; 29 | 30 | import in.blogspot.anselmbros.torchie.R; 31 | import in.blogspot.anselmbros.torchie.utils.SettingsUtils; 32 | 33 | /** 34 | * Created by anselm94 on 8/12/15. 35 | */ 36 | public class WelcomeDialog extends DialogFragment implements View.OnClickListener { 37 | 38 | View rootView; 39 | Button but_dismiss; 40 | 41 | public WelcomeDialog() { 42 | } 43 | 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 46 | rootView = inflater.inflate(R.layout.dialog_welcome, container, false); 47 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 48 | but_dismiss = (Button) rootView.findViewById(R.id.but_welcome_dismiss); 49 | but_dismiss.setOnClickListener(this); 50 | return rootView; 51 | } 52 | 53 | @Override 54 | public void onDestroyView() { 55 | SettingsUtils.setFirstTime(this.getActivity(), false); 56 | super.onDestroyView(); 57 | } 58 | 59 | @Override 60 | public void onClick(View v) { 61 | if (v == but_dismiss) { 62 | Handler mHandler = new Handler(); 63 | mHandler.postDelayed(new Runnable() { 64 | 65 | @Override 66 | public void run() { 67 | dismiss(); 68 | } 69 | 70 | }, 350L); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/helper/DonateDialogListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.helper; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 24-Mar-17. 23 | */ 24 | 25 | public interface DonateDialogListener { 26 | void onDonateDialogResult(boolean isSuccess); 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/widget/settings/CheckBoxDialogPreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.widget.settings; 20 | 21 | import android.content.Context; 22 | import android.util.AttributeSet; 23 | import android.view.View; 24 | import android.widget.CheckBox; 25 | 26 | import in.blogspot.anselmbros.torchie.R; 27 | 28 | /** 29 | * Created by Merbin J Anselm on 27-Jan-17. 30 | */ 31 | 32 | public class CheckBoxDialogPreference extends TimeoutListPreference { 33 | 34 | public CheckBoxDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | public CheckBoxDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) { 39 | super(context, attrs, defStyleAttr); 40 | } 41 | 42 | public CheckBoxDialogPreference(Context context, AttributeSet attrs) { 43 | super(context, attrs); 44 | } 45 | 46 | public CheckBoxDialogPreference(Context context) { 47 | super(context); 48 | } 49 | 50 | @Override 51 | protected void onBindView(View view) { 52 | super.onBindView(view); 53 | int value = Integer.parseInt(this.getValue()); 54 | CheckBox checkBox = view.findViewById(R.id.chkbx_pref); 55 | checkBox.setChecked((value == -1 || value > 0) && isEnabled()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/ui/widget/settings/TimeoutListPreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.ui.widget.settings; 20 | 21 | import android.annotation.TargetApi; 22 | import android.content.Context; 23 | import android.content.res.Resources; 24 | import android.preference.ListPreference; 25 | import android.util.AttributeSet; 26 | 27 | import in.blogspot.anselmbros.torchie.R; 28 | 29 | /** 30 | * Created by Merbin J Anselm on 27-Jan-17. 31 | */ 32 | 33 | public class TimeoutListPreference extends ListPreference { 34 | 35 | @TargetApi(21) 36 | public TimeoutListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 37 | super(context, attrs, defStyleAttr, defStyleRes); 38 | this.setTimeoutValues(this.getEntryValues()); 39 | } 40 | 41 | @TargetApi(21) 42 | public TimeoutListPreference(Context context, AttributeSet attrs, int defStyleAttr) { 43 | super(context, attrs, defStyleAttr); 44 | this.setTimeoutValues(this.getEntryValues()); 45 | } 46 | 47 | public TimeoutListPreference(Context context, AttributeSet attrs) { 48 | super(context, attrs); 49 | this.setTimeoutValues(this.getEntryValues()); 50 | } 51 | 52 | public TimeoutListPreference(Context context) { 53 | super(context); 54 | this.setTimeoutValues(this.getEntryValues()); 55 | } 56 | 57 | protected void setTimeoutValues(CharSequence[] entryValues) { 58 | Resources res = this.getContext().getResources(); 59 | 60 | String txtMinutes = res.getString(R.string.minutes); 61 | String txtSeconds = res.getString(R.string.seconds); 62 | String txtIndefinite = res.getString(R.string.indefinite); 63 | String txtOff = res.getString(R.string.off); 64 | 65 | CharSequence[] entries = new String[entryValues.length]; 66 | for (int i = 0; i < entryValues.length; i++) { 67 | int val = Integer.parseInt(String.valueOf(entryValues[i])); 68 | switch (val) { 69 | case -1: 70 | entries[i] = txtIndefinite; 71 | break; 72 | case 0: 73 | entries[i] = txtOff; 74 | break; 75 | default: 76 | String suffix = ((val / 60) > 0) ? txtMinutes : txtSeconds; 77 | int prefix = ((val / 60) > 0) ? (val / 60) : (val % 60); 78 | entries[i] = prefix + " " + suffix; 79 | } 80 | } 81 | this.setEntries(entries); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils; 20 | 21 | /** 22 | * Created by Merbin J Anselm on 19-Feb-17. 23 | */ 24 | 25 | public class Constants { 26 | public final static String ID_DEVICE = "0"; 27 | 28 | public final static String ID_DEVICE_OUTPUT = "1"; 29 | public final static String ID_DEVICE_OUTPUT_TORCH = "10"; 30 | public final static String ID_DEVICE_OUTPUT_TORCH_FLASH = "11"; 31 | public final static String ID_DEVICE_OUTPUT_TORCH_FLASH_LEGACY = "12"; 32 | public final static String ID_DEVICE_OUTPUT_TORCH_FLASH_NEW = "13"; 33 | public final static String ID_DEVICE_OUTPUT_TORCH_SCREEN = "14"; 34 | public final static String ID_DEVICE_OUTPUT_VIBRATOR = "15"; 35 | 36 | public final static String ID_DEVICE_INPUT = "2"; 37 | public final static String ID_DEVICE_INPUT_VOLUMEKEY = "20"; 38 | public final static String ID_DEVICE_INPUT_VOLUMEKEY_NATIVE = "21"; 39 | public final static String ID_DEVICE_INPUT_VOLUMEKEY_ROCKER = "22"; 40 | public final static String ID_DEVICE_INPUT_PROXIMITY = "23"; 41 | 42 | public final static String PLAY_URI = "https://play.google.com/store/apps/details?id=in.blogspot.anselmbros.torchie"; 43 | public final static String WEB_URI = "https://torchieapp.wordpress.com"; 44 | public final static String ABOUTANSELM_URI = "https://anselm.in"; 45 | public final static String FACEBOOK_URI = "https://facebook.com/torchieapp"; 46 | public final static String WEB_DONATE_URI = "https://torchieapp.wordpress.com/donate/"; 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/IabBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 20 | 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | 25 | /** 26 | * Receiver for the "com.android.vending.billing.PURCHASES_UPDATED" Action 27 | * from the Play Store. 28 | *

29 | *

It is possible that an in-app item may be acquired without the 30 | * application calling getBuyIntent(), for example if the item can be 31 | * redeemed from inside the Play Store using a promotional code. If this 32 | * application isn't running at the time, then when it is started a call 33 | * to getPurchases() will be sufficient notification. However, if the 34 | * application is already running in the background when the item is acquired, 35 | * a message to this BroadcastReceiver will indicate that the an item 36 | * has been acquired.

37 | */ 38 | public class IabBroadcastReceiver extends BroadcastReceiver { 39 | /** 40 | * The Intent action that this Receiver should filter for. 41 | */ 42 | public static final String ACTION = "com.android.vending.billing.PURCHASES_UPDATED"; 43 | private final IabBroadcastListener mListener; 44 | 45 | public IabBroadcastReceiver(IabBroadcastListener listener) { 46 | mListener = listener; 47 | } 48 | 49 | @Override 50 | public void onReceive(Context context, Intent intent) { 51 | if (mListener != null) { 52 | mListener.receivedBroadcast(); 53 | } 54 | } 55 | 56 | /** 57 | * Listener interface for received broadcast messages. 58 | */ 59 | public interface IabBroadcastListener { 60 | void receivedBroadcast(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/IabException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 20 | 21 | /** 22 | * Exception thrown when something went wrong with in-app billing. 23 | * An IabException has an associated IabResult (an error). 24 | * To get the IAB result that caused this exception to be thrown, 25 | * call {@link #getResult()}. 26 | */ 27 | public class IabException extends Exception { 28 | IabResult mResult; 29 | 30 | public IabException(IabResult r) { 31 | this(r, null); 32 | } 33 | 34 | public IabException(int response, String message) { 35 | this(new IabResult(response, message)); 36 | } 37 | 38 | public IabException(IabResult r, Exception cause) { 39 | super(r.getMessage(), cause); 40 | mResult = r; 41 | } 42 | 43 | public IabException(int response, String message, Exception cause) { 44 | this(new IabResult(response, message), cause); 45 | } 46 | 47 | /** 48 | * Returns the IAB result (error) that this exception signals. 49 | */ 50 | public IabResult getResult() { 51 | return mResult; 52 | } 53 | } -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/IabResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 20 | 21 | /** 22 | * Represents the result of an in-app billing operation. 23 | * A result is composed of a response code (an integer) and possibly a 24 | * message (String). You can get those by calling 25 | * {@link #getResponse} and {@link #getMessage()}, respectively. You 26 | * can also inquire whether a result is a success or a failure by 27 | * calling {@link #isSuccess()} and {@link #isFailure()}. 28 | */ 29 | public class IabResult { 30 | int mResponse; 31 | String mMessage; 32 | 33 | public IabResult(int response, String message) { 34 | mResponse = response; 35 | if (message == null || message.trim().length() == 0) { 36 | mMessage = IabHelper.getResponseDesc(response); 37 | } else { 38 | mMessage = message + " (response: " + IabHelper.getResponseDesc(response) + ")"; 39 | } 40 | } 41 | 42 | public int getResponse() { 43 | return mResponse; 44 | } 45 | 46 | public String getMessage() { 47 | return mMessage; 48 | } 49 | 50 | public boolean isSuccess() { 51 | return mResponse == IabHelper.BILLING_RESPONSE_RESULT_OK; 52 | } 53 | 54 | public boolean isFailure() { 55 | return !isSuccess(); 56 | } 57 | 58 | public String toString() { 59 | return "IabResult: " + getMessage(); 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/Inventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 20 | 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * Represents a block of information about in-app items. 28 | * An Inventory is returned by such methods as {@link IabHelper#queryInventory}. 29 | */ 30 | public class Inventory { 31 | Map mSkuMap = new HashMap(); 32 | Map mPurchaseMap = new HashMap(); 33 | 34 | Inventory() { 35 | } 36 | 37 | /** 38 | * Returns the listing details for an in-app product. 39 | */ 40 | public SkuDetails getSkuDetails(String sku) { 41 | return mSkuMap.get(sku); 42 | } 43 | 44 | /** 45 | * Returns purchase information for a given product, or null if there is no purchase. 46 | */ 47 | public Purchase getPurchase(String sku) { 48 | return mPurchaseMap.get(sku); 49 | } 50 | 51 | /** 52 | * Returns whether or not there exists a purchase of the given product. 53 | */ 54 | public boolean hasPurchase(String sku) { 55 | return mPurchaseMap.containsKey(sku); 56 | } 57 | 58 | /** 59 | * Return whether or not details about the given product are available. 60 | */ 61 | public boolean hasDetails(String sku) { 62 | return mSkuMap.containsKey(sku); 63 | } 64 | 65 | /** 66 | * Erase a purchase (locally) from the inventory, given its product ID. This just 67 | * modifies the Inventory object locally and has no effect on the server! This is 68 | * useful when you have an existing Inventory object which you know to be up to date, 69 | * and you have just consumed an item successfully, which means that erasing its 70 | * purchase data from the Inventory you already have is quicker than querying for 71 | * a new Inventory. 72 | */ 73 | public void erasePurchase(String sku) { 74 | if (mPurchaseMap.containsKey(sku)) mPurchaseMap.remove(sku); 75 | } 76 | 77 | /** 78 | * Returns a list of all owned product IDs. 79 | */ 80 | List getAllOwnedSkus() { 81 | return new ArrayList(mPurchaseMap.keySet()); 82 | } 83 | 84 | /** 85 | * Returns a list of all owned product IDs of a given type 86 | */ 87 | List getAllOwnedSkus(String itemType) { 88 | List result = new ArrayList(); 89 | for (Purchase p : mPurchaseMap.values()) { 90 | if (p.getItemType().equals(itemType)) result.add(p.getSku()); 91 | } 92 | return result; 93 | } 94 | 95 | /** 96 | * Returns a list of all purchases. 97 | */ 98 | List getAllPurchases() { 99 | return new ArrayList(mPurchaseMap.values()); 100 | } 101 | 102 | void addSkuDetails(SkuDetails d) { 103 | mSkuMap.put(d.getSku(), d); 104 | } 105 | 106 | void addPurchase(Purchase p) { 107 | mPurchaseMap.put(p.getSku(), p); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/Purchase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 20 | 21 | import org.json.JSONException; 22 | import org.json.JSONObject; 23 | 24 | /** 25 | * Represents an in-app billing purchase. 26 | */ 27 | public class Purchase { 28 | String mItemType; // ITEM_TYPE_INAPP or ITEM_TYPE_SUBS 29 | String mOrderId; 30 | String mPackageName; 31 | String mSku; 32 | long mPurchaseTime; 33 | int mPurchaseState; 34 | String mDeveloperPayload; 35 | String mToken; 36 | String mOriginalJson; 37 | String mSignature; 38 | boolean mIsAutoRenewing; 39 | 40 | public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException { 41 | mItemType = itemType; 42 | mOriginalJson = jsonPurchaseInfo; 43 | JSONObject o = new JSONObject(mOriginalJson); 44 | mOrderId = o.optString("orderId"); 45 | mPackageName = o.optString("packageName"); 46 | mSku = o.optString("productId"); 47 | mPurchaseTime = o.optLong("purchaseTime"); 48 | mPurchaseState = o.optInt("purchaseState"); 49 | mDeveloperPayload = o.optString("developerPayload"); 50 | mToken = o.optString("token", o.optString("purchaseToken")); 51 | mIsAutoRenewing = o.optBoolean("autoRenewing"); 52 | mSignature = signature; 53 | } 54 | 55 | public String getItemType() { 56 | return mItemType; 57 | } 58 | 59 | public String getOrderId() { 60 | return mOrderId; 61 | } 62 | 63 | public String getPackageName() { 64 | return mPackageName; 65 | } 66 | 67 | public String getSku() { 68 | return mSku; 69 | } 70 | 71 | public long getPurchaseTime() { 72 | return mPurchaseTime; 73 | } 74 | 75 | public int getPurchaseState() { 76 | return mPurchaseState; 77 | } 78 | 79 | public String getDeveloperPayload() { 80 | return mDeveloperPayload; 81 | } 82 | 83 | public String getToken() { 84 | return mToken; 85 | } 86 | 87 | public String getOriginalJson() { 88 | return mOriginalJson; 89 | } 90 | 91 | public String getSignature() { 92 | return mSignature; 93 | } 94 | 95 | public boolean isAutoRenewing() { 96 | return mIsAutoRenewing; 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "PurchaseInfo(type:" + mItemType + "):" + mOriginalJson; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/IabUtils/SkuDetails.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) 2016 Merbin J Anselm 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | package in.blogspot.anselmbros.torchie.utils.IabUtils; 21 | 22 | import org.json.JSONException; 23 | import org.json.JSONObject; 24 | 25 | /** 26 | * Represents an in-app product's listing details. 27 | */ 28 | public class SkuDetails { 29 | private final String mItemType; 30 | private final String mSku; 31 | private final String mType; 32 | private final String mPrice; 33 | private final long mPriceAmountMicros; 34 | private final String mPriceCurrencyCode; 35 | private final String mTitle; 36 | private final String mDescription; 37 | private final String mJson; 38 | 39 | public SkuDetails(String jsonSkuDetails) throws JSONException { 40 | this(IabHelper.ITEM_TYPE_INAPP, jsonSkuDetails); 41 | } 42 | 43 | public SkuDetails(String itemType, String jsonSkuDetails) throws JSONException { 44 | mItemType = itemType; 45 | mJson = jsonSkuDetails; 46 | JSONObject o = new JSONObject(mJson); 47 | mSku = o.optString("productId"); 48 | mType = o.optString("type"); 49 | mPrice = o.optString("price"); 50 | mPriceAmountMicros = o.optLong("price_amount_micros"); 51 | mPriceCurrencyCode = o.optString("price_currency_code"); 52 | mTitle = o.optString("title"); 53 | mDescription = o.optString("description"); 54 | } 55 | 56 | public String getSku() { 57 | return mSku; 58 | } 59 | 60 | public String getType() { 61 | return mType; 62 | } 63 | 64 | public String getPrice() { 65 | return mPrice; 66 | } 67 | 68 | public long getPriceAmountMicros() { 69 | return mPriceAmountMicros; 70 | } 71 | 72 | public String getPriceCurrencyCode() { 73 | return mPriceCurrencyCode; 74 | } 75 | 76 | public String getTitle() { 77 | return mTitle; 78 | } 79 | 80 | public String getDescription() { 81 | return mDescription; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return "SkuDetails:" + mJson; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/LogUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils; 20 | 21 | import android.util.Log; 22 | 23 | import in.blogspot.anselmbros.torchie.BuildConfig; 24 | 25 | /** 26 | * Created by Merbin J Anselm on 02-Feb-17. 27 | */ 28 | 29 | public class LogUtils { 30 | 31 | private static final String LOG_PREFIX = "Torchie:"; 32 | private static final int LOG_PREFIX_LENGTH = LOG_PREFIX.length(); 33 | private static final int MAX_LOG_TAG_LENGTH = 23; 34 | 35 | public static boolean LOGGING_ENABLED = !BuildConfig.BUILD_TYPE.equalsIgnoreCase("release"); 36 | 37 | private LogUtils() { 38 | } 39 | 40 | public static String makeLogTag(String str) { 41 | if (str.length() > MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH) { 42 | return LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH - 1); 43 | } 44 | 45 | return LOG_PREFIX + str; 46 | } 47 | 48 | /** 49 | * Don't use this when obfuscating class names! 50 | */ 51 | public static String makeLogTag(Class cls) { 52 | return makeLogTag(cls.getSimpleName()); 53 | } 54 | 55 | public static void LOGD(final String tag, String message) { 56 | if (LOGGING_ENABLED) { 57 | if (Log.isLoggable(tag, Log.DEBUG)) { 58 | Log.d(tag, message); 59 | } 60 | } 61 | } 62 | 63 | public static void LOGD(final String tag, String message, Throwable cause) { 64 | if (LOGGING_ENABLED) { 65 | if (Log.isLoggable(tag, Log.DEBUG)) { 66 | Log.d(tag, message, cause); 67 | } 68 | } 69 | } 70 | 71 | public static void LOGV(final String tag, String message) { 72 | if (LOGGING_ENABLED) { 73 | if (Log.isLoggable(tag, Log.VERBOSE)) { 74 | Log.v(tag, message); 75 | } 76 | } 77 | } 78 | 79 | public static void LOGV(final String tag, String message, Throwable cause) { 80 | if (LOGGING_ENABLED) { 81 | if (Log.isLoggable(tag, Log.VERBOSE)) { 82 | Log.v(tag, message, cause); 83 | } 84 | } 85 | } 86 | 87 | public static void LOGI(final String tag, String message) { 88 | if (LOGGING_ENABLED) { 89 | Log.i(tag, message); 90 | } 91 | } 92 | 93 | public static void LOGI(final String tag, String message, Throwable cause) { 94 | if (LOGGING_ENABLED) { 95 | Log.i(tag, message, cause); 96 | } 97 | } 98 | 99 | public static void LOGW(final String tag, String message) { 100 | Log.w(tag, message); 101 | } 102 | 103 | public static void LOGW(final String tag, String message, Throwable cause) { 104 | Log.w(tag, message, cause); 105 | } 106 | 107 | public static void LOGE(final String tag, String message) { 108 | Log.e(tag, message); 109 | } 110 | 111 | public static void LOGE(final String tag, String message, Throwable cause) { 112 | Log.e(tag, message, cause); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/NotificationUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils; 20 | 21 | import android.app.Notification; 22 | import android.app.NotificationManager; 23 | import android.app.PendingIntent; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.graphics.BitmapFactory; 27 | import androidx.core.app.NotificationCompat; 28 | 29 | import in.blogspot.anselmbros.torchie.R; 30 | 31 | /** 32 | * Created by Merbin J Anselm on 22-Mar-17. 33 | */ 34 | 35 | public class NotificationUtils { 36 | private static Notification buildNotification(Context context, String title, String text) { 37 | NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); 38 | mBuilder.setSmallIcon(R.drawable.ic_logo_mono); 39 | mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); 40 | mBuilder.setContentTitle(title); 41 | mBuilder.setContentText(text); 42 | mBuilder.setAutoCancel(true); 43 | Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); 44 | PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 45 | mBuilder.setContentIntent(resultPendingIntent); 46 | return mBuilder.build(); 47 | } 48 | 49 | public static void sendNotification(Context context, String title, String text) { 50 | int mNotificationId = 1; 51 | NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 52 | mNotifyMgr.notify(mNotificationId, buildNotification(context, title, text)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/in/blogspot/anselmbros/torchie/utils/SettingsUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Merbin J Anselm 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package in.blogspot.anselmbros.torchie.utils; 20 | 21 | import android.content.Context; 22 | import android.content.SharedPreferences; 23 | import android.preference.PreferenceManager; 24 | 25 | import in.blogspot.anselmbros.torchie.R; 26 | 27 | /** 28 | * Created by Merbin J Anselm on 02-Feb-17. 29 | */ 30 | 31 | public class SettingsUtils { 32 | 33 | public static final String PREF_TORCH_TIMEOUT = "pref_torch_timeout"; 34 | public static final String PREF_TORCH_SOURCE = "pref_torch_source"; 35 | public static final String PREF_VIBRATE = "pref_vibrate"; 36 | private static final String PREF_FIRST_TIME = "pref_first_time"; 37 | private static final String PREF_SCREEN_ON = "pref_screen_on"; 38 | private static final String PREF_SCREEN_LOCK = "pref_screen_lock"; 39 | private static final String PREF_SCREEN_OFF = "pref_screen_off_timeout"; 40 | private static final String PREF_PROXIMITY = "pref_proximity"; 41 | 42 | public static boolean isFirstTime(final Context context) { 43 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 44 | return sp.getBoolean(SettingsUtils.PREF_FIRST_TIME, true); 45 | } 46 | 47 | public static void setFirstTime(final Context context, final boolean newValue) { 48 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 49 | sp.edit().putBoolean(SettingsUtils.PREF_FIRST_TIME, newValue).apply(); 50 | } 51 | 52 | public static boolean isScreenOnEnabled(final Context context) { 53 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 54 | return sp.getBoolean(SettingsUtils.PREF_SCREEN_ON, context.getResources().getBoolean(R.bool.pref_default_screen_on)); 55 | } 56 | 57 | public static boolean isScreenLockEnabled(final Context context) { 58 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 59 | return sp.getBoolean(SettingsUtils.PREF_SCREEN_LOCK, context.getResources().getBoolean(R.bool.pref_default_screen_lock)); 60 | } 61 | 62 | public static boolean isScreenOffEnabled(final Context context) { 63 | int value = SettingsUtils.getScreenOffTimeoutSec(context); 64 | return value != 0; 65 | } 66 | 67 | public static boolean isScreenOffIndefinite(final Context context) { 68 | int value = SettingsUtils.getScreenOffTimeoutSec(context); 69 | return value == -1; 70 | } 71 | 72 | public static int getScreenOffTimeoutSec(final Context context) { 73 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 74 | return Integer.parseInt(sp.getString(SettingsUtils.PREF_SCREEN_OFF, context.getResources().getString(R.string.pref_default_screen_off_timeout))); 75 | } 76 | 77 | public static boolean isTorchTimeoutIndefinite(final Context context) { 78 | int value = SettingsUtils.getTorchTimeout(context); 79 | return value == -1; 80 | } 81 | 82 | public static int getTorchTimeout(final Context context) { 83 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 84 | return Integer.parseInt(sp.getString(SettingsUtils.PREF_TORCH_TIMEOUT, context.getResources().getString(R.string.pref_default_torch_timeout))); 85 | } 86 | 87 | public static String getTorchSource(final Context context) { 88 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 89 | return sp.getString(SettingsUtils.PREF_TORCH_SOURCE, context.getResources().getString(R.string.pref_default_torch_source)); 90 | } 91 | 92 | public static boolean isProximityEnabled(final Context context) { 93 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 94 | return sp.getBoolean(SettingsUtils.PREF_PROXIMITY, context.getResources().getBoolean(R.bool.pref_default_proximity)); 95 | } 96 | 97 | public static boolean isVibrateEnabled(final Context context) { 98 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 99 | return sp.getBoolean(SettingsUtils.PREF_VIBRATE, context.getResources().getBoolean(R.bool.pref_default_vibrate)); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/but_ripple.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/but_ripple.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anselm94/Torchie-Android/9e584003ef834f20b3e085f2140bb936492771bb/app/src/main/res/drawable/ic_donate.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_logo_mono.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anselm94/Torchie-Android/9e584003ef834f20b3e085f2140bb936492771bb/app/src/main/res/drawable/ic_logo_mono.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/sw_flash.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sw_flash_off.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sw_flash_on.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/torchie_head_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anselm94/Torchie-Android/9e584003ef834f20b3e085f2140bb936492771bb/app/src/main/res/drawable/torchie_head_norm.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_screenflash.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_settings.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 23 | 24 | 34 | 35 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_donate_failure.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 25 | 26 | 31 | 32 | 40 | 41 | 48 | 49 | 50 | 59 | 60 | 64 | 65 |