From 95ce533745746dd79f64a5beb54dbe7ac891ad8b Mon Sep 17 00:00:00 2001 From: xhinliang Date: Sat, 12 Mar 2016 08:39:11 +0800 Subject: [PATCH] Update MultiSelectPreference. --- app/src/main/AndroidManifest.xml | 5 +-- .../io/mdpreference/OriginalActivity.java | 17 ++++++++++ .../io/mdpreference/OriginalFragment.java | 17 ++++++++++ .../io/mdpreference/SettingsActivity.java | 13 +++++++ app/src/main/res/xml/preference_original.xml | 34 +++++++++++++++++++ .../MultiSelectListPreference.java | 4 +-- 6 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/xhinliang/github/io/mdpreference/OriginalActivity.java create mode 100644 app/src/main/java/xhinliang/github/io/mdpreference/OriginalFragment.java create mode 100644 app/src/main/res/xml/preference_original.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5d7fa25..85bf8b9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,14 +8,15 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - + + + diff --git a/app/src/main/java/xhinliang/github/io/mdpreference/OriginalActivity.java b/app/src/main/java/xhinliang/github/io/mdpreference/OriginalActivity.java new file mode 100644 index 0000000..c04ae1c --- /dev/null +++ b/app/src/main/java/xhinliang/github/io/mdpreference/OriginalActivity.java @@ -0,0 +1,17 @@ +package xhinliang.github.io.mdpreference; + + +import android.app.Fragment; + +/** + * Created by xhinliang on 16-3-11. + * original + */ +public class OriginalActivity extends SingleFragmentActivity { + + + @Override + protected Fragment createFragment() { + return new OriginalFragment(); + } +} diff --git a/app/src/main/java/xhinliang/github/io/mdpreference/OriginalFragment.java b/app/src/main/java/xhinliang/github/io/mdpreference/OriginalFragment.java new file mode 100644 index 0000000..1b56556 --- /dev/null +++ b/app/src/main/java/xhinliang/github/io/mdpreference/OriginalFragment.java @@ -0,0 +1,17 @@ +package xhinliang.github.io.mdpreference; + +import android.os.Bundle; +import android.preference.PreferenceFragment; + +/** + * Created by xhinliang on 16-3-11. + * original + */ +public class OriginalFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getPreferenceManager().setSharedPreferencesName(getString(R.string.app_name)); + addPreferencesFromResource(R.xml.preference_original); + } +} diff --git a/app/src/main/java/xhinliang/github/io/mdpreference/SettingsActivity.java b/app/src/main/java/xhinliang/github/io/mdpreference/SettingsActivity.java index 45d03ac..c749ac2 100644 --- a/app/src/main/java/xhinliang/github/io/mdpreference/SettingsActivity.java +++ b/app/src/main/java/xhinliang/github/io/mdpreference/SettingsActivity.java @@ -1,13 +1,26 @@ package xhinliang.github.io.mdpreference; import android.app.Fragment; +import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import java.util.Set; + +import io.github.xhinliang.mdpreference.MultiSelectListPreference; + public class SettingsActivity extends SingleFragmentActivity { @Override protected Fragment createFragment() { return new SettingsFragment(); } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + SharedPreferences preferences = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE); + preferences.getString("key_fff", ""); + + } } diff --git a/app/src/main/res/xml/preference_original.xml b/app/src/main/res/xml/preference_original.xml new file mode 100644 index 0000000..1169339 --- /dev/null +++ b/app/src/main/res/xml/preference_original.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/mdpreference/src/main/java/io/github/xhinliang/mdpreference/MultiSelectListPreference.java b/mdpreference/src/main/java/io/github/xhinliang/mdpreference/MultiSelectListPreference.java index d041018..1917458 100644 --- a/mdpreference/src/main/java/io/github/xhinliang/mdpreference/MultiSelectListPreference.java +++ b/mdpreference/src/main/java/io/github/xhinliang/mdpreference/MultiSelectListPreference.java @@ -111,7 +111,7 @@ private int getBit(int[] indexes) { return selected; } - private Set getSet(int bit) { + private static Set getSet(int bit) { Set set = new HashSet<>(); int temp = 1; for (int i = 0; i < 32; ++i) { @@ -123,7 +123,7 @@ private Set getSet(int bit) { return set; } - public Set getSetByBit(int bit) { + public static Set getSetByBit(int bit) { return getSet(bit); }