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

@@ -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;