Example usage for android.content SharedPreferences getAll

List of usage examples for android.content SharedPreferences getAll

Introduction

In this page you can find the example usage for android.content SharedPreferences getAll.

Prototype

Map<String, ?> getAll();

Source Link

Document

Retrieve all values from the preferences.

Usage

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void LoadProfile2() {
    SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE2, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();//from   w  w w .  j a v a2s  .  c  om
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
    Api.applications = null;
    showOrLoadApplications();
    refreshHeader();
    toggleVPNbutton(getApplicationContext());
    toggleRoambutton(getApplicationContext());
    toggleLANbutton(getApplicationContext());
    toggleInputWifiButton(getApplicationContext());
    toggleUserSettings(getApplicationContext());
    if (Api.isEnabled(getApplicationContext())) {
        Api.applyIptablesRules(getApplicationContext(), true);
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.applyrules);
            item_onoff.setChecked(true);
        }
    } else {
        Api.saveRules(getApplicationContext());
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.saverules);
            item_onoff.setChecked(false);
        }
    }
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void LoadProfile3() {
    SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE3, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*from   w  w w.  j  a v  a2  s  . c o  m*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
    Api.applications = null;
    showOrLoadApplications();
    refreshHeader();
    toggleVPNbutton(getApplicationContext());
    toggleRoambutton(getApplicationContext());
    toggleLANbutton(getApplicationContext());
    toggleInputWifiButton(getApplicationContext());
    toggleUserSettings(getApplicationContext());
    if (Api.isEnabled(getApplicationContext())) {
        Api.applyIptablesRules(getApplicationContext(), true);
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.applyrules);
            item_onoff.setChecked(true);
        }
    } else {
        Api.saveRules(getApplicationContext());
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.saverules);
            item_onoff.setChecked(false);
        }
    }
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void LoadProfile4() {
    SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE4, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();//from w w w . j  a v a  2  s .  c  o  m
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
    Api.applications = null;
    showOrLoadApplications();
    refreshHeader();
    toggleVPNbutton(getApplicationContext());
    toggleRoambutton(getApplicationContext());
    toggleLANbutton(getApplicationContext());
    toggleInputWifiButton(getApplicationContext());
    toggleUserSettings(getApplicationContext());
    if (Api.isEnabled(getApplicationContext())) {
        Api.applyIptablesRules(getApplicationContext(), true);
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.applyrules);
            item_onoff.setChecked(true);
        }
    } else {
        Api.saveRules(getApplicationContext());
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.saverules);
            item_onoff.setChecked(false);
        }
    }
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void LoadProfile5() {
    SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE5, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*from  www  .ja v  a  2s  .  com*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
    Api.applications = null;
    showOrLoadApplications();
    refreshHeader();
    toggleVPNbutton(getApplicationContext());
    toggleRoambutton(getApplicationContext());
    toggleLANbutton(getApplicationContext());
    toggleInputWifiButton(getApplicationContext());
    toggleUserSettings(getApplicationContext());
    if (Api.isEnabled(getApplicationContext())) {
        Api.applyIptablesRules(getApplicationContext(), true);
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.applyrules);
            item_onoff.setChecked(true);
        }
    } else {
        Api.saveRules(getApplicationContext());
        if (abs_menu != null) {
            final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4);
            final MenuItem item_apply = abs_menu.findItem(R.id.applyrules);
            item_apply.setTitle(R.string.saverules);
            item_onoff.setChecked(false);
        }
    }
}

