List of usage examples for java.lang.reflect Field getInt
@CallerSensitive @ForceInline public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:com.example.SimpleTestClient.Activities.TestMainActivity.java
private void InitializePortait() { mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_test_main_drawer_layout); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name, R.string.app_name) {// w w w. j a v a 2 s . c o m /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { if (showingQuestion != null && getActionBar() != null) { getActionBar().setTitle(showingQuestion.Name()); } invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { if (getActionBar() != null) { getActionBar().setTitle("?"); } invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); Field mDragger = null;//mRightDragger or mLeftDragger based on Drawer Gravity try { mDragger = mDrawerLayout.getClass().getDeclaredField("mLeftDragger"); mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(mDrawerLayout); Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize"); mEdgeSize.setAccessible(true); int edge = mEdgeSize.getInt(draggerObj); mEdgeSize.setInt(draggerObj, edge * 3); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.executequery.datasource.ConnectionPoolImpl.java
private String nameForTransactionIsolationLevel(int isolationLevel) { for (Field field : Connection.class.getFields()) { String name = field.getName(); if (StringUtils.startsWith(name, "TRANSACTION_")) { try { if (isolationLevel == field.getInt(null)) { return name; }//from w w w . ja v a 2 s . c o m } catch (IllegalArgumentException | IllegalAccessException e) { } } } return String.valueOf(isolationLevel); }
From source file:com.netscape.cmstools.cli.MainCLI.java
public void convertCertStatusList(String list, Collection<Integer> statuses) throws Exception { if (list == null) return;/*from w w w . java 2s.c o m*/ Class<SSLCertificateApprovalCallback.ValidityStatus> clazz = SSLCertificateApprovalCallback.ValidityStatus.class; for (String status : list.split(",")) { try { Field field = clazz.getField(status); statuses.add(field.getInt(null)); } catch (NoSuchFieldException e) { throw new Exception("Invalid cert status \"" + status + "\".", e); } } }
From source file:uk.ac.horizon.ubihelper.service.Service.java
@Override public void onCreate() { // One-time set-up... Log.d(TAG, "onCreate()"); // TODO//from w w w . j a v a 2s . c o m super.onCreate(); // handler for requests mHandler = new Handler(); // create taskbar notification int icon = R.drawable.service_notification_icon; CharSequence tickerText = getText(R.string.notification_start_message); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = this; CharSequence contentTitle = getText(R.string.notification_title); CharSequence contentText = getText(R.string.notification_description); Intent notificationIntent = new Intent(this, MainPreferences.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); startForeground(RUNNING_ID, notification); channelManager = new ChannelManager(peerChannelFactory); // sensors if (!isEmulator()) { Log.d(TAG, "Create sensor channels..."); SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD); channelManager.addChannel(magnetic); SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER); channelManager.addChannel(accelerometer); SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE); channelManager.addChannel(gyro); SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT); channelManager.addChannel(light); SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE); channelManager.addChannel(pressure); SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY); channelManager.addChannel(proximity); SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE); channelManager.addChannel(temperature); try { Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE"); SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } try { Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY"); SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } // all sensors by full name SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); if (sensorManager != null) { List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor); channelManager.addChannel(sc); } } BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth"); channelManager.addChannel(btchannel); WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi"); channelManager.addChannel(wifichannel); GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this); channelManager.addChannel(gpsstatus); CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false); channelManager.addChannel(cellchannel); CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true); channelManager.addChannel(cellchannel2); CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength"); channelManager.addChannel(cellchannel3); } channelManager.addChannel(new TimeChannel(mHandler, "time")); List<String> locationProviders = LocationChannel.getAllProviders(this); for (String provider : locationProviders) { LocationChannel locchannel = new LocationChannel("location." + provider, this, provider); channelManager.addChannel(locchannel); } channelManager.addChannel(new MicChannel(mHandler, "mic")); Log.d(TAG, "Create http server..."); // http server httpPort = getPort(); httpListener = new HttpListener(this, httpPort); httpListener.start(); // peer communication peerManager = new PeerManager(this); int serverPort = peerManager.getServerPort(); channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers")); // wifi discovery wifiDiscoveryManager = new WifiDiscoveryManager(this); wifiDiscoverable = getWifiDiscoverable(); wifiDiscoveryManager.setServerPort(serverPort); wifiDiscoveryManager.setEnabled(wifiDiscoverable); bluetooth = BluetoothAdapter.getDefaultAdapter(); if (bluetooth != null) btmac = bluetooth.getAddress(); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (telephony != null) imei = telephony.getDeviceId(); logManager = new LogManager(this, channelManager); logManager.checkPreferences(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener); Log.d(TAG, "onCreate() finished"); }
From source file:de.thkwalter.et.ortskurve.OrtskurveModellTest.java
/** * Test fr die Methode {@link OrtskurveModell#getYPixelGrafik()}. * // ww w . j a v a 2 s .c om * @throws NoSuchFieldException * @throws SecurityException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testGetYPixelGrafik() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { // Die Anzahl der Pixel der Grafik in x-Richtung wird gelesen. Field yPixelGrafikFeld = OrtskurveModell.class.getDeclaredField("yPixelGrafik"); yPixelGrafikFeld.setAccessible(true); int yPixelGrafik = yPixelGrafikFeld.getInt(this.ortskurveModell); // Es wird berprft, ob die korrekte Anzahl der Pixel der Grafik in x-Richtung zurckgegeben wird. assertEquals(yPixelGrafik, this.ortskurveModell.getyPixelGrafik()); }
From source file:de.thkwalter.et.ortskurve.OrtskurveModellTest.java
/** * Test fr die Methode {@link OrtskurveModell#getXPixelGrafik()}. * //from ww w .j ava2 s .c o m * @throws NoSuchFieldException * @throws SecurityException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testGetXPixelGrafik() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { // Die Anzahl der Pixel der Grafik in x-Richtung wird gelesen. Field xPixelGrafikFeld = OrtskurveModell.class.getDeclaredField("xPixelGrafik"); xPixelGrafikFeld.setAccessible(true); int xPixelGrafik = xPixelGrafikFeld.getInt(this.ortskurveModell); // Es wird berprft, ob die korrekte Anzahl der Pixel der Grafik in x-Richtung zurckgegeben wird. assertEquals(xPixelGrafik, this.ortskurveModell.getxPixelGrafik()); }
From source file:com.ycdyng.onemulti.OneActivity.java
private int getFragmentIndex(Fragment fragment) { int fragmentIndex = 0; Class cls = fragment.getClass(); do {/*from w w w .j av a2s . c om*/ cls = cls.getSuperclass(); } while (!cls.getSimpleName().equals("Fragment")); try { Field field = cls.getDeclaredField("mIndex"); field.setAccessible(true); fragmentIndex = field.getInt(fragment); field.setAccessible(false); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return fragmentIndex; }
From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();/*from ww w . ja v a 2 s . c o m*/ if (args.containsKey(ARG_PROP)) { mProp = args.getParcelable(ARG_PROP); } else { mProp = mCallbacks.getProp(args.getInt(ARG_PROP_ID)).getProp(); } mFieldMap = new HashMap<String, Field>(); mViewMap = new HashMap<String, View>(); // Run through the fields of the prop and build groups and mappings for // the fields and views to allow the user to change the property values. Field[] fields = mProp.getClass().getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; PALEPropProperty annotation = field.getAnnotation(PALEPropProperty.class); if (annotation != null) { String fieldName = annotation.value(); View view; if (field.getType().isAssignableFrom(Integer.TYPE)) { try { view = newIntegerInputView(annotation.isSigned(), field.getInt(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(Float.TYPE)) { try { view = newFloatInputView(annotation.isSigned(), field.getFloat(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(String.class)) { try { view = newStringInputView((String) field.get(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else { continue; } mFieldMap.put(fieldName, field); mViewMap.put(fieldName, view); if (mGroupings.containsKey(annotation.group())) { mGroupings.get(annotation.group()).add(fieldName); } else { ArrayList<String> list = new ArrayList<String>(); list.add(fieldName); mGroupings.put(annotation.group(), list); } } } // Initialise grid layout. GridLayout grid = new GridLayout(getActivity()); grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS); grid.setColumnCount(2); grid.setUseDefaultMargins(true); // Run through groupings of properties adding the created views to the // GridLayout in sections. for (String group : mGroupings.keySet()) { if (!TextUtils.isEmpty(group) && !TextUtils.equals(group, "")) { TextView sectionBreak = (TextView) inflater.inflate(R.layout.prop_property_section_break, grid, false); sectionBreak.setText(group); GridLayout.LayoutParams sectionBreakParams = new GridLayout.LayoutParams(); sectionBreakParams.columnSpec = GridLayout.spec(0, 2); sectionBreak.setLayoutParams(sectionBreakParams); grid.addView(sectionBreak); } for (String name : mGroupings.get(group)) { TextView propertyLabel = (TextView) inflater.inflate(R.layout.prop_property_label, grid, false); GridLayout.LayoutParams params = new GridLayout.LayoutParams(); propertyLabel.setLayoutParams(params); propertyLabel.setText(getResources().getString(R.string.format_property_label, name)); View propertyView = mViewMap.get(name); params = new GridLayout.LayoutParams(); params.setGravity(Gravity.FILL_HORIZONTAL); propertyView.setLayoutParams(params); grid.addView(propertyLabel); grid.addView(propertyView); } } return grid; }
From source file:com.cloudera.sqoop.manager.OracleManager.java
/** * Get database type./*from w w w.j ava 2s. c om*/ * @param clazz oracle class representing sql types * @param fieldName field name * @return value of database type constant */ private int getDatabaseType(Class clazz, String fieldName) { // Need to use reflection to extract constant values because the database // specific java libraries are not accessible in this context. int value = -1; try { java.lang.reflect.Field field = clazz.getDeclaredField(fieldName); value = field.getInt(null); } catch (NoSuchFieldException ex) { LOG.error("Could not retrieve value for field " + fieldName, ex); } catch (IllegalAccessException ex) { LOG.error("Could not retrieve value for field " + fieldName, ex); } return value; }
From source file:net.dmulloy2.ultimatearena.types.ArenaConfig.java
@Override public Map<String, Object> serialize() { Map<String, Object> data = new LinkedHashMap<>(); for (Field field : ArenaConfig.class.getDeclaredFields()) { try {/* ww w. j a va 2 s. c o m*/ if (Modifier.isTransient(field.getModifiers())) continue; boolean accessible = field.isAccessible(); field.setAccessible(true); if (field.getType().equals(Integer.TYPE)) { if (field.getInt(this) != 0) data.put(field.getName(), field.getInt(this)); } else if (field.getType().equals(Long.TYPE)) { if (field.getLong(this) != 0) data.put(field.getName(), field.getLong(this)); } else if (field.getType().equals(Boolean.TYPE)) { if (field.getBoolean(this)) data.put(field.getName(), field.getBoolean(this)); } else if (field.getType().isAssignableFrom(Collection.class)) { if (!((Collection<?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(String.class)) { if ((String) field.get(this) != null) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(Map.class)) { if (!((Map<?, ?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else { if (field.get(this) != null) data.put(field.getName(), field.get(this)); } field.setAccessible(accessible); } catch (Throwable ex) { } } serializeCustomOptions(data); return data; }