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; |
Kunhung Li | 1464870 | 2021-04-15 13:45:10 +0800 | [diff] [blame] | 30 | import com.android.wallpaper.util.ActivityUtils; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Activity that displays a view-only preview of a specific wallpaper. |
| 34 | */ |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame] | 35 | public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost { |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 36 | |
| 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 Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 45 | protected static Intent newIntent(Context context, WallpaperInfo wallpaper, |
| 46 | boolean isVewAsHome) { |
Santiago Etchebehere | a5736dc | 2021-06-14 14:32:32 -0700 | [diff] [blame] | 47 | return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HOME, isVewAsHome); |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 48 | } |
| 49 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 50 | @Override |
| 51 | protected void onCreate(Bundle savedInstanceState) { |
| 52 | super.onCreate(savedInstanceState); |
| 53 | setContentView(R.layout.activity_preview); |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 54 | |
Tianguang Zhang | 893187f | 2021-05-07 22:14:04 +0200 | [diff] [blame] | 55 | enableFullScreen(); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 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); |
Santiago Etchebehere | a5736dc | 2021-06-14 14:32:32 -0700 | [diff] [blame] | 64 | boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, true); |
Clément Julliard | ea1638d | 2018-05-21 19:15:17 -0700 | [diff] [blame] | 65 | fragment = InjectorProvider.getInjector().getPreviewFragment( |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 66 | /* context */ this, |
| 67 | wallpaper, |
| 68 | PreviewFragment.MODE_VIEW_ONLY, |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 69 | viewAsHome, |
Clément Julliard | 11ab207 | 2019-04-23 10:04:15 -0700 | [diff] [blame] | 70 | testingModeEnabled); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 71 | fm.beginTransaction() |
| 72 | .add(R.id.fragment_container, fragment) |
| 73 | .commit(); |
| 74 | } |
| 75 | } |
| 76 | |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame] | 77 | @Override |
| 78 | public void onUpArrowPressed() { |
| 79 | onBackPressed(); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean isUpArrowSupported() { |
Kunhung Li | 1464870 | 2021-04-15 13:45:10 +0800 | [diff] [blame] | 84 | return !ActivityUtils.isSUWMode(getBaseContext()); |
Kunhung Li | c670149 | 2021-01-28 17:35:56 +0800 | [diff] [blame] | 85 | } |
| 86 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Implementation that provides an intent to start a PreviewActivity. |
| 89 | */ |
| 90 | public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory { |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 91 | private boolean mIsHomeAndLockPreviews; |
| 92 | private boolean mIsViewAsHome; |
| 93 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 94 | @Override |
| 95 | public Intent newIntent(Context context, WallpaperInfo wallpaper) { |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 96 | if (mIsHomeAndLockPreviews) { |
| 97 | return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome); |
| 98 | } |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 99 | return ViewOnlyPreviewActivity.newIntent(context, wallpaper); |
| 100 | } |
Ching-Sung Li | ef59efa | 2020-06-05 22:41:43 +0800 | [diff] [blame] | 101 | |
| 102 | protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) { |
| 103 | mIsHomeAndLockPreviews = isHomeAndLockPreview; |
| 104 | mIsViewAsHome = isViewAsHome; |
| 105 | } |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 106 | } |
| 107 | } |