Moving dependencies of PhoneFavoriteFragment.
Move common classes from Contacts to Contacts Common.
Bug: 6993891
Change-Id: Idd0b3115df810090340d1b10b04eb698d5facfb6
diff --git a/res-common/values/strings.xml b/res-common/values/strings.xml
index 7e69de2..7e28847 100644
--- a/res-common/values/strings.xml
+++ b/res-common/values/strings.xml
@@ -114,4 +114,25 @@
<!-- Action string for sending an SMS to a MMS phone number -->
<string name="sms_mms">Text MMS</string>
+ <!-- Title of the confirmation dialog for clearing frequents. [CHAR LIMIT=37] -->
+ <string name="clearFrequentsConfirmation_title">Clear frequently contacted?</string>
+
+ <!-- Confirmation dialog for clearing frequents. [CHAR LIMIT=NONE] -->
+ <string name="clearFrequentsConfirmation">You\'ll clear the frequently contacted list in the
+ People and Phone apps, and force email apps to learn your addressing preferences from
+ scratch.
+ </string>
+
+ <!-- Title of the "Clearing frequently contacted" progress-dialog [CHAR LIMIT=35] -->
+ <string name="clearFrequentsProgress_title">Clearing frequently contacted\u2026</string>
+
+ <!-- Used to display as default status when the contact is available for chat [CHAR LIMIT=19] -->
+ <string name="status_available">Available</string>
+
+ <!-- Used to display as default status when the contact is away or idle for chat [CHAR LIMIT=19] -->
+ <string name="status_away">Away</string>
+
+ <!-- Used to display as default status when the contact is busy or Do not disturb for chat [CHAR LIMIT=19] -->
+ <string name="status_busy">Busy</string>
+
</resources>
diff --git a/src/com/android/contacts/common/ContactPresenceIconUtil.java b/src/com/android/contacts/common/ContactPresenceIconUtil.java
new file mode 100644
index 0000000..2f4c9ee
--- /dev/null
+++ b/src/com/android/contacts/common/ContactPresenceIconUtil.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.common;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.provider.ContactsContract.StatusUpdates;
+
+/**
+ * Define the contact present show policy in Contacts
+ */
+public class ContactPresenceIconUtil {
+ /**
+ * Get the presence icon resource according the status.
+ *
+ * @return null means don't show the status icon.
+ */
+ public static Drawable getPresenceIcon (Context context, int status) {
+ // We don't show the offline status in Contacts
+ switch(status) {
+ case StatusUpdates.AVAILABLE:
+ case StatusUpdates.IDLE:
+ case StatusUpdates.AWAY:
+ case StatusUpdates.DO_NOT_DISTURB:
+ case StatusUpdates.INVISIBLE:
+ return context.getResources().getDrawable(
+ StatusUpdates.getPresenceIconResourceId(status));
+ case StatusUpdates.OFFLINE:
+ // The undefined status is treated as OFFLINE in getPresenceIconResourceId();
+ default:
+ return null;
+ }
+ }
+}
diff --git a/src/com/android/contacts/common/dialog/IndeterminateProgressDialog.java b/src/com/android/contacts/common/dialog/IndeterminateProgressDialog.java
new file mode 100644
index 0000000..2fe059f
--- /dev/null
+++ b/src/com/android/contacts/common/dialog/IndeterminateProgressDialog.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.contacts.common.dialog;
+
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.FragmentManager;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Handler;
+
+/**
+ * Indeterminate progress dialog wrapped up in a DialogFragment to work even when the device
+ * orientation is changed. Currently, only supports adding a title and/or message to the progress
+ * dialog. There is an additional parameter of the minimum amount of time to display the progress
+ * dialog even after a call to dismiss the dialog {@link #dismiss()} or
+ * {@link #dismissAllowingStateLoss()}.
+ * <p>
+ * To create and show the progress dialog, use
+ * {@link #show(FragmentManager, CharSequence, CharSequence, long)} and retain the reference to the
+ * IndeterminateProgressDialog instance.
+ * <p>
+ * To dismiss the dialog, use {@link #dismiss()} or {@link #dismissAllowingStateLoss()} on the
+ * instance. The instance returned by
+ * {@link #show(FragmentManager, CharSequence, CharSequence, long)} is guaranteed to be valid
+ * after a device orientation change because the {@link #setRetainInstance(boolean)} is called
+ * internally with true.
+ */
+public class IndeterminateProgressDialog extends DialogFragment {
+ private static final String TAG = IndeterminateProgressDialog.class.getSimpleName();
+
+ private CharSequence mTitle;
+ private CharSequence mMessage;
+ private long mMinDisplayTime;
+ private long mShowTime = 0;
+ private boolean mActivityReady = false;
+ private Dialog mOldDialog;
+ private final Handler mHandler = new Handler();
+ private boolean mCalledSuperDismiss = false;
+ private boolean mAllowStateLoss;
+ private final Runnable mDismisser = new Runnable() {
+ @Override
+ public void run() {
+ superDismiss();
+ }
+ };
+
+ /**
+ * Creates and shows an indeterminate progress dialog. Once the progress dialog is shown, it
+ * will be shown for at least the minDisplayTime (in milliseconds), so that the progress dialog
+ * does not flash in and out to quickly.
+ */
+ public static IndeterminateProgressDialog show(FragmentManager fragmentManager,
+ CharSequence title, CharSequence message, long minDisplayTime) {
+ IndeterminateProgressDialog dialogFragment = new IndeterminateProgressDialog();
+ dialogFragment.mTitle = title;
+ dialogFragment.mMessage = message;
+ dialogFragment.mMinDisplayTime = minDisplayTime;
+ dialogFragment.show(fragmentManager, TAG);
+ dialogFragment.mShowTime = System.currentTimeMillis();
+ dialogFragment.setCancelable(false);
+
+ return dialogFragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setRetainInstance(true);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Create the progress dialog and set its properties
+ final ProgressDialog dialog = new ProgressDialog(getActivity());
+ dialog.setIndeterminate(true);
+ dialog.setIndeterminateDrawable(null);
+ dialog.setTitle(mTitle);
+ dialog.setMessage(mMessage);
+
+ return dialog;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ mActivityReady = true;
+
+ // Check if superDismiss() had been called before. This can happen if in a long
+ // running operation, the user hits the home button and closes this fragment's activity.
+ // Upon returning, we want to dismiss this progress dialog fragment.
+ if (mCalledSuperDismiss) {
+ superDismiss();
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ mActivityReady = false;
+ }
+
+ /**
+ * There is a race condition that is not handled properly by the DialogFragment class.
+ * If we don't check that this onDismiss callback isn't for the old progress dialog from before
+ * the device orientation change, then this will cause the newly created dialog after the
+ * orientation change to be dismissed immediately.
+ */
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ if (mOldDialog != null && mOldDialog == dialog) {
+ // This is the callback from the old progress dialog that was already dismissed before
+ // the device orientation change, so just ignore it.
+ return;
+ }
+ super.onDismiss(dialog);
+ }
+
+ /**
+ * Save the old dialog that is about to get destroyed in case this is due to a change
+ * in device orientation. This will allow us to intercept the callback to
+ * {@link #onDismiss(DialogInterface)} in case the callback happens after a new progress dialog
+ * instance was created.
+ */
+ @Override
+ public void onDestroyView() {
+ mOldDialog = getDialog();
+ super.onDestroyView();
+ }
+
+ /**
+ * This tells the progress dialog to dismiss itself after guaranteeing to be shown for the
+ * specified time in {@link #show(FragmentManager, CharSequence, CharSequence, long)}.
+ */
+ @Override
+ public void dismiss() {
+ mAllowStateLoss = false;
+ dismissWhenReady();
+ }
+
+ /**
+ * This tells the progress dialog to dismiss itself (with state loss) after guaranteeing to be
+ * shown for the specified time in
+ * {@link #show(FragmentManager, CharSequence, CharSequence, long)}.
+ */
+ @Override
+ public void dismissAllowingStateLoss() {
+ mAllowStateLoss = true;
+ dismissWhenReady();
+ }
+
+ /**
+ * Tells the progress dialog to dismiss itself after guaranteeing that the dialog had been
+ * showing for at least the minimum display time as set in
+ * {@link #show(FragmentManager, CharSequence, CharSequence, long)}.
+ */
+ private void dismissWhenReady() {
+ // Compute how long the dialog has been showing
+ final long shownTime = System.currentTimeMillis() - mShowTime;
+ if (shownTime >= mMinDisplayTime) {
+ // dismiss immediately
+ mHandler.post(mDismisser);
+ } else {
+ // Need to wait some more, so compute the amount of time to sleep.
+ final long sleepTime = mMinDisplayTime - shownTime;
+ mHandler.postDelayed(mDismisser, sleepTime);
+ }
+ }
+
+ /**
+ * Actually dismiss the dialog fragment.
+ */
+ private void superDismiss() {
+ mCalledSuperDismiss = true;
+ if (mActivityReady) {
+ // The fragment is either in onStart or past it, but has not gotten to onStop yet.
+ // It is safe to dismiss this dialog fragment.
+ if (mAllowStateLoss) {
+ super.dismissAllowingStateLoss();
+ } else {
+ super.dismiss();
+ }
+ }
+ // If mActivityReady is false, then this dialog fragment has already passed the onStop
+ // state. This can happen if the user hit the 'home' button before this dialog fragment was
+ // dismissed or if there is a configuration change.
+ // In the event that this dialog fragment is re-attached and reaches onStart (e.g.,
+ // because the user returns to this fragment's activity or the device configuration change
+ // has re-attached this dialog fragment), because the mCalledSuperDismiss flag was set to
+ // true, this dialog fragment will be dismissed within onStart. So, there's nothing else
+ // that needs to be done.
+ }
+}