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