1 /* 2 * Copyright (C) 2021 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.content.Context; 19 import android.content.Intent; 20 import android.content.pm.ActivityInfo; 21 import android.os.Bundle; 22 import android.transition.Slide; 23 import android.view.Window; 24 25 import androidx.fragment.app.Fragment; 26 import androidx.fragment.app.FragmentManager; 27 28 import com.android.wallpaper.R; 29 import com.android.wallpaper.config.BaseFlags; 30 import com.android.wallpaper.model.WallpaperInfo; 31 import com.android.wallpaper.module.InjectorProvider; 32 import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost; 33 import com.android.wallpaper.util.ActivityUtils; 34 import com.android.wallpaper.util.DisplayUtils; 35 36 /** 37 * Activity that displays a full preview of a specific wallpaper and provides the ability to set the 38 * wallpaper as the user's current wallpaper. 39 */ 40 public class FullPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost { 41 42 /** 43 * Returns a new Intent with the provided WallpaperInfo instance put as an extra. 44 */ newIntent(Context packageContext, WallpaperInfo wallpaperInfo)45 public static Intent newIntent(Context packageContext, WallpaperInfo wallpaperInfo) { 46 Intent intent = new Intent(packageContext, FullPreviewActivity.class); 47 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 48 intent.putExtra(EXTRA_WALLPAPER_INFO, wallpaperInfo); 49 return intent; 50 } 51 52 /** 53 * Returns a new Intent with the provided WallpaperInfo instance and view as home variable 54 * put as an extra. 55 */ newIntent(Context packageContext, WallpaperInfo wallpaperInfo, boolean viewAsHome)56 public static Intent newIntent(Context packageContext, WallpaperInfo wallpaperInfo, 57 boolean viewAsHome) { 58 return newIntent(packageContext, wallpaperInfo).putExtra(EXTRA_VIEW_AS_HOME, viewAsHome); 59 } 60 61 @Override onCreate(Bundle savedInstanceState)62 protected void onCreate(Bundle savedInstanceState) { 63 super.onCreate(savedInstanceState); 64 getWindow().setAllowEnterTransitionOverlap(true); 65 getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); 66 getWindow().setExitTransition(new Slide()); 67 getWindow().setEnterTransition(new Slide()); 68 setContentView(R.layout.activity_fullscreen_preview); 69 70 enableFullScreen(); 71 72 FragmentManager fm = getSupportFragmentManager(); 73 Fragment fragment = fm.findFragmentById(R.id.fragment_container); 74 75 if (fragment == null) { 76 Intent intent = getIntent(); 77 WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO); 78 BaseFlags flags = InjectorProvider.getInjector().getFlags(); 79 boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, !flags 80 .isFullscreenWallpaperPreviewEnabled(this)); 81 boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false); 82 fragment = InjectorProvider.getInjector().getPreviewFragment( 83 /* context= */ this, 84 wallpaper, 85 PreviewFragment.MODE_CROP_AND_SET_WALLPAPER, 86 viewAsHome, 87 /* viewFullScreen= */ true, 88 testingModeEnabled); 89 fm.beginTransaction() 90 .add(R.id.fragment_container, fragment) 91 .commit(); 92 } 93 } 94 95 @Override onUpArrowPressed()96 public void onUpArrowPressed() { 97 onBackPressed(); 98 } 99 100 @Override isUpArrowSupported()101 public boolean isUpArrowSupported() { 102 return !ActivityUtils.isSUWMode(getBaseContext()); 103 } 104 105 @Override onResume()106 protected void onResume() { 107 super.onResume(); 108 DisplayUtils displayUtils = InjectorProvider.getInjector().getDisplayUtils(this); 109 int orientation = displayUtils.isOnWallpaperDisplay(this) 110 ? ActivityInfo.SCREEN_ORIENTATION_USER : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 111 setRequestedOrientation(orientation); 112 if (isInMultiWindowMode()) { 113 onBackPressed(); 114 } 115 } 116 } 117