Skip to content

Commit

Permalink
refactor: Sonar handling till NDP
Browse files Browse the repository at this point in the history
  • Loading branch information
itachi1706 committed Jun 13, 2024
1 parent 7f7e1d3 commit 20a5d6f
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {

final float[] hsv = {0, 0, 0};

private Random random = new Random();
private final Random random = new Random();

@SuppressWarnings("ResourceType")
private void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class Color {
* @hide Pending API council
*/
@ColorInt
public static int HSBtoColor(@Size(3) float[] hsb) {
return HSBtoColor(hsb[0], hsb[1], hsb[2]);
public static int hsbToColor(@Size(3) float[] hsb) {
return hsbToColor(hsb[0], hsb[1], hsb[2]);
}

/**
Expand All @@ -55,7 +55,7 @@ public static int HSBtoColor(@Size(3) float[] hsb) {
* @hide Pending API council
*/
@ColorInt
public static int HSBtoColor(float h, float s, float b) {
public static int hsbToColor(float h, float s, float b) {
h = MathUtils.constrain(h, 0.0f, 1.0f);
s = MathUtils.constrain(s, 0.0f, 1.0f);
b = MathUtils.constrain(b, 0.0f, 1.0f);
Expand Down
387 changes: 198 additions & 189 deletions app/src/main/java/com/itachi1706/droideggs/eggs/marshmallow/MLand.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.itachi1706.droideggs.eggs.marshmallow;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.itachi1706.droideggs.R;

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public void updateSplashPlayers() {
minus.setVisibility(View.INVISIBLE);
plus.setVisibility(View.VISIBLE);
plus.requestFocus();
} else if (N == mLand.MAX_PLAYERS) {
} else if (N == MLand.MAX_PLAYERS) {
minus.setVisibility(View.VISIBLE);
plus.setVisibility(View.INVISIBLE);
minus.requestFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
* Created by Kenneth on 7/10/2015.
* for DroidEggs in package com.itachi1706.droideggs.MarshmallowEgg
*/

/**
* A class that contains utility methods related to numbers.
*
* @hide Pending API council approval
*/
public final class MathUtils {

private static final Random sRandom = new Random();
Expand All @@ -39,13 +33,13 @@ public static float abs(float v) {
return v > 0 ? v : -v;
}
public static int constrain(int amount, int low, int high) {
return amount < low ? low : (amount > high ? high : amount);
return amount < low ? low : (Math.min(amount, high));
}
public static long constrain(long amount, long low, long high) {
return amount < low ? low : (amount > high ? high : amount);
return amount < low ? low : (Math.min(amount, high));
}
public static float constrain(float amount, float low, float high) {
return amount < low ? low : (amount > high ? high : amount);
return amount < low ? low : (Math.min(amount, high));
}
public static float log(float a) {
return (float) Math.log(a);
Expand All @@ -57,28 +51,28 @@ public static float pow(float a, float b) {
return (float) Math.pow(a, b);
}
public static float max(float a, float b) {
return a > b ? a : b;
return Math.max(a, b);
}
public static float max(int a, int b) {
return a > b ? a : b;
return Math.max(a, b);
}
public static float max(float a, float b, float c) {
return a > b ? (a > c ? a : c) : (b > c ? b : c);
return a > b ? (Math.max(a, c)) : (Math.max(b, c));
}
public static float max(int a, int b, int c) {
return a > b ? (a > c ? a : c) : (b > c ? b : c);
return a > b ? (Math.max(a, c)) : (Math.max(b, c));
}
public static float min(float a, float b) {
return a < b ? a : b;
return Math.min(a, b);
}
public static float min(int a, int b) {
return a < b ? a : b;
return Math.min(a, b);
}
public static float min(float a, float b, float c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c);
return a < b ? (Math.min(a, c)) : (Math.min(b, c));
}
public static float min(int a, int b, int c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c);
return a < b ? (Math.min(a, c)) : (Math.min(b, c));
}
public static float dist(float x1, float y1, float x2, float y2) {
final float x = (x2 - x1);
Expand Down Expand Up @@ -137,11 +131,11 @@ public static float map(float minStart, float minStop, float maxStart, float max
return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
}
public static int random(int howbig) {
return (int) (sRandom.nextFloat() * howbig);
return sRandom.nextInt() * howbig;
}
public static int random(int howsmall, int howbig) {
if (howsmall >= howbig) return howsmall;
return (int) (sRandom.nextFloat() * (howbig - howsmall) + howsmall);
return sRandom.nextInt() * (howbig - howsmall) + howsmall;
}
public static float random(float howbig) {
return sRandom.nextFloat() * howbig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
Expand All @@ -42,6 +41,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import com.itachi1706.droideggs.R;

Expand Down Expand Up @@ -80,15 +80,19 @@ public void getOutline(View view, Outline outline) {
});
final float hue = (float) Math.random();
final Paint bgPaint = new Paint();
bgPaint.setColor(Color.HSBtoColor(hue, 0.4f, 1f));
bgPaint.setColor(Color.hsbToColor(hue, 0.4f, 1f));
final Paint fgPaint = new Paint();
fgPaint.setColor(Color.HSBtoColor(hue, 0.5f, 1f));
final Drawable M = getDrawable(R.drawable.marshmallow_platlogo_m);
fgPaint.setColor(Color.hsbToColor(hue, 0.5f, 1f));
final Drawable m = getDrawable(R.drawable.marshmallow_platlogo_m);
final Drawable platlogo = new Drawable() {
@Override
public void setAlpha(int alpha) { }
public void setAlpha(int alpha) {
// Unused Function
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) { }
public void setColorFilter(@Nullable ColorFilter colorFilter) {
// Unused Function
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
Expand All @@ -98,8 +102,8 @@ public void draw(Canvas c) {
final float r = c.getWidth() / 2f;
c.drawCircle(r, r, r, bgPaint);
c.drawArc(0, 0, 2 * r, 2 * r, 135, 180, false, fgPaint);
M.setBounds(0, 0, c.getWidth(), c.getHeight());
M.draw(c);
m.setBounds(0, 0, c.getWidth(), c.getHeight());
m.draw(c);
}
};
im.setBackground(new RippleDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
Expand All @@ -38,6 +37,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import com.itachi1706.droideggs.R;
import com.itachi1706.droideggs.eggs.marshmallow.Color;
Expand Down Expand Up @@ -77,15 +77,19 @@ public void getOutline(View view, Outline outline) {
});
final float hue = (float) Math.random();
final Paint bgPaint = new Paint();
bgPaint.setColor(Color.HSBtoColor(hue, 0.4f, 1f));
bgPaint.setColor(Color.hsbToColor(hue, 0.4f, 1f));
final Paint fgPaint = new Paint();
fgPaint.setColor(Color.HSBtoColor(hue, 0.5f, 1f));
final Drawable M = getDrawable(R.drawable.marshmallow_platlogo_m);
fgPaint.setColor(Color.hsbToColor(hue, 0.5f, 1f));
final Drawable m = getDrawable(R.drawable.marshmallow_platlogo_m);
final Drawable platlogo = new Drawable() {
@Override
public void setAlpha(int alpha) { }
public void setAlpha(int alpha) {
// Unused Function
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) { }
public void setColorFilter(@Nullable ColorFilter colorFilter) {
// Unused Function
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
Expand All @@ -95,8 +99,8 @@ public void draw(Canvas c) {
final float r = c.getWidth() / 2f;
c.drawCircle(r, r, r, bgPaint);
c.drawArc(0, 0, 2 * r, 2 * r, 135, 180, false, fgPaint);
M.setBounds(0, 0, c.getWidth(), c.getHeight());
M.draw(c);
m.setBounds(0, 0, c.getWidth(), c.getHeight());
m.draw(c);
}
};
im.setBackground(new RippleDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
Expand All @@ -31,6 +30,7 @@
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import com.itachi1706.droideggs.R;

Expand All @@ -53,37 +53,28 @@ protected void onCreate(Bundle savedInstanceState) {
mLayout = new FrameLayout(this);
setContentView(mLayout);
}

@Override
public void onAttachedToWindow() {
final DisplayMetrics dm = getResources().getDisplayMetrics();
final float dp = dm.density;
final int size = (int)
(Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600*dp) - 100*dp);
(Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600 * dp) - 100 * dp);
final ImageView im = new ImageView(this);
final int pad = (int)(40*dp);
final int pad = (int) (40 * dp);
im.setPadding(pad, pad, pad, pad);
im.setTranslationZ(20);
im.setScaleX(0.5f);
im.setScaleY(0.5f);
im.setAlpha(0f);
im.setBackground(new RippleDrawable(
ColorStateList.valueOf(0xFFFFFFFF),
getDrawable(R.drawable.ndp_platlogo),
null));
// im.setOutlineProvider(new ViewOutlineProvider() {
// @Override
// public void getOutline(View view, Outline outline) {
// outline.setOval(0, 0, view.getWidth(), view.getHeight());
// }
// });
im.setBackground(new RippleDrawable(ColorStateList.valueOf(0xFFFFFFFF), getDrawable(R.drawable.ndp_platlogo), null));
im.setClickable(true);
im.setOnClickListener(v -> {
im.setOnLongClickListener(v1 -> {
if (mTapCount < 5) return false;

if (REVEAL_THE_NAME) {
final Drawable overlay = getDrawable(
R.drawable.ndp_platlogo_n);
final Drawable overlay = getDrawable(R.drawable.ndp_platlogo_n);
overlay.setBounds(0, 0, v1.getMeasuredWidth(), v1.getMeasuredHeight());
im.getOverlay().clear();
im.getOverlay().add(overlay);
Expand Down

0 comments on commit 20a5d6f

Please sign in to comment.