Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java

Issue 2801033002: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.signin; 5 package org.chromium.chrome.browser.signin;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.app.Dialog; 10 import android.app.Dialog;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 } 177 }
178 178
179 /** 179 /**
180 * Initiate fetching the user accounts data (images and the full name). 180 * Initiate fetching the user accounts data (images and the full name).
181 * Fetched data will be sent to observers of ProfileDownloader. 181 * Fetched data will be sent to observers of ProfileDownloader.
182 * 182 *
183 * @param profile Profile to use. 183 * @param profile Profile to use.
184 */ 184 */
185 private static void startFetchingAccountsInformation(Context context, Profil e profile) { 185 private static void startFetchingAccountsInformation(Context context, Profil e profile) {
186 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); 186 Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts ();
187 for (int i = 0; i < accounts.length; i++) { 187 for (int i = 0; i < accounts.length; i++) {
188 startFetchingAccountInformation(context, profile, accounts[i].name); 188 startFetchingAccountInformation(context, profile, accounts[i].name);
189 } 189 }
190 } 190 }
191 191
192 public void update() { 192 public void update() {
193 final Context context = getActivity(); 193 final Context context = getActivity();
194 if (context == null) return; 194 if (context == null) return;
195 195
196 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll(); 196 if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
197 197
198 ChromeSigninController signInController = ChromeSigninController.get(); 198 ChromeSigninController signInController = ChromeSigninController.get(con text);
199 if (!signInController.isSignedIn()) { 199 if (!signInController.isSignedIn()) {
200 // The AccountManagementFragment can only be shown when the user is signed in. If the 200 // The AccountManagementFragment can only be shown when the user is signed in. If the
201 // user is signed out, exit the fragment. 201 // user is signed out, exit the fragment.
202 getActivity().finish(); 202 getActivity().finish();
203 return; 203 return;
204 } 204 }
205 205
206 addPreferencesFromResource(R.xml.account_management_preferences); 206 addPreferencesFromResource(R.xml.account_management_preferences);
207 207
208 String signedInAccountName = ChromeSigninController.get().getSignedInAcc ountName(); 208 String signedInAccountName =
209 ChromeSigninController.get(getActivity()).getSignedInAccountName ();
209 String fullName = getCachedUserName(signedInAccountName); 210 String fullName = getCachedUserName(signedInAccountName);
210 if (TextUtils.isEmpty(fullName)) { 211 if (TextUtils.isEmpty(fullName)) {
211 fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedPr ofile()); 212 fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedPr ofile());
212 } 213 }
213 if (TextUtils.isEmpty(fullName)) fullName = signedInAccountName; 214 if (TextUtils.isEmpty(fullName)) fullName = signedInAccountName;
214 215
215 getActivity().setTitle(fullName); 216 getActivity().setTitle(fullName);
216 217
217 configureSignOutSwitch(); 218 configureSignOutSwitch();
218 configureAddAccountPreference(); 219 configureAddAccountPreference();
(...skipping 19 matching lines...) Expand all
238 Preference signOutSwitch = findPreference(PREF_SIGN_OUT); 239 Preference signOutSwitch = findPreference(PREF_SIGN_OUT);
239 if (isChildAccount) { 240 if (isChildAccount) {
240 getPreferenceScreen().removePreference(signOutSwitch); 241 getPreferenceScreen().removePreference(signOutSwitch);
241 } else { 242 } else {
242 signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivit y())); 243 signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivit y()));
243 signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickList ener() { 244 signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickList ener() {
244 @Override 245 @Override
245 public boolean onPreferenceClick(Preference preference) { 246 public boolean onPreferenceClick(Preference preference) {
246 if (!isVisible() || !isResumed()) return false; 247 if (!isVisible() || !isResumed()) return false;
247 248
248 if (ChromeSigninController.get().isSignedIn() 249 if (ChromeSigninController.get(getActivity()).isSignedIn()
249 && getSignOutAllowedPreferenceValue(getActivity())) { 250 && getSignOutAllowedPreferenceValue(getActivity())) {
250 AccountManagementScreenHelper.logEvent( 251 AccountManagementScreenHelper.logEvent(
251 ProfileAccountManagementMetrics.TOGGLE_SIGNOUT, 252 ProfileAccountManagementMetrics.TOGGLE_SIGNOUT,
252 mGaiaServiceType); 253 mGaiaServiceType);
253 254
254 String managementDomain = 255 String managementDomain =
255 SigninManager.get(getActivity()).getManagementDo main(); 256 SigninManager.get(getActivity()).getManagementDo main();
256 if (managementDomain != null) { 257 if (managementDomain != null) {
257 // Show the 'You are signing out of a managed accoun t' dialog. 258 // Show the 'You are signing out of a managed accoun t' dialog.
258 ConfirmManagedSyncDataDialog.showSignOutFromManagedA ccountDialog( 259 ConfirmManagedSyncDataDialog.showSignOutFromManagedA ccountDialog(
(...skipping 15 matching lines...) Expand all
274 275
275 return false; 276 return false;
276 } 277 }
277 278
278 }); 279 });
279 } 280 }
280 } 281 }
281 282
282 private void configureSyncSettings() { 283 private void configureSyncSettings() {
283 final Preferences preferences = (Preferences) getActivity(); 284 final Preferences preferences = (Preferences) getActivity();
284 final Account account = ChromeSigninController.get().getSignedInUser(); 285 final Account account = ChromeSigninController.get(getActivity()).getSig nedInUser();
285 findPreference(PREF_SYNC_SETTINGS) 286 findPreference(PREF_SYNC_SETTINGS)
286 .setOnPreferenceClickListener(new OnPreferenceClickListener() { 287 .setOnPreferenceClickListener(new OnPreferenceClickListener() {
287 @Override 288 @Override
288 public boolean onPreferenceClick(Preference preference) { 289 public boolean onPreferenceClick(Preference preference) {
289 if (!isVisible() || !isResumed()) return false; 290 if (!isVisible() || !isResumed()) return false;
290 291
291 if (ProfileSyncService.get() == null) return true; 292 if (ProfileSyncService.get() == null) return true;
292 293
293 Bundle args = new Bundle(); 294 Bundle args = new Bundle();
294 args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUN T, account.name); 295 args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUN T, account.name);
295 preferences.startFragment(SyncCustomizationFragment.clas s.getName(), args); 296 preferences.startFragment(SyncCustomizationFragment.clas s.getName(), args);
296 297
297 return true; 298 return true;
298 } 299 }
299 }); 300 });
300 } 301 }
301 302
302 private void configureGoogleActivityControls() { 303 private void configureGoogleActivityControls() {
303 Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS); 304 Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS);
304 if (ChildAccountService.isChildAccount()) { 305 if (ChildAccountService.isChildAccount()) {
305 pref.setSummary(R.string.sign_in_google_activity_controls_message_ch ild_account); 306 pref.setSummary(R.string.sign_in_google_activity_controls_message_ch ild_account);
306 } 307 }
307 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { 308 pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
308 @Override 309 @Override
309 public boolean onPreferenceClick(Preference preference) { 310 public boolean onPreferenceClick(Preference preference) {
310 Activity activity = getActivity(); 311 Activity activity = getActivity();
311 AppHooks.get().createGoogleActivityController().openWebAndAppAct ivitySettings( 312 AppHooks.get().createGoogleActivityController().openWebAndAppAct ivitySettings(
312 activity, ChromeSigninController.get().getSignedInAccoun tName()); 313 activity, ChromeSigninController.get(activity).getSigned InAccountName());
313 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo ntrolsClicked"); 314 RecordUserAction.record("Signin_AccountSettings_GoogleActivityCo ntrolsClicked");
314 return true; 315 return true;
315 } 316 }
316 }); 317 });
317 } 318 }
318 319
319 private void configureAddAccountPreference() { 320 private void configureAddAccountPreference() {
320 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference( PREF_ADD_ACCOUNT); 321 ChromeBasePreference addAccount = (ChromeBasePreference) findPreference( PREF_ADD_ACCOUNT);
321 322
322 if (ChildAccountService.isChildAccount()) { 323 if (ChildAccountService.isChildAccount()) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 private void updateAccountsList() { 409 private void updateAccountsList() {
409 PreferenceScreen prefScreen = getPreferenceScreen(); 410 PreferenceScreen prefScreen = getPreferenceScreen();
410 if (prefScreen == null) return; 411 if (prefScreen == null) return;
411 412
412 for (int i = 0; i < mAccountsListPreferences.size(); i++) { 413 for (int i = 0; i < mAccountsListPreferences.size(); i++) {
413 prefScreen.removePreference(mAccountsListPreferences.get(i)); 414 prefScreen.removePreference(mAccountsListPreferences.get(i));
414 } 415 }
415 mAccountsListPreferences.clear(); 416 mAccountsListPreferences.clear();
416 417
417 final Preferences activity = (Preferences) getActivity(); 418 final Preferences activity = (Preferences) getActivity();
418 Account[] accounts = AccountManagerHelper.get().getGoogleAccounts(); 419 Account[] accounts = AccountManagerHelper.get(activity).getGoogleAccount s();
419 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER; 420 int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER;
420 421
421 for (Account account : accounts) { 422 for (Account account : accounts) {
422 ChromeBasePreference pref = new ChromeBasePreference(activity); 423 ChromeBasePreference pref = new ChromeBasePreference(activity);
423 pref.setSelectable(false); 424 pref.setSelectable(false);
424 pref.setTitle(account.name); 425 pref.setTitle(account.name);
425 426
426 boolean isChildAccount = ChildAccountService.isChildAccount(); 427 boolean isChildAccount = ChildAccountService.isChildAccount();
427 pref.setUseReducedPadding(isChildAccount); 428 pref.setUseReducedPadding(isChildAccount);
428 pref.setIcon(new BitmapDrawable(getResources(), 429 pref.setIcon(new BitmapDrawable(getResources(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 dialog.setMessage(getString(R.string.wiping_profile_data_message)); 468 dialog.setMessage(getString(R.string.wiping_profile_data_message));
468 dialog.setIndeterminate(true); 469 dialog.setIndeterminate(true);
469 return dialog; 470 return dialog;
470 } 471 }
471 } 472 }
472 473
473 @Override 474 @Override
474 public void onSignOutClicked() { 475 public void onSignOutClicked() {
475 // In case the user reached this fragment without being signed in, we gu ard the sign out so 476 // In case the user reached this fragment without being signed in, we gu ard the sign out so
476 // we do not hit a native crash. 477 // we do not hit a native crash.
477 if (!ChromeSigninController.get().isSignedIn()) return; 478 if (!ChromeSigninController.get(getActivity()).isSignedIn()) return;
478 479
479 final Activity activity = getActivity(); 480 final Activity activity = getActivity();
480 final DialogFragment clearDataProgressDialog = new ClearDataProgressDial og(); 481 final DialogFragment clearDataProgressDialog = new ClearDataProgressDial og();
481 SigninManager.get(activity).signOut(null, new SigninManager.WipeDataHook s() { 482 SigninManager.get(activity).signOut(null, new SigninManager.WipeDataHook s() {
482 @Override 483 @Override
483 public void preWipeData() { 484 public void preWipeData() {
484 clearDataProgressDialog.show( 485 clearDataProgressDialog.show(
485 activity.getFragmentManager(), CLEAR_DATA_PROGRESS_DIALO G_TAG); 486 activity.getFragmentManager(), CLEAR_DATA_PROGRESS_DIALO G_TAG);
486 } 487 }
487 @Override 488 @Override
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 update(); 536 update();
536 } 537 }
537 538
538 @Override 539 @Override
539 public void onSignedOut() { 540 public void onSignedOut() {
540 update(); 541 update();
541 } 542 }
542 543
543 /** 544 /**
544 * Open the account management UI. 545 * Open the account management UI.
546 * @param applicationContext An application context.
547 * @param profile A user profile.
545 * @param serviceType A signin::GAIAServiceType that triggered the dialog. 548 * @param serviceType A signin::GAIAServiceType that triggered the dialog.
546 */ 549 */
547 public static void openAccountManagementScreen(int serviceType) { 550 public static void openAccountManagementScreen(
548 Intent intent = PreferencesLauncher.createIntentForSettingsPage( 551 Context applicationContext, Profile profile, int serviceType) {
549 ContextUtils.getApplicationContext(), AccountManagementFragment. class.getName()); 552 Intent intent = PreferencesLauncher.createIntentForSettingsPage(applicat ionContext,
553 AccountManagementFragment.class.getName());
550 Bundle arguments = new Bundle(); 554 Bundle arguments = new Bundle();
551 arguments.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, serviceType); 555 arguments.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, serviceType);
552 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, arguments); 556 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, arguments);
553 ContextUtils.getApplicationContext().startActivity(intent); 557 applicationContext.startActivity(intent);
554 } 558 }
555 559
556 /** 560 /**
557 * Converts a square user picture to a round user picture. 561 * Converts a square user picture to a round user picture.
558 * @param bitmap A bitmap to convert. 562 * @param bitmap A bitmap to convert.
559 * @return A rounded picture bitmap. 563 * @return A rounded picture bitmap.
560 */ 564 */
561 public static Bitmap makeRoundUserPicture(Bitmap bitmap) { 565 public static Bitmap makeRoundUserPicture(Bitmap bitmap) {
562 if (bitmap == null) return null; 566 if (bitmap == null) return null;
563 567
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 context, profile, accountName, imageSidePixels, false); 693 context, profile, accountName, imageSidePixels, false);
690 } 694 }
691 695
692 /** 696 /**
693 * Prefetch the primary account image and name. 697 * Prefetch the primary account image and name.
694 * 698 *
695 * @param context A context to use. 699 * @param context A context to use.
696 * @param profile A profile to use. 700 * @param profile A profile to use.
697 */ 701 */
698 public static void prefetchUserNamePicture(Context context, Profile profile) { 702 public static void prefetchUserNamePicture(Context context, Profile profile) {
699 final String accountName = ChromeSigninController.get().getSignedInAccou ntName(); 703 final String accountName = ChromeSigninController.get(context).getSigned InAccountName();
700 if (TextUtils.isEmpty(accountName)) return; 704 if (TextUtils.isEmpty(accountName)) return;
701 if (sToNamePicture.get(accountName) != null) return; 705 if (sToNamePicture.get(accountName) != null) return;
702 706
703 ProfileDownloader.addObserver(new ProfileDownloader.Observer() { 707 ProfileDownloader.addObserver(new ProfileDownloader.Observer() {
704 @Override 708 @Override
705 public void onProfileDownloaded(String accountId, String fullName, S tring givenName, 709 public void onProfileDownloaded(String accountId, String fullName, S tring givenName,
706 Bitmap bitmap) { 710 Bitmap bitmap) {
707 if (TextUtils.equals(accountName, accountId)) { 711 if (TextUtils.equals(accountName, accountId)) {
708 updateUserNamePictureCache(accountId, fullName, bitmap); 712 updateUserNamePictureCache(accountId, fullName, bitmap);
709 ProfileDownloader.removeObserver(this); 713 ProfileDownloader.removeObserver(this);
(...skipping 18 matching lines...) Expand all
728 * @param context A context 732 * @param context A context
729 * @param isAllowed True if the sign out is not disabled due to a child/EDU account 733 * @param isAllowed True if the sign out is not disabled due to a child/EDU account
730 */ 734 */
731 public static void setSignOutAllowedPreferenceValue(Context context, boolean isAllowed) { 735 public static void setSignOutAllowedPreferenceValue(Context context, boolean isAllowed) {
732 ContextUtils.getAppSharedPreferences() 736 ContextUtils.getAppSharedPreferences()
733 .edit() 737 .edit()
734 .putBoolean(SIGN_OUT_ALLOWED, isAllowed) 738 .putBoolean(SIGN_OUT_ALLOWED, isAllowed)
735 .apply(); 739 .apply();
736 } 740 }
737 } 741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698