Merge "Fixes a broken test."
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 066dab9..f3050c4 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -1661,7 +1661,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_accessibility.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1677,7 +1677,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_accounts.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1693,7 +1693,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_apps.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1709,7 +1709,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_battery.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1725,7 +1725,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_connected_device.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1741,7 +1741,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_display.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1753,11 +1753,27 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/homepage_generic_icon_background" />"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/ic_homepage_generic_background.xml"
+ line="20"
+ column="9"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" android:color="@color/homepage_network_background" />"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_network.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1773,7 +1789,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_security.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1789,7 +1805,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_sound.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1805,7 +1821,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_storage.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1821,7 +1837,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_support.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -1837,7 +1853,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_homepage_system_dashboard.xml"
- line="24"
+ line="23"
column="17"/>
</issue>
@@ -2557,7 +2573,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/strings.xml"
- line="5637"
+ line="5651"
column="36"/>
</issue>
@@ -2589,7 +2605,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="437"
+ line="442"
column="44"/>
</issue>
@@ -2605,7 +2621,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="443"
+ line="448"
column="44"/>
</issue>
@@ -2621,7 +2637,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="444"
+ line="449"
column="44"/>
</issue>
@@ -2637,7 +2653,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
- line="467"
+ line="472"
column="41"/>
</issue>
diff --git a/res/drawable/ic_homepage_accessibility.xml b/res/drawable/ic_homepage_accessibility.xml
index 6cfb124..07c9ef2 100644
--- a/res/drawable/ic_homepage_accessibility.xml
+++ b/res/drawable/ic_homepage_accessibility.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_accessibility_background" />
<size
diff --git a/res/drawable/ic_homepage_accounts.xml b/res/drawable/ic_homepage_accounts.xml
index 4cfccc2..ee33505 100644
--- a/res/drawable/ic_homepage_accounts.xml
+++ b/res/drawable/ic_homepage_accounts.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_accounts_background" />
<size
diff --git a/res/drawable/ic_homepage_apps.xml b/res/drawable/ic_homepage_apps.xml
index d494799..3d18d09 100644
--- a/res/drawable/ic_homepage_apps.xml
+++ b/res/drawable/ic_homepage_apps.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_app_and_notification_background" />
<size
diff --git a/res/drawable/ic_homepage_battery.xml b/res/drawable/ic_homepage_battery.xml
index d9ad3d3..abafdcb 100644
--- a/res/drawable/ic_homepage_battery.xml
+++ b/res/drawable/ic_homepage_battery.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_battery_background" />
<size
diff --git a/res/drawable/ic_homepage_connected_device.xml b/res/drawable/ic_homepage_connected_device.xml
index 20707fb..483427c 100644
--- a/res/drawable/ic_homepage_connected_device.xml
+++ b/res/drawable/ic_homepage_connected_device.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_connected_device_background" />
<size
diff --git a/res/drawable/ic_homepage_display.xml b/res/drawable/ic_homepage_display.xml
index ec5e54f..893a583 100644
--- a/res/drawable/ic_homepage_display.xml
+++ b/res/drawable/ic_homepage_display.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_display_background" />
<size
diff --git a/res/drawable/ic_homepage_generic_background.xml b/res/drawable/ic_homepage_generic_background.xml
new file mode 100644
index 0000000..37273a0
--- /dev/null
+++ b/res/drawable/ic_homepage_generic_background.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid
+ android:color="@color/homepage_generic_icon_background" />
+ <size
+ android:width="@dimen/dashboard_tile_image_size"
+ android:height="@dimen/dashboard_tile_image_size" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_homepage_network.xml b/res/drawable/ic_homepage_network.xml
index c72e152..5ed023a 100644
--- a/res/drawable/ic_homepage_network.xml
+++ b/res/drawable/ic_homepage_network.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_network_background" />
<size
diff --git a/res/drawable/ic_homepage_security.xml b/res/drawable/ic_homepage_security.xml
index 52dedfb..5a6ed97 100644
--- a/res/drawable/ic_homepage_security.xml
+++ b/res/drawable/ic_homepage_security.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_security_background" />
<size
diff --git a/res/drawable/ic_homepage_sound.xml b/res/drawable/ic_homepage_sound.xml
index 7210889..4991656 100644
--- a/res/drawable/ic_homepage_sound.xml
+++ b/res/drawable/ic_homepage_sound.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_sound_background" />
<size
diff --git a/res/drawable/ic_homepage_storage.xml b/res/drawable/ic_homepage_storage.xml
index e7f5819..4922844 100644
--- a/res/drawable/ic_homepage_storage.xml
+++ b/res/drawable/ic_homepage_storage.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_storage_background" />
<size
diff --git a/res/drawable/ic_homepage_support.xml b/res/drawable/ic_homepage_support.xml
index 31d51bf..0936304 100644
--- a/res/drawable/ic_homepage_support.xml
+++ b/res/drawable/ic_homepage_support.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_support_background" />
<size
diff --git a/res/drawable/ic_homepage_system_dashboard.xml b/res/drawable/ic_homepage_system_dashboard.xml
index bf3d0eb..60f0476 100644
--- a/res/drawable/ic_homepage_system_dashboard.xml
+++ b/res/drawable/ic_homepage_system_dashboard.xml
@@ -18,8 +18,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
+ <shape android:shape="oval">
<solid
android:color="@color/homepage_system_background" />
<size
diff --git a/src/com/android/settings/dashboard/DashboardAdapterV2.java b/src/com/android/settings/dashboard/DashboardAdapterV2.java
index ad93e4c..2aacc59 100644
--- a/src/com/android/settings/dashboard/DashboardAdapterV2.java
+++ b/src/com/android/settings/dashboard/DashboardAdapterV2.java
@@ -17,7 +17,6 @@
import android.app.Activity;
import android.content.Context;
-import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
@@ -95,7 +94,7 @@
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
mCache = new IconCache(context);
mSuggestionAdapter = new SuggestionAdapterV2(mContext, suggestionControllerMixin,
- savedInstanceState, this /* callback */, lifecycle);
+ savedInstanceState, this /* callback */, lifecycle);
setHasStableIds(true);
@@ -110,11 +109,11 @@
}
mDashboardData = new DashboardDataV2.Builder()
- .setConditions(conditions)
- .setSuggestions(mSuggestionAdapter.getSuggestions())
- .setCategory(category)
- .setConditionExpanded(conditionExpanded)
- .build();
+ .setConditions(conditions)
+ .setSuggestions(mSuggestionAdapter.getSuggestions())
+ .setCategory(category)
+ .setConditionExpanded(conditionExpanded)
+ .build();
}
public void setSuggestions(List<Suggestion> data) {
@@ -126,7 +125,6 @@
}
public void setCategory(DashboardCategory category) {
- tintIcons(category);
final DashboardDataV2 prevData = mDashboardData;
Log.d(TAG, "adapter setCategory called");
mDashboardData = new DashboardDataV2.Builder(prevData)
@@ -155,8 +153,8 @@
// remain as the dashboard item. Need to refresh the dashboard list.
final DashboardDataV2 prevData = mDashboardData;
mDashboardData = new DashboardDataV2.Builder(prevData)
- .setSuggestions(null)
- .build();
+ .setSuggestions(null)
+ .build();
notifyDashboardDataChanged(prevData);
} else {
mSuggestionAdapter.removeSuggestion(suggestion);
@@ -194,7 +192,7 @@
switch (type) {
case R.layout.dashboard_tile:
final Tile tile = (Tile) mDashboardData.getItemEntityByPosition(position);
- onBindTile((DashboardItemHolder) holder, tile);
+ onBindTile(holder, tile);
holder.itemView.setTag(tile);
holder.itemView.setOnClickListener(mTileClickListener);
break;
@@ -214,7 +212,7 @@
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, false);
DashboardDataV2 prevData = mDashboardData;
mDashboardData = new DashboardDataV2.Builder(prevData).
- setConditionExpanded(false).build();
+ setConditionExpanded(false).build();
notifyDashboardDataChanged(prevData);
scrollToTopOfConditions();
});
@@ -275,14 +273,14 @@
} else {
holder.title.setText(null);
holder.summary.setText(
- mContext.getString(R.string.condition_summary, data.conditionCount));
+ mContext.getString(R.string.condition_summary, data.conditionCount));
updateConditionIcons(data.conditionIcons, holder.icons);
holder.icons.setVisibility(View.VISIBLE);
}
holder.itemView.setOnClickListener(v -> {
mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, true);
+ MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, true);
final DashboardDataV2 prevData = mDashboardData;
mDashboardData = new DashboardDataV2.Builder(prevData)
.setConditionExpanded(true).build();
@@ -294,8 +292,8 @@
@VisibleForTesting
void onBindCondition(final ConditionContainerHolder holder, int position) {
final ConditionAdapterV2 adapter = new ConditionAdapterV2(mContext,
- (List<Condition>) mDashboardData.getItemEntityByPosition(position),
- mDashboardData.isConditionExpanded());
+ (List<Condition>) mDashboardData.getItemEntityByPosition(position),
+ mDashboardData.isConditionExpanded());
adapter.addDismissHandling(holder.data);
holder.data.setAdapter(adapter);
holder.data.setLayoutManager(new LinearLayoutManager(mContext));
@@ -306,10 +304,10 @@
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
// header anymore.
final List<Suggestion> suggestions =
- (List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
+ (List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
final int suggestionCount = suggestions.size();
if (suggestions != null && suggestionCount > 0) {
- holder.summary.setText(""+suggestionCount);
+ holder.summary.setText("" + suggestionCount);
mSuggestionAdapter.setSuggestions(suggestions);
holder.data.setAdapter(mSuggestionAdapter);
}
@@ -318,8 +316,14 @@
holder.data.setLayoutManager(layoutManager);
}
- private void onBindTile(DashboardItemHolder holder, Tile tile) {
- holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
+ @VisibleForTesting
+ void onBindTile(DashboardItemHolder holder, Tile tile) {
+ Drawable icon = mCache.getIcon(tile.icon);
+ if (!TextUtils.equals(tile.icon.getResPackage(), mContext.getPackageName())) {
+ icon = new RoundedHomepageIcon(mContext, icon);
+ mCache.updateIcon(tile.icon, icon);
+ }
+ holder.icon.setImageDrawable(icon);
holder.title.setText(tile.title);
if (!TextUtils.isEmpty(tile.summary)) {
holder.summary.setText(tile.summary);
@@ -329,25 +333,6 @@
}
}
- private void tintIcons(DashboardCategory category) {
- if (!mDashboardFeatureProvider.shouldTintIcon()) {
- return;
- }
- // TODO: Better place for tinting?
- final TypedArray a = mContext.obtainStyledAttributes(new int[]{
- android.R.attr.colorControlNormal});
- final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
- a.recycle();
- if (category != null) {
- for (Tile tile : category.getTiles()) {
- if (tile.isIconTintable) {
- // If this drawable is tintable, tint it to match the color.
- tile.icon.setTint(tintColor);
- }
- }
- }
- }
-
@Override
public void onSaveInstanceState(Bundle outState) {
final DashboardCategory category = mDashboardData.getCategory();
@@ -392,10 +377,14 @@
Drawable drawable = mMap.get(icon);
if (drawable == null) {
drawable = icon.loadDrawable(mContext);
- mMap.put(icon, drawable);
+ updateIcon(icon, drawable);
}
return drawable;
}
+
+ public void updateIcon(Icon icon, Drawable drawable) {
+ mMap.put(icon, drawable);
+ }
}
public static class DashboardItemHolder extends RecyclerView.ViewHolder {
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
index c493e672..e0873f5 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -56,7 +56,9 @@
/**
* Whether or not we should tint icons in setting pages.
+ * @deprecated in favor of color icons in homepage
*/
+ @Deprecated
boolean shouldTintIcon();
/**
diff --git a/src/com/android/settings/dashboard/RoundedHomepageIcon.java b/src/com/android/settings/dashboard/RoundedHomepageIcon.java
new file mode 100644
index 0000000..19749b9
--- /dev/null
+++ b/src/com/android/settings/dashboard/RoundedHomepageIcon.java
@@ -0,0 +1,36 @@
+/*
+ * 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.dashboard;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+
+import com.android.settings.R;
+
+public class RoundedHomepageIcon extends LayerDrawable {
+
+ public RoundedHomepageIcon(Context context, Drawable foreground) {
+ super(new Drawable[] {
+ context.getDrawable(R.drawable.ic_homepage_generic_background),
+ foreground
+ });
+ final int insetPx = context.getResources()
+ .getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
+ setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 8b0ed46..18b77bc 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -30,6 +30,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.widget.MasterCheckBoxPreference;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.SwitchBar;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
@@ -277,9 +278,9 @@
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
final NotificationChannel channel, final boolean groupBlocked) {
- MasterSwitchPreference channelPref = new MasterSwitchPreference(
+ MasterCheckBoxPreference channelPref = new MasterCheckBoxPreference(
getPrefContext());
- channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
+ channelPref.setCheckBoxEnabled(mSuspendedAppsAdmin == null
&& isChannelBlockable(channel)
&& isChannelConfigurable(channel)
&& !groupBlocked);
diff --git a/src/com/android/settings/widget/MasterCheckBoxPreference.java b/src/com/android/settings/widget/MasterCheckBoxPreference.java
index 333c9aa..552f51c 100644
--- a/src/com/android/settings/widget/MasterCheckBoxPreference.java
+++ b/src/com/android/settings/widget/MasterCheckBoxPreference.java
@@ -34,6 +34,7 @@
private CheckBox mCheckBox;
private boolean mChecked;
+ private boolean mEnableCheckBox = true;
public MasterCheckBoxPreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
@@ -88,9 +89,7 @@
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
- if (mCheckBox != null) {
- mCheckBox.setEnabled(enabled);
- }
+ setCheckBoxEnabled(enabled);
}
public boolean isChecked() {
@@ -104,6 +103,13 @@
}
}
+ public void setCheckBoxEnabled(boolean enabled) {
+ mEnableCheckBox = enabled;
+ if (mCheckBox != null) {
+ mCheckBox.setEnabled(enabled);
+ }
+ }
+
public CheckBox getCheckBox() {
return mCheckBox;
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterV2Test.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterV2Test.java
index 801a8e4..40150cb 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterV2Test.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterV2Test.java
@@ -16,11 +16,8 @@
package com.android.settings.dashboard;
import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -31,11 +28,12 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.res.Resources;
-import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.service.settings.suggestions.Suggestion;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
+import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
@@ -47,7 +45,6 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
-import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
@@ -58,6 +55,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@@ -97,7 +95,7 @@
mConditionList.add(mCondition);
when(mCondition.shouldShow()).thenReturn(true);
mDashboardAdapter = new DashboardAdapterV2(mContext, null /* savedInstanceState */,
- mConditionList, null /* suggestionControllerMixin */, null /* lifecycle */);
+ mConditionList, null /* suggestionControllerMixin */, null /* lifecycle */);
when(mView.getTag()).thenReturn(mCondition);
}
@@ -105,7 +103,8 @@
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
final DashboardAdapterV2 adapter =
spy(new DashboardAdapterV2(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */));
+ null /* conditions */, null /* suggestionControllerMixin */, null /*
+ lifecycle */));
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3");
adapter.setSuggestions(suggestions);
@@ -143,8 +142,9 @@
new DashboardAdapterV2.SuggestionContainerHolder(itemView);
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3", "pkg4");
final DashboardAdapterV2 adapter = spy(new DashboardAdapterV2(mContext,
- null /*savedInstance */, null /* conditions */, null /* suggestionControllerMixin */,
- null /* lifecycle */));
+ null /*savedInstance */, null /* conditions */,
+ null /* suggestionControllerMixin */,
+ null /* lifecycle */));
adapter.setSuggestions(suggestions);
adapter.onBindSuggestion(holder, 0);
@@ -160,7 +160,8 @@
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
DashboardAdapterV2 adapter =
spy(new DashboardAdapterV2(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */));
+ null /* conditions */, null /* suggestionControllerMixin */, null /*
+ lifecycle */));
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
adapter.setSuggestions(suggestions);
final DashboardDataV2 dashboardData = adapter.mDashboardData;
@@ -173,27 +174,9 @@
}
@Test
- public void testSetCategories_iconTinted() {
- TypedArray mockTypedArray = mock(TypedArray.class);
- doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
- doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
-
- final DashboardCategory category = new DashboardCategory();
- final Icon mockIcon = mock(Icon.class);
- final Tile tile = new Tile();
- tile.isIconTintable = true;
- tile.icon = mockIcon;
- category.addTile(tile);
-
- mDashboardAdapter.setCategory(category);
-
- verify(mockIcon).setTint(eq(0x89000000));
- }
-
- @Test
public void testBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
mDashboardAdapter = new DashboardAdapterV2(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+ null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
mDashboardAdapter.setSuggestions(suggestions);
@@ -217,7 +200,7 @@
@Test
public void testBindSuggestion_shouldSetSummary() {
mDashboardAdapter = new DashboardAdapterV2(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+ null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
mDashboardAdapter.setSuggestions(suggestions);
@@ -231,7 +214,7 @@
final TextView summary = mock(TextView.class);
when(itemView.findViewById(android.R.id.summary)).thenReturn(summary);
final DashboardAdapterV2.SuggestionContainerHolder holder =
- new DashboardAdapterV2.SuggestionContainerHolder(itemView);
+ new DashboardAdapterV2.SuggestionContainerHolder(itemView);
mDashboardAdapter.onBindSuggestion(holder, 0);
@@ -245,6 +228,46 @@
verify(summary).setText("4");
}
+ @Test
+ public void onBindTile_internalTile_shouldNotUseGenericBackgroundIcon() {
+ final Context context = RuntimeEnvironment.application;
+ final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
+ final DashboardAdapterV2.DashboardItemHolder holder =
+ new DashboardAdapterV2.DashboardItemHolder(view);
+ final Tile tile = new Tile();
+ tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
+ final DashboardAdapterV2.IconCache iconCache = mock(DashboardAdapterV2.IconCache.class);
+ when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
+
+ mDashboardAdapter = new DashboardAdapterV2(context, null /* savedInstanceState */,
+ null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+ ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
+ mDashboardAdapter.onBindTile(holder, tile);
+
+ verify(iconCache, never()).updateIcon(any(Icon.class), any(Drawable.class));
+ }
+
+ @Test
+ public void onBindTile_externalTile_shouldNotUseGenericBackgroundIcon() {
+ final Context context = RuntimeEnvironment.application;
+ final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
+ final DashboardAdapterV2.DashboardItemHolder holder =
+ new DashboardAdapterV2.DashboardItemHolder(view);
+ final Tile tile = new Tile();
+ tile.icon = mock(Icon.class);
+ when(tile.icon.getResPackage()).thenReturn("another.package");
+
+ final DashboardAdapterV2.IconCache iconCache = mock(DashboardAdapterV2.IconCache.class);
+ when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
+
+ mDashboardAdapter = new DashboardAdapterV2(context, null /* savedInstanceState */,
+ null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+ ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
+ mDashboardAdapter.onBindTile(holder, tile);
+
+ verify(iconCache).updateIcon(eq(tile.icon), any(RoundedHomepageIcon.class));
+ }
+
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
final List<Suggestion> suggestions = new ArrayList<>();
for (String pkgName : pkgNames) {
diff --git a/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java b/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java
new file mode 100644
index 0000000..4c62a6f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/RoundedHomepageIconTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.dashboard;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class RoundedHomepageIconTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test
+ public void createIcon_shouldSetBackgroundAndInset() {
+ final RoundedHomepageIcon icon = new RoundedHomepageIcon(
+ mContext, new ColorDrawable(Color.BLACK));
+
+ assertThat(icon.getNumberOfLayers()).isEqualTo(2);
+ assertThat(icon.getDrawable(0))
+ .isEqualTo(mContext.getDrawable(R.drawable.ic_homepage_generic_background));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
index e6530d5..ac3e0b6 100644
--- a/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
@@ -89,6 +89,23 @@
}
@Test
+ public void setCheckboxEnabled_shouldOnlyUpdateCheckBoxEnabledState() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(
+ R.layout.preference_widget_master_checkbox, null));
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+
+ mPreference.setCheckBoxEnabled(false);
+ assertThat(mPreference.isEnabled()).isTrue();
+ assertThat(checkBox.isEnabled()).isFalse();
+
+ mPreference.setCheckBoxEnabled(true);
+ assertThat(mPreference.isEnabled()).isTrue();
+ assertThat(checkBox.isEnabled()).isTrue();
+ }
+
+ @Test
public void clickWidgetView_shouldToggleCheckBox() {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(