am 2c5453e5: Merge "Add Preference highlighting"

* commit '2c5453e5ce88ff3ef5ca65d40ef124cb5cdcea56':
  Add Preference highlighting
This commit is contained in:
Fabrice Di Meglio
2014-04-16 23:24:29 +00:00
committed by Android Git Automerger
2 changed files with 39 additions and 4 deletions

View File

@@ -337,6 +337,26 @@ public abstract class PreferenceFragment extends Fragment implements
return mList;
}
/** @hide */
public boolean hasListView() {
if (mList != null) {
return true;
}
View root = getView();
if (root == null) {
return false;
}
View rawListView = root.findViewById(android.R.id.list);
if (!(rawListView instanceof ListView)) {
return false;
}
mList = (ListView)rawListView;
if (mList == null) {
return false;
}
return true;
}
private void ensureList() {
if (mList != null) {
return;

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.preference.Preference.OnPreferenceChangeInternalListener;
import android.view.View;
@@ -91,7 +93,8 @@ public class PreferenceGroupAdapter extends BaseAdapter
}
};
private int mActivatedPosition = -1;
private int mHighlightedPosition = -1;
private Drawable mHighlightedDrawable;
private static class PreferenceLayout implements Comparable<PreferenceLayout> {
private int resId;
@@ -212,8 +215,18 @@ public class PreferenceGroupAdapter extends BaseAdapter
return this.getItem(position).getId();
}
public void setActivated(int position) {
mActivatedPosition = position;
/**
* @hide
*/
public void setHighlighted(int position) {
mHighlightedPosition = position;
}
/**
* @hide
*/
public void setHighlightedDrawable(Drawable drawable) {
mHighlightedDrawable = drawable;
}
public View getView(int position, View convertView, ViewGroup parent) {
@@ -227,7 +240,9 @@ public class PreferenceGroupAdapter extends BaseAdapter
convertView = null;
}
View result = preference.getView(convertView, parent);
result.setActivated(position == mActivatedPosition);
if (position == mHighlightedPosition && mHighlightedDrawable != null) {
result.setBackgroundDrawable(mHighlightedDrawable);
}
return result;
}