号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0

以下内容为反编译后的 ReceiptsPanel.java 源代码,内容仅作参考


package com.chinatelecom.pim.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chinatelecom.pim.R;
import com.chinatelecom.pim.core.CoreManagerFactory;
import com.chinatelecom.pim.foundation.lang.model.contact.Contact;
import com.chinatelecom.pim.foundation.lang.utils.ArrayUtils;
import com.chinatelecom.pim.foundation.lang.utils.DensityUtil;
import com.chinatelecom.pim.foundation.lang.utils.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ReceiptsPanel extends LinearLayout {
    private static final String SPLIT_TAG = ",";
    private List<Contact> contacts;
    private Context context;

    public List<Contact> getContacts() {
        return this.contacts;
    }

    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

    public ReceiptsPanel(Context context) {
        super(context);
        this.context = context;
    }

    public ReceiptsPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setupView();
    }

    private void setupView() {
        this.contacts = new ArrayList();
        Contact c1 = CoreManagerFactory.getInstance().getAddressBookManager().findContactByPhoneNumber("13301162052");
        Contact c2 = CoreManagerFactory.getInstance().getAddressBookManager().findContactByPhoneNumber("13301289696");
        Contact c3 = CoreManagerFactory.getInstance().getAddressBookManager().findContactByPhoneNumber("18911209503");
        addReceipt(c1);
        addReceipt(c2);
        addReceipt(c3);
    }

    public void addReceipt(final Contact contact) {
        this.contacts.add(contact);
        ReceiptItem item = new ReceiptItem(this.context, null, contact);
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ReceiptsPanel.this.removeView(view);
                ReceiptsPanel.this.removeReceipt(contact);
            }
        });
        addView(item);
    }

    public void removeReceipt(Contact contact) {
        this.contacts.remove(contact);
    }

    public class ReceiptItem extends RelativeLayout {
        public ReceiptItem(Context context, Contact c) {
            super(context);
            RelativeLayout view = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.receipt_item_layout, (ViewGroup) null);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
            params.setMargins(DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f));
            view.setLayoutParams(params);
            TextView receiptName = (TextView) view.findViewById(R.id.receipt_name);
            receiptName.setText(c.getName().getDisplayName());
            addView(view);
        }

        public ReceiptItem(Context context, AttributeSet attrs, Contact c) {
            super(context, attrs);
            RelativeLayout view = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.receipt_item_layout, (ViewGroup) null);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
            params.addRule(15);
            params.setMargins(DensityUtil.dip2px(context, 3.0f), 0, DensityUtil.dip2px(context, 3.0f), 0);
            view.setLayoutParams(params);
            params.setMargins(DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f), DensityUtil.dip2px(context, 3.0f));
            TextView receiptName = (TextView) view.findViewById(R.id.receipt_name);
            receiptName.setText(c.getName().getDisplayName());
            addView(view);
        }
    }

    public class DisplayItem {
        public String name;
        private int selectionEnd;
        public String tag;

        public DisplayItem(int selectionStart, String name, String tag) {
            this.selectionEnd = selectionStart;
            this.name = name;
            this.tag = tag;
        }

        public DisplayItem(String name, String tag) {
            this.name = name;
            this.tag = tag;
        }

        public boolean equals(Object o) {
            DisplayItem item = (DisplayItem) o;
            return StringUtils.equals(this.name, item.name) && StringUtils.equals(this.tag, item.tag);
        }

        public int hashCode() {
            return (this.name + "_" + this.tag).hashCode();
        }
    }

    private class DisplayItemChoice {
        private List<DisplayItem> itemList;

        private DisplayItemChoice() {
            this.itemList = new ArrayList();
        }

        public DisplayItemChoice(List<DisplayItem> items) {
            this.itemList = items;
        }

        public void add(int selStart, String name, String tag) {
            boolean equal = false;
            DisplayItem item = new DisplayItem(selStart, name, tag);
            Iterator<DisplayItem> it = this.itemList.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                DisplayItem displayItem = it.next();
                if (displayItem.equals(item)) {
                    equal = true;
                    break;
                }
            }
            if (!equal) {
                this.itemList.add(item);
            }
        }

        public boolean hasItem(String text, String tag) {
            for (DisplayItem displayItem : this.itemList) {
                if (displayItem.equals(new DisplayItem(text, tag))) {
                    return true;
                }
            }
            return false;
        }

        public void removeBySel(int sel) {
            Iterator<DisplayItem> it = this.itemList.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                DisplayItem displayItem = it.next();
                if (displayItem.selectionEnd == sel) {
                    this.itemList.remove(displayItem);
                    break;
                }
            }
            int index = 0;
            for (DisplayItem displayItem2 : this.itemList) {
                index = displayItem2.name.length() + index + ",".length();
                displayItem2.selectionEnd = index;
            }
        }

        public void remove() {
            remove(this.itemList.size() - 1);
        }

        public void remove(int i) {
            this.itemList.remove(i);
        }

        public void removeAll() {
            this.itemList.clear();
        }

        public DisplayItem getItem(int j) {
            return (DisplayItem) this.itemList.toArray()[j];
        }

        public String[] getDisplayNames() {
            List<String> array = new ArrayList<>();
            for (DisplayItem displayItem : this.itemList) {
                array.add(displayItem.name);
            }
            return (String[]) ArrayUtils.toArray(array, String.class);
        }

        public List<DisplayItem> getItemList() {
            return this.itemList;
        }
    }
}