Android Configuration - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Configuration class.

This code example shows how to use the following methods:
    private Configuration configuration;
    private ShadowConfiguration shConfiguration;
 
    @Before 
    public void setUp() throws Exception { 
        configuration = new Configuration();
        shConfiguration = Robolectric.shadowOf( configuration );
    } 
 
    @Test 
    public void testSetToDefaults() throws Exception { 
        configuration.setToDefaults();
        assertThat(configuration.screenLayout).isEqualTo(Configuration.SCREENLAYOUT_LONG_NO | Configuration.SCREENLAYOUT_SIZE_NORMAL);
    } 
     
    @Test 
    public void testSetLocale() { 
    	shConfiguration.setLocale( Locale.US );
        assertThat(configuration.locale).isEqualTo(Locale.US);
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:updateConfiguration
     * Sets locale 
     * @param locale 
     */ 
    private void setLocale(Locale locale) {
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        getContext().getResources().updateConfiguration(config, metrics);
    } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:updateConfiguration
     * Sets locale 
     * @param locale 
     */ 
    private void setLocale(Locale locale) {
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        getContext().getResources().updateConfiguration(config, metrics);
    } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    @Test 
    public void testGetAndSetConfiguration_SameInstance() throws Exception { 
        Activity activity = new Activity();
        Resources resources = activity.getResources();
        assertSame(resources.getConfiguration(), resources.getConfiguration());
        Configuration diffConfig = new Configuration();
        shadowOf(resources).setConfiguration(diffConfig);
        assertSame(diffConfig, resources.getConfiguration());
    } 
 
    @Test(expected = Resources.NotFoundException.class) 
    public void testGetDrawableNullRClass() throws Exception { 
        ResourceLoader resourceLoader = new EmptyResourceLoader();
        resources = new Resources(null, null, null);
        ShadowResources.bind(resources, resourceLoader);
 
        assertThat(resources.getDrawable(-12345)).isInstanceOf(BitmapDrawable.class);
    } 
 
    /** 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    } 
 
    private void setLocale(String code) {
        Locale locale = new Locale(code);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
    } 
 
    private void assertResource(int resId, boolean ewo, boolean ew) throws Throwable {
        boolean expected = mWithOverlay ? ew : ewo;
        boolean actual = mResources.getBoolean(resId);
        assertEquals(expected, actual);
    } 
 
    private void assertResource(int resId, String ewo, String ew) throws Throwable {
        String expected = mWithOverlay ? ew : ewo;
        String actual = mResources.getString(resId);
        assertEquals(expected, actual);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compareTo
 
    @Implementation 
    public boolean equals(Configuration that) {
        if (that == null) return false;
        if (that == realConfiguration) return true;
        return realConfiguration.compareTo(that) == 0;
    } 
 
    @Implementation 
    public boolean equals(Object that) {
        try { 
            return equals((Configuration)that);
        } catch (ClassCastException e) {
        } 
        return false; 
    } 
 
    @Implementation 
    public int hashCode() { 
        int result = 17;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:updateFrom
class InterestingConfigChanges { 
    final Configuration mLastConfiguration = new Configuration();
    int mLastDensity;
 
    boolean applyNewConfig(Resources res) {
        int configChanges = mLastConfiguration.updateFrom(res.getConfiguration());
        boolean densityChanged = mLastDensity != res.getDisplayMetrics().densityDpi;
        if (densityChanged || (configChanges&(ActivityInfo.CONFIG_LOCALE
                |ActivityInfo.CONFIG_UI_MODE|ActivityInfo.CONFIG_SCREEN_LAYOUT)) != 0) {
            mLastDensity = res.getDisplayMetrics().densityDpi;
            return true; 
        } 
        return false; 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
    @SmallTest 
    public void testCHANGE_CONFIGURATION() { 
        try { 
            mAm.updateConfiguration(new Configuration());
            fail("IActivityManager.updateConfiguration did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
            // expected 
        } catch (RemoteException e) {
            fail("Unexpected remote exception");
        } 
    } 
 
    @SmallTest 
    public void testSET_DEBUG_APP() { 
        try { 
            mAm.setDebugApp(null, false, false);
            fail("IActivityManager.setDebugApp did not throw SecurityException as"
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:updateConfiguration
			useLanguage = context.getResources().getConfiguration().locale.getLanguage();
		} else { 
			Locale forcedLocale = new Locale(useLanguage); 
		    Locale.setDefault(forcedLocale);
		     
			Configuration config = new Configuration();
	        config.locale = forcedLocale;
 
	        context.getResources().updateConfiguration(config, context.getResources()
	                .getDisplayMetrics());
 
	        forcedLocale = null;
	        config = null;
		} 
		 
		if (!useLanguage.equals(prefs.getLastRunLanguage())) {
			prefs.setLastRunLanguage(useLanguage);
			DBInterface dbinterface = DBInterface.getInstance(context);
			SQLiteDatabase db = dbinterface.getDBHelper().getWritableDatabase();
			dbinterface.getDBHelper().loadDefaultData(db);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        } catch (RemoteException e) {
            fail("Unexpected remote exception");
        } 
         
        try { 
            mWm.updateOrientationFromAppTokens(new Configuration(), null);
            fail("IWindowManager.updateOrientationFromAppTokens did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
            // expected 
        } catch (RemoteException e) {
            fail("Unexpected remote exception");
        } 
         
        try { 
            mWm.setAppOrientation(null, 0);
            mWm.addWindowToken(null, 0);
            fail("IWindowManager.setAppOrientation did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android Configuration Questions & Answers:

Other Android Configuration Examples

7:				builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
8:				builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
9:				Configuration configuration = builder.build();
10:				
11:				TwitterFactory factory = new TwitterFactory(configuration);

Read More

138:	
139:		@Override
140:		public void onConfigurationChanged(Configuration newConfig) {
141:			super.onConfigurationChanged(newConfig);
142:			// Pass any configuration change to the drawer toggls

Read More

221:	
222:		@Override
223:		public void onConfigurationChanged(Configuration newConfig) {
224:			super.onConfigurationChanged(newConfig);
225:			// Pass any configuration change to the drawer toggls

Read More

See Code Examples for Android Configuration Methods: