diff options
author | Ajay Nadathur <ajayns@google.com> | 2018-02-13 15:02:56 -0800 |
---|---|---|
committer | Ajay Nadathur <ajayns@google.com> | 2018-02-13 16:32:26 -0800 |
commit | 9f0065b61120ff3814a28395b57f79d499079bb4 (patch) | |
tree | 890d88f83c88c5749dce96f99e85b3f8c49d8090 | |
parent | c9c5c4431a920e8a22d96bf3721e2c5377c9b57b (diff) | |
download | setupwizard-9f0065b61120ff3814a28395b57f79d499079bb4.tar.gz |
Add method to retrieve color from partner apk
bug: 73077257
Test: Manually tested and verified
Change-Id: Ia90998780913966d3953011591d9f46e088ef963
-rw-r--r-- | library/main/src/com/android/setupwizardlib/util/Partner.java | 10 | ||||
-rw-r--r-- | library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/library/main/src/com/android/setupwizardlib/util/Partner.java b/library/main/src/com/android/setupwizardlib/util/Partner.java index 67f5546..3a603ee 100644 --- a/library/main/src/com/android/setupwizardlib/util/Partner.java +++ b/library/main/src/com/android/setupwizardlib/util/Partner.java @@ -27,6 +27,7 @@ import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.AnyRes; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.annotation.VisibleForTesting; @@ -76,6 +77,15 @@ public class Partner { } /** + * Convenience method to get color from partner overlay, or if not available, the color from + * the original context. + */ + public static int getColor(Context context, @ColorRes int id) { + final ResourceEntry resourceEntry = getResourceEntry(context, id); + return resourceEntry.resources.getColor(resourceEntry.id); + } + + /** * Convenience method to get a CharSequence from partner overlay, or if not available, the text * from the original context. */ diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java index 683e40b..f8e71be 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java @@ -132,6 +132,20 @@ public class PartnerTest { } @Test + public void getColor_shouldReturnPartnerValueIfPresent() { + final int expectedPartnerColor = 1111; + doReturn(12345).when(mPartnerResources) + .getIdentifier(eq("suw_color_accent_dark"), eq("color"), anyString()); + doReturn(expectedPartnerColor).when(mPartnerResources).getColor(eq(12345)); + mPackageManager.addResolveInfoForIntent( + new Intent(ACTION_PARTNER_CUSTOMIZATION), + Arrays.asList(createResolveInfo("test.partner.package", true, true))); + final int foundColor = Partner.getColor(mContext, R.color.suw_color_accent_dark); + assertEquals("Partner color should be overlayed to: " + expectedPartnerColor, + expectedPartnerColor, foundColor); + } + + @Test public void testLoadDefaultValue() { mPackageManager.addResolveInfoForIntent( new Intent(ACTION_PARTNER_CUSTOMIZATION), |