Move "Received files" in BluetoothSettings
Move it from menu to preference Also clean up the code about menu since there is no menu anymore in BluetoothSettings Bug: 35876447 Test: RunSettingsRoboTests Change-Id: I4a3821595a0cc75382f1cf74bcafb3ecc44cc178
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/bluetooth_settings">
|
||||
|
||||
<Preference
|
||||
@@ -25,6 +26,12 @@
|
||||
android:key="paired_devices"
|
||||
android:title="@string/bluetooth_paired_device_title"/>
|
||||
|
||||
<com.android.settings.DividerPreference
|
||||
android:key="bt_received_files"
|
||||
android:title="@string/bluetooth_show_received_files"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:allowDividerBelow="true"/>
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Controller that shows received files
|
||||
*/
|
||||
public class BluetoothFilesPreferenceController extends PreferenceController {
|
||||
private static final String TAG = "BluetoothFilesPrefCtrl";
|
||||
|
||||
public static final String KEY_RECEIVED_FILES = "bt_received_files";
|
||||
|
||||
/* Private intent to show the list of received files */
|
||||
@VisibleForTesting
|
||||
static final String ACTION_OPEN_FILES = "com.android.bluetooth.action.TransferHistory";
|
||||
@VisibleForTesting
|
||||
static final String EXTRA_SHOW_ALL_FILES = "android.btopp.intent.extra.SHOW_ALL";
|
||||
@VisibleForTesting
|
||||
static final String EXTRA_DIRECTION = "direction";
|
||||
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
public BluetoothFilesPreferenceController(Context context) {
|
||||
super(context);
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_RECEIVED_FILES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_RECEIVED_FILES.equals(preference.getKey())) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsProto.MetricsEvent.ACTION_BLUETOOTH_FILES);
|
||||
Intent intent = new Intent(ACTION_OPEN_FILES);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.putExtra(EXTRA_DIRECTION, 1 /* DIRECTION_INBOUND */);
|
||||
intent.putExtra(EXTRA_SHOW_ALL_FILES, true);
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -22,7 +22,6 @@ import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
@@ -31,13 +30,9 @@ import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.Spannable;
|
||||
import android.text.style.TextAppearanceSpan;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -75,15 +70,6 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
*/
|
||||
public class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable {
|
||||
private static final String TAG = "BluetoothSettings";
|
||||
|
||||
private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 1;
|
||||
|
||||
/* Private intent to show the list of received files */
|
||||
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
|
||||
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
|
||||
private static final String BTOPP_PACKAGE =
|
||||
"com.android.bluetooth";
|
||||
|
||||
private static final int PAIRED_DEVICE_ORDER = 1;
|
||||
private static final int PAIRING_PREF_ORDER = 2;
|
||||
|
||||
@@ -184,31 +170,6 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (mLocalAdapter == null) return;
|
||||
// If the user is not allowed to configure bluetooth, do not show the menu.
|
||||
if (isUiRestricted()) return;
|
||||
|
||||
menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_ID_SHOW_RECEIVED:
|
||||
mMetricsFeatureProvider.action(getActivity(),
|
||||
MetricsEvent.ACTION_BLUETOOTH_FILES);
|
||||
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
|
||||
intent.setPackage(BTOPP_PACKAGE);
|
||||
getActivity().sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceListKey() {
|
||||
return KEY_PAIRED_DEVICES;
|
||||
@@ -233,7 +194,6 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
mPairedDevicesCategory.addPreference(mPairingPreference);
|
||||
updateFooterPreference(mFooterPreference);
|
||||
|
||||
getActivity().invalidateOptionsMenu();
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
return; // not break
|
||||
|
||||
@@ -258,9 +218,6 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
if (messageId != 0) {
|
||||
getEmptyTextView().setText(messageId);
|
||||
}
|
||||
if (!isUiRestricted()) {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void setOffMessage() {
|
||||
@@ -311,16 +268,6 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
updateContent(bluetoothState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanningStateChanged(boolean started) {
|
||||
super.onScanningStateChanged(started);
|
||||
// Update options' enabled state
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
||||
updateContent(mLocalAdapter.getBluetoothState());
|
||||
@@ -417,6 +364,7 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
(SettingsActivity) getActivity());
|
||||
controllers.add(mDeviceNamePrefController);
|
||||
controllers.add(mPairingPrefController);
|
||||
controllers.add(new BluetoothFilesPreferenceController(context));
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothFilesPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private BluetoothFilesPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new BluetoothFilesPreferenceController(mContext);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(BluetoothFilesPreferenceController.KEY_RECEIVED_FILES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_sendBroadcast() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
|
||||
assertThat(intent).isNotNull();
|
||||
assertThat(intent.getAction()).isEqualTo(
|
||||
BluetoothFilesPreferenceController.ACTION_OPEN_FILES);
|
||||
|
||||
final Bundle bundle = intent.getExtras();
|
||||
assertThat(bundle.getInt(BluetoothFilesPreferenceController.EXTRA_DIRECTION)).isEqualTo(1);
|
||||
assertThat(bundle.getBoolean(
|
||||
BluetoothFilesPreferenceController.EXTRA_SHOW_ALL_FILES)).isTrue();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user