From source file:com.aware.Aware_Preferences.java

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

    mSensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

    //Start the Aware
    Intent startAware = new Intent(getApplicationContext(), Aware.class);
    startService(startAware);/*w w w .jav a 2  s .c o  m*/

    addPreferencesFromResource(R.xml.aware_preferences);
    setContentView(R.layout.aware_ui);

    navigationDrawer = (DrawerLayout) findViewById(R.id.aware_ui_main);
    navigationList = (ListView) findViewById(R.id.aware_navigation);
    navigationToggle = new ActionBarDrawerToggle(this, navigationDrawer, R.drawable.ic_drawer,
            R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (Build.VERSION.SDK_INT > 11) {
                getActionBar().setTitle(getTitle());
                invalidateOptionsMenu();
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (Build.VERSION.SDK_INT > 11) {
                getActionBar().setTitle(getTitle());
                invalidateOptionsMenu();
            }
        }
    };

    navigationDrawer.setDrawerListener(navigationToggle);

    String[] options = { "Stream", "Sensors", "Plugins", "Studies" };
    NavigationAdapter nav_adapter = new NavigationAdapter(getApplicationContext(), options);
    navigationList.setAdapter(nav_adapter);
    navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            LinearLayout item_container = (LinearLayout) view.findViewById(R.id.nav_container);
            item_container.setBackgroundColor(Color.DKGRAY);

            for (int i = 0; i < navigationList.getChildCount(); i++) {
                if (i != position) {
                    LinearLayout other = (LinearLayout) navigationList.getChildAt(i);
                    LinearLayout other_item = (LinearLayout) other.findViewById(R.id.nav_container);
                    other_item.setBackgroundColor(Color.TRANSPARENT);
                }
            }

            Bundle animations = ActivityOptions.makeCustomAnimation(Aware_Preferences.this,
                    R.anim.anim_slide_in_left, R.anim.anim_slide_out_left).toBundle();
            switch (position) {
            case 0: //Stream
                Intent stream_ui = new Intent(Aware_Preferences.this, Stream_UI.class);
                startActivity(stream_ui, animations);
                break;
            case 1: //Sensors
                Intent sensors_ui = new Intent(Aware_Preferences.this, Aware_Preferences.class);
                startActivity(sensors_ui, animations);
                break;
            case 2: //Plugins
                Intent plugin_manager = new Intent(Aware_Preferences.this, Plugins_Manager.class);
                startActivity(plugin_manager, animations);
                break;
            case 3: //Studies
                if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0) {
                    new Async_StudyData().execute(
                            Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
                } else {
                    Intent join_study = new Intent(Aware_Preferences.this, CameraStudy.class);
                    startActivityForResult(join_study, REQUEST_JOIN_STUDY, animations);
                }
                break;
            }

            navigationDrawer.closeDrawer(navigationList);
        }
    });

    if (getActionBar() != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
    if (prefs.getAll().isEmpty()
            && Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
        is_first_time = true;
        PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE,
                R.xml.aware_preferences, true);
        prefs.edit().commit(); //commit changes
    } else {
        PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE,
                R.xml.aware_preferences, false);
    }

    Map<String, ?> defaults = prefs.getAll();
    for (Map.Entry<String, ?> entry : defaults.entrySet()) {
        if (Aware.getSetting(getApplicationContext(), entry.getKey()).length() == 0) {
            Aware.setSetting(getApplicationContext(), entry.getKey(), entry.getValue());
        }
    }

    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
        UUID uuid = UUID.randomUUID();
        Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, uuid.toString());
    }
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void saveDefaultProfile() {
    SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*from   w  w  w  .  ja  va  2s  .c  o  m*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void saveProfile1() {
    SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE1, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*  ww w.j  a v  a 2 s  . co  m*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void saveProfile2() {
    SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE2, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*  w  w w . j a  v  a 2  s  .  c  o  m*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void saveProfile3() {
    SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE3, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();//w w  w  .  j a v  a2 s.  co m
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void saveProfile4() {
    SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE4, Context.MODE_PRIVATE);
    final Editor editRules = prefs.edit();
    editRules.clear();/*from w w  w . ja  va  2 s . c o  m*/
    for (Entry<String, ?> entry : prefs2.getAll().entrySet()) {
        Object rule = entry.getValue();
        String keys = entry.getKey();
        if (rule instanceof Boolean)
            editRules.putBoolean(keys, ((Boolean) rule).booleanValue());
        else if (rule instanceof Float)
            editRules.putFloat(keys, ((Float) rule).floatValue());
        else if (rule instanceof String)
            editRules.putString(keys, ((String) rule));
        else if (rule instanceof Long)
            editRules.putLong(keys, ((Long) rule).longValue());
        else if (rule instanceof Integer)
            editRules.putInt(keys, ((Integer) rule).intValue());
    }
    editRules.commit();
}