commit ab3fc7ce52b3d5d885e5f3092af1f77e39c30e73 Author: structix Date: Thu Apr 16 11:54:07 2020 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0f71e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +.idea diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..6d54f62 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.janasroboter" + minSdkVersion 19 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + implementation 'com.squareup.okhttp3:okhttp:4.2.2' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/janasroboter/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/janasroboter/ExampleInstrumentedTest.java new file mode 100644 index 0000000..540d754 --- /dev/null +++ b/app/src/androidTest/java/com/janasroboter/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.janasroboter; + +import android.content.Context; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.janasroboter", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a607ead --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/janasroboter/MainActivity.java b/app/src/main/java/com/janasroboter/MainActivity.java new file mode 100644 index 0000000..6fb391e --- /dev/null +++ b/app/src/main/java/com/janasroboter/MainActivity.java @@ -0,0 +1,51 @@ +package com.janasroboter; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import android.os.StrictMode; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() + .detectDiskReads() + .detectDiskWrites() + .detectNetwork() + .penaltyLog() + .build()); + } + + + public void btnToggle(View view) { + try { + REST.getString("http://192.168.4.1/toggle"); + } catch (IOException e) { + e.printStackTrace(); + } + Toast.makeText(this, "Obacht", Toast.LENGTH_SHORT).show(); + } + + public void btnLos(View view) { + EditText state = view.getRootView().findViewById(R.id.state); + String nummer = state.getText().toString(); + try { + REST.getString("http://192.168.4.1/togglearg?state=" + nummer); + } catch (IOException e) { + e.printStackTrace(); + } + Toast.makeText(this, "Obacht", Toast.LENGTH_SHORT).show(); + } + + +} diff --git a/app/src/main/java/com/janasroboter/REST.java b/app/src/main/java/com/janasroboter/REST.java new file mode 100644 index 0000000..d2e5518 --- /dev/null +++ b/app/src/main/java/com/janasroboter/REST.java @@ -0,0 +1,54 @@ +package com.janasroboter; + +import java.io.IOException; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class REST { + + // Initialize the http client + private static OkHttpClient client = new OkHttpClient(); + + // Initialize the JSON mediatype used for post requests + private static final MediaType JSONTYPE = MediaType.get("application/json; charset=utf-8"); + private static final MediaType PATCHTYPE = MediaType.parse("application/json-patch+json"); + private static final MediaType MEDIA_TYPE_MP4 = MediaType.parse("video/mp4"); + + + /** + * Make a GET request to a url + * @param url the url string + * @return content of the site body + * @throws IOException + */ + public static String getString(String url) throws IOException { + + Request request = new Request.Builder().url(url).build(); + + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } + } + + /** + * Make a GET request with an authentication token + * @param url the url string + * @param authtoken string containing the apikey/authentication token + * @return content of the site body + * @throws IOException + */ + public static String getString(String url, String authtoken) throws IOException { + // Create a request with an additional authorization header + Request request = new Request.Builder().header("Authorization", authtoken) + .url(url).build(); + + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } + } + + + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..2408e30 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..a779bd0 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,41 @@ + + + +