Don't re-use the SaveMode in the group editor anymore.
As we only ever use SaveMode.CLOSE, I decided to remove this entirely.
We don't support re-loading at the moment, so it seems wrong to have
code in there that pretends to be able to do it.
Also I cleaned up some Eclipse warnings, so that the side-bar has fewer
yellow lines
Change-Id: I263b716c2edc98682bd5f5d1bc2b18ede15d7ced
diff --git a/src/com/android/contacts/activities/GroupEditorActivity.java b/src/com/android/contacts/activities/GroupEditorActivity.java
index 7fed0f8..f3255bf 100644
--- a/src/com/android/contacts/activities/GroupEditorActivity.java
+++ b/src/com/android/contacts/activities/GroupEditorActivity.java
@@ -18,7 +18,6 @@
import com.android.contacts.ContactsActivity;
import com.android.contacts.R;
-import com.android.contacts.editor.ContactEditorFragment.SaveMode;
import com.android.contacts.group.GroupEditorFragment;
import com.android.contacts.util.DialogManager;
import com.android.contacts.util.PhoneCapabilityTester;
@@ -108,7 +107,7 @@
@Override
public void onBackPressed() {
// If the change could not be saved, then revert to the default "back" button behavior.
- if (!mFragment.save(SaveMode.CLOSE)) {
+ if (!mFragment.save()) {
super.onBackPressed();
}
}
@@ -123,9 +122,7 @@
String action = intent.getAction();
if (ACTION_SAVE_COMPLETED.equals(action)) {
- mFragment.onSaveCompleted(true,
- intent.getIntExtra(GroupEditorFragment.SAVE_MODE_EXTRA_KEY, SaveMode.CLOSE),
- intent.getData());
+ mFragment.onSaveCompleted(true, intent.getData());
}
}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 4eac313..aa432d3 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -127,8 +127,6 @@
/**
* Modes that specify what the AsyncTask has to perform after saving
*/
- // TODO: Move this into a common utils class or the save service because the contact and
- // group editors need to use this interface definition
public interface SaveMode {
/**
* Close the editor after saving
@@ -1016,7 +1014,7 @@
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int whichButton) {
+ public void onClick(DialogInterface dialogInterface, int whichButton) {
((ContactEditorFragment)getTargetFragment()).doRevertAction();
}
}
@@ -1408,6 +1406,7 @@
.setMessage(R.string.aggregation_suggestion_join_dialog_message)
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int whichButton) {
ContactEditorFragment targetFragment =
(ContactEditorFragment) getTargetFragment();
@@ -1455,6 +1454,7 @@
.setMessage(R.string.aggregation_suggestion_edit_dialog_message)
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int whichButton) {
ContactEditorFragment targetFragment =
(ContactEditorFragment) getTargetFragment();
@@ -1495,21 +1495,6 @@
}
}
- /**
- * Computes bounds of the supplied view relative to its ascendant.
- */
- private Rect getRelativeBounds(View ascendant, View view) {
- Rect rect = new Rect();
- rect.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
-
- View parent = (View) view.getParent();
- while (parent != ascendant) {
- rect.offset(parent.getLeft(), parent.getTop());
- parent = (View) parent.getParent();
- }
- return rect;
- }
-
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelable(KEY_URI, mLookupUri);
@@ -1691,6 +1676,7 @@
bindGroupMetaData();
}
+ @Override
public void onLoaderReset(Loader<Cursor> loader) {
}
};
diff --git a/src/com/android/contacts/group/GroupEditorFragment.java b/src/com/android/contacts/group/GroupEditorFragment.java
index 9d056f4..6ed652f 100644
--- a/src/com/android/contacts/group/GroupEditorFragment.java
+++ b/src/com/android/contacts/group/GroupEditorFragment.java
@@ -23,7 +23,6 @@
import com.android.contacts.GroupMetaDataLoader;
import com.android.contacts.R;
import com.android.contacts.activities.GroupEditorActivity;
-import com.android.contacts.editor.ContactEditorFragment.SaveMode;
import com.android.contacts.editor.SelectAccountDialogFragment;
import com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember;
import com.android.contacts.model.AccountType;
@@ -122,8 +121,6 @@
private static final int LOADER_EXISTING_MEMBERS = 2;
private static final int LOADER_NEW_GROUP_MEMBER = 3;
- public static final String SAVE_MODE_EXTRA_KEY = "saveMode";
-
private static final String MEMBER_RAW_CONTACT_ID_KEY = "rawContactId";
private static final String MEMBER_LOOKUP_URI_KEY = "memberLookupUri";
@@ -502,7 +499,7 @@
public void onDoneClicked() {
if (isGroupMembershipEditable()) {
- save(SaveMode.CLOSE);
+ save();
} else {
// Just revert it.
doRevertAction();
@@ -554,7 +551,7 @@
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int whichButton) {
+ public void onClick(DialogInterface dialogInterface, int whichButton) {
((GroupEditorFragment) getTargetFragment()).doRevertAction();
}
}
@@ -570,19 +567,17 @@
* finishes the activity. This actually only handles saving the group name.
* @return true when successful
*/
- public boolean save(int saveMode) {
+ public boolean save() {
if (!hasValidGroupName() || mStatus != Status.EDITING) {
return false;
}
// If we are about to close the editor - there is no need to refresh the data
- if (saveMode == SaveMode.CLOSE) {
- getLoaderManager().destroyLoader(LOADER_EXISTING_MEMBERS);
- }
+ getLoaderManager().destroyLoader(LOADER_EXISTING_MEMBERS);
// If there are no changes, then go straight to onSaveCompleted()
if (!hasNameChange() && !hasMembershipChange()) {
- onSaveCompleted(false, SaveMode.CLOSE, mGroupUri);
+ onSaveCompleted(false, mGroupUri);
return true;
}
@@ -622,50 +617,40 @@
return true;
}
- public void onSaveCompleted(boolean hadChanges, int saveMode, Uri groupUri) {
+ public void onSaveCompleted(boolean hadChanges, Uri groupUri) {
boolean success = groupUri != null;
- Log.d(TAG, "onSaveCompleted(" + saveMode + ", " + groupUri + ")");
+ Log.d(TAG, "onSaveCompleted(" + groupUri + ")");
if (hadChanges) {
Toast.makeText(mContext, success ? R.string.groupSavedToast :
R.string.groupSavedErrorToast, Toast.LENGTH_SHORT).show();
}
- switch (saveMode) {
- case SaveMode.CLOSE:
- case SaveMode.HOME:
- final Intent resultIntent;
- final int resultCode;
- if (success && groupUri != null) {
- final String requestAuthority =
- groupUri == null ? null : groupUri.getAuthority();
+ final Intent resultIntent;
+ final int resultCode;
+ if (success && groupUri != null) {
+ final String requestAuthority = groupUri.getAuthority();
- resultIntent = new Intent();
- if (LEGACY_CONTACTS_AUTHORITY.equals(requestAuthority)) {
- // Build legacy Uri when requested by caller
- final long groupId = ContentUris.parseId(groupUri);
- final Uri legacyContentUri = Uri.parse("content://contacts/groups");
- final Uri legacyUri = ContentUris.withAppendedId(
- legacyContentUri, groupId);
- resultIntent.setData(legacyUri);
- } else {
- // Otherwise pass back the given Uri
- resultIntent.setData(groupUri);
- }
+ resultIntent = new Intent();
+ if (LEGACY_CONTACTS_AUTHORITY.equals(requestAuthority)) {
+ // Build legacy Uri when requested by caller
+ final long groupId = ContentUris.parseId(groupUri);
+ final Uri legacyContentUri = Uri.parse("content://contacts/groups");
+ final Uri legacyUri = ContentUris.withAppendedId(
+ legacyContentUri, groupId);
+ resultIntent.setData(legacyUri);
+ } else {
+ // Otherwise pass back the given Uri
+ resultIntent.setData(groupUri);
+ }
- resultCode = Activity.RESULT_OK;
- } else {
- resultCode = Activity.RESULT_CANCELED;
- resultIntent = null;
- }
- // It is already saved, so prevent that it is saved again
- mStatus = Status.CLOSING;
- if (mListener != null) {
- mListener.onSaveFinished(resultCode, resultIntent);
- }
- break;
- case SaveMode.RELOAD:
- // TODO: Handle reloading the group list
- default:
- throw new IllegalStateException("Unsupported save mode " + saveMode);
+ resultCode = Activity.RESULT_OK;
+ } else {
+ resultCode = Activity.RESULT_CANCELED;
+ resultIntent = null;
+ }
+ // It is already saved, so prevent that it is saved again
+ mStatus = Status.CLOSING;
+ if (mListener != null) {
+ mListener.onSaveFinished(resultCode, resultIntent);
}
}
@@ -852,7 +837,6 @@
* This represents a single member of the current group.
*/
public static class Member implements Parcelable {
- private static final Member[] EMPTY_ARRAY = new Member[0];
// TODO: Switch to just dealing with raw contact IDs everywhere if possible
private final long mRawContactId;
@@ -894,11 +878,16 @@
public boolean equals(Object object) {
if (object instanceof Member) {
Member otherMember = (Member) object;
- return otherMember != null && Objects.equal(mLookupUri, otherMember.getLookupUri());
+ return Objects.equal(mLookupUri, otherMember.getLookupUri());
}
return false;
}
+ @Override
+ public int hashCode() {
+ return mLookupUri == null ? 0 : mLookupUri.hashCode();
+ }
+
// Parcelable
@Override
public int describeContents() {
@@ -923,10 +912,12 @@
}
public static final Parcelable.Creator<Member> CREATOR = new Parcelable.Creator<Member>() {
+ @Override
public Member createFromParcel(Parcel in) {
return new Member(in);
}
+ @Override
public Member[] newArray(int size) {
return new Member[size];
}