diff options
| author | 2015-08-31 21:53:46 +0000 | |
|---|---|---|
| committer | 2015-08-31 21:53:46 +0000 | |
| commit | 199c74eab1a30bff7db7bb4d24c161f36edb7f5b (patch) | |
| tree | 7b372c8e1a29cbb356ac5902e224bfe52ba9d49b | |
| parent | 82b70db7dd906013d131737a5bec2ae59b41ae61 (diff) | |
| parent | 78056370fa69d10fad80a1ef1023c58dda9ad35d (diff) | |
Merge "DO NOT MERGE. Truncate and ellipsize app name if too long for dialog." into lmp-mr1-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java index c23f45dbdaba..9921bda86b40 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java @@ -24,6 +24,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.graphics.Typeface; import android.media.projection.MediaProjectionManager; import android.media.projection.IMediaProjectionManager; import android.media.projection.IMediaProjection; @@ -31,9 +32,17 @@ import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; +import android.text.BidiFormatter; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.TextPaint; +import android.text.TextUtils; +import android.text.style.StyleSpan; import android.util.Log; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.WindowManager; +import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.TextView; @@ -47,6 +56,8 @@ public class MediaProjectionPermissionActivity extends Activity implements DialogInterface.OnClickListener, CheckBox.OnCheckedChangeListener, DialogInterface.OnCancelListener { private static final String TAG = "MediaProjectionPermissionActivity"; + private static final float MAX_APP_NAME_SIZE_PX = 500f; + private static final String ELLIPSIS = "\u2026"; private boolean mPermanentGrant; private String mPackageName; @@ -92,11 +103,49 @@ public class MediaProjectionPermissionActivity extends Activity return; } - String appName = aInfo.loadLabel(packageManager).toString(); + TextPaint paint = new TextPaint(); + paint.setTextSize(42); + + String label = aInfo.loadLabel(packageManager).toString(); + + // If the label contains new line characters it may push the security + // message below the fold of the dialog. Labels shouldn't have new line + // characters anyways, so just truncate the message the first time one + // is seen. + final int labelLength = label.length(); + int offset = 0; + while (offset < labelLength) { + final int codePoint = label.codePointAt(offset); + final int type = Character.getType(codePoint); + if (type == Character.LINE_SEPARATOR + || type == Character.CONTROL + || type == Character.PARAGRAPH_SEPARATOR) { + label = label.substring(0, offset) + ELLIPSIS; + break; + } + offset += Character.charCount(codePoint); + } + + if (label.isEmpty()) { + label = mPackageName; + } + + String unsanitizedAppName = TextUtils.ellipsize(label, + paint, MAX_APP_NAME_SIZE_PX, TextUtils.TruncateAt.END).toString(); + String appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName); + + String actionText = getString(R.string.media_projection_dialog_text, appName); + SpannableString message = new SpannableString(actionText); + + int appNameIndex = actionText.indexOf(appName); + if (appNameIndex >= 0) { + message.setSpan(new StyleSpan(Typeface.BOLD), + appNameIndex, appNameIndex + appName.length(), 0); + } mDialog = new AlertDialog.Builder(this) .setIcon(aInfo.loadIcon(packageManager)) - .setMessage(getString(R.string.media_projection_dialog_text, appName)) + .setMessage(message) .setPositiveButton(R.string.media_projection_action_text, this) .setNegativeButton(android.R.string.cancel, this) .setView(R.layout.remember_permission_checkbox) @@ -105,6 +154,9 @@ public class MediaProjectionPermissionActivity extends Activity mDialog.create(); + Button btn = mDialog.getButton(DialogInterface.BUTTON_POSITIVE); + btn.getRootView().setFilterTouchesWhenObscured(true); + ((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this); mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |