Use AppCompatListPreference from QuickLyric to fix dialog themes.
Fixes Issue #750. This new class makes sure to use the correct `AlertDialog.Builder` from the support lib. This in turn ensures the correct styles get applied to the result alert dialog.
This commit is contained in:
		
							parent
							
								
									2c1a059da9
								
							
						
					
					
						commit
						79ecffc91c
					
				| @ -0,0 +1,97 @@ | ||||
| /* | ||||
|  * * | ||||
|  *  * 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 <http://www.gnu.org/licenses/>. | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| 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(); | ||||
|     } | ||||
| } | ||||
| @ -1,7 +1,7 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <PreferenceCategory android:title="@string/updates"> | ||||
|         <ListPreference android:title="@string/update_interval" | ||||
|         <com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/update_interval" | ||||
|             android:key="updateInterval" | ||||
|             android:defaultValue="24" | ||||
|             android:entries="@array/updateIntervalNames" | ||||
| @ -24,12 +24,12 @@ | ||||
|             android:title="@string/update_history" /> | ||||
|     </PreferenceCategory> | ||||
|     <PreferenceCategory android:title="@string/display"> | ||||
|         <ListPreference android:title="@string/pref_language" | ||||
|         <com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/pref_language" | ||||
|             android:key="language" | ||||
|             android:defaultValue="" | ||||
|             android:entries="@array/languageNames" | ||||
|             android:entryValues="@array/languageValues" /> | ||||
|         <ListPreference android:title="@string/theme" | ||||
|         <com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/theme" | ||||
|             android:key="theme" | ||||
|             android:defaultValue="light" | ||||
|             android:entries="@array/themeNames" | ||||
| @ -77,7 +77,7 @@ | ||||
|     </PreferenceCategory> | ||||
|     <PreferenceCategory android:title="@string/other" | ||||
|         android:key="pref_category_other"> | ||||
|         <ListPreference android:title="@string/cache_downloaded" | ||||
|         <com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/cache_downloaded" | ||||
|             android:key="keepCacheFor" | ||||
|             android:defaultValue="86400000" | ||||
|             android:entries="@array/keepCacheNames" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Peter Serwylo
						Peter Serwylo