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

The following are Jave code examples for showing how to use setBoolean() 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: OpenJSharp   File: AWTEvent.java   View Source Code Vote up 6 votes
/**
 * Copies all private data from this event into that.
 * Space is allocated for the copied data that will be
 * freed when the that is finalized. Upon completion,
 * this event is not changed.
 */
void copyPrivateDataInto(AWTEvent that) {
    that.bdata = this.bdata;
    // Copy canAccessSystemClipboard value from this into that.
    if (this instanceof InputEvent && that instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                boolean b = field.getBoolean(this);
                field.setBoolean(that, b);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
                }
            }
        }
    }
    that.isSystemGenerated = this.isSystemGenerated;
}
 
Example 2
Project: quickblox-android   File: CoreBaseActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    actionBar = getSupportActionBar();

    // Hack. Forcing overflow button on actionbar on devices with hardware menu button
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
}
 
Example 3
Project: BaseClient   File: Option.java   View Source Code Vote up 6 votes
public void setValue(boolean value) {
    this.value = value;
    Field[] arrfield = this.mod.getClass().getDeclaredFields();
    int n = arrfield.length;
    int n2 = 0;
    while (n2 < n) {
        Field field = arrfield[n2];
        field.setAccessible(true);
        if (field.isAnnotationPresent(Op.class) && field.getName().equalsIgnoreCase(this.name)) {
            try {
                field.setBoolean(this.mod, value);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        ++n2;
    }
    if (Gui.instance != null) {
        Gui.instance.reloadOptions();
    }
    OptionManager.save();
}
 
Example 4
Project: jdk8u-jdk   File: AWTEvent.java   View Source Code Vote up 6 votes
/**
 * Copies all private data from this event into that.
 * Space is allocated for the copied data that will be
 * freed when the that is finalized. Upon completion,
 * this event is not changed.
 */
void copyPrivateDataInto(AWTEvent that) {
    that.bdata = this.bdata;
    // Copy canAccessSystemClipboard value from this into that.
    if (this instanceof InputEvent && that instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                boolean b = field.getBoolean(this);
                field.setBoolean(that, b);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
                }
            }
        }
    }
    that.isSystemGenerated = this.isSystemGenerated;
}
 
