Example usage for java.lang.reflect Field setBoolean

List of usage examples for java.lang.reflect Field setBoolean

Introduction

In this page you can find the example usage for java.lang.reflect Field setBoolean.

Prototype

@CallerSensitive
@ForceInline 
public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Sets the value of a field as a boolean on the specified object.

Usage

From source file:edu.cornell.med.icb.goby.util.barcode.BarcodeMatcherResult.java

/**
 * This constructor is provided as an alternate to the one above. It uses a map
 * to set the values of the fields. This method is considerably slower because it uses reflection to
 * set the values of the class from a map so don't use this in the case where you are creating
 * millions of these objects./*from  w w w  .j a  v  a 2  s.  c  o m*/
 * @param init the map to initiaize the class with
 */
public BarcodeMatcherResult(final Map<String, Object> init) {
    ensureFieldsMap();
    for (final Map.Entry<String, Object> entry : init.entrySet()) {
        try {
            final Object value = entry.getValue();
            if (value == null) {
                continue;
            }
            final Field f = FIELDS_MAP.get(entry.getKey());
            if (value instanceof Integer) {
                f.setInt(this, (Integer) value);
            } else if (value instanceof Boolean) {
                f.setBoolean(this, (Boolean) value);
            }
        } catch (IllegalAccessException e) {
            LOG.error(e);
        } catch (IllegalArgumentException e) {
            LOG.error(e);
        }
    }
}

From source file:tn.codeit.darna.MainActivity.java

private void makeActionOverflowMenuShown() {
    //devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
    try {//w  ww . ja  va  2 s.co  m
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        //       Log.d(TAG, e.getLocalizedMessage());
    }
}

From source file:com.leeyou.weixin6.ActivityMain.java

private void setOverflowShowingAlways() {
    try {//from w w  w  .j  a  v  a  2s.c  om
        // true if a permanent menu key is present, false otherwise.
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.djoin.parking.parking.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setBooleanProperty("showTitle", true);
    setIntegerProperty("splashscreen", R.drawable.boot);
    super.onCreate(savedInstanceState);

    try {//from www  . j a  v  a  2s. co m
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    super.loadUrl(Config.getStartUrl(), 10000);
}

From source file:com.example.android.navigationdrawerexample.SecondActivity.java

private void forceShowOverflowMenu() {
    try {//from   www. ja  v  a 2s  .  c  o  m
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.itbooks.app.activities.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {/*from  w  ww  . j  a v a 2  s . c o  m*/
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception _e) {
        _e.printStackTrace();
    }

    final Wrappers wrappers = new Wrappers();
    //      wrappers.add(onClickWrapper);
    //      wrappers.add(onDismissWrapper);
    SuperCardToast.onRestoreState(savedInstanceState, this, wrappers);
}

From source file:com.daskiworks.ghwatch.ActivityBase.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // hack to show menu overlay button in Action Bar even for phone with hardware menu buttons.
    try {/*  ww  w.j a  va2 s.  c  om*/
        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
    }

}

From source file:com.cubusmail.server.user.PreferencesTypeHandler.java

public Object getResult(ResultGetter getter) throws SQLException {

    String preferencesJson = getter.getString();
    Preferences preferences = null;

    if (preferencesJson != null) {
        preferences = new Preferences();
        try {/*from ww w.  ja  va  2  s  . com*/
            JSONObject object = new JSONObject(preferencesJson);
            Field[] fields = Preferences.class.getFields();
            if (fields != null) {
                for (Field field : fields) {
                    Object value = object.has(field.getName()) ? object.get(field.getName()) : null;
                    if (value != null) {
                        if (value instanceof Integer) {
                            field.setInt(preferences, ((Integer) value).intValue());
                        } else if (value instanceof Boolean) {
                            field.setBoolean(preferences, ((Boolean) value).booleanValue());
                        } else if (value instanceof String) {
                            field.set(preferences, value);
                        }
                    }
                }
            }
        } catch (JSONException e) {
            log.error(e.getMessage(), e);
        } catch (NumberFormatException e) {
            log.error(e.getMessage(), e);
        } catch (IllegalArgumentException e) {
            log.error(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            log.error(e.getMessage(), e);
        }
    }

    return preferences;
}

From source file:org.protocoder.MainActivity.java

/**
* onResume//from  w  w  w  . j a  v a2s . c  o  m
*/
@Override
protected void onResume() {
    super.onResume();

    //set settings
    setScreenAlwaysOn(SettingsFragment.getScreenOn(this));

    MLog.d(TAG, "Registering as an EventBus listener in MainActivity");
    EventBus.getDefault().register(this);

    mStopServerReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            mProtocoder.app.hardKillConnections();
        }
    };

    registerReceiver(connectivityChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    mProtocoder.app.startServers();
    IntentFilter filterSend = new IntentFilter();
    filterSend.addAction("org.protocoder.intent.action.STOP_SERVER");
    registerReceiver(mStopServerReceiver, filterSend);
    observer.startWatching();

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        // presumably, not relevant
    }

    IDEcommunication.getInstance(this).ready(false);
}

From source file:org.ligi.android.dubwise_mk.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DUBwisePrefs.init(this);

    if (DUBwisePrefs.keepLightNow()) {
        if (mWakeLock == null) {
            final PowerManager pm = (PowerManager) (getSystemService(Context.POWER_SERVICE));
            mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "DUBwise");
        }/* w w w . j a v  a  2s . c  o  m*/
        mWakeLock.acquire();
    }

    // do only once
    if (!did_init) {
        //BluetoothMaster.init(activity);
        VoicePrefs.init(this);
        StatusVoice.getInstance().init(this);
        BlackBoxPrefs.init(this);

        // start the default connection
        StartupConnectionService.start(this);

        if (BlackBoxPrefs.isBlackBoxEnabled()) {
            DUBwiseBackgroundHandler.getInstance().addAndStartTask(BlackBox.getInstance());
        }

        did_init = true;
    }

    if (VoicePrefs.isVoiceEnabled() && !DUBwiseBackgroundHandler.getInstance().getBackgroundTasks()
            .contains(StatusVoice.getInstance())) {
        DUBwiseBackgroundHandler.getInstance().addAndStartTask(StatusVoice.getInstance());
    }

    setContentView(R.layout.base_layout);
    contentView = (ViewGroup) findViewById(R.id.content_frame);

    drawerList = (ListView) findViewById(R.id.left_drawer);

    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            IconicMenuItem item = ((IconicMenuItem) (drawerList.getAdapter().getItem(position)));

            if (item.intent != null) {
                startActivity(item.intent);
            }

        }
    });
    refresh_list();

    //mTitle = mDrawerTitle = getTitle();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            //getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            //getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    drawerLayout.setDrawerListener(drawerToggle);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // a little hack because I strongly disagree with the style guide here
    // ;-)
    // not having the Actionbar overfow menu also with devices with hardware
    // key really helps discoverability
    // http://stackoverflow.com/questions/9286822/how-to-force-use-of-overflow-menu-on-devices-with-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 - but at least we tried ;-)
    }

}