• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.settings.wallpaper;
18 
19 import android.app.Activity;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.pm.PackageManager;
24 import android.os.Bundle;
25 
26 import androidx.annotation.VisibleForTesting;
27 
28 import com.android.settings.R;
29 import com.android.settings.core.SubSettingLauncher;
30 import com.android.settings.display.WallpaperPreferenceController;
31 
32 import com.google.android.setupcompat.util.WizardManagerHelper;
33 
34 public abstract class StyleSuggestionActivityBase extends Activity {
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         final PackageManager pm = getPackageManager();
40         final Intent intent = new Intent()
41                 .setComponent(new WallpaperPreferenceController(this, "unused key")
42                         .getComponentName())
43                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
44 
45         // passing the necessary extra to next page
46         WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
47 
48         addExtras(intent);
49 
50         if (pm.resolveActivity(intent, 0) != null) {
51             startActivity(intent);
52         } else {
53             startFallbackSuggestion();
54         }
55 
56         finish();
57     }
58 
59     /**
60      * Add any extras to the intent before launching the wallpaper activity
61      * @param intent
62      */
addExtras(Intent intent)63     protected void addExtras(Intent intent) { }
64 
65     @VisibleForTesting
startFallbackSuggestion()66     void startFallbackSuggestion() {
67         // fall back to default wallpaper picker
68         new SubSettingLauncher(this)
69                 .setDestination(WallpaperTypeSettings.class.getName())
70                 .setTitleRes(R.string.wallpaper_suggestion_title)
71                 .setSourceMetricsCategory(SettingsEnums.DASHBOARD_SUMMARY)
72                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
73                 .launch();
74     }
75 
isWallpaperServiceEnabled(Context context)76     protected static boolean isWallpaperServiceEnabled(Context context) {
77         return context.getResources().getBoolean(
78                 com.android.internal.R.bool.config_enableWallpaperService);
79     }
80 }
81