summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-09-14 18:57:14 -0700
committerDianne Hackborn <hackbod@google.com>2010-09-15 11:00:44 -0700
commitd0fa371f276fde32d81c037006941bc93da0bb03 (patch)
treee1b588f0cbfe23ce289ac50784aa3d9960fd7457 /core
parent53b34a096b6943eef75e8154f6e5b76e4685fa24 (diff)
downloadframeworks_base-d0fa371f276fde32d81c037006941bc93da0bb03.zip
frameworks_base-d0fa371f276fde32d81c037006941bc93da0bb03.tar.gz
frameworks_base-d0fa371f276fde32d81c037006941bc93da0bb03.tar.bz2
Add a new "activated" state to View.
Use this in ListView and GridView if the top view is not checkable. This allows PreferenceActivity to now highlight the current heading that is being shown. Change-Id: I0d28aded9a61a42962b4aece420ae4058712d963
Diffstat (limited to 'core')
-rw-r--r--core/java/android/preference/PreferenceActivity.java5
-rw-r--r--core/java/android/view/View.java330
-rw-r--r--core/java/android/view/ViewGroup.java13
-rw-r--r--core/java/android/widget/GridView.java3
-rw-r--r--core/java/android/widget/ListView.java3
-rw-r--r--core/res/res/drawable/activated_background.xml20
-rw-r--r--core/res/res/drawable/activated_background_light.xml20
-rw-r--r--core/res/res/layout/preference_header_item.xml (renamed from core/res/res/layout/preference_list_item.xml)4
-rwxr-xr-xcore/res/res/values/attrs.xml41
-rw-r--r--core/res/res/values/public.xml22
-rw-r--r--core/res/res/values/themes.xml4
11 files changed, 318 insertions, 147 deletions
diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java
index 60d810e..4247ae5 100644
--- a/core/java/android/preference/PreferenceActivity.java
+++ b/core/java/android/preference/PreferenceActivity.java
@@ -241,7 +241,7 @@ public abstract class PreferenceActivity extends ListActivity implements
View view;
if (convertView == null) {
- view = mInflater.inflate(com.android.internal.R.layout.preference_list_item,
+ view = mInflater.inflate(com.android.internal.R.layout.preference_header_item,
parent, false);
holder = new HeaderViewHolder();
holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon);
@@ -446,6 +446,9 @@ public abstract class PreferenceActivity extends ListActivity implements
if (!mSinglePane) {
// Multi-pane.
getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
+ if (mCurHeader != null) {
+ setSelectedHeader(mCurHeader);
+ }
mPrefsContainer.setVisibility(View.VISIBLE);
}
} else {
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 51c3879..d04007c 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -986,7 +986,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see android.graphics.drawable.Drawable
* @see #getDrawableState()
*/
- protected static final int[] EMPTY_STATE_SET = {};
+ protected static final int[] EMPTY_STATE_SET;
/**
* Indicates the view is enabled. States are used with
* {@link android.graphics.drawable.Drawable} to change the drawing of the
@@ -995,7 +995,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see android.graphics.drawable.Drawable
* @see #getDrawableState()
*/
- protected static final int[] ENABLED_STATE_SET = {R.attr.state_enabled};
+ protected static final int[] ENABLED_STATE_SET;
/**
* Indicates the view is focused. States are used with
* {@link android.graphics.drawable.Drawable} to change the drawing of the
@@ -1004,7 +1004,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see android.graphics.drawable.Drawable
* @see #getDrawableState()
*/
- protected static final int[] FOCUSED_STATE_SET = {R.attr.state_focused};
+ protected static final int[] FOCUSED_STATE_SET;
/**
* Indicates the view is selected. States are used with
* {@link android.graphics.drawable.Drawable} to change the drawing of the
@@ -1013,7 +1013,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see android.graphics.drawable.Drawable
* @see #getDrawableState()
*/
- protected static final int[] SELECTED_STATE_SET = {R.attr.state_selected};
+ protected static final int[] SELECTED_STATE_SET;
/**
* Indicates the view is pressed. States are used with
* {@link android.graphics.drawable.Drawable} to change the drawing of the
@@ -1023,7 +1023,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #getDrawableState()
* @hide
*/
- protected static final int[] PRESSED_STATE_SET = {R.attr.state_pressed};
+ protected static final int[] PRESSED_STATE_SET;
/**
* Indicates the view's window has focus. States are used with
* {@link android.graphics.drawable.Drawable} to change the drawing of the
@@ -1032,8 +1032,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see android.graphics.drawable.Drawable
* @see #getDrawableState()
*/
- protected static final int[] WINDOW_FOCUSED_STATE_SET =
- {R.attr.state_window_focused};
+ protected static final int[] WINDOW_FOCUSED_STATE_SET;
// Doubles
/**
* Indicates the view is enabled and has the focus.
@@ -1041,48 +1040,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #ENABLED_STATE_SET
* @see #FOCUSED_STATE_SET
*/
- protected static final int[] ENABLED_FOCUSED_STATE_SET =
- stateSetUnion(ENABLED_STATE_SET, FOCUSED_STATE_SET);
+ protected static final int[] ENABLED_FOCUSED_STATE_SET;
/**
* Indicates the view is enabled and selected.
*
* @see #ENABLED_STATE_SET
* @see #SELECTED_STATE_SET
*/
- protected static final int[] ENABLED_SELECTED_STATE_SET =
- stateSetUnion(ENABLED_STATE_SET, SELECTED_STATE_SET);
+ protected static final int[] ENABLED_SELECTED_STATE_SET;
/**
* Indicates the view is enabled and that its window has focus.
*
* @see #ENABLED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(ENABLED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is focused and selected.
*
* @see #FOCUSED_STATE_SET
* @see #SELECTED_STATE_SET
*/
- protected static final int[] FOCUSED_SELECTED_STATE_SET =
- stateSetUnion(FOCUSED_STATE_SET, SELECTED_STATE_SET);
+ protected static final int[] FOCUSED_SELECTED_STATE_SET;
/**
* Indicates the view has the focus and that its window has the focus.
*
* @see #FOCUSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is selected and that its window has the focus.
*
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET;
// Triples
/**
* Indicates the view is enabled, focused and selected.
@@ -1091,8 +1084,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #FOCUSED_STATE_SET
* @see #SELECTED_STATE_SET
*/
- protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET =
- stateSetUnion(ENABLED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
+ protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET;
/**
* Indicates the view is enabled, focused and its window has the focus.
*
@@ -1100,8 +1092,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #FOCUSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(ENABLED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is enabled, selected and its window has the focus.
*
@@ -1109,8 +1100,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(ENABLED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is focused, selected and its window has the focus.
*
@@ -1118,8 +1108,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is enabled, focused, selected and its window
* has the focus.
@@ -1129,28 +1118,21 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(ENABLED_FOCUSED_SELECTED_STATE_SET,
- WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed and its window has the focus.
*
* @see #PRESSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed and selected.
*
* @see #PRESSED_STATE_SET
* @see #SELECTED_STATE_SET
*/
- protected static final int[] PRESSED_SELECTED_STATE_SET =
- stateSetUnion(PRESSED_STATE_SET, SELECTED_STATE_SET);
-
+ protected static final int[] PRESSED_SELECTED_STATE_SET;
/**
* Indicates the view is pressed, selected and its window has the focus.
*
@@ -1158,18 +1140,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed and focused.
*
* @see #PRESSED_STATE_SET
* @see #FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_STATE_SET, FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, focused and its window has the focus.
*
@@ -1177,9 +1155,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #FOCUSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, focused and selected.
*
@@ -1187,9 +1163,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET =
- stateSetUnion(PRESSED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
-
+ protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET;
/**
* Indicates the view is pressed, focused, selected and its window has the focus.
*
@@ -1198,18 +1172,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed and enabled.
*
* @see #PRESSED_STATE_SET
* @see #ENABLED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_STATE_SET =
- stateSetUnion(PRESSED_STATE_SET, ENABLED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_STATE_SET;
/**
* Indicates the view is pressed, enabled and its window has the focus.
*
@@ -1217,9 +1187,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #ENABLED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, enabled and selected.
*
@@ -1227,9 +1195,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #ENABLED_STATE_SET
* @see #SELECTED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_STATE_SET, SELECTED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET;
/**
* Indicates the view is pressed, enabled, selected and its window has the
* focus.
@@ -1239,9 +1205,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, enabled and focused.
*
@@ -1249,9 +1213,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #ENABLED_STATE_SET
* @see #FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_STATE_SET, FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, enabled, focused and its window has the
* focus.
@@ -1261,9 +1223,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #FOCUSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_FOCUSED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
/**
* Indicates the view is pressed, enabled, focused and selected.
*
@@ -1272,9 +1232,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #SELECTED_STATE_SET
* @see #FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_FOCUSED_STATE_SET, SELECTED_STATE_SET);
-
+ protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET;
/**
* Indicates the view is pressed, enabled, focused, selected and its window
* has the focus.
@@ -1285,47 +1243,137 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #FOCUSED_STATE_SET
* @see #WINDOW_FOCUSED_STATE_SET
*/
- protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET =
- stateSetUnion(PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, WINDOW_FOCUSED_STATE_SET);
+ protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
/**
* The order here is very important to {@link #getDrawableState()}
*/
- private static final int[][] VIEW_STATE_SETS = {
- EMPTY_STATE_SET, // 0 0 0 0 0
- WINDOW_FOCUSED_STATE_SET, // 0 0 0 0 1
- SELECTED_STATE_SET, // 0 0 0 1 0
- SELECTED_WINDOW_FOCUSED_STATE_SET, // 0 0 0 1 1
- FOCUSED_STATE_SET, // 0 0 1 0 0
- FOCUSED_WINDOW_FOCUSED_STATE_SET, // 0 0 1 0 1
- FOCUSED_SELECTED_STATE_SET, // 0 0 1 1 0
- FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 0 0 1 1 1
- ENABLED_STATE_SET, // 0 1 0 0 0
- ENABLED_WINDOW_FOCUSED_STATE_SET, // 0 1 0 0 1
- ENABLED_SELECTED_STATE_SET, // 0 1 0 1 0
- ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 0 1 0 1 1
- ENABLED_FOCUSED_STATE_SET, // 0 1 1 0 0
- ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, // 0 1 1 0 1
- ENABLED_FOCUSED_SELECTED_STATE_SET, // 0 1 1 1 0
- ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 0 1 1 1 1
- PRESSED_STATE_SET, // 1 0 0 0 0
- PRESSED_WINDOW_FOCUSED_STATE_SET, // 1 0 0 0 1
- PRESSED_SELECTED_STATE_SET, // 1 0 0 1 0
- PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 1 0 0 1 1
- PRESSED_FOCUSED_STATE_SET, // 1 0 1 0 0
- PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, // 1 0 1 0 1
- PRESSED_FOCUSED_SELECTED_STATE_SET, // 1 0 1 1 0
- PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 1 0 1 1 1
- PRESSED_ENABLED_STATE_SET, // 1 1 0 0 0
- PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, // 1 1 0 0 1
- PRESSED_ENABLED_SELECTED_STATE_SET, // 1 1 0 1 0
- PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 1 1 0 1 1
- PRESSED_ENABLED_FOCUSED_STATE_SET, // 1 1 1 0 0
- PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, // 1 1 1 0 1
- PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, // 1 1 1 1 0
- PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, // 1 1 1 1 1
+ private static final int[][] VIEW_STATE_SETS;
+
+ static final int VIEW_STATE_WINDOW_FOCUSED = 1<<0;
+ static final int VIEW_STATE_SELECTED = 1<<1;
+ static final int VIEW_STATE_FOCUSED = 1<<2;
+ static final int VIEW_STATE_ENABLED = 1<<3;
+ static final int VIEW_STATE_PRESSED = 1<<4;
+ static final int VIEW_STATE_ACTIVATED = 1<<5;
+
+ static final int[] VIEW_STATE_IDS = new int[] {
+ R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED,
+ R.attr.state_selected, VIEW_STATE_SELECTED,
+ R.attr.state_focused, VIEW_STATE_FOCUSED,
+ R.attr.state_enabled, VIEW_STATE_ENABLED,
+ R.attr.state_pressed, VIEW_STATE_PRESSED,
+ R.attr.state_activated, VIEW_STATE_ACTIVATED,
};
+ static {
+ int[] orderedIds = new int[VIEW_STATE_IDS.length];
+ for (int i=0; i<R.styleable.ViewDrawableStates.length; i++) {
+ int viewState = R.styleable.ViewDrawableStates[i];
+ for (int j=0; j<VIEW_STATE_IDS.length; j+=2) {
+ if (VIEW_STATE_IDS[j] == viewState) {
+ orderedIds[i*2] = viewState;
+ orderedIds[i*2+1] = VIEW_STATE_IDS[j+1];
+ }
+ }
+ }
+ final int NUM_BITS = VIEW_STATE_IDS.length/2;
+ VIEW_STATE_SETS = new int[1<<NUM_BITS][];
+ for (int i=0; i<VIEW_STATE_SETS.length; i++) {
+ int numBits = Integer.bitCount(i);
+ int[] set = new int[numBits];
+ int pos = 0;
+ for (int j=0; j<orderedIds.length; j+=2) {
+ if ((i&orderedIds[j+1]) != 0) {
+ if (false) {
+ Log.i("View", "Index #" + i + " @ ordered #" + j
+ + " resid=0x" + Integer.toHexString(orderedIds[j])
+ + " mask " + orderedIds[j+1]);
+ }
+ set[pos++] = orderedIds[j];
+ }
+ }
+ VIEW_STATE_SETS[i] = set;
+ }
+
+ EMPTY_STATE_SET = VIEW_STATE_SETS[0];
+ WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED];
+ SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED];
+ SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED];
+ FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED];
+ FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED];
+ FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED];
+ FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_FOCUSED];
+ ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED];
+ ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED];
+ ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_ENABLED];
+ ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_ENABLED];
+ ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED];
+ ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_ENABLED];
+ ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_ENABLED];
+ ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED];
+
+ PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED];
+ PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED];
+ PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_PRESSED];
+ PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_PRESSED];
+ PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED];
+ PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_PRESSED];
+ PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_PRESSED];
+ PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED
+ | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_ENABLED
+ | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED
+ | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED
+ | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED];
+ PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[
+ VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED
+ | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED
+ | VIEW_STATE_PRESSED];
+ }
+
/**
* Used by views that contain lists of items. This state indicates that
* the view is showing the last item.
@@ -1572,6 +1620,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
*/
private static final int PIVOT_EXPLICITLY_SET = 0x10000000;
+ /** {@hide} */
+ static final int ACTIVATED = 0x20000000;
+
/**
* The parent this view is attached to.
* {@hide}
@@ -8343,18 +8394,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
int privateFlags = mPrivateFlags;
- int viewStateIndex = (((privateFlags & PRESSED) != 0) ? 1 : 0);
-
- viewStateIndex = (viewStateIndex << 1)
- + (((mViewFlags & ENABLED_MASK) == ENABLED) ? 1 : 0);
-
- viewStateIndex = (viewStateIndex << 1) + (isFocused() ? 1 : 0);
-
- viewStateIndex = (viewStateIndex << 1)
- + (((privateFlags & SELECTED) != 0) ? 1 : 0);
-
- final boolean hasWindowFocus = hasWindowFocus();
- viewStateIndex = (viewStateIndex << 1) + (hasWindowFocus ? 1 : 0);
+ int viewStateIndex = 0;
+ if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED;
+ if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED;
+ if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED;
+ if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_PRESSED;
+ if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED;
+ if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED;
drawableState = VIEW_STATE_SETS[viewStateIndex];
@@ -8366,7 +8412,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
+ " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED)
+ " fo=" + hasFocus()
+ " sl=" + ((privateFlags & SELECTED) != 0)
- + " wf=" + hasWindowFocus
+ + " wf=" + hasWindowFocus()
+ ": " + Arrays.toString(drawableState));
}
@@ -8680,6 +8726,48 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
}
/**
+ * Changes the activated state of this view. A view can be activated or not.
+ * Note that activation is not the same as selection. Selection is
+ * a transient property, representing the view (hierarchy) the user is
+ * currently interacting with. Activation is a longer-term state that the
+ * user can move views in and out of. For example, in a list view with
+ * single or multiple selection enabled, the views in the current selection
+ * set are activated. (Um, yeah, we are deeply sorry about the terminology
+ * here.) The activated state is propagated down to children of the view it
+ * is set on.
+ *
+ * @param activated true if the view must be activated, false otherwise
+ */
+ public void setActivated(boolean activated) {
+ if (((mPrivateFlags & ACTIVATED) != 0) != activated) {
+ mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0);
+ invalidate();
+ refreshDrawableState();
+ dispatchSetSelected(activated);
+ }
+ }
+
+ /**
+ * Dispatch setActivated to all of this View's children.
+ *
+ * @see #setActivated(boolean)
+ *
+ * @param activated The new activated state
+ */
+ protected void dispatchSetActivated(boolean activated) {
+ }
+
+ /**
+ * Indicates the activation state of this view.
+ *
+ * @return true if the view is activated, false otherwise
+ */
+ @ViewDebug.ExportedProperty
+ public boolean isActivated() {
+ return (mPrivateFlags & ACTIVATED) != 0;
+ }
+
+ /**
* Returns the ViewTreeObserver for this view's hierarchy. The view tree
* observer can be used to get notifications when global events, like
* layout, happen.
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 012f3cc..a18a977 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -2066,6 +2066,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispatchSetActivated(boolean activated) {
+ final View[] children = mChildren;
+ final int count = mChildrenCount;
+ for (int i = 0; i < count; i++) {
+
+ children[i].setActivated(activated);
+ }
+ }
+
@Override
protected void dispatchSetPressed(boolean pressed) {
final View[] children = mChildren;
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index dffe685..46c7d33 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -1341,6 +1341,9 @@ public class GridView extends AbsListView {
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
if (child instanceof Checkable) {
((Checkable) child).setChecked(mCheckStates.get(position));
+ } else if (getContext().getApplicationInfo().targetSdkVersion
+ >= android.os.Build.VERSION_CODES.HONEYCOMB) {
+ child.setActivated(mCheckStates.get(position));
}
}
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index f9bdc43..e5a34e8 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -1785,6 +1785,9 @@ public class ListView extends AbsListView {
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
if (child instanceof Checkable) {
((Checkable) child).setChecked(mCheckStates.get(position));
+ } else if (getContext().getApplicationInfo().targetSdkVersion
+ >= android.os.Build.VERSION_CODES.HONEYCOMB) {
+ child.setActivated(mCheckStates.get(position));
}
}
diff --git a/core/res/res/drawable/activated_background.xml b/core/res/res/drawable/activated_background.xml
new file mode 100644
index 0000000..d92fba1
--- /dev/null
+++ b/core/res/res/drawable/activated_background.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_activated="true" android:drawable="@android:drawable/list_selector_background_selected" />
+ <item android:drawable="@color/transparent" />
+</selector>
diff --git a/core/res/res/drawable/activated_background_light.xml b/core/res/res/drawable/activated_background_light.xml
new file mode 100644
index 0000000..5d5681d
--- /dev/null
+++ b/core/res/res/drawable/activated_background_light.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_activated="true" android:drawable="@drawable/list_selector_background_selected_light" />
+ <item android:drawable="@color/transparent" />
+</selector>
diff --git a/core/res/res/layout/preference_list_item.xml b/core/res/res/layout/preference_header_item.xml
index 3b888b4..80a3ac2 100644
--- a/core/res/res/layout/preference_list_item.xml
+++ b/core/res/res/layout/preference_header_item.xml
@@ -14,12 +14,12 @@
limitations under the License.
-->
-<!-- Layout for a preference category item, containing an icon and label. -->
+<!-- Layout of a header item in PreferenceActivity. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
+ android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index cda997a..2ede9f0 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -151,6 +151,9 @@
<!-- Drawable used as a background for selected list items. -->
<attr name="listChoiceBackgroundIndicator" format="reference" />
+ <!-- Drawable used as a background for activated items. -->
+ <attr name="activatedBackgroundIndicator" format="reference" />
+
<!-- ============= -->
<!-- Button styles -->
<!-- ============= -->
@@ -3104,6 +3107,7 @@
<li>"state_last"
<li>"state_only"
<li>"state_pressed"
+ <li>"state_activated"
<li>"state_error"
<li>"state_circle"
<li>"state_rect"
@@ -3111,23 +3115,35 @@
<li>"state_move"
</ul> -->
<declare-styleable name="DrawableStates">
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when a view has input focus. -->
<attr name="state_focused" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when a view's window has input focus. -->
<attr name="state_window_focused" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when a view is enabled. -->
<attr name="state_enabled" format="boolean" />
- <!-- State identifier indicating that the object <var>may</var> display a check mark.
- See {@link R.attr#state_checked} for the identifier that indicates whether it is
- actually checked. -->
+ <!-- State identifier indicating that the object <var>may</var> display a check mark.
+ See {@link R.attr#state_checked} for the identifier that indicates whether it is
+ actually checked. -->
<attr name="state_checkable" format="boolean"/>
- <!-- State identifier indicating that the object is currently checked. See
- {@link R.attr#state_checkable} for an additional identifier that can indicate if
- any object may ever display a check, regardless of whether state_checked is
- currently set. -->
+ <!-- State identifier indicating that the object is currently checked. See
+ {@link R.attr#state_checkable} for an additional identifier that can indicate if
+ any object may ever display a check, regardless of whether state_checked is
+ currently set. -->
<attr name="state_checked" format="boolean"/>
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when a view (or one of its parents) is currently selected. -->
<attr name="state_selected" format="boolean" />
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when the user is pressing down in a view. -->
+ <attr name="state_pressed" format="boolean" />
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ set when a view or its parent has been "activated" meaning the user has currently
+ marked it as being of interest. This is an alternative representation of
+ state_checked for when the state should be propagated down the view hierarchy. -->
+ <attr name="state_activated" format="boolean" />
<!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_active" format="boolean" />
<!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
@@ -3138,8 +3154,6 @@
<attr name="state_middle" format="boolean" />
<!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_last" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
- <attr name="state_pressed" format="boolean" />
</declare-styleable>
<declare-styleable name="ViewDrawableStates">
<attr name="state_pressed" />
@@ -3147,6 +3161,7 @@
<attr name="state_selected" />
<attr name="state_window_focused" />
<attr name="state_enabled" />
+ <attr name="state_activated" />
</declare-styleable>
<!-- State array representing a menu item that is currently checked. -->
<declare-styleable name="MenuItemCheckedState">
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 86e5579..79040b8 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1346,6 +1346,8 @@
<public type="attr" name="iconifiedByDefault" />
<public type="attr" name="actionLayout" />
<public type="attr" name="actionViewClass" />
+ <public type="attr" name="activatedBackgroundIndicator" />
+ <public type="attr" name="state_activated" />
<public type="anim" name="animator_fade_in" />
<public type="anim" name="animator_fade_out" />
@@ -1354,12 +1356,6 @@
<!-- Context menu ID for the "Select text..." menu item to switch to text
selection context mode in text views. -->
<public type="id" name="selectTextMode" />
-
- <public type="style" name="Theme.WithActionBar" />
- <public type="style" name="Widget.Spinner.DropDown" />
- <public type="style" name="Widget.ActionButton" />
- <public type="style" name="Theme.Dialog.NoFrame" />
- <public type="style" name="Theme.NoTitleBar.OverlayActionModes" />
<!-- Standard content view for a {@link android.app.ListFragment}.
If you are implementing a subclass of ListFragment with your
@@ -1368,6 +1364,15 @@
the base class. -->
<public type="layout" name="list_content" />
+ <!-- A simple ListView item layout which can contain text and support (single or multiple) item selection. -->
+ <public type="layout" name="simple_selectable_list_item" />
+
+ <public type="style" name="Theme.WithActionBar" />
+ <public type="style" name="Widget.Spinner.DropDown" />
+ <public type="style" name="Widget.ActionButton" />
+ <public type="style" name="Theme.Dialog.NoFrame" />
+ <public type="style" name="Theme.NoTitleBar.OverlayActionModes" />
+
<public type="style" name="Theme.Holo" />
<public type="style" name="Theme.Light.Holo" />
<public type="style" name="Theme.Holo.NoActionBar" />
@@ -1375,9 +1380,6 @@
<public type="style" name="Theme.Light.Holo.NoActionBar" />
<public type="style" name="Theme.Light.Holo.NoActionBar.Fullscreen" />
- <!-- A simple ListView item layout which can contain text and support (single or multiple) item selection. -->
- <public type="layout" name="simple_selectable_list_item" id="0x01090022" />
-
- <public type="string" name="selectTextMode" id="0x01040030" />
+ <public type="string" name="selectTextMode" />
</resources>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 8a9ebf0..70daee8 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -97,6 +97,8 @@
<item name="listChoiceBackgroundIndicator">@android:drawable/list_selected_background</item>
+ <item name="activatedBackgroundIndicator">@android:drawable/activated_background</item>
+
<item name="expandableListPreferredItemPaddingLeft">40dip</item>
<item name="expandableListPreferredChildPaddingLeft">
?android:attr/expandableListPreferredItemPaddingLeft</item>
@@ -272,6 +274,8 @@
<item name="editTextColor">?android:attr/textColorPrimary</item>
<item name="listChoiceBackgroundIndicator">@android:drawable/list_selected_background_light</item>
+ <item name="activatedBackgroundIndicator">@android:drawable/activated_background_light</item>
+
<item name="popupWindowStyle">@android:style/Widget.PopupWindow</item>
<item name="textCheckMark">@android:drawable/indicator_check_mark_light</item>