Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.util.Log;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -203,4 +204,13 @@ public static void set(Object obj, Field field, Object obj2) {
Log.e(TAG, field.getName() + " IllegalArgumentException", e2);
}
}

public static Constructor<?> getConstructor(String str, Class<?>... clsArr) {
try {
return Class.forName(str).getDeclaredConstructor(clsArr);
} catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ public static String getField_SEM_PEN_HOVERING() {
}
return obj instanceof String ? (String) obj : "pen_hovering";
}

public static String getField_SEM_ACCESSIBILITY_REDUCE_TRANSPARENCY() {
Method declaredMethod;
Object obj = null;
if (Build.VERSION.SDK_INT >= 31 && (declaredMethod = SeslBaseReflector.getDeclaredMethod(mClass, "hidden_SEM_ACCESSIBILITY_REDUCE_TRANSPARENCY", new Class[0])) != null) {
obj = SeslBaseReflector.invoke(null, declaredMethod, new Object[0]);
}
return obj instanceof String ? (String) obj : "not_supported";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package androidx.reflect.view;

import android.os.Build;
import android.util.Log;
import android.view.View;

import androidx.reflect.SeslBaseReflector;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SeslSemBlurInfoReflector {
private static final String TAG = "SeslSemBlurInfoReflector";
private static final String mBuilderClass = "android.view.SemBlurInfo$Builder";

private SeslSemBlurInfoReflector() {
}

public static Object semCreateBlurBuilder(int i) {
Constructor<?> constructor = SeslBaseReflector.getConstructor(mBuilderClass, Integer.TYPE);
if (Build.VERSION.SDK_INT >= 31 && constructor != null) {
try {
return constructor.newInstance(Integer.valueOf(i));
} catch (IllegalAccessException e) {
Log.e(TAG, "semCreateBlurBuilder IllegalAccessException", e);
} catch (InstantiationException e2) {
Log.e(TAG, "semCreateBlurBuilder InstantiationException", e2);
} catch (InvocationTargetException e3) {
Log.e(TAG, "semCreateBlurBuilder InvocationTargetException", e3);
}
}
return null;
}

public static Object semSetBuilderBlurRadius(Object obj, int i) {
Method declaredMethod = Build.VERSION.SDK_INT >= 31 ? SeslBaseReflector.getDeclaredMethod(mBuilderClass, "hidden_setRadius", Integer.TYPE) : null;
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
SeslBaseReflector.invoke(obj, declaredMethod, Integer.valueOf(i));
}
return obj;
}

public static Object semSetBuilderBlurBackgroundColor(Object obj, int i) {
Method declaredMethod = Build.VERSION.SDK_INT >= 31 ? SeslBaseReflector.getDeclaredMethod(mBuilderClass, "hidden_setBackgroundColor", Integer.TYPE) : null;
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
SeslBaseReflector.invoke(obj, declaredMethod, Integer.valueOf(i));
}
return obj;
}

public static Object semSetBuilderBlurBackgroundCornerRadius(Object obj, float f) {
Method declaredMethod = Build.VERSION.SDK_INT >= 31 ? SeslBaseReflector.getDeclaredMethod(mBuilderClass, "hidden_setBackgroundCornerRadius", Float.TYPE) : null;
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
SeslBaseReflector.invoke(obj, declaredMethod, Float.valueOf(f));
}
return obj;
}

