lint cleanup

This commit is contained in:
edgar 2016-10-29 10:59:19 -07:00
parent 0684a75b44
commit fef6431e67
9 changed files with 65 additions and 109 deletions

View file

@ -7,13 +7,13 @@ import android.view.SurfaceView;
* Created by edgarramirez on 7/17/15. * Created by edgarramirez on 7/17/15.
*/ */
public class GameLoop extends Thread { public class GameLoop extends Thread {
static final long FPS = 60; private static final long FPS = 60;
static final long ticksPS = 1000 / FPS; private static final long ticksPS = 1000 / FPS;
SurfaceView view; private SurfaceView view;
boolean running = false; private boolean running = false;
long startTime; private long startTime;
long sleepTime; private long sleepTime;
Canvas canvas; private Canvas canvas;
public GameLoop(SurfaceView view) { public GameLoop(SurfaceView view) {
this.view = view; this.view = view;

View file

@ -20,36 +20,26 @@ import java.util.Vector;
*/ */
public class GameView extends SurfaceView implements SurfaceHolder.Callback { public class GameView extends SurfaceView implements SurfaceHolder.Callback {
float width; private float width;
float height; private float height;
float centerX; private float posX;
float centerY; private float posY;
float min; private float radius;
float posX; private GameLoop gameLoop;
float posY; private Paint paint;
float radius; private Random random = new Random();
GameLoop gameLoop; private int i;
Paint paint; private int size = 20;
Random random = new Random(); private int maxRadius;
int i; private Bitmap droid;
int size = 20; private RectF rectF;
int minSpeed;
int maxSpeed;
int minRadius;
int maxRadius;
int maxX;
int maxY;
int tmpRadius;
Bitmap droid;
RectF rectF;
float rotate;
double angle; private double angle;
double power; private double power;
double angle2; private double angle2;
Vector<Star> stars; private Vector<Star> stars;
public GameView(Context context, AttributeSet attrs) { public GameView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -79,7 +69,7 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
if (stars != null && stars.size() > 0) { if (stars != null && stars.size() > 0) {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
stars.get(i).draw(canvas, paint, width, height, maxRadius); stars.get(i).draw(canvas, paint, height, maxRadius);
} }
} }
@ -90,6 +80,7 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
if (posY > height - radius) posY = height - radius; if (posY > height - radius) posY = height - radius;
if (posY < radius) posY = radius; if (posY < radius) posY = radius;
float rotate;
if (angle2 == 0) rotate = 0; if (angle2 == 0) rotate = 0;
else rotate = (float) Math.toDegrees(angle2) - 90; else rotate = (float) Math.toDegrees(angle2) - 90;
canvas.rotate(rotate, posX, posY); canvas.rotate(rotate, posX, posY);
@ -108,28 +99,28 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
min = Math.min(width, height); float min = Math.min(width, height);
centerX = width / 2; float centerX = width / 2;
centerY = height / 2; float centerY = height / 2;
posX = centerX; posX = centerX;
posY = centerY; posY = centerY;
radius = min / 12; radius = min / 12;
rectF = new RectF(posX - radius, posY - radius, posX + radius, posY + radius); rectF = new RectF(posX - radius, posY - radius, posX + radius, posY + radius);
minSpeed = (int) (min / 75); int minSpeed = (int) (min / 75);
maxSpeed = (int) (min / 25); int maxSpeed = (int) (min / 25);
minRadius = (int) (min / 250); int minRadius = (int) (min / 250);
maxRadius = (int) (min / 220); maxRadius = (int) (min / 220);
if (maxRadius == minRadius) maxRadius += minRadius; if (maxRadius == minRadius) maxRadius += minRadius;
stars = new Vector<>(); stars = new Vector<>();
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
tmpRadius = random.nextInt(maxRadius - minRadius) + minRadius; int tmpRadius = random.nextInt(maxRadius - minRadius) + minRadius;
maxX = width - tmpRadius; int maxX = width - tmpRadius;
maxY = height - tmpRadius; int maxY = height - tmpRadius;
stars.add(new Star(random.nextInt(maxX - tmpRadius + (maxRadius * 4)) + (tmpRadius - (maxRadius * 4)), stars.add(new Star(random.nextInt(maxX - tmpRadius + (maxRadius * 4)) + (tmpRadius - (maxRadius * 4)),
random.nextInt(maxY - tmpRadius + (maxRadius * 4)) + (tmpRadius - (maxRadius * 4)), random.nextInt(maxY - tmpRadius + (maxRadius * 4)) + (tmpRadius - (maxRadius * 4)),
random.nextInt(maxSpeed - minSpeed) + minSpeed, random.nextInt(maxSpeed - minSpeed) + minSpeed,

View file

@ -8,12 +8,12 @@ import android.graphics.RectF;
* Created by edgarramirez on 6/16/15. * Created by edgarramirez on 6/16/15.
*/ */
public class Star { public class Star {
public float x; private float x;
public float y; private float y;
public float speedY; private float speedY;
public float radius; private float radius;
public boolean ready = false; private boolean ready = false;
RectF rectF; private RectF rectF;
public Star(float x, float y, float speedY, float radius) { public Star(float x, float y, float speedY, float radius) {
this.x = x; this.x = x;
@ -24,9 +24,9 @@ public class Star {
rectF = new RectF(); rectF = new RectF();
} }
public void draw(Canvas canvas, Paint paint, float width, float height, float max) { public void draw(Canvas canvas, Paint paint, float height, float max) {
if (!ready) return; if (!ready) return;
update(width, height, max); update(height, max);
rectF.set(x - radius, y - radius, x + radius, y + radius); rectF.set(x - radius, y - radius, x + radius, y + radius);
@ -34,7 +34,7 @@ public class Star {
canvas.drawOval(rectF, paint); canvas.drawOval(rectF, paint);
} }
public void update(float width, float height, float max) { public void update(float height, float max) {
if (!ready) return; if (!ready) return;
y += speedY; y += speedY;

View file

@ -1,10 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.erz.joystick.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>

View file

@ -1,9 +0,0 @@
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View file

@ -1,6 +0,0 @@
<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>

View file

@ -1,6 +0,0 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View file

@ -1,4 +1,3 @@
<resources> <resources>
<string name="app_name">JoyStick</string> <string name="app_name">JoyStick</string>
<string name="action_settings">Settings</string> </resources>
</resources>

View file

@ -33,38 +33,35 @@ import android.view.View;
*/ */
public class JoyStick extends View { public class JoyStick extends View {
JoyStickListener listener; private JoyStickListener listener;
Paint paint; private Paint paint;
float width; private float centerX;
float height; private float centerY;
float centerX; private float posX;
float centerY; private float posY;
float min; private float radius;
float posX; private float buttonRadius;
float posY; private double power = -1;
float radius; private double angle = -1;
float buttonRadius; private RectF temp;
double power = -1;
double angle = -1;
RectF temp;
//Background Color //Background Color
int padColor; private int padColor;
//Stick Color //Stick Color
int buttonColor; private int buttonColor;
//Keeps joystick in last position //Keeps joystick in last position
boolean stayPut; private boolean stayPut;
//Button Size percentage of the minimum(width, height) //Button Size percentage of the minimum(width, height)
int percentage = 25; private int percentage = 25;
//Background Bitmap //Background Bitmap
Bitmap padBGBitmap = null; private Bitmap padBGBitmap = null;
//Button Bitmap //Button Bitmap
Bitmap buttonBitmap = null; private Bitmap buttonBitmap = null;
public interface JoyStickListener { public interface JoyStickListener {
void onMove(JoyStick joyStick, double angle, double power); void onMove(JoyStick joyStick, double angle, double power);
@ -118,11 +115,11 @@ public class JoyStick extends View {
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = MeasureSpec.getSize(widthMeasureSpec); float width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec); float height = MeasureSpec.getSize(heightMeasureSpec);
centerX = width / 2; centerX = width / 2;
centerY = height / 2; centerY = height / 2;
min = Math.min(width, height); float min = Math.min(width, height);
posX = centerX; posX = centerX;
posY = centerY; posY = centerY;
buttonRadius = (min / 2f * (percentage / 100f)); buttonRadius = (min / 2f * (percentage / 100f));