Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 18 | import static android.view.View.MeasureSpec.EXACTLY; |
| 19 | import static android.view.View.MeasureSpec.makeMeasureSpec; |
| 20 | |
| 21 | import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY; |
| 22 | import static com.android.wallpaper.widget.BottomActionBar.BottomAction.EDIT; |
| 23 | import static com.android.wallpaper.widget.BottomActionBar.BottomAction.INFORMATION; |
| 24 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 25 | import android.animation.Animator; |
| 26 | import android.animation.AnimatorListenerAdapter; |
| 27 | import android.app.Activity; |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 28 | import android.app.WallpaperColors; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 31 | import android.graphics.Bitmap; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 32 | import android.graphics.Color; |
| 33 | import android.graphics.Point; |
| 34 | import android.graphics.PointF; |
| 35 | import android.graphics.Rect; |
| 36 | import android.os.Bundle; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 37 | import android.view.LayoutInflater; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 38 | import android.view.Surface; |
| 39 | import android.view.SurfaceControlViewHost; |
| 40 | import android.view.SurfaceHolder; |
| 41 | import android.view.SurfaceView; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 42 | import android.view.View; |
| 43 | import android.view.ViewGroup; |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 44 | import android.view.ViewGroup.LayoutParams; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 45 | import android.widget.ImageView; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 46 | |
Chuck Liao | fc1b8c9 | 2020-05-21 20:54:15 +0800 | [diff] [blame] | 47 | import androidx.annotation.NonNull; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 48 | import androidx.annotation.Nullable; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 49 | import androidx.cardview.widget.CardView; |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 50 | import androidx.constraintlayout.widget.ConstraintLayout; |
| 51 | import androidx.constraintlayout.widget.ConstraintSet; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 52 | import androidx.fragment.app.FragmentActivity; |
| 53 | |
| 54 | import com.android.wallpaper.R; |
| 55 | import com.android.wallpaper.asset.Asset; |
Chuck Liao | dc424e8 | 2020-09-04 00:17:44 +0800 | [diff] [blame] | 56 | import com.android.wallpaper.asset.CurrentWallpaperAssetVN; |
“Chuck | ffd832c | 2020-03-22 02:15:58 +0800 | [diff] [blame] | 57 | import com.android.wallpaper.model.WallpaperInfo; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 58 | import com.android.wallpaper.module.WallpaperPersister.Destination; |
| 59 | import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback; |
Tianguang Zhang | d3e4f63 | 2021-04-14 00:30:15 +0200 | [diff] [blame] | 60 | import com.android.wallpaper.util.ResourceUtils; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 61 | import com.android.wallpaper.util.ScreenSizeCalculator; |
Santiago Etchebehere | 53c6343 | 2020-05-07 18:55:35 -0700 | [diff] [blame] | 62 | import com.android.wallpaper.util.SizeCalculator; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 63 | import com.android.wallpaper.util.WallpaperCropUtils; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 64 | import com.android.wallpaper.widget.BottomActionBar; |
Wesley.CW Wang | 61c28ec | 2020-06-19 18:58:50 +0800 | [diff] [blame] | 65 | import com.android.wallpaper.widget.BottomActionBar.AccessibilityCallback; |
Chihhang Chuang | a70d90e | 2021-04-09 15:42:27 +0800 | [diff] [blame] | 66 | import com.android.wallpaper.widget.LockScreenPreviewer2; |
Chuck Liao | fc1b8c9 | 2020-05-21 20:54:15 +0800 | [diff] [blame] | 67 | import com.android.wallpaper.widget.WallpaperColorsLoader; |
Tracy Zhou | 3599742 | 2020-05-01 13:42:06 -0700 | [diff] [blame] | 68 | import com.android.wallpaper.widget.WallpaperInfoView; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 69 | |
| 70 | import com.bumptech.glide.Glide; |
| 71 | import com.bumptech.glide.MemoryCategory; |
| 72 | import com.davemorrissey.labs.subscaleview.ImageSource; |
| 73 | import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; |
chihhangchuang | 45d9413 | 2020-07-08 16:18:37 +0800 | [diff] [blame] | 74 | import com.google.android.material.tabs.TabLayout; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 75 | |
chihhangchuang | 923e29b | 2020-07-02 19:09:36 +0800 | [diff] [blame] | 76 | import java.util.Locale; |
| 77 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 78 | /** |
Santiago Etchebehere | 4ecb6aa | 2019-11-07 11:48:58 -0800 | [diff] [blame] | 79 | * Fragment which displays the UI for previewing an individual static wallpaper and its attribution |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 80 | * information. |
| 81 | */ |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 82 | public class ImagePreviewFragment extends PreviewFragment implements WallpaperColorsLoader.Callback{ |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 83 | |
| 84 | private static final float DEFAULT_WALLPAPER_MAX_ZOOM = 8f; |
| 85 | |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 86 | private final WallpaperSurfaceCallback mWallpaperSurfaceCallback = |
| 87 | new WallpaperSurfaceCallback(); |
Tracy Zhou | c5a6bad | 2020-05-20 23:28:22 -0700 | [diff] [blame] | 88 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 89 | private SubsamplingScaleImageView mFullResImageView; |
| 90 | private Asset mWallpaperAsset; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 91 | private Point mScreenSize; |
| 92 | private Point mRawWallpaperSize; // Native size of wallpaper image. |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 93 | private ImageView mLowResImageView; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 94 | private TouchForwardingLayout mTouchForwardingLayout; |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 95 | private ConstraintLayout mContainer; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 96 | private SurfaceView mWorkspaceSurface; |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 97 | private WorkspaceSurfaceHolderCallback mWorkspaceSurfaceCallback; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 98 | private SurfaceView mWallpaperSurface; |
Tracy Zhou | 3599742 | 2020-05-01 13:42:06 -0700 | [diff] [blame] | 99 | private WallpaperInfoView mWallpaperInfoView; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 100 | |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 101 | protected ViewGroup mLockPreviewContainer; |
| 102 | protected LockScreenPreviewer2 mLockScreenPreviewer; |
Chihhang Chuang | 57daaa9 | 2021-04-20 21:40:01 +0800 | [diff] [blame] | 103 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 104 | @Override |
| 105 | public void onCreate(Bundle savedInstanceState) { |
| 106 | super.onCreate(savedInstanceState); |
| 107 | mWallpaperAsset = mWallpaper.getAsset(requireContext().getApplicationContext()); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | protected int getLayoutResId() { |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 112 | return R.layout.fragment_image_preview_v2; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 115 | @Override |
Santiago Etchebehere | dc55b19 | 2019-11-08 13:56:52 -0800 | [diff] [blame] | 116 | protected int getLoadingIndicatorResId() { |
| 117 | return R.id.loading_indicator; |
| 118 | } |
| 119 | |
| 120 | @Override |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 121 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
Michel Comin Escude | b3e1fef | 2019-11-22 11:41:53 -0800 | [diff] [blame] | 122 | Bundle savedInstanceState) { |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 123 | View view = super.onCreateView(inflater, container, savedInstanceState); |
| 124 | |
| 125 | Activity activity = requireActivity(); |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 126 | mScreenSize = ScreenSizeCalculator.getInstance().getScreenSize( |
| 127 | activity.getWindowManager().getDefaultDisplay()); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 128 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 129 | // TODO: Consider moving some part of this to the base class when live preview is ready. |
| 130 | view.findViewById(R.id.low_res_image).setVisibility(View.GONE); |
| 131 | view.findViewById(R.id.full_res_image).setVisibility(View.GONE); |
| 132 | mLoadingProgressBar.hide(); |
| 133 | mContainer = view.findViewById(R.id.container); |
| 134 | mTouchForwardingLayout = mContainer.findViewById(R.id.touch_forwarding_layout); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 135 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 136 | // Set aspect ratio on the preview card dynamically. |
| 137 | ConstraintSet set = new ConstraintSet(); |
| 138 | set.clone(mContainer); |
chihhangchuang | 923e29b | 2020-07-02 19:09:36 +0800 | [diff] [blame] | 139 | String ratio = String.format(Locale.US, "%d:%d", mScreenSize.x, mScreenSize.y); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 140 | set.setDimensionRatio(mTouchForwardingLayout.getId(), ratio); |
| 141 | set.applyTo(mContainer); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 142 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 143 | mWorkspaceSurface = mContainer.findViewById(R.id.workspace_surface); |
| 144 | mWorkspaceSurfaceCallback = new WorkspaceSurfaceHolderCallback(mWorkspaceSurface, |
| 145 | getContext()); |
| 146 | mWallpaperSurface = mContainer.findViewById(R.id.wallpaper_surface); |
chihhangchuang | 287d4b7 | 2020-06-25 01:09:09 +0800 | [diff] [blame] | 147 | mLockPreviewContainer = mContainer.findViewById(R.id.lock_screen_preview_container); |
Chihhang Chuang | a70d90e | 2021-04-09 15:42:27 +0800 | [diff] [blame] | 148 | mLockScreenPreviewer = new LockScreenPreviewer2(getLifecycle(), getContext(), |
chihhangchuang | 287d4b7 | 2020-06-25 01:09:09 +0800 | [diff] [blame] | 149 | mLockPreviewContainer); |
Chuck Liao | fc1b8c9 | 2020-05-21 20:54:15 +0800 | [diff] [blame] | 150 | |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 151 | setUpTabs(view.findViewById(R.id.pill_tabs)); |
chihhangchuang | 45d9413 | 2020-07-08 16:18:37 +0800 | [diff] [blame] | 152 | updateScreenPreview(mViewAsHome); |
Tracy Zhou | e4a5f26 | 2020-05-26 17:40:19 -0700 | [diff] [blame] | 153 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 154 | view.measure(makeMeasureSpec(mScreenSize.x, EXACTLY), |
| 155 | makeMeasureSpec(mScreenSize.y, EXACTLY)); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 156 | ((CardView) mWorkspaceSurface.getParent()) |
| 157 | .setRadius(SizeCalculator.getPreviewCornerRadius( |
| 158 | activity, mContainer.getMeasuredWidth())); |
Chihhang Chuang | 57daaa9 | 2021-04-20 21:40:01 +0800 | [diff] [blame] | 159 | |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 160 | renderImageWallpaper(); |
| 161 | renderWorkspaceSurface(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 162 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 163 | // Trim some memory from Glide to make room for the full-size image in this fragment. |
| 164 | Glide.get(activity).setMemoryCategory(MemoryCategory.LOW); |
Santiago Etchebehere | f4549ed | 2019-11-13 14:18:57 -0800 | [diff] [blame] | 165 | setUpLoadingIndicator(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 166 | return view; |
| 167 | } |
| 168 | |
Santiago Etchebehere | 4ecb6aa | 2019-11-07 11:48:58 -0800 | [diff] [blame] | 169 | @Override |
Chuck Liao | fc1b8c9 | 2020-05-21 20:54:15 +0800 | [diff] [blame] | 170 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
| 171 | super.onViewCreated(view, savedInstanceState); |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 172 | WallpaperColorsLoader.getWallpaperColors(getContext(), |
| 173 | mWallpaper.getThumbAsset(getContext()), this); |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void onLoaded(@Nullable WallpaperColors colors) { |
| 178 | mLockScreenPreviewer.setColor(colors); |
Santiago Etchebehere | 4ecb6aa | 2019-11-07 11:48:58 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Santiago Etchebehere | dc55b19 | 2019-11-08 13:56:52 -0800 | [diff] [blame] | 181 | @Override |
| 182 | protected boolean isLoaded() { |
| 183 | return mFullResImageView != null && mFullResImageView.hasImage(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 186 | @Override |
| 187 | public void onClickOk() { |
| 188 | FragmentActivity activity = getActivity(); |
| 189 | if (activity != null) { |
| 190 | activity.finish(); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void onDestroy() { |
| 196 | super.onDestroy(); |
Santiago Etchebehere | f4549ed | 2019-11-13 14:18:57 -0800 | [diff] [blame] | 197 | if (mLoadingProgressBar != null) { |
| 198 | mLoadingProgressBar.hide(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 199 | } |
Chihhang Chuang | 57daaa9 | 2021-04-20 21:40:01 +0800 | [diff] [blame] | 200 | |
| 201 | if (mFullResImageView != null) { |
| 202 | mFullResImageView.recycle(); |
| 203 | } |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 204 | |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 205 | mWallpaperSurfaceCallback.cleanUp(); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 206 | mWorkspaceSurfaceCallback.cleanUp(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
Tracy Zhou | e4a5f26 | 2020-05-26 17:40:19 -0700 | [diff] [blame] | 210 | protected void onBottomActionBarReady(BottomActionBar bottomActionBar) { |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 211 | super.onBottomActionBarReady(bottomActionBar); |
Tracy Zhou | e4a5f26 | 2020-05-26 17:40:19 -0700 | [diff] [blame] | 212 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 213 | mWallpaperInfoView = (WallpaperInfoView) |
| 214 | LayoutInflater.from(getContext()).inflate( |
| 215 | R.layout.wallpaper_info_view, /* root= */null); |
| 216 | mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION); |
| 217 | mBottomActionBar.showActionsOnly(INFORMATION, EDIT, APPLY); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 218 | mBottomActionBar.setActionClickListener(EDIT, v -> |
Tracy Zhou | 16112e3 | 2020-05-27 13:13:23 -0700 | [diff] [blame] | 219 | setEditingEnabled(mBottomActionBar.isActionSelected(EDIT)) |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 220 | ); |
Chihhang Chuang | ca7c825 | 2020-06-17 17:32:46 +0800 | [diff] [blame] | 221 | mBottomActionBar.setActionSelectedListener(EDIT, this::setEditingEnabled); |
| 222 | mBottomActionBar.setActionClickListener(APPLY, this::onSetWallpaperClicked); |
Wesley.CW Wang | 61c28ec | 2020-06-19 18:58:50 +0800 | [diff] [blame] | 223 | |
| 224 | // Update target view's accessibility param since it will be blocked by the bottom sheet |
| 225 | // when expanded. |
| 226 | mBottomActionBar.setAccessibilityCallback(new AccessibilityCallback() { |
| 227 | @Override |
| 228 | public void onBottomSheetCollapsed() { |
Wesley.CW Wang | b8e51a2 | 2020-07-02 18:40:31 +0800 | [diff] [blame] | 229 | mContainer.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
Wesley.CW Wang | 61c28ec | 2020-06-19 18:58:50 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void onBottomSheetExpanded() { |
Wesley.CW Wang | b8e51a2 | 2020-07-02 18:40:31 +0800 | [diff] [blame] | 234 | mContainer.setImportantForAccessibility( |
| 235 | View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
Wesley.CW Wang | 61c28ec | 2020-06-19 18:58:50 +0800 | [diff] [blame] | 236 | } |
| 237 | }); |
| 238 | |
Chihhang Chuang | ca7c825 | 2020-06-17 17:32:46 +0800 | [diff] [blame] | 239 | // Will trigger onActionSelected callback to update the editing state. |
| 240 | mBottomActionBar.setDefaultSelectedButton(EDIT); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 241 | mBottomActionBar.show(); |
Tracy Zhou | e4a5f26 | 2020-05-26 17:40:19 -0700 | [diff] [blame] | 242 | |
chihhangchuang | 13cb1fe | 2020-06-30 16:46:59 +0800 | [diff] [blame] | 243 | mBottomActionBar.disableActions(); |
| 244 | mWallpaperAsset.decodeRawDimensions(getActivity(), dimensions -> { |
chihhangchuang | 13cb1fe | 2020-06-30 16:46:59 +0800 | [diff] [blame] | 245 | // Don't continue loading the wallpaper if the Fragment is detached. |
| 246 | if (getActivity() == null) { |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | // Return early and show a dialog if dimensions are null (signaling a decoding error). |
| 251 | if (dimensions == null) { |
| 252 | showLoadWallpaperErrorDialog(); |
| 253 | return; |
| 254 | } |
| 255 | |
Chuck Liao | ce7f08d | 2020-09-22 14:39:38 +0800 | [diff] [blame] | 256 | if (mBottomActionBar != null) { |
| 257 | mBottomActionBar.enableActions(); |
| 258 | } |
| 259 | |
chihhangchuang | 13cb1fe | 2020-06-30 16:46:59 +0800 | [diff] [blame] | 260 | mRawWallpaperSize = dimensions; |
| 261 | |
| 262 | setUpExploreIntentAndLabel(ImagePreviewFragment.this::initFullResView); |
| 263 | }); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Chihhang Chuang | 58bd0ca | 2021-04-27 00:41:13 +0800 | [diff] [blame^] | 266 | protected void setUpTabs(TabLayout tabs) { |
| 267 | tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.home_screen_message))); |
| 268 | tabs.addTab(tabs.newTab().setText(getContext().getString(R.string.lock_screen_message))); |
| 269 | tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
| 270 | @Override |
| 271 | public void onTabSelected(TabLayout.Tab tab) { |
| 272 | updateScreenPreview(tab.getPosition() == 0); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void onTabUnselected(TabLayout.Tab tab) {} |
| 277 | |
| 278 | @Override |
| 279 | public void onTabReselected(TabLayout.Tab tab) {} |
| 280 | }); |
| 281 | |
| 282 | // The TabLayout only contains below tabs |
| 283 | // 0. Home tab |
| 284 | // 1. Lock tab |
| 285 | tabs.getTabAt(mViewAsHome ? 0 : 1).select(); |
| 286 | } |
| 287 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Initializes MosaicView by initializing tiling, setting a fallback page bitmap, and |
| 290 | * initializing a zoom-scroll observer and click listener. |
| 291 | */ |
| 292 | private void initFullResView() { |
Tracy Zhou | dee0789 | 2020-06-16 20:14:30 -0700 | [diff] [blame] | 293 | // Minimum scale will only be respected under this scale type. |
| 294 | mFullResImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM); |
| 295 | // When we set a minimum scale bigger than the scale with which the full image is shown, |
| 296 | // disallow user to pan outside the view we show the wallpaper in. |
| 297 | mFullResImageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 298 | |
| 299 | // Set a solid black "page bitmap" so MosaicView draws a black background while waiting |
| 300 | // for the image to load or a transparent one if a thumbnail already loaded. |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 301 | Bitmap backgroundBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); |
Tianguang Zhang | d3e4f63 | 2021-04-14 00:30:15 +0200 | [diff] [blame] | 302 | int preColor = ResourceUtils.getColorAttr(getActivity(), android.R.attr.colorSecondary); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 303 | int color = (mLowResImageView.getDrawable() == null) ? preColor : Color.TRANSPARENT; |
| 304 | backgroundBitmap.setPixel(0, 0, color); |
| 305 | mFullResImageView.setImage(ImageSource.bitmap(backgroundBitmap)); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 306 | |
| 307 | // Then set a fallback "page bitmap" to cover the whole MosaicView, which is an actual |
| 308 | // (lower res) version of the image to be displayed. |
| 309 | Point targetPageBitmapSize = new Point(mRawWallpaperSize); |
| 310 | mWallpaperAsset.decodeBitmap(targetPageBitmapSize.x, targetPageBitmapSize.y, |
| 311 | pageBitmap -> { |
| 312 | // Check that the activity is still around since the decoding task started. |
| 313 | if (getActivity() == null) { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | // Some of these may be null depending on if the Fragment is paused, stopped, |
| 318 | // or destroyed. |
Santiago Etchebehere | f4549ed | 2019-11-13 14:18:57 -0800 | [diff] [blame] | 319 | if (mLoadingProgressBar != null) { |
| 320 | mLoadingProgressBar.hide(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 321 | } |
| 322 | // The page bitmap may be null if there was a decoding error, so show an |
| 323 | // error dialog. |
| 324 | if (pageBitmap == null) { |
| 325 | showLoadWallpaperErrorDialog(); |
| 326 | return; |
| 327 | } |
| 328 | if (mFullResImageView != null) { |
| 329 | // Set page bitmap. |
| 330 | mFullResImageView.setImage(ImageSource.bitmap(pageBitmap)); |
| 331 | |
Chuck Liao | dc424e8 | 2020-09-04 00:17:44 +0800 | [diff] [blame] | 332 | setDefaultWallpaperZoomAndScroll( |
| 333 | mWallpaperAsset instanceof CurrentWallpaperAssetVN); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 334 | crossFadeInMosaicView(); |
| 335 | } |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 336 | getActivity().invalidateOptionsMenu(); |
| 337 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 338 | if (mWallpaperInfoView != null && mWallpaper != null) { |
Chuck Liao | 9991d68 | 2021-01-20 17:45:14 +0800 | [diff] [blame] | 339 | mWallpaperInfoView.populateWallpaperInfo( |
| 340 | mWallpaper, |
| 341 | mActionLabel, |
| 342 | WallpaperInfoHelper.shouldShowExploreButton( |
| 343 | getContext(), mExploreIntent), |
| 344 | this::onExploreClicked); |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 345 | } |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 346 | }); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Makes the MosaicView visible with an alpha fade-in animation while fading out the loading |
| 351 | * indicator. |
| 352 | */ |
| 353 | private void crossFadeInMosaicView() { |
| 354 | long shortAnimationDuration = getResources().getInteger( |
| 355 | android.R.integer.config_shortAnimTime); |
| 356 | |
| 357 | mFullResImageView.setAlpha(0f); |
| 358 | mFullResImageView.animate() |
| 359 | .alpha(1f) |
| 360 | .setDuration(shortAnimationDuration) |
| 361 | .setListener(new AnimatorListenerAdapter() { |
| 362 | @Override |
| 363 | public void onAnimationEnd(Animator animation) { |
| 364 | // Clear the thumbnail bitmap reference to save memory since it's no longer |
| 365 | // visible. |
| 366 | if (mLowResImageView != null) { |
| 367 | mLowResImageView.setImageBitmap(null); |
| 368 | } |
| 369 | } |
| 370 | }); |
| 371 | |
Santiago Etchebehere | f4549ed | 2019-11-13 14:18:57 -0800 | [diff] [blame] | 372 | mLoadingProgressBar.animate() |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 373 | .alpha(0f) |
| 374 | .setDuration(shortAnimationDuration) |
| 375 | .setListener(new AnimatorListenerAdapter() { |
| 376 | @Override |
| 377 | public void onAnimationEnd(Animator animation) { |
Santiago Etchebehere | f4549ed | 2019-11-13 14:18:57 -0800 | [diff] [blame] | 378 | if (mLoadingProgressBar != null) { |
| 379 | mLoadingProgressBar.hide(); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | }); |
| 383 | } |
| 384 | |
| 385 | /** |
Michel Comin Escude | b3e1fef | 2019-11-22 11:41:53 -0800 | [diff] [blame] | 386 | * Sets the default wallpaper zoom and scroll position based on a "crop surface" (with extra |
| 387 | * width to account for parallax) superimposed on the screen. Shows as much of the wallpaper as |
| 388 | * possible on the crop surface and align screen to crop surface such that the default preview |
| 389 | * matches what would be seen by the user in the left-most home screen. |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 390 | * |
| 391 | * <p>This method is called once in the Fragment lifecycle after the wallpaper asset has loaded |
| 392 | * and rendered to the layout. |
Chuck Liao | dc424e8 | 2020-09-04 00:17:44 +0800 | [diff] [blame] | 393 | * |
Santiago Etchebehere | 16cf060 | 2020-12-11 17:04:18 -0800 | [diff] [blame] | 394 | * @param offsetToStart {@code true} if we want to offset the visible rectangle to the start |
| 395 | * side of the raw wallpaper; {@code false} otherwise. |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 396 | */ |
Santiago Etchebehere | 16cf060 | 2020-12-11 17:04:18 -0800 | [diff] [blame] | 397 | private void setDefaultWallpaperZoomAndScroll(boolean offsetToStart) { |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 398 | // Determine minimum zoom to fit maximum visible area of wallpaper on crop surface. |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 399 | int cropWidth = mWallpaperSurface.getMeasuredWidth(); |
| 400 | int cropHeight = mWallpaperSurface.getMeasuredHeight(); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 401 | Point crop = new Point(cropWidth, cropHeight); |
| 402 | Rect visibleRawWallpaperRect = |
| 403 | WallpaperCropUtils.calculateVisibleRect(mRawWallpaperSize, crop); |
Santiago Etchebehere | 16cf060 | 2020-12-11 17:04:18 -0800 | [diff] [blame] | 404 | if (offsetToStart) { |
| 405 | if (WallpaperCropUtils.isRtl(requireContext())) { |
| 406 | visibleRawWallpaperRect.offsetTo(mRawWallpaperSize.x |
| 407 | - visibleRawWallpaperRect.width(), visibleRawWallpaperRect.top); |
| 408 | } else { |
| 409 | visibleRawWallpaperRect.offsetTo(/* newLeft= */ 0, visibleRawWallpaperRect.top); |
| 410 | } |
Chuck Liao | dc424e8 | 2020-09-04 00:17:44 +0800 | [diff] [blame] | 411 | } |
Santiago Etchebehere | e95b6d9 | 2020-06-08 14:19:46 -0700 | [diff] [blame] | 412 | |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 413 | final PointF centerPosition = new PointF(visibleRawWallpaperRect.centerX(), |
| 414 | visibleRawWallpaperRect.centerY()); |
Santiago Etchebehere | e95b6d9 | 2020-06-08 14:19:46 -0700 | [diff] [blame] | 415 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 416 | Point visibleRawWallpaperSize = new Point(visibleRawWallpaperRect.width(), |
| 417 | visibleRawWallpaperRect.height()); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 418 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 419 | final float defaultWallpaperZoom = WallpaperCropUtils.calculateMinZoom( |
| 420 | visibleRawWallpaperSize, crop); |
| 421 | final float minWallpaperZoom = defaultWallpaperZoom; |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 422 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 423 | |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 424 | // Set min wallpaper zoom and max zoom on MosaicView widget. |
| 425 | mFullResImageView.setMaxScale(Math.max(DEFAULT_WALLPAPER_MAX_ZOOM, defaultWallpaperZoom)); |
| 426 | mFullResImageView.setMinScale(minWallpaperZoom); |
| 427 | |
| 428 | // Set center to composite positioning between scaled wallpaper and screen. |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 429 | mFullResImageView.setScaleAndCenter(minWallpaperZoom, centerPosition); |
| 430 | } |
| 431 | |
| 432 | private Rect calculateCropRect() { |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 433 | float wallpaperZoom = mFullResImageView.getScale(); |
Chuck Liao | 5182a31 | 2020-03-04 20:04:18 +0800 | [diff] [blame] | 434 | Context context = requireContext().getApplicationContext(); |
Tracy Zhou | 67fd7e3 | 2020-05-01 18:35:36 -0700 | [diff] [blame] | 435 | |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 436 | Rect visibleFileRect = new Rect(); |
| 437 | mFullResImageView.visibleFileRect(visibleFileRect); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 438 | |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 439 | int cropWidth = mWallpaperSurface.getMeasuredWidth(); |
| 440 | int cropHeight = mWallpaperSurface.getMeasuredHeight(); |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 441 | int maxCrop = Math.max(cropWidth, cropHeight); |
| 442 | int minCrop = Math.min(cropWidth, cropHeight); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 443 | Point hostViewSize = new Point(cropWidth, cropHeight); |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 444 | |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 445 | Resources res = context.getResources(); |
Santiago Etchebehere | bcd6bb6 | 2020-07-09 12:09:21 -0700 | [diff] [blame] | 446 | Point cropSurfaceSize = WallpaperCropUtils.calculateCropSurfaceSize(res, maxCrop, minCrop); |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 447 | |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 448 | Rect cropRect = WallpaperCropUtils.calculateCropRect(context, hostViewSize, |
Santiago Etchebehere | f172aef | 2020-07-04 18:48:35 -0700 | [diff] [blame] | 449 | cropSurfaceSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom); |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 450 | return cropRect; |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | @Override |
| 454 | protected void setCurrentWallpaper(@Destination int destination) { |
| 455 | mWallpaperSetter.setCurrentWallpaper(getActivity(), mWallpaper, mWallpaperAsset, |
| 456 | destination, mFullResImageView.getScale(), calculateCropRect(), |
| 457 | new SetWallpaperCallback() { |
| 458 | @Override |
“Chuck | ffd832c | 2020-03-22 02:15:58 +0800 | [diff] [blame] | 459 | public void onSuccess(WallpaperInfo wallpaperInfo) { |
Ching-Sung Li | b5e9bd7 | 2020-06-15 14:10:55 +0800 | [diff] [blame] | 460 | finishActivity(/* success= */ true); |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public void onError(@Nullable Throwable throwable) { |
| 465 | showSetWallpaperErrorDialog(destination); |
| 466 | } |
| 467 | }); |
| 468 | } |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 469 | |
| 470 | private void renderWorkspaceSurface() { |
| 471 | mWorkspaceSurface.setZOrderMediaOverlay(true); |
| 472 | mWorkspaceSurface.getHolder().addCallback(mWorkspaceSurfaceCallback); |
| 473 | } |
| 474 | |
| 475 | private void renderImageWallpaper() { |
| 476 | mWallpaperSurface.getHolder().addCallback(mWallpaperSurfaceCallback); |
| 477 | } |
| 478 | |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 479 | private class WallpaperSurfaceCallback implements SurfaceHolder.Callback { |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 480 | |
| 481 | private Surface mLastSurface; |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 482 | private SurfaceControlViewHost mHost; |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 483 | |
| 484 | @Override |
| 485 | public void surfaceCreated(SurfaceHolder holder) { |
| 486 | if (mLastSurface != holder.getSurface()) { |
| 487 | mLastSurface = holder.getSurface(); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 488 | if (mFullResImageView != null) { |
| 489 | mFullResImageView.recycle(); |
| 490 | } |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 491 | Context context = getContext(); |
| 492 | View wallpaperPreviewContainer = LayoutInflater.from(context).inflate( |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 493 | R.layout.fullscreen_wallpaper_preview, null); |
| 494 | mFullResImageView = wallpaperPreviewContainer.findViewById(R.id.full_res_image); |
| 495 | mLowResImageView = wallpaperPreviewContainer.findViewById(R.id.low_res_image); |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 496 | // Scale the mWallpaperSurface based on system zoom's scale so that the wallpaper is |
| 497 | // rendered in a larger surface than what preview shows, simulating the behavior of |
| 498 | // the actual wallpaper surface. |
| 499 | float scale = WallpaperCropUtils.getSystemWallpaperMaximumScale(context); |
| 500 | int origWidth = mWallpaperSurface.getWidth(); |
| 501 | int width = (int) (origWidth * scale); |
| 502 | int origHeight = mWallpaperSurface.getHeight(); |
| 503 | int height = (int) (origHeight * scale); |
| 504 | int left = (origWidth - width) / 2; |
| 505 | int top = (origHeight - height) / 2; |
| 506 | |
| 507 | if (WallpaperCropUtils.isRtl(context)) { |
| 508 | left *= -1; |
| 509 | } |
| 510 | |
| 511 | LayoutParams params = mWallpaperSurface.getLayoutParams(); |
| 512 | params.width = width; |
| 513 | params.height = height; |
| 514 | mWallpaperSurface.setX(left); |
| 515 | mWallpaperSurface.setY(top); |
| 516 | mWallpaperSurface.setLayoutParams(params); |
| 517 | mWallpaperSurface.requestLayout(); |
| 518 | |
Chuck Liao | ca1d129 | 2020-06-19 01:29:53 +0800 | [diff] [blame] | 519 | // Load a low-res placeholder image if there's a thumbnail available from the asset |
| 520 | // that can be shown to the user more quickly than the full-sized image. |
| 521 | if (mWallpaperAsset.hasLowResDataSource()) { |
| 522 | Activity activity = requireActivity(); |
| 523 | mWallpaperAsset.loadLowResDrawable(activity, mLowResImageView, Color.BLACK, |
| 524 | new WallpaperPreviewBitmapTransformation( |
| 525 | activity.getApplicationContext(), isRtl())); |
| 526 | } |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 527 | wallpaperPreviewContainer.measure( |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 528 | makeMeasureSpec(width, EXACTLY), |
| 529 | makeMeasureSpec(height, EXACTLY)); |
| 530 | wallpaperPreviewContainer.layout(0, 0, width, height); |
Ching-Sung Li | b940462 | 2020-05-18 22:38:45 +0800 | [diff] [blame] | 531 | mTouchForwardingLayout.setTargetView(mFullResImageView); |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 532 | |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 533 | cleanUp(); |
Santiago Etchebehere | 8557c46 | 2020-12-02 18:41:40 -0800 | [diff] [blame] | 534 | mHost = new SurfaceControlViewHost(context, |
| 535 | context.getDisplay(), mWallpaperSurface.getHostToken()); |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 536 | mHost.setView(wallpaperPreviewContainer, wallpaperPreviewContainer.getWidth(), |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 537 | wallpaperPreviewContainer.getHeight()); |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 538 | mWallpaperSurface.setChildSurfacePackage(mHost.getSurfacePackage()); |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } |
| 544 | |
| 545 | @Override |
| 546 | public void surfaceDestroyed(SurfaceHolder holder) { } |
Tracy Zhou | 4421a3d | 2020-06-15 14:56:18 -0700 | [diff] [blame] | 547 | |
| 548 | public void cleanUp() { |
| 549 | if (mHost != null) { |
| 550 | mHost.release(); |
| 551 | mHost = null; |
| 552 | } |
| 553 | } |
Tracy Zhou | a19cbdd | 2020-04-26 12:12:11 -0700 | [diff] [blame] | 554 | }; |
| 555 | |
Tracy Zhou | 67fd7e3 | 2020-05-01 18:35:36 -0700 | [diff] [blame] | 556 | private void setEditingEnabled(boolean enabled) { |
Tracy Zhou | ecfd6eb | 2020-05-27 23:56:35 -0700 | [diff] [blame] | 557 | mTouchForwardingLayout.setForwardingEnabled(enabled); |
Tracy Zhou | 3eb234c | 2020-05-05 15:17:33 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Wesley.CW Wang | f21486b | 2020-06-02 18:30:32 +0800 | [diff] [blame] | 560 | private void updateScreenPreview(boolean isHomeSelected) { |
chihhangchuang | 287d4b7 | 2020-06-25 01:09:09 +0800 | [diff] [blame] | 561 | mWorkspaceSurface.setVisibility(isHomeSelected ? View.VISIBLE : View.INVISIBLE); |
| 562 | mLockPreviewContainer.setVisibility(isHomeSelected ? View.INVISIBLE : View.VISIBLE); |
Tracy Zhou | 67fd7e3 | 2020-05-01 18:35:36 -0700 | [diff] [blame] | 563 | } |
Santiago Etchebehere | 6d3d1e6 | 2019-09-26 11:11:11 -0700 | [diff] [blame] | 564 | } |