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 |
7 |
8 |
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 |
7 |
8 |
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.