blob: 0e297671858f65d35bb34c78eed8d98764204233 [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;
Jon Miranda16ea1b12017-12-12 14:52:48 -080030
31/**
32 * Activity that displays a view-only preview of a specific wallpaper.
33 */
Kunhung Lic6701492021-01-28 17:35:56 +080034public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost {
Jon Miranda16ea1b12017-12-12 14:52:48 -080035
36 /**
37 * Returns a new Intent with the provided WallpaperInfo instance put as an extra.
38 */
39 public static Intent newIntent(Context context, WallpaperInfo wallpaper) {
40 return new Intent(context, ViewOnlyPreviewActivity.class)
41 .putExtra(EXTRA_WALLPAPER_INFO, wallpaper);
42 }
43
Ching-Sung Lief59efa2020-06-05 22:41:43 +080044 protected static Intent newIntent(Context context, WallpaperInfo wallpaper,
45 boolean isVewAsHome) {
46 return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HODE, isVewAsHome);
47 }
48
Jon Miranda16ea1b12017-12-12 14:52:48 -080049 @Override
50 protected void onCreate(Bundle savedInstanceState) {
51 super.onCreate(savedInstanceState);
52 setContentView(R.layout.activity_preview);
Clément Julliard11ab2072019-04-23 10:04:15 -070053 }
54
55 @Override
56 public void onAttachedToWindow() {
57 super.onAttachedToWindow();
Jon Miranda16ea1b12017-12-12 14:52:48 -080058
59 FragmentManager fm = getSupportFragmentManager();
60 Fragment fragment = fm.findFragmentById(R.id.fragment_container);
61
62 if (fragment == null) {
63 Intent intent = getIntent();
64 WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO);
65 boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
Ching-Sung Li853593f2020-06-10 21:42:20 +080066 boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HODE, true);
Clément Julliardea1638d2018-05-21 19:15:17 -070067 fragment = InjectorProvider.getInjector().getPreviewFragment(
Clément Julliard11ab2072019-04-23 10:04:15 -070068 /* context */ this,
69 wallpaper,
70 PreviewFragment.MODE_VIEW_ONLY,
Ching-Sung Lief59efa2020-06-05 22:41:43 +080071 viewAsHome,
Clément Julliard11ab2072019-04-23 10:04:15 -070072 testingModeEnabled);
Jon Miranda16ea1b12017-12-12 14:52:48 -080073 fm.beginTransaction()
74 .add(R.id.fragment_container, fragment)
75 .commit();
76 }
77 }
78
Kunhung Lic6701492021-01-28 17:35:56 +080079 @Override
80 public void onUpArrowPressed() {
81 onBackPressed();
82 }
83
84 @Override
85 public boolean isUpArrowSupported() {
86 return true;
87 }
88
Jon Miranda16ea1b12017-12-12 14:52:48 -080089 /**
90 * Implementation that provides an intent to start a PreviewActivity.
91 */
92 public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory {
Ching-Sung Lief59efa2020-06-05 22:41:43 +080093 private boolean mIsHomeAndLockPreviews;
94 private boolean mIsViewAsHome;
95
Jon Miranda16ea1b12017-12-12 14:52:48 -080096 @Override
97 public Intent newIntent(Context context, WallpaperInfo wallpaper) {
Ching-Sung Lief59efa2020-06-05 22:41:43 +080098 if (mIsHomeAndLockPreviews) {
99 return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome);
100 }
Jon Miranda16ea1b12017-12-12 14:52:48 -0800101 return ViewOnlyPreviewActivity.newIntent(context, wallpaper);
102 }
Ching-Sung Lief59efa2020-06-05 22:41:43 +0800103
104 protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) {
105 mIsHomeAndLockPreviews = isHomeAndLockPreview;
106 mIsViewAsHome = isViewAsHome;
107 }
Jon Miranda16ea1b12017-12-12 14:52:48 -0800108 }
109}