Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .idea/misc.xml

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

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

1 change: 0 additions & 1 deletion Bugstick.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
Expand Down
11 changes: 5 additions & 6 deletions bugstick/bugstick.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand Down Expand Up @@ -89,6 +86,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
</component>
</module>
4 changes: 2 additions & 2 deletions bugstick/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'bintray-release'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 15
Expand All @@ -21,7 +21,7 @@ android {

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

buildscript {
Expand Down
78 changes: 78 additions & 0 deletions bugstick/src/main/java/com/jmedeisis/bugstick/Joystick.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public enum MotionConstraint {
VERTICAL
}

public enum BaseShape {
OVAL,
RECT
}

private MotionConstraint motionConstraint = MotionConstraint.NONE;
private BaseShape baseShape = BaseShape.OVAL;

private JoystickListener listener;

Expand Down Expand Up @@ -92,6 +98,10 @@ private void init(Context context, AttributeSet attrs) {
}
motionConstraint = MotionConstraint.values()[a.getInt(R.styleable.Joystick_motion_constraint,
motionConstraint.ordinal())];

baseShape = BaseShape.values()[a.getInt(R.styleable.Joystick_base_shape,
baseShape.ordinal())];

a.recycle();
}
}
Expand Down Expand Up @@ -377,7 +387,75 @@ private void onDragStop() {
/**
* Where most of the magic happens. What, basic trigonometry isn't magic?!
*/
// private void onDrag(float dx, float dy) {
// float x = downX + dx - centerX;
// float y = downY + dy - centerY;
//
// switch (motionConstraint) {
// case HORIZONTAL:
// y = 0;
// break;
// case VERTICAL:
// x = 0;
// break;
// }
//
// float offset = (float) Math.sqrt(x * x + y * y);
// if (x * x + y * y > radius * radius) {
// x = radius * x / offset;
// y = radius * y / offset;
// offset = radius;
// }
//
// final double radians = Math.atan2(-y, x);
// final float degrees = (float) (180 * radians / Math.PI);
//
// if (null != listener) listener.onDrag(degrees, 0 == radius ? 0 : offset / radius);
//
// draggedChild.setTranslationX(x);
// draggedChild.setTranslationY(y);
// }

private void onDrag(float dx, float dy) {
if (baseShape == BaseShape.RECT) {
onDragRect(dx, dy);
} else {
onDragOval(dx, dy);
}
}

private void onDragRect(float dx, float dy) {
float x = downX + dx - centerX;
float y = downY + dy - centerY;

switch (motionConstraint) {
case HORIZONTAL:
y = 0;
break;
case VERTICAL:
x = 0;
break;
}

if( x > radius ) x = radius;
if( x < -radius ) x = -radius;

if( y > radius ) y = radius;
if( y < -radius ) y = -radius;

float xOffset = x / radius;
float yOffset = y / radius;

if (null != listener) listener.onDrag(xOffset, -yOffset);

draggedChild.setTranslationX(x);
draggedChild.setTranslationY(y);
}

/**
* Where most of the magic happens. What, basic trigonometry isn't magic?!
*/
private void onDragOval(float dx, float dy) {
float x = downX + dx - centerX;
float y = downY + dy - centerY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ public interface JoystickListener {
void onDown();

/**
* If baseShape = oval
*
* @param degrees -180 -> 180.
* @param offset normalized, 0 -> 1.
*
* If baseShape = rect
*
* @param degrees = xOffset, -1 -> 1.
* @param offset = yOffset, -1 -> 1.
*/
void onDrag(float degrees, float offset);

Expand Down
4 changes: 4 additions & 0 deletions bugstick/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<enum name="Horizontal" value="1" />
<enum name="Vertical" value="2" />
</attr>
<attr name="base_shape" format="enum">
<enum name="oval" value="0" />
<enum name="rect" value="1" />
</attr>
</declare-styleable>

</resources>
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.example.bugstick"
Expand All @@ -21,6 +21,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':bugstick')
}
15 changes: 5 additions & 10 deletions sample/sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand Down Expand Up @@ -71,8 +68,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
Expand All @@ -90,9 +85,9 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="module" module-name="bugstick" exported="" />
</component>
</module>
3 changes: 2 additions & 1 deletion sample/src/main/java/com/example/bugstick/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// setContentView(R.layout.activity_main);
setContentView(R.layout.activity_rect);

final TextView angleView = (TextView) findViewById(R.id.tv_angle);
final TextView offsetView = (TextView) findViewById(R.id.tv_offset);
Expand Down
9 changes: 9 additions & 0 deletions sample/src/main/res/drawable/bg_base_rect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/primary_material_dark" />

<size android:height="10dp" />

<corners android:radius="@dimen/half_stick_size" />
</shape>
Loading