Commit 3a13d26e authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

[AW][Dev-UI] scrollable warning message in flag UI

This puts the flag UI's warning text into the ListView so it can scroll
off screen as the user scrolls down the list of flags. This adds some
complexity because the ListView now supports two different types of
layouts.

This swaps the order of the warning text and the "reset all" button.
This is in order to pin the "reset all" button to the top of the
Fragment.

Fixed: 1059881
Test: Manual - verify the warning text scrolls as expected
Change-Id: Id7afd2b256051d6d7bf5cee18c73592021444194
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2330042
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarHazem Ashmawy <hazems@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795070}
parent c484589b
...@@ -14,17 +14,13 @@ ...@@ -14,17 +14,13 @@
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp"> android:paddingEnd="8dp">
<include
layout="@layout/flag_ui_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!--suppress HardcodedText --> <!--suppress HardcodedText -->
<Button <Button
android:text="Reset all to default" android:text="Reset all to default"
android:id="@+id/reset_flags_button" android:id="@+id/reset_flags_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"/> android:textAppearance="?android:attr/textAppearanceMedium"/>
......
...@@ -24,6 +24,9 @@ import android.widget.ListView; ...@@ -24,6 +24,9 @@ import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import org.chromium.android_webview.common.DeveloperModeUtils; import org.chromium.android_webview.common.DeveloperModeUtils;
import org.chromium.android_webview.common.Flag; import org.chromium.android_webview.common.Flag;
import org.chromium.android_webview.common.ProductionSupportedFlagList; import org.chromium.android_webview.common.ProductionSupportedFlagList;
...@@ -73,10 +76,6 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -73,10 +76,6 @@ public class FlagsFragment extends DevUiBaseFragment {
activity.setTitle("WebView Flags"); activity.setTitle("WebView Flags");
ListView flagsListView = view.findViewById(R.id.flags_list); ListView flagsListView = view.findViewById(R.id.flags_list);
TextView flagsDescriptionView = view.findViewById(R.id.flags_description);
flagsDescriptionView.setText("By enabling these features, you could "
+ "lose app data or compromise your security or privacy. Enabled features apply to "
+ "WebViews across all apps on the device.");
// Restore flag overrides from the service process to repopulate the UI, if developer mode // Restore flag overrides from the service process to repopulate the UI, if developer mode
// is enabled. // is enabled.
...@@ -84,7 +83,13 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -84,7 +83,13 @@ public class FlagsFragment extends DevUiBaseFragment {
mOverriddenFlags = DeveloperModeUtils.getFlagOverrides(mContext.getPackageName()); mOverriddenFlags = DeveloperModeUtils.getFlagOverrides(mContext.getPackageName());
} }
mListAdapter = new FlagsListAdapter(sortFlagList(ProductionSupportedFlagList.sFlagList)); Flag[] sortedFlags = sortFlagList(ProductionSupportedFlagList.sFlagList);
Flag[] flagsAndWarningText = new Flag[ProductionSupportedFlagList.sFlagList.length + 1];
flagsAndWarningText[0] = null; // the first entry is the warning text
for (int i = 0; i < ProductionSupportedFlagList.sFlagList.length; i++) {
flagsAndWarningText[i + 1] = sortedFlags[i];
}
mListAdapter = new FlagsListAdapter(flagsAndWarningText);
flagsListView.setAdapter(mListAdapter); flagsListView.setAdapter(mListAdapter);
Button resetFlagsButton = view.findViewById(R.id.reset_flags_button); Button resetFlagsButton = view.findViewById(R.id.reset_flags_button);
...@@ -163,16 +168,22 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -163,16 +168,22 @@ public class FlagsFragment extends DevUiBaseFragment {
public void onNothingSelected(AdapterView<?> parent) {} public void onNothingSelected(AdapterView<?> parent) {}
} }
@IntDef({LayoutType.WARNING_MESSAGE, LayoutType.TOGGLEABLE_FLAG})
private @interface LayoutType {
int WARNING_MESSAGE = 0;
int TOGGLEABLE_FLAG = 1;
int COUNT = 2;
}
/** /**
* Adapter to create rows of toggleable Flags. * Adapter to create rows of toggleable Flags.
*/ */
private class FlagsListAdapter extends ArrayAdapter<Flag> { private class FlagsListAdapter extends ArrayAdapter<Flag> {
public FlagsListAdapter(Flag[] sortedFlags) { public FlagsListAdapter(Flag[] flagsAndWarningText) {
super(mContext, R.layout.toggleable_flag, sortedFlags); super(mContext, 0, flagsAndWarningText);
} }
@Override private View getToggleableFlag(@NonNull Flag flag, View view, ViewGroup parent) {
public View getView(int position, View view, ViewGroup parent) {
// If the the old view is already created then reuse it, else create a new one by layout // If the the old view is already created then reuse it, else create a new one by layout
// inflation. // inflation.
if (view == null) { if (view == null) {
...@@ -183,7 +194,6 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -183,7 +194,6 @@ public class FlagsFragment extends DevUiBaseFragment {
TextView flagDescription = view.findViewById(R.id.flag_description); TextView flagDescription = view.findViewById(R.id.flag_description);
Spinner flagToggle = view.findViewById(R.id.flag_toggle); Spinner flagToggle = view.findViewById(R.id.flag_toggle);
Flag flag = getItem(position);
String label = flag.getName(); String label = flag.getName();
if (flag.getEnabledStateValue() != null) { if (flag.getEnabledStateValue() != null) {
label += "=" + flag.getEnabledStateValue(); label += "=" + flag.getEnabledStateValue();
...@@ -203,6 +213,43 @@ public class FlagsFragment extends DevUiBaseFragment { ...@@ -203,6 +213,43 @@ public class FlagsFragment extends DevUiBaseFragment {
return view; return view;
} }
private View getWarningMessage(View view, ViewGroup parent) {
// If the the old view is already created then reuse it, else create a new one by layout
// inflation.
if (view == null) {
view = getLayoutInflater().inflate(R.layout.flag_ui_warning, null);
}
TextView flagsDescriptionView = view.findViewById(R.id.flags_description);
flagsDescriptionView.setText("By enabling these features, you could "
+ "lose app data or compromise your security or privacy. Enabled features "
+ "apply to WebViews across all apps on the device.");
return view;
}
@Override
@LayoutType
public int getItemViewType(int position) {
if (getItem(position) == null) return LayoutType.WARNING_MESSAGE;
return LayoutType.TOGGLEABLE_FLAG;
}
@Override
public int getViewTypeCount() {
return LayoutType.COUNT;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
Flag flag = getItem(position);
if (getItemViewType(position) == LayoutType.WARNING_MESSAGE) {
return getWarningMessage(view, parent);
} else {
return getToggleableFlag(flag, view, parent);
}
}
} }
/** /**
......
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