Loading packages/SettingsLib/res/values/dimens.xml +3 −1 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ <!-- The translation for disappearing security views after having solved them. --> <dimen name="disappear_y_translation">-32dp</dimen> <dimen name="circle_avatar_size">40dp</dimen> </resources> packages/SettingsLib/res/values/strings.xml +30 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,34 @@ <!-- Content description of the WIFI signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] --> <string name="accessibility_wifi_signal_full">Wifi signal full.</string> <!-- Label for kernel threads in battery usage --> <string name="process_kernel_label">Android OS</string> <!-- Title of data usage item that represents all uninstalled applications. [CHAR LIMIT=48] --> <string name="data_usage_uninstalled_apps">Removed apps</string> <!-- Title of data usage item that represents all uninstalled applications or removed users. [CHAR LIMIT=48] --> <string name="data_usage_uninstalled_apps_users">Removed apps and users</string> <!-- Tethering controls, item title to go into the tethering settings --> <!-- Tethering controls, item title to go into the tethering settings when only USB tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_usb">USB tethering</string> <!-- Tethering controls, item title to go into the tethering settings when only Wifi tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_wifi">Portable hotspot</string> <!-- Tethering controls, item title to go into the tethering settings when only Bluetooth tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_bluetooth">Bluetooth tethering</string> <!-- Tethering controls, item title to go into the tethering settings when USB and Bluetooth tethering are available [CHAR LIMIT=25]--> <string name="tether_settings_title_usb_bluetooth">Tethering</string> <!-- Tethering controls, item title to go into the tethering settings when USB, Bluetooth and Wifi tethering are available [CHAR LIMIT=25]--> <string name="tether_settings_title_all">Tethering & portable hotspot</string> <!-- Title for a work profile. [CHAR LIMIT=25] --> <string name="managed_user_title">Work profile</string> <!-- Title for Guest user [CHAR LIMIT=35] --> <string name="user_guest">Guest</string> <!-- Manage apps, individual app screen, substituted for the application's label when the app's label CAN NOT be determined.--> <string name="unknown">Unknown</string> <!-- [CHAR LIMIT=NONE] Label of a running process that represents another user --> <string name="running_process_item_user_label">User: <xliff:g id="user_name">%1$s</xliff:g></string> </resources> packages/SettingsLib/src/com/android/settingslib/Utils.java 0 → 100644 +84 −0 Original line number Diff line number Diff line package com.android.settingslib; import android.content.Context; import android.content.pm.UserInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.os.UserManager; import com.android.internal.util.UserIcons; import com.android.settingslib.drawable.CircleFramedDrawable; public final class Utils { /** * Return string resource that best describes combination of tethering * options available on this device. */ public static int getTetheringLabel(ConnectivityManager cm) { String[] usbRegexs = cm.getTetherableUsbRegexs(); String[] wifiRegexs = cm.getTetherableWifiRegexs(); String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs(); boolean usbAvailable = usbRegexs.length != 0; boolean wifiAvailable = wifiRegexs.length != 0; boolean bluetoothAvailable = bluetoothRegexs.length != 0; if (wifiAvailable && usbAvailable && bluetoothAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable && usbAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable && bluetoothAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable) { return R.string.tether_settings_title_wifi; } else if (usbAvailable && bluetoothAvailable) { return R.string.tether_settings_title_usb_bluetooth; } else if (usbAvailable) { return R.string.tether_settings_title_usb; } else { return R.string.tether_settings_title_bluetooth; } } /** * Returns a label for the user, in the form of "User: user name" or "Work profile". */ public static String getUserLabel(Context context, UserInfo info) { String name = info != null ? info.name : null; if (info.isManagedProfile()) { // We use predefined values for managed profiles return context.getString(R.string.managed_user_title); } else if (info.isGuest()) { name = context.getString(R.string.user_guest); } if (name == null && info != null) { name = Integer.toString(info.id); } else if (info == null) { name = context.getString(R.string.unknown); } return context.getResources().getString(R.string.running_process_item_user_label, name); } /** * Returns a circular icon for a user. */ public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) { if (user.isManagedProfile()) { // We use predefined values for managed profiles Bitmap b = BitmapFactory.decodeResource(context.getResources(), com.android.internal.R.drawable.ic_corp_icon); return CircleFramedDrawable.getInstance(context, b); } if (user.iconPath != null) { Bitmap icon = um.getUserIcon(user.id); if (icon != null) { return CircleFramedDrawable.getInstance(context, icon); } } return CircleFramedDrawable.getInstance(context, UserIcons.convertToBitmap( UserIcons.getDefaultUserIcon(user.id, /* light= */ false))); } } packages/SettingsLib/src/com/android/settingslib/drawable/CircleFramedDrawable.java 0 → 100644 +136 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 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.settingslib.drawable; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import com.android.settingslib.R; /** * Converts the user avatar icon to a circularly clipped one. * TODO: Move this to an internal framework class and share with the one in Keyguard. */ public class CircleFramedDrawable extends Drawable { private final Bitmap mBitmap; private final int mSize; private final Paint mPaint; private float mScale; private Rect mSrcRect; private RectF mDstRect; public static CircleFramedDrawable getInstance(Context context, Bitmap icon) { Resources res = context.getResources(); float iconSize = res.getDimension(R.dimen.circle_avatar_size); CircleFramedDrawable instance = new CircleFramedDrawable(icon, (int) iconSize); return instance; } public CircleFramedDrawable(Bitmap icon, int size) { super(); mSize = size; mBitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(mBitmap); final int width = icon.getWidth(); final int height = icon.getHeight(); final int square = Math.min(width, height); final Rect cropRect = new Rect((width - square) / 2, (height - square) / 2, square, square); final RectF circleRect = new RectF(0f, 0f, mSize, mSize); final Path fillPath = new Path(); fillPath.addArc(circleRect, 0f, 360f); canvas.drawColor(0, PorterDuff.Mode.CLEAR); // opaque circle matte mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(Color.BLACK); mPaint.setStyle(Paint.Style.FILL); canvas.drawPath(fillPath, mPaint); // mask in the icon where the bitmap is opaque mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(icon, cropRect, circleRect, mPaint); // prepare paint for frame drawing mPaint.setXfermode(null); mScale = 1f; mSrcRect = new Rect(0, 0, mSize, mSize); mDstRect = new RectF(0, 0, mSize, mSize); } @Override public void draw(Canvas canvas) { final float inside = mScale * mSize; final float pad = (mSize - inside) / 2f; mDstRect.set(pad, pad, mSize - pad, mSize - pad); canvas.drawBitmap(mBitmap, mSrcRect, mDstRect, null); } public void setScale(float scale) { mScale = scale; } public float getScale() { return mScale; } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getIntrinsicWidth() { return mSize; } @Override public int getIntrinsicHeight() { return mSize; } } packages/SettingsLib/src/com/android/settingslib/net/UidDetail.java 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.settingslib.net; import android.graphics.drawable.Drawable; public class UidDetail { public CharSequence label; public CharSequence contentDescription; public CharSequence[] detailLabels; public CharSequence[] detailContentDescriptions; public Drawable icon; } Loading
packages/SettingsLib/res/values/dimens.xml +3 −1 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ <!-- The translation for disappearing security views after having solved them. --> <dimen name="disappear_y_translation">-32dp</dimen> <dimen name="circle_avatar_size">40dp</dimen> </resources>
packages/SettingsLib/res/values/strings.xml +30 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,34 @@ <!-- Content description of the WIFI signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] --> <string name="accessibility_wifi_signal_full">Wifi signal full.</string> <!-- Label for kernel threads in battery usage --> <string name="process_kernel_label">Android OS</string> <!-- Title of data usage item that represents all uninstalled applications. [CHAR LIMIT=48] --> <string name="data_usage_uninstalled_apps">Removed apps</string> <!-- Title of data usage item that represents all uninstalled applications or removed users. [CHAR LIMIT=48] --> <string name="data_usage_uninstalled_apps_users">Removed apps and users</string> <!-- Tethering controls, item title to go into the tethering settings --> <!-- Tethering controls, item title to go into the tethering settings when only USB tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_usb">USB tethering</string> <!-- Tethering controls, item title to go into the tethering settings when only Wifi tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_wifi">Portable hotspot</string> <!-- Tethering controls, item title to go into the tethering settings when only Bluetooth tethering is available [CHAR LIMIT=25]--> <string name="tether_settings_title_bluetooth">Bluetooth tethering</string> <!-- Tethering controls, item title to go into the tethering settings when USB and Bluetooth tethering are available [CHAR LIMIT=25]--> <string name="tether_settings_title_usb_bluetooth">Tethering</string> <!-- Tethering controls, item title to go into the tethering settings when USB, Bluetooth and Wifi tethering are available [CHAR LIMIT=25]--> <string name="tether_settings_title_all">Tethering & portable hotspot</string> <!-- Title for a work profile. [CHAR LIMIT=25] --> <string name="managed_user_title">Work profile</string> <!-- Title for Guest user [CHAR LIMIT=35] --> <string name="user_guest">Guest</string> <!-- Manage apps, individual app screen, substituted for the application's label when the app's label CAN NOT be determined.--> <string name="unknown">Unknown</string> <!-- [CHAR LIMIT=NONE] Label of a running process that represents another user --> <string name="running_process_item_user_label">User: <xliff:g id="user_name">%1$s</xliff:g></string> </resources>
packages/SettingsLib/src/com/android/settingslib/Utils.java 0 → 100644 +84 −0 Original line number Diff line number Diff line package com.android.settingslib; import android.content.Context; import android.content.pm.UserInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.os.UserManager; import com.android.internal.util.UserIcons; import com.android.settingslib.drawable.CircleFramedDrawable; public final class Utils { /** * Return string resource that best describes combination of tethering * options available on this device. */ public static int getTetheringLabel(ConnectivityManager cm) { String[] usbRegexs = cm.getTetherableUsbRegexs(); String[] wifiRegexs = cm.getTetherableWifiRegexs(); String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs(); boolean usbAvailable = usbRegexs.length != 0; boolean wifiAvailable = wifiRegexs.length != 0; boolean bluetoothAvailable = bluetoothRegexs.length != 0; if (wifiAvailable && usbAvailable && bluetoothAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable && usbAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable && bluetoothAvailable) { return R.string.tether_settings_title_all; } else if (wifiAvailable) { return R.string.tether_settings_title_wifi; } else if (usbAvailable && bluetoothAvailable) { return R.string.tether_settings_title_usb_bluetooth; } else if (usbAvailable) { return R.string.tether_settings_title_usb; } else { return R.string.tether_settings_title_bluetooth; } } /** * Returns a label for the user, in the form of "User: user name" or "Work profile". */ public static String getUserLabel(Context context, UserInfo info) { String name = info != null ? info.name : null; if (info.isManagedProfile()) { // We use predefined values for managed profiles return context.getString(R.string.managed_user_title); } else if (info.isGuest()) { name = context.getString(R.string.user_guest); } if (name == null && info != null) { name = Integer.toString(info.id); } else if (info == null) { name = context.getString(R.string.unknown); } return context.getResources().getString(R.string.running_process_item_user_label, name); } /** * Returns a circular icon for a user. */ public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) { if (user.isManagedProfile()) { // We use predefined values for managed profiles Bitmap b = BitmapFactory.decodeResource(context.getResources(), com.android.internal.R.drawable.ic_corp_icon); return CircleFramedDrawable.getInstance(context, b); } if (user.iconPath != null) { Bitmap icon = um.getUserIcon(user.id); if (icon != null) { return CircleFramedDrawable.getInstance(context, icon); } } return CircleFramedDrawable.getInstance(context, UserIcons.convertToBitmap( UserIcons.getDefaultUserIcon(user.id, /* light= */ false))); } }
packages/SettingsLib/src/com/android/settingslib/drawable/CircleFramedDrawable.java 0 → 100644 +136 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 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.settingslib.drawable; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import com.android.settingslib.R; /** * Converts the user avatar icon to a circularly clipped one. * TODO: Move this to an internal framework class and share with the one in Keyguard. */ public class CircleFramedDrawable extends Drawable { private final Bitmap mBitmap; private final int mSize; private final Paint mPaint; private float mScale; private Rect mSrcRect; private RectF mDstRect; public static CircleFramedDrawable getInstance(Context context, Bitmap icon) { Resources res = context.getResources(); float iconSize = res.getDimension(R.dimen.circle_avatar_size); CircleFramedDrawable instance = new CircleFramedDrawable(icon, (int) iconSize); return instance; } public CircleFramedDrawable(Bitmap icon, int size) { super(); mSize = size; mBitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(mBitmap); final int width = icon.getWidth(); final int height = icon.getHeight(); final int square = Math.min(width, height); final Rect cropRect = new Rect((width - square) / 2, (height - square) / 2, square, square); final RectF circleRect = new RectF(0f, 0f, mSize, mSize); final Path fillPath = new Path(); fillPath.addArc(circleRect, 0f, 360f); canvas.drawColor(0, PorterDuff.Mode.CLEAR); // opaque circle matte mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(Color.BLACK); mPaint.setStyle(Paint.Style.FILL); canvas.drawPath(fillPath, mPaint); // mask in the icon where the bitmap is opaque mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(icon, cropRect, circleRect, mPaint); // prepare paint for frame drawing mPaint.setXfermode(null); mScale = 1f; mSrcRect = new Rect(0, 0, mSize, mSize); mDstRect = new RectF(0, 0, mSize, mSize); } @Override public void draw(Canvas canvas) { final float inside = mScale * mSize; final float pad = (mSize - inside) / 2f; mDstRect.set(pad, pad, mSize - pad, mSize - pad); canvas.drawBitmap(mBitmap, mSrcRect, mDstRect, null); } public void setScale(float scale) { mScale = scale; } public float getScale() { return mScale; } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getIntrinsicWidth() { return mSize; } @Override public int getIntrinsicHeight() { return mSize; } }
packages/SettingsLib/src/com/android/settingslib/net/UidDetail.java 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.settingslib.net; import android.graphics.drawable.Drawable; public class UidDetail { public CharSequence label; public CharSequence contentDescription; public CharSequence[] detailLabels; public CharSequence[] detailContentDescriptions; public Drawable icon; }