summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaiyiz <kaiyiz@codeaurora.org>2013-12-09 14:51:05 +0800
committerRoman Birg <roman@cyngn.com>2014-09-02 11:53:42 -0700
commit184ecfdfa83e721ab9cfa4782d136b02eab62576 (patch)
treec239626e9673852d8107f0e451842a37787b8f22
parentf7b46c376ac1f653ecba75899ac31d2569e80208 (diff)
downloadpackages_apps_Contacts-184ecfdfa83e721ab9cfa4782d136b02eab62576.tar.gz
packages_apps_Contacts-184ecfdfa83e721ab9cfa4782d136b02eab62576.tar.bz2
packages_apps_Contacts-184ecfdfa83e721ab9cfa4782d136b02eab62576.zip
Launcher: It will pop shortcut added when the screen no room
Contacts show a sucesssful toast directly after send broadcast to laucher evenwhen there is no room in launcher, Laucher has no response to Contacts, and show the error toast when there is no room. When the shortcut put successful, Launcher broadcast an intent with packagename, so Contacts show the sucessful toast only when receive this intent. CRs-Fixed: BZ707 Change-Id: Ice845de41c6f7ed6d14af2ed9baa98f08af33cac
-rw-r--r--src/com/android/contacts/detail/ContactLoaderFragment.java67
1 files changed, 52 insertions, 15 deletions
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index 67ec681fd..bb72ee194 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -22,8 +22,10 @@ import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.Loader;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -80,6 +82,10 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
private boolean mSendToVoicemailState;
private String mCustomRingtone;
+ private static final String ACTION_INSTALL_SHORTCUT_SUCCESSFUL =
+ "com.android.launcher.action.INSTALL_SHORTCUT_SUCCESSFUL";
+ private static final String EXTRA_RESPONSE_PACKAGENAME = "response_packagename";
+
/**
* This is a listener to the {@link ContactLoaderFragment} and will be notified when the
* contact details have finished loading or if the user selects any menu options.
@@ -112,6 +118,7 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
private static final String KEY_CONTACT_URI = "contactUri";
private static final String LOADER_ARG_CONTACT_URI = "contactUri";
+ private static final String CONTACTS_COMMON_PKG_NAME = "com.android.contacts.common";
private Context mContext;
private Uri mLookupUri;
@@ -119,6 +126,27 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
private Contact mContactData;
+ private IntentFilter mResponseFilter;
+
+ /** Receive broadcast, show toast only when put shortcut sucessful in laucher */
+ private BroadcastReceiver mResponseReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!ACTION_INSTALL_SHORTCUT_SUCCESSFUL.equals(intent.getAction())) {
+ return;
+ }
+ String packageName = intent.getStringExtra(EXTRA_RESPONSE_PACKAGENAME);
+ if (packageName != null && (packageName.equals(context.getPackageName()) ||
+ CONTACTS_COMMON_PKG_NAME.equals(packageName))) {
+ // Send a toast to give feedback to the user that a shortcut to this
+ // contact was added to the launcher.
+ Toast.makeText(context, R.string.createContactShortcutSuccessful,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ };
+
public ContactLoaderFragment() {
}
@@ -128,6 +156,7 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
if (savedInstanceState != null) {
mLookupUri = savedInstanceState.getParcelable(KEY_CONTACT_URI);
}
+ mResponseFilter = new IntentFilter(ACTION_INSTALL_SHORTCUT_SUCCESSFUL);
}
@Override
@@ -162,6 +191,18 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
}
}
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().unregisterReceiver(mResponseReceiver);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getActivity().registerReceiver(mResponseReceiver, mResponseFilter);
+ }
+
public void loadUri(Uri lookupUri) {
if (Objects.equal(lookupUri, mLookupUri)) {
// Same URI, no need to load the data again
@@ -389,12 +430,6 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
// shortcut to this contact
shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT);
parentActivity.sendBroadcast(shortcutIntent);
-
- // Send a toast to give feedback to the user that a shortcut to this
- // contact was added to the launcher.
- Toast.makeText(parentActivity,
- R.string.createContactShortcutSuccessful,
- Toast.LENGTH_SHORT).show();
}
});
@@ -489,21 +524,23 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
}
}
}
-
}
if (TextUtils.isEmpty(name)) {
name = mContext.getResources().getString(R.string.missing_name);
}
+
name = getString(R.string.nameLabelsGroup) + ":" + name + "\r\n";
- phone = phone == null ? "" : getString(R.string.phoneLabelsGroup) + ":" + phone + "\r\n";
- email = email == null ? "" : getString(R.string.emailLabelsGroup) + ":" + email + "\r\n";
- postal = postal == null ? "" : getString(R.string.postalLabelsGroup) + ":" + postal
- + "\r\n";
- organization = organization == null ? "" : getString(R.string.organizationLabelsGroup)
- + ":" + organization + "\r\n";
- sipAddress = sipAddress == null ? "" : getString(R.string.label_sip_address) + ":"
- + sipAddress + "\r\n";
+ phone = (phone == null) ? "" : getString(R.string.phoneLabelsGroup)
+ + ":" + phone + "\r\n";
+ email = (email == null )? "" : getString(R.string.emailLabelsGroup)
+ + ":" + email + "\r\n";
+ postal = (postal == null) ? "" : getString(R.string.postalLabelsGroup)
+ + ":" + postal + "\r\n";
+ organization = (organization == null) ? "" : getString(R.string.organizationLabelsGroup)
+ + ":" + organization + "\r\n";
+ sipAddress = (sipAddress == null) ? "" : getString(R.string.label_sip_address) + ":"
+ + sipAddress + "\r\n";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", name + phone + email + postal + organization + sipAddress);
intent.setType("vnd.android-dir/mms-sms");