summaryrefslogtreecommitdiffstats
path: root/src/com/android/contacts/quickcontact/QuickContactActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/contacts/quickcontact/QuickContactActivity.java')
-rwxr-xr-x[-rw-r--r--]src/com/android/contacts/quickcontact/QuickContactActivity.java82
1 files changed, 67 insertions, 15 deletions
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 58941808f..85d8f2fb0 100644..100755
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -171,10 +171,10 @@ import com.android.contacts.util.StructuredPostalUtils;
import com.android.contacts.widget.MultiShrinkScroller;
import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener;
import com.android.contacts.widget.QuickContactImageView;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableList;
+import java.lang.SecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -184,6 +184,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Mostly translucent {@link Activity} that shows QuickContact dialog. It loads
@@ -348,7 +349,13 @@ public class QuickContactActivity extends ContactsActivity {
LOADER_SMS_ID,
LOADER_CALENDAR_ID,
LOADER_CALL_LOG_ID};
- private Map<Integer, List<ContactInteraction>> mRecentLoaderResults = new HashMap<>();
+ /**
+ * ConcurrentHashMap constructor params: 4 is initial table size, 0.9f is
+ * load factor before resizing, 1 means we only expect a single thread to
+ * write to the map so make only a single shard
+ */
+ private Map<Integer, List<ContactInteraction>> mRecentLoaderResults =
+ new ConcurrentHashMap<>(4, 0.9f, 1);
private static final String FRAGMENT_TAG_SELECT_ACCOUNT = "select_account_fragment";
@@ -416,7 +423,17 @@ public class QuickContactActivity extends ContactsActivity {
getWindow().setDimAmount(mWindowScrim.getAlpha() / DEFAULT_SCRIM_ALPHA);
mHasIntentLaunched = true;
- startActivity(intent);
+ try {
+ startActivity(intent);
+ } catch (SecurityException ex) {
+ Toast.makeText(QuickContactActivity.this, R.string.missing_app,
+ Toast.LENGTH_SHORT).show();
+ Log.e(TAG, "QuickContacts does not have permission to launch "
+ + intent);
+ } catch (ActivityNotFoundException ex) {
+ Toast.makeText(QuickContactActivity.this, R.string.missing_app,
+ Toast.LENGTH_SHORT).show();
+ }
}
};
@@ -933,7 +950,11 @@ public class QuickContactActivity extends ContactsActivity {
QuickContact.MODE_LARGE);
final Uri oldLookupUri = mLookupUri;
- mLookupUri = Preconditions.checkNotNull(lookupUri, "missing lookupUri");
+ if (lookupUri == null) {
+ finish();
+ return;
+ }
+ mLookupUri = lookupUri;
mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES);
if (oldLookupUri == null) {
mContactLoader = (ContactLoader) getLoaderManager().initLoader(
@@ -941,16 +962,21 @@ public class QuickContactActivity extends ContactsActivity {
} else if (oldLookupUri != mLookupUri) {
// After copying a directory contact, the contact URI changes. Therefore,
// we need to restart the loader and reload the new contact.
- for (int interactionLoaderId : mRecentLoaderIds) {
- getLoaderManager().destroyLoader(interactionLoaderId);
- }
+ destroyInteractionLoaders();
mContactLoader = (ContactLoader) getLoaderManager().restartLoader(
LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
+ mCachedCp2DataCardModel = null;
}
NfcHandler.register(this, mLookupUri);
}
+ private void destroyInteractionLoaders() {
+ for (int interactionLoaderId : mRecentLoaderIds) {
+ getLoaderManager().destroyLoader(interactionLoaderId);
+ }
+ }
+
private void runEntranceAnimation() {
if (mHasAlreadyBeenOpened) {
return;
@@ -1131,6 +1157,13 @@ public class QuickContactActivity extends ContactsActivity {
if (mContactCard != null) {
mContactCard.isFireWallInstalled(isFireWallInstalled);
}
+ // When exiting the activity and resuming, we want to force a full reload of all the
+ // interaction data in case something changed in the background. On screen rotation,
+ // we don't need to do this. And, mCachedCp2DataCardModel will be null, so we won't.
+ if (mCachedCp2DataCardModel != null) {
+ destroyInteractionLoaders();
+ startInteractionLoaders(mCachedCp2DataCardModel);
+ }
}
private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel) {
@@ -1837,7 +1870,7 @@ public class QuickContactActivity extends ContactsActivity {
@Override
protected MaterialPalette doInBackground(Void... params) {
- if (imageViewDrawable instanceof BitmapDrawable
+ if (imageViewDrawable instanceof BitmapDrawable && mContactData != null
&& mContactData.getThumbnailPhotoBinaryData() != null
&& mContactData.getThumbnailPhotoBinaryData().length > 0) {
// Perform the color analysis on the thumbnail instead of the full sized
@@ -1994,18 +2027,21 @@ public class QuickContactActivity extends ContactsActivity {
return;
}
if (data.isError()) {
- // This shouldn't ever happen, so throw an exception. The {@link ContactLoader}
- // should log the actual exception.
- throw new IllegalStateException("Failed to load contact", data.getException());
+ // This means either the contact is invalid or we had an
+ // internal error such as an acore crash.
+ Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri());
+ Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage,
+ Toast.LENGTH_LONG).show();
+ finish();
}
if (data.isNotFound()) {
if (!mHasAlreadyBeenOpened) {
Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri());
Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage,
Toast.LENGTH_LONG).show();
- }
- finish();
- return;
+ }
+ finish();
+ return;
}
bindContactData(data);
@@ -2223,6 +2259,11 @@ public class QuickContactActivity extends ContactsActivity {
startActivityForResult(getEditContactIntent(), REQUEST_CODE_CONTACT_EDITOR_ACTIVITY);
}
+ private void deleteContact() {
+ final Uri contactUri = mContactData.getLookupUri();
+ ContactDeletionInteraction.start(this, contactUri, /* finishActivityWhenDone =*/ true);
+ }
+
private void toggleStar(MenuItem starredMenuItem) {
// Make sure there is a contact
if (mContactData != null) {
@@ -2327,6 +2368,9 @@ public class QuickContactActivity extends ContactsActivity {
}
private boolean isShortcutCreatable() {
+ if (mContactData == null || mContactData.isUserProfile()) {
+ return false;
+ }
final Intent createShortcutIntent = new Intent();
createShortcutIntent.setAction(ACTION_INSTALL_SHORTCUT);
final List<ResolveInfo> receivers = getPackageManager()
@@ -2455,6 +2499,9 @@ public class QuickContactActivity extends ContactsActivity {
insertContactFromQrcodMenuItem.setVisible(false);
}
+ final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete);
+ deleteMenuItem.setVisible(isContactEditable());
+
final MenuItem shareMenuItem = menu.findItem(R.id.menu_share);
shareMenuItem.setVisible(isContactShareable());
@@ -2620,8 +2667,13 @@ public class QuickContactActivity extends ContactsActivity {
editContact();
}
return true;
+ case R.id.menu_delete:
+ deleteContact();
+ return true;
case R.id.menu_share:
- shareContact();
+ if (isContactShareable()) {
+ shareContact();
+ }
return true;
case R.id.menu_send_via_sms: {
if (mContactData == null) {