List of usage examples for java.lang.reflect Field setBoolean
@CallerSensitive @ForceInline public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException
From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java
/*** * ???????// ww w.j a v a 2 s . 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:org.dcm4che2.tool.dcm2dcm.Dcm2Dcm.java
/** * Set the monochrome flag on a DicomImageReader *///from www. ja va 2s . c o m private void setMonochrome(DicomImageReader reader, boolean mono) throws NoSuchFieldException, IllegalAccessException { Class<?> clazz = reader.getClass(); java.lang.reflect.Field monochrome = clazz.getSuperclass().getDeclaredField("monochrome"); monochrome.setAccessible(true); monochrome.setBoolean(reader, mono); }
From source file:com.baidu.api.client.core.VersionService.java
private void setField(Field field, String value) throws Exception { field.setAccessible(true);/*from ww w .j a v a2 s.co m*/ Class<?> cls = field.getType(); if (cls.equals(int.class)) { field.setInt(this, Integer.parseInt(value)); } else if (cls.equals(long.class)) { field.setLong(this, Long.parseLong(value)); } else if (cls.equals(boolean.class)) { field.setBoolean(this, Boolean.parseBoolean(value)); } else if (cls.equals(Integer.class)) { field.set(this, Integer.parseInt(value)); } else if (cls.equals(Long.class)) { field.set(this, Long.parseLong(value)); } else if (cls.equals(Boolean.class)) { field.set(this, Boolean.parseBoolean(value)); } else { field.set(this, value); } }
From source file:com.semaphore.sm.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean darktheme = prefs.getBoolean("darktheme", false); if (darktheme) setTheme(android.R.style.Theme_Holo); super.onCreate(savedInstanceState); setContentView(R.layout.main);/* w w w . j a va 2 s.com*/ // setup action bar for tabs 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 } if ("mako".equals(android.os.Build.DEVICE)) Device = SemaDevices.Mako; else Device = SemaDevices.I9000; if (Device == SemaDevices.Mako) sp = new SemaN4Properties(); else sp = new SemaI9000Properties(); checkSU_BB(); unpackScripts(); checkFirstRun(); mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), this); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); PagerTabStrip pagerTitleStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip); pagerTitleStrip.setDrawFullUnderline(true); pagerTitleStrip.setTabIndicatorColor(0x33b5e5); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle("Semaphore Manager"); actionBar.setSubtitle(SemaphoreVer); updateSummaries(); }
From source file:com.klinker.android.twitter.ui.search.SearchPager.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit); try {/*from www .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 ex) { // Ignore } context = this; sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); settings = AppSettings.getInstance(this); try { searchQuery = getIntent().getStringExtra(SearchManager.QUERY); } catch (Exception e) { searchQuery = ""; } if (searchQuery == null) { searchQuery = ""; } handleIntent(getIntent()); if (Build.VERSION.SDK_INT > 18 && settings.uiExtras && (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE || getResources().getBoolean(R.bool.isTablet))) { translucent = true; getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); try { int immersive = android.provider.Settings.System.getInt(getContentResolver(), "immersive_mode"); if (immersive == 1) { translucent = false; } } catch (Exception e) { } } else { translucent = false; } Utils.setUpTheme(context, settings); setContentView(R.layout.search_pager); actionBar = getActionBar(); actionBar.setTitle(getResources().getString(R.string.search)); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); View statusBar = findViewById(R.id.activity_status_bar); mViewPager = (ViewPager) findViewById(R.id.pager); if (translucent) { statusBar.setVisibility(View.VISIBLE); int statusBarHeight = Utils.getStatusBarHeight(context); LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams(); statusParams.height = statusBarHeight; statusBar.setLayoutParams(statusParams); } else { mViewPager.setPadding(0, 0, 0, 0); } mSectionsPagerAdapter = new SearchPagerAdapter(getFragmentManager(), context, onlyStatus, onlyProfile, searchQuery, translucent); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(3); if (settings.addonTheme) { PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip); strip.setBackgroundColor(settings.pagerTitleInt); } mViewPager.setCurrentItem(1); Utils.setActionBar(context, true); if (onlyProfile) { mViewPager.setCurrentItem(2); } }
From source file:com.baidu.drapi.autosdk.core.CommonService.java
/** * Get current version./* ww w . jav a 2 s. co m*/ * @return */ // protected Version getCurrentVersion() { // return currentVersion; // } private void setField(Field field, String value) throws Exception { field.setAccessible(true); Class<?> cls = field.getType(); if (cls.equals(int.class)) { field.setInt(this, Integer.parseInt(value)); } else if (cls.equals(long.class)) { field.setLong(this, Long.parseLong(value)); } else if (cls.equals(boolean.class)) { field.setBoolean(this, Boolean.parseBoolean(value)); } else if (cls.equals(Integer.class)) { field.set(this, Integer.parseInt(value)); } else if (cls.equals(Long.class)) { field.set(this, Long.parseLong(value)); } else if (cls.equals(Boolean.class)) { field.set(this, Boolean.parseBoolean(value)); } else { field.set(this, value); } }
From source file:org.imdea.panel.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override//from www .j a va2 s . c om public void uncaughtException(Thread paramThread, Throwable paramThrowable) { Log.e("Alert", "UNCAUGHT EXCEPTION", paramThrowable); System.exit(1); } }); Thread.setDefaultUncaughtExceptionHandler(onRuntimeError); /* ParseObject testObject = new ParseObject("TestObject"); testObject.put("foo", "bar"); testObject.saveInBackground();*/ SP = PreferenceManager.getDefaultSharedPreferences(this); //Abrimos la base de datos 'DBUsuarios' en modo escritura DBHelper msg_database = new DBHelper(this, "messages.db", null, 1); Global.db = msg_database.getWritableDatabase(); enableBt(); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionbar = getActionBar(); 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 } checkUsername(); TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); fm = getSupportFragmentManager(); viewPager.setAdapter(mAdapter); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionbar.addTab(actionbar.newTab().setText("General").setTabListener(this)); actionbar.addTab(actionbar.newTab().setText("Tags").setTabListener(this)); /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { public void onPageSelected(int position) { // on changing the page // make respected tab selected actionbar.setSelectedNavigationItem(position); } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageScrollStateChanged(int arg0) { } }); /* EXPERIMENTAL SERVICES */ //this.startService(new Intent(this, WifiService.class)); //this.startService(new Intent(this, BtWizService.class)); //this.startService(new Intent(this, MeshService.class)); this.startService(new Intent(this, commService.class)); //if (Global.mqtt) this.startService(new Intent(this, mqttService.class)); //else this.startService(new Intent(this, BtService.class)); //this.startService(new Intent(this, smoothService.class)); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } }
From source file:com.klinker.android.twitter.activities.search.SearchPager.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit); try {/*from www .j a va2 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 ex) { // Ignore } context = this; sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0); settings = AppSettings.getInstance(this); try { searchQuery = getIntent().getStringExtra(SearchManager.QUERY); } catch (Exception e) { searchQuery = ""; } if (searchQuery == null) { searchQuery = ""; } handleIntent(getIntent()); if (Build.VERSION.SDK_INT > 18 && settings.uiExtras && (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE || getResources().getBoolean(R.bool.isTablet))) { translucent = true; getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); try { int immersive = android.provider.Settings.System.getInt(getContentResolver(), "immersive_mode"); if (immersive == 1) { translucent = false; } } catch (Exception e) { } } else { translucent = false; } Utils.setUpTheme(context, settings); setContentView(R.layout.search_pager); actionBar = getActionBar(); actionBar.setTitle(getResources().getString(R.string.search)); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); View statusBar = findViewById(R.id.activity_status_bar); mViewPager = (ViewPager) findViewById(R.id.pager); if (translucent) { statusBar.setVisibility(View.VISIBLE); int statusBarHeight = Utils.getStatusBarHeight(context); LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams(); statusParams.height = statusBarHeight; statusBar.setLayoutParams(statusParams); } else { mViewPager.setPadding(0, 0, 0, 0); } mSectionsPagerAdapter = new SearchPagerAdapter(getFragmentManager(), context, onlyStatus, onlyProfile, searchQuery, translucent); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(3); if (settings.addonTheme) { PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip); strip.setBackgroundColor(settings.pagerTitleInt); } mViewPager.setCurrentItem(1); Utils.setActionBar(context, true); if (onlyProfile) { mViewPager.setCurrentItem(2); } }
From source file:com.example.android.wifidirect.WiFiDirectActivity.java
private void setOverflowShowingAlways() { try {//from www. j av a 2 s.com 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:org.lilyproject.runtime.LilyRuntime.java
public void stop() { if (state != LifeCycle.STARTED) { throw new LilyRTException( "Cannot stop the runtime, it is in state " + state + " instead of " + LifeCycle.STARTED); }//from ww w . j av a2 s.c o m // TODO temporarily disabled because FAM.stop() is slow // See JCI jira patch: https://issues.apache.org/jira/browse/JCI-57 (the newer one in commons-io has the same problem) // fam.stop(); // Added the following workaround: if (System.getSecurityManager() == null) { try { Field famRunningField = fam.getClass().getDeclaredField("running"); famRunningField.setAccessible(true); Field threadField = fam.getClass().getDeclaredField("thread"); threadField.setAccessible(true); Thread famThread = (Thread) threadField.get(fam); if (famThread != null) { famRunningField.setBoolean(fam, false); famThread.interrupt(); fam.stop(); } } catch (Exception e) { infolog.error("Error stopping FilesystemAlterationMonitor", e); } } else { infolog.warn( "Unable to stop the FilesystemAlterationMonitor using workaround since a security manager is installed."); } // In case starting the runtime failed, modules might be null if (modules != null) { infolog.info("Shutting down the modules."); List<Module> reversedModules = new ArrayList<Module>(this.modules); Collections.reverse(reversedModules); this.modules = null; this.javaServiceManager.stop(); for (Module module : reversedModules) { try { module.shutdown(); } catch (Throwable t) { infolog.error("Error shutting down module " + module.getDefinition().getId(), t); } } } settings.getConfManager().shutdown(); }