Move device detail edit button from menu to header
Move the edit button on Bluetooth device detail, From action bar menu to header. Use EntityHeaderController to add and control, Rename those method because we use them on more than one place now. Change-Id: I3afad6baeab80895c109603e2ab13428582a4dd8 Fixes: 76206922 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -73,6 +73,16 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
||||
mHeaderController.setIcon(pair.first);
|
||||
mHeaderController.setIconContentDescription(pair.second);
|
||||
mHeaderController.setSummary(summaryText);
|
||||
mHeaderController.setEditListener(v -> showEditDeviceNameDialog());
|
||||
mHeaderController.setButtonActions(
|
||||
EntityHeaderController.ActionType.ACTION_EDIT_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void showEditDeviceNameDialog() {
|
||||
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice).show(
|
||||
mFragment.getFragmentManager(), RemoteDeviceNameDialogFragment.TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -22,9 +22,6 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
@@ -41,9 +38,6 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
public static final String KEY_DEVICE_ADDRESS = "device_address";
|
||||
private static final String TAG = "BTDeviceDetailsFrg";
|
||||
|
||||
@VisibleForTesting
|
||||
static int EDIT_DEVICE_NAME_ITEM_ID = Menu.FIRST;
|
||||
|
||||
/**
|
||||
* An interface to let tests override the normal mechanism for looking up the
|
||||
* CachedBluetoothDevice and LocalBluetoothManager, and substitute their own mocks instead.
|
||||
@@ -60,9 +54,12 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
@VisibleForTesting
|
||||
static TestDataFactory sTestDataFactory;
|
||||
|
||||
private String mDeviceAddress;
|
||||
private LocalBluetoothManager mManager;
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
@VisibleForTesting
|
||||
String mDeviceAddress;
|
||||
@VisibleForTesting
|
||||
LocalBluetoothManager mManager;
|
||||
@VisibleForTesting
|
||||
CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
public BluetoothDeviceDetailsFragment() {
|
||||
super(DISALLOW_CONFIG_BLUETOOTH);
|
||||
@@ -117,24 +114,6 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
return R.xml.bluetooth_device_details_fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem item = menu.add(0, EDIT_DEVICE_NAME_ITEM_ID, 0, R.string.bluetooth_rename_button);
|
||||
item.setIcon(R.drawable.ic_mode_edit);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
if (menuItem.getItemId() == EDIT_DEVICE_NAME_ITEM_ID) {
|
||||
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice).show(
|
||||
getFragmentManager(), RemoteDeviceNameDialogFragment.TAG);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
ArrayList<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
|
@@ -75,7 +75,7 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
.newInstance(mFragment.getActivity(), mFragment,
|
||||
pref.findViewById(R.id.entity_header));
|
||||
|
||||
mController.setEditZenRuleNameListener(new View.OnClickListener() {
|
||||
mController.setEditListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ZenRuleNameDialog.show(mFragment, mRule.getName(), null,
|
||||
@@ -89,7 +89,7 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
.setPackageName(mRule.getOwner().getPackageName())
|
||||
.setUid(mContext.getUserId())
|
||||
.setHasAppInfoLink(false)
|
||||
.setButtonActions(EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
|
||||
.setButtonActions(EntityHeaderController.ActionType.ACTION_EDIT_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE)
|
||||
.done(mFragment.getActivity(), mContext);
|
||||
|
||||
|
@@ -61,13 +61,13 @@ public class EntityHeaderController {
|
||||
@IntDef({ActionType.ACTION_NONE,
|
||||
ActionType.ACTION_APP_PREFERENCE,
|
||||
ActionType.ACTION_NOTIF_PREFERENCE,
|
||||
ActionType.ACTION_DND_RULE_PREFERENCE,})
|
||||
ActionType.ACTION_EDIT_PREFERENCE,})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ActionType {
|
||||
int ACTION_NONE = 0;
|
||||
int ACTION_APP_PREFERENCE = 1;
|
||||
int ACTION_NOTIF_PREFERENCE = 2;
|
||||
int ACTION_DND_RULE_PREFERENCE = 3;
|
||||
int ACTION_EDIT_PREFERENCE = 3;
|
||||
}
|
||||
|
||||
public static final String PREF_KEY_APP_HEADER = "pref_app_header";
|
||||
@@ -100,7 +100,7 @@ public class EntityHeaderController {
|
||||
|
||||
private boolean mIsInstantApp;
|
||||
|
||||
private View.OnClickListener mEditRuleNameOnClickListener;
|
||||
private View.OnClickListener mEditOnClickListener;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the controller.
|
||||
@@ -227,8 +227,8 @@ public class EntityHeaderController {
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityHeaderController setEditZenRuleNameListener(View.OnClickListener listener) {
|
||||
this.mEditRuleNameOnClickListener = listener;
|
||||
public EntityHeaderController setEditListener(View.OnClickListener listener) {
|
||||
this.mEditOnClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -345,13 +345,13 @@ public class EntityHeaderController {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case ActionType.ACTION_DND_RULE_PREFERENCE: {
|
||||
if (mEditRuleNameOnClickListener == null) {
|
||||
case ActionType.ACTION_EDIT_PREFERENCE: {
|
||||
if (mEditOnClickListener == null) {
|
||||
button.setVisibility(View.GONE);
|
||||
} else {
|
||||
button.setImageResource(R.drawable.ic_mode_edit);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button.setOnClickListener(mEditRuleNameOnClickListener);
|
||||
button.setOnClickListener(mEditOnClickListener);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@@ -17,12 +17,19 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
@@ -39,6 +46,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -97,6 +105,10 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
|
||||
verify(mHeaderController).setIconContentDescription(any(String.class));
|
||||
verify(mHeaderController).setSummary(any(String.class));
|
||||
verify(mHeaderController).setSecondSummary(any(String.class));
|
||||
verify(mHeaderController).setEditListener(any(View.OnClickListener.class));
|
||||
verify(mHeaderController).setButtonActions(
|
||||
EntityHeaderController.ActionType.ACTION_EDIT_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE);
|
||||
verify(mHeaderController).done(mActivity, true);
|
||||
}
|
||||
|
||||
@@ -119,4 +131,20 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
|
||||
inOrder.verify(mHeaderController)
|
||||
.setSummary(mContext.getString(R.string.bluetooth_connecting));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShowEditDeviceNameDialog_showDialog() {
|
||||
showScreen(mController);
|
||||
|
||||
FragmentManager fragmentManager = mock(FragmentManager.class);
|
||||
when(mFragment.getFragmentManager()).thenReturn(fragmentManager);
|
||||
FragmentTransaction ft = mock(FragmentTransaction.class);
|
||||
when(fragmentManager.beginTransaction()).thenReturn(ft);
|
||||
|
||||
ArgumentCaptor<Fragment> captor = ArgumentCaptor.forClass(Fragment.class);
|
||||
mController.showEditDeviceNameDialog();
|
||||
verify(ft).add(captor.capture(), eq(RemoteDeviceNameDialogFragment.TAG));
|
||||
RemoteDeviceNameDialogFragment dialog = (RemoteDeviceNameDialogFragment) captor.getValue();
|
||||
assertThat(dialog).isNotNull();
|
||||
}
|
||||
}
|
||||
|
@@ -18,22 +18,13 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -43,15 +34,15 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.fakes.RoboMenu;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BluetoothDeviceDetailsFragmentTest {
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private BluetoothDeviceDetailsFragment mFragment;
|
||||
private Context mContext;
|
||||
|
||||
@@ -67,46 +58,21 @@ public class BluetoothDeviceDetailsFragmentTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
String deviceAddress = "55:66:77:88:99:AA";
|
||||
mFragment = spy(BluetoothDeviceDetailsFragment.newInstance(deviceAddress));
|
||||
mFragment = spy(BluetoothDeviceDetailsFragment.newInstance(TEST_ADDRESS));
|
||||
doReturn(mLocalManager).when(mFragment).getLocalBluetoothManager(any());
|
||||
doReturn(mCachedDevice).when(mFragment).getCachedDevice(any());
|
||||
|
||||
when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
Bundle args = new Bundle();
|
||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, deviceAddress);
|
||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, TEST_ADDRESS);
|
||||
mFragment.setArguments(args);
|
||||
mFragment.onAttach(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renameControlGetsAdded() {
|
||||
RoboMenu menu = new RoboMenu(mContext);
|
||||
MenuInflater inflater = new MenuInflater(mContext);
|
||||
mFragment.onCreateOptionsMenu(menu, inflater);
|
||||
MenuItem item = menu.getItem(0);
|
||||
assertThat(item.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_rename_button));
|
||||
assertThat(item.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_mode_edit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renameControlClicked() {
|
||||
RoboMenu menu = new RoboMenu(mContext);
|
||||
MenuInflater inflater = new MenuInflater(mContext);
|
||||
mFragment.onCreateOptionsMenu(menu, inflater);
|
||||
MenuItem item = menu.getItem(0);
|
||||
assertThat(item.getItemId())
|
||||
.isEqualTo(BluetoothDeviceDetailsFragment.EDIT_DEVICE_NAME_ITEM_ID);
|
||||
|
||||
FragmentManager fragmentManager = mock(FragmentManager.class);
|
||||
when(mFragment.getFragmentManager()).thenReturn(fragmentManager);
|
||||
FragmentTransaction ft = mock(FragmentTransaction.class);
|
||||
when(fragmentManager.beginTransaction()).thenReturn(ft);
|
||||
|
||||
ArgumentCaptor<Fragment> captor = ArgumentCaptor.forClass(Fragment.class);
|
||||
mFragment.onOptionsItemSelected(item);
|
||||
verify(ft).add(captor.capture(), eq(RemoteDeviceNameDialogFragment.TAG));
|
||||
RemoteDeviceNameDialogFragment dialog = (RemoteDeviceNameDialogFragment) captor.getValue();
|
||||
assertThat(dialog).isNotNull();
|
||||
public void verifyOnAttachResult() {
|
||||
assertThat(mFragment.mDeviceAddress).isEqualTo(TEST_ADDRESS);
|
||||
assertThat(mFragment.mManager).isEqualTo(mLocalManager);
|
||||
assertThat(mFragment.mCachedDevice).isEqualTo(mCachedDevice);
|
||||
}
|
||||
}
|
||||
|
@@ -169,7 +169,7 @@ public class EntityHeaderControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindButton_hasEditRuleNameClickListener_shouldShowButton() {
|
||||
public void bindButton_hasEditClickListener_shouldShowButton() {
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.activityInfo = new ActivityInfo();
|
||||
info.activityInfo.packageName = "123";
|
||||
@@ -179,13 +179,13 @@ public class EntityHeaderControllerTest {
|
||||
when(mActivity.getApplicationContext()).thenReturn(mContext);
|
||||
|
||||
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
|
||||
mController.setEditZenRuleNameListener(new View.OnClickListener() {
|
||||
mController.setEditListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
mController.setButtonActions(
|
||||
EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_EDIT_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE);
|
||||
mController.done(mActivity);
|
||||
|
||||
@@ -197,7 +197,7 @@ public class EntityHeaderControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindButton_noEditRuleNameClickListener_shouldNotShowButton() {
|
||||
public void bindButton_noEditClickListener_shouldNotShowButton() {
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.activityInfo = new ActivityInfo();
|
||||
info.activityInfo.packageName = "123";
|
||||
@@ -207,7 +207,7 @@ public class EntityHeaderControllerTest {
|
||||
|
||||
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
|
||||
mController.setButtonActions(
|
||||
EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_EDIT_PREFERENCE,
|
||||
EntityHeaderController.ActionType.ACTION_NONE);
|
||||
mController.done(mActivity);
|
||||
|
||||
|
Reference in New Issue
Block a user