public static void semBuildSetBlurInfo(Object obj, View view) {
Method declaredMethod = Build.VERSION.SDK_INT >= 31 ? SeslBaseReflector.getDeclaredMethod(mBuilderClass, "hidden_build", new Class[0]) : null;
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
SeslViewReflector.semSetBlurInfo(view, SeslBaseReflector.invoke(obj, declaredMethod, new Object[0]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import android.view.PointerIcon;
import android.view.View;

Expand All @@ -11,6 +12,7 @@
import java.lang.reflect.Method;

public class SeslViewReflector {
private static final String TAG = "SeslViewReflector";
private static final Class<?> mClass = View.class;

private SeslViewReflector() {
Expand Down Expand Up @@ -165,6 +167,19 @@ public static boolean isHoveringUIEnabled(View view) {
return false;
}

public static void semSetBlurInfo(View view, Object obj) {
if (Build.VERSION.SDK_INT >= 31) {
try {
Method declaredMethod = SeslBaseReflector.getDeclaredMethod(mClass, "hidden_semSetBlurInfo", Class.forName("android.view.SemBlurInfo"));
if (declaredMethod != null) {
SeslBaseReflector.invoke(view, declaredMethod, obj);
}
} catch (ClassNotFoundException e) {
Log.e(TAG, "semSetBlurInfo ClassNotFoundException", e);
}
}
}

public static void semSetPointerIcon(View view, int i, PointerIcon pointerIcon) {
Method method;
if (Build.VERSION.SDK_INT >= 29) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Typeface;
import android.provider.Settings;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
Expand All @@ -15,6 +16,8 @@

import androidx.annotation.MenuRes;
import androidx.core.content.res.ResourcesCompat;
import androidx.reflect.provider.SeslSystemReflector;
import androidx.reflect.view.SeslSemBlurInfoReflector;

import java.util.ArrayList;

Expand All @@ -38,6 +41,7 @@ public class PopupMenu {
private CharSequence title;

private int mAnimationStyleRes = 0;
private boolean mBlurEffectEnabled;
private boolean mGroupDividerEnabled;

private int lastGroupId = 0;
Expand All @@ -48,6 +52,7 @@ public PopupMenu(View anchor) {
this.context = anchor.getContext();
this.anchor = anchor;
mIsOneUI4 = context.getTheme().obtainStyledAttributes(new int[]{R.attr.isOneUI4}).getBoolean(0, false);
mBlurEffectEnabled = mIsOneUI4;
}

public interface PopupMenuListener {
Expand Down Expand Up @@ -178,6 +183,29 @@ private TextView createTitleView() {
return titleView;
}

private boolean isReduceTransparencySettingsEnabled() {
String reduceTransparencyFlag = SeslSystemReflector.getField_SEM_ACCESSIBILITY_REDUCE_TRANSPARENCY();
return !reduceTransparencyFlag.equals("not_supported") && Settings.System.getInt(context.getContentResolver(), reduceTransparencyFlag, 0) == 1;
}

private void setupBlurEffect() {
if (mBlurEffectEnabled) {
if (popupWindow.getContentView() != null && context != null) {
Object blurBuilder = SeslSemBlurInfoReflector.semCreateBlurBuilder(0 /* SemBlurInfo.BLUR_MODE_WINDOW */);

if (blurBuilder != null && !isReduceTransparencySettingsEnabled()) {
SeslSemBlurInfoReflector.semSetBuilderBlurRadius(blurBuilder, 120);
SeslSemBlurInfoReflector.semSetBuilderBlurBackgroundColor(blurBuilder, context.getResources().getColor(R.color.sesl_popup_menu_blur_background));
SeslSemBlurInfoReflector.semSetBuilderBlurBackgroundCornerRadius(blurBuilder, context.getResources().getDimension(R.dimen.sesl_menu_popup_corner_radius));
SeslSemBlurInfoReflector.semBuildSetBlurInfo(blurBuilder, popupWindow.getContentView());
if (listView != null) {
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
}
}
}
}

private boolean shouldShowGroupDivider(MenuItem menuItem) {
if (mGroupDividerEnabled) {
if (menuItem.getGroupId() == lastGroupId) {
Expand Down Expand Up @@ -228,6 +256,7 @@ public void show() {
public void show(int xoff, int yoff) {
this.xoff = xoff;
this.yoff = yoff;
setupBlurEffect();
popupWindow.showAsDropDown(anchor, xoff, yoff);
updatePopupSize();
((View) ReflectUtils.genericGetField(popupWindow, "mBackgroundView")).setClipToOutline(true);
Expand All @@ -240,6 +269,10 @@ public void setAnimationStyle(int animationStyle) {
}
}

public void setBlurEffectEnabled(boolean enabled) {
mBlurEffectEnabled = enabled;
}

public void setGroupDividerEnabled(boolean enabled) {
mGroupDividerEnabled = enabled;

Expand Down
1 change: 1 addition & 0 deletions yanndroid/oneui/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<color name="sesl_menu_popup_background_stroke_color">#ff252525</color>
<color name="sesl4_menu_popup_background_color">#ff3a3a3a</color>
<color name="sesl4_menu_popup_background_stroke_color">#ff3a3a3a</color>
<color name="sesl_popup_menu_blur_background">#d6252525</color>
<color name="sesl_spinner_dropdown_item_text_color_normal">#fffafafa</color>
<color name="sesl_spinner_dropdown_item_text_color_disabled">#66fafafa</color>
<color name="sesl_spinner_icon_color_default">#ffd9d9d9</color>
Expand Down
1 change: 1 addition & 0 deletions yanndroid/oneui/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<color name="sesl_menu_popup_background_stroke_color">#fffcfcfc</color>
<color name="sesl4_menu_popup_background_color">#fffcfcfc</color>
<color name="sesl4_menu_popup_background_stroke_color">#fffcfcfc</color>
<color name="sesl_popup_menu_blur_background">#e6fcfcfc</color>
<color name="sesl_popup_menu_item_text_color_checked">?colorPrimaryDark</color>
<color name="sesl_spinner_dropdown_item_checkmark">?colorPrimaryDark</color>
<color name="sesl_spinner_dropdown_item_text_color_disabled">#66000000</color>
Expand Down