use of java.lang.reflect.Field in project Shuttle by timusus.
the class ThemeUtils method themeSearchView.
@SuppressLint("InlinedApi")
public static void themeSearchView(Context context, SearchView searchView) {
FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
NinePatchDrawable disabledDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_default_mtrl_alpha);
NinePatchDrawable otherDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_activated_mtrl_alpha);
int accentColor = ColorUtils.getAccentColor();
ColorFilter colorFilter = new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_activated }, otherDrawable, colorFilter);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, otherDrawable, colorFilter);
stateListDrawable.addState(StateSet.WILD_CARD, disabledDrawable);
View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
searchPlate.setBackground(stateListDrawable);
EditText searchTextView = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
try {
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(searchTextView, 0);
} catch (final Exception | NoClassDefFoundError ignored) {
}
}
use of java.lang.reflect.Field in project Shuttle by timusus.
the class PreferenceManagerCompat method setOnPreferenceTreeClickListener.
/**
* Sets the callback to be invoked when a {@link Preference} in the
* hierarchy rooted at this {@link PreferenceManager} is clicked.
*
* @param listener The callback to be invoked.
*/
static void setOnPreferenceTreeClickListener(PreferenceManager manager, final OnPreferenceTreeClickListener listener) {
try {
Field onPreferenceTreeClickListener = PreferenceManager.class.getDeclaredField("mOnPreferenceTreeClickListener");
onPreferenceTreeClickListener.setAccessible(true);
if (listener != null) {
Object proxy = Proxy.newProxyInstance(onPreferenceTreeClickListener.getType().getClassLoader(), new Class[] { onPreferenceTreeClickListener.getType() }, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) {
if (method.getName().equals("onPreferenceTreeClick")) {
return Boolean.valueOf(listener.onPreferenceTreeClick((PreferenceScreen) args[0], (Preference) args[1]));
} else {
return null;
}
}
});
onPreferenceTreeClickListener.set(manager, proxy);
} else {
onPreferenceTreeClickListener.set(manager, null);
}
} catch (Exception e) {
Log.w(TAG, "Couldn't set PreferenceManager.mOnPreferenceTreeClickListener by reflection", e);
}
}
use of java.lang.reflect.Field in project torodb by torodb.
the class DescriptionFactoryWrapper method document.
private void document(JsonPointer propPointer, BeanProperty prop) {
JavaType type = prop.getType();
if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType() && !type.isMapLikeType()) {
console.println("");
} else if (isPrimitive(type) || type.isEnumType()) {
printTabs();
console.print(propPointer.toString());
console.print("=");
} else if (type.isMapLikeType()) {
printTabs();
console.print(propPointer.append(JsonPointer.compile("/<string>")).toString());
console.print("=");
type = type.getContentType();
}
if (isPrimitive(type)) {
console.print("<");
console.print(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, type.getRawClass().getSimpleName()));
console.print(">");
} else if (type.isEnumType()) {
console.print("<enum:string>");
}
if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
printTabs();
}
printDescription(prop);
if (hasDescription(prop) || isPrimitive(type) || type.isEnumType()) {
console.println("");
}
if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
console.println("");
}
if (type.isEnumType()) {
for (Field enumField : type.getRawClass().getDeclaredFields()) {
if (!enumField.isEnumConstant()) {
continue;
}
printTabs();
console.print(" - ");
console.print(enumField.getName());
Description enumConstantConfigProperty = enumField.getAnnotation(Description.class);
if (enumConstantConfigProperty != null && enumConstantConfigProperty.value() != null) {
console.print(" # ");
console.print(resourceBundle.getString(enumConstantConfigProperty.value()));
}
console.println("");
}
}
}
use of java.lang.reflect.Field in project bazel by bazelbuild.
the class IncrementalClassLoader method setParent.
private static void setParent(ClassLoader classLoader, ClassLoader newParent) {
try {
Field parent = ClassLoader.class.getDeclaredField("parent");
parent.setAccessible(true);
parent.set(classLoader, newParent);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
use of java.lang.reflect.Field in project BGABanner-Android by bingoogolapple.
the class BGAViewPager method getXVelocity.
private float getXVelocity() {
float xVelocity = 0;
Class viewpagerClass = ViewPager.class;
try {
Field velocityTrackerField = viewpagerClass.getDeclaredField("mVelocityTracker");
velocityTrackerField.setAccessible(true);
VelocityTracker velocityTracker = (VelocityTracker) velocityTrackerField.get(this);
Field activePointerIdField = viewpagerClass.getDeclaredField("mActivePointerId");
activePointerIdField.setAccessible(true);
Field maximumVelocityField = viewpagerClass.getDeclaredField("mMaximumVelocity");
maximumVelocityField.setAccessible(true);
int maximumVelocity = maximumVelocityField.getInt(this);
velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
xVelocity = VelocityTrackerCompat.getXVelocity(velocityTracker, activePointerIdField.getInt(this));
} catch (Exception e) {
}
return xVelocity;
}
Aggregations