KindSectionView.java revision 9e83c84a7603eb6fca1b42631d894731d61f7a34
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;
30aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.provider.ContactsContract.Data;
31aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.util.AttributeSet;
329e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.util.DisplayMetrics;
339e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.util.TypedValue;
34aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.view.LayoutInflater;
35aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.view.View;
36aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.view.ViewGroup;
379e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmannimport android.view.WindowManager;
38da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmannimport android.widget.ImageView;
39aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.widget.LinearLayout;
40aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.widget.TextView;
41aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
42aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey/**
43aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Custom view for an entire section of data as segmented by
44aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * {@link DataKind} around a {@link Data#MIMETYPE}. This view shows a
45aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * section header and a trigger for adding new {@link Data} rows.
46aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey */
47bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmannpublic class KindSectionView extends LinearLayout implements EditorListener {
48aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private static final String TAG = "KindSectionView";
499e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    private static int sCachedThemePaddingRight = -1;
50aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
51aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private ViewGroup mEditors;
52aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private View mAdd;
53da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann    private ImageView mAddPlusButton;
54aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private TextView mTitle;
55aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
56aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private DataKind mKind;
57aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    private EntityDelta mState;
5892525ff51e2cb06531447a7dcde5e22334669c8eMegha Joshi    private boolean mReadOnly;
596f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
604b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki    private ViewIdGenerator mViewIdGenerator;
614b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki
62aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public KindSectionView(Context context) {
63aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        super(context);
64aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
65aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
66aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public KindSectionView(Context context, AttributeSet attrs) {
67aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        super(context, attrs);
68aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
69aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
70aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    /** {@inheritDoc} */
71aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    @Override
72aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    protected void onFinishInflate() {
73aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        setDrawingCacheEnabled(true);
74aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        setAlwaysDrawnWithCacheEnabled(true);
75aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
76aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mEditors = (ViewGroup)findViewById(R.id.kind_editors);
77aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
78aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mAdd = findViewById(R.id.kind_header);
79bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        mAdd.setOnClickListener(new OnClickListener() {
80bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann            public void onClick(View v) {
81bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann                addItem();
82bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann            }
83bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        });
84aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
85da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        mAddPlusButton = (ImageView) findViewById(R.id.kind_plus);
86da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
87aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mTitle = (TextView)findViewById(R.id.kind_title);
88aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
89aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
906f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey    /** {@inheritDoc} */
91aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public void onDeleted(Editor editor) {
92bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateAddEnabled();
93bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateEditorsVisible();
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        updateEditorsVisible();
119bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateVisible();
120bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
121bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
122bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public CharSequence getTitle() {
123bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mTitle.getText();
124aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
125aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
126bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public boolean getFieldCount() {
1273122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        if (mState == null) {
1283122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann            return false;
1293122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        }
1303122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann
1313122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        if (!mState.hasMimeEntries(mKind.mimeType)) {
1323122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann            return false;
1333122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        }
1343122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann
135bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        int editorCount = getEditorCount();
1363122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        for (int i = 0; i < editorCount; i++) {
1373122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann            GenericEditorView editorView = (GenericEditorView) mEditors.getChildAt(i);
1383122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann            if (editorView.isAnyFieldFilledOut()) {
1393122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann                return true;
1403122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann            }
1413122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        }
1423122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann
1433122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann        return false;
1443122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann    }
1453122da4be743517f04b6f7159bd39f89f87563ceDaniel Lehmann
146aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    /**
147aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey     * Build editors for all current {@link #mState} rows.
148aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey     */
149aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    public void rebuildFromState() {
150aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Remove any existing editors
151aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mEditors.removeAllViews();
152aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
153da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        // Check if we are displaying anything here
154da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
155da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
156da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        if (hasEntries) {
157da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            int entryIndex = 0;
158da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
159da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                // Skip entries that aren't visible
160da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                if (!entry.isVisible()) continue;
161da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
1629e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                final GenericEditorView editor = new GenericEditorView(mContext);
1639e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
1649e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                editor.setPadding(0, 0, getThemeScrollbarSize(mContext), 0);
165da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
166da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                editor.setEditorListener(this);
1679e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                editor.setDeletable(true);
168da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                mEditors.addView(editor);
169da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann                entryIndex++;
170da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            }
171aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        }
172aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
173aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
1749e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    /**
1759e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann     * Reads the scrollbarSize of the current theme
1769e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann     */
1779e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    private static int getThemeScrollbarSize(Context context) {
1789e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        if (sCachedThemePaddingRight == -1) {
1799e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final TypedValue outValue = new TypedValue();
1809e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            context.getTheme().resolveAttribute(android.R.attr.scrollbarSize, outValue, true);
1819e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final WindowManager windowManager =
1829e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann                    (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
1839e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            final DisplayMetrics metrics = new DisplayMetrics();
1849e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            windowManager.getDefaultDisplay().getMetrics(metrics);
1859e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann            sCachedThemePaddingRight = (int) TypedValue.complexToDimension(outValue.data, metrics);
1869e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        }
1879e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
1889e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        return sCachedThemePaddingRight;
1899e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann    }
1909e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann
191aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    protected void updateEditorsVisible() {
192bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        final boolean hasChildren = getEditorCount() > 0;
193aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE);
194aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
195aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey
196bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    private void updateVisible() {
197bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        setVisibility(getEditorCount() != 0 ? VISIBLE : GONE);
198bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
199bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
200bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
201aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    protected void updateAddEnabled() {
202aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Set enabled state on the "add" view
203aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        final boolean canInsert = EntityModifier.canInsert(mState, mKind);
204da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann        final boolean isEnabled = !mReadOnly && canInsert;
20592525ff51e2cb06531447a7dcde5e22334669c8eMegha Joshi        mAdd.setEnabled(isEnabled);
206aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
2076f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey
208bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public void addItem() {
209bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        // if this is a list, we can freely add. if not, only allow adding the first
210bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        if (!mKind.isList && getEditorCount() == 1)
211da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann            return;
212da5fd9039bd303f5e4634a31ed9a00d58d679b39Daniel Lehmann
2139e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
214eeac4dc8dccb20466669525f16dc58fa593a3483Daniel Lehmann
215aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey        // Insert a new child and rebuild
2164b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
217bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        rebuildFromState();
218bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateAddEnabled();
219bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateEditorsVisible();
2204b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki
2214b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        // Find the newly added EditView and set focus.
2224b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final int newFieldId = mViewIdGenerator.getId(mState, mKind, newValues, 0);
2234b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        final View newField = findViewById(newFieldId);
2244b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        if (newField != null) {
2254b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki            newField.requestFocus();
2264b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki        }
227eeac4dc8dccb20466669525f16dc58fa593a3483Daniel Lehmann
228bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        updateVisible();
229bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
2309e83c84a7603eb6fca1b42631d894731d61f7a34Daniel Lehmann        animator.animate();
231bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
232bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
233bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public int getEditorCount() {
234bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mEditors.getChildCount();
235bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    }
236bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann
237bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann    public DataKind getKind() {
238bb556954e29ae0700b729f128d8cd09ecdd91ee3Daniel Lehmann        return mKind;
239aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey    }
240aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey}
241