// Path: app/src/main/java/pw/thedrhax/util/Util.java
// public final class Util {
//     private Util() {}
// 
//     // Source: https://stackoverflow.com/a/26779342
//     public static int countLines(String input) {
//         LineNumberReader reader = new LineNumberReader(new StringReader(input));
//         try {
//             reader.skip(Long.MAX_VALUE);
//         } catch (IOException ignored) {}
//         return reader.getLineNumber();
//     }
// 
//     // TODO: Store Integers instead of Strings in SharedPreferences
//     public static int getIntPreference (Context context, String name, int def_value) {
//         final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
//         try {
//             return Integer.parseInt(settings.getString(name, Integer.valueOf(def_value).toString()));
//         } catch (NumberFormatException|ClassCastException ignored) {}
// 
//         try {
//             return settings.getInt(name, def_value);
//         } catch (ClassCastException ignored) {}
// 
//         return def_value;
//     }
// 
//     // Source: https://stackoverflow.com/a/34836992
//     public static String readAsset(Context context, String filename) throws IOException {
//         BufferedReader reader = new BufferedReader(
//                 new InputStreamReader(context.getAssets().open(filename), "UTF-8"));
//         StringBuilder sb = new StringBuilder();
//         String mLine = reader.readLine();
//         while (mLine != null) {
//             sb.append(mLine).append('\n');
//             mLine = reader.readLine();
//         }
//         reader.close();
//         return sb.toString();
//     }
// }


import com.edmodo.rangebar.RangeBar;
import pw.thedrhax.mosmetro.R;
import pw.thedrhax.util.Util;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

        ta.recycle();
    }

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        super.onPrepareDialogBuilder(builder);

        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
        final View view = View.inflate(getContext(), R.layout.rangebar_preference, null);
        final RangeBar rangebar = (RangeBar) view.findViewById(R.id.rangebar);

        rangebar.setTickCount((max - min) / step + 1);
        rangebar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
            private TextView rangetext = (TextView) view.findViewById(R.id.rangetext);

            @Override
            public void onIndexChangeListener(RangeBar rangeBar, int left, int right) {
                if (left < min || left > max) {
                    rangeBar.setLeft(min); return;
                }

                if (right < min || right > max) {
                    rangeBar.setRight(max); return;
                }

                rangetext.setText("" + (left + min) * step + " - " + (right + min) * step);
            }
        });

// Path: app/src/main/java/pw/thedrhax/util/Util.java
// public final class Util {
//     private Util() {}
// 
//     // Source: https://stackoverflow.com/a/26779342
//     public static int countLines(String input) {
//         LineNumberReader reader = new LineNumberReader(new StringReader(input));
//         try {
//             reader.skip(Long.MAX_VALUE);
//         } catch (IOException ignored) {}
//         return reader.getLineNumber();
//     }
// 
//     // TODO: Store Integers instead of Strings in SharedPreferences
//     public static int getIntPreference (Context context, String name, int def_value) {
//         final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
//         try {
//             return Integer.parseInt(settings.getString(name, Integer.valueOf(def_value).toString()));
//         } catch (NumberFormatException|ClassCastException ignored) {}
// 
//         try {
//             return settings.getInt(name, def_value);
//         } catch (ClassCastException ignored) {}
// 
//         return def_value;
//     }
// 
//     // Source: https://stackoverflow.com/a/34836992
//     public static String readAsset(Context context, String filename) throws IOException {
//         BufferedReader reader = new BufferedReader(
//                 new InputStreamReader(context.getAssets().open(filename), "UTF-8"));
//         StringBuilder sb = new StringBuilder();
//         String mLine = reader.readLine();
//         while (mLine != null) {
//             sb.append(mLine).append('\n');
//             mLine = reader.readLine();
//         }
//         reader.close();
//         return sb.toString();
//     }
// }


// Path: app/src/main/java/pw/thedrhax/mosmetro/preferences/RangeBarPreference.java
import com.edmodo.rangebar.RangeBar;
import pw.thedrhax.mosmetro.R;
import pw.thedrhax.util.Util;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;


        ta.recycle();
    }

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        super.onPrepareDialogBuilder(builder);

        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
        final View view = View.inflate(getContext(), R.layout.rangebar_preference, null);
        final RangeBar rangebar = (RangeBar) view.findViewById(R.id.rangebar);

        rangebar.setTickCount((max - min) / step + 1);
        rangebar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
            private TextView rangetext = (TextView) view.findViewById(R.id.rangetext);

            @Override
            public void onIndexChangeListener(RangeBar rangeBar, int left, int right) {
                if (left < min || left > max) {
                    rangeBar.setLeft(min); return;
                }

                if (right < min || right > max) {
                    rangeBar.setRight(max); return;
                }

                rangetext.setText("" + (left + min) * step + " - " + (right + min) * step);
            }
        });

        int current_min = Util.getIntPreference(getContext(), key_min, defaultMin);