Commit ef80e6f3 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: add blue dots to flag UI

This updates the flag UI to show blue dots for non-default features. Per
Android best practices, this uses a "compound drawable" (a drawable
attached to a TextView).

This reuses the same shade of blue as chrome://flags.

Bug: 1041600
Test: Manual - toggle flags, restart activity, reset to default, do all
Test: of the above in light/dark theme (works as intended)
Change-Id: Ie3a61ecd8859488964caa1da9e20bd79756d9c39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096118
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarHazem Ashmawy <hazems@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748957}
parent caadf4af
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/blue_circle"
android:shape="oval">
<solid android:color="@color/blue"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>
......@@ -13,6 +13,7 @@
android:layout_marginTop="15dp"
android:orientation="vertical">
<!-- A compound drawable will be populated at runtime, but it's OK to configure drawablePadding now. -->
<TextView
android:id="@+id/flag_name"
android:layout_width="match_parent"
......@@ -20,6 +21,7 @@
android:textIsSelectable="true"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawablePadding="4dp"
android:paddingBottom="2dp"
android:paddingTop="2dp" />
......
......@@ -8,4 +8,5 @@
<resources>
<color name="error_red">#C5221F</color>
<color name="warning_yellow">#FFCC00</color>
<color name="blue">#1967D2</color>
</resources>
......@@ -17,6 +17,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
......@@ -114,8 +115,9 @@ public class FlagsActivity extends Activity {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String flagName = mFlag.getName();
int oldState = booleanToState(mOverriddenFlags.get(flagName));
int newState = position;
switch (sFlagStates[position]) {
switch (sFlagStates[newState]) {
case STATE_DEFAULT:
mOverriddenFlags.remove(flagName);
break;
......@@ -127,12 +129,16 @@ public class FlagsActivity extends Activity {
break;
}
// Only communicate with the service if the map actually updated. This optimizes the
// number of IPCs we make, but this also allows for atomic batch updates by updating
// mOverriddenFlags prior to updating the Spinner state.
int newState = booleanToState(mOverriddenFlags.get(flagName));
// Update UI and Service. Only communicate with the service if the map actually updated.
// This optimizes the number of IPCs we make, but this also allows for atomic batch
// updates by updating mOverriddenFlags prior to updating the Spinner state.
if (oldState != newState) {
sendFlagsToService();
ViewParent grandparent = parent.getParent();
if (grandparent instanceof View) {
formatListEntry((View) grandparent, newState);
}
}
}
......@@ -173,15 +179,35 @@ public class FlagsActivity extends Activity {
adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
flagToggle.setAdapter(adapter);
// Populate spinner state from map.
// Populate spinner state from map and update indicators.
int state = booleanToState(mOverriddenFlags.get(flag.getName()));
flagToggle.setSelection(state);
flagToggle.setOnItemSelectedListener(new FlagStateSpinnerSelectedListener(flag));
formatListEntry(view, state);
return view;
}
}
/**
* Formats a flag list entry. {@code toggleableFlag} should be the View which holds the {@link
* Spinner}, flag title, flag description, etc. as children.
*
* @param toggleableFlag a View representing an entire flag entry.
* @param state the state of the flag.
*/
private void formatListEntry(View toggleableFlag, int state) {
// View stateIndicator = toggleableFlag.findViewById(R.id.flag_state_indicator);
TextView flagName = toggleableFlag.findViewById(R.id.flag_name);
if (state == /* STATE_DEFAULT */ 0) {
// Unset the compound drawable.
flagName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
} else { // STATE_ENABLED or STATE_DISABLED
// Draws a blue circle to the left of the text.
flagName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.blue_circle, 0, 0, 0);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
NavigationMenuHelper.inflate(this, menu);
......
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