Advertisement
wetalkas

Untitled

Jul 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. public class SettingsFragment extends PreferenceFragment {
  2.  
  3.  
  4. public SettingsFragment() {
  5. // Required empty public constructor
  6. }
  7.  
  8. @Override
  9. public void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. addPreferencesFromResource(R.xml.preferences);
  12.  
  13. }/*
  14.  
  15. @Override
  16. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  17. Bundle savedInstanceState) {
  18. // Inflate the layout for this fragment
  19. return inflater.inflate(R.layout.fragment_settings, container, false);
  20. }*/
  21.  
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. public class PreferenceManagerHelper {
  29.  
  30. public static final String PREF_AUTH_SKIP = "pref_auth_skip";
  31.  
  32. public static final String PREF_CONTENT_UPDATE = "pref_content_update";
  33. public static final String PREF_CONTENT_UPDATE_ON_OPEN = "pref_content_update_on_open";
  34. public static final String PREF_CONTENT_UPDATE_IF_EMPTY = "pref_content_update_if_empty";
  35. public static final String PREF_CONTENT_UPDATE_NEVER = "pref_content_update_never";
  36.  
  37. public static final String PREF_PUSH_NOTIFICATION_ADMIN = "pref_push_notification_admin";
  38. public static final String PREF_PUSH_NOTIFICATION_MEMBERS = "pref_push_notification_members";
  39. public static final String PREF_PUSH_NOTIFICATION_COMMENT_REPLIES = "pref_push_notification_comment_replies";
  40.  
  41.  
  42. private Context mContext;
  43. private SharedPreferences mSharedPref;
  44.  
  45. private static PreferenceManagerHelper ourInstance = new PreferenceManagerHelper();
  46.  
  47. public static PreferenceManagerHelper getInstance() {
  48. return ourInstance;
  49. }
  50.  
  51. public void init(Context context) {
  52. this.mContext = context;
  53. mSharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
  54.  
  55. }
  56.  
  57. private PreferenceManagerHelper() {
  58.  
  59. }
  60.  
  61.  
  62. public boolean getPrefAuthSkip() {
  63. return mSharedPref.getBoolean(PREF_AUTH_SKIP, false);
  64. }
  65.  
  66. public String getPrefContentUpdate() {
  67. return mSharedPref.getString(PREF_CONTENT_UPDATE, PREF_CONTENT_UPDATE_ON_OPEN);
  68. }
  69.  
  70. public boolean isPrefContentUpdateOnOpen() {
  71. return getPrefContentUpdate().equals(PREF_CONTENT_UPDATE_ON_OPEN);
  72. }
  73.  
  74. public boolean isPrefContentUpdateIfEmpty() {
  75. return getPrefContentUpdate().equals(PREF_CONTENT_UPDATE_IF_EMPTY);
  76. }
  77.  
  78. public boolean isPrefContentUpdateNever() {
  79. return getPrefContentUpdate().equals(PREF_CONTENT_UPDATE_NEVER);
  80. }
  81.  
  82. public boolean getPushNotificationAdmin() {
  83. return mSharedPref.getBoolean(PREF_PUSH_NOTIFICATION_ADMIN, true);
  84. }
  85.  
  86. public boolean getPushNotificationMembers() {
  87. return mSharedPref.getBoolean(PREF_PUSH_NOTIFICATION_MEMBERS, false);
  88. }
  89.  
  90. public boolean getPushNotificationCommentReplies() {
  91. return mSharedPref.getBoolean(PREF_PUSH_NOTIFICATION_COMMENT_REPLIES, true);
  92. }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. public class SettingsActivity extends BaseFragmentActivity {
  103.  
  104. @Override
  105. protected void onCreate(Bundle savedInstanceState) {
  106. super.onCreate(savedInstanceState);
  107.  
  108. setContentView(R.layout.activity_settings);
  109. getFragmentManager().beginTransaction()
  110. .replace(R.id.container_layout, new SettingsFragment())
  111. .commit();
  112.  
  113. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  114.  
  115. toolbar.setTitle("Настройки");
  116. setSupportActionBar(toolbar);
  117.  
  118. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  119.  
  120. toolbar.setTitle("Настройки");
  121. }
  122.  
  123. @Override
  124. protected int getMainContentLayout() {
  125. return R.layout.activity_settings;
  126. }
  127.  
  128. @Override
  129. public void onFragmentChanged(BaseFragment currentFragment) {
  130.  
  131. }
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. <?xml version="1.0" encoding="utf-8"?>
  139. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  140. <PreferenceCategory
  141. android:title="@string/auth">
  142. <SwitchPreference
  143. android:defaultValue="false"
  144. android:key="pref_auth_skip"
  145. android:title="@string/auth_skip" />
  146. </PreferenceCategory>
  147. <PreferenceCategory android:title="@string/content">
  148. <ListPreference
  149. android:defaultValue="@string/pref_content_update_default"
  150. android:entries="@array/pref_content_update_entries"
  151. android:entryValues="@array/pref_content_update_entry_values"
  152. android:key="pref_content_update"
  153. android:title="@string/content_update" />
  154. </PreferenceCategory>
  155.  
  156. <PreferenceCategory android:title="@string/pref_push_notifications">
  157. <SwitchPreference
  158. android:defaultValue="true"
  159. android:key="pref_push_notification_admin"
  160. android:title="@string/pref_push_notification_admin" />
  161.  
  162. <SwitchPreference
  163. android:defaultValue="false"
  164. android:key="pref_push_notification_members"
  165. android:title="@string/pref_push_notification_members" />
  166.  
  167.  
  168. </PreferenceCategory>
  169. <SwitchPreference
  170. android:defaultValue="true"
  171. android:key="pref_push_notification_comment_replies"
  172. android:title="@string/pref_push_notification_comment_replies" />
  173.  
  174.  
  175. </PreferenceScreen>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement