summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Huang <ath@google.com>2014-11-02 20:51:35 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-11-02 20:51:35 +0000
commit7168727c740d1f34fb31469b224184dd64b2eee0 (patch)
tree5d0098bb34abb41828a2aaca08a16c2c5c4c4657 /src
parenta12e4583c584a9cc24019109286ebd1563b716a5 (diff)
parent93b9408f1f0d1609c42010db14480c271dfe948a (diff)
downloadandroid_packages_apps_UnifiedEmail-7168727c740d1f34fb31469b224184dd64b2eee0.tar.gz
android_packages_apps_UnifiedEmail-7168727c740d1f34fb31469b224184dd64b2eee0.tar.bz2
android_packages_apps_UnifiedEmail-7168727c740d1f34fb31469b224184dd64b2eee0.zip
am 93b9408f: am a5be52c0: am 56aeb97f: am 8a819016: am bd16ec75: Merge "Programmatically set selected state to correspond to peeking conv" into ub-gmail-ur14-dev
* commit '93b9408f1f0d1609c42010db14480c271dfe948a': Programmatically set selected state to correspond to peeking conv
Diffstat (limited to 'src')
-rw-r--r--src/com/android/mail/browse/ConversationItemView.java50
-rw-r--r--src/com/android/mail/browse/SwipeableConversationItemView.java5
-rw-r--r--src/com/android/mail/ui/AnimatedAdapter.java8
-rw-r--r--src/com/android/mail/ui/ConversationListFragment.java47
-rw-r--r--src/com/android/mail/ui/SwipeableListView.java21
-rw-r--r--src/com/android/mail/ui/TwoPaneController.java4
6 files changed, 118 insertions, 17 deletions
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index 5f1dbd29b..65cf5ce33 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -58,6 +58,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.DecelerateInterpolator;
+import android.widget.ListView;
import android.widget.TextView;
import com.android.mail.R;
@@ -126,7 +127,7 @@ public class ConversationItemView extends View
private static Bitmap STATE_FORWARDED;
private static Bitmap STATE_REPLIED_AND_FORWARDED;
private static Bitmap STATE_CALENDAR_INVITE;
- private static Drawable VISIBLE_CONVERSATION_HIGHLIGHT;
+ private static Drawable FOCUSED_CONVERSATION_HIGHLIGHT;
private static String sSendersSplitToken;
private static String sElidedPaddingToken;
@@ -196,6 +197,7 @@ public class ConversationItemView extends View
private final TextView mSubjectTextView;
private final TextView mSnippetTextView;
private int mGadgetMode;
+ private int mAdapterPosition = ListView.INVALID_POSITION;
private static int sFoldersMaxCount;
private static TextAppearanceSpan sSubjectTextUnreadSpan;
@@ -431,7 +433,7 @@ public class ConversationItemView extends View
BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_forward_holo_light);
STATE_CALENDAR_INVITE =
BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light);
- VISIBLE_CONVERSATION_HIGHLIGHT = res.getDrawable(
+ FOCUSED_CONVERSATION_HIGHLIGHT = res.getDrawable(
R.drawable.visible_conversation_highlight);
// Initialize colors.
@@ -470,8 +472,9 @@ public class ConversationItemView extends View
final ConversationCheckedSet set, final Folder folder,
final int checkboxOrSenderImage,
final boolean swipeEnabled, final boolean importanceMarkersEnabled,
- final boolean showChevronsEnabled, final AnimatedAdapter adapter) {
+ final boolean showChevronsEnabled, final AnimatedAdapter adapter, int position) {
Utils.traceBeginSection("CIVC.bind");
+ mAdapterPosition = position;
bind(ConversationItemViewModel.forConversation(mAccount.getEmailAddress(), conversation),
activity, null /* conversationItemAreaClickListener */,
set, folder, checkboxOrSenderImage, swipeEnabled, importanceMarkersEnabled,
@@ -1273,19 +1276,49 @@ public class ConversationItemView extends View
}
// The focused bar
- if (isSelected() || isActivated()) {
- final int w = VISIBLE_CONVERSATION_HIGHLIGHT.getIntrinsicWidth();
+ final SwipeableListView listView = getListView();
+ if (listView != null && listView.isPositionSelected(getViewPosition())) {
+ final int w = FOCUSED_CONVERSATION_HIGHLIGHT.getIntrinsicWidth();
final boolean isRtl = ViewUtils.isViewRtl(this);
// This bar is on the right side of the conv list if it's RTL
- VISIBLE_CONVERSATION_HIGHLIGHT.setBounds(
+ FOCUSED_CONVERSATION_HIGHLIGHT.setBounds(
(isRtl) ? getWidth() - w : 0, 0,
(isRtl) ? getWidth() : w, getHeight());
- VISIBLE_CONVERSATION_HIGHLIGHT.draw(canvas);
+ FOCUSED_CONVERSATION_HIGHLIGHT.draw(canvas);
}
Utils.traceEndSection();
}
+ @Override
+ public void setSelected(boolean selected) {
+ // We catch the selected event here instead of using ListView#setOnItemSelectedListener
+ // because when the framework changes selection due to keyboard events, it sets the selected
+ // state, re-draw the affected views, and then call onItemSelected. That approach won't work
+ // because the view won't know about the new selected position during the re-draw.
+ if (selected) {
+ final SwipeableListView listView = getListView();
+ if (listView != null) {
+ listView.setSelectedPosition(getViewPosition());
+ }
+ }
+ super.setSelected(selected);
+ }
+
+ private int getViewPosition() {
+ if (mAdapterPosition != ListView.INVALID_POSITION) {
+ return mAdapterPosition;
+ } else {
+ final ListView listView = getListView();
+ final int position = listView != null ?
+ listView.getPositionForView(this) : ListView.INVALID_POSITION;
+ LogUtils.e(LOG_TAG,
+ "ConversationItemView didn't set position, using listview's position: %d",
+ position);
+ return position;
+ }
+ }
+
private void drawSendersImage(final Canvas canvas) {
if (!mSendersImageView.isFlipping()) {
final boolean showSenders = !mChecked;
@@ -1372,8 +1405,7 @@ public class ConversationItemView extends View
final SwipeableListView listView = getListView();
try {
- conv.position = mChecked && listView != null ? listView.getPositionForView(this)
- : Conversation.NO_POSITION;
+ conv.position = mChecked ? getViewPosition() : Conversation.NO_POSITION;
} catch (final NullPointerException e) {
// TODO(skennedy) Remove this if we find the root cause b/9527863
}
diff --git a/src/com/android/mail/browse/SwipeableConversationItemView.java b/src/com/android/mail/browse/SwipeableConversationItemView.java
index 10657f4f1..9db966906 100644
--- a/src/com/android/mail/browse/SwipeableConversationItemView.java
+++ b/src/com/android/mail/browse/SwipeableConversationItemView.java
@@ -56,9 +56,10 @@ public class SwipeableConversationItemView extends FrameLayout implements Toggle
final ConversationCheckedSet set, final Folder folder,
final int checkboxOrSenderImage, boolean swipeEnabled,
final boolean importanceMarkersEnabled, final boolean showChevronsEnabled,
- final AnimatedAdapter animatedAdapter) {
+ final AnimatedAdapter animatedAdapter, final int position) {
mConversationItemView.bind(conversation, activity, set, folder, checkboxOrSenderImage,
- swipeEnabled, importanceMarkersEnabled, showChevronsEnabled, animatedAdapter);
+ swipeEnabled, importanceMarkersEnabled, showChevronsEnabled, animatedAdapter,
+ position);
}
public void startUndoAnimation(AnimatorListener listener, boolean swipe) {
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index 2b38d27f8..86a3658bb 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -380,12 +380,12 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
}
public View createConversationItemView(SwipeableConversationItemView view, Context context,
- Conversation conv) {
+ Conversation conv, int position) {
if (view == null) {
view = new SwipeableConversationItemView(context, mAccount);
}
view.bind(conv, mActivity, mBatchConversations, mFolder, getCheckboxSetting(),
- mSwipeEnabled, mImportanceMarkersEnabled, mShowChevronsEnabled, this);
+ mSwipeEnabled, mImportanceMarkersEnabled, mShowChevronsEnabled, this, position);
return view;
}
@@ -556,7 +556,7 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
((SwipeableConversationItemView) convertView).reset();
}
final View v = createConversationItemView((SwipeableConversationItemView) convertView,
- mContext, conv);
+ mContext, conv, position);
Utils.traceEndSection();
return v;
}
@@ -790,7 +790,7 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
position, null, parent);
view.reset();
view.bind(conversation, mActivity, mBatchConversations, mFolder, getCheckboxSetting(),
- mSwipeEnabled, mImportanceMarkersEnabled, mShowChevronsEnabled, this);
+ mSwipeEnabled, mImportanceMarkersEnabled, mShowChevronsEnabled, this, position);
mAnimatingViews.put(conversation.id, view);
return view;
}
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index c72d225f0..d80cdf9ad 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -491,6 +491,14 @@ public final class ConversationListFragment extends Fragment implements
sb.append(mListAdapter);
sb.append(" folder=");
sb.append(mViewContext.folder);
+ if (mListView != null) {
+ sb.append(" selectedPos=");
+ sb.append(mListView.getSelectedPosition());
+ sb.append(" listSelectedPos=");
+ sb.append(mListView.getSelectedItemPosition());
+ sb.append(" isListInTouchMode=");
+ sb.append(mListView.isInTouchMode());
+ }
sb.append("}");
return sb.toString();
}
@@ -874,6 +882,45 @@ public final class ConversationListFragment extends Fragment implements
final int position = cursorPosition + mListAdapter.getPositionOffset(cursorPosition);
setRawActivated(position, different);
+ setRawSelected(position);
+ }
+
+ /**
+ * Set the selected conversation (used by the framework to indicate current focus in the list).
+ * @param cursorPosition The position of the conversation in the cursor (as opposed to
+ * in the list)
+ */
+ public void setSelected(final int cursorPosition) {
+ if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
+ return;
+ }
+
+ final int position = cursorPosition + mListAdapter.getPositionOffset(cursorPosition);
+ setRawSelected(position);
+ }
+
+ /**
+ * Set the selected conversation (used by the framework to indicate current focus in the list).
+ * @param position The position of the item in the list
+ */
+ private void setRawSelected(final int position) {
+ final View selectedView = mListView.getChildAt(
+ position - mListView.getFirstVisiblePosition());
+ // Don't do anything if the view is already selected.
+ if (!(selectedView != null && selectedView.isSelected())) {
+ final int firstVisible = mListView.getFirstVisiblePosition();
+ final int lastVisible = mListView.getLastVisiblePosition();
+ // Check if the view is off the screen
+ if (selectedView == null || position < firstVisible || position > lastVisible) {
+ mListView.setSelection(position);
+ } else {
+ // If the view is on screen, we call setSelectionFromTop with a top offset. This
+ // prevents the list from stupidly scrolling the item to the top because
+ // setSelection calls setSelectionFromTop with y = 0.
+ mListView.setSelectionFromTop(position, selectedView.getTop());
+ }
+ mListView.setSelectedPosition(position);
+ }
}
/**
diff --git a/src/com/android/mail/ui/SwipeableListView.java b/src/com/android/mail/ui/SwipeableListView.java
index fb5198ba1..b8406b3d8 100644
--- a/src/com/android/mail/ui/SwipeableListView.java
+++ b/src/com/android/mail/ui/SwipeableListView.java
@@ -72,6 +72,8 @@ public class SwipeableListView extends ListView implements Callback, OnScrollLis
private SwipeListener mSwipeListener;
+ private int mSelectedPosition = ListView.INVALID_POSITION;
+
// Instantiated through view inflation
@SuppressWarnings("unused")
public SwipeableListView(Context context) {
@@ -406,6 +408,25 @@ public class SwipeableListView extends ListView implements Callback, OnScrollLis
return mScrolling;
}
+ /**
+ * Set the currently selected (focused by the list view) position.
+ */
+ public void setSelectedPosition(int position) {
+ if (position == ListView.INVALID_POSITION) {
+ return;
+ }
+
+ mSelectedPosition = position;
+ }
+
+ public boolean isPositionSelected(int position) {
+ return mSelectedPosition != ListView.INVALID_POSITION && mSelectedPosition == position;
+ }
+
+ public int getSelectedPosition() {
+ return mSelectedPosition;
+ }
+
@Override
public void cancelDismissCounter() {
AnimatedAdapter adapter = getAnimatedAdapter();
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index abcb9a594..2af141a75 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -650,10 +650,10 @@ public final class TwoPaneController extends AbstractActivityController implemen
super.setCurrentConversation(conversation);
final ConversationListFragment convList = getConversationListFragment();
- if (convList != null && conversation != null) {
+ if (different && convList != null && conversation != null) {
if (mCurrentConversationJustPeeking) {
convList.clearChoicesAndActivated();
- // TODO: set the list highlight to this new item
+ convList.setSelected(conversation.position);
} else {
convList.setActivated(conversation.position, different);
}