• 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 androidx.fragment.app.Fragment;
23 import androidx.fragment.app.FragmentManager;
24 
25 import com.android.wallpaper.R;
26 import com.android.wallpaper.model.InlinePreviewIntentFactory;
27 import com.android.wallpaper.model.WallpaperInfo;
28 import com.android.wallpaper.module.InjectorProvider;
29 import com.android.wallpaper.module.LargeScreenMultiPanesChecker;
30 import com.android.wallpaper.picker.AppbarFragment.AppbarFragmentHost;
31 import com.android.wallpaper.util.ActivityUtils;
32 
33 /**
34  * Activity that displays a view-only preview of a specific wallpaper.
35  */
36 public class ViewOnlyPreviewActivity extends BasePreviewActivity implements AppbarFragmentHost {
37 
38     /**
39      * Returns a new Intent with the provided WallpaperInfo instance put as an extra.
40      */
newIntent(Context context, WallpaperInfo wallpaper)41     public static Intent newIntent(Context context, WallpaperInfo wallpaper) {
42         return new Intent(context, ViewOnlyPreviewActivity.class)
43                 .putExtra(EXTRA_WALLPAPER_INFO, wallpaper);
44     }
45 
newIntent(Context context, WallpaperInfo wallpaper, boolean isVewAsHome)46     protected static Intent newIntent(Context context, WallpaperInfo wallpaper,
47             boolean isVewAsHome) {
48         return newIntent(context, wallpaper).putExtra(EXTRA_VIEW_AS_HOME, isVewAsHome);
49     }
50 
51     @Override
onCreate(Bundle savedInstanceState)52     protected void onCreate(Bundle savedInstanceState) {
53         super.onCreate(savedInstanceState);
54         setContentView(R.layout.activity_preview);
55 
56         enableFullScreen();
57 
58         FragmentManager fm = getSupportFragmentManager();
59         Fragment fragment = fm.findFragmentById(R.id.fragment_container);
60 
61         if (fragment == null) {
62             Intent intent = getIntent();
63             WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO);
64             boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
65             boolean viewAsHome = intent.getBooleanExtra(EXTRA_VIEW_AS_HOME, true);
66             fragment = InjectorProvider.getInjector().getPreviewFragment(
67                     /* context */ this,
68                     wallpaper,
69                     PreviewFragment.MODE_VIEW_ONLY,
70                     viewAsHome,
71                     /* viewFullScreen= */ false,
72                     testingModeEnabled);
73             fm.beginTransaction()
74                     .add(R.id.fragment_container, fragment)
75                     .commit();
76         }
77     }
78 
79     @Override
onUpArrowPressed()80     public void onUpArrowPressed() {
81         onBackPressed();
82     }
83 
84     @Override
isUpArrowSupported()85     public boolean isUpArrowSupported() {
86         return !ActivityUtils.isSUWMode(getBaseContext());
87     }
88 
89     /**
90      * Implementation that provides an intent to start a PreviewActivity.
91      */
92     public static class ViewOnlyPreviewActivityIntentFactory implements InlinePreviewIntentFactory {
93         private boolean mIsHomeAndLockPreviews;
94         private boolean mIsViewAsHome;
95 
96         @Override
newIntent(Context context, WallpaperInfo wallpaper)97         public Intent newIntent(Context context, WallpaperInfo wallpaper) {
98             LargeScreenMultiPanesChecker multiPanesChecker = new LargeScreenMultiPanesChecker();
99             // Launch a full preview activity for devices supporting multipanel mode
100             if (multiPanesChecker.isMultiPanesEnabled(context)
101                     && InjectorProvider.getInjector().getFlags()
102                         .isFullscreenWallpaperPreviewEnabled(context)) {
103                 return FullPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome);
104             }
105 
106             if (mIsHomeAndLockPreviews) {
107                 return ViewOnlyPreviewActivity.newIntent(context, wallpaper, mIsViewAsHome);
108             }
109             return ViewOnlyPreviewActivity.newIntent(context, wallpaper);
110         }
111 
setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome)112         protected void setAsHomePreview(boolean isHomeAndLockPreview, boolean isViewAsHome) {
113             mIsHomeAndLockPreviews = isHomeAndLockPreview;
114             mIsViewAsHome = isViewAsHome;
115         }
116     }
117 }
118