Example 5
Project: BaseClient   File: Option.java   View Source Code Vote up 6 votes
public void setValueHard(boolean value) {
    this.value = value;
    Field[] arrfield = this.mod.getClass().getDeclaredFields();
    int n = arrfield.length;
    int n2 = 0;
    while (n2 < n) {
        Field field = arrfield[n2];
        field.setAccessible(true);
        if (field.isAnnotationPresent(Op.class) && field.getName().equalsIgnoreCase(this.name)) {
            try {
                field.setBoolean(this.mod, value);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        ++n2;
    }
    if (Gui.instance != null) {
        Gui.instance.reloadOptions();
    }
    OptionManager.save();
}
 
Example 6
Project: SamaGamesAPI   File: NametagEntity.java   View Source Code Vote up 6 votes
public NametagEntity(final Player player)
{
    super(((CraftWorld)player.getWorld()).getHandle());
    final Location location = player.getLocation();
    this.setInvisible(true);
    this.setPosition(location.getX(), location.getY(), location.getZ());
    try {
        final Field invulnerable = Entity.class.getDeclaredField("invulnerable");
        invulnerable.setAccessible(true);
        invulnerable.setBoolean(this, true);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    this.world.addEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
    this.persistent = true;
    this.hideTag(player);
}
 
Example 7
Project: iReading   File: CommonUtils.java   View Source Code Vote up 6 votes
/**
 * 取消BottomNavigationView各item切换时的位移动效
 *
 * @param navigationView 底部导航栏视图
 */
public static void disableShiftMode(BottomNavigationView navigationView) {

    BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.getChildAt(0);
    try {
        Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
        shiftingMode.setAccessible(true);
        shiftingMode.setBoolean(menuView, false);
        shiftingMode.setAccessible(false);

        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(i);
            itemView.setShiftingMode(false);
            itemView.setChecked(itemView.getItemData().isChecked());
        }

    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: OpenJSharp   File: AWTEvent.java   View Source Code Vote up 5 votes
void dispatched() {
    if (this instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                field.setBoolean(this, false);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("AWTEvent.dispatched() got IllegalAccessException ", e);
                }
            }
        }
    }
}
 
Example 9
Project: Shared-Route   File: Utils.java   View Source Code Vote up 5 votes
public static void forceShowOverflowMenu(Context context) {
	try {
		ViewConfiguration config = ViewConfiguration.get(context);
		Field menuKeyField = ViewConfiguration.class.
				getDeclaredField("sHasPermanentMenuKey");
		if (menuKeyField != null) {
			menuKeyField.setAccessible(true);
			menuKeyField.setBoolean(config, false);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 10
Project: Android-Skin   File: AndroidSkinHook.java   View Source Code Vote up 5 votes
private void hookLayoutInflater(Context context) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    try {
        Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
        field.setAccessible(true);
        field.setBoolean(layoutInflater, false);
        LayoutInflaterCompat.setFactory2(layoutInflater, AndroidSkinFactory.from(context,layoutInflater));
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
Example 11
Project: CodeCompilerApp   File: MyApp.java   View Source Code Vote up 5 votes
@Override
public void onCreate() {
    super.onCreate();
    // force to sow the overflow menu icon
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
}
 
Example 12
Project: Android-skin-support   File: SkinActivityLifecycle.java   View Source Code Vote up 5 votes
private void installLayoutFactory(Context context) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    try {
        Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
        field.setAccessible(true);
        field.setBoolean(layoutInflater, false);
        LayoutInflaterCompat.setFactory(layoutInflater, getSkinDelegate(context));
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
 
Example 13
Project: creacoinj   File: DRMWorkaround.java   View Source Code Vote up 5 votes
public static void maybeDisableExportControls() {
    // This sorry story is documented in https://bugs.openjdk.java.net/browse/JDK-7024850
    // Oracle received permission to ship AES-256 by default in 2011, but didn't get around to it for Java 8
    // even though that shipped in 2014! That's dumb. So we disable the ridiculous US government mandated DRM
    // for AES-256 here, as Tor/BIP38 requires it.

    if (done) return;
    done = true;

    if (Utils.isAndroidRuntime())
        return;
    try {
        Field gate = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
        gate.setAccessible(true);
        gate.setBoolean(null, false);
        final Field allPerm = Class.forName("javax.crypto.CryptoAllPermission").getDeclaredField("INSTANCE");
        allPerm.setAccessible(true);
        Object accessAllAreasCard = allPerm.get(null);
        final Constructor<?> constructor = Class.forName("javax.crypto.CryptoPermissions").getDeclaredConstructor();
        constructor.setAccessible(true);
        Object coll = constructor.newInstance();
        Method addPerm = Class.forName("javax.crypto.CryptoPermissions").getDeclaredMethod("add", java.security.Permission.class);
        addPerm.setAccessible(true);
        addPerm.invoke(coll, accessAllAreasCard);
        Field defaultPolicy = Class.forName("javax.crypto.JceSecurity").getDeclaredField("defaultPolicy");
        defaultPolicy.setAccessible(true);
        defaultPolicy.set(null, coll);
    } catch (Exception e) {
        log.warn("Failed to deactivate AES-256 barrier logic, Tor mode/BIP38 decryption may crash if this JVM requires it: " + e.getMessage());
    }
}
 
Example 14
Project: incubator-netbeans   File: StatusTest.java   View Source Code Vote up 4 votes
private void setAutomaticRefreshEnabled (boolean flag) throws Exception {
    Field f = FilesystemInterceptor.class.getDeclaredField("AUTOMATIC_REFRESH_ENABLED");
    f.setAccessible(true);
    f.setBoolean(FilesystemInterceptor.class, flag);
    assert ((Boolean) f.get(FilesystemInterceptor.class)).equals(flag);
}
 
Example 15
Project: incubator-netbeans   File: NavigatorPanelWithToolbarTest.java   View Source Code Vote up 4 votes
public void testFix217212_ActivatePanel() throws Exception {
    InstanceContent ic = new InstanceContent();
    GlobalLookup4TestImpl nodesLkp = new GlobalLookup4TestImpl(ic);
    UnitTestUtils.prepareTest(new String[]{
                "/META-INF/generated-layer.xml"},
            Lookups.singleton(nodesLkp));

    TestLookupHint hint = new TestLookupHint("annotation/tester");
    ic.add(hint);

    final NavigatorTC navTC = NavigatorTC.getInstance();
    Field field = NavigatorController.class.getDeclaredField("updateWhenNotShown");
    field.setAccessible(true);
    field.setBoolean(navTC.getController(), true);
    try {
        Mutex.EVENT.readAccess(new Mutex.ExceptionAction() {
            @Override
            public Object run() throws Exception {
                navTC.getController().propertyChange(
                        new PropertyChangeEvent(navTC, TopComponent.Registry.PROP_TC_OPENED, null, navTC));
                return null;
            }
        });
        waitForProviders(navTC);
        NavigatorPanel selPanel = navTC.getSelectedPanel();
        assertNotNull("Selected panel is null", selPanel);

        List<? extends NavigatorPanel> panels = navTC.getPanels();
        assertEquals(2, panels.size());

        NavigatorPanel lazyPanel1 = panels.get(0);
        Method method = LazyPanel.class.getDeclaredMethod("initialize");
        method.setAccessible(true);
        NavigatorPanel delegate1 = (NavigatorPanel) method.invoke(lazyPanel1);

        NavigatorPanel lazyPanel2 = panels.get(1);
        method = LazyPanel.class.getDeclaredMethod("initialize");
        method.setAccessible(true);
        NavigatorPanel delegate2 = (NavigatorPanel) method.invoke(lazyPanel2);

        System.out.println("selected panel before: " + selPanel.getDisplayName());

        //find not-selected panel
        final NavigatorPanel toActivate;
        final NavigatorPanel toActivateLazy;
        if (selPanel.equals(lazyPanel1)) {
            toActivate = delegate2;
            toActivateLazy = lazyPanel2;
        } else {
            toActivate = delegate1;
            toActivateLazy = lazyPanel1;

        }

        Mutex.EVENT.readAccess(new Mutex.ExceptionAction() {
            @Override
            public Object run() throws Exception {
                NavigatorHandler.activatePanel(toActivate);
                return null;
            }
        });

        assertTrue(selPanel != navTC.getSelectedPanel());
        assertTrue(toActivateLazy == navTC.getSelectedPanel());

        System.out.println("selected panel after: " + navTC.getSelectedPanel().getDisplayName());
    } finally {
        navTC.getController().propertyChange(
                new PropertyChangeEvent(navTC, TopComponent.Registry.PROP_TC_CLOSED, null, navTC));
    }
}
 
Example 16
Project: Luhn   File: CardTextInputLayout.java   View Source Code Vote up 4 votes
private void toggleEnabled(String fieldName, boolean value) throws NoSuchFieldException, IllegalAccessException {
    Field cthField = null;
    cthField = TextInputLayout.class.getDeclaredField(fieldName);
    cthField.setAccessible(true);
    cthField.setBoolean(this, value);
}
 
Example 17
Project: ETF-Java   File: ReflectionUtils.java   View Source Code Vote up 4 votes
public static void setField(Object instance, Field field, Object value) throws IllegalAccessException {
	if (value == null && field.getType().isPrimitive()) {
		return;
	}
	
	if (UNSAFE != null) {
		if (int.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (int) value);
		} else if (long.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (long) value);
		} else if (double.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (double) value);
		} else if (void.class.equals(field.getType())) {
		
		} else if (float.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (float) value);
		} else if (byte.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (byte) value);
		} else if (char.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (char) value);
		} else if (boolean.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (boolean) value);
		} else if (short.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (short) value);
		} else {
			((sun.misc.Unsafe) UNSAFE).putObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), value);
		}
	} else { //Fallback if unsafe isn't available
		field.setAccessible(true);
		if (int.class.equals(field.getType())) {
			field.setInt(instance, (int) value);
		} else if (long.class.equals(field.getType())) {
			field.setLong(instance, (long) value);
		} else if (double.class.equals(field.getType())) {
			field.setDouble(instance, (double) value);
		} else if (void.class.equals(field.getType())) {
			
		} else if (float.class.equals(field.getType())) {
			field.setFloat(instance, (float) value);
		} else if (byte.class.equals(field.getType())) {
			field.setByte(instance, (byte) value);
		} else if (char.class.equals(field.getType())) {
			field.setChar(instance, (char) value);
		} else if (boolean.class.equals(field.getType())) {
			field.setBoolean(instance, (boolean) value);
		} else if (short.class.equals(field.getType())) {
			field.setShort(instance, (short) value);
		} else {
			field.set(instance, value);
		}
	}
}
 
