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.content.Context; 19 import android.content.Intent; 20 import android.os.Bundle; 21 22 import androidx.fragment.app.Fragment; 23 import androidx.fragment.app.FragmentManager; 24 25 import com.android.wallpaper.R; 26 import com.android.wallpaper.config.BaseFlags; 27 import com.android.wallpaper.model.InlinePreviewIntentFactory; 28 import com.android.wallpaper.model.WallpaperInfo; 29 import com.android.wallpaper.module.InjectorProvider; 30 import com.android.wallpaper.module.LargeScreenMultiPanesChecker; 31 import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost; 32 import com.android.wallpaper.picker.preview.ui.WallpaperPreviewActivity; 33 import com.android.wallpaper.util.ActivityUtils; 34 35 /** 36 * Activity that displays a view-only preview of a specific wallpaper. 37 * 38 * <p>TODO(b/298037335): Maybe reuse PreviewActivity and remove ViewOnlyPreviewActivity. 39 */ 40 public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost { 41 42 /** 43 * Returns a new Intent with the provided WallpaperInfo instance put as an extra. 44 */ newIntent(Context context, WallpaperInfo wallpaper)45 public static Intent newIntent(Context context, WallpaperInfo wallpaper) { 46 return new Intent(context, ViewOnlyPreviewActivity.class) 47 .putExtra(EXTRA_WALLPAPER_INFO, wallpaper); 48 } 49 50 /** 51 * Returns a new Intent with extra to start this activity. 52 * 53 * @param isVewAsHome true to preview home screen, otherwise preview lock screen. 54 */ newIntent(Context context, WallpaperInfo wallpaper, boolean isVewAsHome, boolean isAssetIdPresent)55 public static Intent newIntent(Context context, WallpaperInfo wallpaper, 56 boolean isVewAsHome, boolean isAssetIdPresent) { 57 return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HOME, isVewAsHome) 58 .putExtra(IS_ASSET_ID_PRESENT, isAssetIdPresent); 59 } 60 61 @Override onCreate(Bundle savedInstanceState)62 protected void onCreate(Bundle savedInstanceState) { 63 super.onCreate(savedInstanceState); 64 setContentView(R.layout.activity_preview); 65 66 enableFullScreen(); 67 68 FragmentManager fm = getSupportFragmentManager(); 69 Fragment fragment = fm.findFragmentById(R.id.fragment_container); 70 71 if (fragment == null) { 72 Intent intent = getIntent(); 73 WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO); 74 boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, true); 75 boolean isAssetIdPresent = intent.getBooleanExtra(IS_ASSET_ID_PRESENT, true); 76 fragment = InjectorProvider.getInjector().getPreviewFragment( 77 /* context */ this, 78 wallpaper, 79 viewAsHome, 80 isAssetIdPresent, 81 /* isNewTask= */ false); 82 fm.beginTransaction() 83 .add(R.id.fragment_container, fragment) 84 .commit(); 85 } 86 } 87 88 @Override onUpArrowPressed()89 public void onUpArrowPressed() { 90 onBackPressed(); 91 } 92 93 @Override isUpArrowSupported()94 public boolean isUpArrowSupported() { 95 return !ActivityUtils.isSUWMode(getBaseContext()); 96 } 97 98 /** 99 * Implementation that provides an intent to start a PreviewActivity. 100 * 101 * <p>Get singleton instance from [Injector] instead of creating new instance directly. 102 */ 103 public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory { 104 private boolean mIsViewAsHome = false; 105 106 @Override newIntent(Context context, WallpaperInfo wallpaper, boolean isAssetIdPresent)107 public Intent newIntent(Context context, WallpaperInfo wallpaper, 108 boolean isAssetIdPresent) { 109 Context appContext = context.getApplicationContext(); 110 LargeScreenMultiPanesChecker multiPanesChecker = new LargeScreenMultiPanesChecker(); 111 final boolean isMultiPanel = multiPanesChecker.isMultiPanesEnabled(appContext); 112 final BaseFlags flags = InjectorProvider.getInjector().getFlags(); 113 if (flags.isMultiCropEnabled()) { 114 return WallpaperPreviewActivity.Companion.newIntent(appContext, wallpaper, 115 isAssetIdPresent, mIsViewAsHome, /* isNewTask= */ isMultiPanel); 116 } 117 118 // Launch a full preview activity for devices supporting multipanel mode 119 if (isMultiPanel) { 120 return FullPreviewActivity.newIntent(appContext, wallpaper, mIsViewAsHome, 121 isAssetIdPresent); 122 } 123 124 return ViewOnlyPreviewActivity.newIntent(appContext, wallpaper, mIsViewAsHome, 125 isAssetIdPresent); 126 } 127 128 @Override setViewAsHome(boolean isViewAsHome)129 public void setViewAsHome(boolean isViewAsHome) { 130 mIsViewAsHome = isViewAsHome; 131 } 132 } 133 } 134