• 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.individual;
17 
18 import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_LIVE_WALLPAPER_REQUEST_CODE;
19 import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_WALLPAPER_REQUEST_CODE;
20 
21 import android.app.Activity;
22 import android.util.Log;
23 import android.view.View;
24 
25 import com.android.wallpaper.model.InlinePreviewIntentFactory;
26 import com.android.wallpaper.model.LiveWallpaperInfo;
27 import com.android.wallpaper.model.WallpaperInfo;
28 import com.android.wallpaper.module.InjectorProvider;
29 import com.android.wallpaper.module.UserEventLogger;
30 import com.android.wallpaper.module.WallpaperPersister;
31 import com.android.wallpaper.picker.PreviewActivity;
32 
33 /**
34  * IndividualHolder subclass for a wallpaper tile in the RecyclerView for which a click should
35  * show a full-screen preview of the wallpaper.
36  */
37 class PreviewIndividualHolder extends IndividualHolder implements View.OnClickListener {
38     private static final String TAG = "PreviewIndividualHolder";
39 
40     private WallpaperPersister mWallpaperPersister;
41     private InlinePreviewIntentFactory mPreviewIntentFactory;
42 
PreviewIndividualHolder( Activity hostActivity, int tileHeightPx, View itemView)43     public PreviewIndividualHolder(
44             Activity hostActivity, int tileHeightPx, View itemView) {
45         super(hostActivity, tileHeightPx, itemView);
46         mTileLayout.setOnClickListener(this);
47 
48         mWallpaperPersister = InjectorProvider.getInjector().getWallpaperPersister(hostActivity);
49         mPreviewIntentFactory = new PreviewActivity.PreviewActivityIntentFactory();
50     }
51 
52     @Override
onClick(View view)53     public void onClick(View view) {
54         if (mActivity.isFinishing()) {
55             Log.w(TAG, "onClick received on VH on finishing Activity");
56             return;
57         }
58         UserEventLogger eventLogger =
59                 InjectorProvider.getInjector().getUserEventLogger(mActivity);
60         eventLogger.logIndividualWallpaperSelected(mWallpaper.getCollectionId(mActivity));
61 
62         showPreview(mWallpaper);
63     }
64 
65     /**
66      * Shows the preview activity for the given wallpaper.
67      */
showPreview(WallpaperInfo wallpaperInfo)68     private void showPreview(WallpaperInfo wallpaperInfo) {
69         mWallpaperPersister.setWallpaperInfoInPreview(wallpaperInfo);
70         wallpaperInfo.showPreview(mActivity, mPreviewIntentFactory,
71                 wallpaperInfo instanceof LiveWallpaperInfo ? PREVIEW_LIVE_WALLPAPER_REQUEST_CODE
72                         : PREVIEW_WALLPAPER_REQUEST_CODE);
73     }
74 
75 }
76