diff --git a/.gitignore b/.gitignore
index 39fb081..cea3ef5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
*.iml
.gradle
/local.properties
+/.idea
/.idea/workspace.xml
/.idea/libraries
.DS_Store
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 681f41a..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,116 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- xmlns:android
-
- ^$
-
-
-
-
-
-
-
-
- xmlns:.*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*:id
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- .*:name
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- name
-
- ^$
-
-
-
-
-
-
-
-
- style
-
- ^$
-
-
-
-
-
-
-
-
- .*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*
-
- http://schemas.android.com/apk/res/android
-
-
- ANDROID_ATTRIBUTE_ORDER
-
-
-
-
-
-
- .*
-
- .*
-
-
- BY_NAME
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 6bb3b9a..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 64a67ca..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index fa5c49a..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 7f68460..0000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 3d1c0ae..dade797 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,9 +4,10 @@ buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.3'
+ classpath 'com.android.tools.build:gradle:3.6.1'
// NOTE: Do not place your application dependencies here; they belong
@@ -20,6 +21,7 @@ allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
+ google()
}
}
diff --git a/floatwindow/build.gradle b/floatwindow/build.gradle
index ee82bbb..28f99a3 100644
--- a/floatwindow/build.gradle
+++ b/floatwindow/build.gradle
@@ -28,7 +28,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile 'com.android.support:appcompat-v7:26.+'
+ compile 'com.android.support:appcompat-v7:26.1.0'
testCompile 'junit:junit:4.12'
}
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/FloatWindow.java b/floatwindow/src/main/java/com/yhao/floatwindow/FloatWindow.java
index 966ee51..f748c75 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/FloatWindow.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/FloatWindow.java
@@ -1,7 +1,10 @@
package com.yhao.floatwindow;
import android.animation.TimeInterpolator;
+import android.app.Application;
+import android.content.ComponentCallbacks;
import android.content.Context;
+import android.content.res.Configuration;
import android.support.annotation.LayoutRes;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
@@ -20,13 +23,35 @@
public class FloatWindow {
- private FloatWindow() {
+ private FloatWindow(Context applicationContext) {
+ Application application = (Application) applicationContext;
+ application.registerComponentCallbacks(new ComponentCallbacks() {
+ @Override
+ public void onConfigurationChanged(Configuration configuration) {
+ // 屏幕方向变化
+ Util.orientationChanged();
+
+ int ori = configuration.orientation;
+ for (IFloatWindow window : mFloatWindowMap.values()) {
+ if (window != null) {
+ window.orientationChanged(ori);
+ }
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+
+ }
+ });
}
private static final String mDefaultTag = "default_float_window_tag";
private static Map mFloatWindowMap;
+ private static FloatWindow sInstance;
+
public static IFloatWindow get() {
return get(mDefaultTag);
}
@@ -35,11 +60,13 @@ public static IFloatWindow get(@NonNull String tag) {
return mFloatWindowMap == null ? null : mFloatWindowMap.get(tag);
}
- private static B mBuilder = null;
-
@MainThread
- public static B with(@NonNull Context applicationContext) {
- return mBuilder = new B(applicationContext);
+ public synchronized static B with(@NonNull Context applicationContext) {
+ if (sInstance == null) {
+ sInstance = new FloatWindow(applicationContext);
+ }
+
+ return new B(applicationContext);
}
public static void destroy() {
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindow.java b/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindow.java
index 18b1d3d..10d6b34 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindow.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindow.java
@@ -29,4 +29,6 @@ public abstract class IFloatWindow {
public abstract View getView();
abstract void dismiss();
+
+ abstract void orientationChanged(int ori);
}
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindowImpl.java b/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindowImpl.java
index 84313cc..82d67da 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindowImpl.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindowImpl.java
@@ -47,7 +47,6 @@ public class IFloatWindowImpl extends IFloatWindow {
private int mSlop;
-
private IFloatWindowImpl() {
}
@@ -66,28 +65,7 @@ private IFloatWindowImpl() {
mFloatView.setSize(mB.mWidth, mB.mHeight);
mFloatView.setGravity(mB.gravity, mB.xOffset, mB.yOffset);
mFloatView.setView(mB.mView);
- mFloatLifecycle = new FloatLifecycle(mB.mApplicationContext, mB.mShow, mB.mActivities, mB.lifecycleListener /*new LifecycleListener() {
-
- @Override
- public void onShow() {
- show();
- }
-
- @Override
- public void onHide() {
- hide();
- }
-
- @Override
- public void onBackToDesktop() {
- if (!mB.mDesktopShow) {
- hide();
- }
- if (mB.mViewStateListener != null) {
- mB.mViewStateListener.onBackToDesktop();
- }
- }
- }*/);
+ mFloatLifecycle = new FloatLifecycle(mB.mApplicationContext, mB.mShow, mB.mActivities, mB.lifecycleListener);
}
@Override
@@ -103,6 +81,7 @@ public void show() {
getView().setVisibility(View.VISIBLE);
isShow = true;
}
+
if (mB.mViewStateListener != null) {
mB.mViewStateListener.onShow();
}
@@ -134,6 +113,21 @@ void dismiss() {
}
}
+ @Override
+ void orientationChanged(int ori) {
+ View view = getView();
+ // do not callback if no view.
+ if (view == null || view.getParent() == null) {
+ return;
+ }
+
+ updateXYWithLimit(getX(), getY());
+
+ if (mB.mViewStateListener != null) {
+ mB.mViewStateListener.onOrientationChanged(ori);
+ }
+ }
+
@Override
public void updateX(int x) {
checkMoveType();
@@ -218,19 +212,7 @@ public boolean onTouch(View v, MotionEvent event) {
changeY = event.getRawY() - lastY;
newX = (int) (mFloatView.getX() + changeX);
newY = (int) (mFloatView.getY() + changeY);
- if (newX < 0) {
- newX = 0;
- }
- if (newX > Util.getScreenWidth(mB.mApplicationContext) - v.getWidth()) {
- newX = Util.getScreenWidth(mB.mApplicationContext) - v.getWidth();
- }
- if (newY < 0) {
- newY = 0;
- }
- if (newY > Util.getScreenHeight(mB.mApplicationContext) - v.getHeight()) {
- newY = Util.getScreenHeight(mB.mApplicationContext) - v.getHeight();
- }
- mFloatView.updateXY(newX, newY);
+ updateXYWithLimit(newX, newY);
if (mB.mViewStateListener != null) {
mB.mViewStateListener.onPositionUpdate(MotionEvent.ACTION_MOVE, newX, newY);
}
@@ -295,6 +277,23 @@ public void onAnimationUpdate(ValueAnimator animation) {
}
}
+ private void updateXYWithLimit(int newX, int newY) {
+ View v = getView();
+ if (newX < 0) {
+ newX = 0;
+ }
+ if (newX > Util.getScreenWidth(mB.mApplicationContext) - v.getWidth()) {
+ newX = Util.getScreenWidth(mB.mApplicationContext) - v.getWidth();
+ }
+ if (newY < 0) {
+ newY = 0;
+ }
+ if (newY > Util.getScreenHeight(mB.mApplicationContext) - v.getHeight()) {
+ newY = Util.getScreenHeight(mB.mApplicationContext) - v.getHeight();
+ }
+ mFloatView.updateXY(newX, newY);
+ }
+
private void startAnimator() {
if (mB.mInterpolator == null) {
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/Util.java b/floatwindow/src/main/java/com/yhao/floatwindow/Util.java
index 585117b..34e0bcc 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/Util.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/Util.java
@@ -49,4 +49,8 @@ static int getScreenHeight(Context context) {
static boolean isViewVisible(View view) {
return view.getGlobalVisibleRect(new Rect());
}
+
+ static void orientationChanged() {
+ sPoint = null;
+ }
}
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListener.java b/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListener.java
index b4d2219..dd741fa 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListener.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListener.java
@@ -17,5 +17,5 @@ public interface ViewStateListener {
void onMoveAnimEnd();
- void onBackToDesktop();
+ void onOrientationChanged(int i);
}
diff --git a/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListenerAdapter.java b/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListenerAdapter.java
index 1b15a48..ca13c85 100644
--- a/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListenerAdapter.java
+++ b/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListenerAdapter.java
@@ -7,30 +7,23 @@
public class ViewStateListenerAdapter implements ViewStateListener {
@Override
- public void onPositionUpdate(int action, int x, int y) {
- }
+ public void onPositionUpdate(int action, int x, int y) {}
@Override
- public void onShow() {
- }
+ public void onShow() {}
@Override
- public void onHide() {
- }
+ public void onHide() {}
@Override
- public void onDismiss() {
- }
+ public void onDismiss() {}
@Override
- public void onMoveAnimStart() {
- }
+ public void onMoveAnimStart() {}
@Override
- public void onMoveAnimEnd() {
- }
+ public void onMoveAnimEnd() {}
@Override
- public void onBackToDesktop() {
- }
+ public void onOrientationChanged(int i) {}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 48927dc..4cd4b5e 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Nov 14 22:07:14 GMT+08:00 2017
+#Wed Mar 25 18:32:47 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
diff --git a/sample/src/main/java/com/example/yhao/floatwindow/A_Activity.java b/sample/src/main/java/com/example/yhao/floatwindow/A_Activity.java
index f6278e7..c3c7b5b 100644
--- a/sample/src/main/java/com/example/yhao/floatwindow/A_Activity.java
+++ b/sample/src/main/java/com/example/yhao/floatwindow/A_Activity.java
@@ -4,14 +4,9 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
-import android.view.animation.BounceInterpolator;
-import android.widget.ImageView;
-import android.widget.Toast;
import com.example.yhao.fixedfloatwindow.R;
import com.yhao.floatwindow.FloatWindow;
-import com.yhao.floatwindow.MoveType;
-import com.yhao.floatwindow.Screen;
public class A_Activity extends AppCompatActivity {
@@ -21,6 +16,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
setTitle("A");
+
+ FloatWindow.get().show();
}
public void change(View view) {
diff --git a/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java b/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java
index 4a14c04..e1c07dd 100644
--- a/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java
+++ b/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java
@@ -9,6 +9,7 @@
import com.example.yhao.fixedfloatwindow.R;
import com.yhao.floatwindow.FloatWindow;
+import com.yhao.floatwindow.LifecycleListener;
import com.yhao.floatwindow.MoveType;
import com.yhao.floatwindow.PermissionListener;
import com.yhao.floatwindow.Screen;
@@ -21,7 +22,6 @@
public class BaseApplication extends Application {
-
private static final String TAG = "FloatWindow";
@Override
@@ -32,7 +32,7 @@ public void onCreate() {
imageView.setImageResource(R.drawable.icon);
FloatWindow
- .with(getApplicationContext())
+ .with(this)
.setView(imageView)
.setWidth(Screen.width, 0.2f) //设置悬浮控件宽高
.setHeight(Screen.width, 0.2f)
@@ -43,6 +43,22 @@ public void onCreate() {
.setFilter(true, A_Activity.class, C_Activity.class)
.setViewStateListener(mViewStateListener)
.setPermissionListener(mPermissionListener)
+ .setLifecycleListener(new LifecycleListener() {
+ @Override
+ public void onShow() {
+
+ }
+
+ @Override
+ public void onHide() {
+
+ }
+
+ @Override
+ public void onBackToDesktop() {
+
+ }
+ })
.setDesktopShow(true)
.build();
@@ -99,8 +115,8 @@ public void onMoveAnimEnd() {
}
@Override
- public void onBackToDesktop() {
- Log.d(TAG, "onBackToDesktop");
+ public void onOrientationChanged(int i) {
+ Log.d(TAG, "onOrientationUpdate:" + i);
}
};
}