summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-02-14 02:05:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-02-14 02:05:29 +0000
commit67c5421074b7395bc9f6a69412f0c61404b2f457 (patch)
tree0de8f926fcaba3f5652fcec8f145ce2d04b7cb98
parent267a0cc22a71b37b71b3e79da2ccaace5a185123 (diff)
parent9f0065b61120ff3814a28395b57f79d499079bb4 (diff)
downloadsetupwizard-67c5421074b7395bc9f6a69412f0c61404b2f457.tar.gz
Merge "Add method to retrieve color from partner apk"
-rw-r--r--library/main/src/com/android/setupwizardlib/util/Partner.java10
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java14
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),