blob: 67bb943912a1f9e10ea81efc611b3870b555f4d7 [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
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 */
16package com.android.wallpaper.picker;
17
18import android.content.Context;
19import android.content.Intent;
20import android.os.Bundle;
Jon Miranda16ea1b12017-12-12 14:52:48 -080021
Ching-Sung Li4cf8e742020-04-29 09:59:02 +080022import androidx.fragment.app.Fragment;
23import androidx.fragment.app.FragmentManager;
24
Jon Miranda16ea1b12017-12-12 14:52:48 -080025import com.android.wallpaper.R;
26import com.android.wallpaper.model.InlinePreviewIntentFactory;
27import com.android.wallpaper.model.WallpaperInfo;
Clément Julliardea1638d2018-05-21 19:15:17 -070028import com.android.wallpaper.module.InjectorProvider;
Kunhung Lic6701492021-01-28 17:35:56 +080029import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost;
Kunhung Li14648702021-04-15 13:45:10 +080030import com.android.wallpaper.util.ActivityUtils;
Jon Miranda16ea1b12017-12-12 14:52:48 -080031
32/**
33 * Activity that displays a view-only preview of a specific wallpaper.
34 */
Kunhung Lic6701492021-01-28 17:35:56 +080035public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost {
Jon Miranda16ea1b12017-12-12 14:52:48 -080036
37 /**
38 * Returns a new Intent with the provided WallpaperInfo instance put as an extra.
39 */
40 public static Intent newIntent(Context context, WallpaperInfo wallpaper) {
41 return new Intent(context, ViewOnlyPreviewActivity.class)
42 .putExtra(EXTRA_WALLPAPER_INFO, wallpaper);
43 }
44
Ching-Sung Lief59efa2020-06-05 22:41:43 +080045 protected static Intent newIntent(Context context, WallpaperInfo wallpaper,
46 boolean isVewAsHome) {
Santiago Etchebeherea5736dc2021-06-14 14:32:32 -070047 return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HOME, isVewAsHome);
Ching-Sung Lief59efa2020-06-05 22:41:43 +080048 }
49
Jon Miranda16ea1b12017-12-12 14:52:48 -080050 @Override
51 protected void onCreate(Bundle savedInstanceState) {
52 super.onCreate(savedInstanceState);
53 setContentView(R.layout.activity_preview);
Clément Julliard11ab2072019-04-23 10:04:15 -070054
Tianguang Zhang893187f2021-05-07 22:14:04 +020055 enableFullScreen();
Jon Miranda16ea1b12017-12-12 14:52:48 -080056
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);
Santiago Etchebeherea5736dc2021-06-14 14:32:32 -070064 boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, true);
Clément Julliardea1638d2018-05-21 19:15:17 -070065 fragment = InjectorProvider.getInjector().getPreviewFragment(
Clément Julliard11ab2072019-04-23 10:04:15 -070066 /* context */ this,
67 wallpaper,
68 PreviewFragment.MODE_VIEW_ONLY,
Ching-Sung Lief59efa2020-06-05 22:41:43 +080069 viewAsHome,
Clément Julliard11ab2072019-04-23 10:04:15 -070070 testingModeEnabled);
Jon Miranda16ea1b12017-12-12 14:52:48 -080071 fm.beginTransaction()
72 .add(R.id.fragment_container, fragment)
73 .commit();
74 }
75 }
76
Kunhung Lic6701492021-01-28 17:35:56 +080077 @Override
78 public void onUpArrowPressed() {
79 onBackPressed();
80 }
81
82 @Override
83 public boolean isUpArrowSupported() {
Kunhung Li14648702021-04-15 13:45:10 +080084 return !ActivityUtils.isSUWMode(getBaseContext());
Kunhung Lic6701492021-01-28 17:35:56 +080085 }
86
Jon Miranda16ea1b12017-12-12 14:52:48 -080087 /**
88 * Implementation that provides an intent to start a PreviewActivity.
89 */
90 public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory {
Ching-Sung Lief59efa2020-06-05 22:41:43 +080091 private boolean mIsHomeAndLockPreviews;
92 private boolean mIsViewAsHome;
93
Jon Miranda16ea1b12017-12-12 14:52:48 -080094 @Override
95 public Intent newIntent(Context context, WallpaperInfo wallpaper) {
Ching-Sung Lief59efa2020-06-05 22:41:43 +080096 if (mIsHomeAndLockPreviews) {
97 return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome);
98 }
Jon Miranda16ea1b12017-12-12 14:52:48 -080099 return ViewOnlyPreviewActivity.newIntent(context, wallpaper);
100 }
Ching-Sung Lief59efa2020-06-05 22:41:43 +0800101
102 protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) {
103 mIsHomeAndLockPreviews = isHomeAndLockPreview;
104 mIsViewAsHome = isViewAsHome;
105 }
Jon Miranda16ea1b12017-12-12 14:52:48 -0800106 }
107}