├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── profile.png
│ │ │ ├── profile_decorator.png
│ │ │ └── bubble_counter_bkg.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── bubble_trash_background.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── bubble_trash_background.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── bubble_trash_background.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── bubble_trash_background.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── bubble_trash_background.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── colors.xml
│ │ └── layout
│ │ │ ├── bubble_trash_layout.xml
│ │ │ ├── activity_main.xml
│ │ │ └── bubble_layout.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── txusballesteros
│ │ └── bubbles
│ │ └── app
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── bubbles
├── .gitignore
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── txusballesteros
│ │ │ └── bubbles
│ │ │ ├── OnInitializedCallback.java
│ │ │ ├── BubbleBaseLayout.java
│ │ │ ├── BubbleTrashLayout.java
│ │ │ ├── BubblesManager.java
│ │ │ ├── BubblesLayoutCoordinator.java
│ │ │ ├── BubblesService.java
│ │ │ └── BubbleLayout.java
│ │ ├── AndroidManifest.xml
│ │ └── res
│ │ └── animator
│ │ ├── bubble_shown_animator.xml
│ │ ├── bubble_up_click_animator.xml
│ │ ├── bubble_down_click_animator.xml
│ │ ├── bubble_trash_shown_animator.xml
│ │ ├── bubble_trash_hide_animator.xml
│ │ ├── bubble_trash_hide_magnetism_animator.xml
│ │ └── bubble_trash_shown_magnetism_animator.xml
└── build.gradle
├── settings.gradle
├── assets
├── bubbles_demo.gif
└── Bubble_Trash_Decorator.psd
├── gradle.properties
├── .gitignore
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/bubbles/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':bubbles'
2 |
--------------------------------------------------------------------------------
/assets/bubbles_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/assets/bubbles_demo.gif
--------------------------------------------------------------------------------
/assets/Bubble_Trash_Decorator.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/assets/Bubble_Trash_Decorator.psd
--------------------------------------------------------------------------------
/app/src/main/res/drawable/profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/drawable/profile.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/profile_decorator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/drawable/profile_decorator.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bubble_trash_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-hdpi/bubble_trash_background.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/bubble_trash_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-mdpi/bubble_trash_background.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/bubble_trash_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-xhdpi/bubble_trash_background.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/bubble_trash_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-xxhdpi/bubble_trash_background.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/bubble_trash_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/txusballesteros/bubbles-for-android/HEAD/app/src/main/res/mipmap-xxxhdpi/bubble_trash_background.png
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/txus/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/bubbles/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/txus/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.txusballesteros.bubbles.app"
9 | minSdkVersion 14
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName parent.ext.libraryVersion
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:22.2.0'
25 | compile project(':bubbles')
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 | Bubbles
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/OnInitializedCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | public interface OnInitializedCallback {
28 | void onInitialized();
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 | 16dp
28 | 16dp
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bubble_counter_bkg.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bubble_trash_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Copyright: Benjamin Weiss (keyboardsurfer) https://github.com/keyboardsurfer
2 | # Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
3 |
4 | # built application files
5 | *.apk
6 | *.ap_
7 |
8 | # lint folder
9 | lint
10 |
11 | # files for the dex VM
12 | *.dex
13 |
14 | # Java class files
15 | *.class
16 |
17 | # generated files
18 | bin/
19 | gen/
20 | classes/
21 | gen-external-apklibs/
22 |
23 | # maven output folder
24 | target
25 |
26 | # Local configuration file (sdk path, etc)
27 | local.properties
28 |
29 | # Eclipse project files
30 | .classpath
31 | .project
32 | .metadata
33 | .settings
34 |
35 | # IntelliJ files
36 | .idea
37 | *.iml
38 |
39 | # OSX files
40 | .DS_Store
41 |
42 | # Windows files
43 | Thumbs.db
44 |
45 | # vi swap files
46 | *.swp
47 |
48 | # backup files
49 | *.bak
50 |
51 | # gradle directory
52 | .gradle
53 | gradlew
54 | gradlew.bat
55 | gradle/
56 | build/
57 | captures/
58 |
59 | #for oh-my-zsh jira plugin (https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#jira)
60 | .jira-url
61 | atlassian-ide-plugin.xml
62 |
63 | # Custom: deploy for BB Playbook and device-info files
64 | device-pass.novcs
65 | device-ip.novcs
66 | bar-deploy.sh
67 |
68 | # Hidden Mac OS files
69 | .DS_Store
70 |
71 | HockeySDK.jar.properties
72 | ant.properties
73 | proguard
74 |
75 | *.jar.properties
76 |
77 | /local.properties
78 |
79 | /AndroidManifest.xml.bak
80 |
81 | /local.properties
82 |
83 | /AndroidManifest.xml.bak
84 |
85 | # newrelic
86 | .nrwork
87 |
88 | keystore
89 |
--------------------------------------------------------------------------------
/bubbles/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_shown_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_up_click_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_down_click_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_trash_shown_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_trash_hide_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_trash_hide_magnetism_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/bubbles/src/main/res/animator/bubble_trash_shown_magnetism_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
28 |
29 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
32 |
33 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bubble_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
32 |
33 |
41 |
42 |
53 |
54 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubbleBaseLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.content.Context;
28 | import android.util.AttributeSet;
29 | import android.view.WindowManager;
30 | import android.widget.FrameLayout;
31 |
32 | class BubbleBaseLayout extends FrameLayout {
33 | private WindowManager windowManager;
34 | private WindowManager.LayoutParams params;
35 | private BubblesLayoutCoordinator layoutCoordinator;
36 |
37 | void setLayoutCoordinator(BubblesLayoutCoordinator layoutCoordinator) {
38 | this.layoutCoordinator = layoutCoordinator;
39 | }
40 |
41 | BubblesLayoutCoordinator getLayoutCoordinator() {
42 | return layoutCoordinator;
43 | }
44 |
45 | void setWindowManager(WindowManager windowManager) {
46 | this.windowManager = windowManager;
47 | }
48 |
49 | WindowManager getWindowManager() {
50 | return this.windowManager;
51 | }
52 |
53 | void setViewParams(WindowManager.LayoutParams params) {
54 | this.params = params;
55 | }
56 |
57 | WindowManager.LayoutParams getViewParams() {
58 | return this.params;
59 | }
60 |
61 | public BubbleBaseLayout(Context context) {
62 | super(context);
63 | }
64 |
65 | public BubbleBaseLayout(Context context, AttributeSet attrs) {
66 | super(context, attrs);
67 | }
68 |
69 | public BubbleBaseLayout(Context context, AttributeSet attrs, int defStyleAttr) {
70 | super(context, attrs, defStyleAttr);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/bubbles/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | version = parent.ext.libraryVersion
6 | group = parent.ext.mavenGroupId
7 | def siteUrl = parent.ext.siteUrl
8 | def gitUrl = parent.ext.gitUrl
9 |
10 | Properties properties = new Properties()
11 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
12 |
13 | android {
14 | compileSdkVersion 22
15 | buildToolsVersion "22.0.1"
16 |
17 | defaultConfig {
18 | minSdkVersion 14
19 | targetSdkVersion 22
20 | versionCode 1
21 | versionName version
22 | }
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | }
30 |
31 | dependencies { }
32 |
33 | bintray {
34 | user = properties.getProperty("bintray.user")
35 | key = properties.getProperty("bintray.apikey")
36 | configurations = ['archives']
37 | pkg {
38 | repo = "maven"
39 | name = "bubbles-for-android"
40 | websiteUrl = siteUrl
41 | vcsUrl = gitUrl
42 | licenses = ["Apache-2.0"]
43 | publish = true
44 | }
45 | }
46 |
47 | install {
48 | repositories.mavenInstaller {
49 | pom {
50 | project {
51 | packaging 'aar'
52 | name 'Bubbles for Android'
53 | url siteUrl
54 | licenses {
55 | license {
56 | name 'The Apache Software License, Version 2.0'
57 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58 | }
59 | }
60 | developers {
61 | developer {
62 | id 'txusballesteros'
63 | name 'Txus Ballesteros'
64 | email 'txus.ballesteros@gmail.com'
65 | }
66 | }
67 | scm {
68 | connection gitUrl
69 | developerConnection gitUrl
70 | url siteUrl
71 | }
72 | }
73 | }
74 | }
75 | }
76 |
77 | task sourcesJar(type: Jar) {
78 | from android.sourceSets.main.java.srcDirs
79 | classifier = 'sources'
80 | }
81 |
82 | task javadoc(type: Javadoc) {
83 | source = android.sourceSets.main.java.srcDirs
84 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
85 | }
86 |
87 | task javadocJar(type: Jar, dependsOn: javadoc) {
88 | classifier = 'javadoc'
89 | from javadoc.destinationDir
90 | }
91 |
92 | artifacts {
93 | archives javadocJar
94 | archives sourcesJar
95 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/txusballesteros/bubbles/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles.app;
26 |
27 | import android.os.Bundle;
28 | import android.support.v7.app.ActionBarActivity;
29 | import android.view.LayoutInflater;
30 | import android.view.View;
31 | import android.widget.Toast;
32 |
33 | import com.txusballesteros.bubbles.BubbleLayout;
34 | import com.txusballesteros.bubbles.BubblesManager;
35 | import com.txusballesteros.bubbles.OnInitializedCallback;
36 |
37 | public class MainActivity extends ActionBarActivity {
38 |
39 | private BubblesManager bubblesManager;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_main);
45 |
46 | initializeBubblesManager();
47 |
48 | findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | addNewBubble();
52 | }
53 | });
54 | }
55 |
56 | private void addNewBubble() {
57 | BubbleLayout bubbleView = (BubbleLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.bubble_layout, null);
58 | bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() {
59 | @Override
60 | public void onBubbleRemoved(BubbleLayout bubble) { }
61 | });
62 | bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() {
63 |
64 | @Override
65 | public void onBubbleClick(BubbleLayout bubble) {
66 | Toast.makeText(getApplicationContext(), "Clicked !",
67 | Toast.LENGTH_SHORT).show();
68 | }
69 | });
70 | bubbleView.setShouldStickToWall(true);
71 | bubblesManager.addBubble(bubbleView, 60, 20);
72 | }
73 |
74 | private void initializeBubblesManager() {
75 | bubblesManager = new BubblesManager.Builder(this)
76 | .setTrashLayout(R.layout.bubble_trash_layout)
77 | .setInitializationCallback(new OnInitializedCallback() {
78 | @Override
79 | public void onInitialized() {
80 | addNewBubble();
81 | }
82 | })
83 | .build();
84 | bubblesManager.initialize();
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | super.onDestroy();
90 | bubblesManager.recycle();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
26 |
27 |
28 |
29 | #d51826
30 | #21a5b8
31 | #1f8b9b
32 | #15606c
33 | #0b363c
34 | #83a1a6
35 | #7B989C
36 | #516366
37 | #80516366
38 | #E6516366
39 |
40 |
41 | #ffffff
42 | #3Cffffff
43 | #80ffffff
44 | #B4ffffff
45 | #f6f6f6
46 | #eeeeee
47 | #e6e6e6
48 | #cccccc
49 | #bbbbbb
50 | #999999
51 | #666666
52 | #444444
53 | #333333
54 | #222222
55 | #40333333
56 | #000000
57 | #40000000
58 | #99000000
59 |
60 |
61 | #e1f4f7
62 | #c1e6eb
63 | #fff3f5
64 | #fee0e3
65 | #fffcea
66 |
67 |
68 | #7ed321
69 | #8dce83
70 | #e8a95c
71 | #e45555
72 | #cb4a4a
73 | #9f434e
74 | #d4cbaa
75 | #e8a95c
76 |
77 |
78 | #AB1F24
79 | #921C20
80 | #EAF3F6
81 | #2D8AB4
82 | #333333
83 | #DDDDDD
84 | #dadada
85 |
86 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubbleTrashLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.animation.AnimatorInflater;
28 | import android.animation.AnimatorSet;
29 | import android.content.Context;
30 | import android.os.Vibrator;
31 | import android.util.AttributeSet;
32 |
33 | class BubbleTrashLayout extends BubbleBaseLayout {
34 | public static final int VIBRATION_DURATION_IN_MS = 70;
35 | private boolean magnetismApplied = false;
36 | private boolean attachedToWindow = false;
37 | private boolean isVibrateInThisSession = false;
38 |
39 | public BubbleTrashLayout(Context context) {
40 | super(context);
41 | }
42 |
43 | public BubbleTrashLayout(Context context, AttributeSet attrs) {
44 | super(context, attrs);
45 | }
46 |
47 | public BubbleTrashLayout(Context context, AttributeSet attrs, int defStyleAttr) {
48 | super(context, attrs, defStyleAttr);
49 | }
50 |
51 | @Override
52 | protected void onAttachedToWindow() {
53 | super.onAttachedToWindow();
54 | attachedToWindow = true;
55 | }
56 |
57 | @Override
58 | protected void onDetachedFromWindow() {
59 | super.onDetachedFromWindow();
60 | attachedToWindow = false;
61 | }
62 |
63 | @Override
64 | public void setVisibility(int visibility) {
65 | if (attachedToWindow) {
66 | if (visibility != getVisibility()) {
67 | if (visibility == VISIBLE) {
68 | playAnimation(R.animator.bubble_trash_shown_animator);
69 |
70 |
71 | } else {
72 | playAnimation(R.animator.bubble_trash_hide_animator);
73 | }
74 | }
75 | }
76 | super.setVisibility(visibility);
77 | }
78 |
79 | void applyMagnetism() {
80 | if (!magnetismApplied) {
81 | magnetismApplied = true;
82 | playAnimation(R.animator.bubble_trash_shown_magnetism_animator);
83 | }
84 | }
85 |
86 | void vibrate() {
87 | if (!isVibrateInThisSession){
88 | final Vibrator vibrator = (Vibrator)getContext().getSystemService(Context.VIBRATOR_SERVICE);
89 | vibrator.vibrate(VIBRATION_DURATION_IN_MS);
90 | isVibrateInThisSession = true;
91 | }
92 | }
93 |
94 | void releaseMagnetism() {
95 | if (magnetismApplied) {
96 | magnetismApplied = false;
97 | playAnimation(R.animator.bubble_trash_hide_magnetism_animator);
98 | }
99 | isVibrateInThisSession = false;
100 | }
101 |
102 | private void playAnimation(int animationResourceId) {
103 | if (!isInEditMode()) {
104 | AnimatorSet animator = (AnimatorSet) AnimatorInflater
105 | .loadAnimator(getContext(), animationResourceId);
106 | animator.setTarget(getChildAt(0));
107 | animator.start();
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubblesManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.content.ComponentName;
28 | import android.content.Context;
29 | import android.content.Intent;
30 | import android.content.ServiceConnection;
31 | import android.os.IBinder;
32 |
33 | public class BubblesManager {
34 | private static BubblesManager INSTANCE;
35 | private Context context;
36 | private boolean bounded;
37 | private BubblesService bubblesService;
38 | private int trashLayoutResourceId;
39 | private OnInitializedCallback listener;
40 |
41 | private static BubblesManager getInstance(Context context) {
42 | if (INSTANCE == null) {
43 | INSTANCE = new BubblesManager(context);
44 | }
45 | return INSTANCE;
46 | }
47 |
48 | private ServiceConnection bubbleServiceConnection = new ServiceConnection() {
49 | @Override
50 | public void onServiceConnected(ComponentName name, IBinder service) {
51 | BubblesService.BubblesServiceBinder binder = (BubblesService.BubblesServiceBinder)service;
52 | BubblesManager.this.bubblesService = binder.getService();
53 | configureBubblesService();
54 | bounded = true;
55 | if (listener != null) {
56 | listener.onInitialized();
57 | }
58 | }
59 |
60 | @Override
61 | public void onServiceDisconnected(ComponentName name) {
62 | bounded = false;
63 | }
64 | };
65 |
66 | private BubblesManager(Context context) {
67 | this.context = context;
68 | }
69 |
70 | private void configureBubblesService() {
71 | bubblesService.addTrash(trashLayoutResourceId);
72 | }
73 |
74 | public void initialize() {
75 | context.bindService(new Intent(context, BubblesService.class),
76 | bubbleServiceConnection,
77 | Context.BIND_AUTO_CREATE);
78 | }
79 |
80 | public void recycle() {
81 | context.unbindService(bubbleServiceConnection);
82 | }
83 |
84 | public void addBubble(BubbleLayout bubble, int x, int y) {
85 | if (bounded) {
86 | bubblesService.addBubble(bubble, x, y);
87 | }
88 | }
89 |
90 | public void removeBubble(BubbleLayout bubble) {
91 | if (bounded) {
92 | bubblesService.removeBubble(bubble);
93 | }
94 | }
95 |
96 | public static class Builder {
97 | private BubblesManager bubblesManager;
98 |
99 | public Builder(Context context) {
100 | this.bubblesManager = getInstance(context);
101 | }
102 |
103 | public Builder setInitializationCallback(OnInitializedCallback listener) {
104 | bubblesManager.listener = listener;
105 | return this;
106 | }
107 |
108 | public Builder setTrashLayout(int trashLayoutResourceId) {
109 | bubblesManager.trashLayoutResourceId =trashLayoutResourceId;
110 | return this;
111 | }
112 |
113 | public BubblesManager build() {
114 | return bubblesManager;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Bubbles for Android
2 | =====================
3 |
4 | Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.
5 |
6 | 
7 |
8 | ## Latest Version
9 |
10 | [ ](https://bintray.com/txusballesteros/maven/bubbles-for-android/_latestVersion)  [](https://android-arsenal.com/details/1/2113)
11 |
12 | ## How to use
13 |
14 | ### Configuring your project dependencies
15 |
16 | Add the library dependency in your build.gradle file.
17 |
18 | ```groovy
19 | dependencies {
20 | ...
21 | compile 'com.txusballesteros:bubbles:1.2.1'
22 | }
23 | ```
24 |
25 | ### Adding your first Bubble
26 |
27 | Compose your Bubble layout, for example using a Xml layout file. Remember that the first view of your Bubble layout has to be a BubbleLayout view.
28 |
29 | ```xml
30 |
34 |
35 |
43 |
44 |
45 | ```
46 |
47 | Create your BubblesManager instance.
48 |
49 | ```java
50 | private BubblesManager bubblesManager;
51 |
52 | @Override
53 | protected void onCreate(Bundle savedInstanceState) {
54 | bubblesManager = new BubblesManager.Builder(this)
55 | .build();
56 | bubblesManager.initialize();
57 | ...
58 | }
59 |
60 | @Override
61 | protected void onDestroy() {
62 | bubblesManager.recycle();
63 | ...
64 | }
65 | ```
66 |
67 | Attach your Bubble to the window.
68 |
69 | ```java
70 | BubbleLayout bubbleView = (BubbleLayout)LayoutInflater
71 | .from(MainActivity.this).inflate(R.layout.bubble_layout, null);
72 | bubblesManager.addBubble(bubbleView, 60, 20);
73 | ```
74 |
75 | ### Configuring your Bubbles Trash
76 |
77 | If you want to have a trash to remove on screen bubbles, you can configure the
78 | layout of that.
79 |
80 | Define your trash layout Xml.
81 |
82 | ```xml
83 |
90 | ```
91 |
92 | Configure the trash layout with your BubblesManager builder.
93 |
94 | ```java
95 | private BubblesManager bubblesManager;
96 |
97 | @Override
98 | protected void onCreate(Bundle savedInstanceState) {
99 | bubblesManager = new BubblesManager.Builder(this)
100 | .setTrashLayout(R.layout.bubble_trash_layout)
101 | .build();
102 | bubblesManager.initialize();
103 | ...
104 | }
105 | ```
106 |
107 | ## License
108 |
109 | Copyright Txus Ballesteros 2015 (@txusballesteros)
110 |
111 | This file is part of some open source application.
112 |
113 | Licensed to the Apache Software Foundation (ASF) under one
114 | or more contributor license agreements. See the NOTICE file
115 | distributed with this work for additional information
116 | regarding copyright ownership. The ASF licenses this file
117 | to you under the Apache License, Version 2.0 (the
118 | "License"); you may not use this file except in compliance
119 | with the License. You may obtain a copy of the License at
120 |
121 | http://www.apache.org/licenses/LICENSE-2.0
122 |
123 | Unless required by applicable law or agreed to in writing,
124 | software distributed under the License is distributed on an
125 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
126 | KIND, either express or implied. See the License for the
127 | specific language governing permissions and limitations
128 | under the License.
129 |
130 | Contact: Txus Ballesteros
131 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubblesLayoutCoordinator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.content.Context;
28 | import android.os.Vibrator;
29 | import android.view.View;
30 | import android.view.WindowManager;
31 |
32 | final class BubblesLayoutCoordinator {
33 | private static BubblesLayoutCoordinator INSTANCE;
34 | private BubbleTrashLayout trashView;
35 | private WindowManager windowManager;
36 | private BubblesService bubblesService;
37 |
38 | private static BubblesLayoutCoordinator getInstance() {
39 | if (INSTANCE == null) {
40 | INSTANCE = new BubblesLayoutCoordinator();
41 | }
42 | return INSTANCE;
43 | }
44 |
45 | private BubblesLayoutCoordinator() { }
46 |
47 | public void notifyBubblePositionChanged(BubbleLayout bubble, int x, int y) {
48 | if (trashView != null) {
49 | trashView.setVisibility(View.VISIBLE);
50 | if (checkIfBubbleIsOverTrash(bubble)) {
51 | trashView.applyMagnetism();
52 | trashView.vibrate();
53 | applyTrashMagnetismToBubble(bubble);
54 | } else {
55 | trashView.releaseMagnetism();
56 | }
57 | }
58 | }
59 |
60 | private void applyTrashMagnetismToBubble(BubbleLayout bubble) {
61 | View trashContentView = getTrashContent();
62 | int trashCenterX = (trashContentView.getLeft() + (trashContentView.getMeasuredWidth() / 2));
63 | int trashCenterY = (trashContentView.getTop() + (trashContentView.getMeasuredHeight() / 2));
64 | int x = (trashCenterX - (bubble.getMeasuredWidth() / 2));
65 | int y = (trashCenterY - (bubble.getMeasuredHeight() / 2));
66 | bubble.getViewParams().x = x;
67 | bubble.getViewParams().y = y;
68 | windowManager.updateViewLayout(bubble, bubble.getViewParams());
69 | }
70 |
71 | private boolean checkIfBubbleIsOverTrash(BubbleLayout bubble) {
72 | boolean result = false;
73 | if (trashView.getVisibility() == View.VISIBLE) {
74 | View trashContentView = getTrashContent();
75 | int trashWidth = trashContentView.getMeasuredWidth();
76 | int trashHeight = trashContentView.getMeasuredHeight();
77 | int trashLeft = (trashContentView.getLeft() - (trashWidth / 2));
78 | int trashRight = (trashContentView.getLeft() + trashWidth + (trashWidth / 2));
79 | int trashTop = (trashContentView.getTop() - (trashHeight / 2));
80 | int trashBottom = (trashContentView.getTop() + trashHeight + (trashHeight / 2));
81 | int bubbleWidth = bubble.getMeasuredWidth();
82 | int bubbleHeight = bubble.getMeasuredHeight();
83 | int bubbleLeft = bubble.getViewParams().x;
84 | int bubbleRight = bubbleLeft + bubbleWidth;
85 | int bubbleTop = bubble.getViewParams().y;
86 | int bubbleBottom = bubbleTop + bubbleHeight;
87 | if (bubbleLeft >= trashLeft && bubbleRight <= trashRight) {
88 | if (bubbleTop >= trashTop && bubbleBottom <= trashBottom) {
89 | result = true;
90 | }
91 | }
92 | }
93 | return result;
94 | }
95 |
96 | public void notifyBubbleRelease(BubbleLayout bubble) {
97 | if (trashView != null) {
98 | if (checkIfBubbleIsOverTrash(bubble)) {
99 | bubblesService.removeBubble(bubble);
100 | }
101 | trashView.setVisibility(View.GONE);
102 | }
103 | }
104 |
105 | public static class Builder {
106 | private BubblesLayoutCoordinator layoutCoordinator;
107 |
108 | public Builder(BubblesService service) {
109 | layoutCoordinator = getInstance();
110 | layoutCoordinator.bubblesService = service;
111 | }
112 |
113 | public Builder setTrashView(BubbleTrashLayout trashView) {
114 | layoutCoordinator.trashView = trashView;
115 | return this;
116 | }
117 |
118 | public Builder setWindowManager(WindowManager windowManager) {
119 | layoutCoordinator.windowManager = windowManager;
120 | return this;
121 | }
122 |
123 | public BubblesLayoutCoordinator build() {
124 | return layoutCoordinator;
125 | }
126 | }
127 |
128 | private View getTrashContent() {
129 | return trashView.getChildAt(0);
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubblesService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.app.Service;
28 | import android.content.Intent;
29 | import android.graphics.PixelFormat;
30 | import android.graphics.Point;
31 | import android.os.Binder;
32 | import android.os.Handler;
33 | import android.os.IBinder;
34 | import android.os.Looper;
35 | import android.view.Gravity;
36 | import android.view.LayoutInflater;
37 | import android.view.View;
38 | import android.view.WindowManager;
39 | import android.widget.FrameLayout;
40 |
41 | import java.util.ArrayList;
42 | import java.util.List;
43 |
44 | public class BubblesService extends Service {
45 | private BubblesServiceBinder binder = new BubblesServiceBinder();
46 | private List bubbles = new ArrayList<>();
47 | private BubbleTrashLayout bubblesTrash;
48 | private WindowManager windowManager;
49 | private BubblesLayoutCoordinator layoutCoordinator;
50 |
51 | @Override
52 | public IBinder onBind(Intent intent) {
53 | return binder;
54 | }
55 |
56 | @Override
57 | public boolean onUnbind(Intent intent) {
58 | for (BubbleLayout bubble : bubbles) {
59 | recycleBubble(bubble);
60 | }
61 | bubbles.clear();
62 | return super.onUnbind(intent);
63 | }
64 |
65 | private void recycleBubble(final BubbleLayout bubble) {
66 | new Handler(Looper.getMainLooper()).post(new Runnable() {
67 | @Override
68 | public void run() {
69 | getWindowManager().removeView(bubble);
70 | for (BubbleLayout cachedBubble : bubbles) {
71 | if (cachedBubble == bubble) {
72 | bubble.notifyBubbleRemoved();
73 | bubbles.remove(cachedBubble);
74 | break;
75 | }
76 | }
77 | }
78 | });
79 | }
80 |
81 | private WindowManager getWindowManager() {
82 | if (windowManager == null) {
83 | windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
84 | }
85 | return windowManager;
86 | }
87 |
88 | public void addBubble(BubbleLayout bubble, int x, int y) {
89 | WindowManager.LayoutParams layoutParams = buildLayoutParamsForBubble(x, y);
90 | bubble.setWindowManager(getWindowManager());
91 | bubble.setViewParams(layoutParams);
92 | bubble.setLayoutCoordinator(layoutCoordinator);
93 | bubbles.add(bubble);
94 | addViewToWindow(bubble);
95 | }
96 |
97 | void addTrash(int trashLayoutResourceId) {
98 | if (trashLayoutResourceId != 0) {
99 | bubblesTrash = new BubbleTrashLayout(this);
100 | bubblesTrash.setWindowManager(windowManager);
101 | bubblesTrash.setViewParams(buildLayoutParamsForTrash());
102 | bubblesTrash.setVisibility(View.GONE);
103 | LayoutInflater.from(this).inflate(trashLayoutResourceId, bubblesTrash, true);
104 | addViewToWindow(bubblesTrash);
105 | initializeLayoutCoordinator();
106 | }
107 | }
108 |
109 | private void initializeLayoutCoordinator() {
110 | layoutCoordinator = new BubblesLayoutCoordinator.Builder(this)
111 | .setWindowManager(getWindowManager())
112 | .setTrashView(bubblesTrash)
113 | .build();
114 | }
115 |
116 | private void addViewToWindow(final BubbleBaseLayout view) {
117 | new Handler(Looper.getMainLooper()).post(new Runnable() {
118 | @Override
119 | public void run() {
120 | getWindowManager().addView(view, view.getViewParams());
121 | }
122 | });
123 | }
124 |
125 | private WindowManager.LayoutParams buildLayoutParamsForBubble(int x, int y) {
126 | WindowManager.LayoutParams params = new WindowManager.LayoutParams(
127 | WindowManager.LayoutParams.WRAP_CONTENT,
128 | WindowManager.LayoutParams.WRAP_CONTENT,
129 | WindowManager.LayoutParams.TYPE_PHONE,
130 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
131 | PixelFormat.TRANSPARENT);
132 | params.gravity = Gravity.TOP | Gravity.START;
133 | params.x = x;
134 | params.y = y;
135 | return params;
136 | }
137 |
138 | private WindowManager.LayoutParams buildLayoutParamsForTrash() {
139 | int x = 0;
140 | int y = 0;
141 | WindowManager.LayoutParams params = new WindowManager.LayoutParams(
142 | WindowManager.LayoutParams.MATCH_PARENT,
143 | WindowManager.LayoutParams.MATCH_PARENT,
144 | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
145 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
146 | PixelFormat.TRANSPARENT);
147 | params.x = x;
148 | params.y = y;
149 | return params;
150 | }
151 |
152 | public void removeBubble(BubbleLayout bubble) {
153 | recycleBubble(bubble);
154 | }
155 |
156 | public class BubblesServiceBinder extends Binder {
157 | public BubblesService getService() {
158 | return BubblesService.this;
159 | }
160 | }
161 | }
--------------------------------------------------------------------------------
/bubbles/src/main/java/com/txusballesteros/bubbles/BubbleLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Txus Ballesteros 2015 (@txusballesteros)
3 | *
4 | * This file is part of some open source application.
5 | *
6 | * Licensed to the Apache Software Foundation (ASF) under one
7 | * or more contributor license agreements. See the NOTICE file
8 | * distributed with this work for additional information
9 | * regarding copyright ownership. The ASF licenses this file
10 | * to you under the Apache License, Version 2.0 (the
11 | * "License"); you may not use this file except in compliance
12 | * with the License. You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing,
17 | * software distributed under the License is distributed on an
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | * KIND, either express or implied. See the License for the
20 | * specific language governing permissions and limitations
21 | * under the License.
22 | *
23 | * Contact: Txus Ballesteros
24 | */
25 | package com.txusballesteros.bubbles;
26 |
27 | import android.animation.AnimatorInflater;
28 | import android.animation.AnimatorSet;
29 | import android.content.Context;
30 | import android.graphics.Point;
31 | import android.os.Handler;
32 | import android.os.Looper;
33 | import android.util.AttributeSet;
34 | import android.util.DisplayMetrics;
35 | import android.view.Display;
36 | import android.view.MotionEvent;
37 | import android.view.WindowManager;
38 |
39 | public class BubbleLayout extends BubbleBaseLayout {
40 | private float initialTouchX;
41 | private float initialTouchY;
42 | private int initialX;
43 | private int initialY;
44 | private OnBubbleRemoveListener onBubbleRemoveListener;
45 | private OnBubbleClickListener onBubbleClickListener;
46 | private static final int TOUCH_TIME_THRESHOLD = 150;
47 | private long lastTouchDown;
48 | private MoveAnimator animator;
49 | private int width;
50 | private WindowManager windowManager;
51 | private boolean shouldStickToWall = true;
52 |
53 | public void setOnBubbleRemoveListener(OnBubbleRemoveListener listener) {
54 | onBubbleRemoveListener = listener;
55 | }
56 |
57 | public void setOnBubbleClickListener(OnBubbleClickListener listener) {
58 | onBubbleClickListener = listener;
59 | }
60 |
61 | public BubbleLayout(Context context) {
62 | super(context);
63 | animator = new MoveAnimator();
64 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
65 | initializeView();
66 | }
67 |
68 | public BubbleLayout(Context context, AttributeSet attrs) {
69 | super(context, attrs);
70 | animator = new MoveAnimator();
71 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
72 | initializeView();
73 | }
74 |
75 | public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
76 | super(context, attrs, defStyleAttr);
77 | animator = new MoveAnimator();
78 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
79 | initializeView();
80 | }
81 |
82 | public void setShouldStickToWall(boolean shouldStick) {
83 | this.shouldStickToWall = shouldStick;
84 | }
85 |
86 | void notifyBubbleRemoved() {
87 | if (onBubbleRemoveListener != null) {
88 | onBubbleRemoveListener.onBubbleRemoved(this);
89 | }
90 | }
91 |
92 | private void initializeView() {
93 | setClickable(true);
94 | }
95 |
96 | @Override
97 | protected void onAttachedToWindow() {
98 | super.onAttachedToWindow();
99 | playAnimation();
100 | }
101 |
102 | @Override
103 | public boolean onTouchEvent(MotionEvent event) {
104 | if (event != null) {
105 | switch (event.getAction()) {
106 | case MotionEvent.ACTION_DOWN:
107 | initialX = getViewParams().x;
108 | initialY = getViewParams().y;
109 | initialTouchX = event.getRawX();
110 | initialTouchY = event.getRawY();
111 | playAnimationClickDown();
112 | lastTouchDown = System.currentTimeMillis();
113 | updateSize();
114 | animator.stop();
115 | break;
116 | case MotionEvent.ACTION_MOVE:
117 | int x = initialX + (int)(event.getRawX() - initialTouchX);
118 | int y = initialY + (int)(event.getRawY() - initialTouchY);
119 | getViewParams().x = x;
120 | getViewParams().y = y;
121 | getWindowManager().updateViewLayout(this, getViewParams());
122 | if (getLayoutCoordinator() != null) {
123 | getLayoutCoordinator().notifyBubblePositionChanged(this, x, y);
124 | }
125 | break;
126 | case MotionEvent.ACTION_UP:
127 | goToWall();
128 | if (getLayoutCoordinator() != null) {
129 | getLayoutCoordinator().notifyBubbleRelease(this);
130 | playAnimationClickUp();
131 | }
132 | if (System.currentTimeMillis() - lastTouchDown < TOUCH_TIME_THRESHOLD) {
133 | if (onBubbleClickListener != null) {
134 | onBubbleClickListener.onBubbleClick(this);
135 | }
136 | }
137 | break;
138 | }
139 | }
140 | return super.onTouchEvent(event);
141 | }
142 |
143 | private void playAnimation() {
144 | if (!isInEditMode()) {
145 | AnimatorSet animator = (AnimatorSet) AnimatorInflater
146 | .loadAnimator(getContext(), R.animator.bubble_shown_animator);
147 | animator.setTarget(this);
148 | animator.start();
149 | }
150 | }
151 |
152 | private void playAnimationClickDown() {
153 | if (!isInEditMode()) {
154 | AnimatorSet animator = (AnimatorSet) AnimatorInflater
155 | .loadAnimator(getContext(), R.animator.bubble_down_click_animator);
156 | animator.setTarget(this);
157 | animator.start();
158 | }
159 | }
160 |
161 | private void playAnimationClickUp() {
162 | if (!isInEditMode()) {
163 | AnimatorSet animator = (AnimatorSet) AnimatorInflater
164 | .loadAnimator(getContext(), R.animator.bubble_up_click_animator);
165 | animator.setTarget(this);
166 | animator.start();
167 | }
168 | }
169 |
170 | private void updateSize() {
171 | DisplayMetrics metrics = new DisplayMetrics();
172 | windowManager.getDefaultDisplay().getMetrics(metrics);
173 | Display display = getWindowManager().getDefaultDisplay();
174 | Point size = new Point();
175 | display.getSize(size);
176 | width = (size.x - this.getWidth());
177 |
178 | }
179 |
180 | public interface OnBubbleRemoveListener {
181 | void onBubbleRemoved(BubbleLayout bubble);
182 | }
183 |
184 | public interface OnBubbleClickListener {
185 | void onBubbleClick(BubbleLayout bubble);
186 | }
187 |
188 | public void goToWall() {
189 | if(shouldStickToWall){
190 | int middle = width / 2;
191 | float nearestXWall = getViewParams().x >= middle ? width : 0;
192 | animator.start(nearestXWall, getViewParams().y);
193 | }
194 | }
195 |
196 | private void move(float deltaX, float deltaY) {
197 | getViewParams().x += deltaX;
198 | getViewParams().y += deltaY;
199 | windowManager.updateViewLayout(this, getViewParams());
200 | }
201 |
202 |
203 | private class MoveAnimator implements Runnable {
204 | private Handler handler = new Handler(Looper.getMainLooper());
205 | private float destinationX;
206 | private float destinationY;
207 | private long startingTime;
208 |
209 | private void start(float x, float y) {
210 | this.destinationX = x;
211 | this.destinationY = y;
212 | startingTime = System.currentTimeMillis();
213 | handler.post(this);
214 | }
215 |
216 | @Override
217 | public void run() {
218 | if (getRootView() != null && getRootView().getParent() != null) {
219 | float progress = Math.min(1, (System.currentTimeMillis() - startingTime) / 400f);
220 | float deltaX = (destinationX - getViewParams().x) * progress;
221 | float deltaY = (destinationY - getViewParams().y) * progress;
222 | move(deltaX, deltaY);
223 | if (progress < 1) {
224 | handler.post(this);
225 | }
226 | }
227 | }
228 |
229 | private void stop() {
230 | handler.removeCallbacks(this);
231 | }
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------