Merge "Move "Received files" in BluetoothSettings" into oc-dr1-dev am: d55579889a
am: 5350ec84c6
Change-Id: I266271d5514f03bbb77fcb8c07cb53387fb1ec39
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user