commit 66126df5433c29ab410f3dfad3d124bef1a6d182 Author: edgar Date: Fri Oct 30 21:13:41 2015 -0700 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86ae1fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures + +#Android generated +bin +gen + +#Eclipse +.project +.classpath +.settings + +#IntelliJ IDEA +.idea +*.iml +classes + +#Command line +build.xml +proguard-project.txt + +#Mac specific +.DS_Store + +#User specific +local.properties + +#gradle +build +.gradle +gradle +gradlew +gradlew.bat +signing.properties \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d0bfffa --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.erz.joystick" + minSdkVersion 11 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.0' + compile 'com.android.support:design:23.1.0' + compile project(':joysticklibrary') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..3de46e3 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/edgarramirez/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 *; +#} diff --git a/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java b/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java new file mode 100644 index 0000000..521f396 --- /dev/null +++ b/app/src/androidTest/java/com/erz/joystick/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.erz.joystick; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ad5a924 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/erz/joystick/GameLoop.java b/app/src/main/java/com/erz/joystick/GameLoop.java new file mode 100644 index 0000000..00396ec --- /dev/null +++ b/app/src/main/java/com/erz/joystick/GameLoop.java @@ -0,0 +1,49 @@ +package com.erz.joystick; + +import android.graphics.Canvas; +import android.view.SurfaceView; + +/** + * Created by edgarramirez on 7/17/15. + */ +public class GameLoop extends Thread { + static final long FPS = 60; + static final long ticksPS = 1000 / FPS; + SurfaceView view; + boolean running = false; + long startTime; + long sleepTime; + Canvas canvas; + + public GameLoop(SurfaceView view) { + this.view = view; + } + + public void setRunning(boolean run) { + running = run; + } + + @Override + public void run() { + while (running) { + startTime = System.currentTimeMillis(); + try { + canvas = view.getHolder().lockCanvas(); + synchronized (view.getHolder()) { + view.draw(canvas); + } + } finally { + if (canvas != null) { + view.getHolder().unlockCanvasAndPost(canvas); + } + } + sleepTime = ticksPS - (System.currentTimeMillis() - startTime); + try { + if (sleepTime > 0) + sleep(sleepTime); + else + sleep(10); + } catch (Exception ignore) {} + } + } +} diff --git a/app/src/main/java/com/erz/joystick/GameView.java b/app/src/main/java/com/erz/joystick/GameView.java new file mode 100644 index 0000000..6574c88 --- /dev/null +++ b/app/src/main/java/com/erz/joystick/GameView.java @@ -0,0 +1,154 @@ +package com.erz.joystick; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; +import android.support.annotation.NonNull; +import android.util.AttributeSet; +import android.view.SurfaceHolder; +import android.view.SurfaceView; + +import java.util.Random; +import java.util.Vector; + +/** + * Created by edgarramirez on 6/15/15. + */ +public class GameView extends SurfaceView implements SurfaceHolder.Callback { + + float width; + float height; + float centerX; + float centerY; + float min; + float posX; + float posY; + float radius; + GameLoop gameLoop; + Paint paint; + Random random = new Random(); + int i; + int size = 20; + int minSpeed; + int maxSpeed; + int minRadius; + int maxRadius; + int maxX; + int maxY; + int tmpRadius; + Bitmap droid; + RectF rectF; + float rotate; + + double radians; + double power; + + double radians2; + + Vector stars; + + public GameView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public GameView(Context context) { + super(context); + init(); + } + + private void init() { + getHolder().addCallback(this); + paint = new Paint(); + paint.setAntiAlias(true); + paint.setStyle(Paint.Style.FILL); + paint.setColor(Color.WHITE); + droid = BitmapFactory.decodeResource(getResources(), R.drawable.droid); + rectF = new RectF(); + } + + @Override + public void draw(@NonNull Canvas canvas) { + if (canvas == null) return; + super.draw(canvas); + canvas.drawColor(Color.BLACK); + + if (stars != null && stars.size() > 0) { + for (i=0; i width - radius) posX = width - radius; + if (posX < radius) posX = radius; + if (posY > height - radius) posY = height - radius; + if (posY < radius) posY = radius; + + if (radians2 == 0) rotate = 0; + else rotate = (float) Math.toDegrees(radians2) - 90; + canvas.rotate(rotate, posX, posY); + rectF.set(posX - radius, posY - radius, posX + radius, posY + radius); + canvas.drawBitmap(droid, null, rectF, paint); + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + gameLoop = new GameLoop(this); + gameLoop.setRunning(true); + gameLoop.start(); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + this.width = width; + this.height = height; + min = Math.min(width, height); + + centerX = width/2; + centerY = height/2; + posX = centerX; + posY = centerY; + radius = min/12; + rectF = new RectF(posX - radius, posY - radius, posX + radius, posY + radius); + + minSpeed = (int) (min/75); + maxSpeed = (int) (min/25); + + minRadius = (int) (min/250); + maxRadius = (int) (min/220); + + if (maxRadius == minRadius) maxRadius += minRadius; + + stars = new Vector<>(); + for (i=0; i (height + (max * 4))) { + y = - (max * 4) - radius; + } + } +} diff --git a/app/src/main/res/drawable/droid.png b/app/src/main/res/drawable/droid.png new file mode 100644 index 0000000..40bf934 Binary files /dev/null and b/app/src/main/res/drawable/droid.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..a9e9a1c --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..4066b45 --- /dev/null +++ b/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..251fb9f --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,9 @@ +> + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..812cb7b --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..b0b94ce --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + JoyStick + Settings + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..0a1cd50 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,24 @@ + + + + + + + +