Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 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; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 21 | |
Ching-Sung Li | 4cf8e74 | 2020-04-29 09:59:02 +0800 | [diff] [blame] | 22 | import androidx.fragment.app.Fragment; |
| 23 | import androidx.fragment.app.FragmentManager; |
| 24 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 25 | import com.android.wallpaper.R; |
| 26 | import com.android.wallpaper.model.InlinePreviewIntentFactory; |
| 27 | import com.android.wallpaper.model.WallpaperInfo; |
Clément Julliard | ea1638d | 2018-05-21 19:15:17 -0700 | [diff] [blame] | 28 | import com.android.wallpaper.module.InjectorProvider; |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame^] | 29 | import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Activity that displays a view-only preview of a specific wallpaper. |
| 33 | */ |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame^] | 34 | public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost { |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 35 | |
| 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 Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 44 | 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 Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 49 | @Override |
| 50 | protected void onCreate(Bundle savedInstanceState) { |
| 51 | super.onCreate(savedInstanceState); |
| 52 | setContentView(R.layout.activity_preview); |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void onAttachedToWindow() { |
| 57 | super.onAttachedToWindow(); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 58 | |
| 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 Li | 853593f | 2020-06-10 21:42:20 +0800 | [diff] [blame] | 66 | boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HODE, true); |
Clément Julliard | ea1638d | 2018-05-21 19:15:17 -0700 | [diff] [blame] | 67 | fragment = InjectorProvider.getInjector().getPreviewFragment( |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 68 | /* context */ this, |
| 69 | wallpaper, |
| 70 | PreviewFragment.MODE_VIEW_ONLY, |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 71 | viewAsHome, |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 72 | testingModeEnabled); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 73 | fm.beginTransaction() |
| 74 | .add(R.id.fragment_container, fragment) |
| 75 | .commit(); |
| 76 | } |
| 77 | } |
| 78 | |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame^] | 79 | @Override |
| 80 | public void onUpArrowPressed() { |
| 81 | onBackPressed(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean isUpArrowSupported() { |
| 86 | return true; |
| 87 | } |
| 88 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 89 | /** |
| 90 | * Implementation that provides an intent to start a PreviewActivity. |
| 91 | */ |
| 92 | public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory { |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 93 | private boolean mIsHomeAndLockPreviews; |
| 94 | private boolean mIsViewAsHome; |
| 95 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 96 | @Override |
| 97 | public Intent newIntent(Context context, WallpaperInfo wallpaper) { |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 98 | if (mIsHomeAndLockPreviews) { |
| 99 | return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome); |
| 100 | } |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 101 | return ViewOnlyPreviewActivity.newIntent(context, wallpaper); |
| 102 | } |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 103 | |
| 104 | protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) { |
| 105 | mIsHomeAndLockPreviews = isHomeAndLockPreview; |
| 106 | mIsViewAsHome = isViewAsHome; |
| 107 | } |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 108 | } |
| 109 | } |