17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Utils/OnFragmentBackPressListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Utils
19 |
20 | interface OnFragmentBackPressListener {
21 |
22 | fun onBackPressed()
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
14 |
18 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | android.useAndroidX=true
11 | android.enableJetifier=true
12 | RELEASE_STORE_FILE=release_keystore.jks
13 | RELEASE_STORE_PASSWORD=$BITRISEIO_ANDROID_KEYSTORE_PASSWORD
14 | RELEASE_KEY_ALIAS=$BITRISEIO_ANDROID_KEYSTORE_ALIAS
15 | RELEASE_KEY_PASSWORD=$BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | LOCAL_MODULE_TAGS := optional
4 |
5 | include $(CLEAR_VARS)
6 |
7 | LOCAL_PACKAGE_NAME := Godly Torch
8 | LOCAL_CERTIFICATE := platform
9 | LOCAL_PROGUARD_ENABLED := disabled
10 | LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
11 |
12 | LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
13 | LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-cardview
14 | LOCAL_STATIC_JAVA_LIBRARIES += android-support-design
15 | LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
16 |
17 | LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java faboptions/src/main/java )
18 | LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res \
19 | $(LOCAL_PATH)/faboptions/src/main/res \
20 | frameworks/support/v7/appcompat/res \
21 | frameworks/support/v7/cardview/res \
22 | frameworks/support/design/res
23 |
24 | LOCAL_AAPT_FLAGS := --auto-add-overlay
25 | LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.cardview:android.support.design
26 |
27 | include $(BUILD_PACKAGE)
28 |
29 | include $(CLEAR_VARS)
30 |
31 | include $(BUILD_MULTI_PREBUILT)
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/MainApplication.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch
19 |
20 | import android.app.Application
21 |
22 | import com.crashlytics.android.core.CrashlyticsCore
23 | import io.fabric.sdk.android.Fabric
24 |
25 | class MainApplication : Application() {
26 |
27 | override fun onCreate() {
28 | super.onCreate()
29 | val fabric = Fabric.Builder(this)
30 | .kits(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
31 | .build()
32 | Fabric.with(fabric)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tile_master.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Dialog/TileDialog.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Dialog
19 |
20 | import android.app.AlertDialog
21 | import android.content.Context
22 | import android.content.DialogInterface
23 |
24 | object TileDialog {
25 | fun getDialog(context: Context, title: String, message: String): AlertDialog {
26 |
27 | val builder = AlertDialog.Builder(context)
28 | builder.setTitle(title)
29 | builder.setMessage(message)
30 | builder.setPositiveButton("OK.") { dialogInterface, _ -> dialogInterface.dismiss() }
31 |
32 | return builder.create()
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Godly Torch
2 | [](https://telegram.me/dndofficial)
3 | [](https://github.com/BRoy98/GodlyTorch)
4 | [](https://github.com/BRoy98/GodlyTorch/blob/master/LICENSE)
5 | []()
6 |
7 | A Torch app that can manage specific LEDs of flash and control intensity.
8 |
9 | **NEEDS ROOT !**
10 |
11 | Features
12 | ------------
13 | 1. Control specific LED of flash as torch for dual tone LED devices.
14 | 2. Control intensity for LED through knobs.
15 | 3. Double tap knobs to toggle LED.
16 | 4. Quick settings tiles for android N and up devices.
17 | 3. More coming soon!
18 |
19 | Credits
20 | ----------
21 | * [**Bishwajyoti Roy**](https://github.com/broy98/)
22 | * [**Rohan Khurana**](https://github.com/rk2810/)
23 |
24 | --------
25 | Thanks to a [**Dušan Uverić**](https://github.com/uvera/) for a poorly written bash script as a motivation to make it into app.
26 |
27 | Contributions
28 | ------------
29 | Feel free to fork this project, work on it and then make a pull request against **DEV** branch. Most of the times We will accept them if they add something valuable to the code.
30 |
31 | Donation
32 | -----------
33 | Will have to think of that! :no_mouth:
34 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Toggle
6 | Intensity
7 |
8 |
9 |
10 |
11 | 1
12 | 2
13 |
14 |
15 |
16 |
17 | 2 steps
18 | 3 steps
19 | 4 steps
20 | 5 steps
21 | 6 steps
22 |
23 |
24 |
25 | 1
26 | 2
27 | 3
28 | 4
29 | 5
30 |
31 |
32 |
33 | 15%
34 | 35%
35 | 50%
36 | 65%
37 | 85%
38 | 100%
39 |
40 |
41 |
42 | 15
43 | 35
44 | 50
45 | 65
46 | 85
47 | 100
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
23 |
24 |
30 |
31 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
25 |
26 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "619050989138",
4 | "firebase_url": "https://goldytorch.firebaseio.com",
5 | "project_id": "goldytorch",
6 | "storage_bucket": "goldytorch.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:619050989138:android:bfeb5aef0b0cfaec",
12 | "android_client_info": {
13 | "package_name": "com.teamdarkness.godlytorch"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "619050989138-9rkm17omm0k8t4aqiguflh47togp7f5v.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.teamdarkness.godlytorch",
22 | "certificate_hash": "42749678b33d4446f1a9d0741686005fb16e91b9"
23 | }
24 | },
25 | {
26 | "client_id": "619050989138-oket2k37hmqchh6kjrphe8ah8ca00nuv.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyCnZcei4C3xSbEx7kgRWym7ki2m3IL8j5g"
33 | }
34 | ],
35 | "services": {
36 | "analytics_service": {
37 | "status": 1
38 | },
39 | "appinvite_service": {
40 | "status": 2,
41 | "other_platform_oauth_client": [
42 | {
43 | "client_id": "619050989138-oket2k37hmqchh6kjrphe8ah8ca00nuv.apps.googleusercontent.com",
44 | "client_type": 3
45 | }
46 | ]
47 | },
48 | "ads_service": {
49 | "status": 2
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Utils/Constrains.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Utils
19 |
20 | object Constrains {
21 |
22 | val PREF_DEVICE_ID = "deviceId"
23 | val PREF_DEVICE = "device"
24 | val PREF_SELECTED_DEVICE = "selectedDevice"
25 | val PREF_DOUBLE_TONE_ENABLED = "doubleTapKnob"
26 | val PREF_IS_DUAL_TONE = "deviceDualTone"
27 | val PREF_SINGLE_FILE_LOCATION = "singleLedFileLocation"
28 | val PREF_WHITE_FILE_LOCATION = "whiteLedFileLocation"
29 | val PREF_YELLOW_FILE_LOCATION = "yellowLedFileLocation"
30 | val PREF_TOGGLE_FILE_LOCATION = "toggleFileLocation"
31 | val PREF_BRIGHTNESS_MAX = "brightnessMax"
32 | val PREF_TILE_WHITE_ON = "tileWhiteIsOn"
33 | val PREF_TILE_YELLOW_ON = "tileYellowIsOn"
34 | val PREF_TILE_MASTER_ON = "tileMasterIsOn"
35 | val PREF_TILE_WHITE_NAME = "tileWhiteName"
36 | val PREF_TILE_YELLOW_NAME = "tileYellowName"
37 | val PREF_TILE_MASTER_NAME = "tileMasterName"
38 | val PREF_TILE_MASTER_STATE = "tileMasterState"
39 | val PREF_TILE_WHITE_STATE = "tileWhiteState"
40 | val PREF_TILE_YELLOW_STATE = "tileYellowState"
41 | val PREF_USE_INTERNAL_BUSYBOX = "useInternalBusybox"
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/telegram.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
15 |
20 |
23 |
27 |
30 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Settings/SelectDevicePreference.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Settings
19 |
20 | import android.content.Context
21 | import android.preference.DialogPreference
22 | import android.support.v7.widget.LinearLayoutManager
23 | import android.support.v7.widget.RecyclerView
24 | import android.util.AttributeSet
25 | import android.view.View
26 | import com.teamdarkness.godlytorch.Utils.Device
27 | import com.teamdarkness.godlytorch.Utils.DeviceList
28 | import com.teamdarkness.godlytorch.Utils.Utils .getDevicePositionById
29 |
30 | class SelectDevicePreference(context: Context, attrs: AttributeSet?) : DialogPreference(context, attrs) {
31 |
32 | private var deviceList = emptyList()
33 |
34 | init {
35 | deviceList = DeviceList.getDevices()
36 | }
37 |
38 | override fun onCreateDialogView(): View {
39 | val deviceView = RecyclerView(context)
40 | deviceView.layoutManager = LinearLayoutManager(context)
41 | deviceView.adapter = DeviceListAdapter(context)
42 |
43 | //Scroll to the selected device
44 | getPersistedString(null)?.let {
45 | deviceView.smoothScrollToPosition(getDevicePositionById(getPersistedString(null)))
46 | }
47 | return deviceView
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 | Godly Torch
20 |
21 | sleep 0.01;
22 | echo %1$s > /sys/class/leds/%2$s;
23 |
24 | Looking for root…
25 | I AM ROOT!
26 | I ain\'t root, gimme ROOT !
27 | Root not found.
28 | Checking device compatibility…
29 | Device Incompatible
30 | %1$s is not officially supported yet.
Feel free to contact us for your device support. We are more than happy to help you! You must provide us proper details about your device to get official support.
You can manually change the device below.
Note: Manual device changing may harm your device.]]>
31 | Contact Us
32 | {faw-code} with {faw-heart} by Team Darkness
33 | No device selected
34 | Select device
35 | Apply
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Settings/SettingsActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Settings
19 |
20 | import android.content.Context
21 | import android.support.v7.app.AppCompatActivity
22 | import android.os.Bundle
23 | import android.support.v7.widget.Toolbar
24 | import com.teamdarkness.godlytorch.R
25 | import uk.co.chrisjenx.calligraphy.CalligraphyConfig
26 | import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper
27 |
28 | class SettingsActivity : AppCompatActivity() {
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | CalligraphyConfig.initDefault(CalligraphyConfig.Builder()
33 | .setDefaultFontPath("fonts/sans_regular.ttf")
34 | .setFontAttrId(R.attr.fontPath)
35 | .build())
36 | setContentView(R.layout.activity_settings)
37 | val toolbar: Toolbar = findViewById(R.id.toolbar)
38 |
39 | setSupportActionBar(toolbar)
40 | supportActionBar?.title = "Settings"
41 | supportActionBar?.setDisplayHomeAsUpEnabled(true)
42 | toolbar.setNavigationOnClickListener { onBackPressed() }
43 |
44 | fragmentManager.beginTransaction().replace(R.id.fragment_container,
45 | PreferenceFragment()).commit()
46 | }
47 |
48 | override fun attachBaseContext(newBase: Context) {
49 | super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase))
50 | }
51 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_td.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Utils/Device.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Utils
19 |
20 | class Device {
21 | var deviceName: String = ""
22 | var deviceId: String = ""
23 | var isDualTone: Boolean = false
24 |
25 | var brightnessMax: Int = 0
26 |
27 | // Only for single tone led devices
28 | var singleLedFileLocation: String = ""
29 |
30 | // Only for dual tone led devices
31 | var whiteLedFileLocation: String = ""
32 | var yellowLedFileLocation: String = ""
33 | var toggleFileLocation: String = ""
34 |
35 | fun setName(deviceName: String = ""): Device {
36 | this.deviceName = deviceName
37 | return this
38 | }
39 |
40 | fun setDeviceId(deviceId: String = ""): Device {
41 | this.deviceId = deviceId
42 | return this
43 | }
44 |
45 | fun isDualTone(isDualTone: Boolean = false): Device {
46 | this.isDualTone = isDualTone
47 | return this
48 | }
49 |
50 | fun setBrightnessMax(brightnessMax: Int = 0): Device {
51 | this.brightnessMax = brightnessMax
52 | return this
53 | }
54 |
55 | fun setSingleLedFileLocation(singleLedFileLocation: String = ""): Device {
56 | this.singleLedFileLocation = singleLedFileLocation
57 | return this
58 | }
59 |
60 | fun setWhiteLedFileLocation(whiteLedFileLocation: String = ""): Device {
61 | this.whiteLedFileLocation = whiteLedFileLocation
62 | return this
63 | }
64 |
65 | fun setYellowLedFileLocation(yellowLedFileLocation: String = ""): Device {
66 | this.yellowLedFileLocation = yellowLedFileLocation
67 | return this
68 | }
69 |
70 | fun setToggleFileLocation(toggleFileLocation: String = ""): Device {
71 | this.toggleFileLocation = toggleFileLocation
72 | return this
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/select_device_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
28 |
29 |
39 |
40 |
52 |
53 |
54 |
55 |
61 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_tile_yellow.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_tile_white.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/preferences_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
34 |
35 |
36 |
37 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
17 |
19 |
20 |
28 |
29 |
30 |
31 |
32 |
33 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
47 |
48 |
49 |
50 |
51 |
56 |
57 |
58 |
59 |
60 |
65 |
66 |
67 |
68 |
69 |
70 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Settings/DeviceListAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Settings
19 |
20 | import android.content.Context
21 | import android.support.v7.widget.RecyclerView
22 | import android.util.Log
23 | import android.view.LayoutInflater
24 | import android.view.View
25 | import android.view.ViewGroup
26 | import android.widget.RadioButton
27 | import android.widget.TextView
28 | import com.teamdarkness.godlytorch.R
29 | import com.teamdarkness.godlytorch.Settings.DeviceListAdapter.DeviceHolder
30 | import com.teamdarkness.godlytorch.Utils.Constrains
31 | import com.teamdarkness.godlytorch.Utils.Device
32 | import com.teamdarkness.godlytorch.Utils.DeviceList
33 | import com.teamdarkness.godlytorch.Utils.Utils
34 | import com.teamdarkness.godlytorch.Utils.Utils.getDevicePositionById
35 | import org.jetbrains.anko.defaultSharedPreferences
36 |
37 | class DeviceListAdapter(val context: Context?) : RecyclerView.Adapter() {
38 |
39 | override fun getItemCount(): Int {
40 | return DeviceList.getDevices().size
41 | }
42 |
43 | override fun onBindViewHolder(holder: DeviceHolder, position: Int) {
44 | holder?.bind(DeviceList.getDevices()[position])
45 | }
46 |
47 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DeviceHolder {
48 | val view = LayoutInflater.from(parent?.context).inflate(R.layout.select_device_layout, parent, false)
49 | return DeviceHolder(view)
50 | }
51 |
52 | inner class DeviceHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
53 |
54 | private val radioButton: RadioButton = itemView.findViewById(R.id.radioButton)
55 | private val deviceName: TextView = itemView.findViewById(R.id.deviceName)
56 | private val deviceType: TextView = itemView.findViewById(R.id.deviceType)
57 |
58 |
59 | fun bind(device: Device) {
60 |
61 | val prefs = context?.defaultSharedPreferences
62 |
63 | // get torch file locations
64 | var selectedDevice = prefs?.getString(Constrains.PREF_SELECTED_DEVICE, "")
65 |
66 | deviceName.text = device.deviceName
67 | deviceType.text = device.deviceId
68 | selectedDevice?.let {
69 | radioButton.isChecked = device.deviceId == selectedDevice
70 | }
71 |
72 | itemView.setOnClickListener {
73 | radioButton.performClick()
74 | }
75 |
76 | radioButton.setOnClickListener {
77 | selectedDevice = prefs?.getString(Constrains.PREF_SELECTED_DEVICE, "")
78 | val lastSelectPosition = getDevicePositionById(selectedDevice)
79 | selectedDevice?.let {
80 | notifyItemChanged(lastSelectPosition)
81 | }
82 | Utils.selectDevice(context, device)
83 | }
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'io.fabric'
4 |
5 | android {
6 | compileSdkVersion 28
7 |
8 | def versionProp = file('version.properties')
9 | if (versionProp.canRead()) {
10 |
11 | // Get properties from version.properties
12 | Properties versionProps = new Properties()
13 | versionProps.load(new FileInputStream(versionProp))
14 |
15 | // Increase versionCode
16 | def code = versionProps['VERSION_CODE'].toInteger() + 1
17 |
18 | // Write new versionCode to version.properties
19 | versionProps['VERSION_CODE'] = code.toString()
20 | versionProps.store(versionProp.newWriter(), null)
21 |
22 | defaultConfig {
23 | applicationId "com.teamdarkness.godlytorch"
24 | minSdkVersion 21
25 | targetSdkVersion 28
26 | versionCode code
27 | versionName "1.4.6"
28 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
29 | }
30 | } else {
31 | throw new GradleException("Could not read version.properties!")
32 | }
33 |
34 | configurations.all {
35 | resolutionStrategy.cacheChangingModulesFor 3600, 'seconds'
36 | }
37 |
38 | signingConfigs {
39 | debug {
40 | storeFile file("../debug-key")
41 | storePassword 'godlytorch'
42 | keyAlias 'godly'
43 | keyPassword 'godlytorch'
44 | }
45 | release {
46 | v1SigningEnabled true
47 | v2SigningEnabled true
48 | }
49 | }
50 |
51 | buildTypes {
52 | release {
53 | minifyEnabled false
54 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
55 | signingConfig signingConfigs.release
56 | }
57 | }
58 |
59 | }
60 |
61 | dependencies {
62 | implementation fileTree(dir: 'libs', include: ['*.jar'])
63 | implementation 'com.github.BRoy98:Croller:master-SNAPSHOT'
64 | implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
65 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
66 | implementation 'com.android.support:design:28.0.0-rc02'
67 | implementation 'com.android.support:support-v4:28.0.0-rc02'
68 | implementation 'com.android.support:cardview-v7:28.0.0-rc02'
69 |
70 | testImplementation 'junit:junit:4.12'
71 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
72 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
73 |
74 | implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
75 | implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
76 | transitive = true
77 | }
78 | implementation "com.mikepenz:iconics-core:3.0.3@aar"
79 | implementation "com.mikepenz:iconics-views:3.0.0@aar"
80 | implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
81 | implementation 'com.mikepenz:fontawesome-typeface:4.7.0.2@aar'
82 | implementation 'com.github.nisrulz:easydeviceinfo-base:2.4.1'
83 | //implementation 'com.github.Stericson:RootTools:5.0'
84 | implementation 'com.google.firebase:firebase-core:16.0.3'
85 | implementation "org.jetbrains.anko:anko-commons:$anko_version"
86 | implementation 'eu.chainfire:libsuperuser:1.0.0.+'
87 | implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
88 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
89 | }
90 | repositories {
91 | mavenCentral()
92 | }
93 |
94 | apply plugin: 'kotlin-android-extensions'
95 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_single_knob.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
27 |
28 |
55 |
56 |
74 |
75 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/torch_big.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
14 |
20 |
23 |
33 |
36 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Fragment/LaunchFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Fragment
19 |
20 |
21 | import android.os.Bundle
22 | import android.os.Handler
23 | import android.support.v4.app.Fragment
24 | import android.view.LayoutInflater
25 | import android.view.View
26 | import android.view.ViewGroup
27 | import android.widget.ProgressBar
28 | import android.widget.TextView
29 |
30 | import com.teamdarkness.godlytorch.R
31 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_IS_DUAL_TONE
32 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SELECTED_DEVICE
33 | import com.teamdarkness.godlytorch.Utils.Utils
34 | import com.teamdarkness.godlytorch.Utils.Utils.askRoot
35 | import org.jetbrains.anko.defaultSharedPreferences
36 |
37 | class LaunchFragment : Fragment() {
38 |
39 | private var selectedDevice = ""
40 | private var isDualTone = true
41 |
42 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
43 | savedInstanceState: Bundle?): View? {
44 | // Inflate the layout for this fragment
45 | val view = inflater.inflate(R.layout.fragment_launch, container, false)
46 |
47 | val logText: TextView = view.findViewById(R.id.logText)
48 | val progressBar: ProgressBar = view.findViewById(R.id.progressBar)
49 |
50 | val prefs = context?.defaultSharedPreferences
51 |
52 | prefs?.let {
53 | // get torch file locations
54 | selectedDevice = prefs.getString(PREF_SELECTED_DEVICE, "")
55 | // check for dual tone device
56 | isDualTone = prefs.getBoolean(PREF_IS_DUAL_TONE, true)
57 | }
58 |
59 | logText.text = getString(R.string.root_check)
60 | progressBar.visibility = View.VISIBLE
61 |
62 |
63 |
64 | Handler().postDelayed({
65 | if (askRoot()) {
66 | logText.text = getString(R.string.check_device)
67 | if (selectedDevice.isNotEmpty())
68 | launchKnobs()
69 | else {
70 | if (Utils.checkSupport(context)) {
71 | launchKnobs()
72 | } else {
73 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
74 | fragTransaction?.let {
75 | fragTransaction.replace(R.id.mainFrame, IncompatibleFragment())
76 | fragTransaction.commit()
77 | }
78 | }
79 | }
80 | } else {
81 | logText.text = getString(R.string.root_denied)
82 | progressBar.visibility = View.INVISIBLE
83 | }
84 | }, 1000)
85 | return view
86 | }
87 |
88 | private fun launchKnobs() {
89 | if (isDualTone) {
90 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
91 | fragTransaction?.let {
92 | fragTransaction.replace(R.id.mainFrame, ThreeKnobFragment())
93 | fragTransaction.commit()
94 | }
95 | } else {
96 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
97 | fragTransaction?.let {
98 | fragTransaction.replace(R.id.mainFrame, SingleKnobFragment())
99 | fragTransaction.commit()
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Settings/PreferenceFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Settings
19 |
20 | import android.content.SharedPreferences
21 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener
22 | import android.os.Bundle
23 | import android.preference.PreferenceFragment
24 | import com.teamdarkness.godlytorch.R
25 | import android.preference.PreferenceManager
26 | import com.teamdarkness.godlytorch.Utils.Utils.getDeviceNameById
27 |
28 |
29 | class PreferenceFragment : PreferenceFragment(), OnSharedPreferenceChangeListener {
30 |
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 | addPreferencesFromResource(R.xml.preferences_main)
34 |
35 | updatePrefs()
36 | }
37 |
38 | override fun onSharedPreferenceChanged(p0: SharedPreferences?, p1: String?) {
39 | updatePrefs()
40 | }
41 |
42 | override fun onResume() {
43 | super.onResume()
44 |
45 | // Register preference change listener
46 | preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
47 | }
48 |
49 | override fun onPause() {
50 | super.onPause()
51 |
52 | // Remove preference change listener
53 | preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
54 | }
55 |
56 | private fun updatePrefs() {
57 | val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
58 |
59 | val selectedDevice = findPreference("selectedDevice")
60 | val tileBehaviour = findPreference("tileBehaviour")
61 | val toggleIntensity = findPreference("toggleIntensity")
62 | val intensitySteps = findPreference("intensitySteps")
63 |
64 | prefs.getString("selectedDevice", null)?.let {
65 | selectedDevice.summary = getDeviceNameById(prefs.getString("selectedDevice", null))
66 | }
67 |
68 | // Set 'Tile Behaviour' summery and update 'Intensity Steps' state
69 | tileBehaviour.summary = when(prefs.getString("tileBehaviour", null)) {
70 | "1" -> {
71 | toggleIntensity.isEnabled = true
72 | intensitySteps.isEnabled = false
73 | "Toggle"
74 | }
75 | "2" -> {
76 | toggleIntensity.isEnabled = false
77 | intensitySteps.isEnabled = true
78 | "Intensity"
79 | }
80 | "3" -> {
81 | toggleIntensity.isEnabled = false
82 | intensitySteps.isEnabled = false
83 | "Popup Dialog"
84 | }
85 | else -> {
86 | toggleIntensity.isEnabled = true
87 | intensitySteps.isEnabled = false
88 | "Toggle"
89 | }
90 | }
91 |
92 | // Set 'Intensity Steps' summery
93 | intensitySteps.summary = when(prefs.getString("intensitySteps", null)) {
94 | "1" -> "2 steps"
95 | "2" -> "3 steps"
96 | "3" -> "4 steps"
97 | "4" -> "5 steps"
98 | "5" -> "6 steps"
99 | else -> "6 steps"
100 | }
101 |
102 | // Set 'Toggle intensity' summery
103 | toggleIntensity.summary = when(prefs.getString("toggleIntensity", null)) {
104 | "15" -> "15%%"
105 | "35" -> "35%%"
106 | "50" -> "50%%"
107 | "65" -> "65%%"
108 | "85" -> "85%%"
109 | "100" -> "100%%"
110 | else -> "100%%"
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_launch.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
24 |
25 |
35 |
36 |
39 |
40 |
53 |
54 |
55 |
56 |
57 |
58 |
65 |
66 |
73 |
74 |
75 |
76 |
82 |
83 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Activity/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Activity
19 |
20 | import android.content.Context
21 | import android.support.v7.app.AppCompatActivity
22 | import android.os.Bundle
23 | import android.util.Log
24 | import com.teamdarkness.godlytorch.Fragment.IncompatibleFragment
25 | import com.teamdarkness.godlytorch.Fragment.LaunchFragment
26 | import com.teamdarkness.godlytorch.Fragment.SingleKnobFragment
27 | import com.teamdarkness.godlytorch.Fragment.ThreeKnobFragment
28 | import com.teamdarkness.godlytorch.R
29 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_IS_DUAL_TONE
30 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SELECTED_DEVICE
31 | import com.teamdarkness.godlytorch.Utils.OnFragmentBackPressListener
32 | import com.teamdarkness.godlytorch.Utils.Utils
33 | import org.jetbrains.anko.defaultSharedPreferences
34 | import uk.co.chrisjenx.calligraphy.CalligraphyConfig
35 | import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper
36 |
37 |
38 |
39 | class MainActivity : AppCompatActivity() {
40 |
41 | private var selectedDevice = ""
42 | private var isDualTone = true
43 | private var paused = false
44 |
45 | override fun onCreate(savedInstanceState: Bundle?) {
46 | super.onCreate(savedInstanceState)
47 | CalligraphyConfig.initDefault(CalligraphyConfig.Builder()
48 | .setDefaultFontPath("fonts/sans_regular.ttf")
49 | .setFontAttrId(R.attr.fontPath)
50 | .build())
51 | setContentView(R.layout.activity_main)
52 |
53 | val fragTransaction = supportFragmentManager.beginTransaction()
54 | fragTransaction.replace(R.id.mainFrame, LaunchFragment())
55 | fragTransaction.commit()
56 | }
57 |
58 | override fun attachBaseContext(newBase: Context) {
59 | super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase))
60 | }
61 |
62 | override fun onPause() {
63 | super.onPause()
64 | paused = true
65 | }
66 |
67 | override fun onResume() {
68 | super.onResume()
69 | if(paused) {
70 | paused = false
71 |
72 | val prefs = defaultSharedPreferences
73 |
74 | prefs.let {
75 | // get torch file locations
76 | selectedDevice = prefs.getString(PREF_SELECTED_DEVICE, "")
77 | // check for dual tone device
78 | isDualTone = prefs.getBoolean(PREF_IS_DUAL_TONE, true)
79 | }
80 | if (selectedDevice.isNotEmpty())
81 | launchKnobs()
82 | else {
83 | if (Utils.checkSupport(this)) {
84 | launchKnobs()
85 | } else {
86 | val fragTransaction = supportFragmentManager?.beginTransaction()
87 | fragTransaction?.let {
88 | fragTransaction.replace(R.id.mainFrame, IncompatibleFragment())
89 | fragTransaction.commit()
90 | }
91 | }
92 | }
93 | }
94 | }
95 |
96 | override fun onBackPressed() {
97 | val fragmentList = supportFragmentManager.fragments
98 | fragmentList?.filterIsInstance()?.forEach {
99 | it.onBackPressed()
100 | }
101 | }
102 |
103 |
104 | private fun launchKnobs() {
105 | if (isDualTone) {
106 | val fragTransaction = supportFragmentManager.beginTransaction()
107 | fragTransaction.replace(R.id.mainFrame, ThreeKnobFragment())
108 | fragTransaction.commit()
109 |
110 | } else {
111 | val fragTransaction = supportFragmentManager.beginTransaction()
112 | fragTransaction.replace(R.id.mainFrame, SingleKnobFragment())
113 | fragTransaction.commit()
114 |
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Fragment/SingleKnobFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Fragment
19 |
20 | import android.app.ProgressDialog
21 | import android.content.Intent
22 | import android.os.Bundle
23 | import android.os.Handler
24 | import android.support.v4.app.ActivityCompat.finishAffinity
25 | import android.support.v4.app.Fragment
26 | import android.util.Log
27 | import android.view.LayoutInflater
28 | import android.view.View
29 | import android.view.ViewGroup
30 | import android.widget.ImageButton
31 | import android.widget.Toast
32 | import com.sdsmdg.harjot.crollerTest.Croller
33 | import com.sdsmdg.harjot.crollerTest.OnCrollerChangeListener
34 | import com.teamdarkness.godlytorch.R
35 | import com.teamdarkness.godlytorch.R.layout
36 | import com.teamdarkness.godlytorch.Settings.SettingsActivity
37 | import com.teamdarkness.godlytorch.Utils.Constrains
38 | import com.teamdarkness.godlytorch.Utils.OnFragmentBackPressListener
39 | import com.teamdarkness.godlytorch.Utils.Utils
40 | import org.jetbrains.anko.defaultSharedPreferences
41 |
42 | class SingleKnobFragment : Fragment(), OnFragmentBackPressListener {
43 |
44 | private var doubleBackToExitPressedOnce = false
45 | private var masterSingleTap = false
46 | private var doubleTapEnabled = false
47 |
48 | private var masterValue = 0
49 | private var masterValueOld = 0
50 |
51 | private var singleLedFileLocation = ""
52 | private var brightnessMax: Int = 0
53 |
54 | private var masterProgress = 1
55 |
56 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
57 | savedInstanceState: Bundle?): View? {
58 | // Inflate the layout for this fragment
59 | val view = inflater.inflate(layout.fragment_single_knob, container, false)
60 |
61 | val masterCroller: Croller = view.findViewById(R.id.masterCroller)
62 | val settingsButton: ImageButton = view.findViewById(R.id.settingsButton)
63 |
64 | // get default preference
65 | val prefs = context?.defaultSharedPreferences
66 |
67 | prefs?.let {
68 | // get torch file location
69 | singleLedFileLocation = prefs.getString(Constrains.PREF_SINGLE_FILE_LOCATION, null)
70 |
71 | doubleTapEnabled = prefs.getBoolean(Constrains.PREF_DOUBLE_TONE_ENABLED, true)
72 |
73 | // get max brightness
74 | brightnessMax = prefs.getInt("brightnessMax", 0)
75 | }
76 |
77 | settingsButton.setOnClickListener {
78 | val intent = Intent(context, SettingsActivity::class.java)
79 | startActivity(intent)
80 | }
81 |
82 | masterCroller.setOnCrollerChangeListener(object : OnCrollerChangeListener {
83 |
84 | override fun onProgressChanged(croller: Croller?, progress: Int) {
85 |
86 | if (progress != masterProgress) {
87 | if (progress == 1) {
88 | masterValue = 0
89 | } else {
90 | masterValue = (brightnessMax / 20) * (progress - 1)
91 | if (masterValue > brightnessMax)
92 | masterValue = brightnessMax
93 | }
94 | masterProgress = progress
95 | }
96 | }
97 |
98 | override fun onTap(croller: Croller?) {
99 | if (doubleTapEnabled) {
100 | if (masterSingleTap) {
101 | if (masterProgress > 1)
102 | masterCroller.progress = 1
103 | else
104 | masterCroller.progress = 20
105 | }
106 | masterSingleTap = true
107 | Handler().postDelayed({ masterSingleTap = false }, 300)
108 | }
109 | }
110 |
111 | override fun onStartTrackingTouch(croller: Croller?) {
112 | }
113 |
114 | override fun onStopTrackingTouch(croller: Croller?) {
115 | if (masterValue != masterValueOld) {
116 | controlLed(masterValue)
117 | masterValueOld = masterValue
118 | }
119 | }
120 | })
121 |
122 | return view
123 | }
124 |
125 | private fun controlLed(singleLed: Int = 0) {
126 |
127 | if (singleLedFileLocation.isEmpty())
128 | return
129 | val command: String = String.format(getString(R.string.cmd_echo), "0", singleLedFileLocation) +
130 | getString(R.string.cmd_sleep) +
131 | String.format(getString(R.string.cmd_echo), singleLed, singleLedFileLocation)
132 | return Utils.runCommand(command)
133 | }
134 |
135 | override fun onBackPressed() {
136 | if (doubleBackToExitPressedOnce) {
137 |
138 | val alertDialogBuilder = ProgressDialog.show(context, "Quit", "Please wait...")
139 | alertDialogBuilder.setCancelable(false)
140 | alertDialogBuilder.setProgressStyle(ProgressDialog.STYLE_SPINNER);
141 | alertDialogBuilder.show()
142 |
143 | controlLed(0)
144 |
145 | Handler().postDelayed({
146 | alertDialogBuilder.dismiss()
147 | activity?.finishAffinity()
148 | }, 300)
149 |
150 | return
151 | }
152 |
153 | this.doubleBackToExitPressedOnce = true
154 | Toast.makeText(context, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()
155 |
156 | Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_three_knob.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
27 |
28 |
53 |
54 |
60 |
61 |
62 |
87 |
88 |
94 |
95 |
120 |
121 |
127 |
128 |
147 |
148 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Fragment/IncompatibleFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Fragment
19 |
20 |
21 | import android.app.AlertDialog
22 | import android.content.ActivityNotFoundException
23 | import android.os.Bundle
24 | import android.os.Handler
25 | import android.support.v4.app.Fragment
26 | import android.view.LayoutInflater
27 | import android.view.View
28 | import android.view.ViewGroup
29 | import android.widget.Button
30 | import android.widget.TextView
31 | import android.widget.Toast
32 |
33 | import com.teamdarkness.godlytorch.R
34 | import com.teamdarkness.godlytorch.Utils.OnFragmentBackPressListener
35 | import com.teamdarkness.godlytorch.Utils.Utils.fromHtml
36 | import com.teamdarkness.godlytorch.Utils.Utils.getDeviceId
37 | import com.teamdarkness.godlytorch.Utils.Utils.getDeviceName
38 | import android.content.Intent
39 | import android.net.Uri
40 | import android.support.constraint.ConstraintLayout
41 | import android.support.design.widget.Snackbar
42 | import android.support.v7.widget.LinearLayoutManager
43 | import android.support.v7.widget.RecyclerView
44 | import com.teamdarkness.godlytorch.Settings.DeviceListAdapter
45 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_IS_DUAL_TONE
46 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SELECTED_DEVICE
47 | import com.teamdarkness.godlytorch.Utils.Utils
48 | import com.teamdarkness.godlytorch.Utils.Utils.getDeviceNameById
49 | import com.teamdarkness.godlytorch.Utils.Utils.getSystemProp
50 | import org.jetbrains.anko.defaultSharedPreferences
51 |
52 |
53 | class IncompatibleFragment : Fragment(), OnFragmentBackPressListener {
54 |
55 | private var doubleBackToExitPressedOnce = false
56 |
57 | private lateinit var root: ConstraintLayout
58 |
59 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
60 | savedInstanceState: Bundle?): View? {
61 | // Inflate the layout for this fragment
62 | val view = inflater.inflate(R.layout.fragment_incompatible, container, false)
63 |
64 | val incompatibleText: TextView = view.findViewById(R.id.incompatibleText)
65 | val contactButton: Button = view.findViewById(R.id.contactButton)
66 | val btnSelectDevice: Button = view.findViewById(R.id.btnSelectDevice)
67 | val btnApplyDevice: Button = view.findViewById(R.id.btnApplyDevice)
68 | val deviceName: TextView = view.findViewById(R.id.deviceName)
69 | root = view.findViewById(R.id.root)
70 |
71 | val prefs = context?.defaultSharedPreferences
72 |
73 | contactButton.setOnClickListener {
74 | val colors = arrayOf("Fill up Google form", "Join Telegram Community")
75 |
76 | val builder = AlertDialog.Builder(context)
77 | builder.setTitle(R.string.contact_us)
78 | builder.setItems(colors) { dialog, which ->
79 | when (which) {
80 | 0 -> {
81 | openLink("https://goo.gl/forms/JnbCfWDh6Q0Yrwy83")
82 | }
83 | 1 -> {
84 | openLink("https://t.me/DNDofficial")
85 | }
86 | }
87 | dialog.dismiss()
88 | }
89 | builder.show()
90 | }
91 |
92 | btnSelectDevice.setOnClickListener {
93 | val builder = AlertDialog.Builder(context)
94 | builder.setTitle("Choose device")
95 | val deviceView = RecyclerView(it.context)
96 | deviceView.layoutManager = LinearLayoutManager(context)
97 | deviceView.adapter = DeviceListAdapter(context)
98 | builder.setView(deviceView)
99 | builder.setNegativeButton("Cancel") { dialogInterface, _ ->
100 | dialogInterface.dismiss()
101 | }
102 | builder.setPositiveButton("Select") { dialogInterface, _ ->
103 | dialogInterface.dismiss()
104 | val selectedDevice = prefs?.getString(PREF_SELECTED_DEVICE, "")
105 | deviceName.text = getDeviceNameById(selectedDevice)
106 | }
107 | builder.show()
108 | }
109 |
110 | btnApplyDevice.setOnClickListener {
111 | val selectedDevice = prefs?.getString(PREF_SELECTED_DEVICE, "")
112 |
113 | selectedDevice?.let {
114 | if (selectedDevice.isNotEmpty())
115 | launchKnobs()
116 | else {
117 | if (Utils.checkSupport(context)) {
118 | launchKnobs()
119 | } else {
120 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
121 | fragTransaction?.let {
122 | fragTransaction.replace(R.id.mainFrame, IncompatibleFragment())
123 | fragTransaction.commit()
124 | }
125 | }
126 | }
127 | }
128 | }
129 |
130 | incompatibleText.text = fromHtml(String.format(getString(R.string.incompatible_message), "${getDeviceName()} (${getDeviceId()})"))
131 |
132 | return view
133 | }
134 |
135 | override fun onBackPressed() {
136 | if (doubleBackToExitPressedOnce) {
137 | activity?.finishAffinity()
138 | return
139 | }
140 |
141 | this.doubleBackToExitPressedOnce = true
142 | Toast.makeText(context, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()
143 |
144 | Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
145 | }
146 |
147 | private fun openLink(link: String) {
148 | val intent = Intent()
149 | intent.action = Intent.ACTION_VIEW
150 | intent.data = Uri.parse(link)
151 | try {
152 | startActivity(intent)
153 | } catch (e: ActivityNotFoundException) {
154 | Snackbar.make(root, "Please install a browser and try again", Snackbar.LENGTH_SHORT).show()
155 | }
156 | }
157 |
158 | private fun launchKnobs() {
159 |
160 | val prefs = context?.defaultSharedPreferences
161 | val isDualTone = prefs?.getBoolean(PREF_IS_DUAL_TONE, true)
162 |
163 | isDualTone?.let {
164 | if (isDualTone) {
165 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
166 | fragTransaction?.let {
167 | fragTransaction.replace(R.id.mainFrame, ThreeKnobFragment())
168 | fragTransaction.commit()
169 | }
170 | } else {
171 | val fragTransaction = activity?.supportFragmentManager?.beginTransaction()
172 | fragTransaction?.let {
173 | fragTransaction.replace(R.id.mainFrame, SingleKnobFragment())
174 | fragTransaction.commit()
175 | }
176 | }
177 | }
178 | }
179 |
180 | }// Required empty public constructor
181 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_incompatible.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
25 |
26 |
36 |
37 |
40 |
41 |
54 |
55 |
67 |
68 |
75 |
76 |
81 |
82 |
102 |
103 |
104 |
105 |
106 |
107 |
113 |
114 |
115 |
116 |
117 |
118 |
124 |
125 |
142 |
143 |
149 |
150 |
159 |
160 |
174 |
175 |
190 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Utils/Utils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Utils
19 |
20 | import android.content.Context
21 | import android.os.Build
22 | import android.support.annotation.NonNull
23 | import android.text.Html
24 | import android.text.Spanned
25 | import android.util.Log
26 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_BRIGHTNESS_MAX
27 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_IS_DUAL_TONE
28 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SELECTED_DEVICE
29 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SINGLE_FILE_LOCATION
30 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TOGGLE_FILE_LOCATION
31 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_WHITE_FILE_LOCATION
32 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_YELLOW_FILE_LOCATION
33 | import eu.chainfire.libsuperuser.Shell
34 | import org.jetbrains.anko.defaultSharedPreferences
35 | import org.jetbrains.anko.doAsync
36 | import java.io.BufferedReader
37 | import java.io.File
38 | import java.io.FileOutputStream
39 | import java.io.IOException
40 | import java.io.InputStream
41 | import java.io.InputStreamReader
42 | import java.io.OutputStream
43 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_USE_INTERNAL_BUSYBOX
44 | import github.nisrulz.easydeviceinfo.base.EasyDeviceMod
45 |
46 |
47 | object Utils {
48 |
49 | fun askRoot(): Boolean = Shell.SU.available()
50 |
51 | fun runCommand(cmd: String = "") {
52 | doAsync {
53 | Shell.SU.run(cmd)
54 | }
55 | }
56 |
57 | private fun readMaxBrightness(ledFile: String = "", context: Context?): String {
58 | val defPref = context?.defaultSharedPreferences
59 | var maxBr = ""
60 | var maxBrightnessList = Shell.SU.run("cat /sys/class/leds/${ledFile.replace("brightness", "max_brightness")}")
61 | for (value in maxBrightnessList) {
62 | maxBr = value
63 | return maxBr
64 | }
65 | // Use internal busybox because busybox is not found
66 | if (maxBr.isEmpty()) {
67 | copyBusyBox(context)
68 | val prefEditor = defPref?.edit()
69 | prefEditor?.putBoolean(PREF_USE_INTERNAL_BUSYBOX, true)
70 | prefEditor?.apply()
71 | maxBrightnessList = Shell.SU.run("${context?.filesDir?.absolutePath}/busybox cat /sys/class/leds/${ledFile.replace("brightness", "max_brightness")}")
72 |
73 | for (value in maxBrightnessList) {
74 | maxBr = value
75 | return maxBr
76 | }
77 | }
78 | return ""
79 | }
80 |
81 | // Check if device is supported
82 | fun checkSupport(context: Context?): Boolean {
83 | val deviceList: ArrayList = DeviceList.getDevices()
84 |
85 | val easyDeviceMod = EasyDeviceMod(context)
86 | val deviceId = easyDeviceMod.device.toLowerCase()
87 |
88 | for ((i, device) in deviceList.withIndex()) {
89 | when {
90 | device.deviceId.toLowerCase().contains(deviceId) -> {
91 | selectDevice(context, device)
92 | return true
93 | }
94 | i == deviceList.size - 1 -> {
95 | return false
96 | }
97 | else -> {
98 | }
99 | }
100 | }
101 |
102 |
103 | //val deviceId = getDeviceId().toLowerCase()
104 | /*val deviceProduct = android.os.Build.PRODUCT.toLowerCase()
105 | var deviceProductSplit = ""
106 |
107 | if (deviceProduct.contains("_")) {
108 | val product = deviceProduct.split("_")
109 | deviceProductSplit = product[1]
110 | }
111 |
112 | for ((i, device) in deviceList.withIndex()) {
113 | when {
114 | device.deviceId.toLowerCase().contains(deviceId) -> {
115 | selectDevice(context, device)
116 | return true
117 | }
118 | device.deviceId.toLowerCase().contains(deviceProduct) -> {
119 | selectDevice(context, device)
120 | return true
121 | }
122 | deviceProductSplit.isNotEmpty() && device.deviceId.toLowerCase().contains(deviceProductSplit) -> {
123 | selectDevice(context, device)
124 | return true
125 | }
126 | i == deviceList.size - 1 -> {
127 | return false
128 | }
129 | else -> {
130 | }
131 | }
132 | }*/
133 | return false
134 | }
135 |
136 | fun readDevice(context: Context): Device? {
137 | val device = Device()
138 | val defPref = context.defaultSharedPreferences
139 |
140 | defPref.getString(PREF_SELECTED_DEVICE, null)?.let {
141 | device.deviceId = defPref.getString(PREF_SELECTED_DEVICE, "")
142 | device.isDualTone = defPref.getBoolean(PREF_IS_DUAL_TONE, false)
143 | device.whiteLedFileLocation = defPref.getString(PREF_WHITE_FILE_LOCATION, "")
144 | device.yellowLedFileLocation = defPref.getString(PREF_YELLOW_FILE_LOCATION, "")
145 | device.toggleFileLocation = defPref.getString(PREF_TOGGLE_FILE_LOCATION, "")
146 | device.singleLedFileLocation = defPref.getString(PREF_SINGLE_FILE_LOCATION, "")
147 | return device
148 | }
149 | return null
150 | }
151 |
152 | fun selectDevice(context: Context?, device: Device?): Boolean {
153 | device?.let {
154 | val defPref = context?.defaultSharedPreferences
155 |
156 | defPref?.let {
157 |
158 | try {
159 | val prefEditor = defPref.edit()
160 | prefEditor.putString(PREF_SELECTED_DEVICE, device.deviceId)
161 | prefEditor.putBoolean(PREF_IS_DUAL_TONE, device.isDualTone)
162 | if (device.isDualTone) {
163 | prefEditor.putString(PREF_WHITE_FILE_LOCATION, device.whiteLedFileLocation)
164 | prefEditor.putString(PREF_YELLOW_FILE_LOCATION, device.yellowLedFileLocation)
165 | prefEditor.putString(PREF_TOGGLE_FILE_LOCATION, device.toggleFileLocation)
166 | prefEditor.putInt(PREF_BRIGHTNESS_MAX, readMaxBrightness(device.whiteLedFileLocation, context).toInt())
167 | } else {
168 | prefEditor.putString(PREF_SINGLE_FILE_LOCATION, device.singleLedFileLocation)
169 | prefEditor.putInt(PREF_BRIGHTNESS_MAX, readMaxBrightness(device.singleLedFileLocation, context).toInt())
170 | prefEditor.putString(PREF_WHITE_FILE_LOCATION, "")
171 | prefEditor.putString(PREF_YELLOW_FILE_LOCATION, "")
172 | prefEditor.putString(PREF_TOGGLE_FILE_LOCATION, "")
173 | }
174 | prefEditor.apply()
175 | } catch (e: Exception) {
176 | e.printStackTrace()
177 | return false
178 | }
179 | }
180 | }
181 | return true
182 | }
183 |
184 | fun getDeviceId(): String = getSystemProp("ro.product.device")
185 |
186 | fun getDeviceName(): String = getSystemProp("ro.product.model")
187 |
188 | fun getSystemProp(@NonNull propName: String): String {
189 | var line = ""
190 | try {
191 | val process: Process = Runtime.getRuntime().exec("getprop $propName")
192 | val reader = BufferedReader(InputStreamReader(process.inputStream))
193 | line = reader.readLine()
194 | process.destroy()
195 | } catch (e: Exception) {
196 | e.printStackTrace()
197 | }
198 | return line
199 | }
200 |
201 | @NonNull
202 | fun fromHtml(@NonNull source: String): Spanned {
203 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
204 | Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY)
205 | } else Html.fromHtml(source)
206 | }
207 |
208 | fun getSingleFileLocationById(deviceId: String): String? {
209 | return DeviceList.getDevices()
210 | .firstOrNull { it.deviceId == deviceId }
211 | ?.singleLedFileLocation
212 | }
213 |
214 | fun getWhiteLedFileLocationById(deviceId: String): String? {
215 | return DeviceList.getDevices()
216 | .firstOrNull { it.deviceId == deviceId }
217 | ?.whiteLedFileLocation
218 | }
219 |
220 | fun getYellowLedFileLocationById(deviceId: String): String? {
221 | return DeviceList.getDevices()
222 | .firstOrNull { it.deviceId == deviceId }
223 | ?.yellowLedFileLocation
224 | }
225 |
226 | fun getToggleFileLocationById(deviceId: String): String? {
227 | return DeviceList.getDevices()
228 | .firstOrNull { it.deviceId == deviceId }
229 | ?.toggleFileLocation
230 | }
231 |
232 | fun getDeviceNameById(deviceId: String?): String {
233 | return DeviceList.getDevices()
234 | .firstOrNull { it.deviceId == deviceId }
235 | ?.deviceName
236 | ?: ""
237 | }
238 |
239 | fun getDevicePositionById(deviceId: String?): Int {
240 | for ((i, dev) in DeviceList.getDevices().withIndex()) {
241 | if (dev.deviceId == deviceId)
242 | return i
243 | }
244 | return 0
245 | }
246 |
247 | fun getDeviceById(deviceId: String): Device? {
248 | return DeviceList.getDevices().firstOrNull { it.deviceId == deviceId }
249 | }
250 |
251 |
252 | fun copyBusyBox(context: Context?) {
253 | context?.let {
254 | val assetManager = context.assets
255 | val inStream: InputStream?
256 | val out: OutputStream?
257 | try {
258 | inStream = assetManager.open("binary/busybox") //binary/busybox
259 |
260 | val outDir = context.filesDir?.absolutePath
261 |
262 | val outFile = File(outDir, "busybox")
263 |
264 | out = FileOutputStream(outFile)
265 | copyFile(inStream, out, context)
266 | } catch (e: Exception) {
267 | Log.e("Utils", "Failed to copy asset file", e)
268 | }
269 | }
270 | }
271 |
272 | @Throws(IOException::class)
273 | private fun copyFile(inStream: InputStream, out: OutputStream, context: Context?) {
274 | try {
275 | val buffer = ByteArray(1024)
276 | var read = inStream.read(buffer)
277 | while (read != -1) {
278 | out.write(buffer, 0, read)
279 | read = inStream.read(buffer)
280 | }
281 | val file = File(context?.filesDir?.absolutePath + "/busybox")
282 | file.setExecutable(true)
283 | out.flush()
284 | out.close()
285 | inStream.close()
286 | } catch (e: Exception) {
287 | e.printStackTrace()
288 | }
289 |
290 | }
291 | }
292 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Fragment/ThreeKnobFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Fragment
19 |
20 | import android.app.ProgressDialog
21 | import android.content.Intent
22 | import android.os.Bundle
23 | import android.os.Handler
24 | import android.support.v4.app.Fragment
25 | import android.view.LayoutInflater
26 | import android.view.View
27 | import android.view.ViewGroup
28 | import android.widget.ImageButton
29 | import android.widget.Toast
30 | import com.sdsmdg.harjot.crollerTest.Croller
31 | import com.sdsmdg.harjot.crollerTest.OnCrollerChangeListener
32 |
33 | import com.teamdarkness.godlytorch.R
34 | import com.teamdarkness.godlytorch.Settings.SettingsActivity
35 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_DOUBLE_TONE_ENABLED
36 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TOGGLE_FILE_LOCATION
37 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_WHITE_FILE_LOCATION
38 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_YELLOW_FILE_LOCATION
39 | import com.teamdarkness.godlytorch.Utils.OnFragmentBackPressListener
40 | import com.teamdarkness.godlytorch.Utils.Utils
41 | import org.jetbrains.anko.defaultSharedPreferences
42 |
43 | class ThreeKnobFragment : Fragment(), OnFragmentBackPressListener {
44 |
45 | private var doubleBackToExitPressedOnce = false
46 | private var whiteSingleTap = false
47 | private var yellowSingleTap = false
48 | private var masterSingleTap = false
49 |
50 | private var whiteOn = false
51 | private var yellowOn = false
52 | private var doubleTapEnabled = false
53 |
54 | private var yellowValue = 0
55 | private var whiteValue = 0
56 | private var yellowValueOld = 0
57 | private var whiteValueOld = 0
58 |
59 | private var whiteLedFileLocation = ""
60 | private var yellowLedFileLocation = ""
61 | private var toggleFileLocation = ""
62 | private var brightnessMax = 0
63 |
64 | private var yellowProgress = 1
65 | private var whiteProgress = 1
66 | private var masterProgress = 1
67 |
68 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
69 | savedInstanceState: Bundle?): View? {
70 | // Inflate the layout for this fragment
71 | val view = inflater.inflate(R.layout.fragment_three_knob, container, false)
72 |
73 | val masterCroller: Croller = view.findViewById(R.id.bothCroller)
74 | val whiteCroller: Croller = view.findViewById(R.id.whiteCroller)
75 | val yellowCroller: Croller = view.findViewById(R.id.yellowCroller)
76 | val settingsButton: ImageButton = view.findViewById(R.id.settingsButton)
77 |
78 | val prefs = context?.defaultSharedPreferences
79 |
80 | prefs?.let {
81 | // get torch file location
82 | whiteLedFileLocation = prefs.getString(PREF_WHITE_FILE_LOCATION, null)
83 | yellowLedFileLocation = prefs.getString(PREF_YELLOW_FILE_LOCATION, null)
84 | toggleFileLocation = prefs.getString(PREF_TOGGLE_FILE_LOCATION, null)
85 |
86 | doubleTapEnabled = prefs.getBoolean(PREF_DOUBLE_TONE_ENABLED, true)
87 |
88 | // get max brightness
89 | brightnessMax = prefs.getInt("brightnessMax", 0)
90 | }
91 |
92 | settingsButton.setOnClickListener {
93 | val intent = Intent(context, SettingsActivity::class.java)
94 | startActivity(intent)
95 | }
96 | masterCroller.setOnCrollerChangeListener(object : OnCrollerChangeListener {
97 |
98 | override fun onProgressChanged(croller: Croller?, progress: Int) {
99 |
100 | if (progress != masterProgress) {
101 | if (progress == 1) {
102 | whiteCroller.isEnabled = true
103 | yellowCroller.isEnabled = true
104 | whiteValue = 0
105 | yellowValue = 0
106 | whiteOn = false
107 | yellowOn = false
108 | } else {
109 | whiteCroller.isEnabled = false
110 | yellowCroller.isEnabled = false
111 | yellowOn = true
112 | whiteOn = true
113 | whiteValue = (brightnessMax / 20) * (progress - 1)
114 | if (whiteValue > brightnessMax)
115 | whiteValue = brightnessMax
116 | yellowValue = (brightnessMax / 20) * (progress - 1)
117 | if (yellowValue > brightnessMax)
118 | yellowValue = brightnessMax
119 | }
120 | masterProgress = progress
121 | }
122 | }
123 |
124 | override fun onTap(croller: Croller?) {
125 | if (doubleTapEnabled) {
126 | if (masterSingleTap) {
127 | if (masterProgress > 1)
128 | masterCroller.progress = 1
129 | else
130 | masterCroller.progress = 20
131 | }
132 | masterSingleTap = true
133 | Handler().postDelayed({ masterSingleTap = false }, 300)
134 | }
135 | }
136 |
137 | override fun onStartTrackingTouch(croller: Croller?) {
138 | }
139 |
140 | override fun onStopTrackingTouch(croller: Croller?) {
141 | if (whiteValue != whiteValueOld || yellowValue != yellowValueOld) {
142 | if (yellowOn)
143 | controlLed(whiteValue, yellowValue, true)
144 | else
145 | controlLed(whiteValue, yellowValue, false)
146 | whiteValueOld = whiteValue
147 | yellowValueOld = yellowValue
148 | }
149 | }
150 | })
151 |
152 | whiteCroller.setOnCrollerChangeListener(object : OnCrollerChangeListener {
153 | override fun onProgressChanged(croller: Croller?, progress: Int) {
154 | if (progress != whiteProgress) {
155 | if (progress == 1) {
156 | if (yellowCroller.progress == 1)
157 | masterCroller.isEnabled = true
158 | whiteValue = 0
159 | whiteOn = false
160 | } else {
161 | masterCroller.isEnabled = false
162 | whiteOn = true
163 | whiteValue = (255 / 20) * (progress - 1)
164 | if (whiteValue > 225)
165 | whiteValue = 225
166 | }
167 | whiteProgress = progress
168 | }
169 | }
170 |
171 | override fun onTap(croller: Croller?) {
172 | if (doubleTapEnabled) {
173 | if (whiteSingleTap) {
174 | if (whiteOn)
175 | whiteCroller.progress = 1
176 | else
177 | whiteCroller.progress = 20
178 | }
179 | whiteSingleTap = true
180 | Handler().postDelayed({ whiteSingleTap = false }, 300)
181 | }
182 | }
183 |
184 | override fun onStartTrackingTouch(croller: Croller?) {
185 | }
186 |
187 | override fun onStopTrackingTouch(croller: Croller?) {
188 | if (whiteValue != whiteValueOld) {
189 | when {
190 | whiteOn || yellowOn -> controlLed(whiteValue, yellowValue, true)
191 | else -> controlLed(whiteValue, yellowValue, false)
192 | }
193 | whiteValueOld = whiteValue
194 | }
195 | }
196 | })
197 |
198 | yellowCroller.setOnCrollerChangeListener(object : OnCrollerChangeListener {
199 | override fun onProgressChanged(croller: Croller?, progress: Int) {
200 | if (progress != yellowProgress) {
201 | if (progress == 1) {
202 | if (whiteCroller.progress == 1)
203 | masterCroller.isEnabled = true
204 | yellowValue = 0
205 | yellowOn = false
206 | } else {
207 | masterCroller.isEnabled = false
208 | yellowOn = true
209 | yellowValue = (255 / 20) * (progress - 1)
210 | if (yellowValue > 225)
211 | yellowValue = 225
212 | }
213 | yellowProgress = progress
214 | }
215 | }
216 |
217 | override fun onTap(croller: Croller?) {
218 | if (doubleTapEnabled) {
219 | if (yellowSingleTap) {
220 | if (yellowOn)
221 | yellowCroller.progress = 1
222 | else
223 | yellowCroller.progress = 20
224 | }
225 | yellowSingleTap = true
226 | Handler().postDelayed({ yellowSingleTap = false }, 300)
227 | }
228 | }
229 |
230 | override fun onStartTrackingTouch(croller: Croller?) {
231 | }
232 |
233 | override fun onStopTrackingTouch(croller: Croller?) {
234 | if (yellowValue != yellowValueOld) {
235 | when {
236 | yellowOn || whiteOn -> controlLed(whiteValue, yellowValue, true)
237 | else -> controlLed(whiteValue, yellowValue, false)
238 | }
239 | yellowValueOld = yellowValue
240 | }
241 | }
242 | })
243 |
244 | return view
245 | }
246 |
247 | private fun controlLed(whiteLed: Int = 0, yellowLed: Int = 0, torchState: Boolean = false) {
248 | if (whiteLedFileLocation.isEmpty() || yellowLedFileLocation.isEmpty() || toggleFileLocation.isEmpty())
249 | return
250 | var torch = 0
251 | if (torchState)
252 | torch = this.brightnessMax
253 |
254 | val command: String = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
255 | getString(R.string.cmd_sleep) +
256 | String.format(getString(R.string.cmd_echo), whiteLed, whiteLedFileLocation) +
257 | String.format(getString(R.string.cmd_echo), yellowLed, yellowLedFileLocation) +
258 | String.format(getString(R.string.cmd_echo), torch, toggleFileLocation)
259 | return Utils.runCommand(command)
260 | }
261 |
262 | override fun onBackPressed() {
263 | if (doubleBackToExitPressedOnce) {
264 |
265 | val alertDialogBuilder = ProgressDialog.show(context, "Quit", "Please wait...")
266 | alertDialogBuilder.setCancelable(false)
267 | alertDialogBuilder.setProgressStyle(ProgressDialog.STYLE_SPINNER);
268 | alertDialogBuilder.show()
269 |
270 | controlLed(0)
271 |
272 | Handler().postDelayed({
273 | alertDialogBuilder.dismiss()
274 | activity?.finishAffinity()
275 | }, 300)
276 |
277 | return
278 | }
279 |
280 | this.doubleBackToExitPressedOnce = true
281 | Toast.makeText(context, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()
282 |
283 | Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Utils/DeviceList.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Utils
19 |
20 | import java.util.ArrayList
21 |
22 | object DeviceList {
23 |
24 | private var deviceList: ArrayList = java.util.ArrayList()
25 |
26 | fun getDevices(): ArrayList {
27 | deviceList.clear()
28 | // HTC
29 | deviceList.add(
30 | Device().setName("HTC 10")
31 | .setDeviceId("pme")
32 | .isDualTone(true)
33 | .setYellowLedFileLocation("led:torch_1/brightness")
34 | .setWhiteLedFileLocation("led:torch_0/brightness")
35 | .setToggleFileLocation("led:switch/brightness")
36 | )
37 | // LeEco
38 | deviceList.add(
39 | Device().setName("LeEco Le 2")
40 | .setDeviceId("le_s2")
41 | .isDualTone(true)
42 | .setYellowLedFileLocation("led:torch_0/brightness")
43 | .setWhiteLedFileLocation("led:torch_1/brightness")
44 | .setToggleFileLocation("led:switch/brightness")
45 | )
46 | deviceList.add(
47 | Device().setName("LeEco LePro 3")
48 | .setDeviceId("le_zl1")
49 | .isDualTone(true)
50 | .setYellowLedFileLocation("led:torch_0/brightness")
51 | .setWhiteLedFileLocation("led:torch_1/brightness")
52 | .setToggleFileLocation("led:switch/brightness")
53 | )
54 | // Lenovo
55 | deviceList.add(
56 | Device().setName("Lenovo P2 (kuntao)")
57 | .setDeviceId("kuntao")
58 | .isDualTone(true)
59 | .setYellowLedFileLocation("led:torch_0/brightness")
60 | .setWhiteLedFileLocation("led:torch_1/brightness")
61 | .setToggleFileLocation("led:switch/brightness")
62 | )
63 | deviceList.add(
64 | Device().setName("Lenovo P2 (p2a42)")
65 | .setDeviceId("p2a42")
66 | .isDualTone(true)
67 | .setYellowLedFileLocation("led:torch_0/brightness")
68 | .setWhiteLedFileLocation("led:torch_1/brightness")
69 | .setToggleFileLocation("led:switch/brightness")
70 | )
71 | deviceList.add(
72 | Device().setName("Lenovo P2 (p2c72)")
73 | .setDeviceId("p2c72")
74 | .isDualTone(true)
75 | .setYellowLedFileLocation("led:torch_0/brightness")
76 | .setWhiteLedFileLocation("led:torch_1/brightness")
77 | .setToggleFileLocation("led:switch/brightness")
78 | )
79 | deviceList.add(
80 | Device().setName("Lenovo P2 (p2)")
81 | .setDeviceId("p2")
82 | .isDualTone(true)
83 | .setYellowLedFileLocation("led:torch_0/brightness")
84 | .setWhiteLedFileLocation("led:torch_1/brightness")
85 | .setToggleFileLocation("led:switch/brightness")
86 | )
87 | deviceList.add(
88 | Device().setName("Lenovo K53")
89 | .setDeviceId("karatep")
90 | .isDualTone(true)
91 | .setYellowLedFileLocation("led:torch_0/brightness")
92 | .setWhiteLedFileLocation("led:torch_1/brightness")
93 | .setToggleFileLocation("led:switch/brightness")
94 | )
95 | deviceList.add(
96 | Device().setName("Lenovo Vibe P1 Turbo")
97 | .setDeviceId("passion")
98 | .isDualTone(true)
99 | .setYellowLedFileLocation("lenovo_torch1/brightness")
100 | .setWhiteLedFileLocation("lenovo_torch0/brightness")
101 | .setToggleFileLocation("dummy") // dummy because it is not required
102 | )
103 | deviceList.add(
104 | Device().setName("Lenovo A6000")
105 | .setDeviceId("a6000")
106 | .isDualTone(false)
107 | .setSingleLedFileLocation("flashlight/brightness")
108 | )
109 | // Xiaomi
110 | deviceList.add(
111 | Device().setName("Mi 5")
112 | .setDeviceId("gemini")
113 | .isDualTone(true)
114 | .setYellowLedFileLocation("led:torch_0/brightness")
115 | .setWhiteLedFileLocation("led:torch_1/brightness")
116 | .setToggleFileLocation("led:switch/brightness")
117 | )
118 | deviceList.add(
119 | Device().setName("Mi 6")
120 | .setDeviceId("sagit")
121 | .isDualTone(true)
122 | .setYellowLedFileLocation("led:torch_0/brightness")
123 | .setWhiteLedFileLocation("led:torch_1/brightness")
124 | .setToggleFileLocation("led:switch_0/brightness")
125 | )
126 | deviceList.add(
127 | Device().setName("Mi 5s Plus")
128 | .setDeviceId("natrium")
129 | .isDualTone(true)
130 | .setYellowLedFileLocation("led:torch_0/brightness")
131 | .setWhiteLedFileLocation("led:torch_1/brightness")
132 | .setToggleFileLocation("led:switch/brightness")
133 | )
134 | deviceList.add(
135 | Device().setName("Mi 5s")
136 | .setDeviceId("capricorn")
137 | .isDualTone(true)
138 | .setYellowLedFileLocation("led:torch_0/brightness")
139 | .setWhiteLedFileLocation("led:torch_1/brightness")
140 | .setToggleFileLocation("led:switch/brightness")
141 | )
142 | deviceList.add(
143 | Device().setName("Mi A1")
144 | .setDeviceId("tissot_sprout")
145 | .isDualTone(true)
146 | .setYellowLedFileLocation("led:torch_1/brightness")
147 | .setWhiteLedFileLocation("led:torch_0/brightness")
148 | .setToggleFileLocation("led:switch/brightness")
149 | )
150 | deviceList.add(
151 | Device().setName("Mi Max (hydrogen)")
152 | .setDeviceId("hydrogen")
153 | .isDualTone(true)
154 | .setYellowLedFileLocation("led:torch_1/brightness")
155 | .setWhiteLedFileLocation("led:torch_0/brightness")
156 | .setToggleFileLocation("led:switch/brightness")
157 | )
158 | deviceList.add(
159 | Device().setName("Mi Note 3")
160 | .setDeviceId("jason")
161 | .isDualTone(true)
162 | .setYellowLedFileLocation("led:torch_0/brightness")
163 | .setWhiteLedFileLocation("led:torch_1/brightness")
164 | .setToggleFileLocation("led:switch_0/brightness")
165 | )
166 | // Motorola
167 | deviceList.add(
168 | Device().setName("Moto G5 Plus")
169 | .setDeviceId("potter")
170 | .isDualTone(true)
171 | .setYellowLedFileLocation("led:torch_1/brightness")
172 | .setWhiteLedFileLocation("led:torch_0/brightness")
173 | .setToggleFileLocation("led:switch/brightness")
174 | )
175 | deviceList.add(
176 | Device().setName("Moto G5")
177 | .setDeviceId("cedric")
178 | .isDualTone(true)
179 | .setYellowLedFileLocation("led:torch_0/brightness")
180 | .setWhiteLedFileLocation("led:torch_1/brightness")
181 | .setToggleFileLocation("led:switch/brightness")
182 | )
183 | deviceList.add(
184 | Device().setName("Moto G4")
185 | .setDeviceId("athene")
186 | .isDualTone(true)
187 | .setYellowLedFileLocation("led:torch_0/brightness")
188 | .setWhiteLedFileLocation("led:torch_1/brightness")
189 | .setToggleFileLocation("led:switch/brightness")
190 | )
191 | deviceList.add(
192 | Device().setName("Moto G4 Plus")
193 | .setDeviceId("athene_f")
194 | .isDualTone(true)
195 | .setYellowLedFileLocation("led:torch_0/brightness")
196 | .setWhiteLedFileLocation("led:torch_1/brightness")
197 | .setToggleFileLocation("led:switch/brightness")
198 | )
199 | deviceList.add(
200 | Device().setName("Moto G5S Plus")
201 | .setDeviceId("sanders")
202 | .isDualTone(true)
203 | .setYellowLedFileLocation("led:torch_1/brightness")
204 | .setWhiteLedFileLocation("led:torch_0/brightness")
205 | .setToggleFileLocation("led:switch/brightness")
206 | )
207 | //Nexus
208 | deviceList.add(
209 | Device().setName("Nexus 5X")
210 | .setDeviceId("bullhead")
211 | .isDualTone(true)
212 | .setYellowLedFileLocation("led:torch_1/brightness")
213 | .setWhiteLedFileLocation("led:torch_0/brightness")
214 | .setToggleFileLocation("led:switch/brightness")
215 | )
216 | deviceList.add(
217 | Device().setName("Nexus 6P")
218 | .setDeviceId("angler")
219 | .isDualTone(true)
220 | .setYellowLedFileLocation("led:torch_1/brightness")
221 | .setWhiteLedFileLocation("led:torch_0/brightness")
222 | .setToggleFileLocation("led:switch/brightness")
223 | )
224 | // Oneplus
225 | deviceList.add(
226 | Device().setName("OnePlus One")
227 | .setDeviceId("bacon")
228 | .isDualTone(false)
229 | .setSingleLedFileLocation("torch-light/brightness")
230 | )
231 | deviceList.add(
232 | Device().setName("OnePlus 2")
233 | .setDeviceId("OnePlus2")
234 | .isDualTone(true)
235 | .setYellowLedFileLocation("led:torch_0/brightness")
236 | .setWhiteLedFileLocation("led:torch_1/brightness")
237 | .setToggleFileLocation("dummy")
238 | )
239 | deviceList.add(
240 | Device().setName("OnePlus 3")
241 | .setDeviceId("oneplus3")
242 | .isDualTone(true)
243 | .setYellowLedFileLocation("led:torch_0/brightness")
244 | .setWhiteLedFileLocation("led:torch_1/brightness")
245 | .setToggleFileLocation("led:switch/brightness")
246 | )
247 | deviceList.add(
248 | Device().setName("OnePlus 5")
249 | .setDeviceId("OnePlus5")
250 | .isDualTone(true)
251 | .setYellowLedFileLocation("led:torch_0/brightness")
252 | .setWhiteLedFileLocation("led:torch_1/brightness")
253 | .setToggleFileLocation("led:switch_0/brightness")
254 | )
255 | deviceList.add(
256 | Device().setName("OnePlus 5t")
257 | .setDeviceId("OnePlus5t")
258 | .isDualTone(true)
259 | .setYellowLedFileLocation("led:torch_0/brightness")
260 | .setWhiteLedFileLocation("led:torch_1/brightness")
261 | .setToggleFileLocation("led:switch_0/brightness")
262 | )
263 | // PIXEL
264 | deviceList.add(
265 | Device().setName("Pixel 2 XL")
266 | .setDeviceId("taimen")
267 | .isDualTone(true)
268 | .setYellowLedFileLocation("led:torch_0/brightness")
269 | .setWhiteLedFileLocation("led:torch_1/brightness")
270 | .setToggleFileLocation("led:switch_0/brightness")
271 | )
272 | //Redmi series
273 | deviceList.add(
274 | Device().setName("Redmi 3S")
275 | .setDeviceId("land")
276 | .isDualTone(false)
277 | //.setYellowLedFileLocation("led:torch_0/brightness")
278 | //.setWhiteLedFileLocation("led:torch_1/brightness")
279 | .setToggleFileLocation("led:switch/brightness")
280 | )
281 | deviceList.add(
282 | Device().setName("Redmi 4A")
283 | .setDeviceId("rolex")
284 | .isDualTone(false)
285 | .setSingleLedFileLocation("flashlight/brightness")
286 | )
287 |
288 | deviceList.add(
289 | Device().setName("Redmi Note 3")
290 | .setDeviceId("kenzo")
291 | .isDualTone(false)
292 | .setSingleLedFileLocation("flashlight/brightness")
293 | )
294 | deviceList.add(
295 | Device().setName("Redmi Note 4")
296 | .setDeviceId("mido")
297 | .isDualTone(true)
298 | .setYellowLedFileLocation("led:torch_1/brightness")
299 | .setWhiteLedFileLocation("led:torch_0/brightness")
300 | .setToggleFileLocation("led:switch/brightness")
301 | )
302 | deviceList.add(
303 | Device().setName("Redmi Note 5 Pro")
304 | .setDeviceId("whyred")
305 | .isDualTone(true)
306 | .setYellowLedFileLocation("led:torch_1/brightness")
307 | .setWhiteLedFileLocation("led:torch_0/brightness")
308 | .setToggleFileLocation("led:switch_0/brightness")
309 | )
310 | // Sony
311 | deviceList.add(
312 | Device().setName("Xperia M2 Dual")
313 | .setDeviceId("d2302")
314 | .isDualTone(false)
315 | .setSingleLedFileLocation("torch-light/brightness")
316 | )
317 | // YU
318 | deviceList.add(
319 | Device().setName("YU Yureka")
320 | .setDeviceId("yureka")
321 | .isDualTone(false)
322 | .setSingleLedFileLocation("torch-light0/brightness")
323 | )
324 |
325 | // ZUK
326 | deviceList.add(
327 | Device().setName("ZUK Z1")
328 | .setDeviceId("z1")
329 | .isDualTone(false)
330 | .setSingleLedFileLocation("led:torch_0/brightness")
331 | )
332 |
333 | // Asus
334 | deviceList.add(
335 | Device().setName("Asus Zenfone Max")
336 | .setDeviceId("ASUS_Z010D")
337 | .isDualTone(false)
338 | .setSingleLedFileLocation("torch-light0/brightness")
339 | )
340 |
341 | return deviceList
342 | }
343 | }
344 |
--------------------------------------------------------------------------------
/app/src/main/java/com/teamdarkness/godlytorch/Service/WhiteTileService.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Godly Torch.
3 | *
4 | * Godly Torch 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 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Godly Torch 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
15 | * along with Godly Torch. If not, see .
16 | */
17 |
18 | package com.teamdarkness.godlytorch.Service
19 |
20 | import android.annotation.TargetApi
21 | import android.service.quicksettings.TileService
22 | import android.os.Build
23 | import android.service.quicksettings.Tile
24 | import com.teamdarkness.godlytorch.Utils.Utils.askRoot
25 | import com.teamdarkness.godlytorch.Dialog.TileDialog
26 | import com.teamdarkness.godlytorch.R
27 | import com.teamdarkness.godlytorch.Utils.Utils.checkSupport
28 | import com.teamdarkness.godlytorch.Utils.Utils.runCommand
29 | import com.google.firebase.analytics.FirebaseAnalytics
30 | import android.os.Bundle
31 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_BRIGHTNESS_MAX
32 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_IS_DUAL_TONE
33 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_SELECTED_DEVICE
34 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TILE_MASTER_ON
35 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TILE_WHITE_NAME
36 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TILE_WHITE_ON
37 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TILE_WHITE_STATE
38 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TILE_YELLOW_ON
39 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_TOGGLE_FILE_LOCATION
40 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_WHITE_FILE_LOCATION
41 | import com.teamdarkness.godlytorch.Utils.Constrains.PREF_YELLOW_FILE_LOCATION
42 | import com.teamdarkness.godlytorch.Utils.Utils
43 | import org.jetbrains.anko.defaultSharedPreferences
44 |
45 | @TargetApi(Build.VERSION_CODES.N)
46 | class WhiteTileService : TileService() {
47 |
48 | private val TILE_STATUS = "whiteTileStatus"
49 |
50 | override fun onStartListening() {
51 | super.onStartListening()
52 | val prefs = applicationContext.defaultSharedPreferences
53 | // get torch file locations
54 | val selectedDevice = prefs.getString(PREF_SELECTED_DEVICE, "")
55 | // check for dual tone device
56 | val isDualTone = prefs.getBoolean(PREF_IS_DUAL_TONE, true)
57 |
58 | // show no device selected warning
59 | if (selectedDevice.isEmpty()) {
60 | qsTile.label = "White Torch Unsupported"
61 | qsTile.state = Tile.STATE_UNAVAILABLE
62 | return
63 | }
64 | // show no device selected warning
65 | if (isDualTone) {
66 | qsTile.label = prefs.getString(PREF_TILE_WHITE_NAME, "White Torch")
67 | qsTile.state = prefs.getInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
68 | } else {
69 | qsTile.label = "White Torch Unsupported"
70 | qsTile.state = Tile.STATE_UNAVAILABLE
71 | }
72 | qsTile.updateTile()
73 | }
74 |
75 | override fun onClick() {
76 | super.onClick()
77 | updateTile()
78 | }
79 |
80 | private fun updateTile() {
81 |
82 | val prefs = applicationContext.defaultSharedPreferences
83 |
84 | // get torch file locations
85 | val selectedDevice = prefs.getString(PREF_SELECTED_DEVICE, "")
86 |
87 | // show no device selected warning
88 | if (selectedDevice.isEmpty()) {
89 | showDialog(TileDialog.getDialog(this, "Godly Torch",
90 | "Your device is not set or supported yet." +
91 | " Open the app to request support."))
92 | return
93 | }
94 |
95 | val yellowTileIsOn = prefs.getBoolean(PREF_TILE_YELLOW_ON, false)
96 | val masterTileIsOn = prefs.getBoolean(PREF_TILE_MASTER_ON, false)
97 |
98 | if (yellowTileIsOn) {
99 | showDialog(TileDialog.getDialog(this, "Godly Torch",
100 | "Yellow Torch tile is active. You can use one tile at a time only."))
101 | return
102 | } else if (masterTileIsOn) {
103 | showDialog(TileDialog.getDialog(this, "Godly Torch",
104 | "Master Control tile is active. You can use one tile at a time only."))
105 | return
106 | }
107 |
108 | val tile = this.qsTile
109 | tile.state = Tile.STATE_UNAVAILABLE
110 | tile.updateTile()
111 |
112 | val editor = prefs.edit()
113 | val tileStatus = prefs.getInt(TILE_STATUS, 0)
114 |
115 | if (!askRoot()) {
116 | if (!isLocked) {
117 | showDialog(TileDialog.getDialog(this, "Godly Torch",
118 | "Root access is required to run this app. " +
119 | "Make sure your device is rooted and root access is enabled."))
120 | }
121 | tile.state = Tile.STATE_INACTIVE
122 | tile.updateTile()
123 | return
124 | }
125 | // Read device specific values
126 | val whiteLedFileLocation = prefs.getString(PREF_WHITE_FILE_LOCATION, null)
127 | val yellowLedFileLocation = prefs.getString(PREF_YELLOW_FILE_LOCATION, null)
128 | val toggleFileLocation = prefs.getString(PREF_TOGGLE_FILE_LOCATION, null)
129 |
130 | // get max brightness
131 | val brightnessMax = prefs.getInt(PREF_BRIGHTNESS_MAX, 0)
132 |
133 |
134 | when (prefs.getString("tileBehaviour", "1")) {
135 | "1" -> {
136 | val toggleIntensity = prefs.getString("toggleIntensity", "100")
137 | val currentDevice = Utils.readDevice(baseContext)
138 |
139 | currentDevice?.let {
140 | if (currentDevice.isDualTone) {
141 |
142 | if (tileStatus > 0) {
143 | val command: String = String.format(getString(R.string.cmd_echo), 0, whiteLedFileLocation) +
144 | String.format(getString(R.string.cmd_echo), 0, yellowLedFileLocation) +
145 | String.format(getString(R.string.cmd_echo), 0, toggleFileLocation)
146 |
147 | runCommand(command)
148 | editor.putInt(TILE_STATUS, 0)
149 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
150 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
151 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
152 | editor.apply()
153 | tile.label = "White Torch"
154 | tile.state = Tile.STATE_INACTIVE
155 | tile.updateTile()
156 | } else {
157 | val torchVal = (brightnessMax * toggleIntensity.toInt()) / 100
158 |
159 | val command: String = String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
160 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
161 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
162 |
163 | runCommand(command)
164 | editor.putInt(TILE_STATUS, 1)
165 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
166 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
167 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
168 | editor.apply()
169 | tile.label = "White Torch"
170 | tile.state = Tile.STATE_ACTIVE
171 | tile.updateTile()
172 | }
173 | }
174 | }
175 | }
176 |
177 | "2" -> {
178 |
179 | val intensitySteps = prefs.getString("intensitySteps", "5")
180 | val currentDevice = Utils.readDevice(baseContext)
181 | currentDevice?.let {
182 | when (tileStatus) {
183 | 0 -> {
184 | val torchVal: Int = 100 / (intensitySteps.toInt() + 1)
185 |
186 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
187 | getString(R.string.cmd_sleep) +
188 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
189 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
190 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
191 |
192 |
193 | runCommand(command)
194 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
195 | editor.putInt(TILE_STATUS, 1)
196 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
197 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
198 | editor.apply()
199 | tile.label = "$torchVal%"
200 | tile.state = Tile.STATE_ACTIVE
201 | tile.updateTile()
202 | }
203 | 1 -> {
204 | val torchVal: Int = (100 / (intensitySteps.toInt() + 1)) * 2
205 |
206 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
207 | getString(R.string.cmd_sleep) +
208 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
209 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
210 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
211 |
212 | runCommand(command)
213 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
214 | editor.putInt(TILE_STATUS, 2)
215 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
216 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
217 | editor.apply()
218 | tile.label = "$torchVal%"
219 | tile.state = Tile.STATE_ACTIVE
220 | tile.updateTile()
221 | }
222 | 2 -> {
223 | var torchVal: Int = (100 / (intensitySteps.toInt() + 1)) * 3
224 | if (torchVal > 90)
225 | torchVal = 100
226 |
227 | if (tileStatus == intensitySteps.toInt() + 1) {
228 | val command = String.format(getString(R.string.cmd_echo), "0", whiteLedFileLocation) +
229 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
230 | String.format(getString(R.string.cmd_echo), "0", toggleFileLocation)
231 |
232 | runCommand(command)
233 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
234 | editor.putInt(TILE_STATUS, 0)
235 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
236 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
237 | editor.apply()
238 | tile.label = "White Torch"
239 | tile.state = Tile.STATE_INACTIVE
240 | tile.updateTile()
241 | return
242 | } else {
243 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
244 | getString(R.string.cmd_sleep) +
245 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
246 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
247 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
248 |
249 | runCommand(command)
250 | }
251 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
252 | editor.putInt(TILE_STATUS, 3)
253 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
254 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
255 | editor.apply()
256 | tile.label = "$torchVal%"
257 | tile.state = Tile.STATE_ACTIVE
258 | tile.updateTile()
259 | }
260 | 3 -> {
261 | val torchVal: Int = (100 / (intensitySteps.toInt() + 1)) * 4
262 |
263 | if (tileStatus == intensitySteps.toInt() + 1) {
264 | val command = String.format(getString(R.string.cmd_echo), "0", whiteLedFileLocation) +
265 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
266 | String.format(getString(R.string.cmd_echo), "0", toggleFileLocation)
267 |
268 | runCommand(command)
269 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
270 | editor.putInt(TILE_STATUS, 0)
271 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
272 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
273 | editor.apply()
274 | tile.label = "White Torch"
275 | tile.state = Tile.STATE_INACTIVE
276 | tile.updateTile()
277 | return
278 | } else {
279 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
280 | getString(R.string.cmd_sleep) +
281 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
282 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
283 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
284 |
285 | runCommand(command)
286 | }
287 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
288 | editor.putInt(TILE_STATUS, 4)
289 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
290 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
291 | editor.apply()
292 | tile.label = "$torchVal%"
293 | tile.state = Tile.STATE_ACTIVE
294 | tile.updateTile()
295 | }
296 | 4 -> {
297 | val torchVal: Int = (100 / (intensitySteps.toInt() + 1)) * 5
298 |
299 | if (tileStatus == intensitySteps.toInt() + 1) {
300 | val command = String.format(getString(R.string.cmd_echo), "0", whiteLedFileLocation) +
301 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
302 | String.format(getString(R.string.cmd_echo), "0", toggleFileLocation)
303 |
304 | runCommand(command)
305 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
306 | editor.putInt(TILE_STATUS, 0)
307 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
308 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
309 | editor.apply()
310 | tile.label = "White Torch"
311 | tile.state = Tile.STATE_INACTIVE
312 | tile.updateTile()
313 | return
314 | } else {
315 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
316 | getString(R.string.cmd_sleep) +
317 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
318 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
319 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
320 |
321 | runCommand(command)
322 | }
323 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
324 | editor.putInt(TILE_STATUS, 5)
325 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
326 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
327 | editor.apply()
328 | tile.label = "$torchVal%"
329 | tile.state = Tile.STATE_ACTIVE
330 | tile.updateTile()
331 | }
332 | 5 -> {
333 | var torchVal: Int = (100 / (intensitySteps.toInt() + 1)) * 6
334 | if (torchVal > 90)
335 | torchVal = 100
336 |
337 | if (tileStatus == intensitySteps.toInt() + 1) {
338 | val command = String.format(getString(R.string.cmd_echo), "0", whiteLedFileLocation) +
339 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
340 | String.format(getString(R.string.cmd_echo), "0", toggleFileLocation)
341 |
342 | runCommand(command)
343 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
344 | editor.putInt(TILE_STATUS, 0)
345 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
346 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
347 | editor.apply()
348 | tile.label = "White Torch"
349 | tile.state = Tile.STATE_INACTIVE
350 | tile.updateTile()
351 | return
352 | } else {
353 | val command = String.format(getString(R.string.cmd_echo), "0", toggleFileLocation) +
354 | getString(R.string.cmd_sleep) +
355 | String.format(getString(R.string.cmd_echo), torchVal, whiteLedFileLocation) +
356 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
357 | String.format(getString(R.string.cmd_echo), brightnessMax, toggleFileLocation)
358 |
359 | runCommand(command)
360 | }
361 | editor.putBoolean(PREF_TILE_WHITE_ON, true)
362 | editor.putInt(TILE_STATUS, 6)
363 | editor.putString(PREF_TILE_WHITE_NAME, "$torchVal%")
364 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_ACTIVE)
365 | editor.apply()
366 | tile.label = "$torchVal%"
367 | tile.state = Tile.STATE_ACTIVE
368 | tile.updateTile()
369 |
370 | }
371 | 6 -> {
372 | val command = String.format(getString(R.string.cmd_echo), "0", whiteLedFileLocation) +
373 | String.format(getString(R.string.cmd_echo), "0", yellowLedFileLocation) +
374 | String.format(getString(R.string.cmd_echo), "0", toggleFileLocation)
375 |
376 | runCommand(command)
377 | editor.putBoolean(PREF_TILE_WHITE_ON, false)
378 | editor.putInt(TILE_STATUS, 0)
379 | editor.putString(PREF_TILE_WHITE_NAME, "White Torch")
380 | editor.putInt(PREF_TILE_WHITE_STATE, Tile.STATE_INACTIVE)
381 | editor.apply()
382 | tile.label = "White Torch"
383 | tile.state = Tile.STATE_INACTIVE
384 | tile.updateTile()
385 | }
386 | }
387 | }
388 | }
389 | }
390 | tile.updateTile()
391 | }
392 |
393 | }
394 |
--------------------------------------------------------------------------------