// Path: src/it/reyboz/bustorino/fragments/SettingsFragment.java
// public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
//     private static final String TAG = SettingsFragment.class.getName();
// 
//     private static final String DIALOG_FRAGMENT_TAG =
//             "androidx.preference.PreferenceFragment.DIALOG";
//     //private static final
//     Handler mHandler;
// 
//     @Override
//     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//         mHandler = new Handler();
//         return super.onCreateView(inflater, container, savedInstanceState);
// 
//     }
// 
//     @Override
//     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
//         //getPreferenceManager().setSharedPreferencesName(getString(R.string.mainSharedPreferences));
//         convertStringPrefToIntIfNeeded(getString(R.string.pref_key_num_recents), getContext());
// 
//         getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
//         setPreferencesFromResource(R.xml.preferences,rootKey);
//         /*EditTextPreference editPref = findPreference(getString(R.string.pref_key_num_recents));
//         editPref.setOnBindEditTextListener(editText -> {
//             editText.setInputType(InputType.TYPE_CLASS_NUMBER);
//             editText.setSelection(0,editText.getText().length());
//         });
//          */
// 
//         //ListPreference preference = findPreference(R.string.arrival_times)
// 
// 
//     }
// 
//     @Override
//     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//         Preference pref = findPreference(key);
//         Log.d(TAG,"Preference key "+key+" changed");
//         //sometimes this happens
//         if(getContext()==null) return;
//         /*
//         THIS CODE STAYS COMMENTED FOR FUTURE REFERENCES
//         if (key.equals(getString(R.string.pref_key_num_recents))){
//             //check that is it an int
// 
//             String value = sharedPreferences.getString(key,"");
//             boolean valid = value.length() != 0;
//             try{
//                 Integer intValue = Integer.parseInt(value);
//             } catch (NumberFormatException ex){
//                 valid = false;
//             }
//             if (!valid){
//                 Toast.makeText(getContext(), R.string.invalid_number, Toast.LENGTH_SHORT).show();
//                 if(pref instanceof EditTextPreference){
//                     EditTextPreference prefEdit = (EditTextPreference) pref;
//                     //Intent intent = prefEdit.getIntent();
//                     Log.d(TAG, "opening preference, dialog showing "+
//                             (getParentFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG)!=null) );
//                     //getPreferenceManager().showDialog(pref);
//                     //onDisplayPreferenceDialog(prefEdit);
//                     mHandler.postDelayed(new DelayedDisplay(prefEdit), 500);
//                 }
// 
//             }
//         }
//          */
// 
//         Log.d("BusTO Settings", "changed "+key+"\n "+sharedPreferences.getAll());
// 
//     }
// 
//     private void convertStringPrefToIntIfNeeded(String preferenceKey, Context con){
//         if (con == null) return;
//         SharedPreferences defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
//         try{
// 
//             Integer val = defaultSharedPref.getInt(preferenceKey, 0);
//         } catch (NumberFormatException | ClassCastException ex){
//             //convert the preference
//             //final String preferenceNumRecents = getString(R.string.pref_key_num_recents);
//             Log.d("Preference - BusTO", "Converting to integer the string preference "+preferenceKey);
//             String currentValue = defaultSharedPref.getString(preferenceKey, "10");
//             int newValue;
//             try{
//                 newValue = Integer.parseInt(currentValue);
//             } catch (NumberFormatException e){
//                 newValue = 10;
//             }
//             final SharedPreferences.Editor editor  = defaultSharedPref.edit();
//             editor.remove(preferenceKey);
//             editor.putInt(preferenceKey, newValue);
//             editor.apply();
//         }
//     }
// 
//     class DelayedDisplay implements Runnable{
//         private final WeakReference<DialogPreference> preferenceWeakReference;
// 
//         public DelayedDisplay(DialogPreference preference) {
//             this.preferenceWeakReference = new WeakReference<>(preference);
//         }
// 
//         @Override
//         public void run() {
//             if(preferenceWeakReference.get()==null)
//                 return;
// 
//             getPreferenceManager().showDialog(preferenceWeakReference.get());
//         }
//     }
// }


import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import it.reyboz.bustorino.fragments.SettingsFragment;
package it.reyboz.bustorino;


public class ActivitySettings extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        ActionBar ab = getSupportActionBar();
        if(ab!=null) {
            ab.setIcon(R.drawable.ic_launcher);
            ab.setDisplayHomeAsUpEnabled(true);
        } else {
            Log.e("SETTINGS_ACTIV","ACTION BAR IS NULL");
        }

        FragmentManager framan = getSupportFragmentManager();
        FragmentTransaction ft = framan.beginTransaction();
// Path: src/it/reyboz/bustorino/fragments/SettingsFragment.java
// public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
//     private static final String TAG = SettingsFragment.class.getName();
// 
//     private static final String DIALOG_FRAGMENT_TAG =
//             "androidx.preference.PreferenceFragment.DIALOG";
//     //private static final
//     Handler mHandler;
// 
//     @Override
//     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//         mHandler = new Handler();
//         return super.onCreateView(inflater, container, savedInstanceState);
// 
//     }
// 
//     @Override
//     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
//         //getPreferenceManager().setSharedPreferencesName(getString(R.string.mainSharedPreferences));
//         convertStringPrefToIntIfNeeded(getString(R.string.pref_key_num_recents), getContext());
// 
//         getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
//         setPreferencesFromResource(R.xml.preferences,rootKey);
//         /*EditTextPreference editPref = findPreference(getString(R.string.pref_key_num_recents));
//         editPref.setOnBindEditTextListener(editText -> {
//             editText.setInputType(InputType.TYPE_CLASS_NUMBER);
//             editText.setSelection(0,editText.getText().length());
//         });
//          */
// 
//         //ListPreference preference = findPreference(R.string.arrival_times)
// 
// 
//     }
// 
//     @Override
//     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//         Preference pref = findPreference(key);
//         Log.d(TAG,"Preference key "+key+" changed");
//         //sometimes this happens
//         if(getContext()==null) return;
//         /*
//         THIS CODE STAYS COMMENTED FOR FUTURE REFERENCES
//         if (key.equals(getString(R.string.pref_key_num_recents))){
//             //check that is it an int
// 
//             String value = sharedPreferences.getString(key,"");
//             boolean valid = value.length() != 0;
//             try{
//                 Integer intValue = Integer.parseInt(value);
//             } catch (NumberFormatException ex){
//                 valid = false;
//             }
//             if (!valid){
//                 Toast.makeText(getContext(), R.string.invalid_number, Toast.LENGTH_SHORT).show();
//                 if(pref instanceof EditTextPreference){
//                     EditTextPreference prefEdit = (EditTextPreference) pref;
//                     //Intent intent = prefEdit.getIntent();
//                     Log.d(TAG, "opening preference, dialog showing "+
//                             (getParentFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG)!=null) );
//                     //getPreferenceManager().showDialog(pref);
//                     //onDisplayPreferenceDialog(prefEdit);
//                     mHandler.postDelayed(new DelayedDisplay(prefEdit), 500);
//                 }
// 
//             }
//         }
//          */
// 
//         Log.d("BusTO Settings", "changed "+key+"\n "+sharedPreferences.getAll());
// 
//     }
// 
//     private void convertStringPrefToIntIfNeeded(String preferenceKey, Context con){
//         if (con == null) return;
//         SharedPreferences defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
//         try{
// 
//             Integer val = defaultSharedPref.getInt(preferenceKey, 0);
//         } catch (NumberFormatException | ClassCastException ex){
//             //convert the preference
//             //final String preferenceNumRecents = getString(R.string.pref_key_num_recents);
//             Log.d("Preference - BusTO", "Converting to integer the string preference "+preferenceKey);
//             String currentValue = defaultSharedPref.getString(preferenceKey, "10");
//             int newValue;
//             try{
//                 newValue = Integer.parseInt(currentValue);
//             } catch (NumberFormatException e){
//                 newValue = 10;
//             }
//             final SharedPreferences.Editor editor  = defaultSharedPref.edit();
//             editor.remove(preferenceKey);
//             editor.putInt(preferenceKey, newValue);
//             editor.apply();
//         }
//     }
// 
//     class DelayedDisplay implements Runnable{
//         private final WeakReference<DialogPreference> preferenceWeakReference;
// 
//         public DelayedDisplay(DialogPreference preference) {
//             this.preferenceWeakReference = new WeakReference<>(preference);
//         }
// 
//         @Override
//         public void run() {
//             if(preferenceWeakReference.get()==null)
//                 return;
// 
//             getPreferenceManager().showDialog(preferenceWeakReference.get());
//         }
//     }
// }


// Path: src/it/reyboz/bustorino/ActivitySettings.java
import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import it.reyboz.bustorino.fragments.SettingsFragment;

package it.reyboz.bustorino;


public class ActivitySettings extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        ActionBar ab = getSupportActionBar();
        if(ab!=null) {
            ab.setIcon(R.drawable.ic_launcher);
            ab.setDisplayHomeAsUpEnabled(true);
        } else {
            Log.e("SETTINGS_ACTIV","ACTION BAR IS NULL");
        }

        FragmentManager framan = getSupportFragmentManager();
        FragmentTransaction ft = framan.beginTransaction();
        ft.replace(R.id.setting_container,new SettingsFragment());