diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/FlowerParticle.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/FlowerParticle.java index 7fc6b6ef5..c02d62610 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/FlowerParticle.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/FlowerParticle.java @@ -7,7 +7,6 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.view.Surface; -import android.view.WindowManager; import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.ui.app.holiday.weather.confetto.Confetto; @@ -19,24 +18,28 @@ public class FlowerParticle extends Confetto { private final ConfettoInfo confettoInfo; private final Bitmap petal; private float petalScale; - 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 }; FlowerParticle(Context context, ConfettoInfo confettoInfo) { super(); this.confettoInfo = confettoInfo; - petalScale = 0.6f - (float)Math.random() * 0.15f; - petal = BitmapFactory.decodeResource(context.getResources(), petals[new Random().nextInt(petals.length)]); + this.petalScale = 0.6f - (float)Math.random() * 0.15f; + int[] petals = {R.drawable.confetti1, R.drawable.confetti1, R.drawable.confetti2, R.drawable.confetti2, R.drawable.confetti3, R.drawable.confetti3, R.drawable.petal}; + this.petal = BitmapFactory.decodeResource(context.getResources(), petals[new Random().nextInt(petals.length)]); - int rotation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); - if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) petalScale *= 1.5; + int rotation = context.getDisplay().getRotation(); + if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { + this.petalScale *= 1.5f; + } } + @Override public int getHeight() { - return 0; + return petal.getHeight(); } + @Override public int getWidth() { - return 0; + return petal.getWidth(); } public void reset() { @@ -49,6 +52,7 @@ public void configurePaint(Paint paint) { paint.setAntiAlias(true); } + @Override protected void drawInternal(Canvas canvas, Matrix matrix, Paint paint, float x, float y, float rotation, float percentageAnimated) { switch (confettoInfo.getPrecipType()) { case CLEAR: diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/GravitySensor.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/GravitySensor.java index 76b23213d..965cb916c 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/GravitySensor.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/GravitySensor.java @@ -47,19 +47,31 @@ public void onSensorChanged(SensorEvent event) { if (this.magneticValues == null || this.accelerometerValues == null) return; float[] rotationMatrix = new float[9]; - SensorManager.getRotationMatrix(rotationMatrix, null, this.accelerometerValues, this.magneticValues); float[] remappedRotationMatrix = new float[9]; - SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRotationMatrix); float[] orientationAngles = new float[3]; + + SensorManager.getRotationMatrix(rotationMatrix, null, this.accelerometerValues, this.magneticValues); + SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRotationMatrix); SensorManager.getOrientation(remappedRotationMatrix, orientationAngles); - //double pitch = Math.toDegrees((double)orientationAngles[1]); + double roll = Math.toDegrees(orientationAngles[2]) + Math.random() * 20 - 10; - if (this.orientation == Surface.ROTATION_90) roll += 90; - else if (this.orientation == Surface.ROTATION_270) roll -= 90; - else if (this.orientation == Surface.ROTATION_180) roll += roll > 0 ? 180 : -180; - if (roll > 90) roll -= 180; else if (roll < -90) roll += 180; - this.weatherView.setAngle((int)roll); - this.weatherView.setSpeed(this.speed + (int)Math.round(Math.random() * 20 - 10)); + switch (this.orientation) { + case Surface.ROTATION_90: + roll += 90; + break; + case Surface.ROTATION_270: + roll -= 90; + break; + case Surface.ROTATION_180: + roll += roll > 0 ? 180 : -180; + break; + } + + if (roll > 90) roll -= 180; + else if (roll < -90) roll += 180; + + this.weatherView.setAngle((int) roll); + this.weatherView.setSpeed(this.speed + (int) Math.round(Math.random() * 20 - 10)); } private void registerListener() { @@ -71,31 +83,31 @@ private void unregisterListener() { this.sensorManager.unregisterListener(this); } - public final void start() { + public void start() { this.started = true; this.registerListener(); } - public final void stop() { + public void stop() { this.started = false; this.unregisterListener(); } - public final void onResume() { + public void onResume() { if (this.started) { this.registerListener(); } } - public final void onPause() { + public void onPause() { this.unregisterListener(); } - public final Context getContext() { + public Context getContext() { return this.context; } - public final WeatherView getWeatherView() { + public WeatherView getWeatherView() { return this.weatherView; } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/HolidayHelper.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/HolidayHelper.java index c350752fd..2bd273fc2 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/HolidayHelper.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/holiday/HolidayHelper.java @@ -17,6 +17,7 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Field; +import java.util.Objects; import fan.navigator.app.NavigatorActivity; @@ -36,8 +37,8 @@ public class HolidayHelper { public HolidayHelper(Activity activity) { mContext = activity; - mRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - mContentView = activity.findViewById(android.R.id.content); + mRotation = Objects.requireNonNull(mContext.getDisplay()).getRotation(); + mContentView = activity.findViewById(android.R.id.content); mHolidayView = LayoutInflater.from(mContext).inflate(R.layout.layout_holiday, mContentView, false); initialize(activity instanceof NavigatorActivity); } @@ -68,68 +69,58 @@ private void initView() { private void initHoliday() { mWeatherView.setLayerType(View.LAYER_TYPE_HARDWARE, null); - weatherView = new WeakReference<>(mWeatherView); - GravitySensor listener = null; - if (opt == 1) { - mWeatherView.setPrecipType(PrecipType.SNOW); - mWeatherView.setSpeed(50); - mWeatherView.setEmissionRate(mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? 8 : 4); - mWeatherView.setFadeOutPercent(0.75f); - mWeatherView.setAngle(0); - RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)mWeatherView.getLayoutParams(); - lp.height = mContext.getResources().getDisplayMetrics().heightPixels / (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? 2 : 3); - mWeatherView.setLayoutParams(lp); - setWeatherGenerator(new SnowGenerator(mContext)); - mWeatherView.resetWeather(); - mWeatherView.setVisibility(View.VISIBLE); - mWeatherView.getConfettiManager().setRotationalVelocity(0, 45); - - listener = new GravitySensor(mContext, mWeatherView); - listener.setOrientation(mRotation); - listener.setSpeed(50); - listener.start(); - - mHeaderView.setImageResource(R.drawable.newyear_header); - mHeaderView.setVisibility(View.VISIBLE); - } else if (opt == 2) { - mWeatherView.setPrecipType(PrecipType.SNOW); - mWeatherView.setSpeed(35); - mWeatherView.setEmissionRate(mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? 4 : 2); - mWeatherView.setFadeOutPercent(0.75f); - mWeatherView.setAngle(0); - RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)mWeatherView.getLayoutParams(); - lp.height = mContext.getResources().getDisplayMetrics().heightPixels / (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? 3 : 4); - mWeatherView.setLayoutParams(lp); - setWeatherGenerator(new FlowerGenerator(mContext)); - mWeatherView.resetWeather(); - mWeatherView.setVisibility(View.VISIBLE); - mWeatherView.getConfettiManager().setRotationalVelocity(0, 45); - - listener = new GravitySensor(mContext, mWeatherView); - listener.setOrientation(mRotation); - listener.setSpeed(35); - listener.start(); - - mHeaderView.setImageResource(R.drawable.lunar_newyear_header); - mHeaderView.setVisibility(View.VISIBLE); - } else if (opt == 3) { - mWeatherView.setPrecipType(PrecipType.CLEAR); - mWeatherView.setSpeed(0); - mWeatherView.setEmissionRate(0.6f); - mWeatherView.setFadeOutPercent(1.0f); - mWeatherView.setAngle(0); - setWeatherGenerator(new CoinGenerator(mContext)); - mWeatherView.resetWeather(); - mWeatherView.setVisibility(View.VISIBLE); - mWeatherView.getConfettiManager().setRotationalVelocity(0, 15).setTTL(30000); - - mHeaderView.setImageResource(R.drawable.crypto_header); - mHeaderView.setVisibility(View.VISIBLE); + + mWeatherView.setPrecipType(opt == 3 ? PrecipType.CLEAR : PrecipType.SNOW); + mWeatherView.setSpeed(opt == 1 ? 50 : (opt == 2 ? 35 : 0)); + mWeatherView.setEmissionRate(mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? (opt == 1 ? 8 : 4) : (opt == 1 ? 4 : 2)); + mWeatherView.setFadeOutPercent(opt == 3 ? 1.0f : 0.75f); + mWeatherView.setAngle(0); + RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mWeatherView.getLayoutParams(); + lp.height = mContext.getResources().getDisplayMetrics().heightPixels / (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270 ? (opt == 1 ? 2 : 3) : (opt == 1 ? 3 : 4)); + mWeatherView.setLayoutParams(lp); + setWeatherGenerator(opt == 1 ? new SnowGenerator(mContext) : (opt == 2 ? new FlowerGenerator(mContext) : new CoinGenerator(mContext))); + mWeatherView.resetWeather(); + mWeatherView.setVisibility(View.VISIBLE); + mWeatherView.getConfettiManager().setRotationalVelocity(0, opt == 3 ? 15 : 45); + if (opt == 3) { + mWeatherView.getConfettiManager().setTTL(30000); } + GravitySensor listener = new GravitySensor(mContext, mWeatherView); + listener.setOrientation(mRotation); + listener.setSpeed(opt == 1 ? 50 : 35); + listener.start(); + + setupHeaderView(opt); angleListener = new WeakReference<>(listener); } + public static void pauseAnimation() { + if (angleListener != null) { + GravitySensor listener = angleListener.get(); + if (listener != null) { + listener.stop(); + } + angleListener.clear(); + } + } + + public static void resumeAnimation() { + if (angleListener != null) { + GravitySensor listener = angleListener.get(); + if (listener != null) { + listener.start(); + } + angleListener.clear(); + } + } + + private void setupHeaderView(int opt) { + int headerResId = opt == 1 ? R.drawable.newyear_header : (opt == 2 ? R.drawable.lunar_newyear_header : R.drawable.crypto_header); + mHeaderView.setImageResource(headerResId); + mHeaderView.setVisibility(View.VISIBLE); + } + private void setWeatherGenerator(ConfettoGenerator generator) { try { ConfettiManager manager = weatherView.get().getConfettiManager(); @@ -140,4 +131,4 @@ private void setWeatherGenerator(ConfettoGenerator generator) { t.printStackTrace(); } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/main/HyperCeilerTabActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/main/HyperCeilerTabActivity.java index 03feec56a..4edc37e12 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/app/main/HyperCeilerTabActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/app/main/HyperCeilerTabActivity.java @@ -264,13 +264,29 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten } } + @Override + public void onResume() { + super.onResume(); + if (isLunarNewYearThemeView) { + HolidayHelper.resumeAnimation(); + } + } + + @Override + protected void onPause() { + super.onPause(); + if (isLunarNewYearThemeView) { + HolidayHelper.pauseAnimation(); + } + } + @Override public void onDestroy() { + super.onDestroy(); ShellInit.destroy(); ThreadPoolManager.shutdown(); PreferenceHeader.mUninstallApp.clear(); PreferenceHeader.mDisableOrHiddenApp.clear(); - super.onDestroy(); } // 权限申请 diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/sub/CustomBackgroundSettings.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/sub/CustomBackgroundSettings.java index 31348c072..015d50d65 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/sub/CustomBackgroundSettings.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/sub/CustomBackgroundSettings.java @@ -29,11 +29,11 @@ import com.sevtinge.hyperceiler.ui.base.SettingsPreferenceFragment; import com.sevtinge.hyperceiler.utils.prefs.PrefsUtils; +import fan.pickerwidget.color.HSLColor; import fan.preference.ColorPickerPreference; public class CustomBackgroundSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener { - private String mKey = ""; private String mCustomBackgroundEnabledKey; private String mColorKey; private String mCornerRadiusKey; @@ -59,7 +59,7 @@ public void initPrefs() { Bundle args = getArguments(); if (args != null) { - mKey = args.getString("key"); + String mKey = args.getString("key"); mCustomBackgroundEnabledKey = mKey + "_custom_enable"; @@ -125,7 +125,7 @@ public boolean onPreferenceChange(@NonNull Preference preference, Object o) { if (preference == mCustomEnabledPreference) { setCustomEnable((Boolean) o); } else if (preference == mColorPickerPreference) { - setBackgroundColor((int) o); + setBackgroundColor((HSLColor) o); } else if (preference == mCornerRadiusPreference) { setBackgroundCornerRadius((int) o); } else if (preference == mBlurEnabledPreference) { @@ -141,9 +141,9 @@ private void setCustomEnable(boolean isCustomEnabled) { PrefsUtils.mSharedPreferences.edit().putBoolean(mCustomBackgroundEnabledKey, isCustomEnabled).apply(); } - private void setBackgroundColor(int value) { - mColorPickerPreference.setColor(value); - PrefsUtils.mSharedPreferences.edit().putInt(mColorKey, value).apply(); + private void setBackgroundColor(HSLColor value) { + mColorPickerPreference.setColor(value.color); + PrefsUtils.mSharedPreferences.edit().putInt(mColorKey, value.color).apply(); } private void setBackgroundCornerRadius(int value) { diff --git a/app/src/main/res/layout/layout_holiday.xml b/app/src/main/res/layout/layout_holiday.xml index 93cbc55b7..297f064a7 100644 --- a/app/src/main/res/layout/layout_holiday.xml +++ b/app/src/main/res/layout/layout_holiday.xml @@ -3,7 +3,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="0.1dp" - android:paddingRight="0.1dp" + android:paddingEnd="0.1dp" android:animateLayoutChanges="true" android:fitsSystemWindows="false">