Android Open Source - pokedex Settings Activity






From Project

Back to project page pokedex.

License

The source code is released under:

MIT License

If you think the Android project pokedex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andrescanales.pokedex;
/*ww w. ja  v a  2s . co  m*/
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

/**
 * Created by andrescanales on 10/28/14.
 */
public class SettingsActivity extends PreferenceActivity
        implements Preference.OnPreferenceChangeListener {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // We add the preferences created on xml file under xml directory
        addPreferencesFromResource(R.xml.general_preferences);

        // For all preferences, attach an OnPreferenceChangeListener so the UI summary can be
        // updated when the preference changes.
        bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_rotation_key)));
    }

    private void bindPreferenceSummaryToValue(Preference preference) {
        // Set the listener to watch for value changes.
        preference.setOnPreferenceChangeListener(this);

        // Trigger the listener immediately with the preference's current value.
        onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    }

    @Override
    public void onResume() {
        // Always call the superclass method first
        super.onResume();

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        String unitType = sharedPrefs.getString(
                getString(R.string.pref_rotation_key),
                getString(R.string.pref_rotation_label_default));

        if (unitType.equals(getString(R.string.pref_rotation_label_landscape))) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            //Log.i("MainActivity", "MyClass.getView()  Entering to Landscape");
        }
        else if (unitType.equals(getString(R.string.pref_rotation_label_portrait))) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            // Log.i("MainActivity", "MyClass.getView()  Entering to Portrait");
        }
        else {
        }

    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object value){
        String stringValue = value.toString();

        if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list (since they have separate labels/values).
            ListPreference listPreference = (ListPreference) preference;
            int prefIndex = listPreference.findIndexOfValue(stringValue);

            if (prefIndex >= 0) {
                preference.setSummary(listPreference.getEntries()[prefIndex]);
            }
        } else {
            // For other preferences, set the summary to the value's simple string representation.
            preference.setSummary(stringValue);
        }
        return true;
    }
}




Java Source Code List

com.andrescanales.pokedex.ApplicationTest.java
com.andrescanales.pokedex.GsonRequest.java
com.andrescanales.pokedex.MainActivity.java
com.andrescanales.pokedex.PokedexApplication.java
com.andrescanales.pokedex.PokemonAdapter.java
com.andrescanales.pokedex.PokemonDetailFragment.java
com.andrescanales.pokedex.PokemonDetail.java
com.andrescanales.pokedex.PokemonListApiTask.java
com.andrescanales.pokedex.PokemonListFragment.java
com.andrescanales.pokedex.Pokemon.java
com.andrescanales.pokedex.SettingsActivity.java