Update Bluetooth toggle UI to UX spec - settings

Change-Id: I171d3e55e8a480d304e4dc4e0debbd2f3ab27651
This commit is contained in:
Svet Ganov
2016-09-01 16:34:16 -07:00
parent 597e0d8c36
commit 0cf1298a44
3 changed files with 107 additions and 35 deletions

View File

@@ -263,39 +263,55 @@
<!-- Strings for BluetoothDevicePicker [CHAR LIMIT=40]-->
<string name="device_picker">Choose Bluetooth device</string>
<!-- Strings for dialog title when asking to the user whether to allow an app to enable discovery mode -->
<string name="bluetooth_permission_request">"Bluetooth permission request"</string>
<!-- This string asks the user whether or not to allow an app to enable bluetooth. [CHAR LIMIT=100] -->
<string name="bluetooth_ask_enablement"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth</string>
<!-- This string asks the user whether or not to allow an app to disable bluetooth. [CHAR LIMIT=100] -->
<string name="bluetooth_ask_disablement"><xliff:g id="app_name">%1$s</xliff:g> wants to turn off Bluetooth</string>
<!-- This string asks the user whether or not to allow an app to enable bluetooth. [CHAR LIMIT=100] -->
<string name="bluetooth_ask_enablement">An app wants to turn Bluetooth ON for this device.</string>
<string name="bluetooth_ask_enablement_no_name">An app wants to turn on Bluetooth</string>
<!-- This string asks the user whether or not to allow an app to disable bluetooth. [CHAR LIMIT=100] -->
<string name="bluetooth_ask_disablement">An app wants to turn Bluetooth OFF for this device.</string>
<string name="bluetooth_ask_disablement_no_name">An app wants to turn off Bluetooth</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode -->
<string name="bluetooth_ask_discovery" product="tablet">An app wants to make your tablet visible to other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode -->
<string name="bluetooth_ask_discovery" product="default">An app wants to make your phone visible to other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_discovery" product="tablet"><xliff:g id="app_name">%1$s</xliff:g> wants to make your tablet visible to other Bluetooth devices for <xliff:g id="timeout">%2$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_discovery" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to make your phone visible to other Bluetooth devices for <xliff:g id="timeout">%2$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode -->
<string name="bluetooth_ask_lasting_discovery" product="tablet">An app wants to make your tablet visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<string name="bluetooth_ask_lasting_discovery" product="default">An app wants to make your phone visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_discovery_no_name" product="tablet">An app wants to make your tablet visible to other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_discovery_no_name" product="default">An app wants to make your phone visible to other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to start broadcasting -->
<string name="bluetooth_ask_start_broadcast" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth broadcasting to communicate with other devices nearby. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and start broadcasting -->
<string name="bluetooth_ask_enablement_and_start_broadcast" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth and Bluetooth broadcasting to communicate with other devices nearby. You can change this later in Bluetooth settings.</string>
<!-- Strings for bluetooth broadcasting explanation -->
<string name="bluetooth_broadcasting_explaination" product="default">When this feature is turned on, your phone can communicate with other devices nearby.\n\nBroadcasting uses low-power Bluetooth signals.</string>
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_lasting_discovery" product="tablet"><xliff:g id="app_name">%1$s</xliff:g> wants to make your tablet visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_lasting_discovery" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to make your phone visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
<string name="bluetooth_ask_enablement_and_discovery" product="tablet">An app wants to turn on Bluetooth and make your tablet visible to other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
<string name="bluetooth_ask_enablement_and_discovery" product="default">An app wants to turn on Bluetooth and make your phone visible to other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_lasting_discovery_no_name" product="tablet">An app wants to make your tablet visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_lasting_discovery_no_name" product="default">An app wants to make your phone visible to other Bluetooth devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="tablet">An app wants to turn on Bluetooth and make your tablet visible to other devices. You can change this later in Bluetooth settings.</string>
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="default">An app wants to turn on Bluetooth and make your phone visible to other devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_discovery" product="tablet"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth and make your tablet visible to other devices for <xliff:g id="timeout">%2$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_discovery" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth and make your phone visible to other devices for <xliff:g id="timeout">%2$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_discovery_no_name" product="tablet">An app wants to turn on Bluetooth and make your tablet visible to other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_discovery_no_name" product="default">An app wants to turn on Bluetooth and make your phone visible to other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="tablet"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth and make your tablet visible to other devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="default"><xliff:g id="app_name">%1$s</xliff:g> wants to turn on Bluetooth and make your phone visible to other devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_lasting_discovery_no_name" product="tablet">An app wants to turn on Bluetooth and make your tablet visible to other devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode. [CHAR LIMIT=NONE] -->
<string name="bluetooth_ask_enablement_and_lasting_discovery_no_name" product="default">An app wants to turn on Bluetooth and make your phone visible to other devices. You can change this later in Bluetooth settings.</string>
<!-- Strings for msg to display to user while bluetooth is turning on [CHAR LIMIT=60] -->
<string name="bluetooth_turning_on">"Turning Bluetooth on\u2026"</string>
@@ -1492,9 +1508,9 @@
<string name="link_speed">%1$d Mbps</string>
<!-- This string asks the user whether or not to allow an app to enable WiFi. [CHAR LIMIT=NONE] -->
<string name="wifi_ask_enable"><xliff:g id="requester" example="FancyApp">%s</xliff:g> wants to turn WiFi ON for this device.</string>
<string name="wifi_ask_enable"><xliff:g id="requester" example="FancyApp">%s</xliff:g> wants to turn on Wi-Fi</string>
<!-- This string asks the user whether or not to allow an app to disable WiFi. [CHAR LIMIT=NONE] -->
<string name="wifi_ask_disable"><xliff:g id="requester" example="FancyApp">%s</xliff:g> wants to turn WiFi OFF for this device.</string>
<string name="wifi_ask_disable"><xliff:g id="requester" example="FancyApp">%s</xliff:g> wants to turn off Wi-Fi</string>
<!-- NFC settings -->
<!-- Used in the 1st-level settings screen to turn on NFC -->

