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