FileDocCategorySizeDatePackage
SpareParts.javaAPI DocAndroid 1.5 API12158Wed May 06 22:41:08 BST 2009com.android.spare_parts

SpareParts

public class SpareParts extends android.preference.PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceChangeListener

Fields Summary
private static final String
TAG
private static final String
BATTERY_HISTORY_PREF
private static final String
BATTERY_INFORMATION_PREF
private static final String
USAGE_STATISTICS_PREF
private static final String
WINDOW_ANIMATIONS_PREF
private static final String
TRANSITION_ANIMATIONS_PREF
private static final String
FANCY_IME_ANIMATIONS_PREF
private static final String
FANCY_ROTATION_ANIMATIONS_PREF
private static final String
HAPTIC_FEEDBACK_PREF
private static final String
FONT_SIZE_PREF
private static final String
END_BUTTON_PREF
private static final String
MAPS_COMPASS_PREF
private final android.content.res.Configuration
mCurConfig
private android.preference.ListPreference
mWindowAnimationsPref
private android.preference.ListPreference
mTransitionAnimationsPref
private android.preference.CheckBoxPreference
mFancyImeAnimationsPref
private android.preference.CheckBoxPreference
mFancyRotationAnimationsPref
private android.preference.CheckBoxPreference
mHapticFeedbackPref
private android.preference.ListPreference
mFontSizePref
private android.preference.ListPreference
mEndButtonPref
private android.preference.CheckBoxPreference
mShowMapsCompassPref
private android.view.IWindowManager
mWindowManager
Constructors Summary
Methods Summary
intfloatToIndex(float val, int resid)

        String[] indices = getResources().getStringArray(resid);
        float lastVal = Float.parseFloat(indices[0]);
        for (int i=1; i<indices.length; i++) {
            float thisVal = Float.parseFloat(indices[i]);
            if (val < (lastVal + (thisVal-lastVal)*.5f)) {
                return i-1;
            }
            lastVal = thisVal;
        }
        return indices.length-1;
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        addPreferencesFromResource(R.xml.spare_parts);

        PreferenceScreen prefSet = getPreferenceScreen();
        
        mWindowAnimationsPref = (ListPreference) prefSet.findPreference(WINDOW_ANIMATIONS_PREF);
        mWindowAnimationsPref.setOnPreferenceChangeListener(this);
        mTransitionAnimationsPref = (ListPreference) prefSet.findPreference(TRANSITION_ANIMATIONS_PREF);
        mTransitionAnimationsPref.setOnPreferenceChangeListener(this);
        mFancyImeAnimationsPref = (CheckBoxPreference) prefSet.findPreference(FANCY_IME_ANIMATIONS_PREF);
        mFancyRotationAnimationsPref = (CheckBoxPreference) prefSet.findPreference(FANCY_ROTATION_ANIMATIONS_PREF);
        mHapticFeedbackPref = (CheckBoxPreference) prefSet.findPreference(HAPTIC_FEEDBACK_PREF);
        mFontSizePref = (ListPreference) prefSet.findPreference(FONT_SIZE_PREF);
        mFontSizePref.setOnPreferenceChangeListener(this);
        mEndButtonPref = (ListPreference) prefSet.findPreference(END_BUTTON_PREF);
        mEndButtonPref.setOnPreferenceChangeListener(this);
        mShowMapsCompassPref = (CheckBoxPreference) prefSet.findPreference(MAPS_COMPASS_PREF);
        
        mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
        
        final PreferenceGroup parentPreference = getPreferenceScreen();
        updatePreferenceToSpecificActivityOrRemove(this, parentPreference,
                BATTERY_HISTORY_PREF, 0);
        updatePreferenceToSpecificActivityOrRemove(this, parentPreference,
                BATTERY_INFORMATION_PREF, 0);
        updatePreferenceToSpecificActivityOrRemove(this, parentPreference,
                USAGE_STATISTICS_PREF, 0);
        
        parentPreference.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    
public booleanonPreferenceChange(android.preference.Preference preference, java.lang.Object objValue)

        if (preference == mWindowAnimationsPref) {
            writeAnimationPreference(0, objValue);
        } else if (preference == mTransitionAnimationsPref) {
            writeAnimationPreference(1, objValue);
        } else if (preference == mFontSizePref) {
            writeFontSizePreference(objValue);
        } else if (preference == mEndButtonPref) {
            writeEndButtonPreference(objValue);
        }

        // always let the preference setting proceed.
        return true;
    
public voidonResume()

        super.onResume();
        readAnimationPreference(0, mWindowAnimationsPref);
        readAnimationPreference(1, mTransitionAnimationsPref);
        readFontSizePreference(mFontSizePref);
        readEndButtonPreference(mEndButtonPref);
        updateToggles();
    
public voidonSharedPreferenceChanged(android.content.SharedPreferences preferences, java.lang.String key)

        if (FANCY_IME_ANIMATIONS_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.FANCY_IME_ANIMATIONS,
                    mFancyImeAnimationsPref.isChecked() ? 1 : 0);
        } else if (FANCY_ROTATION_ANIMATIONS_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    "fancy_rotation_anim",
                    mFancyRotationAnimationsPref.isChecked() ? 1 : 0);
        } else if (HAPTIC_FEEDBACK_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.HAPTIC_FEEDBACK_ENABLED,
                    mHapticFeedbackPref.isChecked() ? 1 : 0);
        } else if (MAPS_COMPASS_PREF.equals(key)) {
            try {
                Context c = createPackageContext("com.google.android.apps.maps", 0);
                c.getSharedPreferences("extra-features", MODE_WORLD_WRITEABLE)
                    .edit()
                    .putBoolean("compass", mShowMapsCompassPref.isChecked())
                    .commit();
            } catch (NameNotFoundException e) {
                Log.w(TAG, "Failed setting maps compass");
                e.printStackTrace();
            }
        }
    
public voidreadAnimationPreference(int which, android.preference.ListPreference pref)

        try {
            float scale = mWindowManager.getAnimationScale(which);
            pref.setValueIndex(floatToIndex(scale,
                    R.array.entryvalues_animations));
        } catch (RemoteException e) {
        }
    
public voidreadEndButtonPreference(android.preference.ListPreference pref)

        try {
            pref.setValueIndex(Settings.System.getInt(getContentResolver(),
                    Settings.System.END_BUTTON_BEHAVIOR));
        } catch (SettingNotFoundException e) {
        }
    
public voidreadFontSizePreference(android.preference.ListPreference pref)

        try {
            mCurConfig.updateFrom(
                ActivityManagerNative.getDefault().getConfiguration());
        } catch (RemoteException e) {
        }
        pref.setValueIndex(floatToIndex(mCurConfig.fontScale,
                R.array.entryvalues_font_size));
    
public static booleanupdatePreferenceToSpecificActivityOrRemove(android.content.Context context, android.preference.PreferenceGroup parentPreferenceGroup, java.lang.String preferenceKey, int flags)


        
                  
        
        Preference preference = parentPreferenceGroup.findPreference(preferenceKey);
        if (preference == null) {
            return false;
        }
        
        Intent intent = preference.getIntent();
        if (intent != null) {
            // Find the activity that is in the system image
            PackageManager pm = context.getPackageManager();
            List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
            int listSize = list.size();
            for (int i = 0; i < listSize; i++) {
                ResolveInfo resolveInfo = list.get(i);
                if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
                        != 0) {
                    
                    // Replace the intent with this specific activity
                    preference.setIntent(new Intent().setClassName(
                            resolveInfo.activityInfo.packageName,
                            resolveInfo.activityInfo.name));
                    
                    return true;
                }
            }
        }

        // Did not find a matching activity, so remove the preference
        parentPreferenceGroup.removePreference(preference);
        
        return true;
    
private voidupdateToggles()

        try {
            mFancyImeAnimationsPref.setChecked(Settings.System.getInt(
                    getContentResolver(), 
                    Settings.System.FANCY_IME_ANIMATIONS, 0) != 0);
            mFancyRotationAnimationsPref.setChecked(Settings.System.getInt(
                    getContentResolver(), 
                    "fancy_rotation_anim", 0) != 0);
            mHapticFeedbackPref.setChecked(Settings.System.getInt(
                    getContentResolver(), 
                    Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0);
            Context c = createPackageContext("com.google.android.apps.maps", 0);
            mShowMapsCompassPref.setChecked(c.getSharedPreferences("extra-features", MODE_WORLD_READABLE)
                .getBoolean("compass", false));
        } catch (NameNotFoundException e) {
            Log.w(TAG, "Failed reading maps compass");
            e.printStackTrace();
        }
    
public voidwriteAnimationPreference(int which, java.lang.Object objValue)

        try {
            float val = Float.parseFloat(objValue.toString());
            mWindowManager.setAnimationScale(which, val);
        } catch (NumberFormatException e) {
        } catch (RemoteException e) {
        }
    
public voidwriteEndButtonPreference(java.lang.Object objValue)

        try {
            int val = Integer.parseInt(objValue.toString());
            Settings.System.putInt(getContentResolver(),
                    Settings.System.END_BUTTON_BEHAVIOR, val);
        } catch (NumberFormatException e) {
        }
    
public voidwriteFontSizePreference(java.lang.Object objValue)

        try {
            mCurConfig.fontScale = Float.parseFloat(objValue.toString());
            ActivityManagerNative.getDefault().updateConfiguration(mCurConfig);
        } catch (RemoteException e) {
        }