Skip to content

Commit

Permalink
Added bluetooth controller Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Dec 13, 2016
1 parent 4e92a40 commit 12cd224
Show file tree
Hide file tree
Showing 688 changed files with 5,765 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ControllerSimpleDemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
22 changes: 22 additions & 0 deletions ControllerSimpleDemo/.idea/compiler.xml

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

3 changes: 3 additions & 0 deletions ControllerSimpleDemo/.idea/copyright/profiles_settings.xml

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

19 changes: 19 additions & 0 deletions ControllerSimpleDemo/.idea/gradle.xml

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

46 changes: 46 additions & 0 deletions ControllerSimpleDemo/.idea/misc.xml

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

9 changes: 9 additions & 0 deletions ControllerSimpleDemo/.idea/modules.xml

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

12 changes: 12 additions & 0 deletions ControllerSimpleDemo/.idea/runConfigurations.xml

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

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

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "edu.cs4730.controllersimpledemo"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'

}
17 changes: 17 additions & 0 deletions ControllerSimpleDemo/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Android\android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
20 changes: 20 additions & 0 deletions ControllerSimpleDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.cs4730.controllersimpledemo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package edu.cs4730.controllersimpledemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

TextView name, last, logger;

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

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

getGameControllerIds();

}


@Override
public boolean onGenericMotionEvent(android.view.MotionEvent motionEvent) {
float xaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_X);
float yaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_Y);

boolean handled = false;
// Check if the AXIS_HAT_X value is -1 or 1, and set the D-pad
// LEFT and RIGHT direction accordingly.
if (Float.compare(xaxis, -1.0f) == 0) {
// Dpad.LEFT;
last.setText("Dpad Left");
handled = true;
} else if (Float.compare(xaxis, 1.0f) == 0) {
// Dpad.RIGHT;
last.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");
handled = true;
} else if (Float.compare(yaxis, 1.0f) == 0) {
// Dpad.DOWN;
last.setText("Dpad Down");
handled = true;
}
if (!handled) {
logger.append("dPad: X " + xaxis + " Y " + yaxis +"\n");
}
return handled;
}

@Override
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
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");
break;
case KeyEvent.KEYCODE_BUTTON_A:
last.setText("A Button");
break;
case KeyEvent.KEYCODE_BUTTON_Y:
last.setText("Y Button");
break;
case KeyEvent.KEYCODE_BUTTON_B:
last.setText("B Button");
break;

}

logger.append("code is " + event.getKeyCode() + "\n");
}
return true;
}

return false;
}

//From Google's page on controller-input
public ArrayList getGameControllerIds() {
ArrayList gameControllerDeviceIds = new ArrayList();
int[] deviceIds = InputDevice.getDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = InputDevice.getDevice(deviceId);
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)) {
// This device is a game controller. Store its device ID.
name.setText(dev.getName() );
if (!gameControllerDeviceIds.contains(deviceId)) {
gameControllerDeviceIds.add(deviceId);
}
}
}
return gameControllerDeviceIds;
}

}
61 changes: 61 additions & 0 deletions ControllerSimpleDemo/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="edu.cs4730.controllersimpledemo.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Controller Demo" />

<TextView
android:id="@+id/Textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:text="Controller Name:" />

<TextView
android:id="@+id/Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />

<TextView
android:id="@+id/button_push"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last button/dpad pushed" />

<TextView
android:id="@+id/lastBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="None" />

<TextView
android:id="@+id/TextView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logger:" />

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/logger"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="" />
</android.support.v4.widget.NestedScrollView>

</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions ControllerSimpleDemo/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Loading

0 comments on commit 12cd224

Please sign in to comment.