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:
HJ ChangLiao
2018-04-12 13:14:57 +08:00
parent ccec4e830c
commit f3be34e01b
7 changed files with 68 additions and 85 deletions

View File

@@ -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

View File

@@ -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<>();

View File

@@ -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);

View File

@@ -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;
}