summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWalter Jang <wjang@google.com>2015-02-24 09:18:16 -0800
committerWalter Jang <wjang@google.com>2015-02-24 14:19:15 -0800
commitd35e5eff8737e757a4179d49dfe9c7db999b4e9d (patch)
treee93e320efd34dd5b6106170967ae9322e1fab954 /src
parenta5e4bb287ea08f895c84d5de56fcc2483386b306 (diff)
downloadpackages_apps_Contacts-d35e5eff8737e757a4179d49dfe9c7db999b4e9d.tar.gz
packages_apps_Contacts-d35e5eff8737e757a4179d49dfe9c7db999b4e9d.tar.bz2
packages_apps_Contacts-d35e5eff8737e757a4179d49dfe9c7db999b4e9d.zip
Get join suggestions for the compact editor name field
Also fix photo height in portrait -- made a mistake in ag/641233. Bug 19124091 Change-Id: I988cbcf457002bc6f0996c87a8611fca82bdf78a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/editor/CompactContactEditorFragment.java38
-rw-r--r--src/com/android/contacts/editor/CompactPhotoEditorView.java2
-rw-r--r--src/com/android/contacts/editor/CompactRawContactsEditorView.java18
-rw-r--r--src/com/android/contacts/editor/ContactEditorBaseFragment.java28
-rw-r--r--src/com/android/contacts/editor/ContactEditorFragment.java17
-rw-r--r--src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java4
-rw-r--r--src/com/android/contacts/editor/LabeledEditorView.java4
-rw-r--r--src/com/android/contacts/editor/SuggestionEditConfirmationDialogFragment.java4
8 files changed, 80 insertions, 35 deletions
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index 514541642..cfed52ad5 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -26,6 +26,7 @@ import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.util.MaterialColorMapUtils;
import com.android.contacts.detail.PhotoSelectionHandler;
+import com.android.contacts.editor.Editor.EditorListener;
import com.android.contacts.util.ContactPhotoUtils;
import android.app.Activity;
@@ -204,16 +205,44 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
return;
}
+ // Add input fields for the loaded Contact
final CompactRawContactsEditorView editorView = getContent();
editorView.setListener(this);
editorView.setState(mState, mMaterialPalette, mViewIdGenerator);
- editorView.setEnabled(isEnabled());
- editorView.setVisibility(View.VISIBLE);
+ // Set up the photo widget
mPhotoHandler = createPhotoHandler();
mPhotoRawContactId = editorView.getPhotoRawContactId();
editorView.setPhotoHandler(mPhotoHandler);
+ // Attach the aggregation suggestion engine to the structured name field
+ final StructuredNameEditorView nameEditorView = editorView.getStructuredNameEditorView();
+ if (nameEditorView != null) {
+ nameEditorView.setEditorListener(new EditorListener() {
+ @Override
+ public void onRequest(int request) {
+ final Activity activity = getActivity();
+ if (activity == null || activity.isFinishing()) {
+ return;
+ }
+ if (request == EditorListener.FIELD_CHANGED && !mIsUserProfile) {
+ acquireAggregationSuggestions(activity, nameEditorView.getRawContactId(),
+ nameEditorView.getValues());
+ }
+ }
+
+ @Override
+ public void onDeleteRequested(Editor editor) {
+ }
+ });
+ }
+
+ // The editor is ready now so make it visible
+ editorView.setEnabled(isEnabled());
+ editorView.setVisibility(View.VISIBLE);
+
+ // Refresh the ActionBar as the visibility of the join command
+ // Activity can be null if we have been detached from the Activity.
invalidateOptionsMenu();
}
@@ -268,6 +297,11 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
}
@Override
+ protected View getAggregationAnchorView(long rawContactId) {
+ return getContent().getAggregationAnchorView();
+ }
+
+ @Override
protected void setGroupMetaData() {
// The compact editor does not support groups.
}
diff --git a/src/com/android/contacts/editor/CompactPhotoEditorView.java b/src/com/android/contacts/editor/CompactPhotoEditorView.java
index 38e4f8721..86a0ee80a 100644
--- a/src/com/android/contacts/editor/CompactPhotoEditorView.java
+++ b/src/com/android/contacts/editor/CompactPhotoEditorView.java
@@ -149,7 +149,7 @@ public class CompactPhotoEditorView extends LinearLayout implements View.OnClick
photoWidth = (int) (photoHeight * mLandscapePhotoRatio);
} else {
// Make the photo a square
- photoHeight = getHeight();
+ photoHeight = getWidth();
photoWidth = photoHeight;
}
final ViewGroup.LayoutParams layoutParams = getLayoutParams();
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index 44cf698ce..48e655bbc 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -70,6 +70,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
private AccountTypeManager mAccountTypeManager;
private LayoutInflater mLayoutInflater;
+
private ViewIdGenerator mViewIdGenerator;
private MaterialColorMapUtils.MaterialPalette mMaterialPalette;
@@ -82,7 +83,6 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
private ViewGroup mOther;
private View mMoreFields;
- // TODO: remove this after we handle account selection for photos
private long mPhotoRawContactId;
public CompactRawContactsEditorView(Context context) {
@@ -171,11 +171,25 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
/**
* Get the raw contact ID for the CompactHeaderView photo.
*/
- // TODO: remove me once we support multiple accounts
public long getPhotoRawContactId() {
return mPhotoRawContactId;
}
+ public StructuredNameEditorView getStructuredNameEditorView() {
+ // We only ever show one StructuredName
+ return mNames.getChildCount() == 0
+ ? null : (StructuredNameEditorView) mNames.getChildAt(0);
+ }
+
+ public View getAggregationAnchorView() {
+ // Since there is only one structured name we can just return it as the anchor for
+ // the aggregation suggestions popup
+ if (mNames.getChildCount() == 0) {
+ return null;
+ }
+ return mNames.getChildAt(0).findViewById(R.id.anchor_view);
+ }
+
public void setState(RawContactDeltaList rawContactDeltas,
MaterialColorMapUtils.MaterialPalette materialPalette,
ViewIdGenerator viewIdGenerator) {
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index d2f8aa74b..3ca492b42 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -1353,8 +1353,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
* Triggers an asynchronous search for aggregation suggestions.
*/
protected void acquireAggregationSuggestions(Context context,
- RawContactEditorView rawContactEditor) {
- long rawContactId = rawContactEditor.getRawContactId();
+ long rawContactId, ValuesDelta valuesDelta) {
if (mAggregationSuggestionsRawContactId != rawContactId
&& mAggregationSuggestionView != null) {
mAggregationSuggestionView.setVisibility(View.GONE);
@@ -1372,8 +1371,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
mAggregationSuggestionEngine.setContactId(getContactId());
- LabeledEditorView nameEditor = rawContactEditor.getNameEditor();
- mAggregationSuggestionEngine.onNameChange(nameEditor.getValues());
+ mAggregationSuggestionEngine.onNameChange(valuesDelta);
}
/**
@@ -1403,12 +1401,10 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
return;
}
- final RawContactEditorView rawContactView = (RawContactEditorView)
- getRawContactEditorView(mAggregationSuggestionsRawContactId);
- if (rawContactView == null) {
+ final View anchorView = getAggregationAnchorView(mAggregationSuggestionsRawContactId);
+ if (anchorView == null) {
return; // Raw contact deleted?
}
- final View anchorView = rawContactView.findViewById(R.id.anchor_view);
mAggregationSuggestionPopup = new ListPopupWindow(mContext, null);
mAggregationSuggestionPopup.setAnchorView(anchorView);
mAggregationSuggestionPopup.setWidth(anchorView.getWidth());
@@ -1432,20 +1428,10 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
}
/**
- * Finds raw contact editor view for the given rawContactId.
+ * Returns the raw contact editor view for the given rawContactId that should be used as the
+ * anchor for aggregation suggestions.
*/
- private BaseRawContactEditorView getRawContactEditorView(long rawContactId) {
- for (int i = 0; i < mContent.getChildCount(); i++) {
- final View childView = mContent.getChildAt(i);
- if (childView instanceof BaseRawContactEditorView) {
- final BaseRawContactEditorView editor = (BaseRawContactEditorView) childView;
- if (editor.getRawContactId() == rawContactId) {
- return editor;
- }
- }
- }
- return null;
- }
+ abstract protected View getAggregationAnchorView(long rawContactId);
/**
* Whether the given raw contact ID matches the one used to last load aggregation
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index c87be34a6..eb2de3ac2 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -48,9 +48,6 @@ import com.android.contacts.editor.Editor.EditorListener;
import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.UiClosables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.HashMap;
@@ -252,7 +249,9 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
return;
}
if (request == EditorListener.FIELD_CHANGED && !isEditingUserProfile()) {
- acquireAggregationSuggestions(activity, rawContactEditor);
+ acquireAggregationSuggestions(activity,
+ rawContactEditor.getNameEditor().getRawContactId(),
+ rawContactEditor.getNameEditor().getValues());
} else if (request == EditorListener.EDITOR_FOCUS_CHANGED) {
adjustNameFieldsHintDarkness(rawContactEditor);
}
@@ -283,7 +282,9 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
nickNameEditor.setEditorListener(listener);
if (isAggregationSuggestionRawContactId(rawContactId)) {
- acquireAggregationSuggestions(activity, rawContactEditor);
+ acquireAggregationSuggestions(activity,
+ rawContactEditor.getNameEditor().getRawContactId(),
+ rawContactEditor.getNameEditor().getValues());
}
adjustNameFieldsHintDarkness(rawContactEditor);
@@ -497,6 +498,12 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
/**
* Finds raw contact editor view for the given rawContactId.
*/
+ @Override
+ protected View getAggregationAnchorView(long rawContactId) {
+ BaseRawContactEditorView editorView = getRawContactEditorView(rawContactId);
+ return editorView == null ? null : editorView.findViewById(R.id.anchor_view);
+ }
+
public BaseRawContactEditorView getRawContactEditorView(long rawContactId) {
for (int i = 0; i < mContent.getChildCount(); i++) {
final View childView = mContent.getChildAt(i);
diff --git a/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java b/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java
index dca6e18f6..4d35332ed 100644
--- a/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java
+++ b/src/com/android/contacts/editor/JoinSuggestedContactDialogFragment.java
@@ -47,8 +47,8 @@ public class JoinSuggestedContactDialogFragment extends DialogFragment {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
- ContactEditorFragment targetFragment =
- (ContactEditorFragment) getTargetFragment();
+ ContactEditorBaseFragment targetFragment =
+ (ContactEditorBaseFragment) getTargetFragment();
long rawContactIds[] =
getArguments().getLongArray(ARG_RAW_CONTACT_IDS);
targetFragment.doJoinSuggestedContact(rawContactIds);
diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java
index 397c335c8..5996fa6b6 100644
--- a/src/com/android/contacts/editor/LabeledEditorView.java
+++ b/src/com/android/contacts/editor/LabeledEditorView.java
@@ -120,6 +120,10 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
init(context);
}
+ public Long getRawContactId() {
+ return mState == null ? null : mState.getRawContactId();
+ }
+
private void init(Context context) {
mMinLineItemHeight = context.getResources().getDimensionPixelSize(
R.dimen.editor_min_line_item_height);
diff --git a/src/com/android/contacts/editor/SuggestionEditConfirmationDialogFragment.java b/src/com/android/contacts/editor/SuggestionEditConfirmationDialogFragment.java
index 0af2d2d74..c13d5ea41 100644
--- a/src/com/android/contacts/editor/SuggestionEditConfirmationDialogFragment.java
+++ b/src/com/android/contacts/editor/SuggestionEditConfirmationDialogFragment.java
@@ -49,8 +49,8 @@ public class SuggestionEditConfirmationDialogFragment extends DialogFragment {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
- final ContactEditorFragment targetFragment =
- (ContactEditorFragment) getTargetFragment();
+ final ContactEditorBaseFragment targetFragment =
+ (ContactEditorBaseFragment) getTargetFragment();
final Uri contactUri =
getArguments().getParcelable(ARG_CONTACT_URI);
targetFragment.doEditSuggestedContact(contactUri);