Android Open Source - joanne Settings Activity






From Project

Back to project page joanne.

License

The source code is released under:

GNU General Public License

If you think the Android project joanne 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.gmail.altakey.joanne.activity;
//  w  w w  .j  a v a  2s.  co m
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

import com.gmail.altakey.joanne.R;

import java.util.List;

public class SettingsActivity extends PreferenceActivity {
    private static final boolean ALWAYS_SIMPLE_PREFS = false;
    private static String sVersionName;

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        sVersionName = getVersionName();

        setupSimplePreferencesScreen();
    }

    private void setupSimplePreferencesScreen() {
        if (!isSimplePreferences(this)) {
            return;
        }

        addPreferencesFromResource(R.xml.pref_general);
        bindPreferenceSummaryToValue(findPreference("version"));
    }

    @Override
    public boolean onIsMultiPane() {
        return isXLargeTablet(this) && !isSimplePreferences(this);
    }

    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    private static boolean isXLargeTablet(Context context) {
        try {
            return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
        } catch (NoSuchFieldError e) {
            return false;
        }
    }

    private static boolean isSimplePreferences(Context context) {
        return ALWAYS_SIMPLE_PREFS
                || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                || !isXLargeTablet(context);
    }

    @Override
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public void onBuildHeaders(List<Header> target) {
        if (!isSimplePreferences(this)) {
            loadHeadersFromResource(R.xml.pref_headers, target);
        }
    }

    private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            String stringValue = value.toString();

            if (preference.getKey().equals("version")) {
                preference.setSummary(sVersionName);
            } else {
                preference.setSummary(stringValue);
            }
            return true;
        }
    };

    private String getVersionName() {
        try {
            return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    private static void bindPreferenceSummaryToValue(Preference preference) {
        preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static class GeneralPreferenceFragment extends PreferenceFragment {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.pref_general);
            bindPreferenceSummaryToValue(findPreference("version"));
        }
    }
}




Java Source Code List

com.gmail.altakey.joanne.activity.MainActivity.java
com.gmail.altakey.joanne.activity.SettingsActivity.java
com.gmail.altakey.joanne.fragment.ProcessingDialog.java
com.gmail.altakey.joanne.fragment.WelcomeFragment.java
com.gmail.altakey.joanne.hack.ToastAnimationCanceler.java
com.gmail.altakey.joanne.service.TweetBroadcastService.java
com.gmail.altakey.joanne.service.TwitterAuthService.java
com.gmail.altakey.joanne.util.IdListCoder.java
com.gmail.altakey.joanne.util.UserRelation.java
com.gmail.altakey.joanne.view.OutlinedTextView.java
com.gmail.altakey.joanne.view.RadioProfile.java
com.gmail.altakey.joanne.view.Radio.java
com.gmail.altakey.joanne.view.TweetDisplayBuilder.java
com.gmail.altakey.joanne.view.TweetView.java