Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5403fac authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Use image view when it's section header is a star

* Define mHeaderTextView as a View so that it can be ImageView and TextView
  and rename it as mHeaderView.
* Hide pinned header when it's a star.
* Move section header to left by 14dp and make text and image center aligned.
* Make section header size 16sp.
* Make star pink.

Bug 28426878

Change-Id: I1aa563e5201e41487a7edd7cd861a62d8b662ff5
parent e808621e
Loading
Loading
Loading
Loading
+53 −27
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public class ContactListItemView extends ViewGroup
    private PhotoPosition mPhotoPosition = getDefaultPhotoPosition(false /* normal/non opposite */);

    // Header layout data
    private TextView mHeaderTextView;
    private View mHeaderView;
    private boolean mIsSectionHeaderEnabled;

    // The views inside the contact view
@@ -593,8 +593,8 @@ public class ContactListItemView extends ViewGroup
        height = Math.max(height, preferredHeight);

        // Measure the header if it is visible.
        if (mHeaderTextView != null && mHeaderTextView.getVisibility() == VISIBLE) {
            mHeaderTextView.measure(
        if (mHeaderView != null && mHeaderView.getVisibility() == VISIBLE) {
            mHeaderView.measure(
                    MeasureSpec.makeMeasureSpec(mHeaderWidth, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        }
@@ -617,11 +617,11 @@ public class ContactListItemView extends ViewGroup

        // Put the section header on the left side of the contact view.
        if (mIsSectionHeaderEnabled) {
            if (mHeaderTextView != null) {
                int headerHeight = mHeaderTextView.getMeasuredHeight();
            if (mHeaderView != null) {
                int headerHeight = mHeaderView.getMeasuredHeight();
                int headerTopBound = (bottomBound + topBound - headerHeight) / 2 + mTextOffsetTop;

                mHeaderTextView.layout(
                mHeaderView.layout(
                        isLayoutRtl ? rightBound - mHeaderWidth : leftBound,
                        headerTopBound,
                        isLayoutRtl ? rightBound : leftBound + mHeaderWidth,
@@ -975,28 +975,54 @@ public class ContactListItemView extends ViewGroup
     */
    public void setSectionHeader(String title) {
        if (!TextUtils.isEmpty(title)) {
            if (mHeaderTextView == null) {
                mHeaderTextView = new TextView(getContext());
                mHeaderTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle);
                mHeaderTextView.setGravity(
                        ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT);
                addView(mHeaderTextView);
            }
            setMarqueeText(mHeaderTextView, title);
            mHeaderTextView.setVisibility(View.VISIBLE);
            mHeaderTextView.setAllCaps(true);
            if (TextUtils.equals(getContext().getString(R.string.star_sign), title)) {
                if (mHeaderView == null || mHeaderView instanceof TextView) {
                    addStarImageHeader();
                }
            } else {
                if (mHeaderView == null || mHeaderView instanceof ImageView ) {
                    addTextHeader(title);
                } else {
                    updateHeaderText(((TextView) mHeaderView), title);
                }
            }
        } else if (mHeaderView != null) {
            mHeaderView.setVisibility(View.GONE);
        }
    }

    private void addTextHeader(String title) {
        removeView(mHeaderView);
        mHeaderView = new TextView(getContext());
        final TextView headerTextView = ((TextView) mHeaderView);
        headerTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle);
        headerTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        updateHeaderText(headerTextView, title);
        addView(headerTextView);
    }

    private void updateHeaderText(TextView headerTextView, String title) {
        setMarqueeText(headerTextView, title);
        headerTextView.setAllCaps(true);
        if (ContactsSectionIndexer.BLANK_HEADER_STRING.equals(title)) {
                // No name header (...)
                mHeaderTextView.setContentDescription(
            headerTextView.setContentDescription(
                    getContext().getString(R.string.description_no_name_header));
            } else if (getContext().getString(R.string.star_sign).equals(title)) {
                // Starred header
                mHeaderTextView.setContentDescription(
                        getContext().getString(R.string.list_filter_all_starred));
        }
        } else if (mHeaderTextView != null) {
            mHeaderTextView.setVisibility(View.GONE);
        headerTextView.setVisibility(View.VISIBLE);
    }

    private void addStarImageHeader() {
        removeView(mHeaderView);
        mHeaderView = new ImageView(getContext());
        final ImageView headerImageView = ((ImageView) mHeaderView);
        headerImageView.setImageDrawable(
                getResources().getDrawable(R.drawable.ic_material_star, getContext().getTheme()));
        headerImageView.setImageTintList(ColorStateList.valueOf(getResources()
                .getColor(R.color.material_star_pink)));
        headerImageView.setContentDescription(
                getContext().getString(R.string.list_filter_all_starred));
        headerImageView.setVisibility(View.VISIBLE);
        addView(headerImageView);
    }

    public void setIsSectionHeaderEnabled(boolean isSectionHeaderEnabled) {
+1 −2
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ public class ContactListPinnedHeaderView extends TextView {
        setTextAppearance(getContext(), R.style.SectionHeaderStyle);
        setLayoutParams(new LayoutParams(widthIncludingPadding, LayoutParams.WRAP_CONTENT));
        setLayoutDirection(parent.getLayoutDirection());
        setGravity(Gravity.CENTER_VERTICAL |
                (ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT));
        setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);

        // Apply text top offset. Multiply by two, because we are implementing this by padding for a
        // vertically centered view, rather than adjusting the position directly via a layout.
+8 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.contacts.common.list;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -28,7 +29,9 @@ import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.android.contacts.common.R;
import com.android.contacts.common.util.ViewUtil;

/**
@@ -312,7 +315,11 @@ public class PinnedHeaderListView extends AutoScrollListView
        if (child == null) return;

        PinnedHeader header = mHeaders[viewIndex];
        header.visible = true;
        // Hide header when it's a star.
        // TODO: try showing the view even when it's a star;
        // if we have to hide the star view, then try hiding it in some higher layer.
        header.visible = !TextUtils.equals(
                ((TextView) header.view).getText(), getContext().getString(R.string.star_sign));
        header.state = FADING;
        header.alpha = MAX_ALPHA;
        header.animating = false;