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