List of usage examples for java.lang.reflect Field setInt
@CallerSensitive @ForceInline public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException
From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtilityTest.java
private Log applyMockLog(final LockFileVerifier verifier) throws NoSuchFieldException, IllegalAccessException { Log log = mock(Log.class); if (verifier != null) { doAnswer(new Answer<Void>() { @Override/*from w w w.j a v a2 s . co m*/ public Void answer(InvocationOnMock invocation) throws Throwable { verifier.verify(); return null; } }).when(log).debug(expectedLockFileDebugString(verifier)); } Field field = VfsFileTransferUtility.class.getDeclaredField("log"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, log); return log; }
From source file:com.cubusmail.user.UserAccountDao.java
/** * @param preferencesJson/*from w w w .ja v a 2s. c o m*/ * @param preferences */ private void json2Preferences(String preferencesJson, Preferences preferences) { try { 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) { logger.error(e.getMessage(), e); } catch (NumberFormatException e) { logger.error(e.getMessage(), e); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); } catch (IllegalAccessException e) { logger.error(e.getMessage(), e); } }
From source file:org.wso2.carbon.identity.oauth.endpoint.util.EndpointUtilTest.java
private void setMockedLog(boolean isDebugEnabled) throws Exception { Constructor<EndpointUtil> constructor = EndpointUtil.class.getDeclaredConstructor(new Class[0]); constructor.setAccessible(true);// w w w . j av a 2 s .c o m Object claimUtilObject = constructor.newInstance(new Object[0]); Field logField = claimUtilObject.getClass().getDeclaredField("log"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(logField, logField.getModifiers() & ~Modifier.FINAL); logField.setAccessible(true); logField.set(claimUtilObject, mockedLog); when(mockedLog.isDebugEnabled()).thenReturn(isDebugEnabled); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static void setProgressBarAnimationDuration(ProgressBar progressBar, int duration) { if (progressBar == null) { return;/* ww w .jav a 2 s .c o m*/ } try { Field mCursorDrawableRes = ProgressBar.class.getDeclaredField("mDuration"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.setInt(progressBar, duration); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static void clearCursorDrawable(EditText editText) { if (editText == null) { return;/*from w ww.j a v a2 s . co m*/ } try { Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.setInt(editText, 0); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java
private void enablePageCache(WebSettings settings, int size) { Class<? extends WebSettings> websettings = settings.getClass(); Field mPageCacheCapacity; try {/* w w w .j a v a2 s. c o m*/ mPageCacheCapacity = websettings.getDeclaredField("mPageCacheCapacity"); mPageCacheCapacity.setAccessible(true); mPageCacheCapacity.setInt(settings, size); } catch (Exception e) { LogUtils.e("enablePageCache failed."); } }
From source file:ti.modules.titanium.ui.widget.TiUIDrawerLayout.java
private void setDrawMargin(Integer width) { try {//from w w w . j a va 2 s . c o m Field mDragger = layout.getClass().getDeclaredField("mLeftDragger"); mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(layout); Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize"); mEdgeSize.setAccessible(true); mEdgeSize.setInt(draggerObj, width); } catch (NoSuchFieldException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } }
From source file:tv.acfun.video.HomeActivity.java
private void initDrawer() { try {//from w w w . ja v a2 s . c o m Field mDragger = mDrawer.getClass().getDeclaredField("mLeftDragger"); mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(mDrawer); Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize"); mEdgeSize.setAccessible(true); int edge = mEdgeSize.getInt(draggerObj); mEdgeSize.setInt(draggerObj, edge * 2); } catch (Exception e) { e.printStackTrace(); } }
From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java
/*** * ???????/*ww w .j a va2s. c o m*/ * int,boolean,String,Date?? * @param obj * @param attrs attributes */ private void setValues(Object obj, org.xml.sax.Attributes attrs) { for (int i = 0; i < attrs.getLength(); i++) { try { Field field = getField(obj.getClass(), attrs.getLocalName(i)); field.setAccessible(true); String attr_value = attrs.getValue(i); if (field.getType() == boolean.class) { field.setBoolean(obj, Boolean.valueOf(attr_value)); } else if (field.getType() == int.class) { field.setInt(obj, Integer.parseInt(attr_value)); } else if (field.getType() == String.class) { field.set(obj, attr_value); } else if (field.getType() == Date.class) { String format = "yyyy-MM-dd'T'HH:mm:ss"; field.set(obj, StringUtil.toDate(attr_value, format)); } } catch (Exception ignored) { } } }
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) {/*from w w w.ja v a2 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(); } }