Commit 00afc12d authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Use support library fragments in FRE and sign-in

This CL migrates FirstRun and sign-in activities to support library
fragments (android.support.v4.app.Fragment instead of
android.app.Fragment).
Rationale for this migration:
1. Framework version of fragments are getting deprecated in Android P.
2. Enables use of getChildFragmentManager, getParentFragment, etc., on
all API versions.

Bug: 825789
Change-Id: I2079f211b03e4df1d169c1568d764763bb677bd1
Reviewed-on: https://chromium-review.googlesource.com/980335Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545853}
parent 139eab66
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -118,4 +119,9 @@ public class AccountFirstRunFragment ...@@ -118,4 +119,9 @@ public class AccountFirstRunFragment
mView.cancelConfirmationScreen(); mView.cancelConfirmationScreen();
return true; return true;
} }
@Override
public FragmentManager getSupportFragmentManager() {
return getFragmentManager();
}
} }
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
...@@ -222,7 +222,7 @@ public class FirstRunActivity extends FirstRunActivityBase implements FirstRunPa ...@@ -222,7 +222,7 @@ public class FirstRunActivity extends FirstRunActivityBase implements FirstRunPa
return; return;
} }
mPagerAdapter = new FirstRunPagerAdapter(getFragmentManager(), mPages); mPagerAdapter = new FirstRunPagerAdapter(getSupportFragmentManager(), mPages);
stopProgressionIfNotAcceptedTermsOfService(); stopProgressionIfNotAcceptedTermsOfService();
mPager.setAdapter(mPagerAdapter); mPager.setAdapter(mPagerAdapter);
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Activity; import android.support.v4.app.Fragment;
import android.app.Fragment; import android.support.v4.app.FragmentActivity;
/** /**
* This interface is implemented by FRE fragments. * This interface is implemented by FRE fragments.
...@@ -26,7 +26,7 @@ public interface FirstRunFragment { ...@@ -26,7 +26,7 @@ public interface FirstRunFragment {
/** /**
* @see Fragment#getActivity(). * @see Fragment#getActivity().
*/ */
Activity getActivity(); FragmentActivity getActivity();
/** /**
* Convenience method to get {@link FirstRunPageDelegate}. * Convenience method to get {@link FirstRunPageDelegate}.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment; import android.support.v4.app.Fragment;
/** /**
* Represents first run page shown during the First Run. Actual page implementation is created * Represents first run page shown during the First Run. Actual page implementation is created
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment; import android.support.v4.app.Fragment;
import android.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.List; import java.util.List;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.metrics.UmaSessionStats; import org.chromium.chrome.browser.metrics.UmaSessionStats;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
package org.chromium.chrome.browser.firstrun; package org.chromium.chrome.browser.firstrun;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.provider.Settings; import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
......
...@@ -26,6 +26,7 @@ import android.preference.PreferenceCategory; ...@@ -26,6 +26,7 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.widget.ListView; import android.widget.ListView;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
...@@ -236,9 +237,14 @@ public class AccountManagementFragment extends PreferenceFragment ...@@ -236,9 +237,14 @@ public class AccountManagementFragment extends PreferenceFragment
String managementDomain = SigninManager.get().getManagementDomain(); String managementDomain = SigninManager.get().getManagementDomain();
if (managementDomain != null) { if (managementDomain != null) {
// Show the 'You are signing out of a managed account' dialog. // Show the 'You are signing out of a managed account' dialog.
// TODO(https://crbug.com/710657): Migrate to AccountManagementFragment to
// extend android.support.v7.preference.Preference and remove this cast.
FragmentActivity fragmentActivity = (FragmentActivity) getActivity();
ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog( ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog(
AccountManagementFragment.this, getFragmentManager(), AccountManagementFragment.this,
getResources(), managementDomain); fragmentActivity.getSupportFragmentManager(), getResources(),
managementDomain);
} else { } else {
// Show the 'You are signing out' dialog. // Show the 'You are signing out' dialog.
SignOutDialogFragment signOutFragment = new SignOutDialogFragment(); SignOutDialogFragment signOutFragment = new SignOutDialogFragment();
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
...@@ -94,11 +94,11 @@ public class AccountSigninView extends FrameLayout { ...@@ -94,11 +94,11 @@ public class AccountSigninView extends FrameLayout {
/** /**
* Provides a FragmentManager for the View to create dialogs. This is done through a * Provides a FragmentManager for the View to create dialogs. This is done through a
* different mechanism than getActivity().getFragmentManager() as a potential fix to * different mechanism than getActivity().getSupportFragmentManager() as a potential fix to
* https://crbug.com/646978 on the theory that getActivity() and getFragmentManager() * https://crbug.com/646978 on the theory that getActivity() and getSupportFragmentManager()
* return null at different times. * return null at different times.
*/ */
FragmentManager getFragmentManager(); FragmentManager getSupportFragmentManager();
} }
private static final String TAG = "AccountSigninView"; private static final String TAG = "AccountSigninView";
...@@ -421,7 +421,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -421,7 +421,7 @@ public class AccountSigninView extends FrameLayout {
if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) { if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) {
// This callback is invoked after AccountSigninView is detached from window // This callback is invoked after AccountSigninView is detached from window
// (e.g., Chrome is minimized). Updating view now is redundant and dangerous // (e.g., Chrome is minimized). Updating view now is redundant and dangerous
// (getFragmentManager() can return null, etc.). See https://crbug.com/733117. // (getSupportFragmentManager() can return null, etc.). See https://crbug.com/733117.
return; return;
} }
...@@ -669,7 +669,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -669,7 +669,7 @@ public class AccountSigninView extends FrameLayout {
private void runStateMachineAndShowConfirmationPage() { private void runStateMachineAndShowConfirmationPage() {
mConfirmSyncDataStateMachine = new ConfirmSyncDataStateMachine(getContext(), mConfirmSyncDataStateMachine = new ConfirmSyncDataStateMachine(getContext(),
mDelegate.getFragmentManager(), ImportSyncType.PREVIOUS_DATA_FOUND, mDelegate.getSupportFragmentManager(), ImportSyncType.PREVIOUS_DATA_FOUND,
PrefServiceBridge.getInstance().getSyncLastAccountName(), mSelectedAccountName, PrefServiceBridge.getInstance().getSyncLastAccountName(), mSelectedAccountName,
new ConfirmImportSyncDataDialog.Listener() { new ConfirmImportSyncDataDialog.Listener() {
@Override @Override
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import org.chromium.chrome.R; import org.chromium.chrome.R;
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
package org.chromium.chrome.browser.sync; package org.chromium.chrome.browser.sync;
import android.app.Activity;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
...@@ -34,7 +34,7 @@ public class SyncAccountSwitcher ...@@ -34,7 +34,7 @@ public class SyncAccountSwitcher
private static final String TAG = "SyncAccountSwitcher"; private static final String TAG = "SyncAccountSwitcher";
private final SyncedAccountPreference mSyncedAccountPreference; private final SyncedAccountPreference mSyncedAccountPreference;
private final Activity mActivity; private final FragmentActivity mActivity;
private String mNewAccountName; private String mNewAccountName;
...@@ -44,7 +44,8 @@ public class SyncAccountSwitcher ...@@ -44,7 +44,8 @@ public class SyncAccountSwitcher
* for the data sync fragment. * for the data sync fragment.
* @param syncedAccountPreference The preference to update once signin has been completed. * @param syncedAccountPreference The preference to update once signin has been completed.
*/ */
public SyncAccountSwitcher(Activity activity, SyncedAccountPreference syncedAccountPreference) { public SyncAccountSwitcher(
FragmentActivity activity, SyncedAccountPreference syncedAccountPreference) {
mActivity = activity; mActivity = activity;
mSyncedAccountPreference = syncedAccountPreference; mSyncedAccountPreference = syncedAccountPreference;
} }
...@@ -58,7 +59,7 @@ public class SyncAccountSwitcher ...@@ -58,7 +59,7 @@ public class SyncAccountSwitcher
if (TextUtils.equals(mNewAccountName, currentAccount)) return false; if (TextUtils.equals(mNewAccountName, currentAccount)) return false;
new ConfirmSyncDataStateMachine(mActivity, mActivity.getFragmentManager(), new ConfirmSyncDataStateMachine(mActivity, mActivity.getSupportFragmentManager(),
ImportSyncType.SWITCHING_SYNC_ACCOUNTS, currentAccount, mNewAccountName, this); ImportSyncType.SWITCHING_SYNC_ACCOUNTS, currentAccount, mNewAccountName, this);
// Don't update the selected account in the preference. It will be updated by // Don't update the selected account in the preference. It will be updated by
......
...@@ -22,6 +22,7 @@ import android.preference.PreferenceFragment; ...@@ -22,6 +22,7 @@ import android.preference.PreferenceFragment;
import android.preference.SwitchPreference; import android.preference.SwitchPreference;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.v4.app.FragmentActivity;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
...@@ -210,8 +211,12 @@ public class SyncCustomizationFragment extends PreferenceFragment ...@@ -210,8 +211,12 @@ public class SyncCustomizationFragment extends PreferenceFragment
mSyncedAccountPreference = mSyncedAccountPreference =
(SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST); (SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST);
// TODO(https://crbug.com/710657): Migrate to SyncCustomizationFragment to
// extend android.support.v7.preference.Preference and remove this cast.
FragmentActivity fragmentActivity = (FragmentActivity) getActivity();
mSyncedAccountPreference.setOnPreferenceChangeListener( mSyncedAccountPreference.setOnPreferenceChangeListener(
new SyncAccountSwitcher(getActivity(), mSyncedAccountPreference)); new SyncAccountSwitcher(fragmentActivity, mSyncedAccountPreference));
return view; return view;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment