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.model.InlinePreviewIntentFactory; 27 import com.android.wallpaper.model.WallpaperInfo; 28 import com.android.wallpaper.module.InjectorProvider; 29 import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost; 30 import com.android.wallpaper.util.ActivityUtils; 31 32 /** 33 * Activity that displays a view-only preview of a specific wallpaper. 34 */ 35 public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost { 36 37 /** 38 * Returns a new Intent with the provided WallpaperInfo instance put as an extra. 39 */ newIntent(Context context, WallpaperInfo wallpaper)40 public static Intent newIntent(Context context, WallpaperInfo wallpaper) { 41 return new Intent(context, ViewOnlyPreviewActivity.class) 42 .putExtra(EXTRA_WALLPAPER_INFO, wallpaper); 43 } 44 newIntent(Context context, WallpaperInfo wallpaper, boolean isVewAsHome)45 protected static Intent newIntent(Context context, WallpaperInfo wallpaper, 46 boolean isVewAsHome) { 47 return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HOME, isVewAsHome); 48 } 49 50 @Override onCreate(Bundle savedInstanceState)51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 setContentView(R.layout.activity_preview); 54 55 enableFullScreen(); 56 57 FragmentManager fm = getSupportFragmentManager(); 58 Fragment fragment = fm.findFragmentById(R.id.fragment_container); 59 60 if (fragment == null) { 61 Intent intent = getIntent(); 62 WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO); 63 boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false); 64 boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, true); 65 fragment = InjectorProvider.getInjector().getPreviewFragment( 66 /* context */ this, 67 wallpaper, 68 PreviewFragment.MODE_VIEW_ONLY, 69 viewAsHome, 70 /* viewFullScreen= */ false, 71 testingModeEnabled); 72 fm.beginTransaction() 73 .add(R.id.fragment_container, fragment) 74 .commit(); 75 } 76 } 77 78 @Override onUpArrowPressed()79 public void onUpArrowPressed() { 80 onBackPressed(); 81 } 82 83 @Override isUpArrowSupported()84 public boolean isUpArrowSupported() { 85 return !ActivityUtils.isSUWMode(getBaseContext()); 86 } 87 88 /** 89 * Implementation that provides an intent to start a PreviewActivity. 90 */ 91 public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory { 92 private boolean mIsHomeAndLockPreviews; 93 private boolean mIsViewAsHome; 94 95 @Override newIntent(Context context, WallpaperInfo wallpaper)96 public Intent newIntent(Context context, WallpaperInfo wallpaper) { 97 if (mIsHomeAndLockPreviews) { 98 return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome); 99 } 100 return ViewOnlyPreviewActivity.newIntent(context, wallpaper); 101 } 102 setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome)103 protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) { 104 mIsHomeAndLockPreviews = isHomeAndLockPreview; 105 mIsViewAsHome = isViewAsHome; 106 } 107 } 108 } 109