package com.termux.app.fragments.settings; import android.content.Context; import android.os.Bundle; import androidx.preference.PreferenceDataStore; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import com.termux.R; import com.termux.shared.settings.preferences.TermuxAppSharedPreferences; public class TerminalIOPreferencesFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager.setPreferenceDataStore(TerminalIOPreferencesDataStore.getInstance(getContext())); setPreferencesFromResource(R.xml.terminal_io_preferences, rootKey); } } class TerminalIOPreferencesDataStore extends PreferenceDataStore { private final Context mContext; private final TermuxAppSharedPreferences mPreferences; private static TerminalIOPreferencesDataStore mInstance; private TerminalIOPreferencesDataStore(Context context) { mContext = context; mPreferences = new TermuxAppSharedPreferences(context); } public static synchronized TerminalIOPreferencesDataStore getInstance(Context context) { if (mInstance == null) { mInstance = new TerminalIOPreferencesDataStore(context.getApplicationContext()); } return mInstance; } @Override public void putBoolean(String key, boolean value) { if(key == null) return; switch (key) { case "soft_keyboard_enabled": mPreferences.setSoftKeyboardEnabled(value); break; default: break; } } @Override public boolean getBoolean(String key, boolean defValue) { switch (key) { case "soft_keyboard_enabled": return mPreferences.getSoftKeyboardEnabled(); default: return false; } } }