KindSectionView.java revision 3e7436450f0fdd5ad939c3b46e7176e082c9ee11
1aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey/*
2aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Copyright (C) 2009 The Android Open Source Project
3aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey *
4aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License");
5aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * you may not use this file except in compliance with the License.
6aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * You may obtain a copy of the License at
7aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey *
8aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey *      http://www.apache.org/licenses/LICENSE-2.0
9aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey *
10aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Unless required by applicable law or agreed to in writing, software
11aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS,
12aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * See the License for the specific language governing permissions and
14aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * limitations under the License.
15aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey */
16aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
17aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeypackage com.android.contacts.ui.widget;
18aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
19aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.R;
20aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.Editor;
21aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.EntityDelta;
22aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.EntityModifier;
23aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.ContactsSource.DataKind;
24aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.Editor.EditorListener;
25aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport com.android.contacts.model.EntityDelta.ValuesDelta;
264b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onukiimport com.android.contacts.ui.ViewIdGenerator;
279e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport com.android.contacts.util.ViewGroupAnimator;
28aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
29aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.content.Context;
303e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmannimport android.opengl.Texture;
31aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.provider.ContactsContract.Data;
323e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmannimport android.text.TextUtils;
33aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.util.AttributeSet;
349e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.util.DisplayMetrics;
359e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.util.TypedValue;
36aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.view.View;
37aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.view.ViewGroup;
389e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.view.WindowManager;
39da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmannimport android.widget.ImageView;
40aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.widget.LinearLayout;
41aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.widget.TextView;
42aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
43aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey/**
44aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Custom view for an entire section of data as segmented by
45aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * {@link DataKind} around a {@link Data#MIMETYPE}. This view shows a
46aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * section header and a trigger for adding new {@link Data} rows.
47aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey */
48bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmannpublic class KindSectionView extends LinearLayout implements EditorListener {
49aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private static final String TAG = "KindSectionView";
509e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    private static int sCachedThemePaddingRight = -1;
51aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
52aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private ViewGroup mEditors;
53aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private View mAdd;
54da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann    private ImageView mAddPlusButton;
55aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private TextView mTitle;
56aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
57aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private DataKind mKind;
58aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private EntityDelta mState;
5992525ff51e2cb06531447a7dcde5e22334669c8eMegha Joshi    private boolean mReadOnly;
606f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
614b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki    private ViewIdGenerator mViewIdGenerator;
624b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki
63aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public KindSectionView(Context context) {
64aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        super(context);
65aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
66aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
67aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public KindSectionView(Context context, AttributeSet attrs) {
68aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        super(context, attrs);
69aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
70aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
71aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    /** {@inheritDoc} */
72aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    @Override
73aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    protected void onFinishInflate() {
74aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        setDrawingCacheEnabled(true);
75aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        setAlwaysDrawnWithCacheEnabled(true);
76aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
77aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mEditors = (ViewGroup)findViewById(R.id.kind_editors);
78aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
79aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mAdd = findViewById(R.id.kind_header);
80bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        mAdd.setOnClickListener(new OnClickListener() {
81bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann            public void onClick(View v) {
82bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann                addItem();
83bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann            }
84bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        });
85aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
86da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        mAddPlusButton = (ImageView) findViewById(R.id.kind_plus);
87da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
88aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mTitle = (TextView)findViewById(R.id.kind_title);
89aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
90aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
916f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    /** {@inheritDoc} */
92aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public void onDeleted(Editor editor) {
93bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateAddEnabled();
94bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateVisible();
95aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
96aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
976f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    /** {@inheritDoc} */
986f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    public void onRequest(int request) {
996f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey        // Ignore requests
1006f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    }
1016f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
1024b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki    public void setState(DataKind kind, EntityDelta state, boolean readOnly, ViewIdGenerator vig) {
103aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mKind = kind;
104aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mState = state;
10592525ff51e2cb06531447a7dcde5e22334669c8eMegha Joshi        mReadOnly = readOnly;
1064b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        mViewIdGenerator = vig;
1074b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki
1084b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        setId(mViewIdGenerator.getId(state, kind, null, ViewIdGenerator.NO_VIEW_INDEX));
109aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
110aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // TODO: handle resources from remote packages
111aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mTitle.setText(kind.titleRes);
112aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
113da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        // Only show the add button if this is a list
114da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        mAddPlusButton.setVisibility(mKind.isList ? View.VISIBLE : View.GONE);
115da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
116bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        rebuildFromState();
117bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateAddEnabled();
118bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateVisible();
119bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
120bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
121bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public CharSequence getTitle() {
122bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mTitle.getText();
123aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
124aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
125aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    /**
126aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey     * Build editors for all current {@link #mState} rows.
127aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey     */
128aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public void rebuildFromState() {
129aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Remove any existing editors
130aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mEditors.removeAllViews();
131aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
132da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        // Check if we are displaying anything here
133da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
134da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
135da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        if (hasEntries) {
136da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            int entryIndex = 0;
137da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
138da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                // Skip entries that aren't visible
139da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                if (!entry.isVisible()) continue;
1403e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann                if (isEmptyNoop(entry)) continue;
141da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
1429e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                final GenericEditorView editor = new GenericEditorView(mContext);
1439e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
1449e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                editor.setPadding(0, 0, getThemeScrollbarSize(mContext), 0);
145da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
146da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                editor.setEditorListener(this);
1479e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                editor.setDeletable(true);
148da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                mEditors.addView(editor);
149da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                entryIndex++;
150da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            }
151aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        }
152aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
153aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
1549e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    /**
1553e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann     * Tests whether the given item has no changes (so it exists in the database) but is empty
1563e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann     */
1573e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann    private boolean isEmptyNoop(ValuesDelta item) {
1583e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann        if (!item.isNoop()) return false;
1593e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann        final int fieldCount = mKind.fieldList.size();
1603e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann        for (int i = 0; i < fieldCount; i++) {
1613e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann            final String column = mKind.fieldList.get(i).column;
1623e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann            final String value = item.getAsString(column);
1633e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann            if (!TextUtils.isEmpty(value)) return false;
1643e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann        }
1653e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann        return true;
1663e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann    }
1673e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann
1683e7436450f0fdd5ad939c3b46e7176e082c9ee11Daniel Lehmann    /**
1699e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann     * Reads the scrollbarSize of the current theme
1709e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann     */
1719e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    private static int getThemeScrollbarSize(Context context) {
1729e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        if (sCachedThemePaddingRight == -1) {
1739e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final TypedValue outValue = new TypedValue();
1749e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            context.getTheme().resolveAttribute(android.R.attr.scrollbarSize, outValue, true);
1759e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final WindowManager windowManager =
1769e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                    (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
1779e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final DisplayMetrics metrics = new DisplayMetrics();
1789e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            windowManager.getDefaultDisplay().getMetrics(metrics);
1799e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            sCachedThemePaddingRight = (int) TypedValue.complexToDimension(outValue.data, metrics);
1809e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        }
1819e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
1829e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        return sCachedThemePaddingRight;
1839e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    }
1849e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
185bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    private void updateVisible() {
186bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        setVisibility(getEditorCount() != 0 ? VISIBLE : GONE);
187bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
188bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
189bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
190aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    protected void updateAddEnabled() {
191aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Set enabled state on the "add" view
192aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        final boolean canInsert = EntityModifier.canInsert(mState, mKind);
193da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        final boolean isEnabled = !mReadOnly && canInsert;
19492525ff51e2cb06531447a7dcde5e22334669c8eMegha Joshi        mAdd.setEnabled(isEnabled);
195aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
1966f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
197bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public void addItem() {
198bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        // if this is a list, we can freely add. if not, only allow adding the first
199bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        if (!mKind.isList && getEditorCount() == 1)
200da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            return;
201da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
2029e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
203eeac4dc8dccb20466669525f16dc58fa593a3483Daniel Lehmann
204aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Insert a new child and rebuild
2054b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
206bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        rebuildFromState();
207bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateAddEnabled();
2084b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki
2094b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        // Find the newly added EditView and set focus.
2104b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final int newFieldId = mViewIdGenerator.getId(mState, mKind, newValues, 0);
2114b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final View newField = findViewById(newFieldId);
2124b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        if (newField != null) {
2134b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki            newField.requestFocus();
2144b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        }
215eeac4dc8dccb20466669525f16dc58fa593a3483Daniel Lehmann
216bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateVisible();
217bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
2189e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        animator.animate();
219bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
220bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
221bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public int getEditorCount() {
222bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mEditors.getChildCount();
223bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
224bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
225bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public DataKind getKind() {
226bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mKind;
227aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
228aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey}
229