diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-04-28 13:08:05 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-04-28 13:08:05 +0200 |
commit | 3390972a3eb9e7497943261f2463e5241afee430 (patch) | |
tree | 969e8999c709b2f688bcc6b70ea7afc6ab52b7a2 /src/com | |
parent | aa43b38777be93b7dfb98f6015d113697a1f603d (diff) | |
download | packages_apps_settings-3390972a3eb9e7497943261f2463e5241afee430.zip packages_apps_settings-3390972a3eb9e7497943261f2463e5241afee430.tar.gz packages_apps_settings-3390972a3eb9e7497943261f2463e5241afee430.tar.bz2 |
Fix dialog not opening for app-specific notification light settings.
Change-Id: I8e8d098bcc07824803b9e9931595f5c4fdbabb7b
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/notificationlight/ApplicationLightPreference.java | 32 | ||||
-rw-r--r-- | src/com/android/settings/notificationlight/NotificationLightSettings.java | 65 |
2 files changed, 31 insertions, 66 deletions
diff --git a/src/com/android/settings/notificationlight/ApplicationLightPreference.java b/src/com/android/settings/notificationlight/ApplicationLightPreference.java index cdcb46d..21ffa80 100644 --- a/src/com/android/settings/notificationlight/ApplicationLightPreference.java +++ b/src/com/android/settings/notificationlight/ApplicationLightPreference.java @@ -32,7 +32,6 @@ import android.os.Bundle; import android.preference.DialogPreference; import android.util.AttributeSet; import android.view.View; -import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; @@ -55,7 +54,6 @@ public class ApplicationLightPreference extends DialogPreference { private int mOffValue; private boolean mOnOffChangeable; - private OnLongClickListener mParent; private Resources mResources; private ScreenReceiver mReceiver = null; private AlertDialog mTestDialog; @@ -70,7 +68,6 @@ public class ApplicationLightPreference extends DialogPreference { mOnValue = DEFAULT_TIME; mOffValue = DEFAULT_TIME; mOnOffChangeable = true; - mParent = null; init(); } @@ -85,7 +82,6 @@ public class ApplicationLightPreference extends DialogPreference { mColorValue = color; mOnValue = onValue; mOffValue = offValue; - mParent = null; mOnOffChangeable = true; init(); } @@ -106,40 +102,12 @@ public class ApplicationLightPreference extends DialogPreference { init(); } - /** - * @param context - * @param onLongClickListener - * @param color - * @param onValue - * @param offValue - */ - public ApplicationLightPreference(Context context, OnLongClickListener parent, int color, int onValue, int offValue) { - super(context, null); - mColorValue = color; - mOnValue = onValue; - mOffValue = offValue; - mParent = parent; - mOnOffChangeable = true; - init(); - } - private void init() { setLayoutResource(R.layout.preference_application_light); mResources = getContext().getResources(); } @Override - public View getView(View convertView, ViewGroup parent) { - View view = super.getView(convertView, parent); - - if (mParent != null) { - view.setOnLongClickListener(mParent); - } - - return view; - } - - @Override protected void onBindView(View view) { super.onBindView(view); diff --git a/src/com/android/settings/notificationlight/NotificationLightSettings.java b/src/com/android/settings/notificationlight/NotificationLightSettings.java index a39768a..b189f23 100644 --- a/src/com/android/settings/notificationlight/NotificationLightSettings.java +++ b/src/com/android/settings/notificationlight/NotificationLightSettings.java @@ -68,7 +68,7 @@ import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; public class NotificationLightSettings extends SettingsPreferenceFragment implements - Preference.OnPreferenceChangeListener, View.OnLongClickListener { + Preference.OnPreferenceChangeListener, AdapterView.OnItemLongClickListener { private static final String TAG = "NotificationLightSettings"; private static final String NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR = "notification_light_pulse_default_color"; private static final String NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_ON = "notification_light_pulse_default_led_on"; @@ -99,6 +99,7 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem private boolean mCustomEnabled; private boolean mLightEnabled; private boolean mVoiceCapable; + private PreferenceGroup mAppList; private ApplicationLightPreference mDefaultPref; private ApplicationLightPreference mCallPref; private ApplicationLightPreference mVoicemailPref; @@ -132,8 +133,8 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem mApplications = new HashMap<String, Application>(); // Determine if the device has voice capabilities - mVoiceCapable = (((TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() - != TelephonyManager.PHONE_TYPE_NONE); + TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); + mVoiceCapable = tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; setHasOptionsMenu(true); } @@ -144,6 +145,7 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem refreshDefault(); refreshCustomApplications(); setCustomEnabled(); + getListView().setOnItemLongClickListener(this); } private void refreshDefault() { @@ -204,6 +206,7 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem } } + mAppList = (PreferenceGroup) prefSet.findPreference("applications_list"); } private void refreshCustomApplications() { @@ -216,26 +219,23 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem // Add the Application Preferences final PreferenceScreen prefSet = getPreferenceScreen(); final PackageManager pm = getPackageManager(); - final PreferenceGroup appList = (PreferenceGroup) prefSet.findPreference("applications_list"); - if (appList != null) { + if (mAppList != null) { final Map<CharSequence, ApplicationLightPreference> prefs = new TreeMap<CharSequence, ApplicationLightPreference>(); - appList.removeAll(); + mAppList.removeAll(); for (Application i : mApplications.values()) { try { PackageInfo info = pm.getPackageInfo(i.name, PackageManager.GET_META_DATA); ApplicationLightPreference pref = - new ApplicationLightPreference(context, this, i.color, i.timeon, i.timeoff); + new ApplicationLightPreference(context, i.color, i.timeon, i.timeoff); final CharSequence label = info.applicationInfo.loadLabel(pm); pref.setKey(i.name); pref.setTitle(label); pref.setIcon(info.applicationInfo.loadIcon(pm)); - // Does not fit on low res devices, we need it so we hide the view in the preference - pref.setSummary(i.name); pref.setPersistent(false); pref.setOnPreferenceChangeListener(this); @@ -246,14 +246,13 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem } for (ApplicationLightPreference pref : prefs.values()) { - appList.addPreference(pref); + mAppList.addPreference(pref); } } } private void setCustomEnabled() { - - Boolean enabled = mCustomEnabled && mLightEnabled; + boolean enabled = mCustomEnabled && mLightEnabled; // Phone related preferences if (mVoiceCapable) { @@ -262,10 +261,8 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem } // Custom applications - PreferenceScreen prefSet = getPreferenceScreen(); - PreferenceGroup appList = (PreferenceGroup) prefSet.findPreference("applications_list"); - if (appList != null) { - appList.setEnabled(enabled); + if (mAppList != null) { + mAppList.setEnabled(enabled); setHasOptionsMenu(enabled); } } @@ -368,27 +365,27 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem } } - public boolean onLongClick(View v) { - final TextView tView; - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { + final Preference pref = (Preference) getPreferenceScreen().getRootAdapter().getItem(position); - if ((v != null) && ((tView = (TextView) v.findViewById(android.R.id.summary)) != null)) { - builder.setTitle(R.string.dialog_delete_title); - builder.setMessage(R.string.dialog_delete_message); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - removeCustomApplication(tView.getText().toString()); - } - }); - builder.setNegativeButton(android.R.string.cancel, null); - builder.create().show(); - return true; + if (mAppList.findPreference(pref.getKey()) != pref) { + return false; } - return false; + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.dialog_delete_title) + .setMessage(R.string.dialog_delete_message) + .setIconAttribute(android.R.attr.alertDialogIcon) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + removeCustomApplication(pref.getKey()); + } + }) + .setNegativeButton(android.R.string.cancel, null); + + builder.show(); + return true; } public boolean onPreferenceChange(Preference preference, Object objValue) { |