mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 984503 - Add "Remove Firefox Account" menu option to FxAccount status activity. r=nalexander,rnewman
The menu is exposed as "More..." on devices that do not have a hardware menu button. ========8adeb1be57
Author: Nick Alexander <nalexander@mozilla.com> Bug 984503 - Part 4: Show a toast after removing Firefox Account. ========aeffca77dc
Author: Nick Alexander <nalexander@mozilla.com> Date: Thu Aug 28 15:05:11 2014 -0700 Bug 984503 - Part 3: Hide "More..." option if device has a hardware menu button. The reason for this dance is to keep the "Remove Account" button out of view if at all possible. I don't want to make it too easy to delete your account. ========4efe597308
Author: Nick Alexander <nalexander@mozilla.com> Date: Thu Aug 28 15:04:38 2014 -0700 Bug 984503 - Part 2: Add "More..." to Firefox Account status list. ========ad6a55dc33
Author: vivek <vivekb.balakrishnan@gmail.com> Date: Thu Aug 21 00:25:30 2014 +0300 Bug 984503 - Part 1: Add menu option to remove Firefox Account. --HG-- extra : rebase_source : 946b86baaa36de4b143d6d8a614f7cc3a2118a6a
This commit is contained in:
parent
0b6671c42b
commit
6694cea5ba
@ -4,18 +4,33 @@
|
||||
|
||||
package org.mozilla.gecko.fxa.activities;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.background.common.log.Logger;
|
||||
import org.mozilla.gecko.fxa.FirefoxAccounts;
|
||||
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
import org.mozilla.gecko.sync.setup.activities.LocaleAware.LocaleAwareFragmentActivity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Activity which displays account status.
|
||||
@ -93,6 +108,63 @@ public class FxAccountStatusActivity extends LocaleAwareFragmentActivity {
|
||||
return new AndroidFxAccount(this, account);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to maybe remove the given Android account.
|
||||
*/
|
||||
@SuppressLint("InlinedApi")
|
||||
public void maybeDeleteAndroidAccount(final Account account) {
|
||||
if (account == null) {
|
||||
Logger.warn(LOG_TAG, "Trying to delete null account; ignoring request.");
|
||||
return;
|
||||
}
|
||||
|
||||
final AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>() {
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
Logger.info(LOG_TAG, "Account " + Utils.obfuscateEmail(account.name) + " removed.");
|
||||
final Activity activity = FxAccountStatusActivity.this;
|
||||
final String text = activity.getResources().getString(R.string.fxaccount_remove_account_toast, account.name);
|
||||
Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
|
||||
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Get the best dialog icon from the theme on v11+.
|
||||
* See http://stackoverflow.com/questions/14910536/android-dialog-theme-makes-icon-too-light/14910945#14910945.
|
||||
*/
|
||||
final int icon;
|
||||
if (AppConstants.Versions.feature11Plus) {
|
||||
final TypedValue typedValue = new TypedValue();
|
||||
getTheme().resolveAttribute(android.R.attr.alertDialogIcon, typedValue, true);
|
||||
icon = typedValue.resourceId;
|
||||
} else {
|
||||
icon = android.R.drawable.ic_dialog_alert;
|
||||
}
|
||||
|
||||
final AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.fxaccount_remove_account_dialog_title)
|
||||
.setIcon(icon)
|
||||
.setMessage(R.string.fxaccount_remove_account_dialog_message)
|
||||
.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AccountManager.get(FxAccountStatusActivity.this).removeAccount(account, callback, null);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
@ -100,7 +172,17 @@ public class FxAccountStatusActivity extends LocaleAwareFragmentActivity {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.remove_account:
|
||||
maybeDeleteAndroidAccount(FirefoxAccounts.getFirefoxAccount(this));
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
final MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.fxaccount_status_menu, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
};
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.mozilla.gecko.fxa.tasks.FxAccountCodeResender;
|
||||
import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||
import org.mozilla.gecko.sync.SharedPreferencesClientsDataDelegate;
|
||||
import org.mozilla.gecko.sync.SyncConfiguration;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.ContentResolver;
|
||||
@ -84,6 +85,7 @@ public class FxAccountStatusFragment
|
||||
|
||||
protected EditTextPreference deviceNamePreference;
|
||||
protected Preference syncServerPreference;
|
||||
protected Preference morePreference;
|
||||
|
||||
protected volatile AndroidFxAccount fxAccount;
|
||||
// The contract is: when fxAccount is non-null, then clientsDataDelegate is
|
||||
@ -111,6 +113,13 @@ public class FxAccountStatusFragment
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// We need to do this before we can query the hardware menu button state.
|
||||
// We're guaranteed to have an activity at this point (onAttach is called
|
||||
// before onCreate). It's okay to call this multiple times (with different
|
||||
// contexts).
|
||||
HardwareUtils.init(getActivity());
|
||||
|
||||
addPreferences();
|
||||
}
|
||||
|
||||
@ -155,6 +164,12 @@ public class FxAccountStatusFragment
|
||||
deviceNamePreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
syncServerPreference = ensureFindPreference("sync_server");
|
||||
morePreference = ensureFindPreference("more");
|
||||
morePreference.setOnPreferenceClickListener(this);
|
||||
|
||||
if (HardwareUtils.hasMenuButton()) {
|
||||
syncCategory.removePreference(morePreference);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,6 +224,11 @@ public class FxAccountStatusFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
if (preference == morePreference) {
|
||||
getActivity().openOptionsMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -206,6 +206,15 @@
|
||||
the two uses differently. -->
|
||||
<!ENTITY fxaccount_status_linktos 'Terms of Service'>
|
||||
<!ENTITY fxaccount_status_linkprivacy 'Privacy Notice'>
|
||||
<!ENTITY fxaccount_status_more 'More&ellipsis;'>
|
||||
|
||||
<!ENTITY fxaccount_remove_account_dialog_title 'Remove Firefox Account?'>
|
||||
<!ENTITY fxaccount_remove_account_dialog_message '&brandShortName; will stop syncing with your account, but won’t delete any of your browsing data on this device.'>
|
||||
<!-- Localization note: format string below will be replaced
|
||||
with the Firefox Account's email address. -->
|
||||
<!ENTITY fxaccount_remove_account_toast 'Firefox Account &formatS; removed.'>
|
||||
|
||||
<!ENTITY fxaccount_remove_account_menu_item 'Remove Account'>
|
||||
|
||||
<!-- Localization note: this is the name shown by the Android system
|
||||
itself for a Firefox Account. Don't localize this. -->
|
||||
@ -235,6 +244,6 @@
|
||||
<!ENTITY fxaccount_remote_error_COULD_NOT_CONNECT 'Cannot connect to network'>
|
||||
|
||||
<!ENTITY fxaccount_sync_sign_in_error_notification_title2 '&syncBrand.shortName.label; is not connected'>
|
||||
<!-- Note to translators: the format string below will be replaced
|
||||
<!-- Localization note: the format string below will be replaced
|
||||
with the Firefox Account's email address. -->
|
||||
<!ENTITY fxaccount_sync_sign_in_error_notification_text2 'Tap to sign in as &formatS;'>
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item
|
||||
android:id="@+id/remove_account"
|
||||
android:title="@string/fxaccount_remove_account_menu_item" />
|
||||
</menu>
|
@ -78,12 +78,18 @@
|
||||
android:persistent="false"
|
||||
android:title="@string/fxaccount_status_device_name" />
|
||||
|
||||
<Preference
|
||||
<Preference
|
||||
android:editable="false"
|
||||
android:key="sync_server"
|
||||
android:persistent="false"
|
||||
android:title="@string/fxaccount_status_sync_server" />
|
||||
|
||||
<Preference
|
||||
android:editable="false"
|
||||
android:key="more"
|
||||
android:persistent="false"
|
||||
android:title="@string/fxaccount_status_more" />
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="legal_category"
|
||||
|
@ -190,6 +190,7 @@
|
||||
<string name="fxaccount_status_legal">&fxaccount_status_legal;</string>
|
||||
<string name="fxaccount_status_linktos">&fxaccount_status_linktos;</string>
|
||||
<string name="fxaccount_status_linkprivacy">&fxaccount_status_linkprivacy;</string>
|
||||
<string name="fxaccount_status_more">&fxaccount_status_more;</string>
|
||||
|
||||
<string name="fxaccount_label">&fxaccount_account_type_label;</string>
|
||||
|
||||
@ -208,3 +209,9 @@
|
||||
|
||||
<string name="fxaccount_sync_sign_in_error_notification_title">&fxaccount_sync_sign_in_error_notification_title2;</string>
|
||||
<string name="fxaccount_sync_sign_in_error_notification_text">&fxaccount_sync_sign_in_error_notification_text2;</string>
|
||||
|
||||
<!-- Remove Account -->
|
||||
<string name="fxaccount_remove_account_dialog_title">&fxaccount_remove_account_dialog_title;</string>
|
||||
<string name="fxaccount_remove_account_dialog_message">&fxaccount_remove_account_dialog_message;</string>
|
||||
<string name="fxaccount_remove_account_toast">&fxaccount_remove_account_toast;</string>
|
||||
<string name="fxaccount_remove_account_menu_item">&fxaccount_remove_account_menu_item;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user