Skip to content

Commit 01e33dc

Browse files
committed
Add mouse draw view
0 parents  commit 01e33dc

30 files changed

+589
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdkVersion 29
7+
buildToolsVersion "30.0.3"
8+
9+
defaultConfig {
10+
applicationId "io.github.virresh.matvt"
11+
minSdkVersion 21
12+
targetSdkVersion 29
13+
versionCode 1
14+
versionName "1.0"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
28+
implementation 'androidx.leanback:leanback:1.0.0'
29+
implementation 'androidx.appcompat:appcompat:1.2.0'
30+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="io.github.virresh.matvt">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/Theme.MATVTMouseForAndroidTVToggle">
11+
<activity android:name=".gui.GuiActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
19+
<service
20+
android:name=".services.MouseEventService"
21+
android:label="Mouse Event Listening Service"
22+
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
23+
<intent-filter>
24+
<action android:name="android.accessibilityservice.AccessibilityService" />
25+
</intent-filter>
26+
<meta-data
27+
android:name="android.accessibilityservice"
28+
android:resource="@xml/accessibility_service_config" />
29+
</service>
30+
</application>
31+
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.virresh.matvt.gui;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.app.Activity;
6+
import android.os.Bundle;
7+
8+
import io.github.virresh.matvt.R;
9+
10+
public class GuiActivity extends Activity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_gui);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.github.virresh.matvt.services;
2+
3+
import android.accessibilityservice.AccessibilityService;
4+
import android.accessibilityservice.AccessibilityServiceInfo;
5+
import android.util.Log;
6+
import android.view.KeyEvent;
7+
import android.view.accessibility.AccessibilityEvent;
8+
9+
public class MouseEventService extends AccessibilityService {
10+
11+
private static String LOG_TAG = "MATVT_SERVICE";
12+
13+
@Override
14+
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
15+
16+
}
17+
18+
@Override
19+
protected boolean onKeyEvent(KeyEvent event) {
20+
Log.i(LOG_TAG, event.toString());
21+
return super.onKeyEvent(event);
22+
}
23+
24+
@Override
25+
public void onInterrupt() {
26+
27+
}
28+
29+
@Override
30+
protected void onServiceConnected() {
31+
super.onServiceConnected();
32+
Log.i(LOG_TAG, "TV Service Connected!");
33+
// AccessibilityServiceInfo eventConnectionInfo = new AccessibilityServiceInfo();
34+
// eventConnectionInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
35+
// this.setServiceInfo(eventConnectionInfo);
36+
// Log.i(LOG_TAG, "Setting event types to " + eventConnectionInfo.eventTypes);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.virresh.matvt.view;
2+
3+
import android.content.Context;
4+
import android.graphics.Bitmap;
5+
import android.graphics.Canvas;
6+
import android.graphics.Paint;
7+
import android.graphics.PointF;
8+
import android.graphics.drawable.BitmapDrawable;
9+
import android.view.View;
10+
11+
import io.github.virresh.matvt.R;
12+
13+
/**
14+
* Draw a Mouse Cursor on screen
15+
*/
16+
public class MouseCursorView extends View {
17+
private static final int DEFAULT_ALPHA= 255;
18+
19+
private PointF mPointerLocation;
20+
private Paint mPaintBox;
21+
private Bitmap mPointerBitmap;
22+
private int mAlphaPointer= DEFAULT_ALPHA;
23+
24+
25+
public MouseCursorView(Context context) {
26+
super(context);
27+
setWillNotDraw(false);
28+
mPointerLocation = new PointF();
29+
mPaintBox = new Paint();
30+
31+
BitmapDrawable bp = (BitmapDrawable) getContext().getResources().getDrawable(R.drawable.pointer);
32+
Bitmap originalBitmap = bp.getBitmap();
33+
mPointerBitmap = originalBitmap;
34+
}
35+
36+
@Override
37+
protected void onDraw(Canvas canvas) {
38+
super.onDraw(canvas);
39+
mPaintBox.setAlpha(mAlphaPointer);
40+
canvas.drawBitmap(mPointerBitmap, mPointerLocation.x, mPointerLocation.y, mPaintBox);
41+
}
42+
}

app/src/main/res/drawable/pointer.png

4.34 KB
Loading
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".gui.GuiActivity">
8+
9+
<TextView
10+
android:id="@+id/textView"
11+
android:layout_width="536dp"
12+
android:layout_height="121dp"
13+
android:layout_marginStart="212dp"
14+
android:layout_marginTop="210dp"
15+
android:layout_marginEnd="213dp"
16+
android:layout_marginBottom="210dp"
17+
android:text="Button Events"
18+
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintEnd_toEndOf="parent"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent" />
22+
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<!-- <io.github.virresh.matvt.view.MouseCursorView
7+
style="@style/Widget.Theme.MATVTMouseForAndroidTVToggle.MyView"
8+
android:layout_width="300dp"
9+
android:layout_height="300dp"
10+
android:paddingLeft="20dp"
11+
android:paddingBottom="40dp"
12+
app:exampleDimension="24sp"
13+
app:exampleDrawable="@android:drawable/ic_menu_add"
14+
app:exampleString="Hello, BlackMouseCursor" />
15+
-->
16+
</FrameLayout>
3.51 KB
Loading
2.57 KB
Loading
4.81 KB
Loading
7.72 KB
Loading
10.4 KB
Loading
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<style name="Widget.Theme.MATVTMouseForAndroidTVToggle.MyView" parent="">
4+
<item name="android:background">@color/gray_600</item>
5+
<item name="exampleColor">@color/light_blue_600</item>
6+
</style>
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
<declare-styleable name="BlackMouseCursor">
3+
<attr name="exampleString" format="string" />
4+
<attr name="exampleDimension" format="dimension" />
5+
<attr name="exampleColor" format="color" />
6+
<attr name="exampleDrawable" format="color|reference" />
7+
</declare-styleable>
8+
</resources>

app/src/main/res/values/colors.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<color name="light_blue_400">#FF29B6F6</color>
3+
<color name="light_blue_600">#FF039BE5</color>
4+
<color name="gray_400">#FFBDBDBD</color>
5+
<color name="gray_600">#FF757575</color>
6+
</resources>

app/src/main/res/values/strings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="app_name">MATVT - Mouse for Android TV Toggle</string>
3+
<string name="accessibility_service_description">Control mouse cursor on your Android TV using your remote</string>
4+
</resources>

app/src/main/res/values/styles.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<style name="Widget.Theme.MATVTMouseForAndroidTVToggle.MyView" parent="">
4+
<item name="android:background">@color/gray_400</item>
5+
<item name="exampleColor">@color/light_blue_400</item>
6+
</style>
7+
</resources>

app/src/main/res/values/themes.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
3+
<style name="Theme.MATVTMouseForAndroidTVToggle" parent="@style/Theme.Leanback" />
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:description="@string/accessibility_service_description"
4+
android:accessibilityEventTypes="typeAllMask"
5+
android:canRequestFilterKeyEvents="true"
6+
android:accessibilityFlags="flagRequestFilterKeyEvents"
7+
android:accessibilityFeedbackType="feedbackGeneric"
8+
android:notificationTimeout="100"
9+
android:canRetrieveWindowContent="true"
10+
android:settingsActivity="io.github.virresh.matvt.gui.GuiActivity"
11+
/>

build.gradle

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
buildscript {
3+
repositories {
4+
google()
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:4.1.2'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
}
21+
22+
task clean(type: Delete) {
23+
delete rootProject.buildDir
24+
}

gradle.properties

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app"s APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Automatically convert third-party libraries to use AndroidX
19+
android.enableJetifier=true

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sun Jan 17 00:02:44 IST 2021
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

0 commit comments

Comments
 (0)