Skip to content

Commit

Permalink
updated to viewbinding and gradle.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Sep 12, 2023
1 parent d202d70 commit 306629e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion ControllerSimpleDemo/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ControllerSimpleDemo/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ControllerSimpleDemo/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions ControllerSimpleDemo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 33
compileSdk 33

defaultConfig {
applicationId "edu.cs4730.controllersimpledemo"
minSdkVersion 26
targetSdkVersion 33
minSdkVersion 28
targetSdk 33
versionCode 1
versionName "1.0"
}
Expand All @@ -16,10 +16,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
}
namespace 'edu.cs4730.controllersimpledemo'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.appcompat:appcompat:1.6.1'

}
3 changes: 1 addition & 2 deletions ControllerSimpleDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="edu.cs4730.controllersimpledemo">
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,26 @@
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.TextView;

import java.util.ArrayList;

import edu.cs4730.controllersimpledemo.databinding.ActivityMainBinding;

/**
* A simple demo to show how to get input from a bluetooth controller
* See https://developer.android.com/training/game-controllers/controller-input.html
* for a lot more info
*/
@SuppressLint("SetTextI18n")
public class MainActivity extends AppCompatActivity {

TextView name, last, logger;

ActivityMainBinding binding;
Boolean isJoyStick = false, isGamePad = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

name = findViewById(R.id.Name);
last = findViewById(R.id.lastBtn);
logger = findViewById(R.id.logger);

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// getGameControllerIds();

}
Expand All @@ -56,8 +51,8 @@ public boolean onGenericMotionEvent(android.view.MotionEvent motionEvent) {
xaxis = motionEvent.getAxisValue(MotionEvent.AXIS_X);
yaxis = motionEvent.getAxisValue(MotionEvent.AXIS_Y);

last.setText("JoyStick");
logger.append("JoyStick: X " + xaxis + " Y " + yaxis + "\n");
binding.lastBtn.setText("JoyStick");
binding.logger.append("JoyStick: X " + xaxis + " Y " + yaxis + "\n");
handled = true;
}

Expand All @@ -69,32 +64,31 @@ public boolean onGenericMotionEvent(android.view.MotionEvent motionEvent) {
// LEFT and RIGHT direction accordingly.
if (Float.compare(xaxis, -1.0f) == 0) {
// Dpad.LEFT;
last.setText("Dpad Left");
binding.lastBtn.setText("Dpad Left");
handled = true;
} else if (Float.compare(xaxis, 1.0f) == 0) {
// Dpad.RIGHT;
last.setText("Dpad Right");
binding.lastBtn.setText("Dpad Right");
handled = true;
}
// Check if the AXIS_HAT_Y value is -1 or 1, and set the D-pad
// UP and DOWN direction accordingly.
else if (Float.compare(yaxis, -1.0f) == 0) {
// Dpad.UP;
last.setText("Dpad Up");
binding.lastBtn.setText("Dpad Up");
handled = true;
} else if (Float.compare(yaxis, 1.0f) == 0) {
// Dpad.DOWN;
last.setText("Dpad Down");
binding.lastBtn.setText("Dpad Down");
handled = true;
} else if ((Float.compare(xaxis, 0.0f) == 0)
&& (Float.compare(yaxis, 0.0f) == 0)) {
} else if ((Float.compare(xaxis, 0.0f) == 0) && (Float.compare(yaxis, 0.0f) == 0)) {
//Dpad.center
last.setText("Dpad centered");
binding.lastBtn.setText("Dpad centered");
handled = true;
}
if (!handled) {
last.setText("Unknown");
logger.append("unhandled: X " + xaxis + " Y " + yaxis + "\n");
binding.lastBtn.setText("Unknown");
binding.logger.append("unhandled: X " + xaxis + " Y " + yaxis + "\n");
}

}
Expand All @@ -106,39 +100,35 @@ else if (Float.compare(yaxis, -1.0f) == 0) {
@Override
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
boolean handled = false;
if ((event.getSource() & InputDevice.SOURCE_GAMEPAD)
== InputDevice.SOURCE_GAMEPAD) {
if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {

if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BUTTON_X:
last.setText("X Button");
binding.lastBtn.setText("X Button");
handled = true;
break;
case KeyEvent.KEYCODE_BUTTON_A:
last.setText("A Button");
binding.lastBtn.setText("A Button");
handled = true;
break;
case KeyEvent.KEYCODE_BUTTON_Y:
last.setText("Y Button");
binding.lastBtn.setText("Y Button");
handled = true;
break;
case KeyEvent.KEYCODE_BUTTON_B:
last.setText("B Button");
binding.lastBtn.setText("B Button");
handled = true;
break;
}
if (!handled)
logger.append("code is " + event.getKeyCode() + "\n");
if (!handled) binding.logger.append("code is " + event.getKeyCode() + "\n");
} else if (event.getAction() == KeyEvent.ACTION_UP) {
//don't care, but need to handle it.
handled = true;
} else {
logger.append("unknown action " + event.getAction());
binding.logger.append("unknown action " + event.getAction());
}
return handled;
}

return handled;
}

Expand All @@ -151,10 +141,9 @@ public ArrayList<Integer> getGameControllerIds() {
int sources = dev.getSources();

// Verify that the device has gamepad buttons, control sticks, or both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
// This device is a game controller. Store its device ID.
name.setText(dev.getName());
binding.Name.setText(dev.getName());
if (!gameControllerDeviceIds.contains(deviceId)) {
gameControllerDeviceIds.add(deviceId);
}
Expand All @@ -163,8 +152,8 @@ public ArrayList<Integer> getGameControllerIds() {
isGamePad = true;
if ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)
isJoyStick = true;
logger.append("GamePad: " + isGamePad + "\n");
logger.append("JoyStick: " + isJoyStick + "\n");
binding.logger.append("GamePad: " + isGamePad + "\n");
binding.logger.append("JoyStick: " + isJoyStick + "\n");
}

}
Expand Down
2 changes: 1 addition & 1 deletion ControllerSimpleDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath 'com.android.tools.build:gradle:8.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
3 changes: 3 additions & 0 deletions ControllerSimpleDemo/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-8.0-all.zip

0 comments on commit 306629e

Please sign in to comment.