-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
- Loading branch information
There are no files selected for viewing
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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' | ||
|
||
} |
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 *; | ||
#} |
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; | ||
} | ||
|
||
} |
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> |
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> |
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> |