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 | |
| 22 | import com.android.wallpaper.R; |
| 23 | import com.android.wallpaper.model.InlinePreviewIntentFactory; |
| 24 | import com.android.wallpaper.model.WallpaperInfo; |
Clément Julliard | ea1638d | 2018-05-21 19:15:17 -0700 | [diff] [blame] | 25 | import com.android.wallpaper.module.InjectorProvider; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 26 | |
Sunny Goyal | 8600a3f | 2018-08-15 12:48:01 -0700 | [diff] [blame^] | 27 | import androidx.fragment.app.Fragment; |
| 28 | import androidx.fragment.app.FragmentManager; |
| 29 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Activity that displays a preview of a specific wallpaper and provides the ability to set the |
| 32 | * wallpaper as the user's current wallpaper. |
| 33 | */ |
| 34 | public class PreviewActivity extends BasePreviewActivity { |
| 35 | |
| 36 | /** |
| 37 | * Returns a new Intent with the provided WallpaperInfo instance put as an extra. |
| 38 | */ |
| 39 | public static Intent newIntent(Context packageContext, WallpaperInfo wallpaperInfo) { |
| 40 | Intent intent = new Intent(packageContext, PreviewActivity.class); |
| 41 | intent.putExtra(EXTRA_WALLPAPER_INFO, wallpaperInfo); |
| 42 | return intent; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected void onCreate(Bundle savedInstanceState) { |
| 47 | super.onCreate(savedInstanceState); |
| 48 | setContentView(R.layout.activity_preview); |
| 49 | |
| 50 | FragmentManager fm = getSupportFragmentManager(); |
| 51 | Fragment fragment = fm.findFragmentById(R.id.fragment_container); |
| 52 | |
| 53 | if (fragment == null) { |
| 54 | Intent intent = getIntent(); |
| 55 | WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO); |
| 56 | boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false); |
Clément Julliard | ea1638d | 2018-05-21 19:15:17 -0700 | [diff] [blame] | 57 | fragment = InjectorProvider.getInjector().getPreviewFragment( |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 58 | wallpaper, PreviewFragment.MODE_CROP_AND_SET_WALLPAPER, testingModeEnabled); |
| 59 | fm.beginTransaction() |
| 60 | .add(R.id.fragment_container, fragment) |
| 61 | .commit(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Implementation that provides an intent to start a PreviewActivity. |
| 67 | */ |
| 68 | public static class PreviewActivityIntentFactory implements InlinePreviewIntentFactory { |
| 69 | @Override |
| 70 | public Intent newIntent(Context context, WallpaperInfo wallpaper) { |
| 71 | return PreviewActivity.newIntent(context, wallpaper); |
| 72 | } |
| 73 | } |
| 74 | } |