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 17 package com.android.contacts.ui.widget; 18 19 import com.android.contacts.model.ContactsSource; 20 import com.android.contacts.model.EntityDelta; 21 import com.android.contacts.model.EntityModifier; 22 import com.android.contacts.model.ContactsSource.EditType; 23 import com.android.contacts.model.Editor.EditorListener; 24 import com.android.contacts.model.EntityDelta.ValuesDelta; 25 26 import android.content.Context; 27 import android.content.Entity; 28 import android.graphics.Bitmap; 29 import android.provider.ContactsContract.Data; 30 import android.provider.ContactsContract.RawContacts; 31 import android.provider.ContactsContract.CommonDataKinds.Photo; 32 import android.util.AttributeSet; 33 import android.view.LayoutInflater; 34 import android.widget.LinearLayout; 35 36 /** 37 * Base view that provides common code for the editor interaction for a specific 38 * RawContact represented through an {@link EntityDelta}. Callers can 39 * reuse this view and quickly rebuild its contents through 40 * {@link #setState(EntityDelta, ContactsSource)}. 41 * <p> 42 * Internal updates are performed against {@link ValuesDelta} so that the 43 * source {@link Entity} can be swapped out. Any state-based changes, such as 44 * adding {@link Data} rows or changing {@link EditType}, are performed through 45 * {@link EntityModifier} to ensure that {@link ContactsSource} are enforced. 46 */ 47 public abstract class BaseContactEditorView extends LinearLayout { 48 protected LayoutInflater mInflater; 49 50 protected PhotoEditorView mPhoto; 51 protected boolean mHasPhotoEditor = false; 52 BaseContactEditorView(Context context)53 public BaseContactEditorView(Context context) { 54 super(context); 55 } 56 BaseContactEditorView(Context context, AttributeSet attrs)57 public BaseContactEditorView(Context context, AttributeSet attrs) { 58 super(context, attrs); 59 } 60 61 /** 62 * Assign the given {@link Bitmap} to the internal {@link PhotoEditorView} 63 * for the {@link EntityDelta} currently being edited. 64 */ setPhotoBitmap(Bitmap bitmap)65 public void setPhotoBitmap(Bitmap bitmap) { 66 mPhoto.setPhotoBitmap(bitmap); 67 } 68 69 /** 70 * Return true if the current {@link RawContacts} supports {@link Photo}, 71 * which means that {@link PhotoEditorView} is enabled. 72 */ hasPhotoEditor()73 public boolean hasPhotoEditor() { 74 return mHasPhotoEditor; 75 } 76 77 /** 78 * Return true if internal {@link PhotoEditorView} has a {@link Photo} set. 79 */ hasSetPhoto()80 public boolean hasSetPhoto() { 81 return mPhoto.hasSetPhoto(); 82 } 83 getPhotoEditor()84 public PhotoEditorView getPhotoEditor() { 85 return mPhoto; 86 } 87 88 /** 89 * @return the RawContact ID that this editor is editing. 90 */ getRawContactId()91 public abstract long getRawContactId(); 92 93 /** 94 * Set the internal state for this view, given a current 95 * {@link EntityDelta} state and the {@link ContactsSource} that 96 * apply to that state. 97 */ setState(EntityDelta state, ContactsSource source)98 public abstract void setState(EntityDelta state, ContactsSource source); 99 100 /** 101 * Sets the {@link EditorListener} on the name field 102 */ setNameEditorListener(EditorListener listener)103 public abstract void setNameEditorListener(EditorListener listener); 104 } 105