├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── test.jpg │ │ │ │ ├── close.png │ │ │ │ ├── close_bg.png │ │ │ │ ├── menu_item_selected_bg.xml │ │ │ │ ├── message_bg.xml │ │ │ │ ├── bubble_notification.xml │ │ │ │ ├── input_rounded.xml │ │ │ │ ├── toolbar_bg.xml │ │ │ │ ├── layout_bg.xml │ │ │ │ ├── gradient_bg.xml │ │ │ │ ├── menu_item_bg.xml │ │ │ │ ├── ic_menu_black_24dp.xml │ │ │ │ ├── ic_open_in_new_black_24dp.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── menu │ │ │ │ └── channels_menu.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── message.xml │ │ │ │ ├── menu_header.xml │ │ │ │ ├── bubble.xml │ │ │ │ ├── message_header.xml │ │ │ │ └── chat_head_content.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── sential │ │ │ │ └── discordbubbles │ │ │ │ ├── client │ │ │ │ ├── MessageInfo.kt │ │ │ │ ├── UserInfo.kt │ │ │ │ ├── Client.kt │ │ │ │ ├── GuildInfo.kt │ │ │ │ └── Channel.kt │ │ │ │ ├── chatheads │ │ │ │ ├── SpringConfig.kt │ │ │ │ ├── ChatAdapter.kt │ │ │ │ ├── OverlayService.kt │ │ │ │ ├── Close.kt │ │ │ │ ├── ChatHead.kt │ │ │ │ ├── Content.kt │ │ │ │ └── ChatHeads.kt │ │ │ │ ├── utils │ │ │ │ ├── Utils.kt │ │ │ │ └── BitmapUtils.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── sential │ │ │ └── discordbubbles │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── sential │ │ └── discordbubbles │ │ └── ExampleInstrumentedTest.kt ├── release │ └── output.json ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── runConfigurations.xml └── misc.xml ├── gradle.properties ├── README.md ├── .gitignore ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/drawable/test.jpg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Discord Bubbles 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/drawable/close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/close_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/drawable/close_bg.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sentialx/discord-bubbles/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/menu_item_selected_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/menu/channels_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/message_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bubble_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/input_rounded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":7,"versionName":"0.3.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/main/res/drawable/toolbar_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/layout_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Dec 13 16:43:32 CET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #35383F 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/gradient_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/menu_item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/client/MessageInfo.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.client 2 | 3 | import net.dv8tion.jda.api.entities.Message 4 | 5 | class MessageInfo(message: Message) { 6 | val id = message.id 7 | 8 | val text = message.contentRaw 9 | 10 | val author = UserInfo(message.author) 11 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_open_in_new_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/com/sential/discordbubbles/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/SpringConfig.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import com.facebook.rebound.SpringConfig 4 | 5 | object SpringConfigs { 6 | var NOT_DRAGGING: SpringConfig = SpringConfig.fromOrigamiTensionAndFriction(60.0, 8.0) 7 | var CAPTURING: SpringConfig = SpringConfig.fromBouncinessAndSpeed(8.0, 40.0) 8 | var CLOSE_SCALE: SpringConfig = SpringConfig.fromBouncinessAndSpeed(7.0, 25.0) 9 | var CLOSE_Y: SpringConfig = SpringConfig.fromBouncinessAndSpeed(3.0, 3.0) 10 | var DRAGGING: SpringConfig = SpringConfig.fromOrigamiTensionAndFriction(0.0, 5.0) 11 | var CONTENT_SCALE: SpringConfig = SpringConfig.fromBouncinessAndSpeed(5.0, 40.0) 12 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/client/UserInfo.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.client 2 | 3 | import android.graphics.Bitmap 4 | import net.dv8tion.jda.api.entities.User 5 | 6 | class UserInfo(user: User) { 7 | val id = user.id 8 | 9 | val name = user.name 10 | 11 | val avatarUrl: String = if (user.avatarUrl != null) user.avatarUrl!! else user.defaultAvatarUrl 12 | 13 | val avatarId: String = if (user.avatarId != null) user.avatarId!! else user.defaultAvatarId 14 | 15 | var avatarBitmap: Bitmap? = null 16 | set(value) { 17 | field = value 18 | if (onAvatarChange != null) onAvatarChange!!(value) 19 | } 20 | 21 | var onAvatarChange: ((bmp: Bitmap?) -> Unit)? = null 22 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sential/discordbubbles/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.sential.discordbubbles", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /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=-Xmx1536m 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 | # Kotlin code style for this project: "official" or "obsolete": 15 | kotlin.code.style=official 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/message.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/menu_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Discord Bubbles 2 | [![Downloads](https://img.shields.io/github/downloads/sentialx/discord-chat-heads-android/total.svg?style=flat-square)](https://github.com/sentialx/discord-chat-heads-android/releases) 3 | [![PayPal](https://img.shields.io/badge/PayPal-Donate-brightgreen?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCPPFUAL4R6M6&source=url) 4 | [![Discord](https://discordapp.com/api/guilds/307605794680209409/widget.png?style=shield)](https://discord.gg/P7Vn4VX) 5 | 6 | ## Sadly, this project doesn't work anymore. Something has changed on the Discord side that doesn't allow to login. 7 | 8 | Messenger-like chat heads for Discord on Android. 9 | 10 | # Features 11 | - Very closely followed chat heads animations and behavior from Messenger 12 | - Multiple channels support 13 | - Sending messages 14 | 15 | ![Android-Emulator-Pixel_3a_XL_API_29_5554-2020-01-17-18-56-51](https://user-images.githubusercontent.com/11065386/72634751-7e2e6b80-395b-11ea-9033-a834f1dc61a3.gif) 16 | 17 | # [Downloads](https://github.com/sentialx/discord-chat-heads-android/releases) 18 | > Disclaimer: Although the app is using [official Discord login page](https://discordapp.com/login) making it undetectable, I'm not responsible for your Discord account getting banned. 19 | 20 | # [Roadmap](https://github.com/sentialx/discord-chat-heads-android/projects/1) 21 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/utils/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.utils 2 | 3 | import android.content.res.Resources 4 | import android.os.Build 5 | import android.os.Handler 6 | import android.os.Looper 7 | import android.util.DisplayMetrics 8 | import android.view.WindowManager 9 | import android.util.TypedValue 10 | import net.dv8tion.jda.api.entities.User 11 | 12 | fun getOverlayFlag(): Int { 13 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 14 | WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY 15 | } else { 16 | WindowManager.LayoutParams.TYPE_PHONE 17 | } 18 | } 19 | 20 | fun getScreenSize(): DisplayMetrics { 21 | return Resources.getSystem().displayMetrics 22 | } 23 | 24 | fun dpToPx(dp: Float): Int { 25 | return (dp * Resources.getSystem().displayMetrics.density).toInt() 26 | } 27 | 28 | fun spToPx(sp: Float): Float { 29 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, Resources.getSystem().displayMetrics) 30 | } 31 | 32 | fun runOnMainLoop(fn: () -> Unit) { 33 | Handler(Looper.getMainLooper()).post { 34 | fn() 35 | } 36 | } 37 | 38 | fun getAvatarUrl(user: User): String { 39 | return if (user.avatarUrl != null) { 40 | user.avatarUrl!! 41 | } else { 42 | user.defaultAvatarUrl 43 | } 44 | } 45 | 46 | fun debug(txt: String) { 47 | println("asdf: $txt") 48 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | # Built application files 13 | *.apk 14 | *.ap_ 15 | 16 | # Files for the ART/Dalvik VM 17 | *.dex 18 | 19 | # Java class files 20 | *.class 21 | 22 | # Generated files 23 | bin/ 24 | gen/ 25 | out/ 26 | 27 | # Gradle files 28 | .gradle/ 29 | build/ 30 | 31 | # Local configuration file (sdk path, etc) 32 | local.properties 33 | 34 | # Proguard folder generated by Eclipse 35 | proguard/ 36 | 37 | # Log Files 38 | *.log 39 | 40 | # Android Studio Navigation editor temp files 41 | .navigation/ 42 | 43 | # Android Studio captures folder 44 | captures/ 45 | 46 | # IntelliJ 47 | *.iml 48 | .idea/workspace.xml 49 | .idea/tasks.xml 50 | .idea/gradle.xml 51 | .idea/assetWizardSettings.xml 52 | .idea/dictionaries 53 | .idea/libraries 54 | .idea/caches 55 | 56 | # Keystore files 57 | # Uncomment the following line if you do not want to check your keystore files in. 58 | #*.jks 59 | 60 | # External native build folder generated in Android Studio 2.2 and later 61 | .externalNativeBuild 62 | 63 | # Google Services (e.g. APIs or Firebase) 64 | google-services.json 65 | 66 | # Freeline 67 | freeline.py 68 | freeline/ 69 | freeline_project_description.json 70 | 71 | # fastlane 72 | fastlane/report.xml 73 | fastlane/Preview.html 74 | fastlane/screenshots 75 | fastlane/test_output 76 | 77 | DiscordTestToken.kt 78 | -------------------------------------------------------------------------------- /app/src/main/res/layout/bubble.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 27 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "com.sential.discordbubbles" 11 | minSdkVersion 23 12 | targetSdkVersion 28 13 | multiDexEnabled = true 14 | versionCode 8 15 | versionName "0.3.1" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | } 18 | compileOptions { 19 | sourceCompatibility JavaVersion.VERSION_1_8 20 | targetCompatibility JavaVersion.VERSION_1_8 21 | } 22 | kotlinOptions { 23 | jvmTarget = "1.8" 24 | } 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 36 | implementation 'com.android.support:appcompat-v7:28.0.0' 37 | implementation 'com.android.support:cardview-v7:28.0.0' 38 | implementation 'com.android.support:design:28.0.0' 39 | implementation 'com.facebook.rebound:rebound:0.3.8' 40 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 41 | testImplementation 'junit:junit:4.12' 42 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 43 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 44 | implementation ('net.dv8tion:JDA:4.1.0_81') { 45 | exclude module: 'opus-java' 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/client/Client.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.client 2 | 3 | import net.dv8tion.jda.api.AccountType 4 | import net.dv8tion.jda.api.events.message.MessageReceivedEvent 5 | import net.dv8tion.jda.api.JDABuilder 6 | import net.dv8tion.jda.api.hooks.ListenerAdapter 7 | import com.sential.discordbubbles.chatheads.* 8 | import com.sential.discordbubbles.utils.* 9 | import net.dv8tion.jda.api.JDA 10 | import net.dv8tion.jda.api.entities.ChannelType 11 | import net.dv8tion.jda.api.entities.SelfUser 12 | 13 | class Client(token: String, onLogin: (() -> Unit)? = null) : ListenerAdapter() { 14 | val jda: JDA = JDABuilder(AccountType.CLIENT).setToken(token) 15 | .addEventListeners(this) 16 | .build() 17 | 18 | init { 19 | Thread { 20 | jda.awaitReady() 21 | 22 | runOnMainLoop { 23 | if (onLogin != null) onLogin() 24 | } 25 | }.start() 26 | } 27 | 28 | override fun onMessageReceived(event: MessageReceivedEvent) { 29 | val msg = event.message 30 | 31 | val guildInfo: GuildInfo 32 | 33 | val channel = Channel(event.channel) 34 | 35 | if (event.channelType == ChannelType.PRIVATE) { 36 | guildInfo = GuildInfo( 37 | event.privateChannel.id, 38 | event.privateChannel.name, 39 | getAvatarUrl(event.privateChannel.user), 40 | true, 41 | channel.id 42 | ) 43 | } else { 44 | // TODO: guild icon with first letter 45 | guildInfo = GuildInfo(event.guild.id, event.guild.name, event.guild.iconUrl, false, channel.id) 46 | } 47 | 48 | runOnMainLoop { 49 | val chatHead = OverlayService.instance.chatHeads.add(guildInfo) 50 | chatHead.guildInfo.channels.find { it.id == event.channel.id }?.addMessage(msg) 51 | chatHead.updateNotifications() 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/client/GuildInfo.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.client 2 | 3 | import android.graphics.Bitmap 4 | import android.graphics.Color 5 | import com.sential.discordbubbles.chatheads.ChatHeads 6 | import com.sential.discordbubbles.chatheads.OverlayService 7 | import com.sential.discordbubbles.utils.* 8 | import net.dv8tion.jda.api.entities.MessageChannel 9 | 10 | class GuildInfo(val id: String, val name: String, avatarUrl: String?, val isPrivate: Boolean, var channelId: String) { 11 | var avatarUrl: String? = avatarUrl 12 | set(value) { 13 | field = value 14 | if (value != null) { 15 | Thread { 16 | this.avatarBitmap = fetchBitmap(value) 17 | }.start() 18 | } 19 | } 20 | 21 | var channels: List = emptyList() 22 | 23 | init { 24 | this.avatarUrl = avatarUrl 25 | 26 | val jda = OverlayService.instance.client?.jda 27 | val arr = if (isPrivate) { 28 | listOf(Channel(jda?.privateChannels?.find { it.id == id } as MessageChannel)) 29 | } else { 30 | jda?.getGuildById(id)?.textChannels?.map { Channel(it) } 31 | } 32 | 33 | if (arr != null) channels = arr 34 | } 35 | 36 | val channel: Channel? 37 | get() = channels.find { it.id == channelId } 38 | 39 | var onAvatarChange: (() -> Unit)? = null 40 | 41 | var avatarBitmap: Bitmap? = null 42 | set(value) { 43 | field = value 44 | if (value != null) { 45 | chatHeadBitmap = value 46 | .addBackground(Color.WHITE) 47 | .makeCircular() 48 | .scaleToSize(ChatHeads.CHAT_HEAD_SIZE) 49 | .addShadow() 50 | 51 | if (onAvatarChange != null) { 52 | runOnMainLoop { 53 | onAvatarChange!!() 54 | } 55 | } 56 | } 57 | } 58 | 59 | var chatHeadBitmap: Bitmap = Bitmap.createBitmap(ChatHeads.CHAT_HEAD_SIZE, ChatHeads.CHAT_HEAD_SIZE, Bitmap.Config.ARGB_8888) 60 | .addBackground(Color.WHITE) 61 | .makeCircular() 62 | .scaleToSize(ChatHeads.CHAT_HEAD_SIZE) 63 | .addShadow() 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/message_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 15 | 21 | 25 | 32 | 33 | 41 | 42 | 43 | 52 | 53 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/utils/BitmapUtils.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.utils 2 | 3 | import android.graphics.* 4 | import android.graphics.Bitmap 5 | import android.graphics.PorterDuffXfermode 6 | import android.graphics.BlurMaskFilter 7 | import java.io.IOException 8 | import java.net.HttpURLConnection 9 | 10 | fun Bitmap.addBackground(color: Int): Bitmap { 11 | val newBitmap = Bitmap.createBitmap(width, height, config) 12 | val canvas = Canvas(newBitmap) 13 | canvas.drawColor(color) 14 | val rect = Rect(0, 0, width, height) 15 | canvas.drawBitmap(this, rect, rect, null) 16 | return newBitmap 17 | } 18 | 19 | fun Bitmap.makeCircular(): Bitmap { 20 | val output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) 21 | val canvas = Canvas(output) 22 | 23 | val paint = Paint() 24 | val rect = Rect(0, 0, width, height) 25 | 26 | paint.isAntiAlias = true 27 | canvas.drawARGB(0, 0, 0, 0) 28 | 29 | paint.color = Color.WHITE 30 | paint.style = Paint.Style.FILL 31 | canvas.drawCircle(output.width.toFloat() / 2, output.height.toFloat() / 2, output.width.toFloat() / 2, paint) 32 | 33 | paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) 34 | canvas.drawBitmap(this, rect, rect, paint) 35 | 36 | return output 37 | } 38 | 39 | fun Bitmap.addShadow(): Bitmap { 40 | val bmOut = Bitmap.createBitmap(width + 10, height + 20, Bitmap.Config.ARGB_8888) 41 | 42 | val centerX = (bmOut.width / 2 - width / 2).toFloat() 43 | val centerY = (bmOut.height / 2 - height / 2).toFloat() 44 | 45 | val canvas = Canvas(bmOut) 46 | canvas.drawColor(0, PorterDuff.Mode.CLEAR) 47 | val ptBlur = Paint() 48 | ptBlur.maskFilter = BlurMaskFilter(6f, BlurMaskFilter.Blur.NORMAL) 49 | val offsetXY = IntArray(2) 50 | val bmAlpha = extractAlpha(ptBlur, offsetXY) 51 | val ptAlphaColor = Paint() 52 | ptAlphaColor.color = Color.argb(80, 0, 0, 0) 53 | canvas.drawBitmap(bmAlpha, centerX + offsetXY[0], centerY + offsetXY[1] + 4f, ptAlphaColor) 54 | bmAlpha.recycle() 55 | canvas.drawBitmap(this, centerX, centerY,null) 56 | return bmOut 57 | } 58 | 59 | fun Bitmap.scaleToSize(size: Int): Bitmap { 60 | return Bitmap.createScaledBitmap(this, size, size, true); 61 | } 62 | 63 | fun fetchBitmap(urlStr: String): Bitmap? { 64 | try { 65 | val url = java.net.URL(urlStr) 66 | val connection = url 67 | .openConnection() as HttpURLConnection 68 | connection.doInput = true 69 | connection.connect() 70 | val input = connection.inputStream 71 | return BitmapFactory.decodeStream(input) 72 | } catch (e: IOException) { 73 | e.printStackTrace() 74 | return null 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/client/Channel.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.client 2 | 3 | import android.graphics.Bitmap 4 | import com.sential.discordbubbles.chatheads.OverlayService 5 | import com.sential.discordbubbles.utils.fetchBitmap 6 | import com.sential.discordbubbles.utils.makeCircular 7 | import com.sential.discordbubbles.utils.runOnMainLoop 8 | import net.dv8tion.jda.api.entities.ChannelType 9 | import net.dv8tion.jda.api.entities.Message 10 | import net.dv8tion.jda.api.entities.MessageChannel 11 | 12 | class Channel(messageChannel: MessageChannel) { 13 | val type = messageChannel.type 14 | 15 | val id = messageChannel.id 16 | 17 | val instance: MessageChannel 18 | get() { 19 | val jda = OverlayService.instance.client?.jda 20 | return if (type == ChannelType.PRIVATE) { 21 | jda?.getPrivateChannelById(id) as MessageChannel 22 | } else { 23 | jda?.getTextChannelById(id) as MessageChannel 24 | } 25 | } 26 | 27 | var baseHistoryLoaded = false 28 | 29 | var notifications: Int = 0 30 | 31 | var messages = mutableListOf() 32 | 33 | private var avatarsCache = mutableMapOf() 34 | 35 | fun cacheAvatar(user: UserInfo): Bitmap? { 36 | return if (avatarsCache[user.avatarId] == null) { 37 | val bmp = fetchBitmap(user.avatarUrl)?.makeCircular() 38 | avatarsCache[user.avatarId] = bmp 39 | bmp 40 | } else { 41 | avatarsCache[user.avatarId] 42 | } 43 | } 44 | 45 | fun clearMessages() { 46 | val adapter = OverlayService.instance.chatHeads.content.messagesAdapter 47 | adapter.messages = emptyList() 48 | adapter.notifyDataSetChanged() 49 | } 50 | 51 | fun addMessages(msgs: List) { 52 | notifications += msgs.size 53 | 54 | if (!baseHistoryLoaded) return 55 | 56 | val infos = ArrayList() 57 | val chatHeads = OverlayService.instance.chatHeads 58 | 59 | for (message in msgs) { 60 | val info = MessageInfo(message) 61 | infos.add(info) 62 | messages.add(info) 63 | } 64 | 65 | Thread { 66 | for (info in infos) { 67 | val bmp = cacheAvatar(info.author) 68 | runOnMainLoop { 69 | info.author.avatarBitmap = bmp 70 | } 71 | } 72 | }.start() 73 | 74 | if (chatHeads.activeChatHead?.guildInfo?.channelId == id) { 75 | val adapter = chatHeads.content.messagesAdapter 76 | val lm = chatHeads.content.layoutManager 77 | val startIndex = adapter.messages.lastIndex 78 | adapter.messages = messages 79 | adapter.notifyItemRangeInserted(startIndex, adapter.messages.lastIndex) 80 | 81 | if (lm.findLastVisibleItemPosition() >= startIndex - 1 && adapter.messages.lastIndex >= 0) { 82 | chatHeads.content.messagesView.smoothScrollToPosition(adapter.messages.lastIndex) 83 | } 84 | } 85 | } 86 | 87 | fun addMessage(msg: Message) { 88 | addMessages(listOf(msg)) 89 | } 90 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/ChatAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.content.Context 4 | import android.widget.TextView 5 | import android.support.v7.widget.RecyclerView 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.ImageView 10 | import com.sential.discordbubbles.R 11 | import com.sential.discordbubbles.client.* 12 | 13 | class ChatAdapter( 14 | private val context: Context, 15 | var messages: List 16 | ) : RecyclerView.Adapter() { 17 | override fun getItemCount(): Int { 18 | return messages.size 19 | } 20 | 21 | override fun getItemViewType(position: Int): Int { 22 | val message = messages[position] 23 | 24 | return if (position == 0 || message.author.name != messages[position - 1].author.name) { 25 | VIEW_TYPE_MESSAGE_HEADER 26 | } else { 27 | VIEW_TYPE_MESSAGE_TEXT 28 | } 29 | } 30 | 31 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 32 | if (viewType == VIEW_TYPE_MESSAGE_HEADER) { 33 | val view = LayoutInflater.from(parent.context) 34 | .inflate(R.layout.message_header, parent, false) 35 | return HeaderMessageHolder(view) 36 | } 37 | 38 | val view = LayoutInflater.from(parent.context) 39 | .inflate(R.layout.message, parent, false) 40 | return MessageHolder(view) 41 | } 42 | 43 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 44 | val message = messages[position] 45 | 46 | when (holder.itemViewType) { 47 | VIEW_TYPE_MESSAGE_HEADER -> (holder as HeaderMessageHolder).bind(message) 48 | VIEW_TYPE_MESSAGE_TEXT -> (holder as MessageHolder).bind(message) 49 | } 50 | } 51 | 52 | private inner class MessageHolder internal constructor(view: View) : 53 | RecyclerView.ViewHolder(view) { 54 | private val messageTextView: TextView = view.findViewById(R.id.message_body) 55 | 56 | internal fun bind(message: MessageInfo) { 57 | messageTextView.text = message.text 58 | } 59 | } 60 | 61 | private inner class HeaderMessageHolder internal constructor(view: View) : 62 | RecyclerView.ViewHolder(view) { 63 | private val messageTextView: TextView = view.findViewById(R.id.message_header_body) 64 | private val authorTextView: TextView = view.findViewById(R.id.message_header_author) 65 | private var avatarImageView: ImageView = view.findViewById(R.id.message_header_avatar) 66 | 67 | internal fun bind(message: MessageInfo) { 68 | messageTextView.text = message.text 69 | 70 | authorTextView.text = message.author.name 71 | 72 | avatarImageView.setImageBitmap(message.author.avatarBitmap) 73 | 74 | message.author.onAvatarChange = { 75 | avatarImageView.setImageBitmap(it) 76 | } 77 | } 78 | } 79 | 80 | companion object { 81 | private val VIEW_TYPE_MESSAGE_HEADER = 1 82 | private val VIEW_TYPE_MESSAGE_TEXT = 2 83 | } 84 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/OverlayService.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.app.* 4 | import android.content.BroadcastReceiver 5 | import android.content.Context 6 | import android.content.Intent 7 | import android.os.IBinder 8 | import android.view.* 9 | import android.content.IntentFilter 10 | import android.support.v4.app.NotificationCompat 11 | import android.graphics.Color 12 | import com.sential.discordbubbles.MainActivity 13 | import android.os.Build 14 | import android.support.annotation.RequiresApi 15 | import android.widget.Toast 16 | import com.sential.discordbubbles.R 17 | import com.sential.discordbubbles.client.Client 18 | 19 | class OverlayService : Service() { 20 | companion object { 21 | lateinit var instance: OverlayService 22 | var initialized = false 23 | } 24 | 25 | var token: String? = null 26 | 27 | lateinit var windowManager: WindowManager 28 | lateinit var chatHeads: ChatHeads 29 | 30 | var client: Client? = null 31 | 32 | private lateinit var innerReceiver: InnerReceiver 33 | 34 | override fun onCreate() { 35 | super.onCreate() 36 | 37 | instance = this 38 | initialized = true 39 | 40 | windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager 41 | 42 | chatHeads = ChatHeads(this) 43 | 44 | innerReceiver = InnerReceiver() 45 | val intentFilter = IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) 46 | registerReceiver(innerReceiver, intentFilter) 47 | 48 | val channelId = 49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 50 | createNotificationChannel("overlay_service", "Discord Chat Heads service") 51 | } else { 52 | "" 53 | } 54 | 55 | val notificationIntent = Intent(this, MainActivity::class.java) 56 | 57 | val pendingIntent = PendingIntent.getActivity( 58 | this, 0, 59 | notificationIntent, 0 60 | ) 61 | 62 | val notification = NotificationCompat.Builder(this, channelId) 63 | .setOngoing(true) 64 | .setContentTitle("Discord chat heads are active") 65 | .setSmallIcon(R.mipmap.ic_launcher) 66 | .setCategory(Notification.CATEGORY_SERVICE) 67 | .setContentIntent(pendingIntent).build() 68 | 69 | startForeground(101, notification) 70 | } 71 | 72 | @RequiresApi(Build.VERSION_CODES.O) 73 | private fun createNotificationChannel(channelId: String, channelName: String): String{ 74 | val chan = NotificationChannel(channelId, 75 | channelName, NotificationManager.IMPORTANCE_NONE) 76 | chan.lightColor = Color.BLUE 77 | chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE 78 | val service = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager 79 | service.createNotificationChannel(chan) 80 | return channelId 81 | } 82 | 83 | override fun onDestroy() { 84 | initialized = false 85 | client = null 86 | unregisterReceiver(innerReceiver) 87 | super.onDestroy() 88 | } 89 | 90 | override fun onBind(intent: Intent?): IBinder? { 91 | return null 92 | } 93 | 94 | override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { 95 | if (intent != null && token == null) { 96 | token = intent.extras?.getString("token") 97 | } 98 | 99 | if (client == null) { 100 | if (token != null) { 101 | client = Client(token!!) { 102 | Toast.makeText( 103 | this, "Logged in successfully", 104 | Toast.LENGTH_SHORT 105 | ).show() 106 | } 107 | } 108 | } 109 | 110 | return START_STICKY 111 | } 112 | } 113 | 114 | internal class InnerReceiver : BroadcastReceiver() { 115 | override fun onReceive(context: Context, intent: Intent) { 116 | val action = intent.action 117 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS == action) { 118 | val reason = intent.getStringExtra("reason") 119 | if (reason != null) { 120 | OverlayService.instance.chatHeads.collapse() 121 | } 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.net.Uri 6 | import android.support.v7.app.AppCompatActivity 7 | import android.os.Bundle 8 | import android.provider.Settings 9 | import com.sential.discordbubbles.chatheads.OverlayService 10 | import android.net.http.SslError 11 | import android.view.ViewGroup 12 | import android.webkit.* 13 | import android.webkit.PermissionRequest 14 | import com.sential.discordbubbles.client.Client 15 | import com.sential.discordbubbles.utils.runOnMainLoop 16 | import android.content.SharedPreferences 17 | import android.widget.Toast 18 | 19 | val REQUEST_CODE = 5469 20 | 21 | class MainActivity : AppCompatActivity() { 22 | private lateinit var webView: WebView 23 | 24 | private lateinit var cookieManager: CookieManager 25 | 26 | private lateinit var prefs: SharedPreferences 27 | 28 | private var token: String? = null 29 | 30 | override fun onCreate(savedInstanceState: Bundle?) { 31 | super.onCreate(savedInstanceState) 32 | setContentView(R.layout.activity_main) 33 | 34 | val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName")) 35 | 36 | if (!Settings.canDrawOverlays(this)) { 37 | startActivityForResult(intent, REQUEST_CODE) 38 | } 39 | 40 | webView = findViewById(R.id.webview) 41 | prefs = getSharedPreferences("data", Context.MODE_PRIVATE) 42 | 43 | token = prefs.getString("token", null) 44 | 45 | if (token == null) { 46 | showLogin() 47 | } else { 48 | login() 49 | destroyWebView() 50 | } 51 | } 52 | 53 | private fun showLogin() { 54 | webView.webViewClient = object : WebViewClient() { 55 | override fun shouldInterceptRequest( 56 | view: WebView, 57 | request: WebResourceRequest 58 | ): WebResourceResponse? { 59 | if (request.url.toString() == "https://discordapp.com/api/v6/users/@me/library") { 60 | token = request.requestHeaders.getValue("Authorization") 61 | val editor = prefs.edit() 62 | 63 | editor.putString("token", token) 64 | editor.apply() 65 | 66 | runOnMainLoop { 67 | Toast.makeText( 68 | this@MainActivity, "Obtained token, logging in...", 69 | Toast.LENGTH_LONG 70 | ).show() 71 | 72 | login() 73 | 74 | destroyWebView() 75 | } 76 | } 77 | 78 | return super.shouldInterceptRequest(view, request) 79 | } 80 | 81 | override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) { 82 | handler.proceed() 83 | } 84 | } 85 | 86 | webView.webChromeClient = object : WebChromeClient() { 87 | override fun onPermissionRequest(request: PermissionRequest) { 88 | request.grant(request.resources) 89 | } 90 | } 91 | 92 | webView.settings.javaScriptEnabled = true 93 | webView.settings.useWideViewPort = true 94 | webView.settings.loadWithOverviewMode = true 95 | webView.settings.domStorageEnabled = true 96 | 97 | cookieManager = CookieManager.getInstance() 98 | cookieManager.setAcceptThirdPartyCookies(webView, true) 99 | 100 | WebStorage.getInstance().deleteAllData() 101 | 102 | webView.loadUrl("https://discordapp.com/login") 103 | } 104 | 105 | fun destroyWebView() { 106 | WebStorage.getInstance().deleteAllData() 107 | webView.destroy() 108 | (webView.parent as ViewGroup).removeView(webView) 109 | } 110 | 111 | fun login() { 112 | if (token != null && !OverlayService.initialized && Settings.canDrawOverlays(this)) { 113 | val service = Intent(this, OverlayService::class.java) 114 | service.putExtra("token", token) 115 | startService(service) 116 | } 117 | } 118 | 119 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 120 | if (requestCode == REQUEST_CODE && Settings.canDrawOverlays(this)) { 121 | login() 122 | } 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/Close.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.graphics.* 4 | import android.support.v4.content.ContextCompat 5 | import android.view.* 6 | import android.widget.FrameLayout 7 | import android.widget.RelativeLayout 8 | import com.facebook.rebound.* 9 | import com.sential.discordbubbles.* 10 | import com.sential.discordbubbles.utils.* 11 | 12 | class Close(var chatHeads: ChatHeads): View(chatHeads.context) { 13 | private var params = WindowManager.LayoutParams( 14 | ChatHeads.CLOSE_SIZE + ChatHeads.CLOSE_ADDITIONAL_SIZE, 15 | ChatHeads.CLOSE_SIZE + ChatHeads.CLOSE_ADDITIONAL_SIZE, 16 | getOverlayFlag(), 17 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, 18 | PixelFormat.TRANSLUCENT 19 | ) 20 | 21 | private var gradientParams = FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dpToPx(150f)) 22 | 23 | var springSystem = SpringSystem.create() 24 | 25 | var springY = springSystem.createSpring() 26 | var springX = springSystem.createSpring() 27 | var springAlpha = springSystem.createSpring() 28 | var springScale = springSystem.createSpring() 29 | 30 | val paint = Paint() 31 | 32 | val gradient = FrameLayout(context) 33 | 34 | var hidden = true 35 | 36 | private var bitmapBg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(OverlayService.instance.resources, R.drawable.close_bg), ChatHeads.CLOSE_SIZE, ChatHeads.CLOSE_SIZE, false)!! 37 | private val bitmapClose = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(OverlayService.instance.resources, R.drawable.close), dpToPx(28f), dpToPx(28f), false)!! 38 | 39 | fun hide() { 40 | val metrics = getScreenSize() 41 | springY.endValue = metrics.heightPixels.toDouble() + height 42 | springX.endValue = metrics.widthPixels.toDouble() / 2 - width / 2 43 | 44 | springAlpha.endValue = 0.0 45 | hidden = true 46 | } 47 | 48 | fun show() { 49 | hidden = false 50 | visibility = View.VISIBLE 51 | 52 | springAlpha.endValue = 1.0 53 | resetScale() 54 | } 55 | 56 | fun enlarge() { 57 | springScale.endValue = ChatHeads.CLOSE_ADDITIONAL_SIZE.toDouble() 58 | } 59 | 60 | fun resetScale() { 61 | springScale.endValue = 1.0 62 | } 63 | 64 | fun onPositionUpdate() { 65 | if (chatHeads.closeCaptured && chatHeads.topChatHead != null) { 66 | chatHeads.topChatHead!!.springX.endValue = springX.endValue + width / 2 - chatHeads.topChatHead!!.params.width / 2 + 2 67 | chatHeads.topChatHead!!.springY.endValue = springY.endValue + height / 2 - chatHeads.topChatHead!!.params.height / 2 + 2 68 | } 69 | } 70 | 71 | init { 72 | this.setLayerType(View.LAYER_TYPE_HARDWARE, paint) 73 | 74 | visibility = View.INVISIBLE 75 | hide() 76 | 77 | springY.addListener(object : SimpleSpringListener() { 78 | override fun onSpringUpdate(spring: Spring) { 79 | y = spring.currentValue.toFloat() 80 | 81 | if (chatHeads.closeCaptured && chatHeads.wasMoving && chatHeads.topChatHead != null) { 82 | chatHeads.topChatHead!!.springY.currentValue = spring.currentValue 83 | } 84 | 85 | onPositionUpdate() 86 | } 87 | }) 88 | 89 | springX.addListener(object : SimpleSpringListener() { 90 | override fun onSpringUpdate(spring: Spring) { 91 | x = spring.currentValue.toFloat() 92 | 93 | onPositionUpdate() 94 | } 95 | }) 96 | 97 | springScale.addListener(object : SimpleSpringListener() { 98 | override fun onSpringUpdate(spring: Spring) { 99 | bitmapBg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(OverlayService.instance.resources, R.drawable.close_bg), (spring.currentValue + ChatHeads.CLOSE_SIZE).toInt(), (spring.currentValue + ChatHeads.CLOSE_SIZE).toInt(), false) 100 | invalidate() 101 | } 102 | }) 103 | 104 | springAlpha.addListener(object : SimpleSpringListener() { 105 | override fun onSpringUpdate(spring: Spring) { 106 | gradient.alpha = spring.currentValue.toFloat() 107 | } 108 | }) 109 | 110 | springScale.springConfig = SpringConfigs.CLOSE_SCALE 111 | springY.springConfig = SpringConfigs.CLOSE_Y 112 | 113 | params.gravity = Gravity.START or Gravity.TOP 114 | gradientParams.gravity = Gravity.BOTTOM 115 | 116 | gradient.background = ContextCompat.getDrawable(context, R.drawable.gradient_bg) 117 | springAlpha.currentValue = 0.0 118 | 119 | z = 100f 120 | 121 | chatHeads.addView(this, params) 122 | chatHeads.addView(gradient, gradientParams) 123 | } 124 | 125 | 126 | override fun onDraw(canvas: Canvas?) { 127 | canvas?.drawBitmap(bitmapBg, width / 2 - bitmapBg.width.toFloat() / 2, height / 2 - bitmapBg.height.toFloat() / 2, paint) 128 | canvas?.drawBitmap(bitmapClose, width / 2 - bitmapClose.width.toFloat() / 2, height / 2 - bitmapClose.height.toFloat() / 2, paint) 129 | } 130 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/ChatHead.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.view.* 4 | import android.widget.* 5 | import com.facebook.rebound.* 6 | import com.sential.discordbubbles.client.* 7 | import com.sential.discordbubbles.utils.* 8 | import kotlin.math.pow 9 | import android.text.Spannable 10 | import android.text.style.ForegroundColorSpan 11 | import android.text.SpannableString 12 | import android.graphics.* 13 | import com.sential.discordbubbles.R 14 | 15 | 16 | class ChatHead(var chatHeads: ChatHeads, var guildInfo: GuildInfo): FrameLayout(chatHeads.context), View.OnTouchListener, SpringListener { 17 | var params: WindowManager.LayoutParams = WindowManager.LayoutParams( 18 | WindowManager.LayoutParams.WRAP_CONTENT, 19 | WindowManager.LayoutParams.WRAP_CONTENT, 20 | getOverlayFlag(), 21 | 0, 22 | PixelFormat.TRANSLUCENT 23 | ) 24 | 25 | var springSystem: SpringSystem = SpringSystem.create() 26 | 27 | var springX: Spring = springSystem.createSpring() 28 | var springY: Spring = springSystem.createSpring() 29 | 30 | private val paint = Paint() 31 | 32 | private var initialX = 0.0f 33 | private var initialY = 0.0f 34 | 35 | private var initialTouchX = 0.0f 36 | private var initialTouchY = 0.0f 37 | 38 | private var moving = false 39 | 40 | private var notificationsTextView: TextView 41 | var notificationsView: LinearLayout 42 | 43 | var notifications = 0 44 | set(value) { 45 | if (value >= 0) field = value 46 | 47 | if (value == 0) { 48 | notificationsView.visibility = GONE 49 | } else if (value > 0) { 50 | notificationsView.visibility = VISIBLE 51 | notificationsTextView.text = "$value" 52 | } 53 | } 54 | 55 | override fun onSpringEndStateChange(spring: Spring?) = Unit 56 | override fun onSpringAtRest(spring: Spring?) = Unit 57 | override fun onSpringActivate(spring: Spring?) = Unit 58 | 59 | init { 60 | params.gravity = Gravity.TOP or Gravity.START 61 | params.x = 0 62 | params.y = 0 63 | params.width = ChatHeads.CHAT_HEAD_SIZE + 15 64 | params.height = ChatHeads.CHAT_HEAD_SIZE + 30 65 | 66 | val view = inflate(context, R.layout.bubble, this) 67 | 68 | val imageView: ImageView = view.findViewById(R.id.bubble_avatar) 69 | notificationsTextView = view.findViewById(R.id.bubble_notifications_text) 70 | notificationsView = view.findViewById(R.id.bubble_notifications) 71 | 72 | springX.addListener(object : SimpleSpringListener() { 73 | override fun onSpringUpdate(spring: Spring) { 74 | x = spring.currentValue.toFloat() 75 | } 76 | }) 77 | 78 | springX.springConfig = SpringConfigs.NOT_DRAGGING 79 | springX.addListener(this) 80 | 81 | springY.addListener(object : SimpleSpringListener() { 82 | override fun onSpringUpdate(spring: Spring) { 83 | y = spring.currentValue.toFloat() 84 | } 85 | }) 86 | springY.springConfig = SpringConfigs.NOT_DRAGGING 87 | springY.addListener(this) 88 | 89 | this.setLayerType(View.LAYER_TYPE_HARDWARE, paint) 90 | 91 | chatHeads.addView(this, params) 92 | 93 | this.setOnTouchListener(this) 94 | 95 | imageView.setImageBitmap(guildInfo.chatHeadBitmap) 96 | 97 | guildInfo.onAvatarChange = { 98 | imageView.setImageBitmap(guildInfo.chatHeadBitmap) 99 | } 100 | } 101 | 102 | fun updateNotifications() { 103 | notifications = guildInfo.channels.sumBy { it.notifications } 104 | 105 | if (chatHeads.activeChatHead == this) { 106 | val navView = chatHeads.content.navigationView 107 | for (i in 0 until navView.menu.size()) { 108 | val item = navView.menu.getItem(i) 109 | item.title = item.title.toString() 110 | } 111 | 112 | guildInfo.channels.forEach { 113 | if (it.notifications > 0) { 114 | val id = chatHeads.content.channelIdToMenuIdMap[it.id] 115 | if (id != null) { 116 | val item = navView.menu.getItem(id) 117 | 118 | val mNewTitle = SpannableString(item.title) 119 | mNewTitle.setSpan( 120 | ForegroundColorSpan(Color.WHITE), 121 | 0, 122 | mNewTitle.length, 123 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 124 | ) 125 | item.title = mNewTitle 126 | } 127 | } 128 | } 129 | } 130 | } 131 | 132 | override fun onSpringUpdate(spring: Spring) { 133 | if (spring !== this.springX && spring !== this.springY) return 134 | val totalVelocity = Math.hypot(springX.velocity, springY.velocity).toInt() 135 | 136 | chatHeads.onChatHeadSpringUpdate(this, spring, totalVelocity) 137 | } 138 | 139 | override fun onTouch(v: View?, event: MotionEvent?): Boolean { 140 | val currentChatHead = chatHeads.chatHeads.find { it == v }!! 141 | 142 | val metrics = getScreenSize() 143 | 144 | when (event!!.action) { 145 | MotionEvent.ACTION_DOWN -> { 146 | initialX = x 147 | initialY = y 148 | initialTouchX = event.rawX 149 | initialTouchY = event.rawY 150 | 151 | scaleX = 0.92f 152 | scaleY = 0.92f 153 | } 154 | MotionEvent.ACTION_UP -> { 155 | if (!moving) { 156 | if (currentChatHead == chatHeads.activeChatHead) { 157 | chatHeads.collapse() 158 | } else { 159 | chatHeads.activeChatHead = currentChatHead 160 | chatHeads.updateActiveContent() 161 | } 162 | } else { 163 | springX.endValue = metrics.widthPixels - width - chatHeads.chatHeads.indexOf(this) * (width + ChatHeads.CHAT_HEAD_EXPANDED_PADDING).toDouble() 164 | springY.endValue = ChatHeads.CHAT_HEAD_EXPANDED_MARGIN_TOP.toDouble() 165 | 166 | if (this == chatHeads.activeChatHead) { 167 | chatHeads.content.showContent() 168 | } 169 | } 170 | 171 | scaleX = 1f 172 | scaleY = 1f 173 | 174 | moving = false 175 | } 176 | MotionEvent.ACTION_MOVE -> { 177 | if (ChatHeads.distance(initialTouchX, event.rawX, initialTouchY, event.rawY) > ChatHeads.CHAT_HEAD_DRAG_TOLERANCE.pow(2) && !moving) { 178 | moving = true 179 | 180 | if (this == chatHeads.activeChatHead) { 181 | chatHeads.content.hideContent() 182 | } 183 | } 184 | 185 | if (moving) { 186 | springX.currentValue = initialX + (event.rawX - initialTouchX).toDouble() 187 | springY.currentValue = initialY + (event.rawY - initialTouchY).toDouble() 188 | } 189 | } 190 | } 191 | 192 | return true 193 | } 194 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/chat_head_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 18 | 22 | 30 | 38 | 45 | 46 | 53 | 58 | 68 | 79 | 88 | 89 | 90 | 91 | 99 | 106 | 107 | 108 | 109 | 114 | 115 | 121 | 138 | 146 | 147 | 153 | 154 | 155 | 156 | 167 | 168 | -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/Content.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.content.Context 4 | import android.view.View 5 | import android.view.animation.AlphaAnimation 6 | import android.view.animation.Animation 7 | import android.widget.* 8 | import com.facebook.rebound.SimpleSpringListener 9 | import com.facebook.rebound.Spring 10 | import com.facebook.rebound.SpringSystem 11 | import com.sential.discordbubbles.* 12 | import com.sential.discordbubbles.utils.* 13 | import android.content.pm.PackageManager 14 | import android.net.Uri 15 | import android.support.design.widget.NavigationView 16 | import android.support.v4.widget.DrawerLayout 17 | import android.support.v7.widget.LinearLayoutManager 18 | import android.support.v7.widget.RecyclerView 19 | import android.view.Gravity 20 | import com.sential.discordbubbles.client.Channel 21 | import net.dv8tion.jda.api.entities.ChannelType 22 | 23 | class Content(context: Context): LinearLayout(context) { 24 | private val springSystem = SpringSystem.create() 25 | private val scaleSpring = springSystem.createSpring() 26 | 27 | private var channelView: TextView 28 | private var hashTagView: TextView 29 | private var atView: TextView 30 | 31 | var messagesView: RecyclerView 32 | var messagesAdapter = ChatAdapter(this.context, emptyList()) 33 | var layoutManager = LinearLayoutManager(context) 34 | 35 | var navigationView: NavigationView 36 | var drawerLayout: DrawerLayout 37 | 38 | var menuBtn: LinearLayout 39 | 40 | val idToChannelIdMap = mutableMapOf() 41 | val channelIdToMenuIdMap = mutableMapOf() 42 | 43 | init { 44 | inflate(context, R.layout.chat_head_content, this) 45 | 46 | channelView = findViewById(R.id.channel) 47 | hashTagView = findViewById(R.id.hashtag) 48 | atView = findViewById(R.id.at) 49 | messagesView = findViewById(R.id.messages) 50 | navigationView = findViewById(R.id.navigation) 51 | drawerLayout = findViewById(R.id.drawer) 52 | menuBtn = findViewById(R.id.menu_btn) 53 | 54 | layoutManager.stackFromEnd = true 55 | 56 | messagesView.layoutManager = layoutManager 57 | messagesView.adapter = messagesAdapter 58 | 59 | navigationView.setNavigationItemSelectedListener { 60 | val id = idToChannelIdMap[it.itemId]!! 61 | val chatHead = OverlayService.instance.chatHeads.activeChatHead!! 62 | 63 | it.isChecked = true 64 | 65 | chatHead.guildInfo.channelId = id 66 | setInfo(chatHead) 67 | 68 | drawerLayout.closeDrawers() 69 | 70 | true 71 | } 72 | 73 | messagesView.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> 74 | if (layoutManager.findLastVisibleItemPosition() == messagesAdapter.messages.lastIndex) { 75 | val bubble = OverlayService.instance.chatHeads.activeChatHead 76 | bubble?.guildInfo?.channel?.notifications = 0 77 | bubble?.updateNotifications() 78 | } 79 | } 80 | 81 | val editText: EditText = findViewById(R.id.editText) 82 | val sendBtn: LinearLayout = findViewById(R.id.chat_send) 83 | val openExternalBtn: LinearLayout = findViewById(R.id.open_external) 84 | 85 | openExternalBtn.setOnClickListener { 86 | val bubble = OverlayService.instance.chatHeads.activeChatHead 87 | if (bubble != null) { 88 | val scope = if (bubble.guildInfo.channel?.type == ChannelType.PRIVATE) "@me" else bubble.guildInfo.id 89 | val url = "https://discordapp.com/channels/$scope/${bubble.guildInfo.channel?.id}" 90 | launchDiscord(url) 91 | } 92 | } 93 | 94 | sendBtn.setOnClickListener { 95 | val bubble = OverlayService.instance.chatHeads.activeChatHead 96 | if (!editText.text.isNullOrEmpty()) { 97 | // TODO: add mentioning users 98 | bubble?.guildInfo?.channel?.instance?.sendMessage(editText.text)?.queue() 99 | editText.text.clear() 100 | } 101 | } 102 | 103 | menuBtn.setOnClickListener { 104 | drawerLayout.openDrawer(Gravity.START) 105 | } 106 | 107 | scaleSpring.addListener(object : SimpleSpringListener() { 108 | override fun onSpringUpdate(spring: Spring) { 109 | scaleX = spring.currentValue.toFloat() 110 | scaleY = spring.currentValue.toFloat() 111 | } 112 | }) 113 | scaleSpring.springConfig = SpringConfigs.CONTENT_SCALE 114 | 115 | scaleSpring.currentValue = 0.0 116 | } 117 | 118 | fun setInfo(chatHead: ChatHead) { 119 | if (chatHead.guildInfo.channel?.type == ChannelType.PRIVATE) { 120 | atView.visibility = View.VISIBLE 121 | hashTagView.visibility = View.GONE 122 | channelView.text = chatHead.guildInfo.name 123 | menuBtn.visibility = View.GONE 124 | navigationView.visibility = View.GONE 125 | drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) 126 | } else { 127 | atView.visibility = View.GONE 128 | hashTagView.visibility = View.VISIBLE 129 | channelView.text = chatHead.guildInfo.channel?.instance?.name 130 | menuBtn.visibility = View.VISIBLE 131 | drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) 132 | navigationView.getHeaderView(0).findViewById(R.id.guild_name).text = chatHead.guildInfo.name 133 | } 134 | 135 | val channel = chatHead.guildInfo.channel!! 136 | if (!channel.baseHistoryLoaded) { 137 | Thread { 138 | chatHead.guildInfo.channel?.instance?.history?.retrievePast(50)?.queue { result -> 139 | runOnMainLoop { 140 | channel.addMessages(result.reversed()) 141 | } 142 | } 143 | }.start() 144 | channel.baseHistoryLoaded = true 145 | } 146 | 147 | messagesAdapter.messages = channel.messages 148 | messagesAdapter.notifyDataSetChanged() 149 | messagesView.scrollToPosition(messagesAdapter.messages.lastIndex) 150 | } 151 | 152 | fun updateNavigationDrawer(chatHead: ChatHead) { 153 | idToChannelIdMap.clear() 154 | navigationView.menu.clear() 155 | 156 | chatHead.guildInfo.channels.forEachIndexed { index, it -> 157 | val item = navigationView.menu.add(0, index, index, "# ${it.instance.name}") 158 | item.isCheckable = true 159 | if (chatHead.guildInfo.channelId == it.id) item.isChecked = true 160 | idToChannelIdMap[index] = it.id 161 | channelIdToMenuIdMap[it.id] = index 162 | } 163 | } 164 | 165 | fun launchDiscord(url: String) { 166 | val packageName = "com.discord" 167 | if (isAppInstalled(context, packageName)) 168 | if (isAppEnabled(context, packageName)) { 169 | val intent = context.packageManager.getLaunchIntentForPackage(packageName) 170 | if (intent != null) { 171 | intent.data = Uri.parse(url) 172 | context.startActivity(intent) 173 | OverlayService.instance.chatHeads.collapse() 174 | } 175 | } 176 | else 177 | Toast.makeText(context, "Discord app is not enabled.", Toast.LENGTH_SHORT).show() 178 | else 179 | Toast.makeText(context, "Discord app is not installed.", Toast.LENGTH_SHORT).show() 180 | } 181 | 182 | private fun isAppInstalled(context: Context, packageName: String): Boolean { 183 | val pm = context.packageManager 184 | try { 185 | pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES) 186 | return true 187 | } catch (ignored: PackageManager.NameNotFoundException) { 188 | } 189 | 190 | return false 191 | } 192 | 193 | private fun isAppEnabled(context: Context, packageName: String): Boolean { 194 | var appStatus = false 195 | try { 196 | val ai = context.packageManager.getApplicationInfo(packageName, 0) 197 | if (ai != null) { 198 | appStatus = ai.enabled 199 | } 200 | } catch (e: PackageManager.NameNotFoundException) { 201 | e.printStackTrace() 202 | } 203 | 204 | return appStatus 205 | } 206 | 207 | fun hideContent() { 208 | OverlayService.instance.chatHeads.handler.removeCallbacks( 209 | OverlayService.instance.chatHeads.showContentRunnable) 210 | 211 | scaleSpring.endValue = 0.0 212 | 213 | drawerLayout.closeDrawers() 214 | 215 | val anim = AlphaAnimation(1.0f, 0.0f) 216 | anim.duration = 200 217 | anim.repeatMode = Animation.RELATIVE_TO_SELF 218 | startAnimation(anim) 219 | } 220 | 221 | fun showContent() { 222 | scaleSpring.endValue = 1.0 223 | 224 | val anim = AlphaAnimation(0.0f, 1.0f) 225 | anim.duration = 100 226 | anim.repeatMode = Animation.RELATIVE_TO_SELF 227 | startAnimation(anim) 228 | } 229 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sential/discordbubbles/chatheads/ChatHeads.kt: -------------------------------------------------------------------------------- 1 | package com.sential.discordbubbles.chatheads 2 | 3 | import android.content.Context 4 | import android.graphics.* 5 | import android.view.* 6 | import android.widget.FrameLayout 7 | import android.widget.LinearLayout 8 | import android.view.VelocityTracker 9 | import com.facebook.rebound.Spring 10 | import com.facebook.rebound.SimpleSpringListener 11 | import com.facebook.rebound.SpringChain 12 | import com.sential.discordbubbles.client.GuildInfo 13 | import com.sential.discordbubbles.utils.* 14 | import java.util.* 15 | import kotlin.math.* 16 | 17 | class Rectangle(val x: Double, val y: Double, val w: Double, val h: Double) { 18 | private val OUT_LEFT = 1 19 | private val OUT_TOP = 2 20 | private val OUT_RIGHT = 4 21 | private val OUT_BOTTOM = 8 22 | 23 | fun outcode(x: Double, y: Double): Int { 24 | var out = 0 25 | 26 | when { 27 | w <= 0 -> out = out or (OUT_LEFT or OUT_RIGHT) 28 | x < this.x -> out = out or OUT_LEFT 29 | x > this.x + w -> out = out or OUT_RIGHT 30 | } 31 | when { 32 | h <= 0 -> out = out or (OUT_TOP or OUT_BOTTOM) 33 | y < this.y -> out = out or OUT_TOP 34 | y > this.y + h -> out = out or OUT_BOTTOM 35 | } 36 | return out 37 | } 38 | 39 | fun intersectsLine(x1: Double, y1: Double, x2: Double, y2: Double): Boolean { 40 | var x1 = x1 41 | var y1 = y1 42 | var out1: Int 43 | val out2: Int = outcode(x2, y2) 44 | if (out2 == 0) { 45 | return true 46 | } 47 | do { 48 | out1 = outcode(x1, y1) 49 | 50 | if (out1 == 0) break 51 | 52 | if (out1 and out2 != 0) { 53 | return false 54 | } 55 | if (out1 and (OUT_LEFT or OUT_RIGHT) != 0) { 56 | var x = x 57 | if (out1 and OUT_RIGHT != 0) { 58 | x += w 59 | } 60 | y1 += (x - x1) * (y2 - y1) / (x2 - x1) 61 | x1 = x 62 | } else { 63 | var y = y 64 | if (out1 and OUT_BOTTOM != 0) { 65 | y += h 66 | } 67 | x1 += (y - y1) * (x2 - x1) / (y2 - y1) 68 | y1 = y 69 | } 70 | } while (true) 71 | 72 | return true 73 | } 74 | } 75 | 76 | class Line(val x1: Double, val y1: Double, var x2: Double, var y2: Double) { 77 | fun intersects(r: Rectangle): Boolean { 78 | return r.intersectsLine(x1, y1, x2, y2) 79 | } 80 | 81 | private fun f(x: Double): Double { 82 | val slope = (y2 - y1) / (x2 - x1) 83 | return y1 + (x - x1) * slope 84 | } 85 | 86 | fun changeLength(length: Double): Line { 87 | val newX1 = x1 - length / 2 88 | val newX2 = x2 - length / 2 89 | return Line(newX1, f(newX1), newX2, f(newX2)) 90 | } 91 | } 92 | 93 | class ChatHeads(context: Context) : View.OnTouchListener, FrameLayout(context) { 94 | companion object { 95 | val CHAT_HEAD_OUT_OF_SCREEN_X: Int = dpToPx(10f) 96 | val CHAT_HEAD_SIZE: Int = dpToPx(62f) 97 | val CHAT_HEAD_PADDING: Int = dpToPx(6f) 98 | val CHAT_HEAD_EXPANDED_PADDING: Int = dpToPx(4f) 99 | val CHAT_HEAD_EXPANDED_MARGIN_TOP: Float = dpToPx(6f).toFloat() 100 | val CLOSE_SIZE = dpToPx(64f) 101 | val CLOSE_CAPTURE_DISTANCE = dpToPx(100f) 102 | val CLOSE_CAPTURE_DISTANCE_THROWN = dpToPx(300f) 103 | val CLOSE_ADDITIONAL_SIZE = dpToPx(24f) 104 | 105 | const val CHAT_HEAD_DRAG_TOLERANCE: Float = 20f 106 | 107 | fun distance(x1: Float, x2: Float, y1: Float, y2: Float): Float { 108 | return ((x1 - x2).pow(2) + (y1-y2).pow(2)) 109 | } 110 | } 111 | 112 | var chatHeads = ArrayList() 113 | 114 | var wasMoving = false 115 | var closeCaptured = false 116 | 117 | private var closeVelocityCaptured = false 118 | 119 | private var movingOutOfClose = false 120 | 121 | private var initialX = 0.0f 122 | private var initialY = 0.0f 123 | 124 | private var initialTouchX = 0.0f 125 | private var initialTouchY = 0.0f 126 | 127 | var initialVelocityX = 0.0 128 | var initialVelocityY = 0.0 129 | 130 | private var lastY = 0.0 131 | 132 | private var moving = false 133 | private var toggled = false 134 | private var motionTrackerUpdated = false 135 | private var collapsing = false 136 | private var blockAnim = false 137 | 138 | private var horizontalSpringChain: SpringChain? = null 139 | private var verticalSpringChain: SpringChain? = null 140 | 141 | private var isOnRight = true 142 | set(value) { 143 | field = value 144 | 145 | chatHeads.forEach{ 146 | val lp = it.notificationsView.layoutParams as LayoutParams 147 | lp.gravity = if (value) Gravity.LEFT else Gravity.RIGHT 148 | it.notificationsView.layoutParams = lp 149 | } 150 | } 151 | 152 | private var velocityTracker: VelocityTracker? = null 153 | 154 | private var motionTracker = LinearLayout(context) 155 | 156 | private var detectedOutOfBounds = false 157 | 158 | private var animatingChatHeadInExpandedView = false 159 | 160 | var showContentRunnable: Runnable? = null 161 | 162 | var topChatHead: ChatHead? = null 163 | var activeChatHead: ChatHead? = null 164 | 165 | var content = Content(context) 166 | private var close = Close(this) 167 | 168 | private var motionTrackerParams = WindowManager.LayoutParams( 169 | CHAT_HEAD_SIZE, 170 | CHAT_HEAD_SIZE + 16, 171 | getOverlayFlag(), 172 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, 173 | PixelFormat.TRANSLUCENT 174 | ) 175 | 176 | private var params = WindowManager.LayoutParams( 177 | WindowManager.LayoutParams.MATCH_PARENT, 178 | WindowManager.LayoutParams.MATCH_PARENT, 179 | getOverlayFlag(), 180 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, 181 | PixelFormat.TRANSLUCENT 182 | ) 183 | 184 | init { 185 | params.gravity = Gravity.START or Gravity.TOP 186 | params.dimAmount = 0.7f 187 | 188 | motionTrackerParams.gravity = Gravity.START or Gravity.TOP 189 | 190 | OverlayService.instance.windowManager.addView(motionTracker, motionTrackerParams) 191 | OverlayService.instance.windowManager.addView(this, params) 192 | this.addView(content) 193 | 194 | isFocusableInTouchMode = true 195 | 196 | motionTracker.setOnTouchListener(this) 197 | 198 | setOnTouchListener{ v, event -> 199 | v.performClick() 200 | 201 | when (event.action) { 202 | MotionEvent.ACTION_UP -> { 203 | if (v == this) { 204 | collapse() 205 | } 206 | } 207 | } 208 | 209 | return@setOnTouchListener false 210 | } 211 | } 212 | 213 | override fun dispatchKeyEvent(event: KeyEvent): Boolean { 214 | return if (event.keyCode == KeyEvent.KEYCODE_BACK) { 215 | collapse() 216 | true 217 | } else super.dispatchKeyEvent(event) 218 | } 219 | 220 | fun setTop(chatHead: ChatHead?) { 221 | destroySpringChains() 222 | 223 | if (chatHead == null) { 224 | topChatHead = null 225 | return 226 | } 227 | 228 | chatHeads[chatHeads.indexOf(chatHead)] = chatHeads[0] 229 | chatHeads[0] = chatHead 230 | 231 | topChatHead = chatHead 232 | 233 | resetSpringChains() 234 | } 235 | 236 | private fun destroySpringChains() { 237 | if (horizontalSpringChain != null) { 238 | for (spring in horizontalSpringChain!!.allSprings) { 239 | spring.destroy() 240 | } 241 | } 242 | 243 | if (verticalSpringChain != null) { 244 | for (spring in verticalSpringChain!!.allSprings) { 245 | spring.destroy() 246 | } 247 | } 248 | 249 | verticalSpringChain = null 250 | horizontalSpringChain = null 251 | } 252 | 253 | 254 | private fun resetSpringChains() { 255 | destroySpringChains() 256 | 257 | horizontalSpringChain = SpringChain.create(0, 0, 200, 15) 258 | verticalSpringChain = SpringChain.create(0, 0, 200, 15) 259 | 260 | chatHeads.forEachIndexed { index, element -> 261 | element.z = (chatHeads.size - 1 - index).toFloat() 262 | 263 | if (index == 0) { 264 | horizontalSpringChain!!.addSpring(object : SimpleSpringListener() { }) 265 | verticalSpringChain!!.addSpring(object : SimpleSpringListener() { }) 266 | 267 | horizontalSpringChain!!.setControlSpringIndex(index) 268 | verticalSpringChain!!.setControlSpringIndex(index) 269 | } else { 270 | horizontalSpringChain!!.addSpring(object : SimpleSpringListener() { 271 | override fun onSpringUpdate(spring: Spring?) { 272 | if (!toggled && !blockAnim) { 273 | if (collapsing) { 274 | element.springX.endValue = spring!!.endValue + index * CHAT_HEAD_PADDING * if (isOnRight) 1 else -1 275 | } else { 276 | element.springX.currentValue = spring!!.currentValue + index * CHAT_HEAD_PADDING * if (isOnRight) 1 else -1 277 | } 278 | } 279 | 280 | if (spring?.currentValue == spring?.endValue) { 281 | animatingChatHeadInExpandedView = false 282 | } 283 | } 284 | }) 285 | verticalSpringChain!!.addSpring(object : SimpleSpringListener() { 286 | override fun onSpringUpdate(spring: Spring?) { 287 | if (!toggled && !blockAnim) { 288 | element.springY.currentValue = spring!!.currentValue 289 | } 290 | } 291 | }) 292 | } 293 | } 294 | } 295 | 296 | fun add(guildInfo: GuildInfo): ChatHead { 297 | var chatHead = chatHeads.find { it.guildInfo.id == guildInfo.id } 298 | val newChatHead = chatHead == null 299 | 300 | val metrics = getScreenSize() 301 | 302 | var lx = metrics.widthPixels - CHAT_HEAD_SIZE - 16 + CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 303 | var ly = 0.0 304 | 305 | if (chatHead == null) { 306 | chatHeads.forEach { 307 | it.visibility = View.VISIBLE 308 | } 309 | 310 | chatHead = ChatHead(this, guildInfo) 311 | chatHeads.add(chatHead) 312 | } 313 | 314 | if (topChatHead != null) { 315 | lx = topChatHead!!.springX.currentValue 316 | ly = topChatHead!!.springY.currentValue 317 | } 318 | 319 | setTop(chatHead) 320 | 321 | if (!toggled) { 322 | if (!moving) blockAnim = true 323 | 324 | chatHeads.forEachIndexed { index, element -> 325 | element.springX.currentValue = lx + index * CHAT_HEAD_PADDING * if (isOnRight) 1 else -1 326 | element.springY.currentValue = ly 327 | } 328 | 329 | motionTrackerParams.x = chatHead.springX.currentValue.toInt() 330 | motionTrackerParams.y = chatHead.springY.currentValue.toInt() 331 | motionTrackerParams.flags = motionTrackerParams.flags and WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE.inv() 332 | 333 | OverlayService.instance.windowManager.updateViewLayout(motionTracker, motionTrackerParams) 334 | } else { 335 | if (newChatHead) { 336 | chatHead.springX.currentValue = metrics.widthPixels.toDouble() 337 | chatHead.springY.currentValue = ly 338 | 339 | chatHead.springX.endValue = lx 340 | } 341 | 342 | animatingChatHeadInExpandedView = true 343 | rearrangeExpanded(true) 344 | } 345 | 346 | return chatHead 347 | } 348 | 349 | fun collapse() { 350 | toggled = false 351 | collapsing = true 352 | 353 | val metrics = getScreenSize() 354 | 355 | if (topChatHead != null) { 356 | val newX = if (isOnRight) metrics.widthPixels - topChatHead!!.width + CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() else -CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 357 | val newY = initialY.toDouble() 358 | 359 | topChatHead!!.springX.endValue = newX 360 | topChatHead!!.springY.endValue = newY 361 | } 362 | 363 | activeChatHead = null 364 | 365 | content.hideContent() 366 | 367 | motionTrackerParams.flags = motionTrackerParams.flags and WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE.inv() 368 | OverlayService.instance.windowManager.updateViewLayout(motionTracker, motionTrackerParams) 369 | 370 | params.flags = (params.flags or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) and 371 | WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv() and 372 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL.inv() or 373 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 374 | 375 | OverlayService.instance.windowManager.updateViewLayout(this, params) 376 | } 377 | 378 | fun updateActiveContent() { 379 | if (activeChatHead == null) return 380 | content.setInfo(activeChatHead!!) 381 | content.updateNavigationDrawer(activeChatHead!!) 382 | } 383 | 384 | private fun onClose() { 385 | removeAll() 386 | 387 | closeCaptured = false 388 | movingOutOfClose = false 389 | } 390 | 391 | fun removeAll() { 392 | setTop(null) 393 | chatHeads.forEach { 394 | this.removeView(it) 395 | } 396 | chatHeads.clear() 397 | } 398 | 399 | fun remove(chatHead: ChatHead?) { 400 | if (chatHead == null || chatHeads.size == 0) return 401 | 402 | if (chatHeads.size == 1) { 403 | setTop(null) 404 | } else if (topChatHead == chatHead) { 405 | setTop(chatHeads[1]) 406 | } 407 | 408 | this.removeView(chatHead) 409 | chatHeads.remove(chatHead) 410 | } 411 | 412 | fun rearrangeExpanded(animation: Boolean = true) { 413 | val metrics = getScreenSize() 414 | 415 | chatHeads.forEachIndexed { index, it -> 416 | it.springX.springConfig = SpringConfigs.NOT_DRAGGING 417 | it.springY.springConfig = SpringConfigs.NOT_DRAGGING 418 | 419 | val x = metrics.widthPixels - topChatHead!!.params.width.toDouble() - index * (it.params.width + CHAT_HEAD_EXPANDED_PADDING).toDouble() 420 | val y = CHAT_HEAD_EXPANDED_MARGIN_TOP.toDouble() 421 | 422 | if (animation) { 423 | it.springY.endValue = y 424 | it.springX.endValue = x 425 | } else { 426 | it.springY.currentValue = y 427 | it.springX.currentValue = x 428 | } 429 | } 430 | } 431 | 432 | fun onChatHeadSpringUpdate(chatHead: ChatHead, spring: Spring, totalVelocity: Int) { 433 | val metrics = getScreenSize() 434 | 435 | if (topChatHead != null && chatHead == topChatHead!!) { 436 | if (horizontalSpringChain != null && spring == chatHead.springX) { 437 | horizontalSpringChain!!.controlSpring.currentValue = spring.currentValue 438 | } 439 | 440 | if (verticalSpringChain != null && spring == chatHead.springY) { 441 | verticalSpringChain!!.controlSpring.currentValue = spring.currentValue 442 | } 443 | } 444 | 445 | // Moving content with active chat head 446 | var tmpChatHead: ChatHead? = null 447 | if (collapsing) tmpChatHead = topChatHead!! 448 | else if (chatHead == activeChatHead) tmpChatHead = chatHead 449 | 450 | if (tmpChatHead != null) { 451 | // Whether the content should follow chat head x 452 | val x = (if (animatingChatHeadInExpandedView) tmpChatHead.springX.endValue else tmpChatHead.springX.currentValue).toFloat() 453 | 454 | content.x = x - metrics.widthPixels.toFloat() + chatHeads.indexOf(tmpChatHead) * (tmpChatHead.params.width + CHAT_HEAD_EXPANDED_PADDING) + tmpChatHead.params.width 455 | content.y = tmpChatHead.springY.currentValue.toFloat() - CHAT_HEAD_EXPANDED_MARGIN_TOP 456 | content.pivotX = metrics.widthPixels.toFloat() - chatHead.width / 2 - chatHeads.indexOf(tmpChatHead) * (tmpChatHead.params.width + CHAT_HEAD_EXPANDED_PADDING) 457 | } 458 | 459 | content.pivotY = chatHead.height.toFloat() 460 | 461 | if (topChatHead != null) { 462 | val width = dpToPx(100f) 463 | val height = dpToPx(50f) 464 | val r1 = Rectangle(close.x.toDouble() - if (isOnRight) dpToPx(32f) else width, close.y.toDouble() - height / 2, close.width.toDouble() + width, close.height.toDouble() + height) 465 | 466 | val x = topChatHead!!.springX.currentValue + topChatHead!!.params.width / 2 467 | val y = topChatHead!!.springY.currentValue + topChatHead!!.params.height / 2 468 | val l1 = Line(x, y, initialVelocityX + x, initialVelocityY + y) 469 | 470 | // When a chat head has been thrown towards close 471 | if ( 472 | !moving && 473 | initialVelocityY > 5000.0 && 474 | l1.intersects(r1) && 475 | close.visibility == VISIBLE && 476 | !closeVelocityCaptured 477 | ) { 478 | closeVelocityCaptured = true 479 | 480 | topChatHead!!.springX.endValue = close.springX.endValue + close.width / 2 - topChatHead!!.params.width / 2 + 2 481 | topChatHead!!.springY.endValue = close.springY.endValue + close.height / 2 - topChatHead!!.params.height / 2 + 2 482 | 483 | close.enlarge() 484 | 485 | postDelayed({ 486 | onClose() 487 | }, 100) 488 | } 489 | } 490 | 491 | if (wasMoving) { 492 | motionTrackerParams.x = if (isOnRight) metrics.widthPixels - chatHead.width else 0 493 | 494 | lastY = chatHead.springY.currentValue 495 | 496 | if (!detectedOutOfBounds && !closeCaptured && !closeVelocityCaptured) { 497 | if (chatHead.springY.currentValue < 0) { 498 | chatHead.springY.endValue = 0.0 499 | detectedOutOfBounds = true 500 | } else if (chatHead.springY.currentValue > metrics.heightPixels) { 501 | chatHead.springY.endValue = metrics.heightPixels - CHAT_HEAD_SIZE.toDouble() 502 | detectedOutOfBounds = true 503 | } 504 | } 505 | 506 | if (!moving) { 507 | if (spring === chatHead.springX) { 508 | val xPosition = chatHead.springX.currentValue 509 | if (xPosition + chatHead.width > metrics.widthPixels && chatHead.springX.velocity > 0) { 510 | val newPos = metrics.widthPixels - chatHead.width + CHAT_HEAD_OUT_OF_SCREEN_X 511 | chatHead.springX.springConfig = SpringConfigs.NOT_DRAGGING 512 | chatHead.springX.endValue = newPos.toDouble() 513 | isOnRight = true 514 | } else if (xPosition < 0 && chatHead.springX.velocity < 0) { 515 | chatHead.springX.springConfig = SpringConfigs.NOT_DRAGGING 516 | chatHead.springX.endValue = -CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 517 | isOnRight = false 518 | } 519 | } else if (spring === chatHead.springY) { 520 | val yPosition = chatHead.springY.currentValue 521 | if (yPosition + chatHead.height > metrics.heightPixels && chatHead.springY.velocity > 0) { 522 | chatHead.springY.springConfig = SpringConfigs.NOT_DRAGGING 523 | chatHead.springY.endValue = metrics.heightPixels - chatHead.height.toDouble() - dpToPx(25f) 524 | } else if (yPosition < 0 && chatHead.springY.velocity < 0) { 525 | chatHead.springY.springConfig = SpringConfigs.NOT_DRAGGING 526 | chatHead.springY.endValue = 0.0 527 | } 528 | } 529 | } 530 | 531 | if (Math.abs(totalVelocity) % 10 == 0 && !moving && topChatHead != null) { 532 | motionTrackerParams.y = topChatHead!!.springY.currentValue.toInt() 533 | 534 | OverlayService.instance.windowManager.updateViewLayout(motionTracker, motionTrackerParams) 535 | } 536 | } 537 | } 538 | 539 | override fun onTouch(v: View?, event: MotionEvent?): Boolean { 540 | val metrics = getScreenSize() 541 | 542 | if (topChatHead == null) return true 543 | 544 | when (event!!.action) { 545 | MotionEvent.ACTION_DOWN -> { 546 | initialX = topChatHead!!.springX.currentValue.toFloat() 547 | initialY = topChatHead!!.springY.currentValue.toFloat() 548 | initialTouchX = event.rawX 549 | initialTouchY = event.rawY 550 | 551 | wasMoving = false 552 | collapsing = false 553 | blockAnim = false 554 | detectedOutOfBounds = false 555 | closeVelocityCaptured = false 556 | 557 | close.show() 558 | 559 | topChatHead!!.scaleX = 0.92f 560 | topChatHead!!.scaleY = 0.92f 561 | 562 | topChatHead!!.springX.springConfig = SpringConfigs.DRAGGING 563 | topChatHead!!.springY.springConfig = SpringConfigs.DRAGGING 564 | 565 | topChatHead!!.springX.setAtRest() 566 | topChatHead!!.springY.setAtRest() 567 | 568 | motionTrackerUpdated = false 569 | 570 | if (velocityTracker == null) { 571 | velocityTracker = VelocityTracker.obtain() 572 | } else { 573 | velocityTracker?.clear() 574 | } 575 | 576 | velocityTracker?.addMovement(event) 577 | } 578 | MotionEvent.ACTION_UP -> { 579 | if (moving) wasMoving = true 580 | 581 | postDelayed({ 582 | close.hide() 583 | }, 100) 584 | 585 | if (closeCaptured) { 586 | onClose() 587 | return true 588 | } 589 | 590 | if (!moving) { 591 | if (!toggled) { 592 | toggled = true 593 | 594 | rearrangeExpanded() 595 | 596 | motionTrackerParams.flags = motionTrackerParams.flags or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 597 | OverlayService.instance.windowManager.updateViewLayout(motionTracker, motionTrackerParams) 598 | 599 | params.flags = (params.flags and WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE.inv()) or WindowManager.LayoutParams.FLAG_DIM_BEHIND and WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL.inv() and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.inv() 600 | OverlayService.instance.windowManager.updateViewLayout(this, params) 601 | 602 | activeChatHead = topChatHead 603 | 604 | updateActiveContent() 605 | 606 | handler.removeCallbacks(showContentRunnable) 607 | 608 | showContentRunnable = Runnable { 609 | content.showContent() 610 | } 611 | 612 | handler.postDelayed(showContentRunnable, 200) 613 | } 614 | } else if (!toggled) { 615 | moving = false 616 | 617 | var xVelocity = velocityTracker!!.xVelocity.toDouble() 618 | var yVelocity = velocityTracker!!.yVelocity.toDouble() 619 | var maxVelocityX = 0.0 620 | 621 | velocityTracker?.recycle() 622 | velocityTracker = null 623 | 624 | if (xVelocity < -3500) { 625 | val newVelocity = ((-topChatHead!!.springX.currentValue - CHAT_HEAD_OUT_OF_SCREEN_X) * SpringConfigs.DRAGGING.friction) 626 | maxVelocityX = newVelocity - 5000 627 | if (xVelocity > maxVelocityX) 628 | xVelocity = newVelocity - 500 629 | } else if (xVelocity > 3500) { 630 | val newVelocity = ((metrics.widthPixels - topChatHead!!.springX.currentValue - topChatHead!!.width + CHAT_HEAD_OUT_OF_SCREEN_X) * SpringConfigs.DRAGGING.friction) 631 | maxVelocityX = newVelocity + 5000 632 | if (maxVelocityX > xVelocity) 633 | xVelocity = newVelocity + 500 634 | } else if (yVelocity > 20 || yVelocity < -20) { 635 | topChatHead!!.springX.springConfig = SpringConfigs.NOT_DRAGGING 636 | 637 | if (topChatHead!!.x >= metrics.widthPixels / 2) { 638 | topChatHead!!.springX.endValue = metrics.widthPixels - topChatHead!!.width + CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 639 | isOnRight = true 640 | } else { 641 | topChatHead!!.springX.endValue = -CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 642 | 643 | isOnRight = false 644 | } 645 | } else { 646 | topChatHead!!.springX.springConfig = SpringConfigs.NOT_DRAGGING 647 | topChatHead!!.springY.springConfig = SpringConfigs.NOT_DRAGGING 648 | 649 | if (topChatHead!!.x >= metrics.widthPixels / 2) { 650 | topChatHead!!.springX.endValue = metrics.widthPixels - topChatHead!!.width + 651 | CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 652 | topChatHead!!.springY.endValue = topChatHead!!.y.toDouble() 653 | 654 | isOnRight = true 655 | } else { 656 | topChatHead!!.springX.endValue = -CHAT_HEAD_OUT_OF_SCREEN_X.toDouble() 657 | topChatHead!!.springY.endValue = topChatHead!!.y.toDouble() 658 | 659 | isOnRight = false 660 | } 661 | } 662 | 663 | xVelocity = if (xVelocity < 0) { 664 | max(xVelocity - 1000.0, maxVelocityX) 665 | } else { 666 | min(xVelocity + 1000.0, maxVelocityX) 667 | } 668 | 669 | initialVelocityX = xVelocity 670 | initialVelocityY = yVelocity 671 | 672 | topChatHead!!.springX.velocity = xVelocity 673 | topChatHead!!.springY.velocity = yVelocity 674 | } 675 | 676 | topChatHead!!.scaleX = 1f 677 | topChatHead!!.scaleY = 1f 678 | } 679 | MotionEvent.ACTION_MOVE -> { 680 | if (distance(initialTouchX, event.rawX, initialTouchY, event.rawY) > CHAT_HEAD_DRAG_TOLERANCE.pow(2)) { 681 | moving = true 682 | } 683 | 684 | velocityTracker?.addMovement(event) 685 | 686 | if (moving) { 687 | close.springX.endValue = (metrics.widthPixels / 2) + (((event.rawX + topChatHead!!.width / 2) / 7) - metrics.widthPixels / 2 / 7) - close.width.toDouble() / 2 688 | close.springY.endValue = (metrics.heightPixels - CLOSE_SIZE) + max(((event.rawY + close.height / 2) / 10) - metrics.heightPixels / 10, -dpToPx(30f).toFloat()) - dpToPx(60f).toDouble() 689 | 690 | if (distance(close.springX.endValue.toFloat() + close.width / 2, event.rawX, close.springY.endValue.toFloat() + close.height / 2, event.rawY) < CLOSE_CAPTURE_DISTANCE.toDouble().pow(2)) { 691 | topChatHead!!.springX.springConfig = SpringConfigs.CAPTURING 692 | topChatHead!!.springY.springConfig = SpringConfigs.CAPTURING 693 | 694 | close.enlarge() 695 | 696 | closeCaptured = true 697 | } else if (closeCaptured) { 698 | topChatHead!!.springX.springConfig = SpringConfigs.CAPTURING 699 | topChatHead!!.springY.springConfig = SpringConfigs.CAPTURING 700 | 701 | close.resetScale() 702 | 703 | topChatHead!!.springX.endValue = initialX + (event.rawX - initialTouchX).toDouble() 704 | topChatHead!!.springY.endValue = initialY + (event.rawY - initialTouchY).toDouble() 705 | 706 | closeCaptured = false 707 | 708 | movingOutOfClose = true 709 | 710 | postDelayed({ 711 | movingOutOfClose = false 712 | }, 100) 713 | } else if (!movingOutOfClose) { 714 | topChatHead!!.springX.springConfig = SpringConfigs.DRAGGING 715 | topChatHead!!.springY.springConfig = SpringConfigs.DRAGGING 716 | 717 | topChatHead!!.springX.currentValue = initialX + (event.rawX - initialTouchX).toDouble() 718 | topChatHead!!.springY.currentValue = initialY + (event.rawY - initialTouchY).toDouble() 719 | 720 | velocityTracker?.computeCurrentVelocity(2000) 721 | } 722 | } 723 | } 724 | } 725 | 726 | return true 727 | } 728 | } 729 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | Chat heads for Discord 635 | Copyright (C) 2020 Eryk Rakowski 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Discord Bubbles Copyright (C) 2020 Eryk Rakowski 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------