Commit 69820f8d authored by juncai's avatar juncai Committed by Commit bot

Add code back to change the status of WebBluetooth chooser once discovery is complete

Some context:
https://codereview.chromium.org/1653533002
added code to ItemChooserDialog to notify it that the discovery is complete
and no new devices will be added. It also adds a new string to show when
the discovery is complete.

However,
https://codereview.chromium.org/1739523002
accidentally removed this feature.

This CL added this feature back.

BUG=580346

Review-Url: https://codereview.chromium.org/2175613004
Cr-Commit-Position: refs/heads/master@{#407668}
parent fa40c272
...@@ -141,6 +141,11 @@ public class BluetoothChooserDialog ...@@ -141,6 +141,11 @@ public class BluetoothChooserDialog
new SpanInfo("<link>", "</link>", new SpanInfo("<link>", "</link>",
new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity))); new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
SpannableString statusActive = SpanApplier.applySpans(
mActivity.getString(R.string.bluetooth_not_seeing_it),
new SpanInfo("<link>", "</link>",
new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
SpannableString statusIdleSomeFound = SpanApplier.applySpans( SpannableString statusIdleSomeFound = SpanApplier.applySpans(
mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_found), mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_found),
new SpanInfo("<link1>", "</link1>", new SpanInfo("<link1>", "</link1>",
...@@ -149,7 +154,7 @@ public class BluetoothChooserDialog ...@@ -149,7 +154,7 @@ public class BluetoothChooserDialog
new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity))); new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));
ItemChooserDialog.ItemChooserLabels labels = ItemChooserDialog.ItemChooserLabels labels =
new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
statusIdleNoneFound, statusIdleSomeFound, positiveButton); statusIdleNoneFound, statusIdleSomeFound, positiveButton);
mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels); mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);
......
...@@ -95,6 +95,9 @@ public class ItemChooserDialog { ...@@ -95,6 +95,9 @@ public class ItemChooserDialog {
public final CharSequence searching; public final CharSequence searching;
// The message to show when no results were produced. // The message to show when no results were produced.
public final CharSequence noneFound; public final CharSequence noneFound;
// A status message to show above the button row after an item has
// been added and discovery is still ongoing.
public final CharSequence statusActive;
// A status message to show above the button row after discovery has // A status message to show above the button row after discovery has
// stopped and no devices have been found. // stopped and no devices have been found.
public final CharSequence statusIdleNoneFound; public final CharSequence statusIdleNoneFound;
...@@ -105,11 +108,12 @@ public class ItemChooserDialog { ...@@ -105,11 +108,12 @@ public class ItemChooserDialog {
public final CharSequence positiveButton; public final CharSequence positiveButton;
public ItemChooserLabels(CharSequence title, CharSequence searching, CharSequence noneFound, public ItemChooserLabels(CharSequence title, CharSequence searching, CharSequence noneFound,
CharSequence statusIdleNoneFound, CharSequence statusIdleSomeFound, CharSequence statusActive, CharSequence statusIdleNoneFound,
CharSequence positiveButton) { CharSequence statusIdleSomeFound, CharSequence positiveButton) {
this.title = title; this.title = title;
this.searching = searching; this.searching = searching;
this.noneFound = noneFound; this.noneFound = noneFound;
this.statusActive = statusActive;
this.statusIdleNoneFound = statusIdleNoneFound; this.statusIdleNoneFound = statusIdleNoneFound;
this.statusIdleSomeFound = statusIdleSomeFound; this.statusIdleSomeFound = statusIdleSomeFound;
this.positiveButton = positiveButton; this.positiveButton = positiveButton;
...@@ -119,7 +123,7 @@ public class ItemChooserDialog { ...@@ -119,7 +123,7 @@ public class ItemChooserDialog {
/** /**
* The various states the dialog can represent. * The various states the dialog can represent.
*/ */
private enum State { STARTING, DISCOVERY_IDLE } private enum State { STARTING, PROGRESS_UPDATE_AVAILABLE, DISCOVERY_IDLE }
/** /**
* An adapter for keeping track of which items to show in the dialog. * An adapter for keeping track of which items to show in the dialog.
...@@ -417,7 +421,7 @@ public class ItemChooserDialog { ...@@ -417,7 +421,7 @@ public class ItemChooserDialog {
public void addItemToList(ItemChooserRow item) { public void addItemToList(ItemChooserRow item) {
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
mItemAdapter.add(item); mItemAdapter.add(item);
setState(State.DISCOVERY_IDLE); setState(State.PROGRESS_UPDATE_AVAILABLE);
} }
/** /**
...@@ -474,6 +478,11 @@ public class ItemChooserDialog { ...@@ -474,6 +478,11 @@ public class ItemChooserDialog {
mProgressBar.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.VISIBLE);
mEmptyMessage.setVisibility(View.GONE); mEmptyMessage.setVisibility(View.GONE);
break; break;
case PROGRESS_UPDATE_AVAILABLE:
mStatus.setText(mLabels.statusActive);
mProgressBar.setVisibility(View.GONE);
mListView.setVisibility(View.VISIBLE);
break;
case DISCOVERY_IDLE: case DISCOVERY_IDLE:
boolean showEmptyMessage = mItemAdapter.isEmpty(); boolean showEmptyMessage = mItemAdapter.isEmpty();
mStatus.setText(showEmptyMessage mStatus.setText(showEmptyMessage
......
...@@ -67,7 +67,7 @@ public class UsbChooserDialog implements ItemChooserDialog.ItemSelectedCallback ...@@ -67,7 +67,7 @@ public class UsbChooserDialog implements ItemChooserDialog.ItemSelectedCallback
String searching = ""; String searching = "";
String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt); String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
SpannableString statusIdleNoneFound = SpannableString statusActive =
SpanApplier.applySpans( SpanApplier.applySpans(
activity.getString(R.string.usb_chooser_dialog_footnote_text), activity.getString(R.string.usb_chooser_dialog_footnote_text),
new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() { new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
...@@ -83,11 +83,12 @@ public class UsbChooserDialog implements ItemChooserDialog.ItemSelectedCallback ...@@ -83,11 +83,12 @@ public class UsbChooserDialog implements ItemChooserDialog.ItemSelectedCallback
view.invalidate(); view.invalidate();
} }
})); }));
SpannableString statusIdleSomeFound = statusIdleNoneFound; SpannableString statusIdleNoneFound = statusActive;
SpannableString statusIdleSomeFound = statusActive;
String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text); String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);
ItemChooserDialog.ItemChooserLabels labels = ItemChooserDialog.ItemChooserLabels labels =
new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
statusIdleNoneFound, statusIdleSomeFound, positiveButton); statusIdleNoneFound, statusIdleSomeFound, positiveButton);
mItemChooserDialog = new ItemChooserDialog(activity, this, labels); mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
} }
......
...@@ -1262,6 +1262,9 @@ To obtain new licenses, connect to the internet and play your downloaded content ...@@ -1262,6 +1262,9 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_BLUETOOTH_CONFIRM_BUTTON" desc="The button to confirm association of a website with a Bluetooth device. Use the same term as in 'Pair this Bluetooth headset with your phone.'"> <message name="IDS_BLUETOOTH_CONFIRM_BUTTON" desc="The button to confirm association of a website with a Bluetooth device. Use the same term as in 'Pair this Bluetooth headset with your phone.'">
Pair Pair
</message> </message>
<message name="IDS_BLUETOOTH_NOT_SEEING_IT" desc="The message to show at the bottom of the dialog when Bluetooth scanning has uncovered some items but is still scanning for others.">
Not seeing your device? <ph name="BEGIN_LINK">&lt;link&gt;</ph>Get help<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
<message name="IDS_BLUETOOTH_NOT_SEEING_IT_IDLE_NONE_FOUND" desc="The message to show at the bottom of the dialog when Bluetooth scanning has not uncovered any devices and it is no longer discovering devices."> <message name="IDS_BLUETOOTH_NOT_SEEING_IT_IDLE_NONE_FOUND" desc="The message to show at the bottom of the dialog when Bluetooth scanning has not uncovered any devices and it is no longer discovering devices.">
<ph name="BEGIN_LINK">&lt;link&gt;</ph>Get help<ph name="END_LINK">&lt;/link&gt;</ph> <ph name="BEGIN_LINK">&lt;link&gt;</ph>Get help<ph name="END_LINK">&lt;/link&gt;</ph>
</message> </message>
......
...@@ -224,8 +224,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom ...@@ -224,8 +224,7 @@ public class BluetoothChooserDialogTest extends ChromeActivityTestCaseBase<Chrom
// the progress spinner should disappear, the Commit button should still // the progress spinner should disappear, the Commit button should still
// be disabled (since nothing's selected), and the list view should // be disabled (since nothing's selected), and the list view should
// show. // show.
assertEquals(removeLinkTags(getActivity().getString( assertEquals(removeLinkTags(getActivity().getString(R.string.bluetooth_not_seeing_it)),
R.string.bluetooth_not_seeing_it_idle_some_found)),
statusView.getText().toString()); statusView.getText().toString());
assertFalse(button.isEnabled()); assertFalse(button.isEnabled());
assertEquals(View.VISIBLE, items.getVisibility()); assertEquals(View.VISIBLE, items.getVisibility());
......
...@@ -61,11 +61,12 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi ...@@ -61,11 +61,12 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
SpannableString title = new SpannableString("title"); SpannableString title = new SpannableString("title");
SpannableString searching = new SpannableString("searching"); SpannableString searching = new SpannableString("searching");
SpannableString noneFound = new SpannableString("noneFound"); SpannableString noneFound = new SpannableString("noneFound");
SpannableString statusActive = new SpannableString("statusActive");
SpannableString statusIdleNoneFound = new SpannableString("statusIdleNoneFound"); SpannableString statusIdleNoneFound = new SpannableString("statusIdleNoneFound");
SpannableString statusIdleSomeFound = new SpannableString("statusIdleSomeFound"); SpannableString statusIdleSomeFound = new SpannableString("statusIdleSomeFound");
String positiveButton = new String("positiveButton"); String positiveButton = new String("positiveButton");
final ItemChooserDialog.ItemChooserLabels labels = final ItemChooserDialog.ItemChooserLabels labels =
new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
statusIdleNoneFound, statusIdleSomeFound, positiveButton); statusIdleNoneFound, statusIdleSomeFound, positiveButton);
ItemChooserDialog dialog = ThreadUtils.runOnUiThreadBlockingNoException( ItemChooserDialog dialog = ThreadUtils.runOnUiThreadBlockingNoException(
new Callable<ItemChooserDialog>() { new Callable<ItemChooserDialog>() {
...@@ -134,6 +135,14 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi ...@@ -134,6 +135,14 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key")); mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key"));
mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2", "key2")); mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2", "key2"));
// Two items showing, the empty view should be no more and the button
// should now be enabled.
assertEquals(View.VISIBLE, items.getVisibility());
assertEquals(View.GONE, items.getEmptyView().getVisibility());
assertEquals("statusActive", statusView.getText().toString());
assertFalse(button.isEnabled());
mChooserDialog.setIdleState();
// After discovery stops the list should be visible with two items, // After discovery stops the list should be visible with two items,
// it should not show the empty view and the button should not be enabled. // it should not show the empty view and the button should not be enabled.
// The chooser should show the status idle text. // The chooser should show the status idle text.
...@@ -229,6 +238,8 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi ...@@ -229,6 +238,8 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
assertEquals(itemAdapter.getItem(0), item1); assertEquals(itemAdapter.getItem(0), item1);
assertEquals(itemAdapter.getItem(1), item2); assertEquals(itemAdapter.getItem(1), item2);
mChooserDialog.setIdleState();
// Try removing an item that doesn't exist. // Try removing an item that doesn't exist.
mChooserDialog.removeItemFromList(nonExistentItem); mChooserDialog.removeItemFromList(nonExistentItem);
assertEquals(2, itemAdapter.getCount()); assertEquals(2, itemAdapter.getCount());
......
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