-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
349 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package luyao.box | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import kotlin.properties.Delegates | ||
|
||
/** | ||
* Created by luyao | ||
* on 2018/12/29 13:33 | ||
*/ | ||
class App : Application() { | ||
|
||
companion object { | ||
var CONTEXT: Context by Delegates.notNull() } | ||
override fun onCreate() { | ||
super.onCreate() | ||
CONTEXT=applicationContext | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package luyao.box.adapter | ||
|
||
import com.chad.library.adapter.base.BaseQuickAdapter | ||
import com.chad.library.adapter.base.BaseViewHolder | ||
import luyao.box.R | ||
import luyao.box.bean.HistoryBean | ||
|
||
/** | ||
* Created by luyao | ||
* on 2019/1/10 13:12 | ||
*/ | ||
class HistoryAdapter(layoutResId: Int = R.layout.item_history) : | ||
BaseQuickAdapter<HistoryBean, BaseViewHolder>(layoutResId) { | ||
|
||
override fun convert(helper: BaseViewHolder, item: HistoryBean) { | ||
val position = helper.layoutPosition | ||
if (position == 0 || getItem(position - 1)?.packageName != item.packageName) { | ||
helper.setVisible(R.id.historyPackageName, true) | ||
helper.setText(R.id.historyPackageName, item.packageName) | ||
} else { | ||
helper.setVisible(R.id.historyPackageName, false) | ||
} | ||
helper.setText(R.id.historyWindowName, item.windowName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package luyao.box.bean | ||
|
||
/** | ||
* Created by luyao | ||
* on 2019/1/10 13:18 | ||
*/ | ||
data class HistoryBean( | ||
val packageName:String, | ||
val windowName:String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 32 additions & 6 deletions
38
app/src/main/java/luyao/box/ui/activity/CurrentActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,56 @@ | ||
package luyao.box.ui.activity | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.provider.Settings | ||
import kotlinx.android.synthetic.main.activity_current.* | ||
import kotlinx.android.synthetic.main.title_layout.* | ||
import luyao.box.R | ||
import luyao.box.common.base.BaseActivity | ||
import luyao.box.service.BoxAccessibilityService | ||
import luyao.box.util.AccessibilityUtils | ||
import luyao.box.util.Preference | ||
|
||
class CurrentActivity : BaseActivity() { | ||
|
||
private var showWindow by Preference(Preference.SHOW_WINDOW, false) | ||
private val isOpen by lazy { | ||
AccessibilityUtils.checkBoxAccessibilityEnabled(this) | ||
} | ||
|
||
override fun getLayoutResId() = R.layout.activity_current | ||
|
||
override fun initView() { | ||
mToolbar.title=getString(R.string.current_activity) | ||
mToolbar.title = getString(R.string.current_activity) | ||
windowSwitch.isChecked=showWindow | ||
windowSwitch.setOnCheckedChangeListener { _, isChecked -> updateWindow(isChecked) } | ||
} | ||
|
||
override fun initData() { | ||
initAccessibilityService() | ||
|
||
} | ||
|
||
private fun initAccessibilityService(){ | ||
val isOpen=AccessibilityUtils.checkAccessibilityEnabled("$packageName/${BoxAccessibilityService::class.java.canonicalName.replace(packageName, "")}",this) | ||
accessibilitySwitch.isChecked=isOpen | ||
private fun initAccessibilityService() { | ||
accessibilitySwitch.isChecked = isOpen | ||
if (!isOpen) | ||
AccessibilityUtils.goToAccessibilitySetting(this) | ||
} | ||
|
||
private fun updateWindow(isOpen: Boolean) { | ||
if (AccessibilityUtils.checkBoxAccessibilityEnabled(this)) { | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1 && !Settings.canDrawOverlays(this)) { | ||
windowSwitch.isChecked = false | ||
showWindow = false | ||
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) | ||
intent.data = Uri.parse("package:$packageName") | ||
startActivity(intent) | ||
} else { | ||
showWindow = isOpen | ||
windowSwitch.isChecked = isOpen | ||
} | ||
} else { | ||
showWindow = false | ||
windowSwitch.isChecked = false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package luyao.box.util | ||
|
||
import android.content.Context | ||
import android.graphics.PixelFormat | ||
import android.os.Build | ||
import android.view.Gravity | ||
import android.view.LayoutInflater | ||
import android.view.WindowManager | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import luyao.box.R | ||
import luyao.box.adapter.HistoryAdapter | ||
import luyao.box.bean.HistoryBean | ||
import luyao.box.dp2px | ||
|
||
/** | ||
* Created by luyao | ||
* on 2019/1/10 14:37 | ||
*/ | ||
class FloatWindowManager(mContext: Context) { | ||
|
||
|
||
private val windowManager by lazy { mContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager } | ||
private val windowAdapter by lazy { HistoryAdapter() } | ||
private val view by lazy { LayoutInflater.from(mContext).inflate(R.layout.window_history, null) } | ||
private val layoutParams: WindowManager.LayoutParams by lazy { WindowManager.LayoutParams() } | ||
private val windowRecycleView by lazy { view.findViewById<RecyclerView>(R.id.windowRecycleView) } | ||
|
||
init { | ||
layoutParams.run { | ||
gravity=Gravity.START and Gravity.TOP | ||
width = mContext.dp2px(200) | ||
height = mContext.dp2px(150) | ||
format = PixelFormat.TRANSPARENT | ||
flags = 0x18 | ||
type = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) | ||
WindowManager.LayoutParams.TYPE_TOAST | ||
else | ||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY | ||
} | ||
|
||
|
||
windowRecycleView.run { | ||
layoutManager = LinearLayoutManager(mContext) | ||
adapter = windowAdapter | ||
} | ||
windowManager.addView(view, layoutParams) | ||
} | ||
|
||
fun addItem(historyBean: HistoryBean) { | ||
windowAdapter.addData(0, historyBean) | ||
windowAdapter.notifyDataSetChanged() | ||
windowRecycleView.scrollToPosition(0) | ||
windowManager.updateViewLayout(view, layoutParams) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.