@Override
 public void setListening(boolean listening) {
   if (listening) {
     mController.addStateChangedCallback(mCallback);
   } else {
     mController.removeStateChangedCallback(mCallback);
   }
 }
 @Override
 protected void handleSecondaryClick() {
   if (!mState.value) {
     mState.value = true;
     mController.setBluetoothEnabled(true);
   }
   showDetail(true);
 }
  @Override
  protected void handleUpdateState(BooleanState state, Object arg) {
    final boolean supported = mController.isBluetoothSupported();
    final boolean enabled = mController.isBluetoothEnabled();
    final boolean connected = mController.isBluetoothConnected();
    final boolean connecting = mController.isBluetoothConnecting();
    state.visible = supported;
    state.value = enabled;
    state.autoMirrorDrawable = false;
    if (enabled) {
      state.label = null;
      if (connected) {
        state.icon = ResourceIcon.get(R.drawable.ic_qs_bluetooth_connected);
        state.contentDescription =
            mContext.getString(R.string.accessibility_quick_settings_bluetooth_connected);
        state.label = mController.getLastDeviceName();
      } else if (connecting) {
        state.icon = ResourceIcon.get(R.drawable.ic_qs_bluetooth_connecting);
        state.contentDescription =
            mContext.getString(R.string.accessibility_quick_settings_bluetooth_connecting);
        state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
      } else {
        state.icon = ResourceIcon.get(R.drawable.ic_qs_bluetooth_on);
        state.contentDescription =
            mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
      }
      if (TextUtils.isEmpty(state.label)) {
        state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
      }
    } else {
      state.icon = ResourceIcon.get(R.drawable.ic_qs_bluetooth_off);
      state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
      state.contentDescription =
          mContext.getString(R.string.accessibility_quick_settings_bluetooth_off);
    }

    String bluetoothName = state.label;
    if (connected) {
      bluetoothName =
          state.dualLabelContentDescription =
              mContext.getString(R.string.accessibility_bluetooth_name, state.label);
    }
    state.dualLabelContentDescription = bluetoothName;
  }
 @Override
 protected void handleClick() {
   final boolean isEnabled = (Boolean) mState.value;
   MetricsLogger.action(mContext, getMetricsCategory(), !isEnabled);
   mController.setBluetoothEnabled(!isEnabled);
 }