From 424e88c76c5d9d3d0cb6620a8e64d59d61b1ad4e Mon Sep 17 00:00:00 2001 From: Eugene Surkov Date: Tue, 27 Jun 2017 19:14:19 +0300 Subject: [PATCH 1/2] Update bintray files --- AGMobileGiftInterface/.gitignore | 1 - AGMobileGiftInterface/bintray.gradle | 45 ---------- AGMobileGiftInterface/build.gradle | 54 ------------ AGMobileGiftInterface/install.gradle | 37 -------- AGMobileGiftInterface/proguard-rules.pro | 25 ------ .../src/main/AndroidManifest.xml | 21 ----- .../AGMobileGiftInterface.kt | 8 -- .../AGMobileGiftInterfaceImpl.kt | 17 ---- .../agmobilegiftinterface/GiftService.kt | 85 ------------------- .../src/main/res/values/strings.xml | 3 - README.md | 8 +- settings.gradle | 2 +- 12 files changed, 5 insertions(+), 301 deletions(-) delete mode 100644 AGMobileGiftInterface/.gitignore delete mode 100644 AGMobileGiftInterface/bintray.gradle delete mode 100644 AGMobileGiftInterface/build.gradle delete mode 100644 AGMobileGiftInterface/install.gradle delete mode 100644 AGMobileGiftInterface/proguard-rules.pro delete mode 100644 AGMobileGiftInterface/src/main/AndroidManifest.xml delete mode 100644 AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt delete mode 100644 AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt delete mode 100644 AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt delete mode 100644 AGMobileGiftInterface/src/main/res/values/strings.xml diff --git a/AGMobileGiftInterface/.gitignore b/AGMobileGiftInterface/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/AGMobileGiftInterface/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/AGMobileGiftInterface/bintray.gradle b/AGMobileGiftInterface/bintray.gradle deleted file mode 100644 index 233cd8f..0000000 --- a/AGMobileGiftInterface/bintray.gradle +++ /dev/null @@ -1,45 +0,0 @@ -apply plugin: 'com.jfrog.bintray' - -version = '0.0.1' //YOUR LIBRARY VERSION - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} -artifacts { - archives javadocJar - archives sourcesJar -} - -// Bintray -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) - - -bintray { - user = properties.getProperty("bintray.user") - key = properties.getProperty("bintray.apikey") - - configurations = ['archives'] - pkg { - repo = 'Agilie-Team' - name = 'AGMobileGift' //YOUR PACKAGE NAME - desc = 'This library simplifies interaction with GIF images' // YOUR LIBRARY DESCRIPTION - websiteUrl = 'https://github.com/agilie/AGMobileGift' // YOUR SITE - vcsUrl = 'https://github.com/agilie/AGMobileGift.git' // YOUR GIT REPO - licenses = ["Apache-2.0"] // A LIST OF YOUR LICENCES - publish = true - publicDownloadNumbers = true - } -} - diff --git a/AGMobileGiftInterface/build.gradle b/AGMobileGiftInterface/build.gradle deleted file mode 100644 index e822391..0000000 --- a/AGMobileGiftInterface/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - - -android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" - - defaultConfig { - minSdkVersion 19 - targetSdkVersion 25 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - - testCompile 'junit:junit:4.12' - - compile 'com.android.support:appcompat-v7:25.3.1' - // Gif Animation - compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.6' - // Kotlin - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" - - - - - -} -repositories { - mavenCentral() -} - - - -apply from: 'install.gradle' -apply from: 'bintray.gradle' \ No newline at end of file diff --git a/AGMobileGiftInterface/install.gradle b/AGMobileGiftInterface/install.gradle deleted file mode 100644 index 083d67f..0000000 --- a/AGMobileGiftInterface/install.gradle +++ /dev/null @@ -1,37 +0,0 @@ -apply plugin: 'com.github.dcendents.android-maven' -group = 'com.agilie.agmobilegift' // CREATE A GROUP ID FOR YOUR LIBRARY - -install { - repositories.mavenInstaller { - pom { - project { - packaging 'aar' - groupId 'com.agilie.agmobilegift' // CREATE A GROUP ID FOR YOUR LIBRARY - artifactId 'AGMobileGiftInterface' // THE NAME OF YOUR MODULE - - name 'agmobilegift' // YOUR LIBRARY NAME - description 'This library simplifies interaction with GIF images' // YOUR LIBRARY DESCRIPTION - url 'https://github.com/agilie/AGMobileGift' // YOUR SITE - - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - //id 'AntonioCappiello' //YOUR ID - //name 'Antonio Cappiello' //YOUR NAME - //email 'antoniocappiello1@gmail.com' //YOUR EMAIL - } - } - scm { - connection 'https://github.com/agilie/AGMobileGift.git' // YOUR GIT REPO - developerConnection 'https://github.com/agilie/AGMobileGift.git' // YOUR GIT REPO - url 'https://github.com/agilie/AGMobileGift' // YOUR SITE - } - } - } - } -} \ No newline at end of file diff --git a/AGMobileGiftInterface/proguard-rules.pro b/AGMobileGiftInterface/proguard-rules.pro deleted file mode 100644 index 4cc674c..0000000 --- a/AGMobileGiftInterface/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/eugene/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# 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/AGMobileGiftInterface/src/main/AndroidManifest.xml b/AGMobileGiftInterface/src/main/AndroidManifest.xml deleted file mode 100644 index 3c11dce..0000000 --- a/AGMobileGiftInterface/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt b/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt deleted file mode 100644 index e44d364..0000000 --- a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.agilie.agmobilegiftinterface - -import android.content.Context - - -interface AGMobileGiftInterface { - fun show(context: Context, id: Int) -} \ No newline at end of file diff --git a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt b/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt deleted file mode 100644 index 6e54ae0..0000000 --- a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.agilie.agmobilegiftinterface - -import android.content.Context -import android.content.Intent -import com.agilie.agmobilegiftinterface.GiftService.Companion.RES_ID - - -class AGMobileGiftInterfaceImpl : AGMobileGiftInterface { - - override fun show(context: Context, id: Int) { - val intent = Intent(context, GiftService::class.java).putExtra(RES_ID, id) - Thread().run { - context.startService(intent) - } - } - -} diff --git a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt b/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt deleted file mode 100644 index 5d4ed26..0000000 --- a/AGMobileGiftInterface/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.agilie.agmobilegiftinterface - -import android.app.Service -import android.content.Context -import android.content.Intent -import android.graphics.PixelFormat -import android.os.IBinder -import android.view.Gravity -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.view.WindowManager -import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE -import android.view.WindowManager.LayoutParams.TYPE_TOAST -import pl.droidsonroids.gif.GifDrawable -import pl.droidsonroids.gif.GifImageView - - -class GiftService : Service() { - - companion object { - val RES_ID = "RES_ID" - } - - private var windowManager: WindowManager? = null - private var gifImageView: GifImageView? = null - private var resourceId: Int = 0 - - override fun onCreate() { - super.onCreate() - - init() - } - - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - resourceId = intent?.getIntExtra(RES_ID, 0)!! - try { - setGifAnimation(resourceId) - } catch (e: Exception) { - e.printStackTrace() - } - - return super.onStartCommand(intent, flags, startId) - } - - override fun onDestroy() { - removeGifView() - - super.onDestroy() - } - - override fun onBind(intent: Intent?): IBinder? { - return null - } - - private fun init() { - windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager - gifImageView = GifImageView(applicationContext) - } - - private fun setGifAnimation(gifResId: Int) { - val gif = GifDrawable(resources, gifResId) - gif.addAnimationListener { stopSelf() } - gifImageView?.setImageDrawable(gif) - - with(WindowManager.LayoutParams( - WRAP_CONTENT, - WRAP_CONTENT, - TYPE_TOAST, - FLAG_NOT_FOCUSABLE, - PixelFormat.TRANSLUCENT)) { - - gravity = Gravity.TOP or Gravity.LEFT - x = 0 - y = 0 - - gifImageView?.windowToken?.apply { removeGifView() } ?: windowManager?.addView(gifImageView, this) - } - } - - private fun removeGifView() { - windowManager?.removeView(gifImageView) - } - -} - - diff --git a/AGMobileGiftInterface/src/main/res/values/strings.xml b/AGMobileGiftInterface/src/main/res/values/strings.xml deleted file mode 100644 index c4e4d31..0000000 --- a/AGMobileGiftInterface/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - EasterGift - diff --git a/README.md b/README.md index 028dd06..b6b0d6a 100644 --- a/README.md +++ b/README.md @@ -35,16 +35,16 @@ We made example to congratulate the use on the day of Easter. Add dependency in your `build.gradle` file: ```` -compile 'com.agilie.agmobilegift:AGMobileGiftInterface:0.0.1' +compile 'com.agilie:mobile-gift:1.0' ```` ### Maven Add rependency in your `.pom` file: ```` - com.agilie.agmobilegift - AGMobileGiftInterface - 0.0.1 + com.agilie + mobile-gift + 1.0 pom ```` diff --git a/settings.gradle b/settings.gradle index c277635..03e387a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':AGMobileGiftInterface-Example', ':AGMobileGiftInterface' +include ':AGMobileGiftInterface-Example', ':mobile-gift' From 30d892cafc91ba72afc23f11e221905ac74932a4 Mon Sep 17 00:00:00 2001 From: Eugene Surkov Date: Wed, 28 Jun 2017 10:14:11 +0300 Subject: [PATCH 2/2] Replaced the old dependencies --- AGMobileGiftInterface-Example/build.gradle | 4 +- mobile-gift/.gitignore | 1 + mobile-gift/bintray.gradle | 46 ++++++++++ mobile-gift/build.gradle | 54 ++++++++++++ mobile-gift/install.gradle | 33 +++++++ mobile-gift/proguard-rules.pro | 25 ++++++ mobile-gift/src/main/AndroidManifest.xml | 21 +++++ .../AGMobileGiftInterface.kt | 8 ++ .../AGMobileGiftInterfaceImpl.kt | 17 ++++ .../agmobilegiftinterface/GiftService.kt | 85 +++++++++++++++++++ mobile-gift/src/main/res/values/strings.xml | 3 + 11 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 mobile-gift/.gitignore create mode 100644 mobile-gift/bintray.gradle create mode 100644 mobile-gift/build.gradle create mode 100644 mobile-gift/install.gradle create mode 100644 mobile-gift/proguard-rules.pro create mode 100644 mobile-gift/src/main/AndroidManifest.xml create mode 100644 mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt create mode 100644 mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt create mode 100644 mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt create mode 100644 mobile-gift/src/main/res/values/strings.xml diff --git a/AGMobileGiftInterface-Example/build.gradle b/AGMobileGiftInterface-Example/build.gradle index fec5e22..06119e1 100644 --- a/AGMobileGiftInterface-Example/build.gradle +++ b/AGMobileGiftInterface-Example/build.gradle @@ -30,7 +30,7 @@ dependencies { testCompile 'junit:junit:4.12' // Kotlin compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - // AGMobileGift - compile 'com.agilie.agmobilegift:AGMobileGiftInterface:0.0.1' + // MobileGift + compile 'com.agilie:mobile-gift:1.0' } diff --git a/mobile-gift/.gitignore b/mobile-gift/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/mobile-gift/.gitignore @@ -0,0 +1 @@ +/build diff --git a/mobile-gift/bintray.gradle b/mobile-gift/bintray.gradle new file mode 100644 index 0000000..80720a8 --- /dev/null +++ b/mobile-gift/bintray.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.jfrog.bintray' + +version = '1.0' //YOUR LIBRARY VERSION + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} +artifacts { + archives javadocJar + archives sourcesJar +} + +// Bintray +Properties properties = new Properties() +properties.load(project.rootProject.file('local.properties').newDataInputStream()) + + +bintray { + user = properties.getProperty("bintray.user") + key = properties.getProperty("bintray.apikey") + + configurations = ['archives'] + pkg { + repo = 'maven' + name = 'MobileGift' //YOUR PACKAGE NAME + userOrg = 'agilie' + desc = 'This library simplifies interaction with GIF images' // YOUR LIBRARY DESCRIPTION + websiteUrl = 'https://github.com/agilie/MobileGift' // YOUR SITE + vcsUrl = 'https://github.com/agilie/MobileGift.git' // YOUR GIT REPO + licenses = ["MIT"] // A LIST OF YOUR LICENCES + publish = true + publicDownloadNumbers = true + } +} + diff --git a/mobile-gift/build.gradle b/mobile-gift/build.gradle new file mode 100644 index 0000000..e822391 --- /dev/null +++ b/mobile-gift/build.gradle @@ -0,0 +1,54 @@ + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + + defaultConfig { + minSdkVersion 19 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + + testCompile 'junit:junit:4.12' + + compile 'com.android.support:appcompat-v7:25.3.1' + // Gif Animation + compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.6' + // Kotlin + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + + + + + +} +repositories { + mavenCentral() +} + + + +apply from: 'install.gradle' +apply from: 'bintray.gradle' \ No newline at end of file diff --git a/mobile-gift/install.gradle b/mobile-gift/install.gradle new file mode 100644 index 0000000..b562f7f --- /dev/null +++ b/mobile-gift/install.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.github.dcendents.android-maven' +group = 'com.agilie' // CREATE A GROUP ID FOR YOUR LIBRARY + +install { + repositories.mavenInstaller { + pom { + project { + packaging 'mobile-gift' + groupId 'com.agilie' // CREATE A GROUP ID FOR YOUR LIBRARY + artifactId 'mobile-gift' // THE NAME OF YOUR MODULE + + name 'MobileGift' // YOUR LIBRARY NAME + description 'This library simplifies interaction with GIF images' // YOUR LIBRARY DESCRIPTION + url 'https://github.com/agilie/AGMobileGift' // YOUR SITE + + licenses { + license { + name 'MIT' + } + } + developers { + developer { + } + } + scm { + connection 'https://github.com/agilie/MobileGift.git' // YOUR GIT REPO + developerConnection 'https://github.com/agilie/MobileGift.git' // YOUR GIT REPO + url 'https://github.com/agilie/MobileGift' // YOUR SITE + } + } + } + } +} \ No newline at end of file diff --git a/mobile-gift/proguard-rules.pro b/mobile-gift/proguard-rules.pro new file mode 100644 index 0000000..4cc674c --- /dev/null +++ b/mobile-gift/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/eugene/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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/mobile-gift/src/main/AndroidManifest.xml b/mobile-gift/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3c11dce --- /dev/null +++ b/mobile-gift/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt new file mode 100644 index 0000000..e44d364 --- /dev/null +++ b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterface.kt @@ -0,0 +1,8 @@ +package com.agilie.agmobilegiftinterface + +import android.content.Context + + +interface AGMobileGiftInterface { + fun show(context: Context, id: Int) +} \ No newline at end of file diff --git a/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt new file mode 100644 index 0000000..6e54ae0 --- /dev/null +++ b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/AGMobileGiftInterfaceImpl.kt @@ -0,0 +1,17 @@ +package com.agilie.agmobilegiftinterface + +import android.content.Context +import android.content.Intent +import com.agilie.agmobilegiftinterface.GiftService.Companion.RES_ID + + +class AGMobileGiftInterfaceImpl : AGMobileGiftInterface { + + override fun show(context: Context, id: Int) { + val intent = Intent(context, GiftService::class.java).putExtra(RES_ID, id) + Thread().run { + context.startService(intent) + } + } + +} diff --git a/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt new file mode 100644 index 0000000..5d4ed26 --- /dev/null +++ b/mobile-gift/src/main/java/com/agilie/agmobilegiftinterface/GiftService.kt @@ -0,0 +1,85 @@ +package com.agilie.agmobilegiftinterface + +import android.app.Service +import android.content.Context +import android.content.Intent +import android.graphics.PixelFormat +import android.os.IBinder +import android.view.Gravity +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import android.view.WindowManager +import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE +import android.view.WindowManager.LayoutParams.TYPE_TOAST +import pl.droidsonroids.gif.GifDrawable +import pl.droidsonroids.gif.GifImageView + + +class GiftService : Service() { + + companion object { + val RES_ID = "RES_ID" + } + + private var windowManager: WindowManager? = null + private var gifImageView: GifImageView? = null + private var resourceId: Int = 0 + + override fun onCreate() { + super.onCreate() + + init() + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + resourceId = intent?.getIntExtra(RES_ID, 0)!! + try { + setGifAnimation(resourceId) + } catch (e: Exception) { + e.printStackTrace() + } + + return super.onStartCommand(intent, flags, startId) + } + + override fun onDestroy() { + removeGifView() + + super.onDestroy() + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + private fun init() { + windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager + gifImageView = GifImageView(applicationContext) + } + + private fun setGifAnimation(gifResId: Int) { + val gif = GifDrawable(resources, gifResId) + gif.addAnimationListener { stopSelf() } + gifImageView?.setImageDrawable(gif) + + with(WindowManager.LayoutParams( + WRAP_CONTENT, + WRAP_CONTENT, + TYPE_TOAST, + FLAG_NOT_FOCUSABLE, + PixelFormat.TRANSLUCENT)) { + + gravity = Gravity.TOP or Gravity.LEFT + x = 0 + y = 0 + + gifImageView?.windowToken?.apply { removeGifView() } ?: windowManager?.addView(gifImageView, this) + } + } + + private fun removeGifView() { + windowManager?.removeView(gifImageView) + } + +} + + diff --git a/mobile-gift/src/main/res/values/strings.xml b/mobile-gift/src/main/res/values/strings.xml new file mode 100644 index 0000000..c4e4d31 --- /dev/null +++ b/mobile-gift/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + EasterGift +