Loading res/xml/bluetooth_device_details_fragment.xml 0 → 100644 +29 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/bluetooth_device_advanced_title"> <com.android.settings.applications.LayoutPreference android:key="action_buttons" android:layout="@layout/app_action_buttons" android:selectable="false"/> <PreferenceCategory android:key="bluetooth_profiles"/> </PreferenceScreen> No newline at end of file src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java 0 → 100644 +86 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.widget.Button; import com.android.settings.R; import com.android.settings.applications.LayoutPreference; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; /** * This class adds two buttons: one to connect/disconnect from a device (depending on the current * connected state), and one to "forget" (ie unpair) the device. */ public class BluetoothDetailsButtonsController extends BluetoothDetailsController { private static final String KEY_ACTION_BUTTONS = "action_buttons"; private boolean mIsConnected; private LayoutPreference mActionButtons; public BluetoothDetailsButtonsController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); mIsConnected = device.isConnected(); } @Override protected void init(PreferenceScreen screen) { mActionButtons = (LayoutPreference) screen.findPreference(getPreferenceKey()); Button rightButton = (Button) mActionButtons.findViewById(R.id.right_button); rightButton.setText(R.string.forget); rightButton.setOnClickListener((view) -> { mCachedDevice.unpair(); mFragment.getActivity().finish(); }); } @Override protected void refresh() { Button leftButton = (Button) mActionButtons.findViewById(R.id.left_button); leftButton.setEnabled(!mCachedDevice.isBusy()); boolean notInitialized = TextUtils.isEmpty(leftButton.getText()); boolean previouslyConnected = mIsConnected; mIsConnected = mCachedDevice.isConnected(); if (mIsConnected) { if (notInitialized || !previouslyConnected) { leftButton.setText(R.string.bluetooth_device_context_disconnect); leftButton.setOnClickListener((view) -> { mCachedDevice.disconnect(); }); } } else { if (notInitialized || previouslyConnected) { leftButton.setText(R.string.bluetooth_device_context_connect); leftButton.setOnClickListener((view) -> { mCachedDevice.connect(true); }); } } } @Override public String getPreferenceKey() { return KEY_ACTION_BUTTONS; } } src/com/android/settings/bluetooth/BluetoothDetailsController.java 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import com.android.settings.core.PreferenceController; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnPause; import com.android.settingslib.core.lifecycle.events.OnResume; /** * This class provides common lifecycle and bluetooth device event registration for Bluetooth device * details controllers. */ public abstract class BluetoothDetailsController extends PreferenceController implements CachedBluetoothDevice.Callback, LifecycleObserver, OnPause, OnResume { protected final Context mContext; protected final PreferenceFragment mFragment; protected final CachedBluetoothDevice mCachedDevice; public BluetoothDetailsController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context); mContext = context; mFragment = fragment; mCachedDevice = device; lifecycle.addObserver(this); } @Override public void onPause() { mCachedDevice.unregisterCallback(this); } @Override public void onResume() { mCachedDevice.registerCallback(this); refresh(); } @Override public boolean isAvailable() { return true; } @Override public void onDeviceAttributesChanged() { refresh(); } @Override public final void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); init(screen); } /** * This is a method to do one-time initialization when the screen is first created, such as * adding preferences. * @param screen the screen where this controller's preferences should be added */ protected abstract void init(PreferenceScreen screen); /** * This method is called when something about the bluetooth device has changed, and this object * should update the preferences it manages based on the new state. */ protected abstract void refresh(); } src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import android.util.Pair; import com.android.settings.applications.LayoutPreference; import com.android.settings.widget.EntityHeaderController; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; /** * This class adds a header with device name and status (connected/disconnected, etc.). */ public class BluetoothDetailsHeaderController extends BluetoothDetailsController { private EntityHeaderController mHeaderController; public BluetoothDetailsHeaderController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); } @Override protected void init(PreferenceScreen screen) { mHeaderController = EntityHeaderController.newInstance(mFragment.getActivity(), mFragment, null); LayoutPreference pref = mHeaderController.done(mFragment.getActivity(), mContext); screen.addPreference(pref); } protected void setHeaderProperties() { Pair<Integer, String> pair = Utils.getBtClassDrawableWithDescription (mContext.getResources(), mCachedDevice); int summaryResourceId = mCachedDevice.getConnectionSummary(); mHeaderController.setLabel(mCachedDevice.getName()); mHeaderController.setIcon(mContext.getDrawable(pair.first)); mHeaderController.setIconContentDescription(pair.second); mHeaderController.setSummary( summaryResourceId > 0 ? mContext.getString(summaryResourceId) : null); } @Override protected void refresh() { setHeaderProperties(); mHeaderController.done(mFragment.getActivity(), false); } @Override public String getPreferenceKey() { return EntityHeaderController.PREF_KEY_APP_HEADER; } } src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import com.android.settings.R; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.FooterPreference; import com.android.settingslib.widget.FooterPreferenceMixin; /** * This class adds the device MAC address to a footer. */ public class BluetoothDetailsMacAddressController extends BluetoothDetailsController { FooterPreferenceMixin mFooterPreferenceMixin; FooterPreference mFooterPreference; public BluetoothDetailsMacAddressController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); mFooterPreferenceMixin = new FooterPreferenceMixin(fragment, lifecycle); } @Override protected void init(PreferenceScreen screen) { mFooterPreference = mFooterPreferenceMixin.createFooterPreference(); mFooterPreference.setTitle(mContext.getString( R.string.bluetooth_device_mac_address, mCachedDevice.getDevice().getAddress())); } @Override protected void refresh() {} @Override public String getPreferenceKey() { return mFooterPreference.getKey(); } } Loading
res/xml/bluetooth_device_details_fragment.xml 0 → 100644 +29 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/bluetooth_device_advanced_title"> <com.android.settings.applications.LayoutPreference android:key="action_buttons" android:layout="@layout/app_action_buttons" android:selectable="false"/> <PreferenceCategory android:key="bluetooth_profiles"/> </PreferenceScreen> No newline at end of file
src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java 0 → 100644 +86 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.widget.Button; import com.android.settings.R; import com.android.settings.applications.LayoutPreference; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; /** * This class adds two buttons: one to connect/disconnect from a device (depending on the current * connected state), and one to "forget" (ie unpair) the device. */ public class BluetoothDetailsButtonsController extends BluetoothDetailsController { private static final String KEY_ACTION_BUTTONS = "action_buttons"; private boolean mIsConnected; private LayoutPreference mActionButtons; public BluetoothDetailsButtonsController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); mIsConnected = device.isConnected(); } @Override protected void init(PreferenceScreen screen) { mActionButtons = (LayoutPreference) screen.findPreference(getPreferenceKey()); Button rightButton = (Button) mActionButtons.findViewById(R.id.right_button); rightButton.setText(R.string.forget); rightButton.setOnClickListener((view) -> { mCachedDevice.unpair(); mFragment.getActivity().finish(); }); } @Override protected void refresh() { Button leftButton = (Button) mActionButtons.findViewById(R.id.left_button); leftButton.setEnabled(!mCachedDevice.isBusy()); boolean notInitialized = TextUtils.isEmpty(leftButton.getText()); boolean previouslyConnected = mIsConnected; mIsConnected = mCachedDevice.isConnected(); if (mIsConnected) { if (notInitialized || !previouslyConnected) { leftButton.setText(R.string.bluetooth_device_context_disconnect); leftButton.setOnClickListener((view) -> { mCachedDevice.disconnect(); }); } } else { if (notInitialized || previouslyConnected) { leftButton.setText(R.string.bluetooth_device_context_connect); leftButton.setOnClickListener((view) -> { mCachedDevice.connect(true); }); } } } @Override public String getPreferenceKey() { return KEY_ACTION_BUTTONS; } }
src/com/android/settings/bluetooth/BluetoothDetailsController.java 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import com.android.settings.core.PreferenceController; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnPause; import com.android.settingslib.core.lifecycle.events.OnResume; /** * This class provides common lifecycle and bluetooth device event registration for Bluetooth device * details controllers. */ public abstract class BluetoothDetailsController extends PreferenceController implements CachedBluetoothDevice.Callback, LifecycleObserver, OnPause, OnResume { protected final Context mContext; protected final PreferenceFragment mFragment; protected final CachedBluetoothDevice mCachedDevice; public BluetoothDetailsController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context); mContext = context; mFragment = fragment; mCachedDevice = device; lifecycle.addObserver(this); } @Override public void onPause() { mCachedDevice.unregisterCallback(this); } @Override public void onResume() { mCachedDevice.registerCallback(this); refresh(); } @Override public boolean isAvailable() { return true; } @Override public void onDeviceAttributesChanged() { refresh(); } @Override public final void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); init(screen); } /** * This is a method to do one-time initialization when the screen is first created, such as * adding preferences. * @param screen the screen where this controller's preferences should be added */ protected abstract void init(PreferenceScreen screen); /** * This method is called when something about the bluetooth device has changed, and this object * should update the preferences it manages based on the new state. */ protected abstract void refresh(); }
src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import android.util.Pair; import com.android.settings.applications.LayoutPreference; import com.android.settings.widget.EntityHeaderController; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; /** * This class adds a header with device name and status (connected/disconnected, etc.). */ public class BluetoothDetailsHeaderController extends BluetoothDetailsController { private EntityHeaderController mHeaderController; public BluetoothDetailsHeaderController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); } @Override protected void init(PreferenceScreen screen) { mHeaderController = EntityHeaderController.newInstance(mFragment.getActivity(), mFragment, null); LayoutPreference pref = mHeaderController.done(mFragment.getActivity(), mContext); screen.addPreference(pref); } protected void setHeaderProperties() { Pair<Integer, String> pair = Utils.getBtClassDrawableWithDescription (mContext.getResources(), mCachedDevice); int summaryResourceId = mCachedDevice.getConnectionSummary(); mHeaderController.setLabel(mCachedDevice.getName()); mHeaderController.setIcon(mContext.getDrawable(pair.first)); mHeaderController.setIconContentDescription(pair.second); mHeaderController.setSummary( summaryResourceId > 0 ? mContext.getString(summaryResourceId) : null); } @Override protected void refresh() { setHeaderProperties(); mHeaderController.done(mFragment.getActivity(), false); } @Override public String getPreferenceKey() { return EntityHeaderController.PREF_KEY_APP_HEADER; } }
src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * 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.support.v14.preference.PreferenceFragment; import android.support.v7.preference.PreferenceScreen; import com.android.settings.R; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.FooterPreference; import com.android.settingslib.widget.FooterPreferenceMixin; /** * This class adds the device MAC address to a footer. */ public class BluetoothDetailsMacAddressController extends BluetoothDetailsController { FooterPreferenceMixin mFooterPreferenceMixin; FooterPreference mFooterPreference; public BluetoothDetailsMacAddressController(Context context, PreferenceFragment fragment, CachedBluetoothDevice device, Lifecycle lifecycle) { super(context, fragment, device, lifecycle); mFooterPreferenceMixin = new FooterPreferenceMixin(fragment, lifecycle); } @Override protected void init(PreferenceScreen screen) { mFooterPreference = mFooterPreferenceMixin.createFooterPreference(); mFooterPreference.setTitle(mContext.getString( R.string.bluetooth_device_mac_address, mCachedDevice.getDevice().getAddress())); } @Override protected void refresh() {} @Override public String getPreferenceKey() { return mFooterPreference.getKey(); } }