Remove method that used to get rainbow bt icon
Move get rainbow bt icon method to settingsLib Bug: 128570540 Test: RunSettingsRoboTests Change-Id: Iee022bd1471f1da057b1852bb648e9c7ce334727
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_about_background" />
|
android:color="@color/homepage_about_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_accessibility_background" />
|
android:color="@color/homepage_accessibility_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_accounts_background" />
|
android:color="@color/homepage_accounts_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_app_and_notification_background" />
|
android:color="@color/homepage_app_and_notification_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_battery_background" />
|
android:color="@color/homepage_battery_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_connected_device_background" />
|
android:color="@color/homepage_connected_device_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_display_background" />
|
android:color="@color/homepage_display_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_location_background" />
|
android:color="@color/homepage_location_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_network_background" />
|
android:color="@color/homepage_network_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_privacy_background" />
|
android:color="@color/homepage_privacy_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_security_background" />
|
android:color="@color/homepage_security_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_sound_background" />
|
android:color="@color/homepage_sound_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_storage_background" />
|
android:color="@color/homepage_storage_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_support_background" />
|
android:color="@color/homepage_support_background" />
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<com.android.settings.homepage.AdaptiveIconShapeDrawable
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
android:width="@dimen/dashboard_tile_image_size"
|
android:width="@dimen/dashboard_tile_image_size"
|
||||||
android:height="@dimen/dashboard_tile_image_size"
|
android:height="@dimen/dashboard_tile_image_size"
|
||||||
android:color="@color/homepage_system_background" />
|
android:color="@color/homepage_system_background" />
|
||||||
|
@@ -1398,25 +1398,4 @@
|
|||||||
<item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
|
<item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- Bluetooth icon foreground colors -->
|
|
||||||
<integer-array name="bt_icon_fg_colors">
|
|
||||||
<item>@color/bt_color_icon_1</item>
|
|
||||||
<item>@color/bt_color_icon_2</item>
|
|
||||||
<item>@color/bt_color_icon_3</item>
|
|
||||||
<item>@color/bt_color_icon_4</item>
|
|
||||||
<item>@color/bt_color_icon_5</item>
|
|
||||||
<item>@color/bt_color_icon_6</item>
|
|
||||||
<item>@color/bt_color_icon_7</item>
|
|
||||||
</integer-array>
|
|
||||||
|
|
||||||
<!-- Bluetooth icon background colors -->
|
|
||||||
<integer-array name="bt_icon_bg_colors">
|
|
||||||
<item>@color/bt_color_bg_1</item>
|
|
||||||
<item>@color/bt_color_bg_2</item>
|
|
||||||
<item>@color/bt_color_bg_3</item>
|
|
||||||
<item>@color/bt_color_bg_4</item>
|
|
||||||
<item>@color/bt_color_bg_5</item>
|
|
||||||
<item>@color/bt_color_bg_6</item>
|
|
||||||
<item>@color/bt_color_bg_7</item>
|
|
||||||
</integer-array>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -141,21 +141,4 @@
|
|||||||
<color name="qr_background_color">#b3ffffff</color> <!-- 70% white transparency -->
|
<color name="qr_background_color">#b3ffffff</color> <!-- 70% white transparency -->
|
||||||
<!-- End of QR code scanner colors -->
|
<!-- End of QR code scanner colors -->
|
||||||
|
|
||||||
<color name="bt_color_icon_1">#48a50e0e</color> <!-- 72% Material Red 900 -->
|
|
||||||
<color name="bt_color_icon_2">#480d652d</color> <!-- 72% Material Green 900 -->
|
|
||||||
<color name="bt_color_icon_3">#48e37400</color> <!-- 72% Material Yellow 900 -->
|
|
||||||
<color name="bt_color_icon_4">#48b06000</color> <!-- 72% Material Orange 900 -->
|
|
||||||
<color name="bt_color_icon_5">#489c166b</color> <!-- 72% Material Pink 900 -->
|
|
||||||
<color name="bt_color_icon_6">#48681da8</color> <!-- 72% Material Purple 900 -->
|
|
||||||
<color name="bt_color_icon_7">#48007b83</color> <!-- 72% Material Cyan 900 -->
|
|
||||||
|
|
||||||
<color name="bt_color_bg_1">#fad2cf</color> <!-- Material Red 100 -->
|
|
||||||
<color name="bt_color_bg_2">#ceead6</color> <!-- Material Green 100 -->
|
|
||||||
<color name="bt_color_bg_3">#feefc3</color> <!-- Material Yellow 100 -->
|
|
||||||
<color name="bt_color_bg_4">#fedfc8</color> <!-- Material Orange 100 -->
|
|
||||||
<color name="bt_color_bg_5">#fdcfe8</color> <!-- Material Pink 100 -->
|
|
||||||
<color name="bt_color_bg_6">#e9d2fd</color> <!-- Material Purple 100 -->
|
|
||||||
<color name="bt_color_bg_7">#cbf0f8</color> <!-- Material Cyan 100 -->
|
|
||||||
|
|
||||||
<color name="bt_outline_color">#1f000000</color> <!-- icon outline color -->
|
|
||||||
</resources>
|
</resources>
|
@@ -405,12 +405,6 @@
|
|||||||
<!-- Wi-Fi DPP fragment icon size -->
|
<!-- Wi-Fi DPP fragment icon size -->
|
||||||
<dimen name="wifi_dpp_fragment_icon_width_height">48dp</dimen>
|
<dimen name="wifi_dpp_fragment_icon_width_height">48dp</dimen>
|
||||||
|
|
||||||
<!-- Size of nearby icon -->
|
|
||||||
<dimen name="bt_nearby_icon_size">24dp</dimen>
|
|
||||||
|
|
||||||
<!-- Stroke size of adaptive outline -->
|
|
||||||
<dimen name="adaptive_outline_stroke">1dp</dimen>
|
|
||||||
|
|
||||||
<!-- Elevation of bluetooth icon -->
|
<!-- Elevation of bluetooth icon -->
|
||||||
<dimen name="bt_icon_elevation">4dp</dimen>
|
<dimen name="bt_icon_elevation">4dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -26,6 +26,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
import com.android.settings.widget.EntityHeaderController;
|
||||||
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
@@ -65,8 +66,8 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setHeaderProperties() {
|
protected void setHeaderProperties() {
|
||||||
final Pair<Drawable, String> pair = Utils.getBtRainbowDrawableWithDescription(mContext,
|
final Pair<Drawable, String> pair =
|
||||||
mCachedDevice);
|
BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, mCachedDevice);
|
||||||
String summaryText = mCachedDevice.getConnectionSummary();
|
String summaryText = mCachedDevice.getConnectionSummary();
|
||||||
// If both the hearing aids are connected, two device status should be shown.
|
// If both the hearing aids are connected, two device status should be shown.
|
||||||
// If Second Summary is unavailable, to set it to null.
|
// If Second Summary is unavailable, to set it to null.
|
||||||
|
@@ -38,6 +38,7 @@ import androidx.preference.PreferenceViewHolder;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.GearPreference;
|
import com.android.settings.widget.GearPreference;
|
||||||
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
@@ -129,8 +130,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
|||||||
// Null check is done at the framework
|
// Null check is done at the framework
|
||||||
setSummary(mCachedDevice.getConnectionSummary());
|
setSummary(mCachedDevice.getConnectionSummary());
|
||||||
|
|
||||||
final Pair<Drawable, String> pair = Utils
|
final Pair<Drawable, String> pair =
|
||||||
.getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
|
BluetoothUtils.getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
|
||||||
if (pair.first != null) {
|
if (pair.first != null) {
|
||||||
setIcon(pair.first);
|
setIcon(pair.first);
|
||||||
contentDescription = pair.second;
|
contentDescription = pair.second;
|
||||||
|
@@ -21,33 +21,20 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.AdaptiveIcon;
|
|
||||||
import com.android.settings.widget.AdaptiveOutlineDrawable;
|
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utils is a helper class that contains constants for various
|
* Utils is a helper class that contains constants for various
|
||||||
* Android resource IDs, debug logging flags, and static methods
|
* Android resource IDs, debug logging flags, and static methods
|
||||||
@@ -193,54 +180,4 @@ public final class Utils {
|
|||||||
return META_INT_ERROR;
|
return META_INT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get colorful bluetooth icon with description
|
|
||||||
*/
|
|
||||||
public static Pair<Drawable, String> getBtRainbowDrawableWithDescription(Context context,
|
|
||||||
CachedBluetoothDevice cachedDevice) {
|
|
||||||
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
|
|
||||||
context, cachedDevice);
|
|
||||||
final boolean untetheredHeadset = Utils.getBooleanMetaData(cachedDevice.getDevice(),
|
|
||||||
BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET);
|
|
||||||
final int iconSize = context.getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.bt_nearby_icon_size);
|
|
||||||
final Resources resources = context.getResources();
|
|
||||||
|
|
||||||
// Deal with untethered headset
|
|
||||||
if (untetheredHeadset) {
|
|
||||||
final String uriString = Utils.getStringMetaData(cachedDevice.getDevice(),
|
|
||||||
BluetoothDevice.METADATA_MAIN_ICON);
|
|
||||||
final Uri iconUri = uriString != null ? Uri.parse(uriString) : null;
|
|
||||||
if (iconUri != null) {
|
|
||||||
try {
|
|
||||||
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(
|
|
||||||
context.getContentResolver(), iconUri);
|
|
||||||
if (bitmap != null) {
|
|
||||||
final Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, iconSize,
|
|
||||||
iconSize, false);
|
|
||||||
bitmap.recycle();
|
|
||||||
final AdaptiveOutlineDrawable drawable = new AdaptiveOutlineDrawable(
|
|
||||||
resources, resizedBitmap);
|
|
||||||
return new Pair<>(drawable, pair.second);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Failed to get drawable for: " + iconUri, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deal with normal headset
|
|
||||||
final int[] iconFgColors = resources.getIntArray(R.array.bt_icon_fg_colors);
|
|
||||||
final int[] iconBgColors = resources.getIntArray(R.array.bt_icon_bg_colors);
|
|
||||||
|
|
||||||
// get color index based on mac address
|
|
||||||
final int index = Math.abs(cachedDevice.getAddress().hashCode()) % iconBgColors.length;
|
|
||||||
pair.first.setColorFilter(iconFgColors[index], PorterDuff.Mode.SRC_ATOP);
|
|
||||||
final Drawable adaptiveIcon = new AdaptiveIcon(context, pair.first);
|
|
||||||
((AdaptiveIcon) adaptiveIcon).setBackgroundColor(iconBgColors[index]);
|
|
||||||
|
|
||||||
return new Pair<>(adaptiveIcon, pair.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -46,12 +46,12 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.AdaptiveIcon;
|
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.drawer.TileUtils;
|
import com.android.settingslib.drawer.TileUtils;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
import com.android.settingslib.widget.AdaptiveIcon;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
package com.android.settings.homepage;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.content.res.Resources.Theme;
|
|
||||||
import android.graphics.Path;
|
|
||||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
|
||||||
import android.graphics.drawable.ShapeDrawable;
|
|
||||||
import android.graphics.drawable.shapes.PathShape;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.PathParser;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws a filled {@link ShapeDrawable} using the path from {@link AdaptiveIconDrawable}.
|
|
||||||
*/
|
|
||||||
public class AdaptiveIconShapeDrawable extends ShapeDrawable {
|
|
||||||
public AdaptiveIconShapeDrawable() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdaptiveIconShapeDrawable(Resources resources) {
|
|
||||||
super();
|
|
||||||
init(resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
|
||||||
throws XmlPullParserException, IOException {
|
|
||||||
super.inflate(r, parser, attrs, theme);
|
|
||||||
init(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(Resources resources) {
|
|
||||||
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
|
|
||||||
final Path path = new Path(PathParser.createPathFromPathData(
|
|
||||||
resources.getString(com.android.internal.R.string.config_icon_mask)));
|
|
||||||
setShape(new PathShape(path, pathSize, pathSize));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -46,6 +46,7 @@ import com.android.settings.slices.CustomSliceRegistry;
|
|||||||
import com.android.settings.slices.CustomSliceable;
|
import com.android.settings.slices.CustomSliceable;
|
||||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||||
import com.android.settings.slices.SliceBuilderUtils;
|
import com.android.settings.slices.SliceBuilderUtils;
|
||||||
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
|
||||||
@@ -211,8 +212,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
|
IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
|
||||||
final Pair<Drawable, String> pair =
|
final Pair<Drawable, String> pair =
|
||||||
com.android.settings.bluetooth.Utils.getBtRainbowDrawableWithDescription(mContext,
|
BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, device);
|
||||||
device);
|
|
||||||
final Drawable drawable = pair.first;
|
final Drawable drawable = pair.first;
|
||||||
|
|
||||||
// Use default bluetooth icon if can't get icon.
|
// Use default bluetooth icon if can't get icon.
|
||||||
|
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 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.widget;
|
|
||||||
|
|
||||||
import static androidx.annotation.VisibleForTesting.NONE;
|
|
||||||
|
|
||||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB;
|
|
||||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.graphics.drawable.LayerDrawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
public class AdaptiveIcon extends LayerDrawable {
|
|
||||||
|
|
||||||
private static final String TAG = "AdaptiveHomepageIcon";
|
|
||||||
|
|
||||||
@VisibleForTesting(otherwise = NONE)
|
|
||||||
int mBackgroundColor = -1;
|
|
||||||
private AdaptiveConstantState mAdaptiveConstantState;
|
|
||||||
|
|
||||||
public AdaptiveIcon(Context context, Drawable foreground) {
|
|
||||||
super(new Drawable[]{
|
|
||||||
new AdaptiveIconShapeDrawable(context.getResources()),
|
|
||||||
foreground
|
|
||||||
});
|
|
||||||
final int insetPx = context.getResources()
|
|
||||||
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
|
|
||||||
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
|
|
||||||
mAdaptiveConstantState = new AdaptiveConstantState(context, foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackgroundColor(Context context, Tile tile) {
|
|
||||||
final Bundle metaData = tile.getMetaData();
|
|
||||||
try {
|
|
||||||
if (metaData != null) {
|
|
||||||
// Load from bg.argb first
|
|
||||||
int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
|
|
||||||
0 /* default */);
|
|
||||||
// Not found, load from bg.hint
|
|
||||||
if (bgColor == 0) {
|
|
||||||
final int colorRes = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
|
||||||
0 /* default */);
|
|
||||||
if (colorRes != 0) {
|
|
||||||
bgColor = context.getPackageManager()
|
|
||||||
.getResourcesForApplication(tile.getPackageName())
|
|
||||||
.getColor(colorRes, null /* theme */);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If found anything, use it.
|
|
||||||
if (bgColor != 0) {
|
|
||||||
setBackgroundColor(bgColor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
Log.e(TAG, "Failed to set background color for " + tile.getPackageName());
|
|
||||||
}
|
|
||||||
setBackgroundColor(context.getColor(R.color.homepage_generic_icon_background));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackgroundColor(int color) {
|
|
||||||
mBackgroundColor = color;
|
|
||||||
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
|
||||||
Log.d(TAG, "Setting background color " + mBackgroundColor);
|
|
||||||
mAdaptiveConstantState.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConstantState getConstantState() {
|
|
||||||
return mAdaptiveConstantState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static class AdaptiveConstantState extends ConstantState {
|
|
||||||
Context context;
|
|
||||||
Drawable drawable;
|
|
||||||
int color;
|
|
||||||
|
|
||||||
public AdaptiveConstantState(Context context, Drawable drawable) {
|
|
||||||
this.context = context;
|
|
||||||
this.drawable = drawable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Drawable newDrawable() {
|
|
||||||
final AdaptiveIcon icon = new AdaptiveIcon(context, drawable);
|
|
||||||
icon.setBackgroundColor(color);
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getChangingConfigurations() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.widget;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Path;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
|
||||||
import android.graphics.drawable.DrawableWrapper;
|
|
||||||
import android.util.PathParser;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adaptive outline drawable with white plain background color and black outline
|
|
||||||
*/
|
|
||||||
public class AdaptiveOutlineDrawable extends DrawableWrapper {
|
|
||||||
@VisibleForTesting
|
|
||||||
final Paint mOutlinePaint;
|
|
||||||
private Path mPath;
|
|
||||||
private final int mInsetPx;
|
|
||||||
private final Bitmap mBitmap;
|
|
||||||
|
|
||||||
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) {
|
|
||||||
super(new AdaptiveIconShapeDrawable(resources));
|
|
||||||
|
|
||||||
getDrawable().setTint(Color.WHITE);
|
|
||||||
mPath = new Path(PathParser.createPathFromPathData(
|
|
||||||
resources.getString(com.android.internal.R.string.config_icon_mask)));
|
|
||||||
mOutlinePaint = new Paint();
|
|
||||||
mOutlinePaint.setColor(resources.getColor(R.color.bt_outline_color, null));
|
|
||||||
mOutlinePaint.setStyle(Paint.Style.STROKE);
|
|
||||||
mOutlinePaint.setStrokeWidth(resources.getDimension(R.dimen.adaptive_outline_stroke));
|
|
||||||
mOutlinePaint.setAntiAlias(true);
|
|
||||||
|
|
||||||
mInsetPx = resources
|
|
||||||
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
|
|
||||||
mBitmap = bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Canvas canvas) {
|
|
||||||
super.draw(canvas);
|
|
||||||
final Rect bounds = getBounds();
|
|
||||||
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
|
|
||||||
|
|
||||||
final float scaleX = (bounds.right - bounds.left) / pathSize;
|
|
||||||
final float scaleY = (bounds.bottom - bounds.top) / pathSize;
|
|
||||||
|
|
||||||
final int count = canvas.save();
|
|
||||||
canvas.scale(scaleX, scaleY);
|
|
||||||
// Draw outline
|
|
||||||
canvas.drawPath(mPath, mOutlinePaint);
|
|
||||||
canvas.restoreToCount(count);
|
|
||||||
|
|
||||||
// Draw the foreground icon
|
|
||||||
canvas.drawBitmap(mBitmap, bounds.left + mInsetPx, bounds.top + mInsetPx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getIntrinsicHeight() {
|
|
||||||
return mBitmap.getHeight() + 2 * mInsetPx;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getIntrinsicWidth() {
|
|
||||||
return mBitmap.getWidth() + 2 * mInsetPx;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -29,8 +29,6 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.widget.AdaptiveIcon;
|
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
@@ -41,7 +39,6 @@ import org.mockito.Answers;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class UtilsTest {
|
public class UtilsTest {
|
||||||
@@ -54,8 +51,6 @@ public class UtilsTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private BluetoothDevice mBluetoothDevice;
|
private BluetoothDevice mBluetoothDevice;
|
||||||
@Mock
|
|
||||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
|
||||||
|
|
||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
@@ -111,17 +106,4 @@ public class UtilsTest {
|
|||||||
assertThat(Utils.getBooleanMetaData(mBluetoothDevice,
|
assertThat(Utils.getBooleanMetaData(mBluetoothDevice,
|
||||||
BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET)).isEqualTo(true);
|
BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET)).isEqualTo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getBtRainbowDrawableWithDescription_normalHeadset_returnAdaptiveIcon() {
|
|
||||||
when(mBluetoothDevice.getMetadata(
|
|
||||||
BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET)).thenReturn("false");
|
|
||||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
|
||||||
when(mCachedBluetoothDevice.getAddress()).thenReturn("1f:aa:bb");
|
|
||||||
|
|
||||||
assertThat(Utils.getBtRainbowDrawableWithDescription(RuntimeEnvironment.application,
|
|
||||||
mCachedBluetoothDevice).first).isInstanceOf(
|
|
||||||
AdaptiveIcon.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 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.widget;
|
|
||||||
|
|
||||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB;
|
|
||||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.graphics.drawable.Icon;
|
|
||||||
import android.graphics.drawable.ShapeDrawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
|
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class AdaptiveIconTest {
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private ActivityInfo mActivityInfo;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mActivityInfo = new ActivityInfo();
|
|
||||||
mActivityInfo.packageName = mContext.getPackageName();
|
|
||||||
mActivityInfo.name = "class";
|
|
||||||
mActivityInfo.metaData = new Bundle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createIcon_shouldSetBackgroundAndInset() {
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
|
|
||||||
|
|
||||||
assertThat(icon.getNumberOfLayers()).isEqualTo(2);
|
|
||||||
assertThat(icon.getDrawable(0)).isInstanceOf(AdaptiveIconShapeDrawable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setBackgroundColor_shouldUpdateColorFilter() {
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
spy(new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK)));
|
|
||||||
final ShapeDrawable background = mock(ShapeDrawable.class);
|
|
||||||
when(icon.getDrawable(0)).thenReturn(background);
|
|
||||||
|
|
||||||
icon.setBackgroundColor(Color.BLUE);
|
|
||||||
|
|
||||||
verify(background).setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setBackgroundColor_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
|
|
||||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
|
||||||
mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB, 0xff0000);
|
|
||||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
|
|
||||||
.when(tile).getIcon(mContext);
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
|
|
||||||
|
|
||||||
icon.setBackgroundColor(mContext, tile);
|
|
||||||
assertThat(icon.mBackgroundColor).isEqualTo(0xff0000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setBackgroundColor_tileWithoutBackgroundColor_shouldSetDefaultBackgroundColor() {
|
|
||||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
|
||||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
|
|
||||||
.when(tile).getIcon(mContext);
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
|
|
||||||
|
|
||||||
icon.setBackgroundColor(mContext, tile);
|
|
||||||
|
|
||||||
assertThat(icon.mBackgroundColor).isEqualTo(
|
|
||||||
mContext.getColor(R.color.homepage_generic_icon_background));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
|
|
||||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
|
||||||
mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
|
||||||
R.color.material_blue_500);
|
|
||||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
|
|
||||||
.when(tile).getIcon(mContext);
|
|
||||||
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
|
|
||||||
icon.setBackgroundColor(mContext, tile);
|
|
||||||
|
|
||||||
assertThat(icon.mBackgroundColor)
|
|
||||||
.isEqualTo(mContext.getColor(R.color.material_blue_500));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getConstantState_returnCorrectState() {
|
|
||||||
final AdaptiveIcon icon =
|
|
||||||
new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
|
|
||||||
icon.setBackgroundColor(Color.YELLOW);
|
|
||||||
|
|
||||||
final AdaptiveIcon.AdaptiveConstantState state =
|
|
||||||
(AdaptiveIcon.AdaptiveConstantState) icon.getConstantState();
|
|
||||||
|
|
||||||
assertThat(state.color).isEqualTo(Color.YELLOW);
|
|
||||||
assertThat(state.context).isEqualTo(mContext);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.widget;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class AdaptiveOutlineDrawableTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void constructor_initPaint() {
|
|
||||||
final Resources resources = RuntimeEnvironment.application.getResources();
|
|
||||||
final AdaptiveOutlineDrawable drawable = new AdaptiveOutlineDrawable(resources, null);
|
|
||||||
|
|
||||||
assertThat(drawable.mOutlinePaint.getStyle()).isEqualTo(Paint.Style.STROKE);
|
|
||||||
assertThat(drawable.mOutlinePaint.getStrokeWidth()).isWithin(0.01f).of(
|
|
||||||
resources.getDimension(R.dimen.adaptive_outline_stroke));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user