Advertisement
mmayoub

MathApp, Settings.java

Sep 19th, 2021
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package com.example.mathapplication;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5.  
  6. public class Settings {
  7.     private static final String PREFERENCE_FILE_NAME = "com.example.mathapplication.Settings";
  8.     static int min = 10;
  9.     static int max = 10;
  10.     static boolean add = true;
  11.     static boolean sub = true;
  12.     static boolean mul = true;
  13.     static boolean div = true;
  14.  
  15.  
  16.     static void saveSettings(Context context) {
  17.         SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
  18.  
  19.         SharedPreferences.Editor editor = sharedPref.edit();
  20.         editor.putInt("RANGE_MIN", min);
  21.         editor.putInt("RANGE_MAX", max);
  22.         editor.putBoolean("OPERATOR_ADD", add);
  23.         editor.putBoolean("OPERATOR_SUB", sub);
  24.         editor.putBoolean("OPERATOR_MULL", mul);
  25.         editor.putBoolean("OPERATOR_DIV", div);
  26.         editor.apply();
  27.     }
  28.  
  29.     static void loadSettings(Context context) {
  30.         SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
  31.         min = sharedPref.getInt("RANGE_MIN", min);
  32.         max = sharedPref.getInt("RANGE_MAX", max);
  33.         add = sharedPref.getBoolean("OPERATOR_ADD", add);
  34.         sub = sharedPref.getBoolean("OPERATOR_SUB", sub);
  35.         mul = sharedPref.getBoolean("OPERATOR_MULL", mul);
  36.         div = sharedPref.getBoolean("OPERATOR_DIV", div);
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement