From 534824c1c91dee4d8f8019018c6ba20bb2f0d5b2 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 13 Oct 2014 15:39:41 +0200 Subject: [PATCH] Can't use that --- .../mysqlbrowser/NumberPickerDialog.java | 108 ------------------ .../mysqlbrowser/SettingsFragment.java | 44 ++++--- app/src/main/res/xml/settings.xml | 5 +- 3 files changed, 23 insertions(+), 134 deletions(-) delete mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/NumberPickerDialog.java diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/NumberPickerDialog.java b/app/src/main/java/info/nerull7/mysqlbrowser/NumberPickerDialog.java deleted file mode 100644 index c4778df..0000000 --- a/app/src/main/java/info/nerull7/mysqlbrowser/NumberPickerDialog.java +++ /dev/null @@ -1,108 +0,0 @@ -package info.nerull7.mysqlbrowser; - -/** - * Created by nerull7 on 18.07.14. - */ - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.NumberPicker; - -/** - * A dialog that prompts the user for the message deletion limits. - */ -public class NumberPickerDialog extends AlertDialog implements DialogInterface.OnClickListener { - private static final String NUMBER = "number"; - - /** - * The callback interface used to indicate the user is done filling in - * the time (they clicked on the 'Set' button). - */ - public interface OnNumberSetListener { - - /** - * @param number The number that was set. - */ - void onNumberSet(int number); - } - - private final NumberPicker mNumberPicker; - private final OnNumberSetListener mCallback; - - /** - * @param context Parent. - * @param callBack How parent is notified. - * @param number The initial number. - */ - public NumberPickerDialog(Context context, - OnNumberSetListener callBack, - int number, - int rangeMin, - int rangeMax, - int title) { - this(context, AlertDialog.THEME_HOLO_LIGHT, callBack, number, rangeMin, rangeMax, title); - } - - /** - * @param context Parent. - * @param theme the theme to apply to this dialog - * @param callBack How parent is notified. - * @param number The initial number. - */ - public NumberPickerDialog(Context context, - int theme, - OnNumberSetListener callBack, - int number, - int rangeMin, - int rangeMax, - int title) { - super(context, theme); - mCallback = callBack; - - setTitle(title); - - setButton(DialogInterface.BUTTON_POSITIVE, context.getText(R.string.set), this); - setButton(DialogInterface.BUTTON_NEGATIVE, context.getText(R.string.cancel), - (OnClickListener) null); - - LayoutInflater inflater = - (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.number_picker_dialog, null); - setView(view); - mNumberPicker = (NumberPicker) view.findViewById(R.id.number_picker); - - // initialize state - mNumberPicker.setMinValue(rangeMin); - mNumberPicker.setMaxValue(rangeMax); - mNumberPicker.setValue(number); - mNumberPicker.setOnLongPressUpdateInterval(100); // make the repeat rate three times as fast - // as normal since the range is so large. - mNumberPicker.setWrapSelectorWheel(false); // don't wrap from min->max - } - - public void onClick(DialogInterface dialog, int which) { - if (mCallback != null) { - mNumberPicker.clearFocus(); - mCallback.onNumberSet(mNumberPicker.getValue()); - dialog.dismiss(); - } - } - - @Override - public Bundle onSaveInstanceState() { - Bundle state = super.onSaveInstanceState(); - state.putInt(NUMBER, mNumberPicker.getValue()); - return state; - } - - @Override - public void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - int number = savedInstanceState.getInt(NUMBER); - mNumberPicker.setValue(number); - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java index b49d179..dfff2bc 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java @@ -7,7 +7,6 @@ import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; import android.util.Base64; /** @@ -15,19 +14,18 @@ import android.util.Base64; * * Fragment for Preferences/Settings */ -public class SettingsFragment extends PreferenceFragment implements NumberPickerDialog.OnNumberSetListener, Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { +public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public static final String ENTRIES_PAGE_LIMIT = "entries_limit"; + public static final String ENTRIES_PAGE_LIMIT_STRING = "entries_limit_string"; public static final String SAVE_SERVER_CREDENTIALS = "save_credentials_enabled"; public static final String URL_CREDENTIALS = "url"; public static final String LOGIN_CREDENTIALS = "login"; public static final String PASSWORD_CREDENTIALS = "password"; public static final int ENTRIES_PAGE_LIMIT_DEF = 20; - public static final int ENTRIES_MIN_PAGE = 20; - public static final int ENTRIES_MAX_PAGE = 100; private SharedPreferences preferences; - private Preference mEntriesLimit; + private EditTextPreference mEntriesLimit; private CheckBoxPreference saveCredentials; private EditTextPreference connectorUrlCredentials; private EditTextPreference loginCredentials; @@ -49,17 +47,18 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker addPreferencesFromResource(R.xml.settings); // Getting fields - mEntriesLimit = findPreference(ENTRIES_PAGE_LIMIT); + mEntriesLimit = (EditTextPreference) findPreference(ENTRIES_PAGE_LIMIT_STRING); saveCredentials = (CheckBoxPreference) findPreference(SAVE_SERVER_CREDENTIALS); connectorUrlCredentials = (EditTextPreference) findPreference(URL_CREDENTIALS); loginCredentials = (EditTextPreference) findPreference(LOGIN_CREDENTIALS); passwordCredentials = (EditTextPreference) findPreference(PASSWORD_CREDENTIALS); // TODO: Some encryption // Settings fields - setEntriesPageLimitSummary(); + setEntriesPageLimit(); setPasswordCredentials(); // Settings Listener + mEntriesLimit.setOnPreferenceChangeListener(this); saveCredentials.setOnPreferenceClickListener(this); passwordCredentials.setOnPreferenceChangeListener(this); } @@ -94,6 +93,11 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker mEntriesLimit.setSummary(getString(R.string.entries_summary, getEntriesPageLimit())); } + private void setEntriesPageLimit(){ + mEntriesLimit.setText(String.valueOf(getEntriesPageLimit())); + setEntriesPageLimitSummary(); + } + private void setPasswordCredentials(){ String password; password = preferences.getString(PASSWORD_CREDENTIALS, null); @@ -114,23 +118,6 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker } catch (Exception e) { e.printStackTrace(); } // TODO: Something useful } - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { - if(preference == mEntriesLimit){ - new NumberPickerDialog(getActivity(), this, getEntriesPageLimit(), ENTRIES_MIN_PAGE, ENTRIES_MAX_PAGE, R.string.entries_limit).show(); - } - - return super.onPreferenceTreeClick(preferenceScreen, preference); - } - - @Override - public void onNumberSet(int number) { - SharedPreferences.Editor editor = preferences.edit(); - editor.putInt(ENTRIES_PAGE_LIMIT, number); - editor.apply(); - setEntriesPageLimitSummary(); - } - @Override public boolean onPreferenceClick(Preference preference) { if(preference==saveCredentials){ @@ -146,7 +133,16 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker public boolean onPreferenceChange(Preference preference, Object newValue) { if(preference == passwordCredentials){ savePassword((String) newValue); + } else if (preference == mEntriesLimit) { + saveEntriesLimit((String) newValue); } return false; } + + private void saveEntriesLimit(String newValue) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putInt(ENTRIES_PAGE_LIMIT, Integer.parseInt(newValue)); + editor.apply(); + setEntriesPageLimit(); + } } diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 3cd5391..f310eb7 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -3,8 +3,9 @@ -