Android Тип сервиса с плавающей кнопкой действия с функцией перетаскивания - PullRequest
0 голосов
/ 25 апреля 2020

Кто-нибудь поможет мне сделать сервисный тип подвижной кнопки с плавающим действием, которая будет отображаться на экране android кнопки, подобной устройству, в приложении Accessibility Scanner https://play.google.com/store/apps/details?id=com.google.android.apps.accessibility.auditor&hl=en, я сделал кнопку, но хочу сделать ее подвижной.

вот xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.shamanland.fab.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:floatingActionButtonColor="#FFF"
        app:floatingActionButtonSize="normal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.32"
        android:src="@drawable/ic_accessibility_black_24dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

вот мой сервис

package com.example.accessibilitysoftware;

import android.accessibilityservice.AccessibilityService;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.RequiresApi;

import com.shamanland.fab.FloatingActionButton;

public class Service extends AccessibilityService  {


    FrameLayout frameLayout;


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
    @Override
    protected void onServiceConnected() {





        // Create an overlay and display the action bar
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        frameLayout = new FrameLayout(this);
        WindowManager.LayoutParams layoutParam = new WindowManager.LayoutParams();
        layoutParam.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
        layoutParam.format = PixelFormat.TRANSLUCENT;
        layoutParam.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        layoutParam.width = WindowManager.LayoutParams.WRAP_CONTENT;

        layoutParam.height = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParam.gravity = Gravity.TOP;
        LayoutInflater inflater = LayoutInflater.from(this);
        inflater.inflate(R.layout.service, frameLayout);
        wm.addView(frameLayout, layoutParam);




        configureFloatingActionButton();
    }
    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
    }
    @Override
    public void onInterrupt() {
    }
    private void configureFloatingActionButton(){
         final FloatingActionButton FLATButton = (FloatingActionButton) frameLayout.findViewById(R.id.floatingActionButton);
        FLATButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                    Toast.makeText(Service.this, "Clicked", Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    }
}

вот манифест

<application
       ...
        <service
            android:name=".Service"
            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/app_service" />
        </service>
    </application>

а вот ре \ xml \ app_service. xml file


<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagDefault"
    android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
    android:canPerformGestures="true"
    android:notificationTimeout="100"
    android:canRetrieveWindowContent="true" />

...