Android Open Source - Thrift-box Settings Fragment






From Project

Back to project page Thrift-box.

License

The source code is released under:

GNU General Public License

If you think the Android project Thrift-box 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 ru.sash0k.thriftbox.fragments;
// w ww.j a va  2 s  . com
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v4.preference.PreferenceFragment;

import ru.sash0k.thriftbox.R;
import ru.sash0k.thriftbox.Utils;

/**
 * ??????????? ???????????
 * Created by sash0k on 20.06.14.
 */
public final class SettingsFragment extends PreferenceFragment
        implements SharedPreferences.OnSharedPreferenceChangeListener {
    public static final String TAG = "SettingsFragment";

    /**
     * ????? ?????????
     */
    public static final String PREF_WIDGET_TRANSPARENCY_KEY = "pref_widget_transparency_key";
    public static final String PREF_WIDGET_TEXT_COLOR_KEY = "pref_widget_text_color_key";
    public static final String PREF_VERSION = "version";
    public static final String PREF_DEVELOPER = "developer";


    public static SettingsFragment newInstance() {
        SettingsFragment f = new SettingsFragment();
        //Bundle arguments = new Bundle();
        //arguments.putBoolean(TAG, widgetMode);
        //f.setArguments(arguments);
        return f;
    }
    // ============================================================================

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        // ?????????? ?? ????????? ?????????
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        prefs.registerOnSharedPreferenceChangeListener(this);

        // ????????? ????? ??????? ???????
        findPreference(PREF_WIDGET_TEXT_COLOR_KEY).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final Context context = SettingsFragment.this.getActivity();
                if (context != null) Utils.updateWidgets(context);
                return true;
            }
        });

        // ???????? ???????????
        String version;
        final Context c = getActivity();
        try {
            version = c.getString(R.string.version) + " " +
                    c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName +
                    " " + c.getString(R.string.license_info);
        } catch (PackageManager.NameNotFoundException e) {
            version = "";
        }
        findPreference(PREF_VERSION).setSummary(version);

        // ?????? ??????????? ????????????
        findPreference(PREF_DEVELOPER).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri
                        .parse(c.getString(R.string.url_other_apps)));
                startActivity(intent);
                return true;
            }
        });
    }
    // ============================================================================

    @Override
    public void onActivityCreated(Bundle state) {
        super.onActivityCreated(state);
        getListValues(PREF_WIDGET_TRANSPARENCY_KEY,
                R.array.widget_transparency_title, R.array.widget_transparency_value);
    }
    // ============================================================================

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String tag) {
        if (PREF_WIDGET_TRANSPARENCY_KEY.equals(tag)) {
            setPrefenceTitle(tag);
            final Context context = SettingsFragment.this.getActivity();
            if (context != null) Utils.updateWidgets(context);
        }
    }
    // ============================================================================

    /**
     * ?????????? ????????? ????????
     */
    private void setPrefenceTitle(String tag) {
        final Preference preference = findPreference(tag);
        if (preference instanceof ListPreference) {
            if (((ListPreference) preference).getEntry() != null) {
                final CharSequence title = ((ListPreference) preference).getEntry();
                preference.setSummary(title);
            }

        } else if (preference instanceof EditTextPreference) {
            preference.setTitle(((EditTextPreference) preference).getText());
        }
    }
    // ============================================================================

    /**
     * ?????????? ?????????
     */
    private void getListValues(String tag, int titlesId, int valuesId) {
        ListPreference listprefence = (ListPreference) findPreference(tag);
        if (listprefence != null) {
            listprefence.setEntries(titlesId);
            listprefence.setEntryValues(valuesId);
        }
        setPrefenceTitle(tag);
    }
    // ============================================================================

}




Java Source Code List

android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
android.widget_fixed.CursorFilter.java
android.widget_fixed.CursorTreeAdapter.java
com.github.mikephil.charting.charts.Chart.java
com.github.mikephil.charting.charts.PieChart.java
com.github.mikephil.charting.charts.PieRadarChartBase.java
com.github.mikephil.charting.data.ChartData.java
com.github.mikephil.charting.data.DataSet.java
com.github.mikephil.charting.data.Entry.java
com.github.mikephil.charting.data.PieDataSet.java
com.github.mikephil.charting.data.PieData.java
com.github.mikephil.charting.data.filter.Approximator.java
com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException.java
com.github.mikephil.charting.interfaces.ChartInterface.java
com.github.mikephil.charting.interfaces.OnChartGestureListener.java
com.github.mikephil.charting.interfaces.OnChartValueSelectedListener.java
com.github.mikephil.charting.interfaces.OnDrawLineChartTouchListener.java
com.github.mikephil.charting.interfaces.OnDrawListener.java
com.github.mikephil.charting.listener.PieRadarChartTouchListener.java
com.github.mikephil.charting.matrix.Vector3.java
com.github.mikephil.charting.renderer.Transformer.java
com.github.mikephil.charting.utils.ColorFormatter.java
com.github.mikephil.charting.utils.ColorTemplate.java
com.github.mikephil.charting.utils.Highlight.java
com.github.mikephil.charting.utils.LabelBase.java
com.github.mikephil.charting.utils.LargeValueFormatter.java
com.github.mikephil.charting.utils.Legend.java
com.github.mikephil.charting.utils.LimitLine.java
com.github.mikephil.charting.utils.MarkerView.java
com.github.mikephil.charting.utils.PointD.java
com.github.mikephil.charting.utils.SelInfo.java
com.github.mikephil.charting.utils.Utils.java
com.github.mikephil.charting.utils.ValueFormatter.java
com.github.mikephil.charting.utils.XLabels.java
com.github.mikephil.charting.utils.YLabels.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java
ru.sash0k.thriftbox.AdapterExpenses.java
ru.sash0k.thriftbox.MainActivity.java
ru.sash0k.thriftbox.TypefaceSpan2.java
ru.sash0k.thriftbox.Utils.java
ru.sash0k.thriftbox.Widget.java
ru.sash0k.thriftbox.categories.Categories.java
ru.sash0k.thriftbox.categories.InterceptingHorizontalScrollView.java
ru.sash0k.thriftbox.database.DBProvider.java
ru.sash0k.thriftbox.database.DB.java
ru.sash0k.thriftbox.fragments.CommentDialog.java
ru.sash0k.thriftbox.fragments.DeleteConfirmDialog.java
ru.sash0k.thriftbox.fragments.ExpandableListFragment.java
ru.sash0k.thriftbox.fragments.ExpensesFragment.java
ru.sash0k.thriftbox.fragments.InputFragment.java
ru.sash0k.thriftbox.fragments.PieChartFragment.java
ru.sash0k.thriftbox.fragments.SettingsFragment.java