Skip to content

Commit

Permalink
CHANGELOG: Added QS Animations
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed Apr 29, 2024
1 parent f7c9848 commit 779cd94
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.dhd.oxygencustomizer.utils;

import android.content.Context;
import android.os.Environment;

import java.util.Arrays;
Expand Down Expand Up @@ -196,6 +197,11 @@ public static class QsTilesCustomization {
public static final String QS_BRIGHTNESS_SLIDER_COLOR = "brightness_slider_color";
public static final String QS_BRIGHTNESS_SLIDER_BACKGROUND_ENABLED = "brightness_slider_background_color_enabled";
public static final String QS_BRIGHTNESS_SLIDER_BACKGROUND_COLOR = "brightness_slider_background_color";
public static final String QS_TILE_ANIMATION_STYLE = "qs_tile_animation_style";
public static final String QS_TILE_ANIMATION_INTERPOLATOR = "qs_tile_animation_interpolator";
public static final String QS_TILE_ANIMATION_DURATION = "qs_tile_animation_duration";
public static final String QS_TILE_ANIMATION_TRANSFORMATIONS_SWITCH = "qs_transitions_title_switch";
public static final String QS_TILE_ANIMATION_TRANSFORMATIONS = "qs_tile_transformations";

public static final String[] QS_UPDATE_PREFS = {
QS_TILE_ACTIVE_COLOR_ENABLED,
Expand Down Expand Up @@ -532,7 +538,4 @@ public static final class SoundPrefs {
public static final String CLOCK_TAG = "clock";
public static final String DATE_TAG = "date";

public static final String LATEST_VERSION_URL = "https://raw.githubusercontent.com/DHD2280/Oxygen-Customizer/stable/latestVersion.json";
public static final String LATEST_BETA_URL = "https://raw.githubusercontent.com/DHD2280/Oxygen-Customizer/beta/latestBeta.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsHeaderImage.QS_HEADER_IMAGE_TINT_INTENSITY;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsHeaderImage.QS_HEADER_IMAGE_URI;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsHeaderImage.QS_HEADER_IMAGE_ZOOM_TO_FIT;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsTilesCustomization.QS_TILE_ANIMATION_DURATION;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsTilesCustomization.QS_TILE_ANIMATION_INTERPOLATOR;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsTilesCustomization.QS_TILE_ANIMATION_STYLE;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsTilesCustomization.QS_TILE_ANIMATION_TRANSFORMATIONS;
import static it.dhd.oxygencustomizer.utils.Constants.Preferences.QsTilesCustomization.QS_TILE_ANIMATION_TRANSFORMATIONS_SWITCH;

import android.annotation.SuppressLint;
import android.content.Context;
Expand Down Expand Up @@ -241,6 +246,16 @@ public static boolean isVisible(String key) {
case "brightness_slider_background_color" -> {
return instance.mPreferences.getBoolean("brightness_slider_background_color_enabled", false);
}
case QS_TILE_ANIMATION_INTERPOLATOR,
QS_TILE_ANIMATION_DURATION -> {
return !instance.mPreferences.getString(QS_TILE_ANIMATION_STYLE, "0").equals("0");
}
case QS_TILE_ANIMATION_TRANSFORMATIONS -> {
return instance.mPreferences.getBoolean(QS_TILE_ANIMATION_TRANSFORMATIONS_SWITCH, false);
}
case "qs_tile_label" -> {
return instance.mPreferences.getBoolean("qs_tile_label_enabled", false);
}

// Gesture Prefs
case "gesture_left_height" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static it.dhd.oxygencustomizer.xposed.hooks.systemui.OpUtils.getPrimaryColor;
import static it.dhd.oxygencustomizer.xposed.utils.ViewHelper.dp2px;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
Expand All @@ -28,8 +29,17 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.AbsSeekBar;
import android.widget.CheckBox;
import android.widget.FrameLayout;
Expand All @@ -41,11 +51,14 @@
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.slider.Slider;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
Expand All @@ -54,6 +67,8 @@
import it.dhd.oxygencustomizer.xposed.XposedMods;
import it.dhd.oxygencustomizer.xposed.utils.ShellUtils;
import it.dhd.oxygencustomizer.xposed.utils.SystemUtils;
import it.dhd.oxygencustomizer.xposed.utils.viewpager.ABaseTransformer;
import it.dhd.oxygencustomizer.xposed.utils.viewpager.*;

public class QsTileCustomization extends XposedMods {

Expand All @@ -73,6 +88,11 @@ public class QsTileCustomization extends XposedMods {
private ImageView mExpandIndicator = null;
private boolean advancedCustom = true;
private static final ArrayList<Object> qsViews = new ArrayList<>();
private int mAnimStyle = 0;
private int mInterpolatorType = 0;
private int mAnimDuration = 0;
private boolean mTrasformationsEnabled = false;
private int mTrasformations = 1;

public QsTileCustomization(Context context) {
super(context);
Expand All @@ -82,21 +102,33 @@ public QsTileCustomization(Context context) {
public void updatePrefs(String... Key) {
if (Xprefs == null) return;

// Qs Colors
qsActiveColorEnabled = Xprefs.getBoolean(QS_TILE_ACTIVE_COLOR_ENABLED, false);
qsActiveColor = Xprefs.getInt(QS_TILE_ACTIVE_COLOR, Color.RED);
qsInactiveColorEnabled = Xprefs.getBoolean(QS_TILE_INACTIVE_COLOR_ENABLED, false);
qsInactiveColor = Xprefs.getInt(QS_TILE_INACTIVE_COLOR, Color.GRAY);
qsDisabledColorEnabled = Xprefs.getBoolean(QS_TILE_DISABLED_COLOR_ENABLED, false);
qsDisabledColor = Xprefs.getInt(QS_TILE_DISABLED_COLOR, Color.DKGRAY);

// Brightness Slider
qsBrightnessSliderCustomize = Xprefs.getBoolean(QS_BRIGHTNESS_SLIDER_CUSTOMIZE, false);
qsBrightnessSliderColorMode = Integer.parseInt(Xprefs.getString(QS_BRIGHTNESS_SLIDER_COLOR_MODE, "0"));
qsBrightnessSliderColor = Xprefs.getInt(QS_BRIGHTNESS_SLIDER_COLOR, getPrimaryColor(mContext));
qsBrightnessBackgroundCustomize = Xprefs.getBoolean(QS_BRIGHTNESS_SLIDER_BACKGROUND_ENABLED, false);
qsBrightnessBackgroundColor = Xprefs.getInt(QS_BRIGHTNESS_SLIDER_BACKGROUND_COLOR, Color.TRANSPARENT);

// Labels
qsLabelsHide = Xprefs.getBoolean(QS_TILE_HIDE_LABELS, false);
qsLabelsColorEnabled = Xprefs.getBoolean(QS_TILE_LABELS_CUSTOM_COLOR_ENABLED, false);
qsLabelsColor = Xprefs.getInt(QS_TILE_LABELS_CUSTOM_COLOR, Color.WHITE);

// Qs Animations
mAnimStyle = Integer.parseInt(Xprefs.getString(QS_TILE_ANIMATION_STYLE, "0"));
mInterpolatorType = Integer.parseInt(Xprefs.getString(QS_TILE_ANIMATION_INTERPOLATOR, "0"));
mAnimDuration = Xprefs.getSliderInt(QS_TILE_ANIMATION_DURATION, 1);
mTrasformationsEnabled = Xprefs.getBoolean(QS_TILE_ANIMATION_TRANSFORMATIONS_SWITCH, false);
mTrasformations = Integer.parseInt(Xprefs.getString(QS_TILE_ANIMATION_TRANSFORMATIONS, "1"));

if (Key.length > 0) {
for(String k : QS_UPDATE_PREFS) {
if (Key[0].equals(k)) {
Expand Down Expand Up @@ -243,15 +275,26 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
};

final XC_MethodHook animationHook = new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
View qsTile = (View) param.thisObject;
qsTile.post(()->getTileAnimation(qsTile));
}
};

hookAllMethods(OplusQSTileBaseView, "generateDrawable", colorHook);

hookAllMethods(OplusQSTileBaseView, "performClick", animationHook);

Class<?> OplusQSHighlightTileView;
try {
OplusQSHighlightTileView = findClass("com.oplus.systemui.qs.qstileimpl.OplusQSHighlightTileView", lpparam.classLoader);
} catch (Throwable ignored) {
OplusQSHighlightTileView = findClass("com.oplusos.systemui.qs.qstileimpl.OplusQSHighlightTileView", lpparam.classLoader);
}
hookAllMethods(OplusQSHighlightTileView, "generateDrawable", colorHook);
hookAllMethods(OplusQSHighlightTileView, "performClick", animationHook);


Class<?> OplusQsMediaPanelView = findClass("com.oplus.systemui.qs.media.OplusQsMediaPanelView", lpparam.classLoader);
Expand Down Expand Up @@ -382,6 +425,103 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

} catch (Throwable ignored) {}

try {
Class<?> PagedTileLayout = findClass("com.android.systemui.qs.PagedTileLayout", lpparam.classLoader);
hookAllConstructors(PagedTileLayout, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {

Object VPagerListener = getObjectField(param.thisObject, "mOnPageChangeListener");
Object vPager = param.thisObject;
hookAllMethods(VPagerListener.getClass(),
"onPageScrolled", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!mTrasformationsEnabled) return;
final int childCount = (int) callMethod(vPager, "getChildCount");
for (int i = 0; i < childCount; i++) {
final View child = (View) callMethod(vPager, "getChildAt", i);
final Object lp = callMethod(child, "getLayoutParams");
if (getBooleanField(lp, "isDecor")) continue;
final float transformPos = (float) (child.getLeft() - (int)callMethod(vPager, "getScrollX")) / child.getWidth();
getCustomTransitions().transformPage(child, transformPos);
}
}
});
}
});
} catch (Throwable t) {
log(this.getClass().getSimpleName() + " error: " + t.getMessage());
}

}


private ViewPager.PageTransformer getCustomTransitions() {
return switch (mTrasformations) {
case 1 -> new CubeInTransformer();
case 2 -> new CubeOutTransformer();
case 3 -> new AccordionTransformer();
case 4 -> new BackgroundToForegroundTransformer();
case 5 -> new DepthPageTransformer();
case 6 -> new FadeTransformer();
case 7 -> new ForegroundToBackgroundTransformer();
case 8 -> new RotateDownTransformer();
case 9 -> new RotateUpTransformer();
case 10 -> new StackTransformer();
case 11 -> new TabletTransformer();
case 12 -> new ZoomInTransformer();
case 13 -> new ZoomOutTransformer();
case 14 -> new ZoomOutSlideTransformer();
default -> null;
};

}

private void getTileAnimation(View v) {
ObjectAnimator animTile = null;

switch (mAnimStyle) {
case 1:
animTile = ObjectAnimator.ofFloat(v, "rotationY", 0f, 360f);
break;
case 2:
animTile = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f);
break;
default:
return;
}

switch (mInterpolatorType) {
case 0:
animTile.setInterpolator(new LinearInterpolator());
break;
case 1:
animTile.setInterpolator(new AccelerateInterpolator());
break;
case 2:
animTile.setInterpolator(new DecelerateInterpolator());
break;
case 3:
animTile.setInterpolator(new AccelerateDecelerateInterpolator());
break;
case 4:
animTile.setInterpolator(new BounceInterpolator());
break;
case 5:
animTile.setInterpolator(new OvershootInterpolator());
break;
case 6:
animTile.setInterpolator(new AnticipateInterpolator());
break;
case 7:
animTile.setInterpolator(new AnticipateOvershootInterpolator());
break;
default:
break;
}
animTile.setDuration(mAnimDuration * 1000L);
animTile.start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package it.dhd.oxygencustomizer.xposed.utils.viewpager;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;
import android.view.View;

public abstract class ABaseTransformer implements ViewPager.PageTransformer {
protected abstract void onTransform(View view, float f);

public void transformPage(@NonNull View page, float position) {
onPreTransform(page, position);
onTransform(page, position);
onPostTransform(page, position);
}

protected boolean hideOffscreenPages() {
return true;
}

protected boolean isPagingEnabled() {
return false;
}

protected void onPreTransform(View page, float position) {
float f = 0.0f;
float width = (float) page.getWidth();
page.setRotationX(0.0f);
page.setRotationY(0.0f);
page.setRotation(0.0f);
page.setScaleX(1.0f);
page.setScaleY(1.0f);
page.setPivotX(0.0f);
page.setPivotY(0.0f);
page.setTranslationY(0.0f);
page.setTranslationX(isPagingEnabled() ? 0.0f : (-width) * position);
if (hideOffscreenPages()) {
if (position > -1.0f && position < 1.0f) {
f = 1.0f;
}
page.setAlpha(f);
return;
}
page.setAlpha(1.0f);
}

protected void onPostTransform(View page, float position) {
}

protected static float min(float val, float min) {
return Math.max(val, min);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.dhd.oxygencustomizer.xposed.utils.viewpager;

import android.view.View;

public class AccordionTransformer extends ABaseTransformer {
protected void onTransform(View view, float position) {
view.setPivotX((float) (position < 0.0f ? 0 : view.getWidth()));
view.setScaleX(position < 0.0f ? 1.0f + position : 1.0f - position);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.dhd.oxygencustomizer.xposed.utils.viewpager;


import android.view.View;

public class BackgroundToForegroundTransformer extends ABaseTransformer {
protected void onTransform(View view, float position) {
float f = 1.0f;
float height = (float) view.getHeight();
float width = (float) view.getWidth();
if (position >= 0.0f) {
f = Math.abs(1.0f - position);
}
float scale = min(f, 0.5f);
view.setScaleX(scale);
view.setScaleY(scale);
view.setPivotX(width * 0.5f);
view.setPivotY(height * 0.5f);
view.setTranslationX(position < 0.0f ? width * position : (-width) * position * 0.25f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.dhd.oxygencustomizer.xposed.utils.viewpager;

import android.view.View;

public class CubeInTransformer extends ABaseTransformer {
protected void onTransform(View view, float position) {
view.setPivotX((float) (position > 0.0f ? 0 : view.getWidth()));
view.setPivotY(0.0f);
view.setRotationY(-90.0f * position);
}

public boolean isPagingEnabled() {
return true;
}
}
Loading

0 comments on commit 779cd94

Please sign in to comment.