View File

@@ -16,7 +16,9 @@
package com.android.settings.bluetooth;
import android.annotation.NonNull;
import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -25,7 +27,10 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.android.settings.R;
@@ -62,6 +67,8 @@ public class RequestPermissionActivity extends Activity implements
private BroadcastReceiver mReceiver;
private @NonNull CharSequence mAppLabel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -86,8 +93,10 @@ public class RequestPermissionActivity extends Activity implements
case BluetoothAdapter.STATE_ON:
case BluetoothAdapter.STATE_TURNING_ON: {
Intent intent = new Intent(this, RequestPermissionHelperActivity.class);
intent.putExtra(RequestPermissionHelperActivity.EXTRA_APP_LABEL, mAppLabel);
intent.setAction(RequestPermissionHelperActivity
.ACTION_INTERNAL_REQUEST_BT_OFF);
startActivityForResult(intent, 0);
} break;
@@ -116,6 +125,7 @@ public class RequestPermissionActivity extends Activity implements
*/
Intent intent = new Intent(this, RequestPermissionHelperActivity.class);
intent.setAction(RequestPermissionHelperActivity.ACTION_INTERNAL_REQUEST_BT_ON);
intent.putExtra(RequestPermissionHelperActivity.EXTRA_APP_LABEL, mAppLabel);
if (mRequest == REQUEST_ENABLE_DISCOVERABLE) {
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, mTimeout);
}
@@ -165,9 +175,15 @@ public class RequestPermissionActivity extends Activity implements
// Ask the user whether to turn on discovery mode or not
// For lasting discoverable mode there is a different message
if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
builder.setMessage(getString(R.string.bluetooth_ask_lasting_discovery));
CharSequence message = mAppLabel != null
? getString(R.string.bluetooth_ask_lasting_discovery, mAppLabel)
: getString(R.string.bluetooth_ask_lasting_discovery_no_name);
builder.setMessage(message);
} else {
builder.setMessage(getString(R.string.bluetooth_ask_discovery, mTimeout));
CharSequence message = mAppLabel != null
? getString(R.string.bluetooth_ask_discovery, mAppLabel)
: getString(R.string.bluetooth_ask_discovery_no_name);
builder.setMessage(message);
}
builder.setPositiveButton(getString(R.string.allow), this);
builder.setNegativeButton(getString(R.string.deny), this);
@@ -303,6 +319,23 @@ public class RequestPermissionActivity extends Activity implements
setResult(RESULT_CANCELED);
return true;
}
String packageName = getCallingPackage();
if (TextUtils.isEmpty(packageName)) {
packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
}
if (!TextUtils.isEmpty(packageName)) {
try {
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
packageName, 0);
mAppLabel = applicationInfo.loadSafeLabel(getPackageManager());
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Couldn't find app with package name " + packageName);
setResult(RESULT_CANCELED);
return true;
}
}
mLocalAdapter = manager.getBluetoothAdapter();
return false;

View File

@@ -20,12 +20,17 @@ import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CharSequences;
import com.android.settings.R;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -45,8 +50,13 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
public static final String ACTION_INTERNAL_REQUEST_BT_OFF =
"com.android.settings.bluetooth.ACTION_INTERNAL_REQUEST_BT_OFF";
public static final String EXTRA_APP_LABEL =
"com.android.settings.bluetooth.extra.APP_LABEL";
private LocalBluetoothAdapter mLocalAdapter;
private CharSequence mAppLabel;
private int mTimeout = -1;
private int mRequest;
@@ -78,18 +88,29 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
switch (mRequest) {
case RequestPermissionActivity.REQUEST_ENABLE: {
if (mTimeout < 0) {
p.mMessage = getString(R.string.bluetooth_ask_enablement);
p.mMessage = mAppLabel != null
? getString(R.string.bluetooth_ask_enablement, mAppLabel)
: getString(R.string.bluetooth_ask_enablement_no_name);
} else if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
p.mMessage = getString(
R.string.bluetooth_ask_enablement_and_lasting_discovery);
p.mMessage = mAppLabel != null
? getString(
R.string.bluetooth_ask_enablement_and_lasting_discovery,
mAppLabel)
: getString(
R.string.bluetooth_ask_enablement_and_lasting_discovery_no_name);
} else {
p.mMessage = getString(
R.string.bluetooth_ask_enablement_and_discovery, mTimeout);
p.mMessage = mAppLabel != null
? getString(R.string.bluetooth_ask_enablement_and_discovery,
mAppLabel, mTimeout)
: getString(R.string.bluetooth_ask_enablement_and_discovery_no_name,
mTimeout);
}
} break;
case RequestPermissionActivity.REQUEST_DISABLE: {
p.mMessage = getString(R.string.bluetooth_ask_disablement);
p.mMessage = mAppLabel != null
? getString(R.string.bluetooth_ask_disablement, mAppLabel)
: getString(R.string.bluetooth_ask_disablement_no_name);
} break;
}
@@ -145,6 +166,8 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
return false;
}
mAppLabel = getIntent().getCharSequenceExtra(EXTRA_APP_LABEL);
mLocalAdapter = manager.getBluetoothAdapter();
return true;