Add setting suggestion for style
Also added extra to the existing wallpaper suggestion so it opens directly to that tab instead of the style tab Test: atest com.android.settings.wallpaper.StyleSuggestionActivityTest Fixes: 126230901 Change-Id: I50ca588627063194900dca8a9273baff4a44ca67
This commit is contained in:
@@ -848,6 +848,23 @@
|
||||
<meta-data android:name="com.android.settings.icon_tintable" android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name=".wallpaper.StyleSuggestionActivity"
|
||||
android:label="@string/style_suggestion_title"
|
||||
android:icon="@drawable/ic_theme"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.settings.suggested.category.FIRST_IMPRESSION" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.title"
|
||||
android:resource="@string/style_suggestion_title" />
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/style_suggestion_summary" />
|
||||
<meta-data android:name="com.android.settings.dismiss"
|
||||
android:value="3,7,30" />
|
||||
<meta-data android:name="com.android.settings.icon_tintable" android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="Settings$ZenModeScheduleRuleSettingsActivity"
|
||||
android:exported="true"
|
||||
|
26
res/drawable/ic_theme.xml
Normal file
26
res/drawable/ic_theme.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<!-- This draws a paintbrush like shape -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorAccent">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,2v9c0,1.65 1.35,3 3,3h2v6c0,1.1 0.9,2 2,2h2c1.1,0 2,-0.9 2,-2v-6h2c1.65,0 3,-1.35 3,-3V2C20,2 4,2 4,2zM11,20v-6h2v6H11zM18,11c0,0.55 -0.45,1 -1,1h-2H9H7c-0.55,0 -1,-0.45 -1,-1v-0.93h12V11zM18,8.07H6V4h2.81v2.15h2V4h2.38v2.15h2V4H18V8.07z"/>
|
||||
</vector>
|
@@ -31,6 +31,7 @@ import com.android.settings.notification.ZenOnboardingActivity;
|
||||
import com.android.settings.notification.ZenSuggestionActivity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.ScreenLockSuggestionActivity;
|
||||
import com.android.settings.wallpaper.StyleSuggestionActivity;
|
||||
import com.android.settings.wallpaper.WallpaperSuggestionActivity;
|
||||
import com.android.settings.wifi.calling.WifiCallingSuggestionActivity;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -62,6 +63,8 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
final String className = component.getClassName();
|
||||
if (className.equals(WallpaperSuggestionActivity.class.getName())) {
|
||||
return WallpaperSuggestionActivity.isSuggestionComplete(context);
|
||||
} else if (className.equals(StyleSuggestionActivity.class.getName())) {
|
||||
return StyleSuggestionActivity.isSuggestionComplete(context);
|
||||
} else if (className.equals(FingerprintSuggestionActivity.class.getName())) {
|
||||
return FingerprintSuggestionActivity.isSuggestionComplete(context);
|
||||
} else if (className.equals(FingerprintEnrollSuggestionActivity.class.getName())) {
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
public class StyleSuggestionActivity extends StyleSuggestionActivityBase {
|
||||
|
||||
@VisibleForTesting
|
||||
public static boolean isSuggestionComplete(Context context) {
|
||||
if (!isWallpaperServiceEnabled(context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final String currentTheme = Settings.Secure.getStringForUser(context.getContentResolver(),
|
||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, context.getUserId());
|
||||
if (TextUtils.isEmpty(currentTheme)) {
|
||||
// Empty value means the user has not visited the styles tab yet
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.wallpaper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.display.WallpaperPreferenceController;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
public abstract class StyleSuggestionActivityBase extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final PackageManager pm = getPackageManager();
|
||||
final Intent intent = new Intent()
|
||||
.setComponent(new WallpaperPreferenceController(this, "dummy key")
|
||||
.getComponentName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
|
||||
// passing the necessary extra to next page
|
||||
WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
|
||||
|
||||
addExtras(intent);
|
||||
|
||||
if (pm.resolveActivity(intent, 0) != null) {
|
||||
startActivity(intent);
|
||||
} else {
|
||||
startFallbackSuggestion();
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any extras to the intent before launching the wallpaper activity
|
||||
* @param intent
|
||||
*/
|
||||
protected void addExtras(Intent intent) { }
|
||||
|
||||
@VisibleForTesting
|
||||
void startFallbackSuggestion() {
|
||||
// fall back to default wallpaper picker
|
||||
new SubSettingLauncher(this)
|
||||
.setDestination(WallpaperTypeSettings.class.getName())
|
||||
.setTitleRes(R.string.wallpaper_suggestion_title)
|
||||
.setSourceMetricsCategory(SettingsEnums.DASHBOARD_SUMMARY)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
|
||||
.launch();
|
||||
}
|
||||
|
||||
protected static boolean isWallpaperServiceEnabled(Context context) {
|
||||
return context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_enableWallpaperService);
|
||||
}
|
||||
}
|
@@ -16,63 +16,31 @@
|
||||
|
||||
package com.android.settings.wallpaper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.WallpaperManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.display.WallpaperPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class WallpaperSuggestionActivity extends Activity implements Indexable {
|
||||
public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase implements Indexable {
|
||||
|
||||
private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR";
|
||||
private static final String WALLPAPER_FOCUS = "focus_wallpaper";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final PackageManager pm = getPackageManager();
|
||||
final Intent intent = new Intent()
|
||||
.setComponent(new WallpaperPreferenceController(this, "dummy key")
|
||||
.getComponentName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
|
||||
// passing the necessary extra to next page
|
||||
WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
|
||||
|
||||
if (pm.resolveActivity(intent, 0) != null) {
|
||||
startActivity(intent);
|
||||
} else {
|
||||
startFallbackSuggestion();
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void startFallbackSuggestion() {
|
||||
// fall back to default wallpaper picker
|
||||
new SubSettingLauncher(this)
|
||||
.setDestination(WallpaperTypeSettings.class.getName())
|
||||
.setTitleRes(R.string.wallpaper_suggestion_title)
|
||||
.setSourceMetricsCategory(SettingsEnums.DASHBOARD_SUMMARY)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
|
||||
.launch();
|
||||
protected void addExtras(Intent intent) {
|
||||
intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -85,11 +53,6 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable {
|
||||
return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
|
||||
}
|
||||
|
||||
private static boolean isWallpaperServiceEnabled(Context context) {
|
||||
return context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_enableWallpaperService);
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type";
|
||||
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.wallpaper;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class StyleSuggestionActivityTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallpaperServiceEnabled_no_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService))
|
||||
.thenReturn(false);
|
||||
assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void hasStyleSet_yes_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService))
|
||||
.thenReturn(true);
|
||||
|
||||
Settings.Secure.putString(mContentResolver,
|
||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, "test");
|
||||
assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public void hasStyleSet_no_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService))
|
||||
.thenReturn(true);
|
||||
|
||||
Settings.Secure.putString(mContentResolver,
|
||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, null);
|
||||
assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user