Auth Notification

Some changes that allow a notification to open Account Settings for a specific
account

Bug: 10930585
Change-Id: Ib329e339b405ccbc0631d5ce6a23bf8fa6d62b83
This commit is contained in:
Alon Albert 2013-09-27 17:14:49 -07:00
parent 386c8ccbf9
commit c4d139c4f4
2 changed files with 56 additions and 2 deletions

View File

@ -24,11 +24,15 @@ import android.net.Uri;
import android.text.TextUtils;
public final class IntentUtilities {
public static final String PATH_SETTINGS = "settings";
// Format for activity URIs: content://ui.email.android.com/...
private static final String ACTIVITY_INTENT_SCHEME = "content";
private static final String ACTIVITY_INTENT_HOST = "ui.email.android.com";
private static final String ACCOUNT_ID_PARAM = "ACCOUNT_ID";
private static final String ACCOUNT_NAME_PARAM = "ACCOUNT_NAME";
private static final String MAILBOX_ID_PARAM = "MAILBOX_ID";
private static final String MESSAGE_ID_PARAM = "MESSAGE_ID";
private static final String ACCOUNT_UUID_PARAM = "ACCOUNT_UUID";
@ -56,6 +60,15 @@ public final class IntentUtilities {
}
}
/**
* Add the account name parameter.
*/
public static void setAccountName(Uri.Builder b, String accountName) {
if (accountName != null) {
b.appendQueryParameter(ACCOUNT_NAME_PARAM, accountName);
}
}
/**
* Add the mailbox ID parameter.
*/
@ -91,6 +104,13 @@ public final class IntentUtilities {
return getLongFromIntent(intent, ACCOUNT_ID_PARAM);
}
/**
* Retrieve the account name.
*/
public static String getAccountNameFromIntent(Intent intent) {
return getStringFromIntent(intent, ACCOUNT_NAME_PARAM);
}
/**
* Retrieve the mailbox ID.
*/
@ -125,6 +145,14 @@ public final class IntentUtilities {
return value;
}
private static String getStringFromIntent(Intent intent, String paramName) {
String value = null;
if (intent.getData() != null) {
value = getStringParamFromUri(intent.getData(), paramName, null);
}
return value;
}
private static long getLongParamFromUri(Uri uri, String paramName, long defaultValue) {
final String value = uri.getQueryParameter(paramName);
if (!TextUtils.isEmpty(value)) {
@ -137,6 +165,14 @@ public final class IntentUtilities {
return defaultValue;
}
private static String getStringParamFromUri(Uri uri, String paramName, String defaultValue) {
final String value = uri.getQueryParameter(paramName);
if (value == null) {
return defaultValue;
}
return value;
}
/**
* Create an {@link Intent} to launch an activity as the main entry point. Existing activities
* will all be closed.

View File

@ -42,7 +42,6 @@ import android.widget.TextView;
import com.android.email.R;
import com.android.email.activity.ActivityHelper;
import com.android.email.mail.Sender;
import com.android.email.provider.EmailProvider;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
@ -149,7 +148,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
*/
public static Intent createAccountSettingsIntent(long accountId,
String loginWarningAccountName, String loginWarningReason) {
final Uri.Builder b = IntentUtilities.createActivityIntentUrlBuilder("settings");
final Uri.Builder b = IntentUtilities.createActivityIntentUrlBuilder(
IntentUtilities.PATH_SETTINGS);
IntentUtilities.setAccountId(b, accountId);
final Intent i = new Intent(Intent.ACTION_EDIT, b.build());
if (loginWarningAccountName != null) {
@ -161,6 +161,24 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
return i;
}
@Override
public Intent getIntent() {
final Intent intent = super.getIntent();
final long accountId = IntentUtilities.getAccountIdFromIntent(intent);
if (accountId < 0) {
return intent;
}
Intent modIntent = new Intent(intent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, AccountSettingsFragment.class.getCanonicalName());
modIntent.putExtra(
EXTRA_SHOW_FRAGMENT_ARGUMENTS,
AccountSettingsFragment.buildArguments(
accountId, IntentUtilities.getAccountNameFromIntent(intent)));
modIntent.putExtra(EXTRA_NO_HEADERS, true);
return modIntent;
}
/**
* Launch generic settings and pre-enable the debug preferences
*/