Improve Search results highlighting
- remove unnecessary code
- use keyed Tag with a well known App key for preventing collisions
- fix missing Brightness Level preference key (used for highlight)
Change-Id: I070e3b8c3cb43da7addd34be192aade21951f57c
diff --git a/res/values/ids.xml b/res/values/ids.xml
new file mode 100644
index 0000000..2fbf70b
--- /dev/null
+++ b/res/values/ids.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2014, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources>
+ <item type="id" name="preference_highlight_key" />
+</resources>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index c145938..4a8211f 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -19,6 +19,7 @@
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.android.settings.BrightnessPreference
+ android:key="brightness"
android:title="@string/brightness"
android:persistent="false"/>
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 1d41816..dbef6cb 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -360,7 +360,8 @@
mDataEnabled = new Switch(inflater.getContext());
mDataEnabledView = inflatePreference(inflater, mNetworkSwitches, mDataEnabled);
- mDataEnabledView.setTag(DATA_USAGE_ENABLE_MOBILE_KEY);
+ mDataEnabledView.setTag(R.id.preference_highlight_key,
+ DATA_USAGE_ENABLE_MOBILE_KEY);
mDataEnabled.setOnCheckedChangeListener(mDataEnabledListener);
mNetworkSwitches.addView(mDataEnabledView);
@@ -368,7 +369,8 @@
mDisableAtLimit.setClickable(false);
mDisableAtLimit.setFocusable(false);
mDisableAtLimitView = inflatePreference(inflater, mNetworkSwitches, mDisableAtLimit);
- mDisableAtLimitView.setTag(DATA_USAGE_DISABLE_MOBILE_LIMIT_KEY);
+ mDisableAtLimitView.setTag(R.id.preference_highlight_key,
+ DATA_USAGE_DISABLE_MOBILE_LIMIT_KEY);
mDisableAtLimitView.setClickable(true);
mDisableAtLimitView.setFocusable(true);
mDisableAtLimitView.setOnClickListener(mDisableAtLimitListener);
@@ -377,7 +379,7 @@
// bind cycle dropdown
mCycleView = mHeader.findViewById(R.id.cycles);
- mCycleView.setTag(DATA_USAGE_CYCLE_KEY);
+ mCycleView.setTag(R.id.preference_highlight_key, DATA_USAGE_CYCLE_KEY);
mCycleSpinner = (Spinner) mCycleView.findViewById(R.id.cycles_spinner);
mCycleAdapter = new CycleAdapter(context);
mCycleSpinner.setAdapter(mCycleAdapter);
diff --git a/src/com/android/settings/HighlightingFragment.java b/src/com/android/settings/HighlightingFragment.java
index 1424abd..4a233b4 100644
--- a/src/com/android/settings/HighlightingFragment.java
+++ b/src/com/android/settings/HighlightingFragment.java
@@ -116,7 +116,7 @@
}
private boolean checkTag(View view, String key) {
- final Object tag = view.getTag();
+ final Object tag = view.getTag(R.id.preference_highlight_key);
if (tag == null || !(tag instanceof String)) {
return false;
}
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 67432c0..eb2bea9 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -204,19 +204,6 @@
}, DELAY_HIGHLIGHT_DURATION_MILLIS);
}
});
- } else {
- // Try locating the Preference View thru its tag
- View preferenceView = findPreferenceViewForKey(getView(), key);
- if (preferenceView != null ) {
- mPreferenceHighlighted = true;
-
- preferenceView.setBackground(highlight);
- final int centerX = preferenceView.getWidth() / 2;
- final int centerY = preferenceView.getHeight() / 2;
- highlight.setHotspot(centerX, centerY);
- preferenceView.setPressed(true);
- preferenceView.setPressed(false);
- }
}
}
@@ -235,33 +222,6 @@
return -1;
}
- private View findPreferenceViewForKey(View root, String key) {
- if (checkTag(root, key)) {
- return root;
- }
- if (root instanceof ViewGroup) {
- final ViewGroup group = (ViewGroup) root;
- final int count = group.getChildCount();
- for (int n = 0; n < count; n++) {
- final View child = group.getChildAt(n);
- final View view = findPreferenceViewForKey(child, key);
- if (view != null) {
- return view;
- }
- }
- }
- return null;
- }
-
- private boolean checkTag(View view, String key) {
- final Object tag = view.getTag();
- if (tag == null || !(tag instanceof String)) {
- return false;
- }
- final String prefKey = (String) tag;
- return (!TextUtils.isEmpty(prefKey) && prefKey.equals(key));
- }
-
protected void removePreference(String key) {
Preference pref = findPreference(key);
if (pref != null) {