Skip to content

Commit

Permalink
Add InputMethodUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Aug 17, 2019
1 parent 8ea941b commit 3fdc062
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 26 deletions.
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
> [EasyFloat:浮窗从未如此简单](https://www.jianshu.com/p/7d1a7c82094a)
### 特点功能:
- 支持单页面浮窗,无需权限申请
- 支持全局浮窗、应用前台浮窗,需要授权悬浮窗权限
- 自动权限检测、自动跳转浮窗权限管理页、自动处理授权结果
- 支持系统浮窗的页面过滤
- 支持拖拽,支持各种状态的回调
- 支持默认位置的设定,支持对齐方式和偏移量的设定
- 支持创建多个单页面浮窗、多个系统浮窗,Tag进行区分
- 支持出入动画的设定,有默认动画,可自行替换(策略模式)
- 使用简单、链式调用,无侵入性
- 支持xml直接使用,满足拖拽控件的需求
- 支持解锁更多姿势,如:拖拽缩放、通知弹窗...
- **支持单页面浮窗,无需权限申请**
- **支持全局浮窗、应用前台浮窗,需要授权悬浮窗权限**
- **自动权限检测、自动跳转浮窗权限管理页、自动处理授权结果**
- **支持系统浮窗的页面过滤**
- **支持拖拽,支持各种状态的回调**
- **支持默认位置的设定,支持对齐方式和偏移量的设定**
- **支持创建多个单页面浮窗、多个系统浮窗,Tag进行区分**
- **支持出入动画的设定,有默认动画,可自行替换(策略模式)**
- **使用简单、链式调用,无侵入性**
- **支持xml直接使用,满足拖拽控件的需求**
- **支持解锁更多姿势,如:拖拽缩放、通知弹窗...**


|权限申请|系统浮窗|
Expand All @@ -37,7 +37,7 @@ allprojects {
- 在应用模块的`build.gradle`添加:
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.0.2'
implementation 'com.github.princekin-f:EasyFloat:1.0.3'
}
```

Expand Down Expand Up @@ -133,7 +133,7 @@ setDragEnable(activity: Activity? = null, dragEnable: Boolean, floatTag: String?
isShow(activity: Activity? = null, floatTag: String? = null)
```

补充一下:**`? = null` 代表可选参数,不填也行,默认值为null。下同。**
**补充一下:`? = null` 代表可选参数,不填也行,默认值为null。下同。**

#### 系统浮窗的相关API:
```
Expand Down Expand Up @@ -168,6 +168,16 @@ removeFilters(tag: String? = null, vararg clazz: Class<*>)
clearFilters(tag: String? = null)
```

#### 系统浮窗中使用`EditText`
**1,为`EditText`设置点击事件,调用`openInputMethod`方法:**
```
InputMethodUtils.openInputMethod(editText, tag)
```
**2,软键盘关闭时,调用`closedInputMethod`方法:**
```
InputMethodUtils.closedInputMethod(tag)
```

#### 直接在xml布局使用拖拽控件:
```
<com.lzf.easyfloat.widget.activityfloat.FloatingView
Expand All @@ -183,7 +193,7 @@ clearFilters(tag: String? = null)
</com.lzf.easyfloat.widget.activityfloat.FloatingView>
```
需要为FloatingView设置点击事件,不然无法拖拽:
**需要为FloatingView设置点击事件,不然无法拖拽:**
```
floatingView.setOnClickListener {}
```
Expand All @@ -198,6 +208,11 @@ floatingView.setOnClickListener {}

### 更新日志:
#### v 1.0.2:
#### v 1.0.3:
- 修改魅族手机,权限申请回调异常的问题;
- 为系统浮窗的`EditText`,提供了软键盘的打开、关闭后的焦点移除;
- 但暂未提供软键盘的关闭监听方案,希望大家一起努力。

#### v 1.0.2:
- 修改`enum`包名,解决Java特殊路径无法调用的问题;
- 添加`@JvmOverloads`注解,支持对Java的方法重载。
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lzf.easyfloat.permission

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Fragment
import android.content.Intent
Expand All @@ -20,7 +19,6 @@ internal class PermissionFragment : Fragment() {
companion object {
private var onPermissionResult: OnPermissionResult? = null

@SuppressLint("CommitTransaction")
fun requestPermission(activity: Activity, onPermissionResult: OnPermissionResult) {
this.onPermissionResult = onPermissionResult
activity.fragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void applyPermission(Fragment fragment) {
Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
// intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");//remove this line code for fix flyme6.3
intent.putExtra("packageName", fragment.getActivity().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
fragment.startActivityForResult(intent, PermissionUtils.requestCode);
} catch (Exception e) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.lzf.easyfloat.utils

import android.content.Context.INPUT_METHOD_SERVICE
import android.os.Handler
import android.os.Looper
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import com.lzf.easyfloat.service.FloatService

/**
* @author: liuzhenfeng
* @function: 软键盘工具类
* 1,解决系统浮窗内的EditText,无法弹起软键盘的问题;
* 2,暂未提供软键盘关闭的监听,需要使用者自行处理,希望各位大佬共同提供解决方案。
* @date: 2019-08-17 11:11
*/
object InputMethodUtils {

/**
* 让系统浮窗获取焦点,并打开软键盘
*/
@JvmStatic
@JvmOverloads
fun openInputMethod(editText: EditText, tag: String? = null) {
FloatService.floatMap[tag ?: FloatService.DEFAULT_TAG]?.run {
// 更改flags,并刷新布局,让系统浮窗获取焦点
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
windowManager.updateViewLayout(frameLayout, params)
}

Handler(Looper.getMainLooper()).postDelayed({
// 打开软键盘
val inputManager =
editText.context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager?
inputManager?.showSoftInput(editText, 0)
}, 100)
}

/**
* 当软键盘关闭时,调用此方法,移除系统浮窗的焦点,不然系统返回键无效
*/
@JvmStatic
@JvmOverloads
fun closedInputMethod(tag: String? = null) {
FloatService.floatMap[tag ?: FloatService.DEFAULT_TAG]?.run {
params.flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
windowManager.updateViewLayout(frameLayout, params)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import com.lzf.easyfloat.utils.DisplayUtils
*/
internal class AppFloatManager(val context: Context, var config: FloatConfig) {

private lateinit var windowManager: WindowManager
private lateinit var params: WindowManager.LayoutParams
private var frameLayout: ParentFrameLayout? = null
lateinit var windowManager: WindowManager
lateinit var params: WindowManager.LayoutParams
var frameLayout: ParentFrameLayout? = null
private lateinit var touchUtils: TouchUtils


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.os.Bundle
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.widget.EditText
import android.widget.TextView
import com.lzf.easyfloat.EasyFloat
import com.lzf.easyfloat.anim.AppFloatDefaultAnimator
import com.lzf.easyfloat.anim.DefaultAnimator
Expand All @@ -13,17 +15,45 @@ import com.lzf.easyfloat.enums.SidePattern
import com.lzf.easyfloat.example.R
import com.lzf.easyfloat.interfaces.OnFloatCallbacks
import com.lzf.easyfloat.interfaces.OnInvokeView
import com.lzf.easyfloat.utils.InputMethodUtils
import kotlinx.android.synthetic.main.activity_third.*

/**
* @author: liuzhenfeng
* @function:
* @function: 测试EditText
* @date: 2019-07-26 13:13
*/
class ThirdActivity : Activity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_third)

openEditTextFloat.setOnClickListener {
showEditTextFloat()
}
}

private fun showEditTextFloat(tag: String? = "editTextFloat") {
EasyFloat.with(this)
.setLayout(R.layout.float_edit)
.setShowPattern(ShowPattern.ALL_TIME)
.setGravity(Gravity.CENTER)
.setTag(tag)
.invokeView(OnInvokeView {
it.findViewById<EditText>(R.id.editText).setOnClickListener { et ->
InputMethodUtils.openInputMethod(et as EditText, tag)
}

it.findViewById<TextView>(R.id.tvImmClosed).setOnClickListener {
InputMethodUtils.closedInputMethod(tag)
}

it.findViewById<TextView>(R.id.tvCloseFloat).setOnClickListener {
EasyFloat.dismissAppFloat(this, tag)
}
})
.show()
}

private fun showFloat() {
Expand Down
8 changes: 4 additions & 4 deletions example/src/main/res/layout/activity_third.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello EasyFloat" />
android:id="@+id/openEditTextFloat"
style="@style/TextStyle2"
android:layout_marginTop="120dp"
android:text="OpenEditTextFloat" />

</LinearLayout>
31 changes: 31 additions & 0 deletions example/src/main/res/layout/float_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@color/translucent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dp">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/tvImmClosed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="软键盘已关闭"
android:textColor="@color/white" />

<TextView
android:id="@+id/tvCloseFloat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="关闭浮窗"
android:textColor="@color/white" />

</LinearLayout>

0 comments on commit 3fdc062

Please sign in to comment.