Add a generic blue background on some homepage tiles
If a homepage tile is injected from external packages, we can't control what their icons look like, so we put a generic blue circular background to make it consistent with the other icons. Change-Id: I2a935db37fff097ae15540262bff94efea55179a Fixes: 69314641 Test: robotests
This commit is contained in:
@@ -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,10 +1741,26 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/drawable/ic_homepage_display.xml"
|
||||
line="24"
|
||||
line="23"
|
||||
column="17"/>
|
||||
</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_generic_icon_background" />"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/drawable/ic_homepage_generic_background.xml"
|
||||
line="20"
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -1757,7 +1773,7 @@
|
||||
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>
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
24
res/drawable/ic_homepage_generic_background.xml
Normal file
24
res/drawable/ic_homepage_generic_background.xml
Normal file
@@ -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>
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -17,7 +17,6 @@ package com.android.settings.dashboard;
|
||||
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
|
||||
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 class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
// 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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
} 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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
@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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
// 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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
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 {
|
||||
|
@@ -56,7 +56,9 @@ public interface DashboardFeatureProvider {
|
||||
|
||||
/**
|
||||
* Whether or not we should tint icons in setting pages.
|
||||
* @deprecated in favor of color icons in homepage
|
||||
*/
|
||||
@Deprecated
|
||||
boolean shouldTintIcon();
|
||||
|
||||
/**
|
||||
|
36
src/com/android/settings/dashboard/RoundedHomepageIcon.java
Normal file
36
src/com/android/settings/dashboard/RoundedHomepageIcon.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -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 static org.mockito.Mockito.when;
|
||||
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.dashboard.suggestions.SuggestionAdapterV2;
|
||||
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.Mock;
|
||||
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 @@ public class DashboardAdapterV2Test {
|
||||
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 class DashboardAdapterV2Test {
|
||||
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 @@ public class DashboardAdapterV2Test {
|
||||
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 class DashboardAdapterV2Test {
|
||||
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;
|
||||
@@ -172,28 +173,10 @@ public class DashboardAdapterV2Test {
|
||||
verify(adapter).notifyDashboardDataChanged(any());
|
||||
}
|
||||
|
||||
@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 @@ public class DashboardAdapterV2Test {
|
||||
@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 @@ public class DashboardAdapterV2Test {
|
||||
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 @@ public class DashboardAdapterV2Test {
|
||||
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) {
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user