Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eaf9b108 authored by Scott Brady's avatar Scott Brady Committed by Steve Kondik
Browse files

Fixed up mouse pointer with auto bluetooth on and scroll Change-Id:...

Fixed up mouse pointer with auto bluetooth on and scroll Change-Id: I6850236a3058475694793e40717f69683c50edd7

Change-Id: I760e09e63c51278c96e2ae3b75b02d73da091eb5
parent 937a7ba3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2019,6 +2019,14 @@ public final class Settings {
         */
        public static final String POINTER_LOCATION = "pointer_location";

        /**
         * Show mouse pointer on screen?
         * 0 = no
         * 1 = yes
         * @hide
         */
        public static final String MOUSE_POINTER = "mouse_pointer";

        /**
         * Whether to play a sound for low-battery alerts.
         * @hide
+8 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ package android.server;

import android.bluetooth.BluetoothHid;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetoothHid;
@@ -369,6 +370,13 @@ public class BluetoothHidService extends IBluetoothHid.Stub {
                    state == BluetoothHid.STATE_CONNECTING ||
                    state == BluetoothHid.STATE_CONNECTED) {
                setHidDevicePriority(device, BluetoothHid.PRIORITY_AUTO_CONNECT);
		if ((device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PERIPHERAL_POINTING_DEVICE) || 
		    (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PERIPHERAL_COMBO_KEYBORD_POINTING)) {
		    Settings.System.putInt(mContext.getContentResolver(), Settings.System.MOUSE_POINTER, 1);
		}		
            }
	    else if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PERIPHERAL_POINTING_DEVICE) {
		    Settings.System.putInt(mContext.getContentResolver(), Settings.System.MOUSE_POINTER, 0);
	    }
            Intent intent = new Intent(BluetoothHid.HID_DEVICE_STATE_CHANGED_ACTION);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+163 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.widget;

import android.app.Instrumentation;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

public class MousePointerView extends View {
    private static final String TAG = "MousePointer";

    private float mouseX;
    private float mouseY;
    private float lastX;
    private float lastY;

    private Paint mPaint;
    private Path mPath;

    public MousePointerView(Context c) {
        super(c);
        setFocusable(true);
        mPaint = new Paint();
	mPaint.setAntiAlias(true);
        mPath = new Path();
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
	if (mouseX == 0 && mouseY == 0) {
	}
	else if ((lastX == 0 && lastY == 0) || lastX - mouseX < 10.0f || lastY - mouseY < 10.0f) {
            // Draw mouse cursor
	    mPath.rewind();
            mPath.moveTo(mouseX, mouseY);
            mPath.lineTo(mouseX + 12.0f, mouseY + 12.0f);
            mPath.lineTo(mouseX + 7.0f, mouseY + 12.0f);
            mPath.lineTo(mouseX + 11.0f, mouseY + 20.0f);
            mPath.lineTo(mouseX + 8.0f, mouseY + 21.0f);
            mPath.lineTo(mouseX + 4.0f, mouseY + 13.0f);
            mPath.lineTo(mouseX + 0.0f, mouseY + 17.0f);
            mPath.close();
            mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mPaint.setStrokeWidth(1);
            mPaint.setColor(0xffffffff);
            canvas.drawPath(mPath, mPaint);
	    mPaint.setStyle(Paint.Style.STROKE);
	    mPaint.setStrokeWidth(1);
            mPaint.setColor(0xff000000);
	    mPath.offset(0,0);
	    canvas.drawPath(mPath, mPaint);
	}
    }
    
    private void mouseScrollUp()
    {
	long downTime = SystemClock.uptimeMillis();
	long eventTime = SystemClock.uptimeMillis();
	Instrumentation inst = new Instrumentation();
	MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, mouseX, mouseY, 0);
	inst.sendPointerSync(event);
	eventTime = SystemClock.uptimeMillis();
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 5.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 10.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 15.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 25.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 35.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY + 45.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, mouseX, mouseY + 60.0f, 0);
	inst.sendPointerSync(event);
    }

    private void mouseScrollDown()
    {
	long downTime = SystemClock.uptimeMillis();
	long eventTime = SystemClock.uptimeMillis();
	Instrumentation inst = new Instrumentation();
	MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, mouseX, mouseY, 0);
	inst.sendPointerSync(event);
	eventTime = SystemClock.uptimeMillis();
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 5.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 10.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 15.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 25.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 35.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, mouseX, mouseY - 45.0f, 0);
	inst.sendPointerSync(event);
	event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, mouseX, mouseY - 60.0f, 0);
	inst.sendPointerSync(event);
    }

    public void addTouchEvent(MotionEvent event) {
	lastX = mouseX;
	lastY = mouseY;
	mouseX = event.getX();
	mouseY = event.getY();
	postInvalidate();
    }

    public void addKeyEvent(KeyEvent event) {
	if (event.getKeyCode() == 0x5c) {
		mouseScrollUp();
	}
	else if (event.getKeyCode() == 0x5d) {
		mouseScrollDown();
	}
	postInvalidate();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        addTouchEvent(event);
        return true;
    }

    @Override
    public boolean onTrackballEvent(MotionEvent event) {
        return super.onTrackballEvent(event);
    }
 
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        addKeyEvent(event);
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return true;
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -119,6 +119,9 @@ enum {

    /* The input device has switches. */
    INPUT_DEVICE_CLASS_SWITCH        = 0x00000080,

    /* The input device is a mouse. */
    INPUT_DEVICE_CLASS_MOUSE         = 0x00000100,
};

/*
+62 −0
Original line number Diff line number Diff line
@@ -504,6 +504,68 @@ private:
    void sync(nsecs_t when);
};

class MouseInputMapper : public InputMapper {
public:
    MouseInputMapper(InputDevice* device, int32_t associatedDisplayId);
    virtual ~MouseInputMapper();

    virtual uint32_t getSources();
    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
    virtual void dump(String8& dump);
    virtual void reset();
    virtual void process(const RawEvent* rawEvent);

    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);

private:
    Mutex mLock;

    int32_t mAssociatedDisplayId;

    struct Accumulator {
        enum {
            FIELD_BTN_MOUSE = 1,
            FIELD_REL_X = 2,
            FIELD_REL_Y = 4,
            FIELD_BTN_RIGHT = 8,
            FIELD_BTN_MIDDLE = 16, 
            FIELD_BTN_SIDE = 32, 
            FIELD_BTN_EXTRA = 64, 
            FIELD_BTN_FORWARD = 128, 
            FIELD_BTN_BACK = 256,
	    FIELD_REL_WHEEL = 512,
        };

        uint32_t fields;

        bool btnMouse;
        bool btnRight;
        bool btnMiddle; 
	bool btnSide;
	bool btnExtra;
	bool btnForward;
	bool btnBack;
	bool btnScrollUp;
	bool btnScrollDown;
        int32_t relX;
        int32_t relY;
        int32_t absX;
        int32_t absY;

        inline void clear() {
            fields = 0;
        }
    } mAccumulator;

    struct LockedState {
        bool down;
        nsecs_t downTime;
    } mLocked;

    void initializeLocked();

    void sync(nsecs_t when);
};

class TouchInputMapper : public InputMapper {
public:
Loading