├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── DemoAndroidFloatingView.iml ├── DemoFloatingView.iml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── icetea09 │ │ └── demofloatingview │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── icetea09 │ │ └── demofloatingview │ │ ├── DemoFloatingViewApplication.java │ │ ├── FloatingViewService.java │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | DemoAndroidFloatingView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DemoAndroidFloatingView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /DemoFloatingView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Trinh Le 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Demo Android Floating View 2 | 3 | Floating View like Facebook Chatheads 4 | 5 | This is Demo application for the [Android] Floating View like Facebook Chatheads tutorial from Ice Tea 09 (http://icetea09.com). 6 | 7 | This demo will allow you to show/hide and drag around the "floating view". 8 | 9 | Floating View is the view that was drawn on top of other applications like Facebook headchats. 10 | 11 | Please go to http://icetea09.com/blog/2015/03/16/android-floating-view-like-facebook-chatheads/ for the details of this tutorial. 12 | 13 | You can also watch the demo video here: 14 | https://www.youtube.com/watch?v=Dfv0tsdyJmE 15 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.2" 6 | 7 | defaultConfig { 8 | applicationId "com.icetea09.demofloatingview" 9 | minSdkVersion 14 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 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:21.0.3' 25 | } 26 | -------------------------------------------------------------------------------- /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 D:\Softwares\android-sdk/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/src/androidTest/java/com/icetea09/demofloatingview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.icetea09.demofloatingview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/icetea09/demofloatingview/DemoFloatingViewApplication.java: -------------------------------------------------------------------------------- 1 | package com.icetea09.demofloatingview; 2 | 3 | import android.app.Application; 4 | 5 | public class DemoFloatingViewApplication extends Application{ 6 | 7 | @Override 8 | public void onCreate() { 9 | super.onCreate(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/icetea09/demofloatingview/FloatingViewService.java: -------------------------------------------------------------------------------- 1 | package com.icetea09.demofloatingview; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.graphics.PixelFormat; 6 | import android.os.IBinder; 7 | import android.view.Gravity; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.WindowManager; 11 | import android.widget.ImageView; 12 | import android.widget.Toast; 13 | 14 | public class FloatingViewService extends Service { 15 | 16 | private WindowManager mWindowManager; 17 | private ImageView mImgFloatingView; 18 | private boolean mIsFloatingViewAttached = false; 19 | 20 | @Override 21 | public IBinder onBind(Intent intent) { 22 | //Not use this method 23 | return null; 24 | } 25 | 26 | @Override 27 | public int onStartCommand(Intent intent, int flags, int startId) { 28 | if(!mIsFloatingViewAttached){ 29 | mWindowManager.addView(mImgFloatingView, mImgFloatingView.getLayoutParams()); 30 | } 31 | return super.onStartCommand(intent, flags, startId); 32 | } 33 | 34 | @Override 35 | public void onCreate() { 36 | super.onCreate(); 37 | 38 | mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); 39 | 40 | mImgFloatingView = new ImageView(this); 41 | mImgFloatingView.setImageResource(R.mipmap.ic_launcher); 42 | 43 | final WindowManager.LayoutParams params = new WindowManager.LayoutParams( 44 | WindowManager.LayoutParams.WRAP_CONTENT, 45 | WindowManager.LayoutParams.WRAP_CONTENT, 46 | WindowManager.LayoutParams.TYPE_PHONE, 47 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, 48 | PixelFormat.TRANSLUCENT); 49 | 50 | params.gravity = Gravity.TOP | Gravity.LEFT; 51 | 52 | mWindowManager.addView(mImgFloatingView, params); 53 | 54 | mImgFloatingView.setOnTouchListener(new View.OnTouchListener() { 55 | private int initialX; 56 | private int initialY; 57 | private float initialTouchX; 58 | private float initialTouchY; 59 | 60 | @Override 61 | public boolean onTouch(View v, MotionEvent event) { 62 | switch (event.getAction()) { 63 | case MotionEvent.ACTION_DOWN: 64 | initialX = params.x; 65 | initialY = params.y; 66 | initialTouchX = event.getRawX(); 67 | initialTouchY = event.getRawY(); 68 | return true; 69 | case MotionEvent.ACTION_UP: 70 | return true; 71 | case MotionEvent.ACTION_MOVE: 72 | params.x = initialX + (int) (event.getRawX() - initialTouchX); 73 | params.y = initialY + (int) (event.getRawY() - initialTouchY); 74 | mWindowManager.updateViewLayout(mImgFloatingView, params); 75 | return true; 76 | } 77 | return false; 78 | } 79 | }); 80 | 81 | mIsFloatingViewAttached = true; 82 | } 83 | 84 | public void removeView() { 85 | if (mImgFloatingView != null){ 86 | mWindowManager.removeView(mImgFloatingView); 87 | mIsFloatingViewAttached = false; 88 | } 89 | } 90 | 91 | @Override 92 | public void onDestroy() { 93 | Toast.makeText(getApplicationContext(), "onDestroy", Toast.LENGTH_SHORT); 94 | super.onDestroy(); 95 | removeView(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/com/icetea09/demofloatingview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.icetea09.demofloatingview; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.ActionBarActivity; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | 10 | public class MainActivity extends ActionBarActivity implements View.OnClickListener{ 11 | 12 | private Button mBtnShowView; 13 | private boolean mIsFloatingViewShow; //Flag variable used to identify if the Floating View is visible or not 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | mBtnShowView = (Button)findViewById(R.id.btn_show_floating_view); 20 | mBtnShowView.setOnClickListener(this); 21 | mIsFloatingViewShow = false; 22 | } 23 | 24 | @Override 25 | public void onClick(View v) { 26 | switch (v.getId()){ 27 | case R.id.btn_show_floating_view: 28 | if(mIsFloatingViewShow){ 29 | hideFloatingView(); 30 | mIsFloatingViewShow = false; 31 | mBtnShowView.setText(R.string.show_floating_view); 32 | } 33 | else{ 34 | showFloatingView(); 35 | mIsFloatingViewShow = true; 36 | mBtnShowView.setText(R.string.hide_floating_view); 37 | } 38 | break; 39 | } 40 | } 41 | 42 | private void showFloatingView() { 43 | startService(new Intent(getApplicationContext(), FloatingViewService.class)); 44 | } 45 | 46 | private void hideFloatingView() { 47 | stopService(new Intent(getApplicationContext(), FloatingViewService.class)); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 |