Example 18
Project: tomcat7   File: WebappClassLoaderBase.java   View Source Code Vote up 4 votes
private void clearReferencesStopTimerThread(Thread thread) {

        // Need to get references to:
        // in Sun/Oracle JDK:
        // - newTasksMayBeScheduled field (in java.util.TimerThread)
        // - queue field
        // - queue.clear()
        // in IBM JDK, Apache Harmony:
        // - cancel() method (in java.util.Timer$TimerImpl)

        try {

            try {
                Field newTasksMayBeScheduledField =
                    thread.getClass().getDeclaredField("newTasksMayBeScheduled");
                newTasksMayBeScheduledField.setAccessible(true);
                Field queueField = thread.getClass().getDeclaredField("queue");
                queueField.setAccessible(true);

                Object queue = queueField.get(thread);

                Method clearMethod = queue.getClass().getDeclaredMethod("clear");
                clearMethod.setAccessible(true);

                synchronized(queue) {
                    newTasksMayBeScheduledField.setBoolean(thread, false);
                    clearMethod.invoke(queue);
                    queue.notify();  // In case queue was already empty.
                }

            }catch (NoSuchFieldException nfe){
                Method cancelMethod = thread.getClass().getDeclaredMethod("cancel");
                synchronized(thread) {
                    cancelMethod.setAccessible(true);
                    cancelMethod.invoke(thread);
                }
            }

            log.error(sm.getString("webappClassLoader.warnTimerThread",
                    contextName, thread.getName()));

        } catch (Exception e) {
            // So many things to go wrong above...
            Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(t);
            log.warn(sm.getString(
                    "webappClassLoader.stopTimerThreadFail",
                    thread.getName(), contextName), t);
        }
    }
 
