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