Commit 0b33759f authored by Elizabeth Popova's avatar Elizabeth Popova Committed by Chromium LUCI CQ

[Autofill][Android] Open Autofill-specific help from settings

Prior to this change, on help icon press in Autofill profiles/payments
settings the general help article was opened. With this change the
"Fill out forms automatically" page is shown instead.

Bug: 1157449
Change-Id: If1ac8016713ed58d35f5e777ba07b29cc9eeb847
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592796Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Elizabeth Popova <lizapopova@google.com>
Cr-Commit-Position: refs/heads/master@{#838019}
parent 1e3aedba
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.autofill;
import android.app.Activity;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.res.Configuration;
......@@ -26,6 +27,8 @@ import androidx.core.widget.TextViewCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.profiles.Profile;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -61,6 +64,16 @@ public class AutofillUiUtils {
int NOT_ENOUGH_INFO = 6;
int NONE = 7;
}
/**
* Launches the Autofill help page on top of the current @{link android.app.Activity} and
* current @{link Profile}.
*/
public static void launchAutofillHelpPage(Activity activity, Profile profile) {
HelpAndFeedbackLauncherImpl.getInstance().show(
activity, activity.getString(R.string.help_context_autofill), profile, null);
}
/**
* Show Tooltip UI.
*
......
......@@ -9,7 +9,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
......@@ -42,8 +41,8 @@ import androidx.core.view.MarginLayoutParamsCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.autofill.settings.CreditCardNumberFormattingTextWatcher;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.browser_ui.widget.AlwaysDismissedDialog;
......@@ -76,7 +75,7 @@ public class EditorDialog
private static EditorObserverForTest sObserverForTest;
private final Context mContext;
private final Activity mActivity;
private final Handler mHandler;
private final TextView.OnEditorActionListener mEditorActionListener;
private final int mHalfRowMargin;
......@@ -115,7 +114,7 @@ public class EditorDialog
super(activity, R.style.Theme_Chromium_Fullscreen);
// Sets transparent background for animating content view.
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mContext = activity;
mActivity = activity;
mHandler = new Handler();
mIsDismissed = false;
mEditorActionListener = new TextView.OnEditorActionListener() {
......@@ -172,12 +171,6 @@ public class EditorDialog
getWindow().setAttributes(attributes);
}
/** Launches the Autofill help page on top of the current Context and current Profile. */
public static void launchAutofillHelpPage(Context context, Profile profile) {
HelpAndFeedbackLauncherImpl.getInstance().show((Activity) context,
context.getString(R.string.help_context_autofill), profile, null);
}
/**
* Prepares the toolbar for use.
*
......@@ -202,7 +195,7 @@ public class EditorDialog
mDeleteRunnable.run();
animateOutDialog();
} else if (item.getItemId() == R.id.help_menu_id) {
launchAutofillHelpPage(mContext, mProfile);
AutofillUiUtils.launchAutofillHelpPage(mActivity, mProfile);
}
return true;
}
......@@ -406,7 +399,7 @@ public class EditorDialog
addFieldViewToEditor(mDataView, fieldModel);
} else {
// Create a LinearLayout to put it and the next view side by side.
LinearLayout rowLayout = new LinearLayout(mContext);
LinearLayout rowLayout = new LinearLayout(mActivity);
mDataView.addView(rowLayout);
View firstView = addFieldViewToEditor(rowLayout, fieldModel);
......@@ -448,9 +441,9 @@ public class EditorDialog
View childView = null;
if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_ICONS) {
childView = new EditorIconsField(mContext, parent, fieldModel).getLayout();
childView = new EditorIconsField(mActivity, parent, fieldModel).getLayout();
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_LABEL) {
childView = new EditorLabelField(mContext, parent, fieldModel).getLayout();
childView = new EditorLabelField(mActivity, parent, fieldModel).getLayout();
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_DROPDOWN) {
Runnable prepareEditorRunnable = new Runnable() {
@Override
......@@ -465,7 +458,7 @@ public class EditorDialog
}
};
EditorDropdownField dropdownView =
new EditorDropdownField(mContext, parent, fieldModel, prepareEditorRunnable);
new EditorDropdownField(mActivity, parent, fieldModel, prepareEditorRunnable);
mFieldViews.add(dropdownView);
mDropdownFields.add(dropdownView.getDropdown());
......@@ -475,7 +468,7 @@ public class EditorDialog
checkbox.setId(R.id.payments_edit_checkbox);
checkbox.setText(fieldModel.getLabel());
checkbox.setChecked(fieldModel.isChecked());
checkbox.setMinimumHeight(mContext.getResources().getDimensionPixelSize(
checkbox.setMinimumHeight(mActivity.getResources().getDimensionPixelSize(
R.dimen.editor_dialog_checkbox_min_height));
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
......@@ -499,7 +492,7 @@ public class EditorDialog
}
EditorTextField inputLayout = new EditorTextField(
mContext, fieldModel, mEditorActionListener, filter, formatter);
mActivity, fieldModel, mEditorActionListener, filter, formatter);
mFieldViews.add(inputLayout);
EditText input = inputLayout.getEditText();
......@@ -527,15 +520,15 @@ public class EditorDialog
*/
public void show(EditorModel editorModel) {
// If an asynchronous task calls show, while the activity is already finishing, return.
if (((Activity) mContext).isFinishing()) return;
if (mActivity.isFinishing()) return;
setOnShowListener(this);
setOnDismissListener(this);
mEditorModel = editorModel;
mLayout = LayoutInflater.from(mContext).inflate(R.layout.payment_request_editor, null);
mLayout = LayoutInflater.from(mActivity).inflate(R.layout.payment_request_editor, null);
setContentView(mLayout);
mFooter = LayoutInflater.from(mContext).inflate(
mFooter = LayoutInflater.from(mActivity).inflate(
R.layout.editable_option_editor_footer, null, false);
prepareToolbar();
......
......@@ -27,7 +27,7 @@ import android.widget.Spinner;
import androidx.fragment.app.Fragment;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.browser_ui.widget.FadingEdgeScrollView;
......@@ -93,8 +93,10 @@ public abstract class AutofillEditorBase
deleteEntry();
getActivity().finish();
return true;
} else if (item.getItemId() == R.id.help_menu_id) {
EditorDialog.launchAutofillHelpPage(getActivity(), Profile.getLastUsedRegularProfile());
}
if (item.getItemId() == R.id.help_menu_id) {
AutofillUiUtils.launchAutofillHelpPage(
getActivity(), Profile.getLastUsedRegularProfile());
return true;
}
......
......@@ -10,6 +10,9 @@ import android.graphics.drawable.Drawable;
import android.hardware.biometrics.BiometricManager;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
......@@ -19,10 +22,12 @@ import androidx.preference.PreferenceScreen;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.payments.AndroidPaymentAppFactory;
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
......@@ -37,7 +42,7 @@ public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getActivity().setTitle(R.string.autofill_payment_methods);
setHasOptionsMenu(true);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getStyledContext());
// Suppresses unwanted animations while Preferences are removed from and re-added to the
// screen.
......@@ -46,6 +51,24 @@ public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat
setPreferenceScreen(screen);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem help =
menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
help.setIcon(R.drawable.ic_help_and_feedback);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_id_targeted_help) {
AutofillUiUtils.launchAutofillHelpPage(
getActivity(), Profile.getLastUsedRegularProfile());
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onResume() {
super.onResume();
......
......@@ -8,6 +8,9 @@ import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
......@@ -17,6 +20,7 @@ import androidx.preference.PreferenceScreen;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog;
......@@ -41,7 +45,7 @@ public class AutofillProfilesFragment extends PreferenceFragmentCompat
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getActivity().setTitle(R.string.autofill_addresses_settings_title);
setHasOptionsMenu(true);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getStyledContext());
// Suppresses unwanted animations while Preferences are removed from and re-added to the
// screen.
......@@ -50,6 +54,24 @@ public class AutofillProfilesFragment extends PreferenceFragmentCompat
setPreferenceScreen(screen);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem help =
menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
help.setIcon(R.drawable.ic_help_and_feedback);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_id_targeted_help) {
AutofillUiUtils.launchAutofillHelpPage(
getActivity(), Profile.getLastUsedRegularProfile());
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onResume() {
super.onResume();
......
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