Android Open Source - android-quiz-php Type List Preference






From Project

Back to project page android-quiz-php.

License

The source code is released under:

Copyright (c) 2014, Fabricio Bedeschi All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are me...

If you think the Android project android-quiz-php 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.quiz.php.ui;
/*from  ww  w.ja  v a2  s.  c  o m*/
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.quiz.php.R;

/**
 * Created by fabricio on 4/30/14.
 */
public class TypeListPreference extends ListPreference {

    private Context mContext;

    public TypeListPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
        setSummary(getFormattedSummary(prefs.getString(SettingsActivity.PREF_TYPE, "0")));

        setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference pref, Object value) {
                pref.setSummary(getFormattedSummary(value.toString()));
                return true;
            }
        });
    }

    private String getFormattedSummary(String type) {
        String[] arrayTypes = mContext.getResources().getStringArray(R.array.entries_type_preference);

        return arrayTypes[Integer.parseInt(type)];
    }

    // NOTE:
    // The framework forgot to call notifyChanged() in setValue() on previous versions of android.
    // This bug has been fixed in android-4.4_r0.7.
    // Commit: platform/frameworks/base/+/94c02a1a1a6d7e6900e5a459e9cc699b9510e5a2
    // Time: Tue Jul 23 14:43:37 2013 -0700
    //
    // However on previous versions, we have to workaround it by ourselves.
    @Override
    public void setValue(String value) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            super.setValue(value);
        } else {
            String oldValue = getValue();
            super.setValue(value);
            if (!TextUtils.equals(value, oldValue)) {
                notifyChanged();
            }
        }
    }
}




Java Source Code List

com.quiz.php.QuizApp.java
com.quiz.php.core.Alternative.java
com.quiz.php.core.Category.java
com.quiz.php.core.Question.java
com.quiz.php.core.Quiz.java
com.quiz.php.core.Util.java
com.quiz.php.persistence.DBHelper.java
com.quiz.php.ui.CodeTextView.java
com.quiz.php.ui.NumberPickerDialogPreference.java
com.quiz.php.ui.QuestionControlsFragment.java
com.quiz.php.ui.QuestionFragment.java
com.quiz.php.ui.QuestionPagerActivity.java
com.quiz.php.ui.QuizSummaryListActivity.java
com.quiz.php.ui.QuizSummaryListFragment.java
com.quiz.php.ui.ResultActivity.java
com.quiz.php.ui.ResultFragment.java
com.quiz.php.ui.SettingsActivity.java
com.quiz.php.ui.SingleFragmentActivity.java
com.quiz.php.ui.TimePickerDialogPreference.java
com.quiz.php.ui.TypeListPreference.java