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
fun isAccessibilityServiceEnabled(mContext: Context): Boolean { | |
var accessibilityEnabled = 0 | |
val service: String = mContext.packageName + "/" + YourAccessibilityService::class.java.canonicalName | |
try { | |
accessibilityEnabled = Settings.Secure.getInt( | |
mContext.applicationContext.contentResolver, | |
Settings.Secure.ACCESSIBILITY_ENABLED | |
) | |
Log.v(TAG, "accessibilityEnabled = $accessibilityEnabled") | |
} catch (e: Settings.SettingNotFoundException) { |
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
override fun onServiceConnected() { | |
super.onServiceConnected() | |
val wm = getSystemService(WINDOW_SERVICE) as WindowManager | |
val mLayout = FrameLayout(this) | |
val lp = WindowManager.LayoutParams() | |
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY | |
lp.format = PixelFormat.TRANSLUCENT | |
lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | |
lp.width = WindowManager.LayoutParams.WRAP_CONTENT | |
lp.height = WindowManager.LayoutParams.WRAP_CONTENT |
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
fun dispatch(x: Float, y: Float): Boolean { | |
val result = accessibilityService?.dispatchGesture( | |
buildClick(x, y), | |
object : GestureResultCallback() { | |
override fun onCompleted(gestureDescription: GestureDescription?) { | |
super.onCompleted(gestureDescription) | |
Log.d(TAG, "gesture completed") | |
} | |
override fun onCancelled(gestureDescription: GestureDescription?) { |
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
private fun buildClick(x: Float, y: Float): GestureDescription { | |
val clickPath = Path() | |
clickPath.moveTo(x, y) | |
val clickStroke = StrokeDescription(clickPath, 0, 1) | |
val clickBuilder = GestureDescription.Builder() | |
clickBuilder.addStroke(clickStroke) | |
return clickBuilder.build() | |
} | |
private fun buildSwipe( |
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
<?xml version="1.0" encoding="utf-8"?> | |
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" | |
android:accessibilityFlags="flagDefault" | |
android:accessibilityFeedbackType="feedbackGeneric" | |
android:canPerformGestures="true" | |
android:canRetrieveWindowContent="true" /> |
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
class YourAccessibilityService : AccessibilityService() { | |
override fun onServiceConnected() { | |
super.onServiceConnected() | |
Log.d(TAG, "onServiceConnected:") | |
} | |
override fun onAccessibilityEvent(e: AccessibilityEvent?) { | |
Log.d(TAG, "onAccessibilityEvent: $e") | |
} | |
} |
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
<service | |
android:name=".YourAccessibilityService" | |
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> | |
<intent-filter> | |
<action android:name="android.accessibilityservice.AccessibilityService" /> | |
</intent-filter> | |
<meta-data | |
android:name="android.accessibilityservice" | |
android:resource="@xml/your_accessibility_service" /> | |
</service> |
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
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog | |
bottomSheetDialog.setOnShowListener { | |
val dialog = it as BottomSheetDialog | |
val bottomSheet = dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) | |
BottomSheetBehavior.from(bottomSheet).state = BottomSheetBehavior.STATE_EXPANDED | |
} | |
return bottomSheetDialog | |
} |
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
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
(view?.parent as View).setBackgroundColor(Color.TRANSPARENT) | |
val resources = resources | |
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { | |
assert(view != null) | |
val parent = view?.parent as View | |
val layoutParams = parent.layoutParams as CoordinatorLayout.LayoutParams | |
layoutParams.setMargins( |
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
package com.mihir.bottomsheet | |
import android.app.Activity | |
import android.os.Bundle | |
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
NewerOlder