diff --git a/app/src/main/java/com/geecko/QuickLyric/view/AppCompatListPreference.java b/app/src/main/java/com/geecko/QuickLyric/view/AppCompatListPreference.java new file mode 100644 index 000000000..e8b3b08f7 --- /dev/null +++ b/app/src/main/java/com/geecko/QuickLyric/view/AppCompatListPreference.java @@ -0,0 +1,100 @@ +/* + * * + * * This file is part of QuickLyric + * * Created by geecko + * * + * * QuickLyric is free software: you can redistribute it and/or modify + * * it under the terms of the GNU General Public License as published by + * * the Free Software Foundation, either version 3 of the License, or + * * (at your option) any later version. + * * + * * QuickLyric is distributed in the hope that it will be useful, + * * but WITHOUT ANY WARRANTY; without even the implied warranty of + * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License + * * along with QuickLyric. If not, see . + * + */ + +package com.geecko.QuickLyric.view; + +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.PreferenceManager; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatDialog; +import android.util.AttributeSet; + +import java.lang.reflect.Method; + +public class AppCompatListPreference extends ListPreference { + + private AppCompatDialog mDialog; + + public AppCompatListPreference(Context context) { + super(context); + } + + public AppCompatListPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public AppCompatDialog getDialog() { + return mDialog; + } + + @Override + protected void showDialog(Bundle state) { + if (getEntries() == null || getEntryValues() == null) { + throw new IllegalStateException( + "ListPreference requires an entries array and an entryValues array."); + } + + int preselect = findIndexOfValue(getValue()); + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) + .setTitle(getDialogTitle()) + .setIcon(getDialogIcon()) + .setSingleChoiceItems(getEntries(), preselect, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (which >= 0 && getEntryValues() != null) { + String value = getEntryValues()[which].toString(); + if (callChangeListener(value) && isPersistent()) { + setValue(value); + } + } + dialog.dismiss(); + } + }); + + PreferenceManager pm = getPreferenceManager(); + try { + Method method = pm.getClass().getDeclaredMethod( + "registerOnActivityDestroyListener", + PreferenceManager.OnActivityDestroyListener.class); + method.setAccessible(true); + method.invoke(pm, this); + } catch (Exception e) { + e.printStackTrace(); + } + + mDialog = builder.create(); + if (state != null) { + mDialog.onRestoreInstanceState(state); + } + mDialog.show(); + } + + @Override + public void onActivityDestroy() { + super.onActivityDestroy(); + if (mDialog != null && mDialog.isShowing() && + mDialog.getWindow() != null && mDialog.getWindow().getWindowManager() != null) { + mDialog.dismiss(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/fdroid/fdroid/PreferencesActivity.java b/app/src/main/java/org/fdroid/fdroid/PreferencesActivity.java index d23862669..82a1559c1 100644 --- a/app/src/main/java/org/fdroid/fdroid/PreferencesActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/PreferencesActivity.java @@ -22,13 +22,13 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.NavUtils; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.widget.LinearLayout; import org.fdroid.fdroid.views.fragments.PreferencesFragment; -public class PreferencesActivity extends ActionBarActivity { +public class PreferencesActivity extends AppCompatActivity { public static final int RESULT_RESTART = 4; diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 96ae03aaa..da67b38da 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1,7 +1,7 @@ - - - -