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 @@ + + + +