diff options
Diffstat (limited to 'src/com')
5 files changed, 69 insertions, 33 deletions
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java index 805ee3956..316c69529 100644 --- a/src/com/android/contacts/detail/ContactDetailFragment.java +++ b/src/com/android/contacts/detail/ContactDetailFragment.java @@ -1338,7 +1338,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen } @Override - public boolean shouldCollapseWith(DetailViewEntry entry) { + public boolean shouldCollapseWith(DetailViewEntry entry, Context context) { if (entry == null) { return false; } @@ -1357,10 +1357,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen return true; } - public boolean shouldCollapseWith(DetailViewEntry entry, Context context) { - return false; - } - @Override public void click(View clickedView, Listener fragmentListener) { if (fragmentListener == null || intent == null) return; @@ -2027,7 +2023,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen final long defaultGroupId = getDefaultGroupId(groups); if (defaultGroupId == -1) return false; - final RawContact rawContact = (RawContact) mContactData.getRawContacts().get(0); + final RawContact rawContact = mContactData.getRawContacts().get(0); final AccountType type = rawContact.getAccountType(getContext()); // Offline or non-writeable account? Nothing to fix if (type == null || !type.areContactsWritable()) return false; diff --git a/src/com/android/contacts/quickcontact/DataAction.java b/src/com/android/contacts/quickcontact/DataAction.java index 37021ec7c..b590814f4 100644 --- a/src/com/android/contacts/quickcontact/DataAction.java +++ b/src/com/android/contacts/quickcontact/DataAction.java @@ -315,7 +315,7 @@ public class DataAction implements Action { } @Override - public boolean shouldCollapseWith(Action t) { + public boolean shouldCollapseWith(Action t, Context context) { if (t == null) { return false; } @@ -334,10 +334,6 @@ public class DataAction implements Action { return true; } - public boolean shouldCollapseWith(Action t, Context context) { - return false; - } - @Override public Integer getTimesUsed() { return mTimesUsed; diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java index 209284f20..390fc2843 100644 --- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java +++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java @@ -112,6 +112,10 @@ public class ExpandingEntryCardView extends LinearLayout { } } + public interface ExpandingEntryCardViewListener { + void onCollapse(int heightDelta); + } + private View mExpandCollapseButton; private TextView mExpandCollapseTextView; private TextView mTitleTextView; @@ -120,6 +124,7 @@ public class ExpandingEntryCardView extends LinearLayout { private OnClickListener mOnClickListener; private boolean mIsExpanded = false; private int mCollapsedEntriesCount; + private ExpandingEntryCardViewListener mListener; private List<Entry> mEntries; private List<View> mEntryViews; private LinearLayout mEntriesViewGroup; @@ -169,12 +174,13 @@ public class ExpandingEntryCardView extends LinearLayout { * @param entries The Entry list to display. */ public void initialize(List<Entry> entries, int numInitialVisibleEntries, - boolean isExpanded) { + boolean isExpanded, ExpandingEntryCardViewListener listener) { LayoutInflater layoutInflater = LayoutInflater.from(getContext()); mIsExpanded = isExpanded; mEntries = entries; mEntryViews = new ArrayList<View>(entries.size()); mCollapsedEntriesCount = Math.min(numInitialVisibleEntries, entries.size()); + mListener = listener; if (mIsExpanded) { updateExpandCollapseButton(getCollapseButtonText()); @@ -415,6 +421,7 @@ public class ExpandingEntryCardView extends LinearLayout { private void collapse() { int startingHeight = mEntriesViewGroup.getHeight(); int finishHeight = measureCollapsedViewGroupHeight(); + mListener.onCollapse(startingHeight - finishHeight); mIsExpanded = false; updateExpandCollapseButton(getExpandButtonText()); diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java index e21a8c863..975ec65f2 100644 --- a/src/com/android/contacts/quickcontact/QuickContactActivity.java +++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java @@ -90,6 +90,7 @@ import com.android.contacts.interactions.ContactDeletionInteraction; import com.android.contacts.interactions.ContactInteraction; import com.android.contacts.interactions.SmsInteractionsLoader; import com.android.contacts.quickcontact.ExpandingEntryCardView.Entry; +import com.android.contacts.quickcontact.ExpandingEntryCardView.ExpandingEntryCardViewListener; import com.android.contacts.util.ImageViewDrawableSetter; import com.android.contacts.util.SchedulingUtils; import com.android.contacts.widget.MultiShrinkScroller; @@ -234,6 +235,14 @@ public class QuickContactActivity extends ContactsActivity { } }; + final ExpandingEntryCardViewListener mExpandingEntryCardViewListener + = new ExpandingEntryCardViewListener() { + @Override + public void onCollapse(int heightDelta) { + mScroller.prepareForShrinkingScrollChild(heightDelta); + } + }; + /** * Headless fragment used to handle account selection callbacks invoked from * {@link DirectoryContactUtil}. @@ -477,15 +486,15 @@ public class QuickContactActivity extends ContactsActivity { /** Assign this string to the view if it is not empty. */ private void setHeaderNameText(int resId) { if (mScroller != null) { - mScroller.setTitle(String.valueOf(getText(resId))); + mScroller.setTitle(getText(resId) == null ? null : getText(resId).toString()); } } /** Assign this string to the view if it is not empty. */ - private void setHeaderNameText(CharSequence value) { + private void setHeaderNameText(String value) { if (!TextUtils.isEmpty(value)) { if (mScroller != null) { - mScroller.setTitle(value.toString()); + mScroller.setTitle(value); } } } @@ -586,7 +595,7 @@ public class QuickContactActivity extends ContactsActivity { if (entries.size() > 0) { mCommunicationCard.initialize(entries, /* numInitialVisibleEntries = */ MIN_NUM_COMMUNICATION_ENTRIES_SHOWN, - /* isExpanded = */ false); + /* isExpanded = */ false, mExpandingEntryCardViewListener); } final boolean hasData = !entries.isEmpty(); @@ -890,29 +899,21 @@ public class QuickContactActivity extends ContactsActivity { private List<Entry> actionsToEntries(List<Action> actions) { List<Entry> entries = new ArrayList<>(); for (Action action : actions) { - String header = null; + final String header = action.getBody() == null ? null : action.getBody().toString(); + final String footer = action.getBody() == null ? null : action.getBody().toString(); String body = null; - String footer = null; Drawable icon = null; switch (action.getMimeType()) { case Phone.CONTENT_ITEM_TYPE: - header = String.valueOf(action.getBody()); - footer = String.valueOf(action.getSubtitle()); icon = getResources().getDrawable(R.drawable.ic_phone_24dp); break; case Email.CONTENT_ITEM_TYPE: - header = String.valueOf(action.getBody()); - footer = String.valueOf(action.getSubtitle()); icon = getResources().getDrawable(R.drawable.ic_email_24dp); break; case StructuredPostal.CONTENT_ITEM_TYPE: - header = String.valueOf(action.getBody()); - footer = String.valueOf(action.getSubtitle()); icon = getResources().getDrawable(R.drawable.ic_place_24dp); break; default: - header = String.valueOf(action.getSubtitle()); - footer = String.valueOf(action.getBody()); icon = ResolveCache.getInstance(this).getIcon(action); } entries.add(new Entry(icon, header, body, footer, action.getIntent(), @@ -1087,7 +1088,7 @@ public class QuickContactActivity extends ContactsActivity { if (allInteractions.size() > 0) { mRecentCard.initialize(contactInteractionsToEntries(allInteractions), /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN, - /* isExpanded = */ false); + /* isExpanded = */ false, mExpandingEntryCardViewListener); mRecentCard.setVisibility(View.VISIBLE); } } diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java index 9163d2352..67fbf3cc2 100644 --- a/src/com/android/contacts/widget/MultiShrinkScroller.java +++ b/src/com/android/contacts/widget/MultiShrinkScroller.java @@ -494,6 +494,26 @@ public class MultiShrinkScroller extends LinearLayout { } /** + * Change the height of the header/toolbar. Do *not* use this outside animations. This was + * designed for use by {@link #prepareForShrinkingScrollChild}. + */ + @NeededForReflection + public void setToolbarHeight(int delta) { + final LinearLayout.LayoutParams toolbarLayoutParams + = (LayoutParams) mToolbar.getLayoutParams(); + toolbarLayoutParams.height = delta; + mToolbar.setLayoutParams(toolbarLayoutParams); + + updatePhotoTintAndDropShadow(); + updateHeaderTextSize(); + } + + @NeededForReflection + public int getToolbarHeight() { + return mToolbar.getLayoutParams().height; + } + + /** * Set the height of the toolbar and update its tint accordingly. */ @NeededForReflection @@ -673,14 +693,17 @@ public class MultiShrinkScroller extends LinearLayout { * allow the the ScrollView to scroll unless there is new content off of the edge of ScrollView. */ private int getFullyCompressedHeaderHeight() { - final LinearLayout.LayoutParams toolbarLayoutParams - = (LayoutParams) mToolbar.getLayoutParams(); + return Math.min(Math.max(mToolbar.getLayoutParams().height - getOverflowingChildViewSize(), + mMinimumHeaderHeight), mIntermediateHeaderHeight); + } + + /** + * Returns the amount of mScrollViewChild that doesn't fit inside its parent. + */ + private int getOverflowingChildViewSize() { final int usedScrollViewSpace = mScrollViewChild.getHeight() - mLeftOverSpaceView.getHeight(); - final int leftOverSpace = -getHeight() + usedScrollViewSpace + toolbarLayoutParams.height; - return Math.min( - Math.max(toolbarLayoutParams.height - leftOverSpace, mMinimumHeaderHeight), - mIntermediateHeaderHeight); + return -getHeight() + usedScrollViewSpace + mToolbar.getLayoutParams().height; } private void scrollDown(int delta) { @@ -979,4 +1002,17 @@ public class MultiShrinkScroller extends LinearLayout { return (long)(1000 / getRefreshRate()); } } + + /** + * Expand the header if the mScrollViewChild is about to shrink by enough to create new empty + * space at the bottom of this ViewGroup. + */ + public void prepareForShrinkingScrollChild(int heightDelta) { + final int newEmptyScrollViewSpace = -getOverflowingChildViewSize() + heightDelta; + if (newEmptyScrollViewSpace > 0 && !mIsTwoPanel) { + final int newDesiredToolbarHeight = Math.min(mToolbar.getLayoutParams().height + + newEmptyScrollViewSpace, mIntermediateHeaderHeight); + ObjectAnimator.ofInt(this, "toolbarHeight", newDesiredToolbarHeight).start(); + } + } } |