Skip to content

Commit 887dc19

Browse files
committed
Happy 2025
1 parent 85afc48 commit 887dc19

53 files changed

Lines changed: 2390 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sevtinge.hyperceiler.holiday;
2+
3+
import android.content.Context;
4+
5+
import com.sevtinge.hyperceiler.holiday.weather.PrecipType;
6+
import com.sevtinge.hyperceiler.holiday.weather.confetto.Confetto;
7+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoGenerator;
8+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoInfo;
9+
10+
import java.util.Random;
11+
12+
public class CoinGenerator implements ConfettoGenerator {
13+
private final ConfettoInfo confettoInfo;
14+
private final Context context;
15+
16+
public CoinGenerator(Context ctx) {
17+
super();
18+
this.context = ctx;
19+
this.confettoInfo = new ConfettoInfo(PrecipType.CLEAR);
20+
}
21+
22+
public Confetto generateConfetto(Random random) {
23+
return new CoinParticle(this.context, this.confettoInfo);
24+
}
25+
26+
public final ConfettoInfo getConfettoInfo() {
27+
return this.confettoInfo;
28+
}
29+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.sevtinge.hyperceiler.holiday;
2+
3+
import android.content.Context;
4+
import android.graphics.Bitmap;
5+
import android.graphics.BitmapFactory;
6+
import android.graphics.Canvas;
7+
import android.graphics.Matrix;
8+
import android.graphics.Paint;
9+
import android.view.Surface;
10+
import android.view.WindowManager;
11+
12+
import com.sevtinge.hyperceiler.R;
13+
import com.sevtinge.hyperceiler.holiday.weather.confetto.Confetto;
14+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoInfo;
15+
16+
import java.util.Random;
17+
18+
@SuppressWarnings("FieldCanBeLocal")
19+
public class CoinParticle extends Confetto {
20+
private final Context mContext;
21+
private float startX;
22+
private float startY;
23+
private int signX;
24+
private int signY;
25+
private int distance;
26+
private int maxAlpha;
27+
private final ConfettoInfo confettoInfo;
28+
private final Bitmap coin;
29+
private final float coinScale;
30+
private final int[] coins = new int[] {
31+
R.drawable.coin1, R.drawable.coin2, R.drawable.coin3, R.drawable.coin4, R.drawable.coin5, R.drawable.coin6, R.drawable.coin7, R.drawable.coin8, R.drawable.coin9, R.drawable.coin10,
32+
R.drawable.coin11, R.drawable.coin12, R.drawable.coin13, R.drawable.coin14, R.drawable.coin15, R.drawable.coin16, R.drawable.coin17, R.drawable.coin18, R.drawable.coin19, R.drawable.coin20,
33+
R.drawable.coin21, R.drawable.coin22
34+
};
35+
36+
private void randomizeStartPoint() {
37+
int width = mContext.getResources().getDisplayMetrics().widthPixels;
38+
int height = mContext.getResources().getDisplayMetrics().heightPixels;
39+
float gapX = width / 20.0f;
40+
float gapY = height / 15.0f;
41+
42+
int rotation = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
43+
boolean isLandscape = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
44+
Random rand = new Random();
45+
float selector = rand.nextFloat();
46+
if (selector < 0.25f) {
47+
startX = rand.nextFloat() * (isLandscape ? gapY : gapX);
48+
startY = rand.nextFloat() * (isLandscape ? width : height);
49+
} else if (selector >= 0.25f && selector < 0.5f) {
50+
startX = width - rand.nextFloat() * (isLandscape ? gapY : gapX);
51+
startY = rand.nextFloat() * (isLandscape ? width : height);
52+
} else if (selector >= 0.5f && selector < 0.75f) {
53+
startX = rand.nextFloat() * (isLandscape ? height : width);
54+
startY = rand.nextFloat() * (isLandscape ? gapX : gapY);
55+
} else {
56+
startX = rand.nextFloat() * (isLandscape ? height : width);
57+
startY = height - rand.nextFloat() * (isLandscape ? gapX : gapY);
58+
}
59+
signX = rand.nextInt(3) - 1;
60+
signY = rand.nextInt(3) - 1;
61+
maxAlpha = rand.nextInt(40) + 30;
62+
distance = rand.nextInt(76) + 75;
63+
}
64+
65+
CoinParticle(Context context, ConfettoInfo confettoInfo) {
66+
super();
67+
this.confettoInfo = confettoInfo;
68+
mContext = context;
69+
coinScale = 1.2f - new Random().nextFloat() * 0.2f;
70+
coin = BitmapFactory.decodeResource(context.getResources(), coins[new Random().nextInt(coins.length)]);
71+
randomizeStartPoint();
72+
}
73+
74+
public int getHeight() {
75+
return 0;
76+
}
77+
78+
public int getWidth() {
79+
return 0;
80+
}
81+
82+
public void reset() {
83+
super.reset();
84+
randomizeStartPoint();
85+
}
86+
87+
protected void configurePaint(Paint paint) {
88+
super.configurePaint(paint);
89+
paint.setColor(-1);
90+
paint.setAntiAlias(true);
91+
}
92+
93+
protected void drawInternal(Canvas canvas, Matrix matrix, Paint paint, float x, float y, float rotation, float percentageAnimated) {
94+
matrix.postScale(coinScale, coinScale);
95+
matrix.postRotate(rotation, coin.getWidth() / 2f, coin.getHeight() / 2f);
96+
matrix.postTranslate(startX + signX * distance * percentageAnimated, startY + signY * distance * percentageAnimated);
97+
if (percentageAnimated < 0.1f)
98+
paint.setAlpha(Math.round(maxAlpha * percentageAnimated / 0.1f));
99+
else if (percentageAnimated > 0.9f)
100+
paint.setAlpha(Math.round(maxAlpha * (1.0f - percentageAnimated) / 0.1f));
101+
else
102+
paint.setAlpha(maxAlpha);
103+
canvas.drawBitmap(coin, matrix, paint);
104+
}
105+
106+
public final ConfettoInfo getConfettoInfo() {
107+
return this.confettoInfo;
108+
}
109+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sevtinge.hyperceiler.holiday;
2+
3+
import android.content.Context;
4+
5+
import com.sevtinge.hyperceiler.holiday.weather.PrecipType;
6+
import com.sevtinge.hyperceiler.holiday.weather.confetto.Confetto;
7+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoGenerator;
8+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoInfo;
9+
10+
import java.util.Random;
11+
12+
public class FlowerGenerator implements ConfettoGenerator {
13+
private final ConfettoInfo confettoInfo;
14+
private final Context context;
15+
16+
public FlowerGenerator(Context ctx) {
17+
super();
18+
this.context = ctx;
19+
this.confettoInfo = new ConfettoInfo(PrecipType.SNOW);
20+
}
21+
22+
public Confetto generateConfetto(Random random) {
23+
return new FlowerParticle(this.context, this.confettoInfo);
24+
}
25+
26+
public final ConfettoInfo getConfettoInfo() {
27+
return this.confettoInfo;
28+
}
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.sevtinge.hyperceiler.holiday;
2+
3+
import android.content.Context;
4+
import android.graphics.Bitmap;
5+
import android.graphics.BitmapFactory;
6+
import android.graphics.Canvas;
7+
import android.graphics.Matrix;
8+
import android.graphics.Paint;
9+
import android.view.Surface;
10+
import android.view.WindowManager;
11+
12+
import com.sevtinge.hyperceiler.R;
13+
import com.sevtinge.hyperceiler.holiday.weather.confetto.Confetto;
14+
import com.sevtinge.hyperceiler.holiday.weather.confetto.ConfettoInfo;
15+
16+
import java.util.Random;
17+
18+
public class FlowerParticle extends Confetto {
19+
private final ConfettoInfo confettoInfo;
20+
private final Bitmap petal;
21+
private float petalScale;
22+
private final int[] petals = new int[] { R.drawable.confetti1, R.drawable.confetti1, R.drawable.confetti2, R.drawable.confetti2, R.drawable.confetti3, R.drawable.confetti3, R.drawable.petal };
23+
24+
FlowerParticle(Context context, ConfettoInfo confettoInfo) {
25+
super();
26+
this.confettoInfo = confettoInfo;
27+
petalScale = 0.6f - (float)Math.random() * 0.15f;
28+
petal = BitmapFactory.decodeResource(context.getResources(), petals[new Random().nextInt(petals.length)]);
29+
30+
int rotation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
31+
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) petalScale *= 1.5;
32+
}
33+
34+
public int getHeight() {
35+
return 0;
36+
}
37+
38+
public int getWidth() {
39+
return 0;
40+
}
41+
42+
public void reset() {
43+
super.reset();
44+
}
45+
46+
public void configurePaint(Paint paint) {
47+
super.configurePaint(paint);
48+
paint.setColor(-1);
49+
paint.setAntiAlias(true);
50+
}
51+
52+
protected void drawInternal(Canvas canvas, Matrix matrix, Paint paint, float x, float y, float rotation, float percentageAnimated) {
53+
switch (confettoInfo.getPrecipType()) {
54+
case CLEAR:
55+
break;
56+
case SNOW:
57+
matrix.postScale(petalScale, petalScale);
58+
matrix.postRotate(rotation, petal.getWidth() / 2f, petal.getHeight() / 2f);
59+
matrix.postTranslate(x, y);
60+
canvas.drawBitmap(petal, matrix, paint);
61+
break;
62+
}
63+
}
64+
65+
public final ConfettoInfo getConfettoInfo() {
66+
return this.confettoInfo;
67+
}
68+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.sevtinge.hyperceiler.holiday;
2+
3+
import android.content.Context;
4+
import android.hardware.Sensor;
5+
import android.hardware.SensorEvent;
6+
import android.hardware.SensorEventListener;
7+
import android.hardware.SensorManager;
8+
import android.view.Surface;
9+
10+
public final class GravitySensor implements SensorEventListener {
11+
private final SensorManager sensorManager;
12+
private float[] magneticValues;
13+
private float[] accelerometerValues;
14+
private int orientation;
15+
private int speed;
16+
private boolean started;
17+
private final Context context;
18+
private final WeatherView weatherView;
19+
20+
public GravitySensor(Context context, WeatherView weatherView) {
21+
super();
22+
this.context = context;
23+
this.weatherView = weatherView;
24+
this.sensorManager = (SensorManager)this.context.getSystemService(Context.SENSOR_SERVICE);
25+
}
26+
27+
public final boolean getStarted() {
28+
return this.started;
29+
}
30+
31+
public void setOrientation(int orient) {
32+
this.orientation = orient;
33+
}
34+
35+
public void setSpeed(int spd) {
36+
this.speed = spd;
37+
}
38+
39+
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
40+
41+
public void onSensorChanged(SensorEvent event) {
42+
if (event == null || event.sensor == null) return;
43+
switch (event.sensor.getType()) {
44+
case 1: this.accelerometerValues = event.values; break;
45+
case 2: this.magneticValues = event.values; break;
46+
}
47+
if (this.magneticValues == null || this.accelerometerValues == null) return;
48+
49+
float[] rotationMatrix = new float[9];
50+
SensorManager.getRotationMatrix(rotationMatrix, null, this.accelerometerValues, this.magneticValues);
51+
float[] remappedRotationMatrix = new float[9];
52+
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRotationMatrix);
53+
float[] orientationAngles = new float[3];
54+
SensorManager.getOrientation(remappedRotationMatrix, orientationAngles);
55+
//double pitch = Math.toDegrees((double)orientationAngles[1]);
56+
double roll = Math.toDegrees(orientationAngles[2]) + Math.random() * 20 - 10;
57+
if (this.orientation == Surface.ROTATION_90) roll += 90;
58+
else if (this.orientation == Surface.ROTATION_270) roll -= 90;
59+
else if (this.orientation == Surface.ROTATION_180) roll += roll > 0 ? 180 : -180;
60+
if (roll > 90) roll -= 180; else if (roll < -90) roll += 180;
61+
this.weatherView.setAngle((int)roll);
62+
this.weatherView.setSpeed(this.speed + (int)Math.round(Math.random() * 20 - 10));
63+
}
64+
65+
private void registerListener() {
66+
this.sensorManager.registerListener(this, this.sensorManager.getDefaultSensor(1), 2);
67+
this.sensorManager.registerListener(this, this.sensorManager.getDefaultSensor(2), 2);
68+
}
69+
70+
private void unregisterListener() {
71+
this.sensorManager.unregisterListener(this);
72+
}
73+
74+
public final void start() {
75+
this.started = true;
76+
this.registerListener();
77+
}
78+
79+
public final void stop() {
80+
this.started = false;
81+
this.unregisterListener();
82+
}
83+
84+
public final void onResume() {
85+
if (this.started) {
86+
this.registerListener();
87+
}
88+
}
89+
90+
public final void onPause() {
91+
this.unregisterListener();
92+
}
93+
94+
public final Context getContext() {
95+
return this.context;
96+
}
97+
98+
public final WeatherView getWeatherView() {
99+
return this.weatherView;
100+
}
101+
102+
}

0 commit comments

Comments
 (0)