Example 19
Project: MagicBox   File: BooleanReader.java   View Source Code Vote up 4 votes
@Override
public void read(Bundle bundle, Object to, StateField field) throws IllegalAccessException {
    Field propertyField = field.getField();
    propertyField.setAccessible(true);
    propertyField.setBoolean(to,bundle.getBoolean(field.getBundleKey()));
}
 
Example 20
Project: VoidApi   File: SerializableConfig.java   View Source Code Vote up 4 votes
public void deserializePrimitiveField(Field f, Property prop, Object instance) throws IllegalArgumentException, IllegalAccessException
{
	switch(fromJavaPrimitiveType(f.getType()))
	{
		case INTEGER:
		{
			if (f.getType().equals(Byte.TYPE))
			{
				f.setByte(instance, (byte) prop.getInt());
			}
			
			if (f.getType().equals(Short.TYPE))
			{
				f.setShort(instance, (short) prop.getInt());
			}
			
			if (f.getType().equals(Integer.TYPE))
			{
				f.setInt(instance, prop.getInt());
			}
			
			break;
		}
		
		case DOUBLE:
		{
			if (f.getType().equals(Float.TYPE))
			{
				f.setFloat(instance, (float) prop.getDouble());
			}
			
			if (f.getType().equals(Double.TYPE))
			{
				f.setDouble(instance, prop.getDouble());
			}
			
			if (f.getType().equals(Long.TYPE))
			{
				f.setLong(instance, (long) prop.getDouble());
			}
			
			break;
		}
		
		case BOOLEAN:
		{
			f.setBoolean(instance, prop.getBoolean());
			break;
		}
		
		default:
		{
			f.set(instance, prop.getString());
		}
	}
}