From 8665380ac4eeaca2ea664ccc7b774cb2aaaea05e Mon Sep 17 00:00:00 2001 From: Vladimir Svistelnikov Date: Sun, 30 Jun 2019 15:43:02 +0300 Subject: [PATCH] 03-Service: Add get application implementation Signed-off-by: Vladimir Svistelnikov --- 03-Service/.gitignore | 4 + 03-Service/GetterApp/.gitignore | 13 ++ 03-Service/GetterApp/app/.gitignore | 1 + 03-Service/GetterApp/app/build.gradle | 29 +++ 03-Service/GetterApp/app/proguard-rules.pro | 21 +++ .../getterapp/ExampleInstrumentedTest.java | 27 +++ .../app/src/main/AndroidManifest.xml | 22 +++ .../getterapp/IGetSetServicelInterface.aidl | 17 ++ .../com/example/getterapp/MainActivity.java | 75 ++++++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 16 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 11 ++ .../example/getterapp/ExampleUnitTest.java | 17 ++ 03-Service/GetterApp/build.gradle | 27 +++ 03-Service/GetterApp/gradle.properties | 20 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + 03-Service/GetterApp/gradlew | 172 ++++++++++++++++++ 03-Service/GetterApp/gradlew.bat | 84 +++++++++ 03-Service/GetterApp/settings.gradle | 1 + 35 files changed, 786 insertions(+) create mode 100644 03-Service/GetterApp/.gitignore create mode 100644 03-Service/GetterApp/app/.gitignore create mode 100644 03-Service/GetterApp/app/build.gradle create mode 100644 03-Service/GetterApp/app/proguard-rules.pro create mode 100644 03-Service/GetterApp/app/src/androidTest/java/com/example/getterapp/ExampleInstrumentedTest.java create mode 100644 03-Service/GetterApp/app/src/main/AndroidManifest.xml create mode 100644 03-Service/GetterApp/app/src/main/aidl/com/example/getterapp/IGetSetServicelInterface.aidl create mode 100644 03-Service/GetterApp/app/src/main/java/com/example/getterapp/MainActivity.java create mode 100644 03-Service/GetterApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 03-Service/GetterApp/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 03-Service/GetterApp/app/src/main/res/layout/activity_main.xml create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 03-Service/GetterApp/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 03-Service/GetterApp/app/src/main/res/values/colors.xml create mode 100644 03-Service/GetterApp/app/src/main/res/values/strings.xml create mode 100644 03-Service/GetterApp/app/src/main/res/values/styles.xml create mode 100644 03-Service/GetterApp/app/src/test/java/com/example/getterapp/ExampleUnitTest.java create mode 100644 03-Service/GetterApp/build.gradle create mode 100644 03-Service/GetterApp/gradle.properties create mode 100644 03-Service/GetterApp/gradle/wrapper/gradle-wrapper.jar create mode 100644 03-Service/GetterApp/gradle/wrapper/gradle-wrapper.properties create mode 100755 03-Service/GetterApp/gradlew create mode 100644 03-Service/GetterApp/gradlew.bat create mode 100644 03-Service/GetterApp/settings.gradle diff --git a/03-Service/.gitignore b/03-Service/.gitignore index d10386f..746cbd9 100644 --- a/03-Service/.gitignore +++ b/03-Service/.gitignore @@ -5,3 +5,7 @@ GetSetService/.gradle/ SetterApp/app/build/ SetterApp/.idea/ SetterApp/.gradle/ + +GetterApp/app/build/ +GetterApp/.idea/ +GetterApp/.gradle/ diff --git a/03-Service/GetterApp/.gitignore b/03-Service/GetterApp/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/03-Service/GetterApp/.gitignore @@ -0,0 +1,13 @@ +*.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 diff --git a/03-Service/GetterApp/app/.gitignore b/03-Service/GetterApp/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/03-Service/GetterApp/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/03-Service/GetterApp/app/build.gradle b/03-Service/GetterApp/app/build.gradle new file mode 100644 index 0000000..f3dc249 --- /dev/null +++ b/03-Service/GetterApp/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.0" + defaultConfig { + applicationId "com.example.getterapp" + minSdkVersion 26 + 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:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/03-Service/GetterApp/app/proguard-rules.pro b/03-Service/GetterApp/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/03-Service/GetterApp/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/03-Service/GetterApp/app/src/androidTest/java/com/example/getterapp/ExampleInstrumentedTest.java b/03-Service/GetterApp/app/src/androidTest/java/com/example/getterapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..582cca2 --- /dev/null +++ b/03-Service/GetterApp/app/src/androidTest/java/com/example/getterapp/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.example.getterapp; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + * 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.getTargetContext(); + + assertEquals("com.example.getterapp", appContext.getPackageName()); + } +} diff --git a/03-Service/GetterApp/app/src/main/AndroidManifest.xml b/03-Service/GetterApp/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3994104 --- /dev/null +++ b/03-Service/GetterApp/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/03-Service/GetterApp/app/src/main/aidl/com/example/getterapp/IGetSetServicelInterface.aidl b/03-Service/GetterApp/app/src/main/aidl/com/example/getterapp/IGetSetServicelInterface.aidl new file mode 100644 index 0000000..842b604 --- /dev/null +++ b/03-Service/GetterApp/app/src/main/aidl/com/example/getterapp/IGetSetServicelInterface.aidl @@ -0,0 +1,17 @@ +// IGetSetServicelInterface.aidl +package com.example.getterapp; + +// Declare any non-default types here with import statements + +interface IGetSetServicelInterface { + /** + * Demonstrates some basic types that you can use as parameters + * and return values in AIDL. + */ +/* + void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, + double aDouble, String aString); +*/ + int getValue(); + void setValue( int newValue); +} \ No newline at end of file diff --git a/03-Service/GetterApp/app/src/main/java/com/example/getterapp/MainActivity.java b/03-Service/GetterApp/app/src/main/java/com/example/getterapp/MainActivity.java new file mode 100644 index 0000000..1352aef --- /dev/null +++ b/03-Service/GetterApp/app/src/main/java/com/example/getterapp/MainActivity.java @@ -0,0 +1,75 @@ +package com.example.getterapp; + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +public class MainActivity extends AppCompatActivity { + private static String LOG_TAG = "GetterApp"; + private com.example.getterapp.IGetSetServicelInterface mService; + private BroadcastReceiver mBroadReceiver = null; + + private void Log(@NonNull String format, @NonNull Object... objects) { + Log.d(LOG_TAG, "-> %s" + String.format(format, objects)); + } + + @Override + protected void onPostResume() { + Log("onPostResume()"); + super.onPostResume(); + + IntentFilter filter = new IntentFilter("com.example.getsetservice.GET_VALUE_RESULT"); + mBroadReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.hasExtra("value")) { + int value = intent.getIntExtra("value", 0); + Log("GetValue() method done: %d", value); + } + + } + }; + this.registerReceiver(mBroadReceiver, filter); + } + + @Override + protected void onPause() { + super.onPause(); + Log("onPause()"); + + this.unregisterReceiver(mBroadReceiver); + mBroadReceiver = null; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + Log("onCreate()"); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Button getValueBtn = findViewById(R.id.getValueBtn); + getValueBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + getValueBtnOnClick(); + } + }); + } + + private void getValueBtnOnClick() { + Log("getValueBtnOnClick()"); + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.example.getsetservice", "com.example.getsetservice.GetSetService")); + intent.setAction("com.example.getsetservice.GET_VALUE"); + startForegroundService(intent); + } +} diff --git a/03-Service/GetterApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/03-Service/GetterApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/03-Service/GetterApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/03-Service/GetterApp/app/src/main/res/drawable/ic_launcher_background.xml b/03-Service/GetterApp/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/03-Service/GetterApp/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/03-Service/GetterApp/app/src/main/res/layout/activity_main.xml b/03-Service/GetterApp/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..9d70398 --- /dev/null +++ b/03-Service/GetterApp/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + +