Java Code Examples for java.lang.reflect.Field.setInt()

The following are Jave code examples for showing how to use setInt() of the java.lang.reflect.Field class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JRediClients   File: ConfigSupport.java   View Source Code Vote up 6 votes
private void patchUriField(String methodName, String fieldName)
        throws IOException {
    try {
        Method lowMask = URI.class.getDeclaredMethod(methodName, String.class);
        lowMask.setAccessible(true);
        Long lowMaskValue = (Long) lowMask.invoke(null, "-_");
        
        Field lowDash = URI.class.getDeclaredField(fieldName);
        
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(lowDash, lowDash.getModifiers() & ~Modifier.FINAL);
        
        lowDash.setAccessible(true);
        lowDash.setLong(null, lowMaskValue);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
 
Example 2
Project: LearningOfThinkInJava   File: ModifyingPrivateFields.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws Exception {
  WithPrivateFinalField pf = new WithPrivateFinalField();
  System.out.println(pf);
  Field f = pf.getClass().getDeclaredField("i");
  f.setAccessible(true);
  System.out.println("f.getInt(pf): " + f.getInt(pf));
  f.setInt(pf, 47);
  System.out.println(pf);
  f = pf.getClass().getDeclaredField("s");
  f.setAccessible(true);
  System.out.println("f.get(pf): " + f.get(pf));
  f.set(pf, "No, you're not!");
  System.out.println(pf);
  f = pf.getClass().getDeclaredField("s2");
  f.setAccessible(true);
  System.out.println("f.get(pf): " + f.get(pf));
  f.set(pf, "No, you're not!");
  System.out.println(pf);
}
 
Example 3
Project: boohee_v5.6   File: StatusBarProxy.java   View Source Code Vote up 6 votes
public static boolean setStatusBarDarkIcon(Window window, boolean dark) {
    if (window == null) {
        return false;
    }
    try {
        LayoutParams lp = window.getAttributes();
        Field darkFlag = LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
        Field meizuFlags = LayoutParams.class.getDeclaredField("meizuFlags");
        darkFlag.setAccessible(true);
        meizuFlags.setAccessible(true);
        int bit = darkFlag.getInt(null);
        int value = meizuFlags.getInt(lp);
        if (dark) {
            value |= bit;
        } else {
            value &= bit ^ -1;
        }
        meizuFlags.setInt(lp, value);
        window.setAttributes(lp);
        return true;
    } catch (Exception e) {
        Log.e(TAG, "setStatusBarDarkIcon: failed");
        return false;
    }
}
 
Example 4
Project: OpenJSharp   File: Unsafe.java   View Source Code Vote up 6 votes
public void putIntVolatile(Object obj, long offset, int newValue)
{
    if (obj instanceof cli.System.Array)
    {
        synchronized(this)
        {
            WriteInt32(obj, offset, newValue);
        }
    }
    else
    {
        Field field = getField(offset);
        synchronized(field)
        {
            try
            {
                field.setInt(obj, newValue);
            }
            catch(IllegalAccessException x)
            {
                throw (InternalError)new InternalError().initCause(x);
            }
        }
    }
}
 
Example 5
Project: Coder   File: ImmersionBar.java   View Source Code Vote up 6 votes
/**
 * 设置状态栏图标为深色和魅族特定的文字风格
 * 可以用来判断是否为Flyme用户
 *
 * @return boolean 成功执行返回true
 */
private void FlymeSetStatusBarLightMode() {
    if (mWindow != null) {
        try {
            WindowManager.LayoutParams lp = mWindow.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class
                    .getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (mBarParams.darkFont) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            mWindow.setAttributes(lp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 6
Project: ForgeHax   File: FastField.java   View Source Code Vote up 6 votes
@Override
protected Field lookup() throws Exception {
    for(State state : State.values()) {
        String n = name.getByState(state);
        if(!Strings.isNullOrEmpty(n)) try {
                Field f = insideClass.getDeclaredField(n);
                f.setAccessible(true);
                if(stripFinal) {
                    Field modifiersField = Field.class.getDeclaredField("modifiers");
                    modifiersField.setAccessible(true);
                    modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
                }
                return f;
        } catch (Exception e) {
            ;
        }
    }
    return null;
}
 
Example 7
Project: Sofia   File: Utils.java   View Source Code Vote up 6 votes
private static void setMeizuStatusBarFont(Activity activity, boolean darkFont) {
    try {
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
        Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
        darkFlag.setAccessible(true);
        meizuFlags.setAccessible(true);
        int bit = darkFlag.getInt(null);
        int value = meizuFlags.getInt(lp);
        if (darkFont) {
            value |= bit;
        } else {
            value &= ~bit;
        }
        meizuFlags.setInt(lp, value);
        activity.getWindow().setAttributes(lp);
    } catch (Exception ignored) {
    }
}
 
Example 8
Project: Device-Mod-Apps   File: Utils.java   View Source Code Vote up 5 votes
public static void setFinalStatic(Field field, Object newValue) throws Exception {
    field.setAccessible(true);

    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

    field.set(null, newValue);
}
 
Example 9
Project: SmartChart   File: StatusBarUtil.java   View Source Code Vote up 5 votes
/**
 * 设置Flyme4+的darkMode,darkMode时候字体颜色及icon变黑
 * http://open-wiki.flyme.cn/index.php?title=Flyme%E7%B3%BB%E7%BB%9FAPI
 */
public static boolean darkModeForFlyme4(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        try {
            WindowManager.LayoutParams e = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(e);
            if (dark) {
                value |= bit;
            } else {
                value &= ~bit;
            }

            meizuFlags.setInt(e, value);
            window.setAttributes(e);
            result = true;
        } catch (Exception var8) {
            Log.e("StatusBar", "darkIcon: failed");
        }
    }

    return result;
}
 
Example 10
Project: openjdk-jdk10   File: CommonSeeder.java   View Source Code Vote up 5 votes
static void setDefaultSeeder(EntropySource es) throws Exception {
    Field f = AbstractDrbg.class.getDeclaredField("defaultES");
    f.setAccessible(true);  // no more private
    Field f2 = Field.class.getDeclaredField("modifiers");
    f2.setAccessible(true);
    f2.setInt(f, f2.getInt(f) - Modifier.FINAL);    // no more final
    f.set(null, es);
}
 
Example 11
Project: CustomRecipes   File: ReflectionUtil.java   View Source Code Vote up 5 votes
public static void setStaticFinalFieldValue(Class<?> clazz, String fieldName, Object value) {
 		Field field = getDeclaredFieldRecursively(clazz, fieldName);
  	try {
  		Field modifiersField = Field.class.getDeclaredField("modifiers");
  		modifiersField.setAccessible(true);
	modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
	field.set(null, value);
} catch (Exception e) {
	e.printStackTrace();
}
  }
 
Example 12
Project: ProtocolSupportPocketStuff   File: ReflectionUtils.java   View Source Code Vote up 5 votes
public static void setInt(Field field, Object source, int value) {
	try {
		field.setInt(source, value);
		return;
	} catch (Exception e) {
		e.printStackTrace();
	}
	throw new RuntimeException("Error while setting field \"" + field.getName() + "\" from " + source + "!");
}
 
Example 13
Project: theskeleton   File: SocialConfig.java   View Source Code Vote up 5 votes
@PostConstruct
public void init() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
	Field field = Class.forName("org.springframework.social.facebook.api.UserOperations").
		getDeclaredField("PROFILE_FIELDS");
	field.setAccessible(true);
	Field modifiers = field.getClass().getDeclaredField("modifiers");
	modifiers.setAccessible(true);
	modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
	field.set(null, PROFILE_FIELDS);
}
 
Example 14
Project: Biliomi   File: TestUtils.java   View Source Code Vote up 5 votes
public static void setStaticFinalField(Class<?> clazz, String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
  Field modifiersField = Field.class.getDeclaredField("modifiers");
  Field targetfield = clazz.getDeclaredField(fieldName);

  targetfield.setAccessible(true);
  modifiersField.setAccessible(true);
  modifiersField.setInt(targetfield, targetfield.getModifiers() & ~Modifier.FINAL);

  targetfield.set(null, newValue);
}
 
Example 15
Project: BaseCore   File: FlymeHelper.java   View Source Code Vote up 5 votes
/**
 * 设置状态栏图标为深色和魅族特定的文字风格
 * 可以用来判断是否为Flyme用户
 *
 * @param isFontColorDark 是否把状态栏字体及图标颜色设置为深色
 * @return boolean 成功执行返回true
 */
@Override
public boolean setStatusBarLightMode(Activity activity, boolean isFontColorDark) {
    Window window = activity.getWindow();
    boolean result = false;
    if (window != null) {
        try {
            WindowManager.LayoutParams lp = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class
                    .getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (isFontColorDark) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            window.setAttributes(lp);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return result;
}
 
Example 16
Project: VanillaExtras   File: PacketReturnWorker.java   View Source Code Vote up 5 votes
@SuppressWarnings("rawtypes")
void processMessage(PacketReturnWorker message) {
	try {
		Class clazz = Class.forName(message.className);
		Field cooldownField = clazz.getDeclaredField(message.cooldownFieldName);
		Field maxCooldownField = clazz.getDeclaredField(message.maxCooldownFieldName);
		cooldownField.setInt(clazz, message.cooldown);
		maxCooldownField.setInt(clazz, message.maxCooldown);
	} catch (Exception e) {
		Utils.getLogger(Refs.NAME).catching(e);
	}
}
 
Example 17
Project: rmq4note   File: DefaultRequestProcessorTest.java   View Source Code Vote up 5 votes
private static void setFinalStatic(Field field, Object newValue) throws Exception {
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(null, newValue);
}
 
Example 18
Project: QMUI_Android   File: QMUIStatusBarHelper.java   View Source Code Vote up 5 votes
/**
 * 设置状态栏图标为深色和魅族特定的文字风格
 * 可以用来判断是否为 Flyme 用户
 *
 * @param window 需要设置的窗口
 * @param dark   是否把状态栏字体及图标颜色设置为深色
 * @return boolean 成功执行返回true
 */
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {

    // flyme 在 6.2.0.0A 支持了 Android 官方的实现方案,旧的方案失效
    Android6SetStatusBarLightMode(window, dark);

    boolean result = false;
    if (window != null) {
        try {
            WindowManager.LayoutParams lp = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class
                    .getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (dark) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            window.setAttributes(lp);
            result = true;
        } catch (Exception ignored) {

        }
    }
    return result;
}
 
Example 19
Project: polymorphia   File: MappedField.java   View Source Code Vote up 4 votes
@Override
public <T> void decodeInternal(BsonReader reader, T instance, Field field) throws IllegalAccessException {
    field.setInt(instance, reader.readInt32());
}
 
Example 20
Project: BlockBall   File: CustomRabbit.java   View Source Code Vote up 4 votes
private void ignoreFinalField(Field field) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    field.setAccessible(true);
    final Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
}