1 /*
2  * Copyright (C) 2017 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 package com.android.wallpaper.picker;
17 
18 import android.os.Bundle;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.TextView;
23 
24 import androidx.annotation.IntDef;
25 import androidx.fragment.app.Fragment;
26 
27 import com.android.wallpaper.R;
28 import com.android.wallpaper.module.InjectorProvider;
29 import com.android.wallpaper.module.WallpaperPreferences;
30 
31 import java.util.Date;
32 
33 /**
34  * Displays the UI indicating that setting wallpaper is disabled.
35  */
36 public class WallpaperDisabledFragment extends Fragment {
37     public static final int SUPPORTED_CAN_SET = 0;
38     public static final int NOT_SUPPORTED_BLOCKED_BY_ADMIN = 1;
39     public static final int NOT_SUPPORTED_BY_DEVICE = 2;
40     private static final String ARG_WALLPAPER_SUPPORT_LEVEL = "wallpaper_support_level";
41 
newInstance( @allpaperSupportLevel int wallpaperSupportLevel)42     public static WallpaperDisabledFragment newInstance(
43             @WallpaperSupportLevel int wallpaperSupportLevel) {
44         Bundle args = new Bundle();
45         args.putInt(ARG_WALLPAPER_SUPPORT_LEVEL, wallpaperSupportLevel);
46 
47         WallpaperDisabledFragment fragment = new WallpaperDisabledFragment();
48         fragment.setArguments(args);
49         return fragment;
50     }
51 
52     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)53     public View onCreateView(LayoutInflater inflater, ViewGroup container,
54                              Bundle savedInstanceState) {
55         View view = inflater.inflate(R.layout.fragment_disabled_by_admin, container, false);
56 
57         @WallpaperSupportLevel int wallpaperSupportLevel = getArguments().getInt(
58                 ARG_WALLPAPER_SUPPORT_LEVEL);
59         TextView messageView = (TextView) view.findViewById(R.id.wallpaper_disabled_message);
60         if (wallpaperSupportLevel == NOT_SUPPORTED_BLOCKED_BY_ADMIN) {
61             messageView.setText(R.string.wallpaper_disabled_by_administrator_message);
62         } else if (wallpaperSupportLevel == NOT_SUPPORTED_BY_DEVICE) {
63             messageView.setText(R.string.wallpaper_disabled_message);
64         }
65         return view;
66     }
67 
68     @Override
onResume()69     public void onResume() {
70         super.onResume();
71 
72         WallpaperPreferences preferences = InjectorProvider.getInjector().getPreferences(getActivity());
73         preferences.setLastAppActiveTimestamp(new Date().getTime());
74     }
75 
76     /**
77      * Whether or not setting wallpapers is supported on the current device and profile.
78      */
79     @IntDef({
80             SUPPORTED_CAN_SET,
81             NOT_SUPPORTED_BLOCKED_BY_ADMIN,
82             NOT_SUPPORTED_BY_DEVICE
83     })
84     public @interface WallpaperSupportLevel {
85     }
86 }
87