Editor.java revision 1b22073590c1801c3e6c7bde2f4636632a049f6c
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts.editor;
18
19import com.android.contacts.model.DataKind;
20import com.android.contacts.model.EntityDelta;
21import com.android.contacts.model.EntityDelta.ValuesDelta;
22
23import android.provider.ContactsContract.Data;
24
25/**
26 * Generic definition of something that edits a {@link Data} row through an
27 * {@link ValuesDelta} object.
28 */
29public interface Editor {
30    /**
31     * Listener for an {@link Editor}, usually to handle deleted items.
32     */
33    public interface EditorListener {
34        /**
35         * Called when the given {@link Editor} has been deleted.
36         */
37        public void onDeleted(Editor editor);
38
39        /**
40         * Called when the given {@link Editor} has a request, for example it
41         * wants to select a photo.
42         */
43        public void onRequest(int request);
44
45        public static final int REQUEST_PICK_PHOTO = 1;
46        public static final int FIELD_CHANGED = 2;
47
48        // The editor has switched between different representations of the same
49        // data, e.g. from full name to structured name
50        public static final int EDITOR_FORM_CHANGED = 3;
51    }
52
53    /**
54     * Returns whether or not there is at least one empty field (i.e. text
55     * fields) in this {@link Editor}.
56     */
57    public boolean hasEmptyField();
58
59    /**
60     * Prepares this editor for the given {@link ValuesDelta}, which
61     * builds any needed views. Any changes performed by the user will be
62     * written back to that same object.
63     */
64    public void setValues(DataKind kind, ValuesDelta values, EntityDelta state, boolean readOnly,
65            ViewIdGenerator vig);
66
67    public void setDeletable(boolean deletable);
68
69    /**
70     * Add a specific {@link EditorListener} to this {@link Editor}.
71     */
72    public void setEditorListener(EditorListener listener);
73
74    /**
75     * Called internally when the contents of a specific field have changed,
76     * allowing advanced editors to persist data in a specific way.
77     */
78    public void onFieldChanged(String column, String value);
79}
80