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