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;
21 import android.view.View;
22 
23 import androidx.fragment.app.Fragment;
24 import androidx.fragment.app.FragmentManager;
25 
26 import com.android.wallpaper.R;
27 import com.android.wallpaper.model.InlinePreviewIntentFactory;
28 import com.android.wallpaper.model.WallpaperInfo;
29 import com.android.wallpaper.module.InjectorProvider;
30 
31 /**
32  * Activity that displays a preview of a specific wallpaper and provides the ability to set the
33  * wallpaper as the user's current wallpaper.
34  */
35 public class PreviewActivity extends BasePreviewActivity {
36 
37     /**
38      * Returns a new Intent with the provided WallpaperInfo instance put as an extra.
39      */
newIntent(Context packageContext, WallpaperInfo wallpaperInfo)40     public static Intent newIntent(Context packageContext, WallpaperInfo wallpaperInfo) {
41         Intent intent = new Intent(packageContext, PreviewActivity.class);
42         intent.putExtra(EXTRA_WALLPAPER_INFO, wallpaperInfo);
43         return intent;
44     }
45 
46     @Override
onCreate(Bundle savedInstanceState)47     protected void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49         setContentView(R.layout.activity_preview);
50         getWindow().getDecorView().setSystemUiVisibility(
51                 View.SYSTEM_UI_FLAG_LAYOUT_STABLE
52                         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
53                         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
54 
55         FragmentManager fm = getSupportFragmentManager();
56         Fragment fragment = fm.findFragmentById(R.id.fragment_container);
57 
58         if (fragment == null) {
59             Intent intent = getIntent();
60             WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO);
61             boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
62             fragment = InjectorProvider.getInjector().getPreviewFragment(
63                     /* context */ this,
64                     wallpaper,
65                     PreviewFragment.MODE_CROP_AND_SET_WALLPAPER,
66                     testingModeEnabled);
67             fm.beginTransaction()
68                     .add(R.id.fragment_container, fragment)
69                     .commit();
70         }
71     }
72 
73 
74     /**
75      * Implementation that provides an intent to start a PreviewActivity.
76      */
77     public static class PreviewActivityIntentFactory implements InlinePreviewIntentFactory {
78         @Override
newIntent(Context context, WallpaperInfo wallpaper)79         public Intent newIntent(Context context, WallpaperInfo wallpaper) {
80             return PreviewActivity.newIntent(context, wallpaper);
81         }
82     }
83 }
84