27 | * Must be called before starting any new thread. 28 | * 29 | * @param level the log level 30 | */ 31 | public static void initLogLevel(Level level) { 32 | threshold = level; 33 | } 34 | 35 | public static boolean isEnabled(Level level) { 36 | return level.ordinal() >= threshold.ordinal(); 37 | } 38 | 39 | public static void v(String message) { 40 | if (isEnabled(Level.VERBOSE)) { 41 | Log.v(TAG, message); 42 | System.out.print(PREFIX + "VERBOSE: " + message + '\n'); 43 | } 44 | } 45 | 46 | public static void d(String message) { 47 | if (isEnabled(Level.DEBUG)) { 48 | Log.d(TAG, message); 49 | System.out.print(PREFIX + "DEBUG: " + message + '\n'); 50 | } 51 | } 52 | 53 | public static void i(String message) { 54 | if (isEnabled(Level.INFO)) { 55 | Log.i(TAG, message); 56 | System.out.print(PREFIX + "INFO: " + message + '\n'); 57 | } 58 | } 59 | 60 | public static void w(String message, Throwable throwable) { 61 | if (isEnabled(Level.WARN)) { 62 | Log.w(TAG, message, throwable); 63 | System.err.print(PREFIX + "WARN: " + message + '\n'); 64 | if (throwable != null) { 65 | throwable.printStackTrace(); 66 | } 67 | } 68 | } 69 | 70 | public static void w(String message) { 71 | w(message, null); 72 | } 73 | 74 | public static void e(String message, Throwable throwable) { 75 | if (isEnabled(Level.ERROR)) { 76 | Log.e(TAG, message, throwable); 77 | System.err.print(PREFIX + "ERROR: " + message + "\n"); 78 | if (throwable != null) { 79 | throwable.printStackTrace(); 80 | } 81 | } 82 | } 83 | 84 | public static void e(String message) { 85 | e(message, null); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /draw/src/main/java/com/example/draw/wrappers/PowerManager.java: -------------------------------------------------------------------------------- 1 | package com.example.draw.wrappers; 2 | 3 | 4 | import android.annotation.SuppressLint; 5 | import android.os.Build; 6 | import android.os.IInterface; 7 | 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.lang.reflect.Method; 10 | 11 | public final class PowerManager { 12 | private final IInterface manager; 13 | private Method isScreenOnMethod; 14 | 15 | public PowerManager(IInterface manager) { 16 | this.manager = manager; 17 | } 18 | 19 | private Method getIsScreenOnMethod() throws NoSuchMethodException { 20 | if (isScreenOnMethod == null) { 21 | @SuppressLint("ObsoleteSdkInt") // we may lower minSdkVersion in the future 22 | String methodName = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH ? "isInteractive" : "isScreenOn"; 23 | isScreenOnMethod = manager.getClass().getMethod(methodName); 24 | } 25 | return isScreenOnMethod; 26 | } 27 | 28 | public boolean isScreenOn() { 29 | try { 30 | Method method = getIsScreenOnMethod(); 31 | return (boolean) method.invoke(manager); 32 | } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { 33 | Ln.e("Could not invoke method", e); 34 | return false; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /draw/src/main/java/com/example/draw/wrappers/SettingsException.java: -------------------------------------------------------------------------------- 1 | package com.example.draw.wrappers; 2 | 3 | public class SettingsException extends Exception { 4 | private static String createMessage(String method, String table, String key, String value) { 5 | return "Could not access settings: " + method + " " + table + " " + key + (value != null ? " " + value : ""); 6 | } 7 | 8 | public SettingsException(String method, String table, String key, String value, Throwable cause) { 9 | super(createMessage(method, table, key, value), cause); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /draw/src/main/java/com/example/draw/wrappers/Size.java: -------------------------------------------------------------------------------- 1 | package com.example.draw.wrappers; 2 | 3 | import android.graphics.Rect; 4 | 5 | import java.util.Objects; 6 | 7 | public final class Size { 8 | private final int width; 9 | private final int height; 10 | 11 | public Size(int width, int height) { 12 | this.width = width; 13 | this.height = height; 14 | } 15 | 16 | public int getWidth() { 17 | return width; 18 | } 19 | 20 | public int getHeight() { 21 | return height; 22 | } 23 | 24 | public Size rotate() { 25 | return new Size(height, width); 26 | } 27 | 28 | public Rect toRect() { 29 | return new Rect(0, 0, width, height); 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | if (this == o) { 35 | return true; 36 | } 37 | if (o == null || getClass() != o.getClass()) { 38 | return false; 39 | } 40 | Size size = (Size) o; 41 | return width == size.width && height == size.height; 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return Objects.hash(width, height); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Size{" + "width=" + width + ", height=" + height + '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /draw/src/test/java/com/example/draw/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.draw; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /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=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Enables namespacing of each library's R class so that its R class includes only the 19 | # resources declared in the library itself and none from the library's dependencies, 20 | # thereby reducing the size of the R class for that library 21 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | agp = "8.2.0-alpha07" 3 | junit = "4.13.2" 4 | androidx-test-ext-junit = "1.1.5" 5 | espresso-core = "3.5.1" 6 | appcompat = "1.6.1" 7 | material = "1.9.0" 8 | 9 | [libraries] 10 | junit = { group = "junit", name = "junit", version.ref = "junit" } 11 | androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" } 12 | espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" } 13 | appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } 14 | material = { group = "com.google.android.material", name = "material", version.ref = "material" } 15 | 16 | [plugins] 17 | androidApplication = { id = "com.android.application", version.ref = "agp" } 18 | androidLibrary = { id = "com.android.library", version.ref = "agp" } 19 | 20 | [bundles] 21 | 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enenH/AndroidNativeDraw/58d4f2a775b8eae3b085ed6ea60dbb2f8c65e219/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 05 14:19:48 CEST 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | 16 | rootProject.name = "NativeDraw" 17 | include(":draw") 18 | --------------------------------------------------------------------------------