From 80e0dca5f8ab17c3e9970d5d2b03569c1a4b23c0 Mon Sep 17 00:00:00 2001 From: edgar Date: Mon, 2 Nov 2015 17:47:25 -0800 Subject: [PATCH] small changes, removed the alpha variable for bitmaps, alpha can just be added to the bitmaps themselves --- .../java/com/erz/joystick/MainActivity.java | 1 - .../com/erz/joysticklibrary/JoyStick.java | 24 +------------------ joysticklibrary/src/main/res/values/attrs.xml | 2 -- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/app/src/main/java/com/erz/joystick/MainActivity.java b/app/src/main/java/com/erz/joystick/MainActivity.java index bea7f04..609cb1e 100644 --- a/app/src/main/java/com/erz/joystick/MainActivity.java +++ b/app/src/main/java/com/erz/joystick/MainActivity.java @@ -22,7 +22,6 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick ((JoyStick)findViewById(R.id.joy2)).enableStayPut(true); ((JoyStick)findViewById(R.id.joy2)).setButtonSize(50); ((JoyStick)findViewById(R.id.joy2)).setButtonDrawable(R.drawable.droid); - ((JoyStick)findViewById(R.id.joy2)).setButtonAlpha(100); } @Override diff --git a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java index e0299d5..710fe98 100644 --- a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java +++ b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java @@ -66,12 +66,6 @@ public class JoyStick extends View { //Button Bitmap Bitmap buttonBitmap = null; - //Background Alpha - int padAlpha = 255; - - //Button Alpha - int buttonAlpha = 255; - public interface JoyStickListener { void onMove(JoyStick joyStick, double angle, double power); } @@ -116,8 +110,6 @@ public class JoyStick extends View { buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId); } - padAlpha = typedArray.getInt(R.styleable.JoyStick_backgroundAlpha, 255); - buttonAlpha = typedArray.getInt(R.styleable.JoyStick_buttonAlpha, 255); typedArray.recycle(); } } @@ -134,7 +126,7 @@ public class JoyStick extends View { posX = centerX; posY = centerY; buttonRadius = (min / 2f * (percentage/100f)); - radius = (min / 2 * 0.75f); + radius = (min / 2f * ((100f-percentage)/100f)); } @Override @@ -145,7 +137,6 @@ public class JoyStick extends View { paint.setColor(padColor); canvas.drawCircle(centerX, centerY, radius, paint); } else { - paint.setAlpha(padAlpha); temp.set(posX - radius, posY - radius, posX + radius, posY + radius); canvas.drawBitmap(padBGBitmap, null, temp, paint); } @@ -153,7 +144,6 @@ public class JoyStick extends View { paint.setColor(buttonColor); canvas.drawCircle(posX, posY, buttonRadius, paint); } else { - paint.setAlpha(buttonAlpha); temp.set(posX - buttonRadius, posY - buttonRadius, posX + buttonRadius, posY + buttonRadius); canvas.drawBitmap(buttonBitmap, null, temp, paint); } @@ -242,16 +232,4 @@ public class JoyStick extends View { public void setButtonDrawable(int resId) { this.buttonBitmap = BitmapFactory.decodeResource(getResources(), resId); } - - public void setBackgroundAlpha(int alpha) { - padAlpha = alpha; - if (padAlpha > 255) padAlpha = 255; - if (padAlpha < 0) padAlpha = 0; - } - - public void setButtonAlpha(int alpha) { - buttonAlpha = alpha; - if (buttonAlpha > 255) buttonAlpha = 255; - if (buttonAlpha < 0) buttonAlpha = 0; - } } \ No newline at end of file diff --git a/joysticklibrary/src/main/res/values/attrs.xml b/joysticklibrary/src/main/res/values/attrs.xml index f383ba5..e16d604 100644 --- a/joysticklibrary/src/main/res/values/attrs.xml +++ b/joysticklibrary/src/main/res/values/attrs.xml @@ -7,7 +7,5 @@ - - \ No newline at end of file