├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── allenliu
│ │ └── floatview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── allenliu
│ │ │ └── floatview
│ │ │ ├── CallShowReceiver.java
│ │ │ └── FloatViewDemoActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_float_view_demo.xml
│ │ ├── callshow_layout.xml
│ │ └── floatview_layotu.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── demo.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── allenliu
│ └── floatview
│ └── ExampleUnitTest.java
├── build.gradle
├── floatview.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── allenliu
│ │ └── floatview
│ │ └── library
│ │ └── FloatView.java
│ └── res
│ └── values
│ └── strings.xml
├── settings.gradle
├── z.gif
└── z3.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | FloatView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FloatView
2 | floatview on windowmanager,and you can be easy to add call show by using it
3 |
4 | 自定义floatview,无需申明悬浮框权限,利用WindowManager TYPE_TOAST实现全站浮动式按钮,重写touch事件实现任意拖动,将view加入windowmanager层,可以使用控件实现类似来电秀的效果。
5 |
6 | ## MIUI使用TYPE_TOAST也会无效,所以MIUI系统中需要在manifest里面注册SYSTEM_ALERT_Winow权限,其他系统可以不用.
7 |
8 | 

9 |
10 |
11 | ### 导入:
12 |
13 | `compile 'com.allenliu:floatview:1.0.1'`
14 |
15 | ### 初始化Floatview:
16 |
17 | FloatView(Context context, int x, int y, View childView)
18 | or
19 | FloatView(Context context, int x, int y, int layoutres)
20 | ### 其他方法:
21 |
22 | ```
23 | updateFloatViewPosition(int x, int y)//更新位置
24 |
25 | setFloatViewClickListener(IFloatViewClick listener)`
26 |
27 | addToWindow()//加入窗口
28 |
29 | setIsAllowTouch(boolean flag)//是否允许拖动
30 |
31 | removeFromWindow()//移除窗口
32 | ```
33 |
34 |
35 | 由于控件显示在windowmanager上,所以控件显示的生命周期需要自己手动管理,可以在Application或者基层Activity里控制显示和隐藏。
36 |
37 | ### 来电秀
38 | 利用控件也可以显示在来电秀上。
39 |
40 | 由于继承自linearlayout所以可以添加子view,可以初始化时将View或layout传入,也可以手动addview,在监听来电时加入view即可,有兴趣的朋友可以
41 | 参考下源码
42 |
43 | case TelephonyManager.CALL_STATE_RINGING:
44 | if (!viewIsShow) {
45 | viewIsShow = true;
46 | if (floatView == null)
47 | floatView = new FloatView(context, 0, 0, R.layout.callshow_layout);
48 | floatView.addToWindow();
49 | }
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.allenliu.floatview"
9 | minSdkVersion 15
10 | targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile project(':library')
27 | }
28 |
--------------------------------------------------------------------------------
/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:\Eclipse\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/allenliu/floatview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.floatview;
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 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/allenliu/floatview/CallShowReceiver.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.floatview;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.telephony.PhoneStateListener;
7 | import android.telephony.TelephonyManager;
8 | import android.util.DisplayMetrics;
9 | import android.view.ViewGroup;
10 | import android.view.WindowManager;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.allenliu.floatview.library.FloatView;
15 |
16 | /**
17 | * Created by Allen Liu on 2016/5/25.
18 | */
19 | public class CallShowReceiver extends BroadcastReceiver {
20 | private String TAG="CALLSHOWRECEIVER";
21 | private boolean viewIsShow=false;
22 | private FloatView floatView;
23 | private PhoneStateListener phoneStateListener;
24 | @Override
25 | public void onReceive(Context context, Intent intent) {
26 | // if(intent.getAction().equals("com.allenliu.floatview.REGISTER_CALLSHOW"))
27 | initPhoneStateListener(context,intent);
28 | }
29 | private void initPhoneStateListener(final Context context, final Intent intent) {
30 | if(phoneStateListener==null) {
31 | phoneStateListener = new PhoneStateListener() {
32 | @Override
33 | public void onCallStateChanged(int state, String incomingNumber) {
34 | super.onCallStateChanged(state, incomingNumber);
35 | switch (state) {
36 | //挂机或没有电话时的状态
37 | case TelephonyManager.CALL_STATE_IDLE:
38 | if (floatView != null) {
39 | floatView.removeFromWindow();
40 | viewIsShow = false;
41 | }
42 | break;
43 | //响铃中
44 | case TelephonyManager.CALL_STATE_RINGING:
45 | // Log.v(TAG,"SHOW");
46 | if (!viewIsShow) {
47 | viewIsShow = true;
48 | if (floatView == null)
49 | floatView = new FloatView(context, 0, 0, R.layout.callshow_layout);
50 | TextView textView = (TextView) floatView.findViewById(R.id.tv_phone);
51 | ImageView imageView = (ImageView) floatView.findViewById(R.id.iv);
52 | ViewGroup.LayoutParams params = imageView.getLayoutParams();
53 | params.width = getScreenWidth(context);
54 | // params.height=400;
55 | imageView.setLayoutParams(params);
56 | textView.setText(incomingNumber + "来电了");
57 |
58 | floatView.addToWindow();
59 | }
60 | break;
61 | //接听电话了
62 | case TelephonyManager.CALL_STATE_OFFHOOK:
63 | if (floatView != null) {
64 | floatView.removeFromWindow();
65 | viewIsShow = false;
66 | }
67 | break;
68 | }
69 | }
70 | };
71 | //注册监听,
72 | TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
73 | manager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
74 | }
75 | }
76 | private int getScreenWidth(Context context) {
77 | WindowManager wm = (WindowManager) context
78 | .getSystemService(Context.WINDOW_SERVICE);
79 | DisplayMetrics outMetrics = new DisplayMetrics();
80 | wm.getDefaultDisplay().getMetrics(outMetrics);
81 | return outMetrics.widthPixels;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/allenliu/floatview/FloatViewDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.floatview;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.EditText;
9 | import android.widget.Toast;
10 |
11 | import com.allenliu.floatview.library.FloatView;
12 |
13 | public class FloatViewDemoActivity extends AppCompatActivity {
14 | FloatView floatView;
15 | EditText et1;
16 | EditText et2;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_float_view_demo);
22 | init();
23 |
24 |
25 | }
26 |
27 | private void init() {
28 | et1 = (EditText) findViewById(R.id.et1);
29 | et2 = (EditText) findViewById(R.id.et2);
30 |
31 | floatView = new FloatView(this, 0, 0, R.layout.floatview_layotu);
32 | floatView.setFloatViewClickListener(new FloatView.IFloatViewClick() {
33 | @Override
34 | public void onFloatViewClick() {
35 | Toast.makeText(FloatViewDemoActivity.this, "floatview is clicked", Toast.LENGTH_SHORT).show();
36 |
37 | }
38 | });
39 | }
40 |
41 | public void onClick(View view) {
42 | switch (view.getId()) {
43 | case R.id.btn1:
44 | floatView.removeFromWindow();
45 | Log.v("SS", "REMOVE");
46 | break;
47 | case R.id.btn2:
48 | floatView.addToWindow();
49 | break;
50 | case R.id.btn_update:
51 | int x = Integer.parseInt(et1.getText().toString());
52 | int y = Integer.parseInt(et2.getText().toString());
53 | floatView.updateFloatViewPosition(x, y);
54 | break;
55 | case R.id.btn3:
56 | Intent intent = new Intent();
57 | intent.setAction("com.allenliu.floatview.REGISTER_CALLSHOW");
58 | sendBroadcast(intent);
59 | break;
60 | }
61 |
62 | }
63 |
64 | @Override
65 | protected void onStart() {
66 | floatView.addToWindow();
67 | super.onStart();
68 | }
69 |
70 | @Override
71 | protected void onStop() {
72 | floatView.removeFromWindow();
73 | super.onStop();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_float_view_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
19 |
27 |
28 |
34 |
42 |
50 |
56 |
57 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/callshow_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/floatview_layotu.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-xhdpi/demo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FloatView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/allenliu/floatview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.floatview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.2'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/floatview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/floatview.gif
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 04 14:05:29 CST 2017
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.3"
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | }
15 | lintOptions {
16 | abortOnError false
17 | checkReleaseBuilds false
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 | publish {
27 | userOrg = 'zkxy'
28 | groupId = 'com.allenliu'
29 | artifactId = 'floatview'
30 | publishVersion = '1.0.1'
31 | desc = 'a floatview on android'
32 | website = 'https://github.com/AlexLiuSheng/FloatView'
33 | }
34 |
35 | dependencies {
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/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/allenliu/Library/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/java/com/allenliu/floatview/library/FloatView.java:
--------------------------------------------------------------------------------
1 | package com.allenliu.floatview.library;
2 |
3 | import android.content.Context;
4 | import android.graphics.PixelFormat;
5 | import android.os.Build;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.WindowManager;
11 | import android.widget.LinearLayout;
12 |
13 |
14 | public class FloatView extends LinearLayout {
15 |
16 | private WindowManager.LayoutParams wmParams;
17 | private WindowManager wm;
18 | private float mTouchStartX;
19 | private float mTouchStartY;
20 | private float x;
21 | private float y;
22 | private IFloatViewClick listener;
23 | private boolean isAllowTouch = true;
24 |
25 | public FloatView(Context context, int x, int y, int layoutres) {
26 | super(context);
27 | View view = LayoutInflater.from(getContext()).inflate(layoutres, null);
28 | init(view, x, y);
29 | // TODO 自动生成的构造函数存根
30 | // wmParams=MyApplication.parmas;
31 | }
32 |
33 | public FloatView(Context context, int x, int y, View childView) {
34 | super(context);
35 | init(childView, x, y);
36 | }
37 |
38 | private void init(View childView, int x, int y) {
39 | wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
40 | wmParams = new WindowManager.LayoutParams();
41 | //设置你要添加控件的类型,TYPE_ALERT需要申明权限,TOast不需要,在某些定制系统中会禁止悬浮框显示,所以最后用TYPE_TOAST
42 | wmParams.type = WindowManager.LayoutParams.TYPE_TOAST;
43 | //设置控件在坐标计算规则,相当于屏幕左上角
44 | wmParams.gravity = Gravity.LEFT | Gravity.TOP;
45 | wmParams.format = PixelFormat.RGBA_8888;
46 | wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
47 | wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
48 | wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
49 | wmParams.x = (int) x;
50 | wmParams.y = (int) y;
51 | if (childView != null) {
52 | addView(childView);
53 | }
54 | // wm.addView(this, wmParams);
55 | }
56 |
57 | /**
58 | * 更新位置
59 | *
60 | * @param x
61 | * @param y
62 | */
63 | public void updateFloatViewPosition(int x, int y) {
64 | wmParams.x = x;
65 | wmParams.y = y;
66 | wm.updateViewLayout(this, wmParams);
67 | }
68 |
69 | public void setFloatViewClickListener(IFloatViewClick listener) {
70 | this.listener = listener;
71 | }
72 |
73 | /**
74 | * 添加至窗口
75 | *
76 | * @return
77 | */
78 | public boolean addToWindow() {
79 | if (wm != null) {
80 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
81 | if (!isAttachedToWindow()) {
82 | wm.addView(this, wmParams);
83 | return true;
84 | } else {
85 | return false;
86 | }
87 | } else {
88 | try {
89 | if (getParent() == null) {
90 | wm.addView(this, wmParams);
91 | }
92 | return true;
93 | } catch (Exception e) {
94 | return false;
95 | }
96 | }
97 |
98 |
99 | } else {
100 | return false;
101 | }
102 | }
103 |
104 | public void setIsAllowTouch(boolean flag) {
105 | isAllowTouch = flag;
106 | }
107 |
108 | /**
109 | * 从窗口移除
110 | *
111 | * @return
112 | */
113 | public boolean removeFromWindow() {
114 | if (wm != null) {
115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
116 | if (isAttachedToWindow()) {
117 | wm.removeViewImmediate(this);
118 | return true;
119 | } else {
120 | return false;
121 | }
122 | } else {
123 | try {
124 | if (getParent() != null) {
125 | wm.removeViewImmediate(this);
126 | }
127 | return true;
128 | } catch (Exception e) {
129 | return false;
130 | }
131 | }
132 |
133 |
134 | } else {
135 | return false;
136 | }
137 |
138 | }
139 |
140 |
141 | // 此wmParams为获取的全局变量,用以保存悬浮窗口的属性
142 |
143 | // 重写,返回true 拦截触摸事件
144 | // @Override
145 | public boolean onInterceptTouchEvent(MotionEvent ev) {
146 | // TODO Auto-generated method stub
147 | return isAllowTouch;
148 | }
149 |
150 |
151 | @Override
152 | public boolean onTouchEvent(MotionEvent event) {
153 | switch (event.getAction()) {
154 | case MotionEvent.ACTION_DOWN:
155 | mTouchStartX = (int) event.getRawX() - this.getMeasuredWidth() / 2;
156 | mTouchStartY = (int) event.getRawY() - this.getMeasuredHeight() / 2 ;
157 |
158 | return true;
159 | case MotionEvent.ACTION_MOVE:
160 | wmParams.x = (int) event.getRawX() - this.getMeasuredWidth() / 2;
161 | // 减25为状态栏的高度
162 | wmParams.y = (int) event.getRawY() - this.getMeasuredHeight() / 2 ;
163 | // 刷新
164 | if (Math.abs(wmParams.y - mTouchStartY) > 10 || Math.abs(wmParams.x - mTouchStartX) > 10) {
165 | wm.updateViewLayout(this, wmParams);
166 | }
167 | return true;
168 | case MotionEvent.ACTION_UP:
169 | y = (int) event.getRawY() - this.getMeasuredHeight() / 2 ;
170 | x = (int) event.getRawX() - this.getMeasuredWidth() / 2;
171 | if (Math.abs(y - mTouchStartY) > 10 || Math.abs(x - mTouchStartX) > 10) {
172 | wm.updateViewLayout(this, wmParams);
173 | } else {
174 | if (listener != null) {
175 | listener.onFloatViewClick();
176 | }
177 |
178 | }
179 | return true;
180 | default:
181 | break;
182 | }
183 | return false;
184 |
185 | }
186 |
187 |
188 | public interface IFloatViewClick {
189 | void onFloatViewClick();
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app' ,':library'
2 |
--------------------------------------------------------------------------------
/z.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/z.gif
--------------------------------------------------------------------------------
/z3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexLiuSheng/FloatView/ae5859b2cdb00640f07c8eff29ef08c9818717f2/z3.gif
--------------------------------------------------------------------------------